/*************************************************************************** shx_mod.cpp - description ------------------- begin : Fri Apr 22 21:26:11 2005 copyright : (C) 2002 by Cavalli Andrea email : cavalli@bioc.unizh.ch **************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace Almost; #define ALMTOSTRING(s) \ template<> \ inline string to_string(const s & ){ \ return "<" #s ">"; \ } ALMTOSTRING(Molecules); ALMTOSTRING(MDB); extern void mol2pdb(const Molecules & mols, string ofile); extern Coor mols_coor(const Molecules & molecules); int alm_shx_main(const Molecules & molecules, double * ha, double * h, double * n, double * ca, double * cb, double * c ); int alm_shx_main_fake(const Molecules & molecules, double * ha, double * h, double * n, double * ca, double * cb, double * c ); static string apmf_dir = "../PMF/"; template struct SHXOptions { //force field options enum { NONE = 0, SASA = 1, EEF1 = 2}; enum { BERENDSEN = 0, LANGEVIN = 1, NEWTON = 2}; enum { C19 = 0, C22 = 1}; enum { OFF, RDIE, CDIE, LJ, SHIFT, SWITCH }; enum { PLAIN, CUBIC}; int kind; int elec; int elec_cutoff; int vdw; int vdw_cutoff; int solv; bool solv_ignore_h; float_type cut_on; float_type cut_off; float_type cut_nb; float_type e_zero; float_type e_14; float_type eps; float_type r_water; float_type gamma_water; //NEW bool vect; //MD int algorithm; //Geometry int geometry; float_type Lx; float_type Ly; float_type Lz; int granularity; string trj; string vtrj; string rst; string log; string dat; int steps; int nprint; int nsave; int nupdate; int nrottrans; int nsurf; //NEW int shake_mode; float_type shake_tol; float_type begin_temp; float_type end_temp; int sa_steps; int ga_steps; float_type time_step; float_type tau; int seed; bool save_fitted; string selection; //MIP int nreplica; SHXOptions(int k = C19):kind(k){ if(kind==C19) c19_defaults(); else if(kind==C22) c22_defaults(); else c19_defaults(); r_water = 1.4; gamma_water = 91; algorithm = BERENDSEN; geometry = PLAIN; Lx = Ly = Lz = 3*cut_nb; granularity = 1; trj = "run_coor.dcd"; vtrj = "none"; rst = "run.rst"; log = "stdout"; dat = "none"; steps = 100000; nprint = 1000; nsave = 1000; nupdate = 10; nsurf = 1000; nrottrans = 1000; shake_mode = Shake::BONDH; shake_tol = 10E-6; begin_temp = 1000.00; end_temp = 0.00; sa_steps = 100; ga_steps = 100; time_step = 0.002; tau = 5.0; seed = 30869; save_fitted=0; selection = "///CA"; nreplica = 2; } private: void c19_defaults(){ elec = RDIE; elec_cutoff = SHIFT; vdw = LJ; vdw_cutoff = SHIFT; solv = SASA; solv_ignore_h =1; cut_on = 6.5; cut_off = 7.5; cut_nb = 8.0; e_zero = 332.0716; e_14 = 0.4; eps = 2.0; vect = 0; } void c22_defaults(){ elec = RDIE; elec_cutoff = SHIFT; vdw = LJ; vdw_cutoff = SHIFT; solv = NONE; solv_ignore_h =0; cut_on = 10; cut_off = 12; cut_nb = 14; e_zero = 332.0716; e_14 = 1; eps = 1.0; vect = 0; } }; template inline ostream & operator<<(ostream & out, const SHXOptions & opt){ out<<"\t>> Force field kind: "; if(opt.kind == SHXOptions::C19) out<<" C19\n"; else out<<" C22\n"; out<<"\t>> Electrostatic: "; if(opt.elec==SHXOptions::RDIE) out<<" RDIE"<<"\n"; else if(opt.elec==SHXOptions::CDIE) out<<" CDIE"<<"\n"; else out<<" Off"<<"\n"; out<<"\t>> Elec-Cutoff: "; if(opt.elec_cutoff==SHXOptions::SHIFT) out<<" SHIFT"<<"\n"; else out<<" SWITCH"<<"\n"; out<<"\t>> VdW-Cutoff: "; if(opt.vdw_cutoff==SHXOptions::SHIFT) out<<" SHIFT"<<"\n"; else out<<" SWITCH"<<"\n"; out<<"\t>> Solvation: "; if(opt.solv==SHXOptions::SASA) out<<" SASA"<<"\n"; else if(opt.solv==SHXOptions::EEF1) out<<" EEF1"<<"\n"; else out<<" none"<<"\n"; out<<"\t>> Cut on: " <> Cut off: " <> Cut nb: " <> E_zero: " <> E_14: " <> Eps: " <> r_water: "<> Vector code: "; if(opt.vect) out<<"yes"<<"\n"; else out<<"no"<<"\n"; out<<"\t>> Algorithm: "; if(opt.algorithm==SHXOptions::BERENDSEN) out<<"Berendsen\n"; else if(opt.algorithm==SHXOptions::LANGEVIN) out<<"Langevin\n"; else out<<"Newton\n"; out<<"\t>> Geometry: "; if(opt.geometry==SHXOptions::PLAIN) out<<"plain\n"; else out<<"cubic"; out<<"\t>> Box size: " <> Granularity: " <> Trajectory: " <> Velocity: " <> Restart: " <> Log : " <> Data : " <> Number of steps: " <> Print frequency: " <> Save frequency: " <> NB Update frequency: " <> RT stopping frequency: " <> SHAKE mode: "; switch(opt.shake_mode){ case Shake::NONE: out<<"none"<<"\n"; break; case Shake::BONDH: out<<"bond-H"<<"\n"; break; case Shake::BONDALL: out<<"all bonds"<<"\n"; break; default: out<<"unknown (error)"<<"\n"; } out<<"\t>> SHAKE tolerance: "<> Begin temperature: " <> End temperature: " <> Simulated annealing steps: " <> Genetic algorithm steps: " <> Time step: "<> Tau: "<> Seed: " <> Selection: " <> Save fitted: " <> Number of replicas: "< struct SHXMCOptions { //force field options enum { NONE = 0, SASA = 1, EEF1 = 2}; enum { BERENDSEN = 0, LANGEVIN = 1, NEWTON = 2}; enum { C19 = 0, C22 = 1}; enum { OFF, RDIE, CDIE, LJ, SHIFT, SWITCH }; enum { PLAIN, CUBIC}; int kind; int elec; int elec_cutoff; int vdw; int vdw_cutoff; int solv; bool solv_ignore_h; float_type cut_on; float_type cut_off; float_type cut_nb; float_type e_zero; float_type e_14; float_type eps; float_type r_water; float_type gamma_water; //NEW bool vect; //MD int algorithm; //Geometry int geometry; float_type Lx; float_type Ly; float_type Lz; int granularity; string trj; string vtrj; string rst; string log; string dat; int steps; int nprint; int nsave; int nupdate; int nrottrans; int nsurf; //NEW int shake_mode; float_type shake_tol; float_type begin_temp; float_type end_temp; int sa_steps; int mc_steps; float_type mc_temp; float_type time_step; float_type tau; int seed; bool save_fitted; string selection; //MIP SHXMCOptions(int k = C19):kind(k){ if(kind==C19) c19_defaults(); else if(kind==C22) c22_defaults(); else c19_defaults(); r_water = 1.4; gamma_water = 91; algorithm = BERENDSEN; geometry = PLAIN; Lx = Ly = Lz = 3*cut_nb; granularity = 1; trj = "run_coor.dcd"; vtrj = "none"; rst = "run.rst"; log = "stdout"; dat = "none"; steps = 100000; nprint = 1000; nsave = 1000; nupdate = 10; nsurf = 1000; nrottrans = 1000; shake_mode = Shake::BONDH; shake_tol = 10E-6; begin_temp = 1000.00; end_temp = 0.00; sa_steps = 100; mc_temp = 1; mc_steps = 100; time_step = 0.002; tau = 5.0; seed = 30869; save_fitted=0; selection = "///CA"; } private: void c19_defaults(){ elec = RDIE; elec_cutoff = SHIFT; vdw = LJ; vdw_cutoff = SHIFT; solv = SASA; solv_ignore_h =1; cut_on = 6.5; cut_off = 7.5; cut_nb = 8.0; e_zero = 332.0716; e_14 = 0.4; eps = 2.0; vect = 0; } void c22_defaults(){ elec = RDIE; elec_cutoff = SHIFT; vdw = LJ; vdw_cutoff = SHIFT; solv = NONE; solv_ignore_h =0; cut_on = 10; cut_off = 12; cut_nb = 14; e_zero = 332.0716; e_14 = 1; eps = 1.0; vect = 0; } }; template inline ostream & operator<<(ostream & out, const SHXMCOptions & opt){ out<<"\t>> Force field kind: "; if(opt.kind == SHXMCOptions::C19) out<<" C19\n"; else out<<" C22\n"; out<<"\t>> Electrostatic: "; if(opt.elec==SHXMCOptions::RDIE) out<<" RDIE"<<"\n"; else if(opt.elec==SHXMCOptions::CDIE) out<<" CDIE"<<"\n"; else out<<" Off"<<"\n"; out<<"\t>> Elec-Cutoff: "; if(opt.elec_cutoff==SHXMCOptions::SHIFT) out<<" SHIFT"<<"\n"; else out<<" SWITCH"<<"\n"; out<<"\t>> VdW-Cutoff: "; if(opt.vdw_cutoff==SHXMCOptions::SHIFT) out<<" SHIFT"<<"\n"; else out<<" SWITCH"<<"\n"; out<<"\t>> Solvation: "; if(opt.solv==SHXMCOptions::SASA) out<<" SASA"<<"\n"; else if(opt.solv==SHXMCOptions::EEF1) out<<" EEF1"<<"\n"; else out<<" none"<<"\n"; out<<"\t>> Cut on: " <> Cut off: " <> Cut nb: " <> E_zero: " <> E_14: " <> Eps: " <> r_water: "<> Vector code: "; if(opt.vect) out<<"yes"<<"\n"; else out<<"no"<<"\n"; out<<"\t>> Algorithm: "; if(opt.algorithm==SHXMCOptions::BERENDSEN) out<<"Berendsen\n"; else if(opt.algorithm==SHXMCOptions::LANGEVIN) out<<"Langevin\n"; else out<<"Newton\n"; out<<"\t>> Geometry: "; if(opt.geometry==SHXMCOptions::PLAIN) out<<"plain\n"; else out<<"cubic"; out<<"\t>> Box size: " <> Granularity: " <> Trajectory: " <> Velocity: " <> Restart: " <> Log : " <> Data : " <> Number of steps: " <> Print frequency: " <> Save frequency: " <> NB Update frequency: " <> RT stopping frequency: " <> SHAKE mode: "; switch(opt.shake_mode){ case Shake::NONE: out<<"none"<<"\n"; break; case Shake::BONDH: out<<"bond-H"<<"\n"; break; case Shake::BONDALL: out<<"all bonds"<<"\n"; break; default: out<<"unknown (error)"<<"\n"; } out<<"\t>> SHAKE tolerance: "<> Begin temperature: " <> End temperature: " <> Simulated annealing steps: " <> Monte Carlo temperature: " <> Monte Carlo steps: " <> Time step: "<> Tau: "<> Seed: " <> Selection: " <> Save fitted: " < > const_seeds; vector< vector > current_const; vector HA,HN,N,CA,CB,CO; double k[6]; const Molecules * molecules_; GAConstraints(const Molecules & molecules, string file, string shx_file, int ng){ ifstream in; in.open(file.c_str()); if(!in){ cout<<"FATAL ERROR: no such file "<0){ int r = lrand48(); r = r%const_seeds[i].size(); current_const[rep][i] = const_seeds[i][r]; } else current_const[rep][i] = rc; } } molecules_ = &molecules; read_shifts(shx_file,HA,HN,N,CA,CB,CO); k[0] = 17.53; k[1] = 10; k[2] = 0.18; k[3] = 0.99; k[4] = 0.91; k[5] = 1.21; } DihedralConst constraints(int rep, int step){ DihedralConst dc(*molecules_); char buff[256]; sprintf(buff,"const_%i_%i.cst",rep,step); ofstream dbg; dbg.open(buff); for(int i=0;i & vdw){ map score; for(int rep = 0; rep< xmols.size();rep++){ vector ha,hn,n,ca,cb,co; double e = 0; mol2pdb(xmols[rep],"__.pdb"); int status = system("shifts_local __.pdb"); if(status==-1){ cout<<"FATAL ERROR: could't compute shifts\n"; exit(-1); } else { read_shifts("__.shx", ha,hn,n,ca,cb,co ); } // for(int i= 0;i> Replica "<> Replica "<> Replica "<> Replica "<> Replica "<> Score replica "< > new_const; new_const.resize(xmols.size()); //Take First randomized map::iterator iter = score.begin(),end = score.end(); new_const[0] = current_const[iter->second]; ++iter; new_const[1] = current_const[iter->second]; ++iter; double rand = drand48(); if(rand<0.5){ cross(new_const[0],new_const[1]); } else { shake(new_const[0]); shake(new_const[1]); } //For the oder take other candidate ResidueConst rc; for(int rep =2; repsecond]; if(rand<0.25) shake(new_const[rep]); else{ cross_noshake(new_const[rep-1],new_const[rep]); } } else { for(int i=0;i0){ int r = lrand48(); r = r%const_seeds[i].size(); new_const[rep].push_back(const_seeds[i][r]); } else new_const[rep].push_back(rc); } } ++iter; } iter = score.begin(); int pos = 0; while(iter!=end){ current_const[iter->second] = new_const[pos]; ++iter; ++pos; } } private: double correlation(vector & v1, vector & v2){ double X,Y,XX,YY,XY; X = Y = XX = YY = XY = 0; for(int i=0;i & rc){ for(int r = 0;r & rc1, vector & rc2){ int r = lrand48()%rc1.size(); for(int i=0;i & rc1, vector & rc2){ int r = lrand48()%rc1.size(); for(int i=0;i iter(in),end; //Format num phi psi omega while(iter!=end){ int num = atoi((*iter).c_str()); ++iter; if((num<1)||(num>molecules.fragment_size())){ cout<<"FATAL ERROR: invalid fragment number "< &ha_, vector &hn_, vector &n_, vector &ca_, vector &cb_, vector &co_){ ifstream in; in.open(file.c_str()); if(!in){ cout<<"FATAL ERROR: couldn't open shift file "< iter(in),end; while(iter!=end){ double sh; sh = atof((*iter).c_str());++iter; ha_.push_back(sh); sh = atof((*iter).c_str());++iter; hn_.push_back(sh); sh = atof((*iter).c_str());++iter; n_.push_back(sh); sh = atof((*iter).c_str());++iter; ca_.push_back(sh); sh = atof((*iter).c_str());++iter; cb_.push_back(sh); sh = atof((*iter).c_str());++iter; co_.push_back(sh); } } }; class MCConstraints { public: struct ResidueConst { ResidueConst(){ phi = psi = omega = 999; } double phi; double psi; double omega; }; vector< vector > const_seeds; vector current_const; vector buffer_const; double current_energy; double tmp_energy; double temp; vector HA,HN,N,CA,CB,CO; double k[6]; const Molecules * molecules_; APMF pmf; MCConstraints(const Molecules & molecules, string file, string shx_file) :pmf(molecules,apmf_dir+"frag.lib",apmf_dir+"alm.pmf", APMF::ALL,0.00181242){ ifstream in; in.open(file.c_str()); if(!in){ cout<<"FATAL ERROR: no such file "<0){ int r = lrand48(); r = r%const_seeds[i].size(); current_const[i] = const_seeds[i][r]; } else current_const[i] = rc; } buffer_const = current_const; molecules_ = &molecules; read_shifts(shx_file,HA,HN,N,CA,CB,CO); k[0] = 17.53; k[1] = 10; k[2] = 0.18; k[3] = 0.99; k[4] = 0.91; k[5] = 1.21; eval(molecules); current_energy = tmp_energy; current_const = buffer_const; } void set_temp(double t) { temp = t;} DihedralConst constraints(int step, int mc_step){ DihedralConst dc(*molecules_); char buff[256]; sprintf(buff,"const_%i.cst",mc_step); ofstream dbg; dbg.open(buff); for(int i=0;i ha,hn,n,ca,cb,co; double e = 0; mol2pdb(mols,"__.pdb"); int status = system("shifts_local __.pdb"); if(status==-1){ cout<<"FATAL ERROR: could't compute shifts\n"; exit(-1); } else { read_shifts("__.shx", ha,hn,n,ca,cb,co ); } double c; c = correlation(ha,HA); cout<<"\t>> HA correlation "<> HN correlation "<> N correlation "<> CA correlation "<> CB correlation "<> Coorelation score: "<> PMF Energy: "< n; vector c; vector ca; for(int i=0;i coor(mols); const int dim = Coor::DIM; current_const[0].psi = (180.0/M_PI)*Kernel::Geometry::dihedral(coor.coor+dim*n[0], coor.coor+dim*ca[0], coor.coor+dim*c[0], coor.coor+dim*n[1]); for(int aa = 1; aa> SHXMC shake const\n"; } else { rebuild(current_const); cout<<"\t>> SHXMC build const\n"; } } bool metropolis(){ if(tmp_energy> Score "<> Accepted\n"; return true; } double d = drand48(); if(d> Score "<> Accepted\n"; return true; } else { current_const = buffer_const; cout<<"\t>> Score "<> Rejected\n"; return false; } } private: double correlation(vector & v1, vector & v2){ double X,Y,XX,YY,XY; X = Y = XX = YY = XY = 0; for(int i=0;i & rc){ //MODIF: shake delta now 25 deg for(int r = 0;r & rest){ ResidueConst rc; for(int i=0;i0){ int r = lrand48(); r = r%const_seeds[i].size(); rest[i] = const_seeds[i][r]; } else rest[i] = rc; } } void parse(const Molecules & molecules, ifstream & in){ const_seeds.resize(molecules.fragment_size()); istream_iterator iter(in),end; //Format num phi psi omega while(iter!=end){ int num = atoi((*iter).c_str()); ++iter; if((num<1)||(num>molecules.fragment_size())){ cout<<"FATAL ERROR: invalid fragment number!"< &ha_, vector &hn_, vector &n_, vector &ca_, vector &cb_, vector &co_){ ifstream in; in.open(file.c_str()); if(!in){ cout<<"FATAL ERROR: couldn't open shift file "< iter(in),end; while(iter!=end){ double sh; sh = atof((*iter).c_str());++iter; ha_.push_back(sh); sh = atof((*iter).c_str());++iter; hn_.push_back(sh); sh = atof((*iter).c_str());++iter; n_.push_back(sh); sh = atof((*iter).c_str());++iter; ca_.push_back(sh); sh = atof((*iter).c_str());++iter; cb_.push_back(sh); sh = atof((*iter).c_str());++iter; co_.push_back(sh); } } }; class SHX { GAConstraints ga_const; vector vdw_energy; public: SHX(const Molecules & molecules, string file, string shx_file, int ng) :ga_const(molecules,file,shx_file,ng){ vdw_energy.resize(ng); } XMolecules run(const XMolecules & molecules, const SHXOptions & options, const MDB & mdb){ srand48(options.seed); //Does plain aneeling XMolecules m = molecules; for(int ga_step = 0; ga_step & options, const MDB & mdb, int rep, int ga_step){ double b = options.begin_temp; double e = options.end_temp; double dt = (b-e)/options.sa_steps; Molecules res = m; for(int a=0;a dc = ga_const.constraints(rep,step); HBConst hb = HBConst(m); cc.add(dc); cc.add(hb); MD md(cc); MDOptions opts = getopts(options,rep,step,ga_step,b-step*dt); Molecules ress = md.run(res,opts,mdb); for(int a=0;a ene_opts = geteneopts(options); ConstraintCollection cc; DihedralConst dc = ga_const.constraints(rep,options.sa_steps); // APMF pmf = APMF(m,"frag.lib","alm.pmf", // APMF::ALL, // 0.001); cc.add(dc); // cc.add(pmf); EnergyData ene = const_sd(res,ene_opts,cc,mdb,1000,0.01); vdw_energy[rep] = ene["const"]; char buff[256]; sprintf(buff,"coor_pmf_%i_%i.pdb",rep,ga_step); mol2pdb(res,buff); return res; } MDOptions getopts(const SHXOptions & options, int rep, int step, int ga_step, double temp){ MDOptions opts; opts.kind = options.kind; opts.elec = options.elec; opts.elec_cutoff = options.elec_cutoff; opts.vdw = options.vdw; opts.vdw_cutoff = options.vdw_cutoff; opts.solv = options.solv; opts.solv_ignore_h = options.solv_ignore_h; opts.cut_on = options.cut_on; opts.cut_off = options.cut_off; opts.cut_nb = options.cut_nb; opts.e_zero = options.e_zero; opts.e_14 = options.e_14; opts.eps = options.eps; opts.r_water = options.r_water; opts.gamma_water = options.gamma_water; opts.vect = options.vect; opts.algorithm = options.algorithm; opts.geometry = options.geometry; opts.Lx = options.Lx; opts.Ly = options.Ly; opts.Lz = options.Lz; opts.granularity = options.granularity; opts.trj = mkname(rep,step,ga_step,options.trj); // opts.vtrj = mkname(rep,step,ga_step,options.vtrj); opts.rst = mkname(rep,step,ga_step,options.rst); // opts.log = mkname(rep,step,ga_step,options.log); opts.dat = mkname(rep,step,ga_step,options.dat); opts.steps = options.steps; opts.nprint = options.nprint; opts.nsave = options.nsave; opts.nupdate = options.nupdate; opts.nrottrans = options.nrottrans; opts.nsurf = options.nsurf; opts.shake_mode = options.shake_mode; opts.shake_tol = options.shake_tol; opts.temp = temp; opts.time_step = options.time_step; opts.tau = options.tau; opts.seed = options.seed+rep*step; opts.save_fitted = options.save_fitted; opts.selection = options.selection; return opts; } EnergyOptions geteneopts(const SHXOptions & options){ EnergyOptions opts; opts.kind = options.kind; opts.elec = options.elec; opts.elec_cutoff = options.elec_cutoff; opts.vdw = options.vdw; opts.vdw_cutoff = options.vdw_cutoff; opts.solv = options.solv; opts.solv_ignore_h = options.solv_ignore_h; opts.cut_on = options.cut_on; opts.cut_off = options.cut_off; opts.cut_nb = options.cut_nb; opts.e_zero = options.e_zero; opts.e_14 = options.e_14; opts.eps = options.eps; opts.r_water = options.r_water; opts.vect = options.vect; opts.geometry = options.geometry; opts.Lx = options.Lx; opts.Ly = options.Ly; opts.Lz = options.Lz; opts.granularity = options.granularity; return opts; } string mkname(int rep,int step, int ga_step, string s){ char buff[256]; sprintf(buff,"_%i_%i_%i",ga_step,rep,step); int pos = s.find("."); string name; if(pos!=string::npos){ name = string(s.begin(),s.begin()+pos) +string(buff)+ string(s.begin()+pos,s.end()); } else { name = s+string(buff); } cout<<"DEBUG name "< & options, const MDB & mdb){ srand48(options.seed); mc_const.set_temp(options.mc_temp); Molecules m = molecules; Molecules b = molecules; for(int a=0;a & options, const MDB & mdb,int mc_step){ double b = options.begin_temp; double e = options.end_temp; double dt = (b-e)/options.sa_steps; Molecules res = m; for(int a=0;a dc = mc_const.constraints(step,mc_step); HBConst hb = HBConst(m); cc.add(dc); cc.add(hb); MD md(cc); MDOptions opts = getopts(options,step,mc_step,b-step*dt); Molecules ress = md.run(res,opts,mdb); for(int a=0;a ene_opts = geteneopts(options); ConstraintCollection cc; DihedralConst dc = mc_const.constraints(options.sa_steps,mc_step); cc.add(dc); //MODIF setps where 10000 EnergyData ene = const_sd(res,ene_opts,cc,mdb,1000,0.01); // vdw_energy[rep] = ene["vdw"]; char buff[256]; sprintf(buff,"coor_%i.pdb",mc_step); mol2pdb(res,buff); return res; } MDOptions getopts(const SHXMCOptions & options, int step, int mc_step, double temp){ MDOptions opts; opts.kind = options.kind; opts.elec = options.elec; opts.elec_cutoff = options.elec_cutoff; opts.vdw = options.vdw; opts.vdw_cutoff = options.vdw_cutoff; opts.solv = options.solv; opts.solv_ignore_h = options.solv_ignore_h; opts.cut_on = options.cut_on; opts.cut_off = options.cut_off; opts.cut_nb = options.cut_nb; opts.e_zero = options.e_zero; opts.e_14 = options.e_14; opts.eps = options.eps; opts.r_water = options.r_water; opts.gamma_water = options.gamma_water; opts.vect = options.vect; opts.algorithm = options.algorithm; opts.geometry = options.geometry; opts.Lx = options.Lx; opts.Ly = options.Ly; opts.Lz = options.Lz; opts.granularity = options.granularity; opts.trj = mkname(step,mc_step,options.trj); // opts.vtrj = mkname(step,mc_step,options.vtrj); opts.rst = mkname(step,mc_step,options.rst); // opts.log = mkname(step,mc_step,options.log); opts.dat = mkname(step,mc_step,options.dat); opts.steps = options.steps; opts.nprint = options.nprint; opts.nsave = options.nsave; opts.nupdate = options.nupdate; opts.nrottrans = options.nrottrans; opts.nsurf = options.nsurf; opts.shake_mode = options.shake_mode; opts.shake_tol = options.shake_tol; opts.temp = temp; opts.time_step = options.time_step; opts.tau = options.tau; opts.seed = options.seed+step; opts.save_fitted = options.save_fitted; opts.selection = options.selection; return opts; } EnergyOptions geteneopts(const SHXMCOptions & options){ EnergyOptions opts; opts.kind = options.kind; opts.elec = options.elec; opts.elec_cutoff = options.elec_cutoff; opts.vdw = options.vdw; opts.vdw_cutoff = options.vdw_cutoff; opts.solv = options.solv; opts.solv_ignore_h = options.solv_ignore_h; opts.cut_on = options.cut_on; opts.cut_off = options.cut_off; opts.cut_nb = options.cut_nb; opts.e_zero = options.e_zero; opts.e_14 = options.e_14; opts.eps = options.eps; opts.r_water = options.r_water; opts.vect = options.vect; opts.geometry = options.geometry; opts.Lx = options.Lx; opts.Ly = options.Ly; opts.Lz = options.Lz; opts.granularity = options.granularity; return opts; } string mkname(int step, int mc_step, string s){ char buff[256]; sprintf(buff,"_%i_%i",mc_step,step); int pos = s.find("."); string name; if(pos!=string::npos){ name = string(s.begin(),s.begin()+pos) +string(buff)+ string(s.begin()+pos,s.end()); } else { name = s+string(buff); } cout<<"DEBUG name "< &ha_, vector &hn_, vector &n_, vector &ca_, vector &cb_, vector &co_){ ifstream in; in.open(file.c_str()); if(!in){ cout<<"FATAL ERROR: couldn't open shift file "< iter(in),end; while(iter!=end){ double sh; sh = atof((*iter).c_str());++iter; ha_.push_back(sh); sh = atof((*iter).c_str());++iter; hn_.push_back(sh); sh = atof((*iter).c_str());++iter; n_.push_back(sh); sh = atof((*iter).c_str());++iter; ca_.push_back(sh); sh = atof((*iter).c_str());++iter; cb_.push_back(sh); sh = atof((*iter).c_str());++iter; co_.push_back(sh); } } double correlation(vector & v1, vector & v2){ double X,Y,XX,YY,XY; X = Y = XX = YY = XY = 0; for(int i=0;i & v2){ double X,Y,XX,YY,XY; X = Y = XX = YY = XY = 0; for(int i=0;i & v1, vector & v2){ double X,Y,XX,YY,XY,Z; X = Y = XX = YY = XY = Z = 0; for(int i=0;i & v2){ double X,Y,XX,YY,XY,Z; X = Y = XX = YY = XY = Z = 0; for(int i=0;i HA,HN,N,CA,CB,CO; double k[6]; k[0] = 17.53; k[1] = 10; k[2] = 0.18; k[3] = 0.99; k[4] = 0.91; k[5] = 1.21; read_shifts(file,HA,HN,N,CA,CB,CO); vector ha,hn,n,ca,cb,co; mol2pdb(mols,"__.pdb"); // int status = system("shifts_local __.pdb"); read_shifts("__.shx", ha,hn,n,ca,cb,co ); { int size = HA.size(); for(int i=0;i HA,HN,N,CA,CB,CO; double k[6]; k[0] = 17.53; k[1] = 10; k[2] = 0.18; k[3] = 0.99; k[4] = 0.91; k[5] = 1.21; double *ha,*hn,*n,*ca,*cb,*co; int fsize = mols.fragment_size(); ha = new double[fsize]; hn = new double[fsize]; n = new double[fsize]; ca = new double[fsize]; cb = new double[fsize]; co = new double[fsize]; read_shifts(file,HA,HN,N,CA,CB,CO); alm_shx_main(mols,ha,hn,n,ca,cb,co); { int size = HA.size(); for(int i=0;i HA,HN,N,CA,CB,CO; double k[6]; k[0] = 17.53; k[1] = 10; k[2] = 10; k[3] = 10; k[4] = 10; k[5] = 10; double *ha,*hn,*n,*ca,*cb,*co; int fsize = mols.fragment_size(); ha = new double[fsize]; hn = new double[fsize]; n = new double[fsize]; ca = new double[fsize]; cb = new double[fsize]; co = new double[fsize]; read_shifts(file,HA,HN,N,CA,CB,CO); alm_shx_main(mols,ha,hn,n,ca,cb,co); { int size = HA.size(); for(int i=0;i.911){ c=.911; } e = 0;//k[0]*(1-c); c = newcorrelation(hn,HN); // cout<<"HN correlation "<.909){ c=.909; } e += k[2]*(1-c); c = newcorrelation(ca,CA); cout<<"CA correlation "<.980){ c=.980; } e += k[3]*(1-c); c = newcorrelation(cb,CB); cout<<"CB correlation "<.996){ c=.996; } e += k[4]*(1-c); e *= 100; delete [] ha; delete [] hn; delete [] n; delete [] ca; delete [] cb; delete [] co; // cout<<"DEBUG shx "< & HA, vector & H, vector & N, vector & CA, vector & CB, vector & C ){ double *ha,*hn,*n,*ca,*cb,*co; int fsize = mols.fragment_size(); ha = new double[fsize]; hn = new double[fsize]; n = new double[fsize]; ca = new double[fsize]; cb = new double[fsize]; co = new double[fsize]; alm_shx_main(mols,ha,hn,n,ca,cb,co); for(int i=0;i HA,HN,N,CA,CB,CO; double k[6]; k[0] = 17.53; k[1] = 10; k[2] = 0.18; k[3] = 0.99; k[4] = 0.91; k[5] = 1.21; double *ha,*hn,*n,*ca,*cb,*co; int fsize = mols.fragment_size(); ha = new double[fsize]; hn = new double[fsize]; n = new double[fsize]; ca = new double[fsize]; cb = new double[fsize]; co = new double[fsize]; read_shifts(file,HA,HN,N,CA,CB,CO); alm_shx_main(mols,ha,hn,n,ca,cb,co); { int size = HA.size(); for(int i=0;i HA,HN,N,CA,CB,CO; double k[6]; // k[0] = 17.53; // k[1] = 10; k[2] = 0.18; k[3] = 0.99; k[4] = 0.91; k[5] = 1.21; double *ha,*hn,*n,*ca,*cb,*co; int fsize = mols.fragment_size(); ha = new double[fsize]; hn = new double[fsize]; n = new double[fsize]; ca = new double[fsize]; cb = new double[fsize]; co = new double[fsize]; read_shifts(file,HA,HN,N,CA,CB,CO); alm_shx_main_fake(mols,ha,hn,n,ca,cb,co); { int size = HA.size(); for(int i=0;i HA,HN,N,CA,CB,CO; double k[6]; // k[0] = 17.53; // k[1] = 10; k[2] = 0.18; k[3] = 0.99; k[4] = 0.91; k[5] = 1.21; double *ha,*hn,*n,*ca,*cb,*co; int fsize = mols.fragment_size(); ha = new double[fsize]; hn = new double[fsize]; n = new double[fsize]; ca = new double[fsize]; cb = new double[fsize]; co = new double[fsize]; read_shifts(file,HA,HN,N,CA,CB,CO); alm_shx_main_fake(mols,ha,hn,n,ca,cb,co); int size = HA.size(); for(int i=0;i inline string to_string(const SHXOptions & c19md_opt){ stringstream s; s< inline string to_string(const SHXMCOptions & c19md_opt){ stringstream s; s< inline string to_string(const SHX &){ return ""; } //template inline string to_string(const SHXMC &){ return ""; } template<> inline string to_string(const XMolecules & molecules){ return ""; } extern "C" { int shx_main( int argc, char *argv[], double * ha, double * h, double * n, double * ca, double * cb, double * c ); } int alm_shx_main(const Molecules & molecules, double * ha, double * h, double * n, double * ca, double * cb, double * c ){ //Print molecules to tmp int pid = getpid(); // char buff[256]; // sprintf(buff,"/tmp/%i.pdb",pid); int argc=4; char ** argv = new char*[4]; for(int i=0;i<4;i++) argv[i] = new char[256]; strcpy(argv[0],"almost"); strcpy(argv[1],"1"); sprintf(argv[2],"/tmp/%i.pdb",pid); sprintf(argv[3],"/tmp/%i.s",pid); mol2pdb(molecules,argv[2]); shx_main(argc,argv,ha,h,n,ca,cb,c); unlink(argv[2]); unlink(argv[3]); for(int i=0;i<4;i++) delete [] argv[i]; delete [] argv; return 1; } void mol2pdb_fake(const Molecules &molecules,char * file){ ofstream out; out.open(file); char buff[180]; for(int i=0;i >(mod.self(),"shx") .def_method("run",&SHX::run); Class >(mod.self(),"shx_mc") .def_method("run",&SHXMC::run); #define REGATTR(c,s,w) def_attribute(#s,&c::s,w::s) Class >(mod.self(),"gaoptions") .REGATTR(SHXOptions,kind,FFDoc) .REGATTR(SHXOptions,elec,FFDoc) .REGATTR(SHXOptions,elec_cutoff,FFDoc) .REGATTR(SHXOptions,vdw,FFDoc) .REGATTR(SHXOptions,vdw_cutoff,FFDoc) .REGATTR(SHXOptions,solv,FFDoc) .REGATTR(SHXOptions,solv_ignore_h,FFDoc) .REGATTR(SHXOptions,cut_on,FFDoc) .REGATTR(SHXOptions,cut_off,FFDoc) .REGATTR(SHXOptions,cut_nb,FFDoc) .REGATTR(SHXOptions,e_zero,FFDoc) .REGATTR(SHXOptions,e_14,FFDoc) .REGATTR(SHXOptions,eps,FFDoc) .REGATTR(SHXOptions,r_water,FFDoc) .REGATTR(SHXOptions,gamma_water,RunDoc) .REGATTR(SHXOptions,vect,RunDoc) .REGATTR(SHXOptions,algorithm,RunDoc) .REGATTR(SHXOptions,geometry,RunDoc) .REGATTR(SHXOptions,Lx,RunDoc) .REGATTR(SHXOptions,Ly,RunDoc) .REGATTR(SHXOptions,Lz,RunDoc) .REGATTR(SHXOptions,granularity,RunDoc) .REGATTR(SHXOptions,trj,RunDoc) .REGATTR(SHXOptions,vtrj,RunDoc) .REGATTR(SHXOptions,rst,RunDoc) .REGATTR(SHXOptions,log,RunDoc) .REGATTR(SHXOptions,dat,RunDoc) .REGATTR(SHXOptions,steps,RunDoc) .REGATTR(SHXOptions,nprint,RunDoc) .REGATTR(SHXOptions,nsave,RunDoc) .REGATTR(SHXOptions,nupdate,RunDoc) .REGATTR(SHXOptions,nrottrans,RunDoc) .REGATTR(SHXOptions,shake_mode,RunDoc) .REGATTR(SHXOptions,shake_tol,RunDoc) // .REGATTR(SHXOptions,temp,RunDoc) .REGATTR(SHXOptions,time_step,RunDoc) .REGATTR(SHXOptions,tau,RunDoc) .REGATTR(SHXOptions,seed,RunDoc) .REGATTR(SHXOptions,save_fitted,RunDoc) .REGATTR(SHXOptions,selection,RunDoc) .REGATTR(SHXOptions,nreplica,RunDoc); Class >(mod.self(),"mcoptions") .REGATTR(SHXMCOptions,kind,FFDoc) .REGATTR(SHXMCOptions,elec,FFDoc) .REGATTR(SHXMCOptions,elec_cutoff,FFDoc) .REGATTR(SHXMCOptions,vdw,FFDoc) .REGATTR(SHXMCOptions,vdw_cutoff,FFDoc) .REGATTR(SHXMCOptions,solv,FFDoc) .REGATTR(SHXMCOptions,solv_ignore_h,FFDoc) .REGATTR(SHXMCOptions,cut_on,FFDoc) .REGATTR(SHXMCOptions,cut_off,FFDoc) .REGATTR(SHXMCOptions,cut_nb,FFDoc) .REGATTR(SHXMCOptions,e_zero,FFDoc) .REGATTR(SHXMCOptions,e_14,FFDoc) .REGATTR(SHXMCOptions,eps,FFDoc) .REGATTR(SHXMCOptions,r_water,FFDoc) .REGATTR(SHXMCOptions,gamma_water,RunDoc) .REGATTR(SHXMCOptions,vect,RunDoc) .REGATTR(SHXMCOptions,algorithm,RunDoc) .REGATTR(SHXMCOptions,geometry,RunDoc) .REGATTR(SHXMCOptions,Lx,RunDoc) .REGATTR(SHXMCOptions,Ly,RunDoc) .REGATTR(SHXMCOptions,Lz,RunDoc) .REGATTR(SHXMCOptions,granularity,RunDoc) .REGATTR(SHXMCOptions,trj,RunDoc) .REGATTR(SHXMCOptions,vtrj,RunDoc) .REGATTR(SHXMCOptions,rst,RunDoc) .REGATTR(SHXMCOptions,log,RunDoc) .REGATTR(SHXMCOptions,dat,RunDoc) .REGATTR(SHXMCOptions,steps,RunDoc) .REGATTR(SHXMCOptions,nprint,RunDoc) .REGATTR(SHXMCOptions,nsave,RunDoc) .REGATTR(SHXMCOptions,nupdate,RunDoc) .REGATTR(SHXMCOptions,nrottrans,RunDoc) .REGATTR(SHXMCOptions,shake_mode,RunDoc) .REGATTR(SHXMCOptions,shake_tol,RunDoc) // .REGATTR(SHXMCOptions,temp,RunDoc) .REGATTR(SHXMCOptions,time_step,RunDoc) .REGATTR(SHXMCOptions,tau,RunDoc) .REGATTR(SHXMCOptions,seed,RunDoc) .REGATTR(SHXMCOptions,save_fitted,RunDoc) .REGATTR(SHXMCOptions,selection,RunDoc) ; mod .def_function("score","Returns shx score",score) .def_function("score_silent","Returns shx score",score_silent) .def_function("new_score_silent","Returns shx score",new_score_silent) .def_function("score_noha","Returns shx score",score_noha) .def_function("score_silent_fix","Returns shx score",score_silent_fib) .def_function("score_silent_fix2","Returns shx score",score_silent_fib2) // .def_function("shx_score","Returns shx score",alm_shx_main) .def_const("apmf_dir",apmf_dir); ; } }