/*************************************************************************** energy_mod.cpp - description ------------------- begin : Tue Dec 23 08:37:05 2003 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 using namespace Almost; #define ALMTOSTRING(s) \ template<> \ inline string to_string(const s & ){ \ return "<" #s ">"; \ } ALMTOSTRING(ConstraintCollection); template inline string to_string(const EnergyData & data){ stringstream s; s< inline string to_string(const Coor & data){ return "Coor"; } template inline string to_string(const EnergyOptions & c19_opt){ stringstream s; s< EnergyData energy(const Molecules & molecules, const EnergyOptions & options, const MDB & mdb){ //create ff ForceField ff(molecules,options,mdb); //coordinates Coor atomCoor(molecules); EnergyData ene = ff.energy(atomCoor); return ene; } template<> inline string to_string(const ForceField &){ return "ForceField"; } #if (__GNUC__ >= 3) template<> #endif map,ForceField::ff_factory> ForceField::factory #if (__GNUC__ >= 3) = map,ForceField::ff_factory>(); #endif ; #if (__GNUC__ >= 3) template<> #endif map,ForceField::ff_factory> ForceField::factory #if (__GNUC__ >= 3) = map,ForceField::ff_factory>(); #endif ; // #if (__GNUC__ >= 3) // template<> // #endif // map::ff_factory> ForceField::factory // #if (__GNUC__ >= 3) // = map::ff_factory>(); // #endif // ; template<> inline string to_string(const Molecules & molecules){ return ""; } template<> inline string to_string(const MDB & mdb){ return ""; } void check_const(ConstraintCollection & cc, Molecules & mols, double dx, int steps){ vector xconst; xconst = cc.constraints(); int asize= mols.atom_size(); Coor coor(mols), coor_buffer(mols),ff; ff.resize(asize); ff.clear(); double W = 0; double Ene = 0; double tmp_ene = 0; for(int i=0;ienergy_force(coor,ff); } cout<<"Initial energy "<::DIM*j; coor.coor[pos] += dx*(drand48()-0.5); coor.coor[pos+1] += dx*(drand48()-0.5); coor.coor[pos+2] += dx*(drand48()-0.5); } tmp_ene = 0; for(int i=0;ienergy_force(coor,ff); } cout<<"Current energy "<::DIM*j; W += (coor.coor[pos]-coor_buffer.coor[pos])*ff.coor[pos]; pos = pos + 1; W += (coor.coor[pos]-coor_buffer.coor[pos])*ff.coor[pos]; pos = pos + 1; W += (coor.coor[pos]-coor_buffer.coor[pos])*ff.coor[pos]; } cout<<"Current energy difference "< & opts, MDB & mdb, double dx, int steps){ ForceField force(mols,opts,mdb); int asize= mols.atom_size(); Coor coor(mols), coor_buffer(mols),ff; ff.resize(asize); ff.clear(); double W = 0; double Ene0 = 0; double Ene1 = 0; double DeltaE = 0; double Einit = force.energy(coor)["energy"]; for(int i = 0;i::DIM*j; coor.coor[pos] += dx*(drand48()-0.5); coor.coor[pos+1] += dx*(drand48()-0.5); coor.coor[pos+2] += dx*(drand48()-0.5); } force.force(coor,ff,true); Ene1 = force.energy(coor)["energy"]; DeltaE += Ene1 - Ene0; for(int j = 0;j::DIM*j; W += 0.5*(coor.coor[pos]-coor_buffer.coor[pos])*ff.coor[pos]; pos = pos + 1; W += 0.5*(coor.coor[pos]-coor_buffer.coor[pos])*ff.coor[pos]; pos = pos + 1; W += 0.5*(coor.coor[pos]-coor_buffer.coor[pos])*ff.coor[pos]; } // cout<<"Current energy difference "< & opts, MDB & mdb, double dx){ ForceField force(mols,opts,mdb); int asize= mols.atom_size(); Coor coor(mols), coor_buffer(mols),ff; ff.resize(asize); ff.clear(); double Ene0 = 0; double Ene1 = 0; //Force force.energy_force(coor,ff,true); double err = 0; Ene0 = force.energy(coor)["energy"]; for(int pos = 0;pos::DIM; { coor_buffer.assign(coor); //X coor_buffer.coor[apos] += dx; Ene1 = force.energy(coor_buffer)["energy"]; double terr = abs((Ene1-Ene0)-ff.coor[apos]*dx); if(terr>err) err = terr; cout<<"Grad: "<< (Ene1-Ene0)/dx<<" "<err) err = terr; cout<< (Ene1-Ene0)/dx<<" "<err) err = terr; cout<< (Ene1-Ene0)/dx<<" "< EnergyOptions amber_ene_defaults(){ return EnergyOptions(EnergyOptions::AMBER); } template EnergyOptions c22_ene_defaults(){ return EnergyOptions(EnergyOptions::C22); } template EnergyOptions c19_ene_defaults(int kind){ return c19_defaults(kind); // return EnergyOptions(EnergyOptions::C19); } extern "C" { void init_energy(){ //declarations here Module mod = Module("energy","Energy Tools"); Class >(mod.self(),"data"); ZObj::BinaryOperator::BOM()[pair (typeid(ZType< EnergyData >), typeid(ZString))] = index_operator,const char *,double>; Class >(mod.self(),"energy_options") .def_attribute("kind",&EnergyOptions< double >::kind,FFDoc::kind) .def_attribute("elec",&EnergyOptions::elec,FFDoc::elec) .def_attribute("elec_cutoff",&EnergyOptions::elec_cutoff,FFDoc::elec_cutoff) .def_attribute("vdw",&EnergyOptions::vdw,FFDoc::vdw) .def_attribute("vdw_cutoff",&EnergyOptions::vdw_cutoff,FFDoc::vdw_cutoff) .def_attribute("solv",&EnergyOptions::solv,FFDoc::solv) .def_attribute("solv_ignore_h",&EnergyOptions::solv_ignore_h,FFDoc::solv_ignore_h) .def_attribute("geometry",&EnergyOptions::geometry,RunDoc::geometry) .def_attribute("Lx",&EnergyOptions::Lx,RunDoc::Lx) .def_attribute("Ly",&EnergyOptions::Ly,RunDoc::Ly) .def_attribute("Lz",&EnergyOptions::Lz,RunDoc::Lz) .def_attribute("vect",&EnergyOptions::vect,RunDoc::vect) .def_attribute("cut_on",&EnergyOptions::cut_on,FFDoc::cut_on) .def_attribute("cut_off",&EnergyOptions::cut_off,FFDoc::cut_off) .def_attribute("cut_nb",&EnergyOptions::cut_nb,FFDoc::cut_nb) .def_attribute("alpha",&EnergyOptions::alpha,FFDoc::alpha) .def_attribute("e_zero",&EnergyOptions::e_zero,FFDoc::e_zero) .def_attribute("e_14",&EnergyOptions::e_14,FFDoc::e_14) .def_attribute("eps",&EnergyOptions::eps,FFDoc::eps) .def_attribute("r_water",&EnergyOptions::r_water,FFDoc::r_water) .def_attribute("rgbmax",&EnergyOptions::rgbmax,"Undocumented") .def_attribute("fsmax",&EnergyOptions::fsmax,"Undocumented") .def_attribute("eps_water",&EnergyOptions::eps_water,"Undocumented") .def_attribute("offset",&EnergyOptions::offset,"Undocumented") .def_attribute("surftens",&EnergyOptions::surftens,"Undocumented") .def_attribute("nsmooth",&EnergyOptions::nsmooth,"Undocumented") .def_attribute("memb_width",&EnergyOptions::memb_width,"Undocumented") .def_attribute("elec_strength",&EnergyOptions::elec_strength,"Undocumented") ; Class,ArgList3,MDB> > (mod.self(),"force_field") .def_method("energy",&ForceField::energy) .def_method("intenergy",&ForceField::intenergy) .def_method("energy_force",&ForceField::energy_force) .def_method("force",&ForceField::force) .def_method("intforce",&ForceField::intforce) ; mod.def_function("energy","Computes C19 energy for molecules", energy) .def_function("check_const","Check that MD constraints work",check_const) .def_function("check_ff","Check that FF are correct",check_ff) .def_function("check_ff_pos","Check that FF are correct",check_ff_pos); ; mod .def_const("C19",(int)EnergyOptions::C19) .def_const("C22",(int)EnergyOptions::C22) .def_const("AMBER",(int)EnergyOptions::AMBER) .def_const("NONE",(int)EnergyOptions::NONE) .def_const("SASA",(int)EnergyOptions::SASA) .def_const("EEF1",(int)EnergyOptions::EEF1) .def_const("IMM1",(int)EnergyOptions::IMM1) .def_const("GB",(int)EnergyOptions::GB) .def_const("GB2",(int)EnergyOptions::GB2) .def_const("OFF",(int)EnergyOptions::OFF) .def_const("RDIE",(int)EnergyOptions::RDIE) .def_const("CDIE",(int)EnergyOptions::CDIE) .def_const("LJ",(int)EnergyOptions::LJ) .def_const("SHIFT",(int)EnergyOptions::SHIFT) .def_const("SWITCH",(int)EnergyOptions::SWITCH) .def_const("TRUNC",(int)EnergyOptions::TRUNC) .def_const("PLAIN",(int)EnergyOptions::PLAIN) .def_const("CUBIC",(int)EnergyOptions::CUBIC) .def_const("SSE",(int)EnergyOptions::SSE) // .def_const("NONE",(int)Shake::NONE) // .def_const("BONDH",(int)Shake::BONDH) // .def_const("BONDALL",(int)Shake::BONDALL) ; mod // .def_function("c19_options","Return options with right defaults",c19_md_options) .def_function("amber_defaults","Return options with right defaults",amber_ene_defaults) .def_function("c22_defaults","Return options with right defaults",c22_ene_defaults) .def_function("c19_defaults","Return options with right defaults",c19_ene_defaults); } }