From 50180d70375899292717f9e1e09d9df85c457c82 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 5 Apr 2016 11:17:53 +0200 Subject: [PATCH 01/90] Changements setup.py Benoist --- setup.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/setup.py b/setup.py index ed4a460..fec34cd 100644 --- a/setup.py +++ b/setup.py @@ -120,23 +120,23 @@ def find_header(names, paths, useEnvPath=False): sources.append("bindings/_ptools.pyx") -setup(ext_modules=[Extension( - "_ptools", # name of extension - sources = sources, - language="c++", # causes Cython to create C++ source - #libraries=['f2c'], - library_dirs = [boostdir], - extra_objects = [f2clib], - include_dirs = ['headers', f2c_header, boostdir], - ) - - ], - cmdclass={'build_ext': build_ext}, +ptools = Extension("_ptools", + sources=sources, + language="c++", + library_dirs=[boostdir], + include_dirs=['headers', f2c_header, boostdir], + extra_objects=[f2clib]) + +cgopt = Extension("cgopt", + sources=["PyAttract/cgopt.pyx", "PyAttract/chrg_scorpion.c"], + language="c", + include_dirs=[f2c_header, 'PyAttract'], + extra_objects = [f2clib]) + +setup(ext_modules=[ptools, cgopt], + cmdclass={'build_ext': build_ext}, packages = ['.'], name="ptools", version = "1.2" - - - ) From 7e29d68e2a99c111cd487384363bc6ea6d80d52a Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 5 Apr 2016 17:21:57 +0200 Subject: [PATCH 02/90] Modified C++ code: created Mcop class and AttractMcop subclass (replaces Region class) --- headers/mcopff.h | 93 +++++++++++++++++++--------- headers/pdbio.h | 4 +- src/mcopff.cpp | 153 +++++++++++++++++++++++++++++++++++++---------- 3 files changed, 189 insertions(+), 61 deletions(-) diff --git a/headers/mcopff.h b/headers/mcopff.h index 4e5048a..b713aa8 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -9,62 +9,101 @@ #include "attractforcefield.h" #include "rigidbody.h" +#include "pdbio.h" namespace PTools{ // typedef std::vector ensemble ; - -class Region +class Mcop { private: -std::vector _copies; +std::vector _copies; public: /* - void AttractEulerRotate(const dbl& phi, const dbl& ssi, const dbl& rot) - { - for (uint i=0; i<_copies.size(); i++) - { - _copies[i].AttractEulerRotate(phi, ssi, rot); - } - - }; - - void Translate(const Coord3D& co) - { - for(uint i =0; i< _copies.size(); ++i) + void AttractEulerRotate(const dbl& phi, const dbl& ssi, const dbl& rot) + { + for (uint i=0; i<_copies.size(); i++) { - _copies[i].Translate(co); + _copies[i].AttractEulerRotate(phi, ssi, rot); } - }*/ + }; - void addCopy(const AttractRigidbody& cop){_copies.push_back(cop);}; + void Translate(const Coord3D& co) + { + for(uint i =0; i< _copies.size(); ++i) + { + _copies[i].Translate(co); + } + }*/ - size_t size() const {return _copies.size();}; + //Contructor : no arguments + Mcop(){ } + //Contructor : takes filename + Mcop(std::string filename); + + + virtual void addCopy(const Rigidbody& cop){_copies.push_back(cop);}; + + virtual size_t size() const {return _copies.size();}; + - AttractRigidbody& operator[](uint i){return _copies[i];}; + virtual Rigidbody& operator[](uint i){return _copies[i];}; + virtual Rigidbody& getCopy(int i){return _copies[i];}; + + void ReadmcopPDB(const std::string name); + void ReadmcopPDB(std::istream& file, std::vector& protein); + void ReadModelsPDB(std::istream& file, std::vector& protein); + bool isNewModel(const std::string & line); + + void clear(){_copies.clear();}; }; +class AttractMcop: public Mcop +{ +private: + + std::vector attract_copies; + +public: + + //Constructor : no arguments + AttractMcop(){ }; + //Constructor : takes filename + AttractMcop(std::string filename); + //Constructor : takes mcop + AttractMcop(const Mcop& mcop); + + virtual void addCopy(const AttractRigidbody& cop){attract_copies.push_back(cop);}; + + virtual size_t size() const {return attract_copies.size();}; + + + virtual AttractRigidbody& operator[](uint i){return attract_copies[i];}; + virtual AttractRigidbody& getCopy(int i){return attract_copies[i];}; + +}; + + class Mcoprigid //multicopy rigidbody { public: - Mcoprigid(); //using default copy operator - void setMain(AttractRigidbody& main) ; - void addEnsemble(const Region& reg){ _vregion.push_back(reg); std::vector v; _weights.push_back(v); }; + void setCore(AttractRigidbody& core) ; + void addEnsemble(const AttractMcop& reg){ _vregion.push_back(reg); std::vector v; _weights.push_back(v); }; void AttractEulerRotate(const dbl& phi, const dbl& ssi, const dbl& rot); @@ -77,11 +116,11 @@ class Mcoprigid //multicopy rigidbody private: - AttractRigidbody _main; - std::vector< Region > _vregion ; + AttractRigidbody _core; + std::vector< AttractMcop > _vregion ; bool _complete ; - Coord3D _center ; ///
> _weights; @@ -138,5 +177,3 @@ class McopForceField: public ForceField #endif // _MCOPFF_H_ - - diff --git a/headers/pdbio.h b/headers/pdbio.h index 7d76d00..43cd742 100644 --- a/headers/pdbio.h +++ b/headers/pdbio.h @@ -9,7 +9,6 @@ #include #include - #include "rigidbody.h" namespace PTools @@ -21,6 +20,9 @@ void ReadPDB(std::istream& fichier,Rigidbody& protein ); ///< read a PDB file fr void ReadPDB(const std::string name,Rigidbody& protein ); ///< read a PDB file from a filename and load data in Rigidbody void WritePDB(const Rigidbody& rigid, std::string filename); ///< write a PDB file given a Rigidbody and a filename +Coord3D pdbToCoords(const std::string & line); ///< returns Coord3D from a PDB-like string +void pdbToAtomproperty(const std::string & line, Atomproperty& atp); ///< Set Atomproperty from a PDB-like string +bool isAtom(const std::string & line ); ///< check if pdb line contains an atom } #endif //#ifndef PDBIO_H diff --git a/src/mcopff.cpp b/src/mcopff.cpp index 56b623c..e464877 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -1,10 +1,11 @@ #include "mcopff.h" #include - +#include namespace PTools { +/////////////////// -- Class McopRigid -- //////////////////// Mcoprigid::Mcoprigid() { @@ -15,9 +16,9 @@ Mcoprigid::Mcoprigid() -void Mcoprigid::setMain(AttractRigidbody& main) { - _main=main; - _center = _main.FindCenter(); +void Mcoprigid::setCore(AttractRigidbody& core) { + _core=core; + _center = _core.FindCenter(); }; @@ -28,8 +29,8 @@ void Mcoprigid::AttractEulerRotate(const dbl& phi, const dbl& ssi, const dbl& ro //the Mcoprigid object must be centered -//rotates the main body: - _main.AttractEulerRotate(phi, ssi, rot); +//rotates the core body: + _core.AttractEulerRotate(phi, ssi, rot); //for each multicopy region, rotates the copy: @@ -42,12 +43,12 @@ void Mcoprigid::AttractEulerRotate(const dbl& phi, const dbl& ssi, const dbl& ro void Mcoprigid::Translate(const Coord3D& c) { -//translates the main body: - _main.Translate(c); +//translates the core body: + _core.Translate(c); //for each multicopy region, translates the copy: for (uint i=0; i < _vregion.size(); i++) - for (uint j=0; j<_vregion[i].size(); j++) + for (uint j=0; j < _vregion[i].size(); j++) _vregion[i][j].Translate(c); } @@ -68,9 +69,95 @@ void Mcoprigid::PrintWeights() } +/////////////////// -- Class Mcop -- //////////////////// + +Mcop::Mcop(std::string filename){ + ReadmcopPDB(filename); +} + + +void Mcop::ReadmcopPDB(const std::string name) { + + std::string nomfich = name ; + // pointer toward the filename given in the constructor argument + std::ifstream file(nomfich.c_str()); + if (!file) + { + std::ostringstream oss; + throw std::invalid_argument("##### ReadPDB:Could not open file \"" + nomfich + "\" #####") ; + } + + ReadmcopPDB(file, _copies); + file.close(); + +} + +void Mcop::ReadmcopPDB(std::istream& file, std::vector& protein) { + + ReadModelsPDB(file, protein); + +} +void Mcop::ReadModelsPDB(std::istream& file, std::vector& protein){ + + std::string line; + while(std::getline(file, line)){ + if(isNewModel(line)){ + // The line is a new model + Rigidbody model; + while(std::getline(file,line)){ + if(isAtom(line)){ + // The line is an atom + Coord3D pos = pdbToCoords(line); + Atomproperty a; + pdbToAtomproperty(line, a); + model.AddAtom(a,pos); + } + else{ + protein.push_back(model); + //Just finished writing a model + break; + } + } + } + } +} + +bool Mcop::isNewModel(const std::string & line){ + + if(line.substr(0,5)==(std::string)"MODEL") return true; + else return false; +} + + +/////////////////// -- Class AttractMcop -- //////////////////// +AttractMcop::AttractMcop(std::string filename){ + + Mcop copies(filename); + for(int i=0; i < copies.size(); i++){ + Rigidbody copy = copies.getCopy(i); + AttractRigidbody attcopy = AttractRigidbody(copy); + attract_copies.push_back(attcopy); + } + copies.clear(); +} + +AttractMcop::AttractMcop(const Mcop& mcop){ + + Mcop copies = mcop; + for(int i=0; i < copies.size(); i++){ + Rigidbody copy = copies.getCopy(i); + AttractRigidbody attcopy = AttractRigidbody(copy); + attract_copies.push_back(attcopy); + } + copies.clear(); +} + + +/////////////////// -- Class McopForceField -- //////////////////// + /////////////////////////////////////////////////// // Forcefield implementation /////////////////////////////////////////////////// @@ -94,8 +181,8 @@ void McopForceField::calculate_weights(Mcoprigid& lig, bool print) for (uint copy = 0; copy < _receptor._vregion[loopregion].size(); copy++) { - AttractPairList cpl ( lig._main, _receptor._vregion[loopregion][copy], _cutoff ); - dbl e = _ff.nonbon8( lig._main, _receptor._vregion[loopregion][copy] , cpl ); + AttractPairList cpl ( lig._core, _receptor._vregion[loopregion][copy], _cutoff ); + dbl e = _ff.nonbon8( lig._core, _receptor._vregion[loopregion][copy] , cpl ); Eik.push_back(e); } @@ -163,13 +250,13 @@ dbl McopForceField::Function(const Vdouble & v) //2) calculates the energy - //2.1) main ligand body with main receptor + //2.1) core ligand body with core receptor - AttractPairList pl (_receptor._main, lig._main, _cutoff ); - ener += _ff.nonbon8(_receptor._main, lig._main, pl ); + AttractPairList pl (_receptor._core, lig._core, _cutoff ); + ener += _ff.nonbon8(_receptor._core, lig._core, pl ); - //2.2) main lignd with receptor copies: + //2.2) core lignd with receptor copies: assert(_receptor._vregion.size() == _receptor._weights.size()); for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++) @@ -179,7 +266,7 @@ dbl McopForceField::Function(const Vdouble & v) // std::vector Eik; - Region& ref_ensemble = _receptor._vregion[loopregion]; + AttractMcop& ref_ensemble = _receptor._vregion[loopregion]; std::vector& ref_weights = _receptor._weights[loopregion]; assert( ref_ensemble.size() == ref_weights.size()); @@ -190,24 +277,24 @@ dbl McopForceField::Function(const Vdouble & v) dbl& weight = ref_weights[copynb]; AttractRigidbody& copy = ref_ensemble[copynb]; - AttractPairList cpl ( lig._main, copy, _cutoff ); + AttractPairList cpl ( lig._core, copy, _cutoff ); std::vector copyforce(copy.Size()); - std::vector mainforce(lig._main.Size()); + std::vector coreforce(lig._core.Size()); -// dbl e = _ff.nonbon8( lig._main, _receptor._vregion[loopregion][copy] , cpl ); - dbl e = _ff.nonbon8_forces(lig._main, copy, cpl, mainforce, copyforce); +// dbl e = _ff.nonbon8( lig._core, _receptor._vregion[loopregion][copy] , cpl ); + dbl e = _ff.nonbon8_forces(lig._core, copy, cpl, coreforce, copyforce); enercopy += e * weight;//lig._weights[loopregion][copy]; //multiply forces by copy weight: for(uint i=0; i & weights = _receptor._weights[i]; for(uint j=0; j Date: Tue, 5 Apr 2016 17:29:54 +0200 Subject: [PATCH 03/90] Created bindings for Mcop class and AttractMcop subclass. --- bindings/_ptools.pyx | 2 + bindings/mcopff.pyx | 164 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+) create mode 100644 bindings/mcopff.pyx diff --git a/bindings/_ptools.pyx b/bindings/_ptools.pyx index d9a86e0..87c15da 100644 --- a/bindings/_ptools.pyx +++ b/bindings/_ptools.pyx @@ -15,3 +15,5 @@ include "rmsd.pyx" include "version.pyx" include "coordsarray.pyx" include "superpose.pyx" +include "mcopff.pyx" +include "multicopy.py" diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx new file mode 100644 index 0000000..892ae7e --- /dev/null +++ b/bindings/mcopff.pyx @@ -0,0 +1,164 @@ +from cython.operator cimport dereference as deref +from libcpp.string cimport string + +cdef extern from "" namespace "std": + cdef cppclass stringstream: + stringstream() + string str() + void str(string &s) + +cdef extern from "mcopff.h" namespace "PTools": + cdef cppclass CppMcop "PTools::Mcop": + CppMcop() + CppMcop(string&) except+ + CppMcop(CppMcop&) + CppRigidbody getCopy(unsigned int) + CppRigidbody operator[](unsigned int) + unsigned int size() + void addCopy(CppRigidbody&) + cdef cppclass CppAttractMcop "PTools::AttractMcop": + CppAttractMcop() + CppAttractMcop(string&) except+ + CppAttractMcop(CppMcop&) + CppAttractMcop(CppAttractMcop&) + CppAttractRigidbody getCopy(unsigned int) + CppAttractRigidbody operator[](unsigned int) + unsigned int size() + void addCopy(CppAttractRigidbody&) + + +cdef class Mcop: + cdef CppMcop* thisptr + + def __cinit__(self, filename=''): + cdef CppMcop* oldptr + cdef Mcop oldmcop + cdef char* name + cdef string *cppname + cdef CppMcop* newmcop + + if isinstance(filename, str): + if filename == '': + self.thisptr = new CppMcop() + else: + # there is a filename, loading the pdb file + name = filename + cppname = new string(name) + newmcop = new CppMcop(deref(cppname)) + del cppname + self.thisptr = newmcop + + elif isinstance(filename, Mcop): + oldmcop = filename + oldptr = (oldmcop.thisptr) + self.thisptr = new CppMcop(deref(oldptr)) + if not self.thisptr: + print "FATAL: this should never happen" + + else: + raise RuntimeError("invalid argument in Mcop()") + + def __dealloc__(self): + if self.thisptr: + del self.thisptr + self.thisptr = 0 + + def getCopy(self, unsigned int i): + cdef CppRigidbody cpp_copy = self.thisptr.getCopy(i) + cdef Rigidbody cop = Rigidbody() + cdef CppRigidbody* new_cop = new CppRigidbody(cpp_copy) + del cop.thisptr + cop.thisptr = new_cop + return cop + + def __getitem__(self,unsigned int i): + cdef CppRigidbody cpp_copy = self.thisptr.getCopy(i) + cdef Rigidbody cop = Rigidbody() + cdef CppRigidbody* new_cop = new CppRigidbody(cpp_copy) + del cop.thisptr + cop.thisptr = new_cop + return cop + + def __len__(self): + return self.thisptr.size() + + def addCopy(self, Rigidbody rigid): + self.thisptr.addCopy(deref(rigid.thisptr)) + + +cdef class AttractMcop (Mcop): + cdef CppAttractMcop* thisptr2 + + def __cinit__(self, filename=''): + + # first deallocate the previously allocated Mcop + del self.thisptr + self.thisptr = new CppMcop() + + cdef CppAttractMcop* oldptr + cdef CppMcop* oldmcop_ptr + cdef AttractMcop oldattractmcop + cdef Mcop oldmcop + cdef char* name + cdef string *cppname + cdef CppAttractMcop* newattractmcop + + if isinstance(filename, str): + if filename == '': + self.thisptr2 = new CppAttractMcop() + else: + # there is a filename, laoding the pdb file + + name = filename + cppname = new string(name) + newattractmcop = new CppAttractMcop(deref(cppname)) + del cppname + self.thisptr2 = newattractmcop + + elif isinstance(filename, AttractMcop): + oldattractmcop = filename + oldptr = (oldattractmcop.thisptr2) + self.thisptr2 = new CppAttractMcop(deref(oldptr)) + if not self.thisptr2: + print "FATAL: this should never happen" + + elif isinstance(filename, Mcop): + + oldmcop = filename + oldmcop_ptr = (oldmcop.thisptr) + self.thisptr2 = new CppAttractMcop(deref(oldmcop_ptr)) + if not self.thisptr2: + print "FATAL; this should never happen" + + else: + raise RuntimeError("invalid argument in Mcop()") + + def __dealloc__(self): + if self.thisptr: + del self.thisptr + self.thisptr = 0 + if self.thisptr2: + del self.thisptr2 + self.thisptr2 = 0 + + def getCopy(self, unsigned int i): + cdef CppAttractRigidbody cpp_copy = self.thisptr2.getCopy(i) + cdef AttractRigidbody cop = AttractRigidbody() + cdef CppAttractRigidbody* new_cop = new CppAttractRigidbody(cpp_copy) + del cop.thisptr + cop.thisptr = new_cop + return cop + + def __getitem__(self,unsigned int i): + cdef CppAttractRigidbody cpp_copy = self.thisptr2.getCopy(i) + cdef AttractRigidbody cop = AttractRigidbody() + cdef CppAttractRigidbody* new_cop = new CppAttractRigidbody(cpp_copy) + del cop.thisptr + cop.thisptr = new_cop + return cop + + def addCopy(self, AttractRigidbody attrigid): + self.thisptr2.addCopy(deref(attrigid.thisptr)) + + def __len__(self): + return self.thisptr2.size() From 9ad5c5d49384042dbca475efde94e6e4697fab74 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 5 Apr 2016 17:33:36 +0200 Subject: [PATCH 04/90] Added no argument constructor to attractrigidbody.pyx --- bindings/attractrigidbody.pyx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/bindings/attractrigidbody.pyx b/bindings/attractrigidbody.pyx index 13942e1..3ebfdb0 100644 --- a/bindings/attractrigidbody.pyx +++ b/bindings/attractrigidbody.pyx @@ -46,9 +46,8 @@ cdef CppAttractRigidbody* _getAttractRigidbody_from_py_name(pyname): cdef class AttractRigidbody (Rigidbody) : - # cdef CppAttractRigidbody* thisptr - def __cinit__(self, arg): + def __cinit__(self, arg=''): # first deallocate the previously allocated Rigidbody del self.thisptr @@ -60,8 +59,12 @@ cdef class AttractRigidbody (Rigidbody) : self.thisptr = new CppAttractRigidbody(deref(rigidbodyptr)) return elif isinstance(arg, str): - self.thisptr = _getAttractRigidbody_from_py_name(arg) - return + if arg == '': + self.thisptr = new CppAttractRigidbody() + return + else: + self.thisptr = _getAttractRigidbody_from_py_name(arg) + return elif isinstance(arg, AttractRigidbody): oldrigidbody = arg oldrigidbody_ptr = oldrigidbody.thisptr @@ -145,4 +148,4 @@ cdef class AttractRigidbody (Rigidbody) : del ret.thisptr cdef CppAtomSelection new_sel = self.thisptr.CA() ret.thisptr = new CppAtomSelection(new_sel) - return ret \ No newline at end of file + return ret From a2b69acce5b4e764bc24bdfefecca36ca27610d1 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 5 Apr 2016 17:35:46 +0200 Subject: [PATCH 05/90] Fixed cython constructor for atomselection. --- bindings/atomselection.pyx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bindings/atomselection.pyx b/bindings/atomselection.pyx index 63f82d6..4b654e6 100644 --- a/bindings/atomselection.pyx +++ b/bindings/atomselection.pyx @@ -6,7 +6,7 @@ cdef extern from "atomselection.h" namespace "PTools": cdef cppclass CppAtomSelection "PTools::AtomSelection": CppAtomSelection() CppAtomSelection(CppAtomSelection&) - CppAtomSelection(CppRigidbody) + CppAtomSelection(CppRigidbody&) unsigned int Size() void SetRigid(CppRigidbody&) @@ -38,19 +38,20 @@ cdef class AtomSelection: self.thisptr = new CppAtomSelection() return - if isinstance(AtomSelection, arg): + elif isinstance(arg, AtomSelection): atsel = arg atselptr = atsel.thisptr self.thisptr = new CppAtomSelection(deref(atselptr)) return - if isinstance(Rigidbody, arg): + elif isinstance(arg, Rigidbody): rig = arg rigptr = rig.thisptr self.pyRigid = arg self.thisptr = new CppAtomSelection(deref(rigptr)) - raise RuntimeError("cannot reach here") + else: + raise RuntimeError("cannot reach here") def __dealloc__(self): if self.thisptr: @@ -95,4 +96,4 @@ cdef class AtomSelection: def SetRigid(self, Rigidbody r): self.pyRigid = r # to increase the refcount of r, preventing bad things if r is destroyed - self.thisptr.SetRigid(deref(r.thisptr)) \ No newline at end of file + self.thisptr.SetRigid(deref(r.thisptr)) From 1fc8b14ebd304139b96ba34029975f4f194f4c48 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 5 Apr 2016 17:36:49 +0200 Subject: [PATCH 06/90] Modified reduce.py to accept mcop option. --- PyAttract/reduce.py | 53 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/PyAttract/reduce.py b/PyAttract/reduce.py index 7a0df5d..232a9f5 100755 --- a/PyAttract/reduce.py +++ b/PyAttract/reduce.py @@ -6,6 +6,14 @@ import os from optparse import OptionParser +# ---- Functions ---- # +def is_digit_array(s): + for digit in s: + if not digit.isdigit(): + return False + return True +# -- End of Functions -- # + usage = "%prog --ff force_field [--dna] [--cgopt] [--dgrid 1.5] [--allow_missing] atomic_file.pdb > reduced_file.red" version = "%prog 1.0" parser = OptionParser(usage) @@ -25,6 +33,9 @@ parser.add_option("--allow_missing", action="store_true", dest="warning",default=False, help="don't stop program if atoms are missing, only display a warning on stderr") +# --mcop option: create multicopy reduced protein +parser.add_option("--mcop", dest="regions", default=False, help="positions of the multicopy region(s) separated by ':' (eg. --mcop 12-21:45-48)\n If entire protein, enter ':' (eg. --mcop :") + (options, args) = parser.parse_args() @@ -38,6 +49,8 @@ print "thispath is: ", thispath # define other parameter files + +# Check force field option (--ff) cmd_options=[] if options.ffversion not in ["attract1","attract2","scorpion"]: sys.stderr.write ("Error: please choose one of the following CG force field: attract1, attract2 or scorpion\n") @@ -47,12 +60,46 @@ cmd_options.append("--allow_missing") else: sys.stderr.write("Warning: allow_missing option not supported by SCORPION force field\n") + + +# Check multicopy option (--mcop) +if options.regions: + if options.regions.endswith('.pdb'): + cmd_options.append('--mcop .pdb') + args.insert(0,options.regions) + elif options.regions == ':': + cmd_options.append("--mcop :") + else: + pos = options.regions.replace(':','-').split('-') + reg = options.regions.split(':') + num_positions = len(pos) + num_regions = len(reg) + + if num_positions != 2*num_regions or not is_digit_array(pos): + sys.stderr.write ("Error: the --mcop input format is incorrect. \n Separate start and end of a region with '-'. \n Separate different regions with ':' \n (Example for 2 regions : --mcop 12-21:45-48)\n Or enter the files containing core, and region copies.\n (Example for 2 regions : --mcop core.pdb region1.pdb region2.pdb)\n") + sys.exit(1) + + starts = [] + ends = [] + for i in xrange(0,len(reg)): + starts.append(min(map(int, reg[i].split('-')))) + ends.append(max(map(int, reg[i].split('-')))) + starts, ends = zip(*sorted(zip(starts,ends))) + + for i in xrange(0,len(reg)-1): + if ends[i] >= starts[i+1]: + sys.stderr.write("Error: the --mcop input has overlapping regions.\n") + sys.exit(1) + + cmd_options.append("--mcop %s"%options.regions) + +#Launch the selected force field version. if options.ffversion=="scorpion": if options.optimizecharges: cmd_options.append("--cgopt") if options.delgrid: cmd_options.append("--dgrid %f"%options.delgrid) - cmd_options.append(args[0]) + cmd_options.extend(args) prgname = os.path.join(thispath, "reduce_scorpion.py") os.system(prgname + " " + " ".join(cmd_options)) @@ -62,13 +109,13 @@ cmd_options.append("--dna") else: cmd_options.append("--prot") - cmd_options.append(args[0]) + cmd_options.extend(args) prgname = os.path.join(thispath, "reduce_attract1.py") os.system(prgname + " %s"%" ".join(cmd_options)) if options.ffversion=="attract2": - cmd_options.append(args[0]) + cmd_options.extend(args) prgname = os.path.join(thispath, "reduce_attract2.py") os.system(prgname + " %s"%" ".join(cmd_options)) From adc12baeb007f074184394c7f43c7570fcbf577c Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 5 Apr 2016 17:38:55 +0200 Subject: [PATCH 07/90] Created python functions useful for reduce's mcop option. Functions are added to Ptools module. --- bindings/multicopy.py | 265 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 265 insertions(+) create mode 100644 bindings/multicopy.py diff --git a/bindings/multicopy.py b/bindings/multicopy.py new file mode 100644 index 0000000..ef66f36 --- /dev/null +++ b/bindings/multicopy.py @@ -0,0 +1,265 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +from ptools import * +import sys + + +def multicopy(models_pdb, mcop_arg): + """ + Takes the filename of a pdb containing multiple models and the string of + the mcop argument indicating the region positions. + + Returns a single core of the protein (Rigidbody object) and all the copies + of the region(s) (list of Mcop objects where each Mcop object contains the + copies of a region which are Rigidbody) with respect to the mcop argument. + + ex: core, region_copies = ("NMRmodels.pdb", "23-44:66-79") + + The mcop argument uses the following format: + - If there are different regions, they are separated by ':' + - The start and end position of a region are separated by '-' + - To fetch copies of the whole protein, the mcop argument is ':' + + """ + starts, ends = convert_mcop_argument(mcop_arg) + models = Mcop(models_pdb) + cores, region_copies = extract_regions(models, starts, ends) + if mcop_arg == ':': + core = Rigidbody() + moved_copies = region_copies + else: + core = find_core(cores) + matrices = get_align_matrices(cores, core) + moved_copies = [] + for i in xrange(0,len(region_copies)): + moved_copies.append(apply_matrices(region_copies[i], matrices)) + return core, moved_copies + + +def convert_mcop_argument(arg): + """ + Takes the mcop arguement (string). + + Returns start and end positions (list of int) of the region(s). + + ex: starts, ends = convert_mcop_argument("23-44:66-79") + - starts variable contains [23, 66] + - ends variable contains [66, 79] + + Note : if the argument is ':', returns (-1,) and (-1,). This case is for + fetching copies of the whole protein. See extract_regions() + """ + # if whole protein + if arg == ':': + return ((-1,), (-1,)) + else: + reg = arg.split(':') + starts = [] + ends = [] + for i in xrange(0,len(reg)): + starts.append(min(map(int, reg[i].split('-')))) + ends.append(max(map(int, reg[i].split('-')))) + starts, ends = zip(*sorted(zip(starts,ends))) + return starts, ends + + +def extract_regions(models, starts, ends): + """ + Takes different models of a protein (Mcop object), start + position(s) of region(s) (list int), and end position(s) of + region(s) (list int). + + Returns the different cores of the protein (Mcop object) + and all the copies of the region(s) (list of Mcop objects where each Mcop + object contains the copies of a region) with respect to the start and + end positions. + + ex: cores, region_copies = extract_regions(models, starts, ends) + + Note: To fetch copies of the whole protein, starts and ends must both + contain -1 (int) at index 0. + + Note: a single core can then be selected from the returned multiple cores + thanks to the find_core() function. + """ + mcop = [] + cores = Mcop() + # loop through models + for i in xrange(0,len(models)): + reg = [] + model = models[i] + # selecting first region + reg.append(model.SelectResRange(starts[0], ends[0])) + fused_regions = reg[0] + if i == 0: + mcop.append(Mcop()) + #Creating and adding copy of region + copy = reg[0] + mcop[0].addCopy(copy.CreateRigid()) + for j in xrange(1, len(starts)): + #adding other region + if i == 0: + mcop.append(Mcop()) + #Creating and adding copy of region + reg.append(model.SelectResRange(starts[j], ends[j])) + copy = reg[j] + mcop[j].addCopy(copy.CreateRigid()) + fused_regions = copy | fused_regions + #Creating and Adding core (inverse of regions) + core = AtomSelection(model) + core = core & ~fused_regions + core = core.CreateRigid() + cores.addCopy(core) + # if whole protein + if starts[0] == -1 and ends[0] == -1: + temp = cores + cores = mcop[0] + mcop[0] = temp + return cores, mcop + + +def write_region_copies(filename, models, append=False): + """ + Writes a list of Mcop objects in a pdb file where each written model is + delimited by MODEL i j and ENDMDL i j. (i = region number, j = copy number) + + Takes an output filename (string), and a list of Mcop objects. + + Default arguments : + - append option (False if overide, True if append), default value = False + """ + if append: + f = open(filename, 'a') + else: + f = open(filename, 'w') + # iterate through number of regions + for i in xrange(0, len(models)): + # iterate through number of regions copies + for j in xrange(0,len(models[i])): + f.write('MODEL ' + str(i+1) + ' ' + str(j+1) + '\n') + f.write(str(models[i][j]) + '\n') + f.write('ENDMDL ' + str(i+1) + ' ' + str(j+1) + '\n') + f.close() + + +def write_single_model(filename, model, append=False, model_index=1): + """ + Writes a single Rigidbody object into a pdb file. The written model is + delimited by MODEL i and ENDMDL i (i = index value of the model). + + Takes an output filename (string), and a Rigidbody object. + + Default arguments : + - "append": False if overide file, True if append file, default value = False + - "model_index": index value of the written model (int), default value = 1 + """ + if append: + f = open(filename, 'a') + else: + f = open(filename, 'w') + f.write('MODEL ' + str(model_index) + '\n') + f.write(str(model) + '\n') + f.write('ENDMDL ' + str(model_index) + '\n') + f.close() + + +def write_mcop(filename, core, region_copies): + """ + Writes a multicopy pdb file. This type of file uses the following format : + The first model is the core of the protein and is delimited by MODEL 0 and + ENDMDL 0. + + The following models are the copies of the defined variable region(s). + These are delimited by MODEL i j and ENDMDL i j + (i = region number, j = copy number). + + Takes an output filename (string), the protein core (Rigidbody object), + and the region copies (list of Mcop objects). + """ + if len(core) > 0: + write_single_model(filename, core, model_index=0) + write_region_copies(filename, region_copies, append=True) + + +def rmsd_sums(cores): + """ + Does pairwise superpositions of proteins, and for each protein, calculates + the sum of the RMSD obtained from all of its superpositions. + + Takes a list of proteins, generally protein cores + (list of Rigidbody objects). + + Returns a list of the corresponding RMSD sums (list of int). + """ + rmsd_sums = [0 for x in xrange(0,len(cores))] + for i in xrange(0, len(cores)): + core1 = cores[i] + for j in xrange(i+1,len(cores)): + core2 = cores[j] + sup = superpose(core1.CA().CreateRigid(), core2.CA().CreateRigid()) + rmsd_sums[i] += sup.rmsd + rmsd_sums[j] += sup.rmsd + return rmsd_sums + + +def find_core(cores): + """ + From a list of proteins, returns the protein with the smallest RMSD sum + (with pairwise superpositions using the rmsd_sums function). This + is generally used to select the protein core from a list of potential cores. + + Takes of a list of Rigidbody objects. + + Returns a single Rigidbody object. + """ + sys.stderr.write("\nFinding core:\n") + sums = rmsd_sums(cores) + core_index = sums.index(min(sums)) + for i,sum in enumerate(sums): + sys.stderr.write("Core candidate %i: " %(i+1)) + sys.stderr.write("mean RMSD %f A \n" %(sum/(len(sums)-1))) + sys.stderr.write("\nSelected core candiate %i: mean RMSD %f A\n"\ + %(core_index+1, sums[core_index]/(len(sums)-1))) + return cores[core_index] + + +def get_align_matrices(cores, core): + """ + Finds the displacement matrices (translation and rotation) of + superpositions of a list of proteins (generally counterselected + protein cores) over one protein (generally the selected protein core). + These matrices are usefull to then move copies of other regions of the + protein (they generally correspond to, but are not present in, the + conterselected protein cores) to better position them onto the selected + protein core. + + Takes a Mcop objects, and a single Rigidbody objects. + Returns a list of Matrix objects corresponding to the entered list of + Rigidbody objects. + """ + matrices = [] + for i in xrange(0, len(cores)): + mobile_core = cores[i] + sup = superpose(core, mobile_core) + matrices.append(sup.matrix) + return matrices + + +def apply_matrices(region_copies, matrices): + """ + Modifies the coordinates of a list of Mcop objects according to a list of + Matrix objects. This function is usually used after obtaining the matrices + from the get_align_matrices function. + + Takes a series of region copies (list of Mcop objects) + Returns a series of moved region copies (list of Mcop ojects with + new cordinates) + + """ + moved_copies = Mcop() + for i in xrange(0, len(region_copies)): + cop = region_copies[i] + cop.ApplyMatrix(matrices[i]) + moved_copies.addCopy(cop) + return moved_copies + From 9e8ea0f188cd5c626d59dece22cc06da0bc521f1 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 5 Apr 2016 17:45:25 +0200 Subject: [PATCH 08/90] Modified the python reduce file of all forcefields to code the mcop option. Can now create reduced pdb files in the mcop format. --- PyAttract/reduce_attract1.py | 217 ++++++++++++--------- PyAttract/reduce_attract2.py | 190 +++++++++++-------- PyAttract/reduce_scorpion.py | 352 ++++++++++++++++++++--------------- 3 files changed, 447 insertions(+), 312 deletions(-) diff --git a/PyAttract/reduce_attract1.py b/PyAttract/reduce_attract1.py index 6e9a04a..dbb36ee 100755 --- a/PyAttract/reduce_attract1.py +++ b/PyAttract/reduce_attract1.py @@ -31,6 +31,9 @@ parser.add_option("--allow_missing", action="store_true", dest="warning",default=False, help="don't stop program if atoms are missing, only display a warning on stderr") +# --mcop option: create multicopy reduced protein +parser.add_option("--mcop", dest="regions", default=False, help="positions of the multicopy region(s) separated by ';' (eg. 12-21;45-48)") + (options, args) = parser.parse_args() @@ -297,91 +300,133 @@ def Show(self): #========================================================== # load atomic pdb file into Rigidbody object #========================================================== -allAtom=Rigidbody(atomicName) -sys.stderr.write("Load atomic file %s with %d atoms \n" %(atomicName, len(allAtom))) - -#extract all 'atoms' objects -atomList=[] -for i in xrange(len(allAtom)): - atom = allAtom.CopyAtom(i) - # look for residue or base type conversion - resName = atom.residType - if resName in resConv.keys(): - atom.residType = resConv[resName] - # look for atom type conversion - atomTag = atom.residType + '-' + atom.atomType - if atomTag in atomConv.keys(): - atomName = atomConv[atomTag].split('-')[1] - atom.atomType = atomName - atomList.append(atom) - -#count residues -residueTagList=[] -coarseResList=[] -for atom in atomList: - resName = atom.residType - # create a unique identifier for every residue - # resTag is for instance "LEU-296-A" - resTag = resName + '-'+ str(atom.residId) + '-' + atom.chainId - if resTag not in residueTagList: - if resBeadAtomModel.has_key(resName): - residueTagList.append(resTag) - # add a pattern residue to the list of coarse residues for the protein - # beware of the hugly list copy: use copy.deepcopy() ! - coarseResList.append(copy.deepcopy(resBeadAtomModel[resName])) - else: - sys.stderr.write("WARNING: residue %s is unknown the residues <-> beads <-> atoms list !!\n" %(resName)) - sys.stderr.write(" : residue %s will not be reduced into coarse grain\n" %(resName)) -sys.stderr.write("Number of residues: %i\n" %(len(residueTagList))) -#========================================================== -# iterate through all atoms and residues to fill beads -#========================================================== -sys.stderr.write("Reading all atoms and filling beads:\n") -for atom in atomList: - #resTag is like "LEU-296-A" - resTag = atom.residType + '-' + str(atom.residId) + '-' + atom.chainId - if resTag in residueTagList: - id = residueTagList.index(resTag) - coarseResList[id].FillAtom(atom.atomType, atom.coords.x, atom.coords.y, atom.coords.z) -#========================================================== -# reduce beads -#========================================================== -coarsegrainPdb = "" # complete coarse grain (reduced) pdb file -atomCnt = 0 # atom counter -sys.stderr.write("Coarse graining:\n") -for i in range(len(residueTagList)): - tag = residueTagList[i].split('-') - resName = tag[0] - resId = int(tag[1]) - coarseRes = coarseResList[i].Reduce(resName, resId) - for bead in coarseRes: - coord = bead[0] - atomName = bead[1] - atomTypeId = bead[2] - if atomTypeId in beadChargeDic: - atomCharge = beadChargeDic[atomTypeId] - else: - sys.stderr.write("WARNING: cannot find charge of bead %s %2d in %s \n" %(atomName, atomTypeId, ffName)) - sys.stderr.write(" : set default charge to 0.0\n") - atomCharge = 0.0 - prop = Atomproperty() - prop.atomType = atomName - atomCnt += 1 - prop.atomId = atomCnt - prop.residId = resId - prop.residType = resName - prop.chainId = ' ' - extra = ('%5i%8.3f%2i%2i') %(atomTypeId,atomCharge,0,0) - prop.extra = extra - newAtom = Atom(prop, coord) - coarsegrainPdb += newAtom.ToPdbString() + "\n" - -#========================================================== -# output coarse grain (reduced) pdb file -#========================================================== -sys.stdout.write("HEADER ATTRACT1 REDUCED PDB FILE\n") -sys.stdout.write(coarsegrainPdb) -sys.stderr.write("Coarse grain (reduced) output") -sys.stderr.write(": %d beads \n" %(atomCnt)) +models = [] +if options.regions: +# Preparing pdb multicopy models + if options.regions.endswith('.pdb'): + core = Rigidbody(args[0]) + region_copies = [] + for i in xrange(1, len(args)): + region_copies.append(Mcop(args[i])) + models.append(core) + models.append(region_copies) + write_mcop('_mcop.pdb', core, region_copies) + else: + core, region_copies = multicopy(atomicName, options.regions) + write_mcop('_mcop.pdb', core, region_copies) + models.append(core) + models.append(region_copies) +else: + models.append(Rigidbody(atomicName)) + sys.stderr.write("Load atomic file %s with %d atoms \n" %(atomicName, len(models[0]))) + +def reduce_model(allAtom): + #extract all 'atoms' objects + atomList=[] + for i in xrange(len(allAtom)): + atom = allAtom.CopyAtom(i) + # look for residue or base type conversion + resName = atom.residType + if resName in resConv.keys(): + atom.residType = resConv[resName] + # look for atom type conversion + atomTag = atom.residType + '-' + atom.atomType + if atomTag in atomConv.keys(): + atomName = atomConv[atomTag].split('-')[1] + atom.atomType = atomName + atomList.append(atom) + + #count residues + residueTagList=[] + coarseResList=[] + for atom in atomList: + resName = atom.residType + # create a unique identifier for every residue + # resTag is for instance "LEU-296-A" + resTag = resName + '-'+ str(atom.residId) + '-' + atom.chainId + if resTag not in residueTagList: + if resBeadAtomModel.has_key(resName): + residueTagList.append(resTag) + # add a pattern residue to the list of coarse residues for the protein + # beware of the hugly list copy: use copy.deepcopy() ! + coarseResList.append(copy.deepcopy(resBeadAtomModel[resName])) + else: + sys.stderr.write("WARNING: residue %s is unknown the residues <-> beads <-> atoms list !!\n" %(resName)) + sys.stderr.write(" : residue %s will not be reduced into coarse grain\n" %(resName)) + sys.stderr.write("Number of residues: %i\n" %(len(residueTagList))) + + #========================================================== + # iterate through all atoms and residues to fill beads + #========================================================== + sys.stderr.write("Reading all atoms and filling beads:\n") + for atom in atomList: + #resTag is like "LEU-296-A" + resTag = atom.residType + '-' + str(atom.residId) + '-' + atom.chainId + if resTag in residueTagList: + id = residueTagList.index(resTag) + coarseResList[id].FillAtom(atom.atomType, atom.coords.x, atom.coords.y, atom.coords.z) + #========================================================== + # reduce beads + #========================================================== + coarsegrainPdb = "" # complete coarse grain (reduced) pdb file + atomCnt = 0 # atom counter + sys.stderr.write("Coarse graining:\n") + for i in range(len(residueTagList)): + tag = residueTagList[i].split('-') + resName = tag[0] + resId = int(tag[1]) + coarseRes = coarseResList[i].Reduce(resName, resId) + for bead in coarseRes: + coord = bead[0] + atomName = bead[1] + atomTypeId = bead[2] + if atomTypeId in beadChargeDic: + atomCharge = beadChargeDic[atomTypeId] + else: + sys.stderr.write("WARNING: cannot find charge of bead %s %2d in %s \n" %(atomName, atomTypeId, ffName)) + sys.stderr.write(" : set default charge to 0.0\n") + atomCharge = 0.0 + prop = Atomproperty() + prop.atomType = atomName + atomCnt += 1 + prop.atomId = atomCnt + prop.residId = resId + prop.residType = resName + prop.chainId = ' ' + extra = ('%5i%8.3f%2i%2i') %(atomTypeId,atomCharge,0,0) + prop.extra = extra + newAtom = Atom(prop, coord) + coarsegrainPdb += newAtom.ToPdbString() + "\n" + + #========================================================== + # output coarse grain (reduced) pdb file + #========================================================== + sys.stdout.write(coarsegrainPdb) + sys.stderr.write("Coarse grain (reduced) output") + sys.stderr.write(": %d beads \n" %(atomCnt)) + +# iterate through all models (important for multicopy option) and write reduced pdb +print "HEADER ATTRACT1 REDUCED PDB FILE" +# iterate through 'models' varialbe which contains max 2 elements. +# The fist element of the models list is a Rigidbody (the core in the mcop case, and the whole protein in the normal case) +# In the mcop case, there is a second element, which is the region_copies list (a list of Mcop objects). +for i in xrange(0,len(models)): + if i == 0 and options.regions != ':': + sys.stderr.write("\nCore:\n") + print 'MODEL 0' + reduce_model(models[i]) + print 'ENDMDL 0' + if i >= 1: + # iterate through number of regions + for j in xrange(0, len(models[1])): + # iterate through number of regions copies + for k in xrange(0,len(models[1][j])): + sys.stderr.write("\nRegion %i Copy %i:\n" %(j+1, k+1)) + print 'MODEL ' + str(j+1) + ' ' + str(k+1) + reduce_model(models[1][j][k]) + print 'ENDMDL ' + str(j+1) + ' ' + str(k+1) + sys.stderr.write("\n\nSummary:\n") + for j in xrange(0, len(models[1])): + sys.stderr.write("Region %i: %i copies\n" %(j+1,len(models[1][j]))) diff --git a/PyAttract/reduce_attract2.py b/PyAttract/reduce_attract2.py index 5124660..7e8adc7 100755 --- a/PyAttract/reduce_attract2.py +++ b/PyAttract/reduce_attract2.py @@ -17,6 +17,9 @@ parser.add_option("--allow_missing", dest="ignoremissing", action="store_true", default=False, help="ignore missing heavy atoms (which will result in missing beads)" ) +# --mcop option: create multicopy reduced protein +parser.add_option("--mcop", dest="regions", default=False, help="positions of the multicopy region(s) separated by ';' (eg. 12-21;45-48)") + (options, args) = parser.parse_args() @@ -138,77 +141,118 @@ def create(self): +models = [] +if options.regions: +# Preparing pdb multicopy models + if options.regions.endswith('.pdb'): + core = Rigidbody(args[0]) + region_copies = [] + for i in xrange(1, len(args)): + region_copies.append(Mcop(args[i])) + models.append(core) + models.append(region_copies) + write_mcop('new_mcop.pdb', core, region_copies) + else: + core, region_copies = multicopy(args[0], options.regions) + write_mcop('new_mcop.pdb', core, region_copies) + models.append(core) + models.append(region_copies) +else: + models.append(Rigidbody(sys.argv[1])) + sys.stderr.write("Number of atoms:%i \n" %len(models[0]) ) + +def reduce_model(allAtom): + #extract all 'atoms' objects + atoms=[] + for i in xrange(len(allAtom)): + atoms.append(allAtom.CopyAtom(i)) + + + + #count residues: + residuMap={} + residulist=[] + + # chain id for the reduced file: + outChainId = atoms[0].chainId + + for at in atoms: + #fix for incorrect pdb: append a chainId when it's missing + if at.chainId=='': + at.chainId = 'A' + residueIdentifier = at.residType + str(at.chainId) + str(at.residId) + #residueIdentifier is like "LEUA296" + residuMap.setdefault(residueIdentifier, []).append(at) + if residueIdentifier not in residulist: + residulist.append(residueIdentifier) + + sys.stderr.write("Number of residues: %i\n" %(len(residuMap))) + sys.stderr.write("Start atom of each residue:\n") + orderedresid=[residuMap[i] for i in residulist ] + startatoms=[lat[0].atomId for lat in orderedresid ] + out = "" + for statom in startatoms: + out+=(str(statom))+" " + sys.stderr.write(out+"\n") + + + #iterates through all the residues and create reduced beads: + + totAtoms=0 + + index = 0 + for residKey, atomList in zip(residulist,orderedresid): + residType=residKey[:3] + if (residType)=="HIE": residType="HIS" #fix for an amber output file + #print "key:", residKey + residNumber=int(residKey[4:]) + #print "reducing residue %s of type %s" % (residKey, residType) + correspList=beadCorresp[residType] + #print correspList + for correspUnit in correspList: + atomTypeName=correspUnit[0] + lstToReduce=correspUnit[1] + atomTypeNumber=correspUnit[2] + atomCharge=correspUnit[3] + beadcreator=BeadCreator(atomTypeName,atomTypeNumber, atomCharge, lstToReduce, outChainId ) + for atom in atomList: + beadcreator.submit(atom) + try: + bead = beadcreator.create() + except IncompleteBead: + sys.stderr.write("The bead %i of residue %s is incomplete. Please check your pdb!\n"\ + %(totAtoms+1,residKey) ) + if not options.ignoremissing: raise + totAtoms+=1 + #now we must modify the bead: change the residue type and set the "extra" field correctly + bead.residType = residType + extra = ('%5i'+'%8.3f'+'%2i'*2) %(atomTypeNumber,atomCharge,0, 0) + bead.extra = extra + bead.atomId = totAtoms + bead.residId = residNumber + print bead.ToPdbString() + +# iterate through all models (important for multicopy option) and write reduced pdb +print "HEADER ATTRACT2 REDUCED PDB FILE" +# iterate through 'models' varialbe which contains max 2 elements. +# The fist element of the models list is a Rigidbody (the core in the mcop case, and the whole protein in the normal case) +# In the mcop case, there is a second element, which is the region_copies list (a list of Mcop objects). +for i in xrange(0,len(models)): + if i == 0 and options.regions != ':': + sys.stderr.write("\nCore:\n") + print 'MODEL 0' + reduce_model(models[i]) + print 'ENDMDL 0' + if i >= 1: + # iterate through number of regions + for j in xrange(0, len(models[1])): + # iterate through number of regions copies + for k in xrange(0,len(models[1][j])): + sys.stderr.write("\nRegion %i Copy %i:\n" %(j+1, k+1)) + print 'MODEL ' + str(j+1) + ' ' + str(k+1) + reduce_model(models[1][j][k]) + print 'ENDMDL ' + str(j+1) + ' ' + str(k+1) + sys.stderr.write("\n\nSummary:\n") + for j in xrange(0, len(models[1])): + sys.stderr.write("Region %i: %i copies\n" %(j+1,len(models[1][j]))) -allAtom=Rigidbody(sys.argv[1]) -sys.stderr.write("Number of atoms:%i \n" %len(allAtom) ) - -#extract all 'atoms' objects -atoms=[] -for i in xrange(len(allAtom)): - atoms.append(allAtom.CopyAtom(i)) - - - -#count residues: -residuMap={} -residulist=[] - -# chain id for the reduced file: -outChainId = atoms[0].chainId - -for at in atoms: - #fix for incorrect pdb: append a chainId when it's missing - if at.chainId=='': - at.chainId = 'A' - residueIdentifier = at.residType + str(at.chainId) + str(at.residId) - #residueIdentifier is like "LEUA296" - residuMap.setdefault(residueIdentifier, []).append(at) - if residueIdentifier not in residulist: - residulist.append(residueIdentifier) - -sys.stderr.write("Number of residues: %i\n" %(len(residuMap))) -sys.stderr.write("Start atom of each residue:\n") -orderedresid=[residuMap[i] for i in residulist ] -startatoms=[lat[0].atomId for lat in orderedresid ] -out = "" -for statom in startatoms: - out+=(str(statom))+" " -sys.stderr.write(out+"\n") - - -#iterates through all the residues and create reduced beads: - -totAtoms=0 - -print "HEADER ATTRACT2 REDUCED PDB FILE" -index = 0 -for residKey, atomList in zip(residulist,orderedresid): - residType=residKey[:3] - if (residType)=="HIE": residType="HIS" #fix for an amber output file - #print "key:", residKey - residNumber=int(residKey[4:]) - #print "reducing residue %s of type %s" % (residKey, residType) - correspList=beadCorresp[residType] - #print correspList - for correspUnit in correspList: - atomTypeName=correspUnit[0] - lstToReduce=correspUnit[1] - atomTypeNumber=correspUnit[2] - atomCharge=correspUnit[3] - beadcreator=BeadCreator(atomTypeName,atomTypeNumber, atomCharge, lstToReduce, outChainId ) - for atom in atomList: - beadcreator.submit(atom) - try: - bead = beadcreator.create() - except IncompleteBead: - sys.stderr.write("The bead %i of residue %s is incomplete. Please check your pdb!\n"\ - %(totAtoms+1,residKey) ) - if not options.ignoremissing: raise - totAtoms+=1 - #now we must modify the bead: change the residue type and set the "extra" field correctly - bead.residType = residType - extra = ('%5i'+'%8.3f'+'%2i'*2) %(atomTypeNumber,atomCharge,0, 0) - bead.extra = extra - bead.atomId = totAtoms - bead.residId = residNumber - print bead.ToPdbString() diff --git a/PyAttract/reduce_scorpion.py b/PyAttract/reduce_scorpion.py index 9046f87..e689605 100755 --- a/PyAttract/reduce_scorpion.py +++ b/PyAttract/reduce_scorpion.py @@ -3,15 +3,20 @@ from optparse import OptionParser +from cgopt import optimize parser = OptionParser() + +# --cgopt option: choice of charge optimization with SCORPION parser.add_option("--cgopt", dest="optimizecharges", action="store_true", default=False, help="optimize SCORPION coarse grained charges") parser.add_option("--dgrid", type="float",dest="delgrid", default=1.5, help="grid spacing (A) for charge optimization (default is 1.5), works only with -cgopt option") -(options, args) = parser.parse_args() +# --mcop option: create multicopy reduced protein +parser.add_option("--mcop", dest="regions", default=False, help="positions of the multicopy region(s) separated by ';' (eg. 12-21;45-48)") +(options, args) = parser.parse_args() import sys import copy @@ -153,171 +158,212 @@ def create(self): descriptions.append(beadDescription) beadCorresp[residname] = descriptions +models = [] +if options.regions: +# Preparing pdb multicopy models + if options.regions.endswith('.pdb'): + core = Rigidbody(args[0]) + region_copies = [] + for i in xrange(1, len(args)): + region_copies.append(Mcop(args[i])) + models.append(core) + models.append(region_copies) + write_mcop('new_mcop.pdb', core, region_copies) + else: + core, region_copies = multicopy(args[0], options.regions) + write_mcop('_mcop.pdb', core, region_copies) + models.append(core) + models.append(region_copies) +else: + models.append(Rigidbody(args[0])) + + + + +def reduce_model(allAtom): + newallAtom = [] + for i in xrange(len(allAtom)): + atom = allAtom.CopyAtom(i) + if atom.chainId == '': atom.chainId = ' ' + if atom.atomType[0] != 'H' and atom.atomType != 'OXT' and atom.atomType!= 'OT2': + newallAtom.append(atom) + allAtom = Rigidbody() + for at in newallAtom: + allAtom.AddAtom(at) + + + + sys.stderr.write("Number of atoms: %d\n" %(len(allAtom) )) + + #extract all 'atoms' objects + atoms=[] + for i in xrange(len(allAtom) ): + atoms.append(allAtom.CopyAtom(i)) + + + + #count residues: + residuMap={} + residulist=[] + for at in atoms: + residueIdentifier = at.residType + str(at.chainId) + str(at.residId) + #residueIdentifier is like "LEUA296" + residuMap.setdefault(residueIdentifier, []).append(at) + if residueIdentifier not in residulist: + residulist.append(residueIdentifier) + + sys.stderr.write("Number of residues: %i\n" %(len(residuMap))) + sys.stderr.write("Start atom of each residue:\n") + orderedresid=[residuMap[i] for i in residulist ] + startatoms=[lat[0].atomId for lat in orderedresid ] + out = "" + for statom in startatoms: + out+=(str(statom))+" " + sys.stderr.write(out+"\n") + + + #iterates through all the residues and create reduced beads: + + totAtoms=0 + + protein = [] + + for residKey, atomList in zip(residulist,orderedresid): + residType=residKey[:3] + if (residType)=="HIE": residType="HIS" #fix for an amber output file + residNumber=int(residKey[4:]) + correspList=beadCorresp[residType] + + for correspUnit in correspList: + atomTypeName=correspUnit[0] + lstToReduce=correspUnit[1] + atomTypeNumber=correspUnit[2] + atomCharge=correspUnit[3] + beadcreator=BeadCreator(atomTypeName,atomTypeNumber, atomCharge, lstToReduce) + for atom in atomList: + beadcreator.submit(atom) + try: + bead = beadcreator.create() + except IncompleteBead: + sys.stderr.write("The bead %i of residue %s is incomplete. Please check your pdb!\n"\ + %(totAtoms+1,residKey) ) + sys.exit(1) + totAtoms+=1 + #now we must modify the bead: change the residue type and set the "extra" field correctly + bead.residType = residType + extra = ('%5i'+'%8.3f'+'%2i'*2) %(atomTypeNumber,atomCharge,0, 0) + bead.extra = extra + bead.atomId = totAtoms + bead.residId = residNumber + protein.append(bead) + + + charge = [] + radius = [] + cx = [] + cy = [] + cz = [] + + cgch = [] + cgr = [] + cgx = [] + cgy = [] + cgz = [] + + + + for i in range(len(allAtom)): + atom = allAtom.CopyAtom(i) + residu_type= atom.residType + atomtype = atom.atomType + if residu_type =="ILE" and atomtype == "CD": + atomtype = "CD1" + key = "%s:%s"%(residu_type, atomtype) + radius.append( allAtomRadius[key] ) + charge.append ( allAtomCharges[key] ) + cx.append( atom.coords.x) + cy.append( atom.coords.y) + cz.append( atom.coords.z) + + + + for i, atom in enumerate(protein): + + cgch.append( atom.atomCharge ) + + residu_type= atom.residType + atomtype = atom.atomType + if residu_type =="ILE" and atomtype == "CD": + atomtype = "CD1" + key = "%s:%s"%(residu_type, atomtype) - -allAtom=Rigidbody(args[0]) - -newallAtom = [] -for i in xrange(len(allAtom)): - atom = allAtom.CopyAtom(i) - if atom.chainId == '': atom.chainId = ' ' - if atom.atomType[0] != 'H' and atom.atomType != 'OXT' and atom.atomType!= 'OT2': - newallAtom.append(atom) -allAtom = Rigidbody() -for at in newallAtom: - allAtom.AddAtom(at) - - - -sys.stderr.write("Number of atoms: %d\n" %(len(allAtom) )) - -#extract all 'atoms' objects -atoms=[] -for i in xrange(len(allAtom) ): - atoms.append(allAtom.CopyAtom(i)) - - - -#count residues: -residuMap={} -residulist=[] -for at in atoms: - residueIdentifier = at.residType + str(at.chainId) + str(at.residId) - #residueIdentifier is like "LEUA296" - residuMap.setdefault(residueIdentifier, []).append(at) - if residueIdentifier not in residulist: - residulist.append(residueIdentifier) - -sys.stderr.write("Number of residues: %i\n" %(len(residuMap))) -sys.stderr.write("Start atom of each residue:\n") -orderedresid=[residuMap[i] for i in residulist ] -startatoms=[lat[0].atomId for lat in orderedresid ] -out = "" -for statom in startatoms: - out+=(str(statom))+" " -sys.stderr.write(out+"\n") + cgr.append( beadRadius[key] ) + cgx.append( atom.coords.x) + cgy.append( atom.coords.y) + cgz.append( atom.coords.z) -#iterates through all the residues and create reduced beads: -totAtoms=0 -protein = [] -for residKey, atomList in zip(residulist,orderedresid): - residType=residKey[:3] - if (residType)=="HIE": residType="HIS" #fix for an amber output file - residNumber=int(residKey[4:]) - correspList=beadCorresp[residType] - for correspUnit in correspList: - atomTypeName=correspUnit[0] - lstToReduce=correspUnit[1] - atomTypeNumber=correspUnit[2] - atomCharge=correspUnit[3] - beadcreator=BeadCreator(atomTypeName,atomTypeNumber, atomCharge, lstToReduce) - for atom in atomList: - beadcreator.submit(atom) - try: - bead = beadcreator.create() - except IncompleteBead: - sys.stderr.write("The bead %i of residue %s is incomplete. Please check your pdb!\n"\ - %(totAtoms+1,residKey) ) - sys.exit(1) - totAtoms+=1 - #now we must modify the bead: change the residue type and set the "extra" field correctly - bead.residType = residType - extra = ('%5i'+'%8.3f'+'%2i'*2) %(atomTypeNumber,atomCharge,0, 0) - bead.extra = extra - bead.atomId = totAtoms - bead.residId = residNumber - protein.append(bead) + first = False + last = False + for i, at in enumerate(protein): + if at.atomType == 'CA': + cgch[i] += 1 + break + protein.reverse() + cgch.reverse() + for i,at in enumerate(protein): + if at.atomType == 'CA': + cgch[i] -= 1 + break + + protein.reverse() + cgch.reverse() + if options.optimizecharges: + optimized = optimize(len(allAtom), charge, radius, cx, cy, cz, len(protein), cgch, cgr, cgx, cgy, cgz, options.delgrid ) + else: + optimized = cgch -from cgopt import optimize + for i, bead in enumerate(protein): + #ugly hack to set correct charges values due to a bug atom to pdb conversion + extra = bead.extra + atomTypeNumber = int(extra.split()[0]) + bead.extra = ('%5i'+'%8.3f'+'%2i'*2) %(atomTypeNumber,optimized[i],0, 0) + + print bead.ToPdbString() -charge = [] -radius = [] -cx = [] -cy = [] -cz = [] - -cgch = [] -cgr = [] -cgx = [] -cgy = [] -cgz = [] - - - -for i in range(len(allAtom)): - atom = allAtom.CopyAtom(i) - residu_type= atom.residType - atomtype = atom.atomType - if residu_type =="ILE" and atomtype == "CD": - atomtype = "CD1" - key = "%s:%s"%(residu_type, atomtype) - radius.append( allAtomRadius[key] ) - charge.append ( allAtomCharges[key] ) - cx.append( atom.coords.x) - cy.append( atom.coords.y) - cz.append( atom.coords.z) - - - -for i, atom in enumerate(protein): - - cgch.append( atom.atomCharge ) - - residu_type= atom.residType - atomtype = atom.atomType - if residu_type =="ILE" and atomtype == "CD": - atomtype = "CD1" - key = "%s:%s"%(residu_type, atomtype) - - cgr.append( beadRadius[key] ) - cgx.append( atom.coords.x) - cgy.append( atom.coords.y) - cgz.append( atom.coords.z) - - - - - - -first = False -last = False -for i, at in enumerate(protein): - if at.atomType == 'CA': - cgch[i] += 1 - break -protein.reverse() -cgch.reverse() - -for i,at in enumerate(protein): - if at.atomType == 'CA': - cgch[i] -= 1 - break - -protein.reverse() -cgch.reverse() -if options.optimizecharges: - optimized = optimize(len(allAtom), charge, radius, cx, cy, cz, len(protein), cgch, cgr, cgx, cgy, cgz, options.delgrid ) -else: - optimized = cgch - +# iterate through all models (important for multicopy option) and write reduced pdb print "HEADER SCORPION REDUCED PDB FILE" - -for i, bead in enumerate(protein): - #ugly hack to set correct charges values due to a bug atom to pdb conversion - extra = bead.extra - atomTypeNumber = int(extra.split()[0]) - bead.extra = ('%5i'+'%8.3f'+'%2i'*2) %(atomTypeNumber,optimized[i],0, 0) - - print bead.ToPdbString() - +# iterate through 'models' variable which contains max 2 elements. +# The fist element of the models list is a Rigidbody (the core in the mcop case, and the whole protein in the normal case) +# In the mcop case, there is a second element, which is the region_copies list (a list of Mcop objects). +for i in xrange(0,len(models)): + if i == 0 and options.regions != ':': + sys.stderr.write("\nCore:\n") + print 'MODEL 0' + reduce_model(models[i]) + print 'ENDMDL 0' + if i >= 1: + # iterate through number of regions + for j in xrange(0, len(models[1])): + # iterate through number of regions copies + for k in xrange(0,len(models[1][j])): + sys.stderr.write("\nRegion %i Copy %i:\n" %(j+1, k+1)) + print 'MODEL ' + str(j+1) + ' ' + str(k+1) + reduce_model(models[1][j][k]) + print 'ENDMDL ' + str(j+1) + ' ' + str(k+1) + sys.stderr.write("\n\nSummary:\n") + for j in xrange(0, len(models[1])): + sys.stderr.write("Region %i: %i copies\n" %(j+1,len(models[1][j]))) + + + From 14534a093403fea83ed04efe30be941fabf85d5a Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Mon, 11 Apr 2016 14:53:22 +0200 Subject: [PATCH 09/90] Created Mcoprigid C++ constructor that takes a multicopy pdb filename and uses the newly created ReadMcoprigidPDB function (and this function uses newly created functions, line_to_region_number and line_to_copy_number). --- headers/mcopff.h | 6 ++++ src/mcopff.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 75 insertions(+), 5 deletions(-) diff --git a/headers/mcopff.h b/headers/mcopff.h index b713aa8..030be09 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -99,6 +99,7 @@ class Mcoprigid //multicopy rigidbody public: Mcoprigid(); + Mcoprigid(std::string filename); //using default copy operator @@ -112,6 +113,11 @@ class Mcoprigid //multicopy rigidbody void PrintWeights(); std::vector > getWeights(){return _weights;}; + + void ReadMcoprigidPDB(const std::string name); + void ReadMcoprigidPDB(std::istream& file, AttractRigidbody& core, std::vector& regions); + uint line_to_region_number(std::string line); + uint line_to_copy_number(std::string line); private: diff --git a/src/mcopff.cpp b/src/mcopff.cpp index e464877..a3d466e 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -5,15 +5,19 @@ namespace PTools { -/////////////////// -- Class McopRigid -- //////////////////// +/////////////////// -- Class Mcoprigid -- //////////////////// -Mcoprigid::Mcoprigid() -{ +Mcoprigid::Mcoprigid(){ _complete = false; }; +Mcoprigid::Mcoprigid(std::string filename){ + ReadMcoprigidPDB(filename); + _center = _core.FindCenter(); + +} void Mcoprigid::setCore(AttractRigidbody& core) { @@ -54,6 +58,58 @@ void Mcoprigid::Translate(const Coord3D& c) } +void Mcoprigid::ReadMcoprigidPDB(const std::string name) { + + // pointer toward the filename given in the constructor argument + std::ifstream file(name.c_str()); + if (!file) + { + std::ostringstream oss; + throw std::invalid_argument("##### ReadPDB:Could not open file \"" + name + "\" #####") ; + } + + ReadMcoprigidPDB(file, _core, _vregion); + file.close(); + +} + + +void Mcoprigid::ReadMcoprigidPDB(std::istream& file, AttractRigidbody& core, std::vector& regions){ + + uint region_num; + uint copy_num; + std::string line; + while(std::getline(file, line)){ + if(Mcop::isNewModel(line)){ + // The line is a new model + region_num = line_to_region_number(line); + copy_num = line_to_copy_number(line); + AttractRigidbody model; + while(std::getline(file,line)){ + if(isAtom(line)){ + // The line is an atom + Coord3D pos = pdbToCoords(line); + Atomproperty a; + pdbToAtomproperty(line, a); + // if region_num is core, append attom to core + if(region_num == 0) core.AddAtom(a,pos); + else model.AddAtom(a,pos); + } + // if region_num is not core, add region copy + else if(region_num != 0){ + + // if new region, add region to vector + if(regions.size() < region_num) + regions.push_back(AttractMcop()); + regions[copy_num-1].addCopy(model); + //Just finished adding a region copy + break; + } + } + } + } +} + void Mcoprigid::PrintWeights() { @@ -68,6 +124,15 @@ void Mcoprigid::PrintWeights() } } +uint Mcoprigid::line_to_region_number(std::string line){ + + return std::atoi(line.substr(12,1).c_str()); +} + +uint Mcoprigid::line_to_copy_number(std::string line){ + + return std::atoi(line.substr(15,1).c_str()); +} /////////////////// -- Class Mcop -- //////////////////// @@ -115,7 +180,7 @@ void Mcop::ReadModelsPDB(std::istream& file, std::vector& protein){ } else{ protein.push_back(model); - //Just finished writing a model + //Just finished adding a model break; } } @@ -124,7 +189,6 @@ void Mcop::ReadModelsPDB(std::istream& file, std::vector& protein){ } - bool Mcop::isNewModel(const std::string & line){ if(line.substr(0,5)==(std::string)"MODEL") return true; From 270e7f6d70cdc9123b23ee6c4b89044b5e10e147 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Mon, 11 Apr 2016 15:07:58 +0200 Subject: [PATCH 10/90] Changed Mcop::isNewModel to static so Mcoprigid::ReadMcoprigidPDB can call it. --- headers/mcopff.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/headers/mcopff.h b/headers/mcopff.h index 030be09..124d07e 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -59,7 +59,7 @@ std::vector _copies; void ReadmcopPDB(const std::string name); void ReadmcopPDB(std::istream& file, std::vector& protein); void ReadModelsPDB(std::istream& file, std::vector& protein); - bool isNewModel(const std::string & line); + static bool isNewModel(const std::string & line); void clear(){_copies.clear();}; From e7b92bd4ea90f69ae2453c8c403dfbb9917c5e1b Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Mon, 11 Apr 2016 18:06:26 +0200 Subject: [PATCH 11/90] Created Mcoprigid constructors in binding interface mcopff.pyx : Mcoprigid(), Mcoprigid(string filename), Mcoprigid(Mcoprigid mcoprigid_to_duplicate) --- bindings/mcopff.pyx | 46 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx index 892ae7e..1e75ee1 100644 --- a/bindings/mcopff.pyx +++ b/bindings/mcopff.pyx @@ -25,6 +25,13 @@ cdef extern from "mcopff.h" namespace "PTools": CppAttractRigidbody operator[](unsigned int) unsigned int size() void addCopy(CppAttractRigidbody&) + cdef cppclass CppMcoprigid "Ptools::Mcoprigid": + CppMcoprigid() + CppMcoprigid(string&) + CppMcoprigid(CppRigidbody&, vector(CppAttractMcop)) + CppMcoprigid(CppMcoprigid&) + CppAttractMcop getRegion(unsigned int) + CppAttractRigidbody getCore() cdef class Mcop: @@ -131,7 +138,7 @@ cdef class AttractMcop (Mcop): print "FATAL; this should never happen" else: - raise RuntimeError("invalid argument in Mcop()") + raise RuntimeError("invalid argument in AttractMcop()") def __dealloc__(self): if self.thisptr: @@ -162,3 +169,40 @@ cdef class AttractMcop (Mcop): def __len__(self): return self.thisptr2.size() + +cdef class Mcoprigid: + cdef CppMcoprigid* thisptr + + def __cinit__(self, filename='', arg2=''): + cdef CppMcoprigid* oldptr + cdef Mcoprigid oldmcoprigid + cdef char* name + cdef string *cppname + cdef CppMcoprigid* newmcoprigid + + if isinstance(filename, str): + if filename == '': + self.thisptr = new CppMcoprigid() + else: + # there is a filename, loading the pdb file + name = filename + cppname = new string(name) + newmcoprigid = new CppMcoprigid(deref(cppname)) + del cppname + self.thisptr = newmcoprigid + + elif isinstance(filename, Mcoprigid): + oldmcoprigid = filename + oldptr = oldmcoprigid.thisptr + self.thisptr = new CppMcoprigid(deref(oldptr)) + if not self.thisptr: + print "FATAL: this should never happen" + + # if filename is AttractRigibody and arg2 is list of AttractMcop + # elif isinstance(arg2, AttractRigidbody) and isinstance(filename, (list, tuple)) and all(isinstance(elem, AttractMcop) for elem in arg2): + # TODO + + else: + raise RunetimeError("invalid argument in Mcoprigid()") + + From a71887c5654e06b400001afb2b6d2bfd2155f2c3 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Mon, 11 Apr 2016 18:13:57 +0200 Subject: [PATCH 12/90] =?UTF-8?q?Created=20d=C3=A9allocator=20of=20the=20M?= =?UTF-8?q?coprigid=20class=20in=20binding=20interface=20mcopff.pyx?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bindings/mcopff.pyx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx index 1e75ee1..6f22741 100644 --- a/bindings/mcopff.pyx +++ b/bindings/mcopff.pyx @@ -204,5 +204,10 @@ cdef class Mcoprigid: else: raise RunetimeError("invalid argument in Mcoprigid()") + + def __dealloc__(self): + if self.thisptr: + del self.thisptr + self.thisptr = 0 From 1727a749ccc3a1d05198a285bb2095bbe7deb9bf Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Mon, 11 Apr 2016 19:10:55 +0200 Subject: [PATCH 13/90] Created C++ functions for Mcoprigid class: getCore(), getRegion(i), size(). --- headers/mcopff.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/headers/mcopff.h b/headers/mcopff.h index 124d07e..f7593d4 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -118,6 +118,10 @@ class Mcoprigid //multicopy rigidbody void ReadMcoprigidPDB(std::istream& file, AttractRigidbody& core, std::vector& regions); uint line_to_region_number(std::string line); uint line_to_copy_number(std::string line); + + AttractRigidbody& getCore(){return _core;}; + AttractMcop& getRegion(int i){return _vregion[i];}; + size_t size() const {return _vregion.size();}; private: From b32cf1c8c19e88fe1b8dbeecbc5d5af1b33efba6 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 12 Apr 2016 14:17:01 +0200 Subject: [PATCH 14/90] Fixed cython Mcoprigig constructor compilation error. Changed Ptools to PTools. --- bindings/mcopff.pyx | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx index 6f22741..f725f0e 100644 --- a/bindings/mcopff.pyx +++ b/bindings/mcopff.pyx @@ -25,19 +25,20 @@ cdef extern from "mcopff.h" namespace "PTools": CppAttractRigidbody operator[](unsigned int) unsigned int size() void addCopy(CppAttractRigidbody&) - cdef cppclass CppMcoprigid "Ptools::Mcoprigid": + cdef cppclass CppMcoprigid "PTools::Mcoprigid": CppMcoprigid() - CppMcoprigid(string&) - CppMcoprigid(CppRigidbody&, vector(CppAttractMcop)) + CppMcoprigid(string&) except+ + #CppMcoprigid(CppRigidbody&, vector(CppAttractMcop)) CppMcoprigid(CppMcoprigid&) - CppAttractMcop getRegion(unsigned int) - CppAttractRigidbody getCore() + #CppAttractMcop getRegion(unsigned int) + #CppAttractRigidbody getCore() cdef class Mcop: cdef CppMcop* thisptr def __cinit__(self, filename=''): + cdef CppMcop* oldptr cdef Mcop oldmcop cdef char* name @@ -169,11 +170,13 @@ cdef class AttractMcop (Mcop): def __len__(self): return self.thisptr2.size() - + + cdef class Mcoprigid: cdef CppMcoprigid* thisptr def __cinit__(self, filename='', arg2=''): + cdef CppMcoprigid* oldptr cdef Mcoprigid oldmcoprigid cdef char* name @@ -198,9 +201,10 @@ cdef class Mcoprigid: if not self.thisptr: print "FATAL: this should never happen" - # if filename is AttractRigibody and arg2 is list of AttractMcop - # elif isinstance(arg2, AttractRigidbody) and isinstance(filename, (list, tuple)) and all(isinstance(elem, AttractMcop) for elem in arg2): - # TODO + #if filename is AttractRigibody and arg2 is list of AttractMcop + elif isinstance(arg2, AttractRigidbody) and isinstance(filename, (list, tuple)) and all(isinstance(elem, AttractMcop) for elem in arg2): + print 'test' + # TODO else: raise RunetimeError("invalid argument in Mcoprigid()") @@ -209,5 +213,21 @@ cdef class Mcoprigid: if self.thisptr: del self.thisptr self.thisptr = 0 + + def getCore() + cdef CppAttractRigidbody cpp_core = self.thisptr.getCore(i) + cdef AttractRigidbody core = AttractRigidbody() + cdef CppAttractRigbody* new_core = new CppAttractRigidbody(cpp_core) + del core.thisptr + core.thisptr = new_core + return core + + def getRegion(i) + cdef CppAttractMcop cpp_region = self.thisptr.getRegion(i) + cdef AttractMcop region = AttractMcop() + cdef CppAttractMcop* new_region = new CppAttractMcop(cpp_region) + del region.thisptr + region.thisptr = new_region + return region + - From e968a97c510ec6623166c76fb6930fd67e1cac06 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 12 Apr 2016 14:37:45 +0200 Subject: [PATCH 15/90] Fixed compilation of getCore and getRegion in Mcoprigid class (mcopff.pyx). --- bindings/mcopff.pyx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx index f725f0e..1d17f15 100644 --- a/bindings/mcopff.pyx +++ b/bindings/mcopff.pyx @@ -30,8 +30,8 @@ cdef extern from "mcopff.h" namespace "PTools": CppMcoprigid(string&) except+ #CppMcoprigid(CppRigidbody&, vector(CppAttractMcop)) CppMcoprigid(CppMcoprigid&) - #CppAttractMcop getRegion(unsigned int) - #CppAttractRigidbody getCore() + CppAttractMcop getRegion(unsigned int) + CppAttractRigidbody getCore() cdef class Mcop: @@ -214,20 +214,20 @@ cdef class Mcoprigid: del self.thisptr self.thisptr = 0 - def getCore() - cdef CppAttractRigidbody cpp_core = self.thisptr.getCore(i) + def getCore(self): + cdef CppAttractRigidbody cpp_core = self.thisptr.getCore() cdef AttractRigidbody core = AttractRigidbody() - cdef CppAttractRigbody* new_core = new CppAttractRigidbody(cpp_core) + cdef CppAttractRigidbody* new_core = new CppAttractRigidbody(cpp_core) del core.thisptr - core.thisptr = new_core + core.thisptr = new_core return core - def getRegion(i) + def getRegion(self,i): cdef CppAttractMcop cpp_region = self.thisptr.getRegion(i) cdef AttractMcop region = AttractMcop() cdef CppAttractMcop* new_region = new CppAttractMcop(cpp_region) del region.thisptr - region.thisptr = new_region + region.thisptr2 = new_region return region From df8341dcdd774d109429238abf2cd87e3ad876ff Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 12 Apr 2016 15:42:40 +0200 Subject: [PATCH 16/90] Fixed C++ bugs in ReadMcoprigidPDB (mcopff.cpp) --- src/mcopff.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/mcopff.cpp b/src/mcopff.cpp index a3d466e..1b07241 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -76,14 +76,17 @@ void Mcoprigid::ReadMcoprigidPDB(const std::string name) { void Mcoprigid::ReadMcoprigidPDB(std::istream& file, AttractRigidbody& core, std::vector& regions){ - uint region_num; - uint copy_num; + uint region_num = 0; + uint copy_num = 0; std::string line; while(std::getline(file, line)){ if(Mcop::isNewModel(line)){ // The line is a new model - region_num = line_to_region_number(line); - copy_num = line_to_copy_number(line); + printf("Line size = %i\n",line.size()); + if(line.size() > 12) region_num = line_to_region_number(line); + printf("Region number = %i\n", region_num); + if(line.size() > 15) copy_num = line_to_copy_number(line); + printf("Copy number = %i\n", copy_num); AttractRigidbody model; while(std::getline(file,line)){ if(isAtom(line)){ @@ -95,13 +98,16 @@ void Mcoprigid::ReadMcoprigidPDB(std::istream& file, AttractRigidbody& core, std if(region_num == 0) core.AddAtom(a,pos); else model.AddAtom(a,pos); } - // if region_num is not core, add region copy - else if(region_num != 0){ - - // if new region, add region to vector - if(regions.size() < region_num) - regions.push_back(AttractMcop()); - regions[copy_num-1].addCopy(model); + + else{ + // if region_num is not core, add region copy + if(region_num != 0){ + // if new region, add region to vector before adding region copy + if(regions.size() < region_num) + regions.push_back(AttractMcop()); + // copy + regions[region_num-1].addCopy(model); + } //Just finished adding a region copy break; } @@ -131,7 +137,7 @@ uint Mcoprigid::line_to_region_number(std::string line){ uint Mcoprigid::line_to_copy_number(std::string line){ - return std::atoi(line.substr(15,1).c_str()); + return std::atoi(line.substr(15,line.size()-15).c_str()); } /////////////////// -- Class Mcop -- //////////////////// From c96439d86feefd9908c7a6d70f905b89e5891cd8 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 12 Apr 2016 15:49:00 +0200 Subject: [PATCH 17/90] Created __len__ function for Mcoprigid class (mcopff.pyx) --- bindings/mcopff.pyx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx index 1d17f15..3b17237 100644 --- a/bindings/mcopff.pyx +++ b/bindings/mcopff.pyx @@ -32,6 +32,7 @@ cdef extern from "mcopff.h" namespace "PTools": CppMcoprigid(CppMcoprigid&) CppAttractMcop getRegion(unsigned int) CppAttractRigidbody getCore() + unsigned int size() cdef class Mcop: @@ -202,8 +203,7 @@ cdef class Mcoprigid: print "FATAL: this should never happen" #if filename is AttractRigibody and arg2 is list of AttractMcop - elif isinstance(arg2, AttractRigidbody) and isinstance(filename, (list, tuple)) and all(isinstance(elem, AttractMcop) for elem in arg2): - print 'test' + #elif isinstance(arg2, AttractRigidbody) and isinstance(filename, (list, tuple)) and all(isinstance(elem, AttractMcop) for elem in arg2): # TODO else: @@ -229,5 +229,8 @@ cdef class Mcoprigid: del region.thisptr region.thisptr2 = new_region return region + + def __len__(self): + return self.thisptr.size() From 93b11315ac82eb42c302efb095dd77c3d2e3da27 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 12 Apr 2016 16:04:07 +0200 Subject: [PATCH 18/90] Added --mcop to option parser in attract.py. --- PyAttract/attract.py | 1 + 1 file changed, 1 insertion(+) diff --git a/PyAttract/attract.py b/PyAttract/attract.py index 4d2016a..e2d877b 100755 --- a/PyAttract/attract.py +++ b/PyAttract/attract.py @@ -192,6 +192,7 @@ def checkFile(name, comment): parser.add_option("--ref", action="store", type="string", dest="reffile", help="reference ligand for rmsd" ) parser.add_option("-t", "--translation", action="store", type="int", dest="transnb", help="translation number (distributed mode) starting from 0 for the first one!") parser.add_option("--start1", action="store_true", default=False, dest="start1", help="(only useful with -t), use 1 for the first translation point") +parser.add_option("--mcop", action="store_true", default=False, help="mcop option for multi-copy rigid-body docking") (options, args) = parser.parse_args() From 6eeb945d1656444547d34bddcda8ea28f23c995a Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 12 Apr 2016 16:04:58 +0200 Subject: [PATCH 19/90] Removed debug prints from ReadMcoprigidPDB in mcopff.cpp --- src/mcopff.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/mcopff.cpp b/src/mcopff.cpp index 1b07241..bbae095 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -82,11 +82,8 @@ void Mcoprigid::ReadMcoprigidPDB(std::istream& file, AttractRigidbody& core, std while(std::getline(file, line)){ if(Mcop::isNewModel(line)){ // The line is a new model - printf("Line size = %i\n",line.size()); if(line.size() > 12) region_num = line_to_region_number(line); - printf("Region number = %i\n", region_num); if(line.size() > 15) copy_num = line_to_copy_number(line); - printf("Copy number = %i\n", copy_num); AttractRigidbody model; while(std::getline(file,line)){ if(isAtom(line)){ From 8ef34cff1b012c1f4493a661d7ec0dfcce4b0e71 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 12 Apr 2016 16:05:53 +0200 Subject: [PATCH 20/90] Minor comment mod --- headers/mcopff.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/headers/mcopff.h b/headers/mcopff.h index f7593d4..8f870b7 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -75,11 +75,11 @@ class AttractMcop: public Mcop public: - //Constructor : no arguments + //Constructor: no arguments AttractMcop(){ }; - //Constructor : takes filename + //Constructor: takes filename AttractMcop(std::string filename); - //Constructor : takes mcop + //Constructor: takes mcop AttractMcop(const Mcop& mcop); virtual void addCopy(const AttractRigidbody& cop){attract_copies.push_back(cop);}; @@ -98,7 +98,9 @@ class Mcoprigid //multicopy rigidbody { public: + //Constructor: no arguments Mcoprigid(); + //Constructor: takes filename Mcoprigid(std::string filename); //using default copy operator From 80fe3bf676efac3c07807a33d4c3c3c6287e1691 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 12 Apr 2016 16:16:45 +0200 Subject: [PATCH 21/90] In attract.py, when loading ligand file (line 293), if --mcop option, load as Mcoprigid instead of Rigidbody --- PyAttract/attract.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/PyAttract/attract.py b/PyAttract/attract.py index e2d877b..7e196eb 100755 --- a/PyAttract/attract.py +++ b/PyAttract/attract.py @@ -192,7 +192,7 @@ def checkFile(name, comment): parser.add_option("--ref", action="store", type="string", dest="reffile", help="reference ligand for rmsd" ) parser.add_option("-t", "--translation", action="store", type="int", dest="transnb", help="translation number (distributed mode) starting from 0 for the first one!") parser.add_option("--start1", action="store_true", default=False, dest="start1", help="(only useful with -t), use 1 for the first translation point") -parser.add_option("--mcop", action="store_true", default=False, help="mcop option for multi-copy rigid-body docking") +parser.add_option("--mcop", action="store_true", default=False, dest="regions", help="mcop option for multi-copy rigid-body docking") (options, args) = parser.parse_args() @@ -291,9 +291,12 @@ def check_ffversion(reduced): #load receptor and ligand: rec=Rigidbody(options.receptor_name) -lig=Rigidbody(options.ligand_name) rec=AttractRigidbody(rec) -lig=AttractRigidbody(lig) +if options.regions: + lig=Mcoprigid(lig) +else: + lig=AttractRigidbody(lig) + lig=Rigidbody(options.ligand_name) print "Reading receptor (fixed): %s with %d particules" %( options.receptor_name, len(rec) ) print "Reading ligand (mobile): %s with %d particules" %( options.ligand_name, len(lig) ) From 14265ea3697874fee71fc8bc5ca5d96589f9ae55 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Thu, 14 Apr 2016 11:18:25 +0200 Subject: [PATCH 22/90] Changed rec to Mcoprgid instead of lig (attract.py). --- PyAttract/attract.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/PyAttract/attract.py b/PyAttract/attract.py index 7e196eb..4d10f7e 100755 --- a/PyAttract/attract.py +++ b/PyAttract/attract.py @@ -290,13 +290,13 @@ def check_ffversion(reduced): #load receptor and ligand: -rec=Rigidbody(options.receptor_name) -rec=AttractRigidbody(rec) +lig=Rigidbody(options.ligand_name) +lig=AttractRigidbody(lig) if options.regions: - lig=Mcoprigid(lig) + rec=Mcoprigid(rec) else: - lig=AttractRigidbody(lig) - lig=Rigidbody(options.ligand_name) + rec=AttractRigidbody(rec) + rec=Rigidbody(options.receptor_name) print "Reading receptor (fixed): %s with %d particules" %( options.receptor_name, len(rec) ) print "Reading ligand (mobile): %s with %d particules" %( options.ligand_name, len(lig) ) From 1ce5d40d8ed0e2f161afdad3dd81c5a86cf8035c Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Mon, 18 Apr 2016 11:25:22 +0200 Subject: [PATCH 23/90] Added getCore function to binding interface of Mcoprigid class. --- bindings/mcopff.pyx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx index 3b17237..f4e2681 100644 --- a/bindings/mcopff.pyx +++ b/bindings/mcopff.pyx @@ -33,6 +33,7 @@ cdef extern from "mcopff.h" namespace "PTools": CppAttractMcop getRegion(unsigned int) CppAttractRigidbody getCore() unsigned int size() + void setCore(CppAttractRigidbody&) cdef class Mcop: @@ -230,6 +231,9 @@ cdef class Mcoprigid: region.thisptr2 = new_region return region + def setCore(self, AttractRigidbody core): + self.thisptr.setCore(deref(core.thisptr)) + def __len__(self): return self.thisptr.size() From e30d41f674f3c84095c520f193af477161934732 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Mon, 18 Apr 2016 12:49:11 +0200 Subject: [PATCH 24/90] In attract.py import lig as Mcoprigid if mcop option. --- PyAttract/attract.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/PyAttract/attract.py b/PyAttract/attract.py index 4d10f7e..a66ca45 100755 --- a/PyAttract/attract.py +++ b/PyAttract/attract.py @@ -290,13 +290,16 @@ def check_ffversion(reduced): #load receptor and ligand: -lig=Rigidbody(options.ligand_name) -lig=AttractRigidbody(lig) if options.regions: - rec=Mcoprigid(rec) + rec=Mcoprigid(options.receptor_name) + core=AttractRigidbody(options.ligand_name) + lig=Mcoprigid() + lig.seCore(core) else: - rec=AttractRigidbody(rec) rec=Rigidbody(options.receptor_name) + rec=AttractRigidbody(rec) + lig=Rigidbody(options.ligand_name) + lig=AttractRigidbody(lig) print "Reading receptor (fixed): %s with %d particules" %( options.receptor_name, len(rec) ) print "Reading ligand (mobile): %s with %d particules" %( options.ligand_name, len(lig) ) @@ -381,10 +384,10 @@ def check_ffversion(reduced): #performs single minimization on receptor and ligand, given maxiter=niter and restraint constant rstk forcefield=ff_specs['ff_class'](ff_specs['ff_file'], surreal(cutoff) ) - rec.setTranslation(False) - rec.setRotation(False) + rec.setTranslation(False) #TODO + rec.setRotation(False) #TODO - forcefield.AddLigand(rec) + forcefield.AddLigand(rec) #TODO forcefield.AddLigand(ligand) rstk=minim['rstk'] #restraint force #if rstk>0.0: From fdf4c870108b3681abdccc173c42042583931489 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Mon, 18 Apr 2016 14:25:50 +0200 Subject: [PATCH 25/90] Added iniWeights function that in used in constructor of Mcoprigid class. It initialises loop weights to 1/(number of loops). --- headers/mcopff.h | 2 +- src/mcopff.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/headers/mcopff.h b/headers/mcopff.h index 8f870b7..a1a3848 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -102,9 +102,9 @@ class Mcoprigid //multicopy rigidbody Mcoprigid(); //Constructor: takes filename Mcoprigid(std::string filename); - //using default copy operator + void iniWeights(); void setCore(AttractRigidbody& core) ; void addEnsemble(const AttractMcop& reg){ _vregion.push_back(reg); std::vector v; _weights.push_back(v); }; diff --git a/src/mcopff.cpp b/src/mcopff.cpp index bbae095..6df12a1 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -16,9 +16,20 @@ Mcoprigid::Mcoprigid(std::string filename){ ReadMcoprigidPDB(filename); _center = _core.FindCenter(); + iniWeights(); } +void Mcoprigid::iniWeights(){ + for(int i=0; i < _vregion.size(); i++){ + std::vector newvector; + _weights.push_back(newvector); + for(int j=0; j < _vregion[i].size(); j++){ + dbl weight = 1/_vregion[i].size(); + _weights[i].push_back(weight); + } + } +} void Mcoprigid::setCore(AttractRigidbody& core) { _core=core; From ab36ac30309c698786a8b52d60209dc8dd15bd74 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Thu, 21 Apr 2016 10:00:46 +0200 Subject: [PATCH 26/90] Added mcopff variable of type McopForceField in attract.py, but still need to create binding interface for McopForceField. --- PyAttract/attract.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PyAttract/attract.py b/PyAttract/attract.py index a66ca45..e4d75c5 100755 --- a/PyAttract/attract.py +++ b/PyAttract/attract.py @@ -294,7 +294,7 @@ def check_ffversion(reduced): rec=Mcoprigid(options.receptor_name) core=AttractRigidbody(options.ligand_name) lig=Mcoprigid() - lig.seCore(core) + lig.setCore(core) else: rec=Rigidbody(options.receptor_name) rec=AttractRigidbody(rec) @@ -384,6 +384,7 @@ def check_ffversion(reduced): #performs single minimization on receptor and ligand, given maxiter=niter and restraint constant rstk forcefield=ff_specs['ff_class'](ff_specs['ff_file'], surreal(cutoff) ) + mcopff = McopForceField(forcefield, surreal(cutoff)) rec.setTranslation(False) #TODO rec.setRotation(False) #TODO From c803661edfbb1e2c74651fcad45e6aca5ccb858f Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Thu, 21 Apr 2016 13:31:16 +0200 Subject: [PATCH 27/90] Added McopForceField class to binding interface. --- bindings/mcopff.pyx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx index f4e2681..2b9a1b0 100644 --- a/bindings/mcopff.pyx +++ b/bindings/mcopff.pyx @@ -34,6 +34,8 @@ cdef extern from "mcopff.h" namespace "PTools": CppAttractRigidbody getCore() unsigned int size() void setCore(CppAttractRigidbody&) + cdef cppclass CppMcopForceField "PTools::McopForceField": + CppMcopForceField(CppBaseAttractForceField&, double) cdef class Mcop: @@ -238,3 +240,21 @@ cdef class Mcoprigid: return self.thisptr.size() +cdef class McopForceField: + cdef CppMcopForceField* thisptr + + def __cinit__(self, ff, cutoff): + + cdef BaseAttractForceField old_ff + cdef CppBaseAttractForceField c_ff + cdef CppBaseAttractForceField* c_ff_ptr + + old_ff = ff + c_ff_ptr = old_ff.thisptr + self.thisptr = new CppMcopForceField(deref(c_ff_ptr), cutoff) + + + def __dealloc__(self): + if self.thisptr: + del self.thisptr + self.thisptr = 0 \ No newline at end of file From 9eb0b162fd4ecea46bfaff3957d94da34885fdb2 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Thu, 21 Apr 2016 15:10:57 +0200 Subject: [PATCH 28/90] Override setTranslation and setRotation in Mcoprigid class to apply it to its _core attribute (of type AttractRigidbody) --- headers/attractrigidbody.h | 4 ++-- headers/mcopff.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/headers/attractrigidbody.h b/headers/attractrigidbody.h index e014ae2..4a14ba1 100644 --- a/headers/attractrigidbody.h +++ b/headers/attractrigidbody.h @@ -78,8 +78,8 @@ class AttractRigidbody: public Rigidbody } - void setRotation(bool value) {hasrotation = value;} ///< allow/disallow rotation - void setTranslation(bool value) {hastranslation = value;} ///< allow/disallow translation + virtual void setRotation(bool value) {hasrotation = value;} ///< allow/disallow rotation + virtual void setTranslation(bool value) {hastranslation = value;} ///< allow/disallow translation void setDummyTypes(const std::vector& dummy); ///< set a list of ignored atom types diff --git a/headers/mcopff.h b/headers/mcopff.h index a1a3848..e7898d1 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -125,6 +125,8 @@ class Mcoprigid //multicopy rigidbody AttractMcop& getRegion(int i){return _vregion[i];}; size_t size() const {return _vregion.size();}; + virtual void setRotation(bool value) {_core.setRotation(value)} ///< allow/disallow rotation + virtual void setTranslation(bool value) {_core.setTranslation(value)} ///< allow/disallow translation private: From cfae988a763d5dc236a14f4405fb19de987691c6 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Thu, 21 Apr 2016 15:22:41 +0200 Subject: [PATCH 29/90] In attract.py, applied setLigand and setReceptor to mcopff variable (of type McopForceField) if there is mcop option. --- PyAttract/attract.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/PyAttract/attract.py b/PyAttract/attract.py index e4d75c5..8acbb3c 100755 --- a/PyAttract/attract.py +++ b/PyAttract/attract.py @@ -385,11 +385,15 @@ def check_ffversion(reduced): #performs single minimization on receptor and ligand, given maxiter=niter and restraint constant rstk forcefield=ff_specs['ff_class'](ff_specs['ff_file'], surreal(cutoff) ) mcopff = McopForceField(forcefield, surreal(cutoff)) - rec.setTranslation(False) #TODO - rec.setRotation(False) #TODO + rec.setTranslation(False) + rec.setRotation(False) - forcefield.AddLigand(rec) #TODO - forcefield.AddLigand(ligand) + if option.regions: + mcopff.setReceptor(rec) + mcopff.setLigand(lig) + else: + forcefield.AddLigand(rec) + forcefield.AddLigand(ligand) rstk=minim['rstk'] #restraint force #if rstk>0.0: #forcefield.SetRestraint(rstk) From 810b264c1a92127e5fecb1216a4f73aba8a72c19 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Thu, 21 Apr 2016 15:46:38 +0200 Subject: [PATCH 30/90] In attract.py, if mcop option, create Lbfgs minimizer from mcopff object. --- PyAttract/attract.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/PyAttract/attract.py b/PyAttract/attract.py index 8acbb3c..63158d5 100755 --- a/PyAttract/attract.py +++ b/PyAttract/attract.py @@ -397,7 +397,10 @@ def check_ffversion(reduced): rstk=minim['rstk'] #restraint force #if rstk>0.0: #forcefield.SetRestraint(rstk) - lbfgs_minimizer=ff_specs['minimizer_class'](forcefield) + if option.regions: + lbfgs_minimizer=Lbfgs(mcopff) + else : + lbfgs_minimizer=ff_specs['minimizer_class'](forcefield) lbfgs_minimizer.minimize(niter) X=lbfgs_minimizer.GetMinimizedVars() #optimized freedom variables after minimization From 508fd1338c29eb8527c5f222eccfb909d7fe1925 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Thu, 21 Apr 2016 16:21:44 +0200 Subject: [PATCH 31/90] Added Mcoprigid's getWeights() to binding interface. --- bindings/mcopff.pyx | 4 ++++ headers/mcopff.h | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx index 2b9a1b0..127a115 100644 --- a/bindings/mcopff.pyx +++ b/bindings/mcopff.pyx @@ -34,6 +34,7 @@ cdef extern from "mcopff.h" namespace "PTools": CppAttractRigidbody getCore() unsigned int size() void setCore(CppAttractRigidbody&) + vector[vector[double]] getWeights() cdef cppclass CppMcopForceField "PTools::McopForceField": CppMcopForceField(CppBaseAttractForceField&, double) @@ -236,6 +237,9 @@ cdef class Mcoprigid: def setCore(self, AttractRigidbody core): self.thisptr.setCore(deref(core.thisptr)) + def getWeights(self): + return self.thisptr.getWeights() + def __len__(self): return self.thisptr.size() diff --git a/headers/mcopff.h b/headers/mcopff.h index e7898d1..8b53e54 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -125,8 +125,8 @@ class Mcoprigid //multicopy rigidbody AttractMcop& getRegion(int i){return _vregion[i];}; size_t size() const {return _vregion.size();}; - virtual void setRotation(bool value) {_core.setRotation(value)} ///< allow/disallow rotation - virtual void setTranslation(bool value) {_core.setTranslation(value)} ///< allow/disallow translation + virtual void setRotation(bool value) {_core.setRotation(value);}; ///< allow/disallow rotation + virtual void setTranslation(bool value) {_core.setTranslation(value);}; ///< allow/disallow translation private: From bab931ba6a9bbe0e0f0908c2fc55a1183e5f7ef7 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Thu, 21 Apr 2016 17:24:06 +0200 Subject: [PATCH 32/90] Created C++ functions denormalize_weights() and normalize_weights() in Mcoprigid class. Did binding interface for these functions. Added _denorm_weights attribute to Mcoprigid class. --- bindings/mcopff.pyx | 8 ++++++++ headers/mcopff.h | 3 +++ 2 files changed, 11 insertions(+) diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx index 127a115..d1392e2 100644 --- a/bindings/mcopff.pyx +++ b/bindings/mcopff.pyx @@ -35,6 +35,8 @@ cdef extern from "mcopff.h" namespace "PTools": unsigned int size() void setCore(CppAttractRigidbody&) vector[vector[double]] getWeights() + void denormalize_weights() + void normalize_weights() cdef cppclass CppMcopForceField "PTools::McopForceField": CppMcopForceField(CppBaseAttractForceField&, double) @@ -240,6 +242,12 @@ cdef class Mcoprigid: def getWeights(self): return self.thisptr.getWeights() + def denormalize_weights(self): + self.thisptr.denormalize_weights() + + def normalize_weigths(self): + self.thisptr.normalize_weights() + def __len__(self): return self.thisptr.size() diff --git a/headers/mcopff.h b/headers/mcopff.h index 8b53e54..6b43763 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -115,6 +115,8 @@ class Mcoprigid //multicopy rigidbody void PrintWeights(); std::vector > getWeights(){return _weights;}; + void denormalize_weights(); + void normalize_weights(); void ReadMcoprigidPDB(const std::string name); void ReadMcoprigidPDB(std::istream& file, AttractRigidbody& core, std::vector& regions); @@ -137,6 +139,7 @@ class Mcoprigid //multicopy rigidbody Coord3D _center ; ///
> _weights; + std::vector< std::vector > _denorm_weights; friend class McopForceField; From 3822c7fd7095adde42738a79cfb9f148459f5acf Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Thu, 21 Apr 2016 17:24:23 +0200 Subject: [PATCH 33/90] Created C++ functions denormalize_weights() and normalize_weights() in Mcoprigid class. Did binding interface for these functions. Added _denorm_weights attribute to Mcoprigid class. --- src/mcopff.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/mcopff.cpp b/src/mcopff.cpp index 6df12a1..6533994 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -1,6 +1,7 @@ #include "mcopff.h" #include #include +#include namespace PTools { @@ -24,10 +25,13 @@ void Mcoprigid::iniWeights(){ for(int i=0; i < _vregion.size(); i++){ std::vector newvector; _weights.push_back(newvector); + _denorm_weights.push_back(newvector); for(int j=0; j < _vregion[i].size(); j++){ dbl weight = 1/_vregion[i].size(); _weights[i].push_back(weight); + _denorm_weights[i].push_back(0); } + denormalize_weights(); } } @@ -148,6 +152,29 @@ uint Mcoprigid::line_to_copy_number(std::string line){ return std::atoi(line.substr(15,line.size()-15).c_str()); } +void Mcoprigid::denormalize_weights(){ + for(uint i; i < _weights.size(); i++){ + dbl max_weight = *max_element(_weights[i].begin(), _weights[i].end()); + for(uint j; j < _weights[i].size(); j++){ + _denorm_weights[i][j] = sqrt(_weights[i][j]/max_weight); + } + } +} + +void Mcoprigid::normalize_weights(){ + + for(uint i; i < _denorm_weights.size(); i++){ + dbl sum_squared_denorm_weights = 0; + for(uint j; j < _denorm_weights[i].size(); j++){ + sum_squared_denorm_weights += pow(_denorm_weights[i][j], 2); + } + for(uint j; j < _denorm_weights[i].size(); j++){ + _weights[i][j] = pow(_denorm_weights[i][j], 2)/sum_squared_denorm_weights; + } + } +} + + /////////////////// -- Class Mcop -- //////////////////// Mcop::Mcop(std::string filename){ From 8f23efda4f2de13f87bf3d1cb79d90054b2f2b5a Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Thu, 21 Apr 2016 17:41:18 +0200 Subject: [PATCH 34/90] Added C++ function getWeights(), normalize_weights(), and denormalize_weights() in McopForceField class. They all call their equivalent function in McopForceFeild's _receptor attribute (of type Mcoprigid). Added these functions to binding interface. --- bindings/mcopff.pyx | 14 +++++++++++++- headers/mcopff.h | 4 ++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx index d1392e2..93b7d64 100644 --- a/bindings/mcopff.pyx +++ b/bindings/mcopff.pyx @@ -39,6 +39,9 @@ cdef extern from "mcopff.h" namespace "PTools": void normalize_weights() cdef cppclass CppMcopForceField "PTools::McopForceField": CppMcopForceField(CppBaseAttractForceField&, double) + vector[vector[double]] getWeights() + void denormalize_weights() + void normalize_weights() cdef class Mcop: @@ -269,4 +272,13 @@ cdef class McopForceField: def __dealloc__(self): if self.thisptr: del self.thisptr - self.thisptr = 0 \ No newline at end of file + self.thisptr = 0 + + def getWeights(self): + return self.thisptr.getWeights() + + def denormalize_weights(self): + self.thisptr.denormalize_weights() + + def normalize_weigths(self): + self.thisptr.normalize_weights() \ No newline at end of file diff --git a/headers/mcopff.h b/headers/mcopff.h index 6b43763..dac85b3 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -173,6 +173,10 @@ class McopForceField: public ForceField uint ProblemSize() {return 6;}; void initMinimization(){}; + std::vector > getWeights(){return _receptor.getWeights();}; + void denormalize_weights(){_receptor.denormalize_weights();}; + void normalize_weights(){_receptor.normalize_weights();}; + private: BaseAttractForceField& _ff ; From 1abd458f14d5daa83463c8281158adbcceb2092f Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Fri, 22 Apr 2016 10:21:56 +0200 Subject: [PATCH 35/90] Defined overriden ProblemSize() function in McopForceField. --- headers/mcopff.h | 2 +- src/mcopff.cpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/headers/mcopff.h b/headers/mcopff.h index dac85b3..0f33cfc 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -170,7 +170,7 @@ class McopForceField: public ForceField void calculate_weights(Mcoprigid& lig, bool print=false); - uint ProblemSize() {return 6;}; + uint ProblemSize(); void initMinimization(){}; std::vector > getWeights(){return _receptor.getWeights();}; diff --git a/src/mcopff.cpp b/src/mcopff.cpp index 6533994..1c45060 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -326,7 +326,16 @@ void McopForceField::calculate_weights(Mcoprigid& lig, bool print) } - +uint McopForceField::ProblemSize() +{ + uint size = 0; + if (_centered_ligand.getCore().hastranslation) size += 3; + if (_centered_ligand.getCore().hasrotation) size += 3; + for(uint i=0; i<_centered_ligand.getWeights().size(); i++){ + size += _centered_ligand.getWeights()[i].size(); + } + return size; +} /** \brief calculates energy of the system From 44c0f9e22487e0c507fa317619aac25afc9c1043 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Fri, 22 Apr 2016 11:35:29 +0200 Subject: [PATCH 36/90] Added normalize_weights() and denormalize_weights() in Lbfgs class. They call their equivalent function in Lbjgs's objToMinimize attribute (of type Forcefield) only if this attribute is of type McopForcefield. Added these functions to binding interface. --- bindings/lbfgs.pyx | 10 +++++++++- headers/lbfgs_interface.h | 2 ++ src/minimizers/lbfgs_interface.cpp | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/bindings/lbfgs.pyx b/bindings/lbfgs.pyx index fee4def..6c44cd9 100644 --- a/bindings/lbfgs.pyx +++ b/bindings/lbfgs.pyx @@ -8,6 +8,8 @@ cdef extern from "lbfgs_interface.h" namespace "PTools": vector[double] GetMinimizedVars() vector[double] GetMinimizedVarsAtIter(int) int GetNumberIter() + void denormalize_weights() + void normalize_weights() cdef class Lbfgs: @@ -40,4 +42,10 @@ cdef class Lbfgs: out = [] for i in xrange(vars.size()): out.append(vars[i]) - return out \ No newline at end of file + return out + + def denormalize_weights(self): + self.thisptr.denormalize_weights() + + def normalize_weigths(self): + self.thisptr.normalize_weights() \ No newline at end of file diff --git a/headers/lbfgs_interface.h b/headers/lbfgs_interface.h index a149275..160be94 100644 --- a/headers/lbfgs_interface.h +++ b/headers/lbfgs_interface.h @@ -27,6 +27,8 @@ class Lbfgs std::vector GetMinimizedVarsAtIter(uint iter); int GetNumberIter() {return m_opt->niter;} + void denormalize_weights(); + void normalize_weights(); diff --git a/src/minimizers/lbfgs_interface.cpp b/src/minimizers/lbfgs_interface.cpp index a658d95..f70bb9f 100644 --- a/src/minimizers/lbfgs_interface.cpp +++ b/src/minimizers/lbfgs_interface.cpp @@ -209,7 +209,25 @@ if (iter>=m_vars_over_time.size()) return m_vars_over_time[iter]; } +void Lbfgs::denormalize_weights() +{ + if (McopForceField * p = dynamic_cast(&objToMinimize)){ + // objToMinimize is or is of type McopForceField + objToMinimize.denormalize_weights(); + } + //else + // objToMinimize is not a McopForceField +}; +void Lbfgs::normalize_weights() +{ + if (McopForceField * p = dynamic_cast(&objToMinimize)){ + // objToMinimize is or is of type McopForceField + objToMinimize.normalize_weights(); + } + //else + // objToMinimize is not a McopForceField +}; From 8b8241311ad834bac69ee71a382ec7b5f48f80af Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Fri, 22 Apr 2016 14:24:49 +0200 Subject: [PATCH 37/90] Before each minimization step, denormalize weights (call denormalize_weights() at start of Function() in McopForceField). After each minimization step, normalize weights (call normalize_weights() at end of Function() in McopForceField and after minimize() in attract.py). --- PyAttract/attract.py | 5 ++++- src/mcopff.cpp | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/PyAttract/attract.py b/PyAttract/attract.py index 63158d5..fb790a0 100755 --- a/PyAttract/attract.py +++ b/PyAttract/attract.py @@ -399,9 +399,12 @@ def check_ffversion(reduced): #forcefield.SetRestraint(rstk) if option.regions: lbfgs_minimizer=Lbfgs(mcopff) + lbfgs_minimizer.minimize(niter) + lbfgs_minimizer.normalize_weights() else : lbfgs_minimizer=ff_specs['minimizer_class'](forcefield) - lbfgs_minimizer.minimize(niter) + lbfgs_minimizer.minimize(niter) + X=lbfgs_minimizer.GetMinimizedVars() #optimized freedom variables after minimization diff --git a/src/mcopff.cpp b/src/mcopff.cpp index 1c45060..ab095f2 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -338,6 +338,7 @@ uint McopForceField::ProblemSize() } + /** \brief calculates energy of the system * * this functions returns nonbonded energy of a receptor with multicopy and a ligand without copy. @@ -345,6 +346,7 @@ uint McopForceField::ProblemSize() */ dbl McopForceField::Function(const Vdouble & v) { + denormalize_weights(); dbl ener = 0.0 ; dbl enercopy =0.0; @@ -420,6 +422,7 @@ dbl McopForceField::Function(const Vdouble & v) } + normalize_weights(); return ener + enercopy; } From e5825308cfe6a968f1cfe4a5e344d5c887d26836 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Mon, 25 Apr 2016 15:12:49 +0200 Subject: [PATCH 38/90] Fixed lbjgs_interface.cpp compilation error in denormalize and normalize functions. --- src/minimizers/lbfgs_interface.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/minimizers/lbfgs_interface.cpp b/src/minimizers/lbfgs_interface.cpp index f70bb9f..ddf00fa 100644 --- a/src/minimizers/lbfgs_interface.cpp +++ b/src/minimizers/lbfgs_interface.cpp @@ -1,4 +1,5 @@ #include "lbfgs_interface.h" +#include "mcopff.h" #include #include @@ -213,21 +214,25 @@ void Lbfgs::denormalize_weights() { if (McopForceField * p = dynamic_cast(&objToMinimize)){ // objToMinimize is or is of type McopForceField - objToMinimize.denormalize_weights(); + ForceField& r_objToMinimize = objToMinimize; + McopForceField& r_Mcop_objToMinimize = dynamic_cast(r_objToMinimize); + r_Mcop_objToMinimize.denormalize_weights(); } //else // objToMinimize is not a McopForceField -}; +} void Lbfgs::normalize_weights() { if (McopForceField * p = dynamic_cast(&objToMinimize)){ // objToMinimize is or is of type McopForceField - objToMinimize.normalize_weights(); + ForceField& r_objToMinimize = objToMinimize; + McopForceField& r_Mcop_objToMinimize = dynamic_cast(r_objToMinimize); + r_Mcop_objToMinimize.normalize_weights(); } //else // objToMinimize is not a McopForceField -}; +} From 050dc7d09d4f311a3ab8f1d8f2519b204ae4dd62 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Mon, 25 Apr 2016 15:14:52 +0200 Subject: [PATCH 39/90] Changed McopForceField's Function() (calculates energies) to use denormalized weights. --- src/mcopff.cpp | 67 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/src/mcopff.cpp b/src/mcopff.cpp index ab095f2..e196303 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -348,7 +348,8 @@ dbl McopForceField::Function(const Vdouble & v) { denormalize_weights(); - dbl ener = 0.0 ; + dbl ener_region = 0.0 ; + dbl ener_core = 0.0 ; dbl enercopy =0.0; // 1) put the objects to the right place @@ -358,10 +359,28 @@ dbl McopForceField::Function(const Vdouble & v) Mcoprigid & lig = _moved_ligand ; assert(lig._vregion.size()==0); - + //TODO: take into account if not rotation or no translation lig.AttractEulerRotate(v[0],v[1],v[2]); lig.Translate(Coord3D(v[3],v[4],v[5])); + assert(_receptor._vregion.size() == _receptor._weights.size()); + assert(_receptor._vregion.size() == _receptor._denorm_weights.size()); + + //Update the denormalized weights + + uint k = 0; + for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++){ + assert( ref_ensemble.size() == ref_denorm_weights.size()); + AttractMcop& ref_ensemble = _receptor._vregion[loopregion]; + std::vector& ref_denorm_weights = _receptor._denorm_weights[loopregion]; + for (uint copynb = 0; copynb < ref_ensemble.size(); copynb++){ + k++; + dbl& denorm_weight = ref_denorm_weights[copynb]; + denorm_weight += v[5+k]; // ??? += or = ??? + } + } + + normalize_weights(); //2) calculates the energy @@ -369,11 +388,11 @@ dbl McopForceField::Function(const Vdouble & v) //2.1) core ligand body with core receptor AttractPairList pl (_receptor._core, lig._core, _cutoff ); - ener += _ff.nonbon8(_receptor._core, lig._core, pl ); + ener_core += _ff.nonbon8(_receptor._core, lig._core, pl ); //2.2) core lignd with receptor copies: - assert(_receptor._vregion.size() == _receptor._weights.size()); + for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++) { @@ -383,14 +402,18 @@ dbl McopForceField::Function(const Vdouble & v) AttractMcop& ref_ensemble = _receptor._vregion[loopregion]; + std::vector& ref_denorm_weights = _receptor._denorm_weights[loopregion]; std::vector& ref_weights = _receptor._weights[loopregion]; + assert( ref_ensemble.size() == ref_denorm_weights.size()); assert( ref_ensemble.size() == ref_weights.size()); + dbl max_weight = *max_element(ref_weights.begin(), ref_weights.end()); + for (uint copynb = 0; copynb < ref_ensemble.size(); copynb++) { - dbl& weight = ref_weights[copynb]; + dbl& denorm_weight = ref_denorm_weights[copynb]; AttractRigidbody& copy = ref_ensemble[copynb]; AttractPairList cpl ( lig._core, copy, _cutoff ); @@ -399,8 +422,30 @@ dbl McopForceField::Function(const Vdouble & v) // dbl e = _ff.nonbon8( lig._core, _receptor._vregion[loopregion][copy] , cpl ); dbl e = _ff.nonbon8_forces(lig._core, copy, cpl, coreforce, copyforce); - enercopy += e * weight;//lig._weights[loopregion][copy]; + //TODO : vecteur Eik + enercopy += e*pow(denorm_weight, 2);//lig._denorm_weights[loopregion][copy]; + + + + + } + ener_region += max_weight*enercopy; + + } + + for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++) + { + AttractMcop& ref_ensemble = _receptor._vregion[loopregion]; + std::vector& ref_weights = _receptor._weights[loopregion]; + + for (uint copynb = 0; copynb < ref_ensemble.size(); copynb++) + { + dbl& weight = ref_weights[copynb]; + AttractRigidbody& copy = ref_ensemble[copynb]; + std::vector copyforce(copy.Size()); + std::vector coreforce(lig._core.Size()); + //multiply forces by copy weight: for(uint i=0; i Date: Mon, 25 Apr 2016 15:50:07 +0200 Subject: [PATCH 40/90] Made McopForceField's Function() more generic in case there is no rotation or no translation. --- src/mcopff.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/mcopff.cpp b/src/mcopff.cpp index e196303..4d7de54 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -368,15 +368,17 @@ dbl McopForceField::Function(const Vdouble & v) //Update the denormalized weights - uint k = 0; + uint svptr = 0; // stateVars 'pointer' + if (lig.getCore().hasrotation) svptr += 3; + if (lig.getCore().hastranslation) svptr += 3; for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++){ assert( ref_ensemble.size() == ref_denorm_weights.size()); AttractMcop& ref_ensemble = _receptor._vregion[loopregion]; std::vector& ref_denorm_weights = _receptor._denorm_weights[loopregion]; for (uint copynb = 0; copynb < ref_ensemble.size(); copynb++){ - k++; + svptr += 1; dbl& denorm_weight = ref_denorm_weights[copynb]; - denorm_weight += v[5+k]; // ??? += or = ??? + denorm_weight += v[svptr]; // ??? += or = ??? } } From 588198ad855e2796aca78bb128b5cb074f8f415d Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Mon, 25 Apr 2016 17:07:22 +0200 Subject: [PATCH 41/90] Fix error in McopForceField's Function(): put force calculations in same loop as energy calculations. --- src/mcopff.cpp | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/src/mcopff.cpp b/src/mcopff.cpp index 4d7de54..5993f96 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -416,6 +416,7 @@ dbl McopForceField::Function(const Vdouble & v) { dbl& denorm_weight = ref_denorm_weights[copynb]; + dbl& weight = ref_weights[copynb]; AttractRigidbody& copy = ref_ensemble[copynb]; AttractPairList cpl ( lig._core, copy, _cutoff ); @@ -427,28 +428,7 @@ dbl McopForceField::Function(const Vdouble & v) //TODO : vecteur Eik enercopy += e*pow(denorm_weight, 2);//lig._denorm_weights[loopregion][copy]; - - - - } - ener_region += max_weight*enercopy; - - } - - - for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++) - { - AttractMcop& ref_ensemble = _receptor._vregion[loopregion]; - std::vector& ref_weights = _receptor._weights[loopregion]; - - for (uint copynb = 0; copynb < ref_ensemble.size(); copynb++) - { - dbl& weight = ref_weights[copynb]; - AttractRigidbody& copy = ref_ensemble[copynb]; - std::vector copyforce(copy.Size()); - std::vector coreforce(lig._core.Size()); - - //multiply forces by copy weight: + //multiply forces by copy weight: for(uint i=0; i Date: Mon, 25 Apr 2016 19:21:00 +0200 Subject: [PATCH 42/90] Coded McopForceField's Derivatives() : Rotation/Translation but not weights derivative yet. Not compiled yet. --- src/mcopff.cpp | 125 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 109 insertions(+), 16 deletions(-) diff --git a/src/mcopff.cpp b/src/mcopff.cpp index 5993f96..e31c442 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -376,9 +376,9 @@ dbl McopForceField::Function(const Vdouble & v) AttractMcop& ref_ensemble = _receptor._vregion[loopregion]; std::vector& ref_denorm_weights = _receptor._denorm_weights[loopregion]; for (uint copynb = 0; copynb < ref_ensemble.size(); copynb++){ - svptr += 1; dbl& denorm_weight = ref_denorm_weights[copynb]; denorm_weight += v[svptr]; // ??? += or = ??? + svptr += 1; } } @@ -416,7 +416,7 @@ dbl McopForceField::Function(const Vdouble & v) { dbl& denorm_weight = ref_denorm_weights[copynb]; - dbl& weight = ref_weights[copynb]; + //dbl& weight = ref_weights[copynb]; AttractRigidbody& copy = ref_ensemble[copynb]; AttractPairList cpl ( lig._core, copy, _cutoff ); @@ -430,11 +430,11 @@ dbl McopForceField::Function(const Vdouble & v) //multiply forces by copy weight: for(uint i=0; i& ref_weights = _receptor._weights[loopregion]; + dbl max_weight = *max_element(ref_weights.begin(), ref_weights.end()); + + for (uint i=0; i< pLigCentered->m_activeAtoms.size(); i++) + { + uint atomIndex = pLigCentered->m_activeAtoms[i]; -Coord3D ligtransForces; //translational forces for the ligand: -for(uint i=0; i<_moved_ligand._core.Size(); i++) - { - ligtransForces += _moved_ligand._core.m_forces[i]; - } + Coord3D coords = pLigCentered->GetCoords(atomIndex); + X = coords.x; + Y = coords.y; + Z = coords.z; + xar=X*crot+Y*srot; + yar=-X*srot+Y*crot; + pm[0][0]=-xar*cssp-yar*cp-Z*sssp ; + pm[1][0]=xar*cscp-yar*sp+Z*sscp ; + pm[2][0]=0.0 ; + + pm[0][1]=-xar*sscp+Z*cscp ; + pm[1][1]=-xar*sssp+Z*cssp ; + pm[2][1]=-xar*cs-Z*ss ; + + pm[0][2]=yar*cscp+xar*sp ; + pm[1][2]=yar*cssp-xar*cp ; + pm[2][2]=-yar*ss ; + + + g[svptr + 0] += pm[0][j] * pLigMoved->m_forces[atomIndex].x * max_weight; + g[svptr + 1] += pm[1][j] * pLigMoved->m_forces[atomIndex].y * max_weight; + g[svptr + 2] += pm[2][j] * pLigMoved->m_forces[atomIndex].z * max_weight; + } -Coord3D receptortransForces; + } + svptr += 3; + +} + +//sum the forces over x, y and z: calculate de translational forces +if (lig.getCore().hastranslation){ + g[svptr+0] = 0; + g[svptr+1] = 0; + g[svptr+2] = 0; + + + for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++){ + + std::vector& ref_weights = _receptor._weights[loopregion]; + dbl max_weight = *max_element(ref_weights.begin(), ref_weights.end()); + Coord3D ligtransForces; //translational forces for the ligand from loopregion + + for(uint i=0; i<_moved_ligand._core.Size(); i++){ + ligtransForces += _moved_ligand._core.m_forces[i]; + } + + g[svptr+0] += ligtransForces.x * max_weight; + g[svptr+1] += ligtransForces.y * max_weight; + g[svptr+2] += ligtransForces.z * max_weight; + } + + svptr += 3; +} + + + + +/*Coord3D receptortransForces; //translational forces for the receptor: for(uint i=0; i<_receptor._core.Size(); i++) { -receptortransForces+= _receptor._core.m_forces[i]; + receptortransForces+= _receptor._core.m_forces[i]; } - for (uint i=0; i <_receptor._vregion.size(); i++) - { +{ AttractMcop& ens = _receptor._vregion[i]; std::vector & weights = _receptor._weights[i]; @@ -487,7 +580,7 @@ for (uint i=0; i <_receptor._vregion.size(); i++) //TODO DEBUG: std::cout << "differences between the two forces: " << (ligtransForces - receptortransForces).toString() << std::endl ; - } + }*/ From d41fbd7c0d0f9e6c3759bd7a89ba659b9772c3ef Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Mon, 25 Apr 2016 19:57:41 +0200 Subject: [PATCH 43/90] Added _mcop_E attribute to McopForceField. Coded McopForceField's Derivatives(): the weight derivatives calculations. Not compiled yet. --- headers/mcopff.h | 1 + src/mcopff.cpp | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/headers/mcopff.h b/headers/mcopff.h index 0f33cfc..81d1880 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -187,6 +187,7 @@ class McopForceField: public ForceField Mcoprigid _centered_ligand ; Mcoprigid _moved_ligand ; Mcoprigid _receptor; + std::vecor< std::vector > _mcop_E; //Energies diff --git a/src/mcopff.cpp b/src/mcopff.cpp index e31c442..5db1aff 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -401,7 +401,8 @@ dbl McopForceField::Function(const Vdouble & v) //calculates interaction energy between receptor copies and ligand body: // std::vector Eik; - + std::vector newvector; + _mcop_E.push_back(newvector); AttractMcop& ref_ensemble = _receptor._vregion[loopregion]; std::vector& ref_denorm_weights = _receptor._denorm_weights[loopregion]; @@ -425,7 +426,8 @@ dbl McopForceField::Function(const Vdouble & v) // dbl e = _ff.nonbon8( lig._core, _receptor._vregion[loopregion][copy] , cpl ); dbl e = _ff.nonbon8_forces(lig._core, copy, cpl, coreforce, copyforce); - //TODO : vecteur Eik + _mcop_E[copynb].push_back(e); + enercopy += e*pow(denorm_weight, 2);//lig._denorm_weights[loopregion][copy]; //multiply forces by copy weight: @@ -553,8 +555,23 @@ if (lig.getCore().hastranslation){ svptr += 3; } +// Calculate de weight derivative - +assert(_receptor._vregion.size() == _mcop_E.size()); +uint k = 0; +for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++){ + + std::vector& ref_weights = _receptor._weights[loopregion]; + std::vector& ref_denorm_weights = _receptor._denorm_weights[loopregion]; + std::vector& ref_mcop_E = _mcop_E[loopregion]; + assert(ref_weights.size() == _ref_mcop_E.size()); + + dbl max_weight = *max_element(ref_weights.begin(), ref_weights.end()); + for(uint copynb; copynb < _mcop_E[loopregion].size(); copynb++){ + // weight derivative function + g[svptr + k] = 2*max_weight*ref_denorm_weights[copynb]*_ref_mcop_E[copynb]; + k++; + } /*Coord3D receptortransForces; //translational forces for the receptor: for(uint i=0; i<_receptor._core.Size(); i++) From 5b218f1c9eb798f000ac4001d319668118bbeedf Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 26 Apr 2016 13:27:01 +0200 Subject: [PATCH 44/90] Fixed McopForceField's Derivatives() and can now compile. --- headers/mcopff.h | 2 +- src/mcopff.cpp | 43 +++++++++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/headers/mcopff.h b/headers/mcopff.h index 81d1880..1385760 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -187,7 +187,7 @@ class McopForceField: public ForceField Mcoprigid _centered_ligand ; Mcoprigid _moved_ligand ; Mcoprigid _receptor; - std::vecor< std::vector > _mcop_E; //Energies + std::vector< std::vector > _mcop_E; //Energies diff --git a/src/mcopff.cpp b/src/mcopff.cpp index 5db1aff..9628c6f 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -456,6 +456,7 @@ dbl McopForceField::Function(const Vdouble & v) void McopForceField::Derivatives(const Vdouble& v, Vdouble & g ) { +Mcoprigid & lig = _moved_ligand; uint svptr = 0; // stateVars 'pointer' // calculate de rotational forces: @@ -472,16 +473,16 @@ if (lig.getCore().hasrotation){ g[svptr+1] = 0; g[svptr+2] = 0; - cs=cos(ssi); - cp=cos(phi); - ss=sin(ssi); - sp=sin(phi); + cs=cos(v[svptr+1]); + cp=cos(v[svptr+0]); + ss=sin(v[svptr+1]); + sp=sin(v[svptr+0]); cscp=cs*cp; cssp=cs*sp; sscp=ss*cp; sssp=ss*sp; - crot=cos(rot); - srot=sin(rot); + crot=cos(v[svptr+2]); + srot=sin(v[svptr+2]); // for the x, y and z coordinates, we need // the coordinates of the centered, non-translated molecule @@ -519,10 +520,11 @@ if (lig.getCore().hasrotation){ pm[1][2]=yar*cssp-xar*cp ; pm[2][2]=-yar*ss ; - - g[svptr + 0] += pm[0][j] * pLigMoved->m_forces[atomIndex].x * max_weight; - g[svptr + 1] += pm[1][j] * pLigMoved->m_forces[atomIndex].y * max_weight; - g[svptr + 2] += pm[2][j] * pLigMoved->m_forces[atomIndex].z * max_weight; + for(uint j=0; j < 3; j++){ + g[svptr + j] += pm[0][j] * pLigMoved->m_forces[atomIndex].x * max_weight; + g[svptr + j] += pm[1][j] * pLigMoved->m_forces[atomIndex].y * max_weight; + g[svptr + j] += pm[2][j] * pLigMoved->m_forces[atomIndex].z * max_weight; + } } } @@ -561,17 +563,18 @@ assert(_receptor._vregion.size() == _mcop_E.size()); uint k = 0; for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++){ - std::vector& ref_weights = _receptor._weights[loopregion]; - std::vector& ref_denorm_weights = _receptor._denorm_weights[loopregion]; - std::vector& ref_mcop_E = _mcop_E[loopregion]; - assert(ref_weights.size() == _ref_mcop_E.size()); + std::vector& ref_weights = _receptor._weights[loopregion]; + std::vector& ref_denorm_weights = _receptor._denorm_weights[loopregion]; + std::vector& ref_mcop_E = _mcop_E[loopregion]; + assert(ref_weights.size() == _ref_mcop_E.size()); - dbl max_weight = *max_element(ref_weights.begin(), ref_weights.end()); - for(uint copynb; copynb < _mcop_E[loopregion].size(); copynb++){ - // weight derivative function - g[svptr + k] = 2*max_weight*ref_denorm_weights[copynb]*_ref_mcop_E[copynb]; - k++; - } + dbl max_weight = *max_element(ref_weights.begin(), ref_weights.end()); + for(uint copynb; copynb < _mcop_E[loopregion].size(); copynb++){ + // weight derivative function + g[svptr + k] = 2*max_weight*ref_denorm_weights[copynb]*ref_mcop_E[copynb]; + k++; + } +} /*Coord3D receptortransForces; //translational forces for the receptor: for(uint i=0; i<_receptor._core.Size(); i++) From 3b698700f776d994a9d6b354fc55c1b850c105e4 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 26 Apr 2016 14:17:10 +0200 Subject: [PATCH 45/90] In McopForcefield's Function(), absolute changes (instead of relative) to _denorm_weights at each min step. --- src/mcopff.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mcopff.cpp b/src/mcopff.cpp index 9628c6f..89d9a96 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -27,7 +27,7 @@ void Mcoprigid::iniWeights(){ _weights.push_back(newvector); _denorm_weights.push_back(newvector); for(int j=0; j < _vregion[i].size(); j++){ - dbl weight = 1/_vregion[i].size(); + dbl weight = 1/(double)_vregion[i].size(); _weights[i].push_back(weight); _denorm_weights[i].push_back(0); } @@ -377,7 +377,7 @@ dbl McopForceField::Function(const Vdouble & v) std::vector& ref_denorm_weights = _receptor._denorm_weights[loopregion]; for (uint copynb = 0; copynb < ref_ensemble.size(); copynb++){ dbl& denorm_weight = ref_denorm_weights[copynb]; - denorm_weight += v[svptr]; // ??? += or = ??? + denorm_weight = v[svptr] + 1/(double)ref_denorm_weights.size(); //delta weight + original weight svptr += 1; } } From d5eb4c79edea3de0bf3193c8fa6cb8445583280b Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 26 Apr 2016 14:43:02 +0200 Subject: [PATCH 46/90] Added FindCenter() to McopRigid class and added it to binding interface. --- bindings/mcopff.pyx | 4 ++++ headers/mcopff.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx index 93b7d64..07f475e 100644 --- a/bindings/mcopff.pyx +++ b/bindings/mcopff.pyx @@ -37,6 +37,7 @@ cdef extern from "mcopff.h" namespace "PTools": vector[vector[double]] getWeights() void denormalize_weights() void normalize_weights() + Coord3D FindCenter() cdef cppclass CppMcopForceField "PTools::McopForceField": CppMcopForceField(CppBaseAttractForceField&, double) vector[vector[double]] getWeights() @@ -251,6 +252,9 @@ cdef class Mcoprigid: def normalize_weigths(self): self.thisptr.normalize_weights() + def FindCenter(self): + return self.FindCenter() + def __len__(self): return self.thisptr.size() diff --git a/headers/mcopff.h b/headers/mcopff.h index 1385760..5b624bf 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -111,7 +111,7 @@ class Mcoprigid //multicopy rigidbody void AttractEulerRotate(const dbl& phi, const dbl& ssi, const dbl& rot); void Translate(const Coord3D& c); - + Coord3D FindCenter(){_core.FindCenter();}; void PrintWeights(); std::vector > getWeights(){return _weights;}; From db4a2181ea5314895e9a0b926dae8e327bf785f3 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 26 Apr 2016 14:55:39 +0200 Subject: [PATCH 47/90] Added if statement in attract.py: if mcop option, ligand is lig.getCore() --- PyAttract/attract.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/PyAttract/attract.py b/PyAttract/attract.py index fb790a0..ed3e682 100755 --- a/PyAttract/attract.py +++ b/PyAttract/attract.py @@ -368,7 +368,10 @@ def check_ffversion(reduced): rotnb+=1 print "----- Rotation nb %i -----"%rotnb minimcounter=0 - ligand=AttractRigidbody(lig) + if options.regions: + ligand=AttractRigidbody(lig.getCore()) + else: + ligand=AttractRigidbody(lig) center=ligand.FindCenter() ligand.Translate(Coord3D()-center) #set ligand center of mass to 0,0,0 From 60a1768f69b44afad452975993fbd8d51df0c411 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 26 Apr 2016 16:23:22 +0200 Subject: [PATCH 48/90] Fixed Mcoprigid's FindCenter() in binding interface. --- bindings/mcopff.pyx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx index 07f475e..5734959 100644 --- a/bindings/mcopff.pyx +++ b/bindings/mcopff.pyx @@ -253,7 +253,13 @@ cdef class Mcoprigid: self.thisptr.normalize_weights() def FindCenter(self): - return self.FindCenter() + #cdef Coord3D c = Coord3D() + #cdef CppCoord3D cpp = self.thisptr.FindCenter() + #c.x = cpp.x + #c.y = cpp.y + #c.z = cpp.z + #return c + return self.getCore().FindCenter() def __len__(self): return self.thisptr.size() From e12bd429c52135f0ce71f4b8354767374064937e Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 26 Apr 2016 16:37:00 +0200 Subject: [PATCH 49/90] Added Mcoprigid's setTranslation(), setRotation(), Translate(), and AttractEulerRotate() to binding interface. --- bindings/mcopff.pyx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx index 5734959..c6174a8 100644 --- a/bindings/mcopff.pyx +++ b/bindings/mcopff.pyx @@ -38,6 +38,11 @@ cdef extern from "mcopff.h" namespace "PTools": void denormalize_weights() void normalize_weights() Coord3D FindCenter() + void setTranslation(int) + void setRotation(int) + void Translate(CppCoord3D&) + void AttractEulerRotate(double, double, double) + cdef cppclass CppMcopForceField "PTools::McopForceField": CppMcopForceField(CppBaseAttractForceField&, double) vector[vector[double]] getWeights() @@ -261,6 +266,18 @@ cdef class Mcoprigid: #return c return self.getCore().FindCenter() + def setTranslation(self, flag): + self.thisptr.setTranslation(flag) + + def setRotation(self, flag): + self.thisptr.setRotation(flag) + + def AttractEulerRotate(self, double phi, double ssi, double rot): + self.thisptr.AttractEulerRotate(phi, ssi, rot) + + def Translate(self, Coord3D tr): + self.thisptr.Translate(deref(tr.thisptr)) + def __len__(self): return self.thisptr.size() From cc1ecb7cc8ea081fde4da308d4ed94c11fcc9809 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 26 Apr 2016 16:47:21 +0200 Subject: [PATCH 50/90] Typo fix. --- PyAttract/attract.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyAttract/attract.py b/PyAttract/attract.py index ed3e682..7ba8813 100755 --- a/PyAttract/attract.py +++ b/PyAttract/attract.py @@ -391,7 +391,7 @@ def check_ffversion(reduced): rec.setTranslation(False) rec.setRotation(False) - if option.regions: + if options.regions: mcopff.setReceptor(rec) mcopff.setLigand(lig) else: From 4429c7d26bfd792a4859b7558752e417c19aaeb8 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 26 Apr 2016 16:48:09 +0200 Subject: [PATCH 51/90] Added McopForceField's setReceptor() and setLigand() to binding interface. --- bindings/mcopff.pyx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx index c6174a8..854ff7d 100644 --- a/bindings/mcopff.pyx +++ b/bindings/mcopff.pyx @@ -48,6 +48,8 @@ cdef extern from "mcopff.h" namespace "PTools": vector[vector[double]] getWeights() void denormalize_weights() void normalize_weights() + void setReceptor(CppMcoprigid&) + void setLigand(CppMcoprigid&) cdef class Mcop: @@ -308,4 +310,10 @@ cdef class McopForceField: self.thisptr.denormalize_weights() def normalize_weigths(self): - self.thisptr.normalize_weights() \ No newline at end of file + self.thisptr.normalize_weights() + + def setReceptor(self, Mcoprigid rec): + self.thisptr.setReceptor(deref(rec.thisptr)) + + def setLigand(self, Mcoprigid lig): + self.thisptr.setLigand(deref(lig.thisptr)) \ No newline at end of file From 62479242ddcdcd5e5b7168085b1f3b73ffede536 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 26 Apr 2016 16:49:40 +0200 Subject: [PATCH 52/90] typo fix --- PyAttract/attract.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyAttract/attract.py b/PyAttract/attract.py index 7ba8813..2a1b1b4 100755 --- a/PyAttract/attract.py +++ b/PyAttract/attract.py @@ -400,7 +400,7 @@ def check_ffversion(reduced): rstk=minim['rstk'] #restraint force #if rstk>0.0: #forcefield.SetRestraint(rstk) - if option.regions: + if options.regions: lbfgs_minimizer=Lbfgs(mcopff) lbfgs_minimizer.minimize(niter) lbfgs_minimizer.normalize_weights() From b3598eb84264840652769d931768a7e28fef5409 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 26 Apr 2016 18:46:54 +0200 Subject: [PATCH 53/90] In binding interface, made lbfgs class's ff attribute of type ForceField instead of BaseAttractForceField (modifications in lbjfgs.pyx and attractforcefield.pyx). In binding interface, changed McopForceField into a subclass of ForceField (modifications in mcopff.pyx). --- bindings/attractforcefield.pyx | 53 ++++++++++++++++++++++++---------- bindings/lbfgs.pyx | 6 ++-- bindings/mcopff.pyx | 25 ++++++++++------ 3 files changed, 56 insertions(+), 28 deletions(-) diff --git a/bindings/attractforcefield.pyx b/bindings/attractforcefield.pyx index a600ccc..f41d119 100644 --- a/bindings/attractforcefield.pyx +++ b/bindings/attractforcefield.pyx @@ -37,11 +37,13 @@ cdef extern from "attractforcefield.h" namespace "PTools": cdef cppclass CppAttractForceField2 "PTools::AttractForceField2" (CppBaseAttractForceField) : CppAttractForceField2(string&, double) - -cdef class BaseAttractForceField: - cdef CppBaseAttractForceField * thisptr - - + +cdef class ForceField: + #cdef int junk_variable; # to avoid having empty cdef class + cdef CppForceField* thisptr + +cdef class BaseAttractForceField(ForceField): + cdef int junk_variable; # to avoid having empty cdef class cdef class AttractForceField2(BaseAttractForceField): @@ -49,6 +51,10 @@ cdef class AttractForceField2(BaseAttractForceField): #cdef CppAttractForceField2* thisptr def __cinit__(self, filename, cutoff): + # deallocate + del self.thisptr + self.thisptr = 0 + cdef char* c_filename cdef string * cppname @@ -63,23 +69,28 @@ cdef class AttractForceField2(BaseAttractForceField): def AddLigand(self, AttractRigidbody rig): self.rigidlist.append(rig) - self.thisptr.AddLigand(deref(rig.thisptr)) + cdef CppBaseAttractForceField* cpp_ptr = self.thisptr + cpp_ptr.AddLigand(deref(rig.thisptr)) def Function(self, vec): cdef vector[double] v for el in vec: v.push_back(el) - return self.thisptr.Function(v) + cdef CppBaseAttractForceField* cpp_ptr = self.thisptr + return cpp_ptr.Function(v) def getVdw(self): - return self.thisptr.getVdw() + cdef CppBaseAttractForceField* cpp_ptr = self.thisptr + return cpp_ptr.getVdw() def getCoulomb(self): - return self.thisptr.getCoulomb() + cdef CppBaseAttractForceField* cpp_ptr = self.thisptr + return cpp_ptr.getCoulomb() def nonbon8(self, AttractRigidbody rec, AttractRigidbody lig, AttractPairList pl, verbose=False): - return self.thisptr.nonbon8(deref(rec.thisptr), deref(lig.thisptr), deref(pl.thisptr), verbose) + cdef CppBaseAttractForceField* cpp_ptr = self.thisptr + return cpp_ptr.nonbon8(deref(rec.thisptr), deref(lig.thisptr), deref(pl.thisptr), verbose) cdef extern from "attractforcefield.h" namespace "PTools": @@ -98,33 +109,43 @@ cdef class AttractForceField1(BaseAttractForceField): def __cinit__(self, filename, cutoff): + # deallocate + del self.thisptr + self.thisptr = 0 + cdef char* c_filename cdef string * cppname c_filename = filename cppname = new string(c_filename) - self.thisptr = new CppAttractForceField1(deref(cppname), cutoff) + self.thisptr = new CppAttractForceField1(deref(cppname), cutoff) del cppname def __dealloc__(self): del self.thisptr def AddLigand(self, AttractRigidbody rig): - self.thisptr.AddLigand(deref(rig.thisptr)) + self.rigidlist.append(rig) + cdef CppBaseAttractForceField* cpp_ptr = self.thisptr + cpp_ptr.AddLigand(deref(rig.thisptr)) def Function(self, vec): cdef vector[double] v for el in vec: v.push_back(el) - return self.thisptr.Function(v) + cdef CppBaseAttractForceField* cpp_ptr = self.thisptr + return cpp_ptr.Function(v) def getVdw(self): - return self.thisptr.getVdw() + cdef CppBaseAttractForceField* cpp_ptr = self.thisptr + return cpp_ptr.getVdw() def getCoulomb(self): - return self.thisptr.getCoulomb() + cdef CppBaseAttractForceField* cpp_ptr = self.thisptr + return cpp_ptr.getCoulomb() def nonbon8(self, AttractRigidbody rec, AttractRigidbody lig, AttractPairList pl, verbose=False): - return self.thisptr.nonbon8(deref(rec.thisptr), deref(lig.thisptr), deref(pl.thisptr), verbose) + cdef CppBaseAttractForceField* cpp_ptr = self.thisptr + return cpp_ptr.nonbon8(deref(rec.thisptr), deref(lig.thisptr), deref(pl.thisptr), verbose) diff --git a/bindings/lbfgs.pyx b/bindings/lbfgs.pyx index 6c44cd9..586d7b5 100644 --- a/bindings/lbfgs.pyx +++ b/bindings/lbfgs.pyx @@ -3,7 +3,7 @@ from libcpp.string cimport string cdef extern from "lbfgs_interface.h" namespace "PTools": cdef cppclass CppLbfgs "PTools::Lbfgs": - CppLbfgs(CppBaseAttractForceField&) + CppLbfgs(CppForceField&) void minimize(int) vector[double] GetMinimizedVars() vector[double] GetMinimizedVarsAtIter(int) @@ -17,8 +17,8 @@ cdef class Lbfgs: def __cinit__(self, forcefield): - ff = forcefield - cdef CppBaseAttractForceField * ffptr = ff.thisptr + ff = forcefield + cdef CppForceField * ffptr = ff.thisptr self.thisptr = new CppLbfgs(deref(ffptr)) def __dealloc__(self): diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx index 854ff7d..e5aa1de 100644 --- a/bindings/mcopff.pyx +++ b/bindings/mcopff.pyx @@ -284,10 +284,12 @@ cdef class Mcoprigid: return self.thisptr.size() -cdef class McopForceField: - cdef CppMcopForceField* thisptr +cdef class McopForceField(ForceField): def __cinit__(self, ff, cutoff): + # deallocate + del self.thisptr + self.thisptr = 0 cdef BaseAttractForceField old_ff cdef CppBaseAttractForceField c_ff @@ -295,25 +297,30 @@ cdef class McopForceField: old_ff = ff c_ff_ptr = old_ff.thisptr - self.thisptr = new CppMcopForceField(deref(c_ff_ptr), cutoff) + self.thisptr = new CppMcopForceField(deref(c_ff_ptr), cutoff) def __dealloc__(self): if self.thisptr: del self.thisptr - self.thisptr = 0 + self.thisptr = 0 def getWeights(self): - return self.thisptr.getWeights() + cdef CppMcopForceField* cpp_ptr = self.thisptr + return cpp_ptr.getWeights() def denormalize_weights(self): - self.thisptr.denormalize_weights() + cdef CppMcopForceField* cpp_ptr = self.thisptr + cpp_ptr.denormalize_weights() def normalize_weigths(self): - self.thisptr.normalize_weights() + cdef CppMcopForceField* cpp_ptr = self.thisptr + cpp_ptr.normalize_weights() def setReceptor(self, Mcoprigid rec): - self.thisptr.setReceptor(deref(rec.thisptr)) + cdef CppMcopForceField* cpp_ptr = self.thisptr + cpp_ptr.setReceptor(deref(rec.thisptr)) def setLigand(self, Mcoprigid lig): - self.thisptr.setLigand(deref(lig.thisptr)) \ No newline at end of file + cdef CppMcopForceField* cpp_ptr = self.thisptr + cpp_ptr.setLigand(deref(lig.thisptr)) \ No newline at end of file From 6c1363b9005cb9d2933630ec403067a25b4273e1 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 26 Apr 2016 18:47:53 +0200 Subject: [PATCH 54/90] comment typo fix --- src/mcopff.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mcopff.cpp b/src/mcopff.cpp index 89d9a96..df1798e 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -359,7 +359,7 @@ dbl McopForceField::Function(const Vdouble & v) Mcoprigid & lig = _moved_ligand ; assert(lig._vregion.size()==0); - //TODO: take into account if not rotation or no translation + //TODO: take into account if no rotation or no translation lig.AttractEulerRotate(v[0],v[1],v[2]); lig.Translate(Coord3D(v[3],v[4],v[5])); From b416178b1a64de67f626641cc4be12b5e83a2886 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Wed, 27 Apr 2016 18:20:26 +0200 Subject: [PATCH 55/90] In Mcoprigid::getWeights : get weights from _receptor, not _centered_ligand. --- src/mcopff.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/mcopff.cpp b/src/mcopff.cpp index df1798e..a4a6e5f 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -21,13 +21,14 @@ Mcoprigid::Mcoprigid(std::string filename){ } +// Normalized weight initialized at 1/(number of copies) and denormalized weights initialized at 0. void Mcoprigid::iniWeights(){ for(int i=0; i < _vregion.size(); i++){ std::vector newvector; _weights.push_back(newvector); _denorm_weights.push_back(newvector); for(int j=0; j < _vregion[i].size(); j++){ - dbl weight = 1/(double)_vregion[i].size(); + dbl weight = 1.0/(double)_vregion[i].size(); _weights[i].push_back(weight); _denorm_weights[i].push_back(0); } @@ -331,8 +332,8 @@ uint McopForceField::ProblemSize() uint size = 0; if (_centered_ligand.getCore().hastranslation) size += 3; if (_centered_ligand.getCore().hasrotation) size += 3; - for(uint i=0; i<_centered_ligand.getWeights().size(); i++){ - size += _centered_ligand.getWeights()[i].size(); + for(uint i=0; i<_receptor.getWeights().size(); i++){ + size += _receptor.getWeights()[i].size(); } return size; } @@ -362,7 +363,6 @@ dbl McopForceField::Function(const Vdouble & v) //TODO: take into account if no rotation or no translation lig.AttractEulerRotate(v[0],v[1],v[2]); lig.Translate(Coord3D(v[3],v[4],v[5])); - assert(_receptor._vregion.size() == _receptor._weights.size()); assert(_receptor._vregion.size() == _receptor._denorm_weights.size()); @@ -377,21 +377,20 @@ dbl McopForceField::Function(const Vdouble & v) std::vector& ref_denorm_weights = _receptor._denorm_weights[loopregion]; for (uint copynb = 0; copynb < ref_ensemble.size(); copynb++){ dbl& denorm_weight = ref_denorm_weights[copynb]; - denorm_weight = v[svptr] + 1/(double)ref_denorm_weights.size(); //delta weight + original weight + denorm_weight = v[svptr] + 1.0/ref_denorm_weights.size(); //delta weight + original weight svptr += 1; } } normalize_weights(); - //2) calculates the energy //2.1) core ligand body with core receptor - - AttractPairList pl (_receptor._core, lig._core, _cutoff ); + AttractPairList pl (_receptor._core, lig._core, _cutoff ); + std::cout << "AttractPairList" << std::endl; ener_core += _ff.nonbon8(_receptor._core, lig._core, pl ); - + std::cout << "nonbon8" << std::endl; //2.2) core lignd with receptor copies: From 998334e254cbaa648eb43427aad63fee467a4884 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Wed, 27 Apr 2016 18:22:45 +0200 Subject: [PATCH 56/90] Added space for nicer formatting --- headers/coordsarray.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/headers/coordsarray.h b/headers/coordsarray.h index 22b0dae..fd28c03 100644 --- a/headers/coordsarray.h +++ b/headers/coordsarray.h @@ -21,7 +21,7 @@ #define _COORDS_ARRAY_H_ #include -#include +#include #include "coord3d.h" From 535b7bdfddcbbe26d92839274dcf7ed34a7a1a11 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Wed, 27 Apr 2016 18:29:32 +0200 Subject: [PATCH 57/90] Made AddAtom() in Rigidody virtual. Override AdAtom() in AttractRigidbody to add parameters specific to AttractRigidbody (bugfix for creating Mcoprigid from file). Made CoordsArray public to Rigidbody (was private) to fix bug 'CoordsArray inaccessible to AttractRigidbody', when calling setCoords() in AttractRigidbody's AddAtom(). --- headers/attractrigidbody.h | 4 +++- headers/rigidbody.h | 9 ++++----- src/attractrigidbody.cpp | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/headers/attractrigidbody.h b/headers/attractrigidbody.h index 4a14ba1..5e343e1 100644 --- a/headers/attractrigidbody.h +++ b/headers/attractrigidbody.h @@ -57,7 +57,6 @@ class AttractRigidbody: public Rigidbody }; virtual bool isAtomActive(uint i) const { - uint atomtype = this->m_atomTypeNumber[i]; for(uint j=0; j #include - +#include "coordsarray.h" #include "coord3d.h" #include "atom.h" #include "basetypes.h" -#include "coordsarray.h" namespace PTools @@ -44,7 +43,7 @@ namespace PTools class AtomSelection; // forward declaration -class Rigidbody:private CoordsArray +class Rigidbody: public CoordsArray { private: @@ -102,10 +101,10 @@ class Rigidbody:private CoordsArray void SetAtom(uint pos, const Atom& atom); /// add an atom to the molecule (deep copy) - void AddAtom(const Atomproperty& at, Coord3D co); + virtual void AddAtom(const Atomproperty& at, Coord3D co); /// add an atom to the molecule - void AddAtom(const Atom& at); + virtual void AddAtom(const Atom& at); //returns the coordinates of atom i Coord3D GetCoords(uint i) const diff --git a/src/attractrigidbody.cpp b/src/attractrigidbody.cpp index aa25d56..2bbfb15 100644 --- a/src/attractrigidbody.cpp +++ b/src/attractrigidbody.cpp @@ -84,7 +84,26 @@ std::swap(m_activeAtoms, newactivelist); } +void AttractRigidbody::AddAtom(const Atom& at) +{ + Atomproperty atp(at); + Coord3D co = at.coords; + AddAtom(atp,co); +} +void AttractRigidbody::AddAtom(const Atomproperty& at, Coord3D co) +{ + mAtomProp.push_back(at); + AddCoord(co); + //Add AttractRigidbody parameters + uint atcategory = 0; + dbl atcharge = 0.0; + std::string extra = at.extra; + std::istringstream iss( extra ); + iss >> atcategory >> atcharge ; + m_atomTypeNumber.push_back(atcategory-1); // -1 to directly use the atomTypeNumber into C-array + m_charge.push_back(atcharge); +} } //namespace PTools From 037ffc64fb7a62056f30f64d71d4fbe702db5c3f Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Thu, 28 Apr 2016 16:08:54 +0200 Subject: [PATCH 58/90] typo fix --- bindings/lbfgs.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/lbfgs.pyx b/bindings/lbfgs.pyx index 586d7b5..ac2f803 100644 --- a/bindings/lbfgs.pyx +++ b/bindings/lbfgs.pyx @@ -47,5 +47,5 @@ cdef class Lbfgs: def denormalize_weights(self): self.thisptr.denormalize_weights() - def normalize_weigths(self): + def normalize_weights(self): self.thisptr.normalize_weights() \ No newline at end of file From 7ad7c63a4be511dd2423eb50a2b50c8a0ab6400c Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Thu, 28 Apr 2016 16:11:29 +0200 Subject: [PATCH 59/90] nothing --- headers/attractforcefield.h | 1 - 1 file changed, 1 deletion(-) diff --git a/headers/attractforcefield.h b/headers/attractforcefield.h index 76c35a4..882b5aa 100644 --- a/headers/attractforcefield.h +++ b/headers/attractforcefield.h @@ -40,7 +40,6 @@ class BaseAttractForceField: public ForceField { std::vector forcesrec (rec.Size()); std::vector forceslig (lig.Size()); - dbl ener = nonbon8_forces(rec, lig, pairlist, forcesrec, forceslig, print); rec.addForces(forcesrec); lig.addForces(forceslig); From e183a22fd398ff864a8a0234ee424db8c8ffec25 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Thu, 28 Apr 2016 16:15:45 +0200 Subject: [PATCH 60/90] nothing --- src/minimizers/lbfgs_interface.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/minimizers/lbfgs_interface.cpp b/src/minimizers/lbfgs_interface.cpp index ddf00fa..cb92665 100644 --- a/src/minimizers/lbfgs_interface.cpp +++ b/src/minimizers/lbfgs_interface.cpp @@ -72,18 +72,15 @@ inline std::vector todbl(std::vector & vcplx) void Lbfgs::minimize(int maxiter) { - int n = objToMinimize.ProblemSize(); std::cout << "number of free variables for the minimizer: " << n << std::endl; - - std::vector l(n); std::vector u(n); Vint nbd(n); - x.resize(n); g.resize(n); + for (int i=0;iiprint=-1; double f = DBL_MAX; @@ -167,10 +162,8 @@ void Lbfgs::minimize(int maxiter) tocplx(x,vdblx); std::vector vdblg; tocplx(g,vdblg); - f = objToMinimize.Function(vdblx); objToMinimize.Derivatives(vdblx,vdblg); - g=todbl(vdblg); // std::cout << "analytical derivatives: \n"; From 3dd3ab3160fb3912e7d0c6bb3872560d76e76b1c Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Thu, 28 Apr 2016 16:18:38 +0200 Subject: [PATCH 61/90] Bugfix: added initialization of m_forces in AttractRigidbody's AddAtom(). --- src/attractrigidbody.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/attractrigidbody.cpp b/src/attractrigidbody.cpp index 2bbfb15..f130214 100644 --- a/src/attractrigidbody.cpp +++ b/src/attractrigidbody.cpp @@ -103,6 +103,7 @@ void AttractRigidbody::AddAtom(const Atomproperty& at, Coord3D co) iss >> atcategory >> atcharge ; m_atomTypeNumber.push_back(atcategory-1); // -1 to directly use the atomTypeNumber into C-array m_charge.push_back(atcharge); + m_forces.push_back(Coord3D()); } } //namespace PTools From a881c8c49b671960574de6859558755c9e2ba136 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Thu, 28 Apr 2016 16:20:55 +0200 Subject: [PATCH 62/90] Bugfix: Coded ini_energies() and applied it to McopForceField's setReceptor() in order to initialize _mcop_E (energies) attribute. --- headers/mcopff.h | 7 ++++--- src/mcopff.cpp | 16 ++++++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/headers/mcopff.h b/headers/mcopff.h index 5b624bf..c86068d 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -124,6 +124,7 @@ class Mcoprigid //multicopy rigidbody uint line_to_copy_number(std::string line); AttractRigidbody& getCore(){return _core;}; + std::vector& getRegions(){return _vregion;}; AttractMcop& getRegion(int i){return _vregion[i];}; size_t size() const {return _vregion.size();}; @@ -159,14 +160,14 @@ class McopForceField: public ForceField McopForceField(BaseAttractForceField& ff, dbl cutoff) :_ff(ff), _cutoff(cutoff) {}; - + void ini_energies(); dbl Function(const Vdouble&); void Derivatives(const Vdouble& v, Vdouble & g ); - void setReceptor(const Mcoprigid& rec) {_receptor = rec;}; - void setLigand(const Mcoprigid& lig) { _centered_ligand = lig; }; + void setReceptor(const Mcoprigid& rec) {_receptor = rec; ini_energies();}; + void setLigand(const Mcoprigid& lig) { _centered_ligand = lig;}; void calculate_weights(Mcoprigid& lig, bool print=false); diff --git a/src/mcopff.cpp b/src/mcopff.cpp index a4a6e5f..a6d3b0f 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -269,6 +269,15 @@ AttractMcop::AttractMcop(const Mcop& mcop){ /////////////////////////////////////////////////// +void McopForceField::ini_energies(){ + for(int i=0; i < _receptor.getRegions().size(); i++){ + std::vector newvector; + _mcop_E.push_back(newvector); + for(int j=0; j < _receptor.getRegions()[i].size(); j++){ + _mcop_E[i].push_back(0); + } + } +} void McopForceField::calculate_weights(Mcoprigid& lig, bool print) { @@ -388,9 +397,7 @@ dbl McopForceField::Function(const Vdouble & v) //2.1) core ligand body with core receptor AttractPairList pl (_receptor._core, lig._core, _cutoff ); - std::cout << "AttractPairList" << std::endl; ener_core += _ff.nonbon8(_receptor._core, lig._core, pl ); - std::cout << "nonbon8" << std::endl; //2.2) core lignd with receptor copies: @@ -400,8 +407,6 @@ dbl McopForceField::Function(const Vdouble & v) //calculates interaction energy between receptor copies and ligand body: // std::vector Eik; - std::vector newvector; - _mcop_E.push_back(newvector); AttractMcop& ref_ensemble = _receptor._vregion[loopregion]; std::vector& ref_denorm_weights = _receptor._denorm_weights[loopregion]; @@ -425,10 +430,9 @@ dbl McopForceField::Function(const Vdouble & v) // dbl e = _ff.nonbon8( lig._core, _receptor._vregion[loopregion][copy] , cpl ); dbl e = _ff.nonbon8_forces(lig._core, copy, cpl, coreforce, copyforce); - _mcop_E[copynb].push_back(e); + _mcop_E[loopregion][copynb] = e; enercopy += e*pow(denorm_weight, 2);//lig._denorm_weights[loopregion][copy]; - //multiply forces by copy weight: for(uint i=0; i Date: Fri, 29 Apr 2016 10:11:06 +0200 Subject: [PATCH 63/90] Coded CalcEnergy() in McopForceField, added it to binding interface and implemented it in attract.py. Bugfix: energy of copies in McopForceField Function()is = 0 when starting a new region. --- PyAttract/attract.py | 34 +++++++++++++++++++++++----------- bindings/mcopff.pyx | 30 ++++++++++++++++++++++++++++-- headers/mcopff.h | 1 + src/mcopff.cpp | 36 +++++++++++++++++++++++++++++++++++- 4 files changed, 87 insertions(+), 14 deletions(-) diff --git a/PyAttract/attract.py b/PyAttract/attract.py index 2a1b1b4..fc50a62 100755 --- a/PyAttract/attract.py +++ b/PyAttract/attract.py @@ -11,8 +11,6 @@ import bz2 #for compression of Ligand and receptor data import base64 #compressed ligand and receptor as base64 strings - - def surreal(i): return i @@ -195,7 +193,6 @@ def checkFile(name, comment): parser.add_option("--mcop", action="store_true", default=False, dest="regions", help="mcop option for multi-copy rigid-body docking") (options, args) = parser.parse_args() - #receptor_name=args[0] #ligand_name=args[1] @@ -288,7 +285,6 @@ def check_ffversion(reduced): - #load receptor and ligand: if options.regions: rec=Mcoprigid(options.receptor_name) @@ -300,6 +296,7 @@ def check_ffversion(reduced): rec=AttractRigidbody(rec) lig=Rigidbody(options.ligand_name) lig=AttractRigidbody(lig) +# TODO: Redo message for mcop print "Reading receptor (fixed): %s with %d particules" %( options.receptor_name, len(rec) ) print "Reading ligand (mobile): %s with %d particules" %( options.ligand_name, len(lig) ) @@ -369,7 +366,7 @@ def check_ffversion(reduced): print "----- Rotation nb %i -----"%rotnb minimcounter=0 if options.regions: - ligand=AttractRigidbody(lig.getCore()) + ligand=Mcoprigid(lig) else: ligand=AttractRigidbody(lig) @@ -387,7 +384,8 @@ def check_ffversion(reduced): #performs single minimization on receptor and ligand, given maxiter=niter and restraint constant rstk forcefield=ff_specs['ff_class'](ff_specs['ff_file'], surreal(cutoff) ) - mcopff = McopForceField(forcefield, surreal(cutoff)) + if options.regions: + mcopff = McopForceField(forcefield, surreal(cutoff)) rec.setTranslation(False) rec.setRotation(False) @@ -401,9 +399,13 @@ def check_ffversion(reduced): #if rstk>0.0: #forcefield.SetRestraint(rstk) if options.regions: + print "debug" lbfgs_minimizer=Lbfgs(mcopff) + print "debug2" lbfgs_minimizer.minimize(niter) + print "debug3" lbfgs_minimizer.normalize_weights() + print "debug4" else : lbfgs_minimizer=ff_specs['minimizer_class'](forcefield) lbfgs_minimizer.minimize(niter) @@ -412,14 +414,20 @@ def check_ffversion(reduced): #TODO: test and use CenterToOrigin() ! - output=AttractRigidbody(ligand) + if options.regions: + output=Mcoprigid(ligand) + else: + output=AttractRigidbody(ligand) center=output.FindCenter() output.Translate(Coord3D()-center) output.AttractEulerRotate(surreal(X[0]), surreal(X[1]), surreal(X[2])) output.Translate(Coord3D(surreal(X[3]),surreal(X[4]),surreal(X[5]))) output.Translate(center) - ligand=AttractRigidbody(output) + if options.regions: + ligand=Mcoprigid(output) + else: + ligand=AttractRigidbody(output) if (options.single): ntraj=lbfgs_minimizer.GetNumberIter() for iteration in range(ntraj): @@ -441,9 +449,13 @@ def check_ffversion(reduced): #with the new ligand position forcefield=ff_specs['ff_class'](ff_specs['ff_file'], surreal(500)) print "%4s %6s %6s %13s %13s" %(" ","Trans", "Rot", "Ener", "RmsdCA_ref") - pl = AttractPairList(rec, ligand,surreal(500)) - print "%-4s %6d %6d %13.7f %13s" %("==", transnb, rotnb, forcefield.nonbon8(rec,ligand,pl), str(rms)) - output.PrintMatrix() + if options.regions: + print "%-4s %6d %6d %13.7f %13s" %("==", transnb, rotnb, mcopff.CalcEnergy(rec,ligand,forcefield,500), str(rms)) + output.getCore().PrintMatrix() #getCore because PrintMatrix works on AttractRigidy and not Mcoprigid + else: + pl = AttractPairList(rec, ligand,surreal(500)) + print "%-4s %6d %6d %13.7f %13s" %("==", transnb, rotnb, forcefield.nonbon8(rec,ligand,pl), str(rms)) + output.PrintMatrix() #output compressed ligand and receptor: diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx index e5aa1de..e025bdc 100644 --- a/bindings/mcopff.pyx +++ b/bindings/mcopff.pyx @@ -50,7 +50,9 @@ cdef extern from "mcopff.h" namespace "PTools": void normalize_weights() void setReceptor(CppMcoprigid&) void setLigand(CppMcoprigid&) - + double CalcEnergy(CppMcoprigid&, CppMcoprigid&, CppScorpionForceField&, double) + double CalcEnergy(CppMcoprigid&, CppMcoprigid&, CppAttractForceField1&, double) + double CalcEnergy(CppMcoprigid&, CppMcoprigid&, CppAttractForceField2&, double) cdef class Mcop: cdef CppMcop* thisptr @@ -323,4 +325,28 @@ cdef class McopForceField(ForceField): def setLigand(self, Mcoprigid lig): cdef CppMcopForceField* cpp_ptr = self.thisptr - cpp_ptr.setLigand(deref(lig.thisptr)) \ No newline at end of file + cpp_ptr.setLigand(deref(lig.thisptr)) + + + def CalcEnergy(self, Mcoprigid rec, Mcoprigid lig, ScorpionForceField ff, double cutoff): + cdef CppMcopForceField* cpp_ptr = self.thisptr + cdef CppScorpionForceField* cppff_scorp + cppff_scorp = ff.thisptr + return cpp_ptr.CalcEnergy(deref(rec.thisptr), deref(lig.thisptr), deref(cppff_scorp), cutoff) + + def CalcEnergy(self, Mcoprigid rec, Mcoprigid lig, AttractForceField1 ff, double cutoff): + cdef CppMcopForceField* cpp_ptr = self.thisptr + cdef CppAttractForceField1* cppff_att1 + cppff_scorp = ff.thisptr + return cpp_ptr.CalcEnergy(deref(rec.thisptr), deref(lig.thisptr), deref(cppff_att1), cutoff) + + def CalcEnergy(self, Mcoprigid rec, Mcoprigid lig, AttractForceField2 ff, double cutoff): + cdef CppMcopForceField* cpp_ptr = self.thisptr + cdef CppAttractForceField2* cppff_att2 + cppff_scorp = ff.thisptr + return cpp_ptr.CalcEnergy(deref(rec.thisptr), deref(lig.thisptr), deref(cppff_att2), cutoff) + + + + + \ No newline at end of file diff --git a/headers/mcopff.h b/headers/mcopff.h index c86068d..cb50008 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -163,6 +163,7 @@ class McopForceField: public ForceField void ini_energies(); dbl Function(const Vdouble&); + dbl CalcEnergy(Mcoprigid & receptor,Mcoprigid & ligand, BaseAttractForceField & ff, dbl cutoff); void Derivatives(const Vdouble& v, Vdouble & g ); diff --git a/src/mcopff.cpp b/src/mcopff.cpp index a6d3b0f..b34fb5d 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -360,7 +360,6 @@ dbl McopForceField::Function(const Vdouble & v) dbl ener_region = 0.0 ; dbl ener_core = 0.0 ; - dbl enercopy =0.0; // 1) put the objects to the right place @@ -408,6 +407,7 @@ dbl McopForceField::Function(const Vdouble & v) //calculates interaction energy between receptor copies and ligand body: // std::vector Eik; + dbl enercopy =0.0; AttractMcop& ref_ensemble = _receptor._vregion[loopregion]; std::vector& ref_denorm_weights = _receptor._denorm_weights[loopregion]; std::vector& ref_weights = _receptor._weights[loopregion]; @@ -455,6 +455,40 @@ dbl McopForceField::Function(const Vdouble & v) } +// To calculation interaction energy between an Mcoprigid receptor with variable region(s) +// and an Mcoprigid ligand without variable regions. +// Uses the receptor's normalized weights and a given forcefeild and cutoff. +dbl McopForceField::CalcEnergy(Mcoprigid & receptor, Mcoprigid & ligand, BaseAttractForceField & ff, dbl cutoff){ + + dbl ener_region = 0.0 ; + dbl ener_core = 0.0 ; + + AttractPairList pl (receptor._core, ligand._core, cutoff ); + ener_core += ff.nonbon8(receptor._core, ligand._core, pl ); + + //calculates interaction energy between receptor copies and ligand body: + for(uint loopregion=0; loopregion < receptor.getRegions().size(); loopregion++){ + + dbl enercopy =0.0; + + for(uint copynb=0; copynb < receptor.getRegion(loopregion).size(); copynb++){ + + dbl weight = receptor.getWeights()[loopregion][copynb]; + AttractRigidbody& copy = receptor.getRegion(loopregion).getCopy(copynb); + AttractPairList cpl (ligand._core, copy, cutoff); + + std::vector copyforce(copy.Size()); + std::vector coreforce(ligand._core.Size()); + + dbl e = ff.nonbon8_forces(ligand._core, copy, cpl, coreforce, copyforce); + enercopy += e*weight; + } + + ener_region += enercopy; + } + return ener_core + ener_region; +} + void McopForceField::Derivatives(const Vdouble& v, Vdouble & g ) { From b93f3ee273df2ece71acb184ab88b2fd032bfaf2 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Fri, 29 Apr 2016 10:44:53 +0200 Subject: [PATCH 64/90] Added getWeights() in Lbfgs class. It calls its equivalent funciton in objToMinimize attribute (type ForceField) only if this attribute is of type McopForceField. Added this function to binding interface. --- bindings/lbfgs.pyx | 6 +++++- headers/lbfgs_interface.h | 2 ++ src/minimizers/lbfgs_interface.cpp | 11 +++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/bindings/lbfgs.pyx b/bindings/lbfgs.pyx index ac2f803..862ae34 100644 --- a/bindings/lbfgs.pyx +++ b/bindings/lbfgs.pyx @@ -10,6 +10,7 @@ cdef extern from "lbfgs_interface.h" namespace "PTools": int GetNumberIter() void denormalize_weights() void normalize_weights() + vector[vector[double]] getWeights() cdef class Lbfgs: @@ -48,4 +49,7 @@ cdef class Lbfgs: self.thisptr.denormalize_weights() def normalize_weights(self): - self.thisptr.normalize_weights() \ No newline at end of file + self.thisptr.normalize_weights() + + def getWeights(self): + self.thisptr.getWeights() \ No newline at end of file diff --git a/headers/lbfgs_interface.h b/headers/lbfgs_interface.h index 160be94..655e237 100644 --- a/headers/lbfgs_interface.h +++ b/headers/lbfgs_interface.h @@ -29,6 +29,8 @@ class Lbfgs int GetNumberIter() {return m_opt->niter;} void denormalize_weights(); void normalize_weights(); + std::vector< std::vector > getWeights(); + diff --git a/src/minimizers/lbfgs_interface.cpp b/src/minimizers/lbfgs_interface.cpp index cb92665..09dc06c 100644 --- a/src/minimizers/lbfgs_interface.cpp +++ b/src/minimizers/lbfgs_interface.cpp @@ -215,6 +215,7 @@ void Lbfgs::denormalize_weights() // objToMinimize is not a McopForceField } + void Lbfgs::normalize_weights() { if (McopForceField * p = dynamic_cast(&objToMinimize)){ @@ -227,6 +228,16 @@ void Lbfgs::normalize_weights() // objToMinimize is not a McopForceField } +std::vector< std::vector > Lbfgs::getWeights(){ + if (McopForceField * p = dynamic_cast(&objToMinimize)){ + // objToMinimize is or is of type McopForceField + ForceField& r_objToMinimize = objToMinimize; + McopForceField& r_Mcop_objToMinimize = dynamic_cast(r_objToMinimize); + r_Mcop_objToMinimize.getWeights(); + } + //else + // objToMinimize is not a McopForceField +} From 6b110c102ab69b9d86c2a70d8ee59e3850089e82 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Fri, 29 Apr 2016 13:46:37 +0200 Subject: [PATCH 65/90] Added _buffer_weights and _buffer_denorm_weights attributes to McopForceField. Used these attributes in McopForceField's Function() and Derivatives() instead of _weights and _denorm_weights in order to preserve the original weights from before the minimization. --- headers/mcopff.h | 3 +++ src/mcopff.cpp | 36 ++++++++++++++++++++---------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/headers/mcopff.h b/headers/mcopff.h index cb50008..5783ef7 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -141,6 +141,9 @@ class Mcoprigid //multicopy rigidbody std::vector< std::vector > _weights; std::vector< std::vector > _denorm_weights; + std::vector< std::vector > _buffer_weights; + std::vector< std::vector > _buffer_denorm_weights; + friend class McopForceField; diff --git a/src/mcopff.cpp b/src/mcopff.cpp index b34fb5d..b7a9d4d 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -32,8 +32,8 @@ void Mcoprigid::iniWeights(){ _weights[i].push_back(weight); _denorm_weights[i].push_back(0); } - denormalize_weights(); } + denormalize_weights(); } void Mcoprigid::setCore(AttractRigidbody& core) { @@ -367,6 +367,7 @@ dbl McopForceField::Function(const Vdouble & v) Mcoprigid & lig = _moved_ligand ; assert(lig._vregion.size()==0); + //std::vector< std::vector > weights; //TODO: take into account if no rotation or no translation lig.AttractEulerRotate(v[0],v[1],v[2]); @@ -379,18 +380,20 @@ dbl McopForceField::Function(const Vdouble & v) uint svptr = 0; // stateVars 'pointer' if (lig.getCore().hasrotation) svptr += 3; if (lig.getCore().hastranslation) svptr += 3; + std::vector< std::vector > denorm_weights = _receptor._denorm_weights; for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++){ assert( ref_ensemble.size() == ref_denorm_weights.size()); AttractMcop& ref_ensemble = _receptor._vregion[loopregion]; - std::vector& ref_denorm_weights = _receptor._denorm_weights[loopregion]; + std::vector & denorm_weights_loop = denorm_weights[loopregion]; for (uint copynb = 0; copynb < ref_ensemble.size(); copynb++){ - dbl& denorm_weight = ref_denorm_weights[copynb]; - denorm_weight = v[svptr] + 1.0/ref_denorm_weights.size(); //delta weight + original weight + dbl & denorm_weight = denorm_weights_loop[copynb]; + denorm_weight = v[svptr] + denorm_weight; //delta weight + original weight svptr += 1; } } normalize_weights(); + std::vector< std::vector > weights = _receptor._weights; //2) calculates the energy @@ -409,19 +412,18 @@ dbl McopForceField::Function(const Vdouble & v) dbl enercopy =0.0; AttractMcop& ref_ensemble = _receptor._vregion[loopregion]; - std::vector& ref_denorm_weights = _receptor._denorm_weights[loopregion]; - std::vector& ref_weights = _receptor._weights[loopregion]; + std::vector& denorm_weights_loop = denorm_weights[loopregion]; + std::vector& weights_loop = weights[loopregion]; - assert( ref_ensemble.size() == ref_denorm_weights.size()); - assert( ref_ensemble.size() == ref_weights.size()); + assert( ref_ensemble.size() == denorm_weights_loop.size()); + assert( ref_ensemble.size() == weights_loop.size()); - dbl max_weight = *max_element(ref_weights.begin(), ref_weights.end()); + dbl max_weight = *max_element(weights_loop.begin(), weights_loop.end()); for (uint copynb = 0; copynb < ref_ensemble.size(); copynb++) { - dbl& denorm_weight = ref_denorm_weights[copynb]; - //dbl& weight = ref_weights[copynb]; + dbl& denorm_weight = denorm_weights_loop[copynb]; AttractRigidbody& copy = ref_ensemble[copynb]; AttractPairList cpl ( lig._core, copy, _cutoff ); @@ -451,6 +453,8 @@ dbl McopForceField::Function(const Vdouble & v) ener_region += max_weight*enercopy; } + _receptor._buffer_weights = weights; + _receptor._buffer_denorm_weights = denorm_weights; return ener_core + ener_region; } @@ -531,7 +535,7 @@ if (lig.getCore().hasrotation){ for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++){ - std::vector& ref_weights = _receptor._weights[loopregion]; + std::vector& ref_weights = _receptor._buffer_weights[loopregion]; dbl max_weight = *max_element(ref_weights.begin(), ref_weights.end()); for (uint i=0; i< pLigCentered->m_activeAtoms.size(); i++) @@ -578,7 +582,7 @@ if (lig.getCore().hastranslation){ for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++){ - std::vector& ref_weights = _receptor._weights[loopregion]; + std::vector& ref_weights = _receptor._buffer_weights[loopregion]; dbl max_weight = *max_element(ref_weights.begin(), ref_weights.end()); Coord3D ligtransForces; //translational forces for the ligand from loopregion @@ -600,10 +604,10 @@ assert(_receptor._vregion.size() == _mcop_E.size()); uint k = 0; for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++){ - std::vector& ref_weights = _receptor._weights[loopregion]; - std::vector& ref_denorm_weights = _receptor._denorm_weights[loopregion]; + std::vector& ref_weights = _receptor._buffer_weights[loopregion]; + std::vector& ref_denorm_weights = _receptor._buffer_denorm_weights[loopregion]; std::vector& ref_mcop_E = _mcop_E[loopregion]; - assert(ref_weights.size() == _ref_mcop_E.size()); + assert(ref_weights.size() == ref_mcop_E.size()); dbl max_weight = *max_element(ref_weights.begin(), ref_weights.end()); for(uint copynb; copynb < _mcop_E[loopregion].size(); copynb++){ From 42432f78f4c4d743e5994999a8aa2acfcc70dfd0 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Fri, 29 Apr 2016 15:02:36 +0200 Subject: [PATCH 66/90] Coded update_weights() in Mcoprigid class. Coded checkTranslation() and checkRotation() in Mcoprigid and Attractrigidbody. Added all these functions to binding interface. --- bindings/mcopff.pyx | 13 +++++++++++++ headers/attractrigidbody.h | 2 ++ headers/mcopff.h | 11 +++++++---- src/mcopff.cpp | 12 ++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx index e025bdc..aca6533 100644 --- a/bindings/mcopff.pyx +++ b/bindings/mcopff.pyx @@ -1,5 +1,6 @@ from cython.operator cimport dereference as deref from libcpp.string cimport string +from cpython cimport bool cdef extern from "" namespace "std": cdef cppclass stringstream: @@ -35,11 +36,14 @@ cdef extern from "mcopff.h" namespace "PTools": unsigned int size() void setCore(CppAttractRigidbody&) vector[vector[double]] getWeights() + void updateWeights(vector[double], int) void denormalize_weights() void normalize_weights() Coord3D FindCenter() void setTranslation(int) void setRotation(int) + bool checkTranslation() + bool checkRotation() void Translate(CppCoord3D&) void AttractEulerRotate(double, double, double) @@ -255,6 +259,9 @@ cdef class Mcoprigid: def getWeights(self): return self.thisptr.getWeights() + def updateWeights(self, vector[double] v, int svptr): + self.thisptr.updateWeights(v, svptr) + def denormalize_weights(self): self.thisptr.denormalize_weights() @@ -276,6 +283,12 @@ cdef class Mcoprigid: def setRotation(self, flag): self.thisptr.setRotation(flag) + def checkTranslation(self): + return self.thisptr.checkTranslation() + + def checkRotation(self): + return self.thisptr.checkRotation(); + def AttractEulerRotate(self, double phi, double ssi, double rot): self.thisptr.AttractEulerRotate(phi, ssi, rot) diff --git a/headers/attractrigidbody.h b/headers/attractrigidbody.h index 5e343e1..ed76c9b 100644 --- a/headers/attractrigidbody.h +++ b/headers/attractrigidbody.h @@ -79,6 +79,8 @@ class AttractRigidbody: public Rigidbody virtual void setRotation(bool value) {hasrotation = value;} ///< allow/disallow rotation virtual void setTranslation(bool value) {hastranslation = value;} ///< allow/disallow translation + bool checkRotation(){return hasrotation;}; + bool checkTranslation(){return hastranslation;}; void setDummyTypes(const std::vector& dummy); ///< set a list of ignored atom types diff --git a/headers/mcopff.h b/headers/mcopff.h index 5783ef7..986e910 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -117,6 +117,7 @@ class Mcoprigid //multicopy rigidbody std::vector > getWeights(){return _weights;}; void denormalize_weights(); void normalize_weights(); + void updateWeights(const std::vector& v, int svptr); void ReadMcoprigidPDB(const std::string name); void ReadMcoprigidPDB(std::istream& file, AttractRigidbody& core, std::vector& regions); @@ -130,6 +131,8 @@ class Mcoprigid //multicopy rigidbody virtual void setRotation(bool value) {_core.setRotation(value);}; ///< allow/disallow rotation virtual void setTranslation(bool value) {_core.setTranslation(value);}; ///< allow/disallow translation + bool checkRotation(){return _core.checkRotation();}; + bool checkTranslation(){return _core.checkTranslation();}; private: @@ -139,10 +142,10 @@ class Mcoprigid //multicopy rigidbody bool _complete ; Coord3D _center ; ///
> _weights; - std::vector< std::vector > _denorm_weights; - std::vector< std::vector > _buffer_weights; - std::vector< std::vector > _buffer_denorm_weights; + std::vector< std::vector > _weights; + std::vector< std::vector > _denorm_weights; + std::vector< std::vector > _buffer_weights; + std::vector< std::vector > _buffer_denorm_weights; friend class McopForceField; diff --git a/src/mcopff.cpp b/src/mcopff.cpp index b7a9d4d..83aa318 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -175,6 +175,18 @@ void Mcoprigid::normalize_weights(){ } } +void Mcoprigid::updateWeights(const std::vector& v, int svptr){ + //svptr: state variable "pointer" + for (uint loopregion=0; loopregion < _vregion.size() ; loopregion++){ + for (uint copynb = 0; copynb < _vregion[loopregion].size(); copynb++){ + dbl & d_w = _denorm_weights[loopregion][copynb]; + d_w = v[svptr] + d_w; //delta weight + original weight + svptr += 1; + } + } + normalize_weights(); +} + /////////////////// -- Class Mcop -- //////////////////// From 2fa0dbbf0906645a64f6dc9ed76bcdfbabd3a5e3 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Fri, 29 Apr 2016 15:39:51 +0200 Subject: [PATCH 67/90] Implemented updateWeights() in attract.py. Coded and implemented printWeights() in attract.py. --- PyAttract/attract.py | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/PyAttract/attract.py b/PyAttract/attract.py index fc50a62..d129737 100755 --- a/PyAttract/attract.py +++ b/PyAttract/attract.py @@ -31,6 +31,18 @@ def PrintVect(vect): print vect[i], " | ", print '' +def printWeights(w): + print "### WEIGHTS BEGIN" + for region in xrange(0, len(w)): + sum = 0 + print "### Start Region %d" %(region+1) + for copy in xrange(0, len(w[region])): + sum += w[region][copy] + print "WEIGHT REGION %d COPY %d = %f" %(region+1, copy+1, w[region][copy]) + print "WEIGHT SUM OF WEIGHTS = %f" %sum + print "### End Region %d" %(region+1) + print "### WEIGHTS END" + class Rotation: @@ -367,8 +379,10 @@ def check_ffversion(reduced): minimcounter=0 if options.regions: ligand=Mcoprigid(lig) + receptor=Mcoprigid(rec) else: ligand=AttractRigidbody(lig) + receptor=AttractRigidbody(rec) center=ligand.FindCenter() ligand.Translate(Coord3D()-center) #set ligand center of mass to 0,0,0 @@ -386,26 +400,22 @@ def check_ffversion(reduced): forcefield=ff_specs['ff_class'](ff_specs['ff_file'], surreal(cutoff) ) if options.regions: mcopff = McopForceField(forcefield, surreal(cutoff)) - rec.setTranslation(False) - rec.setRotation(False) + receptor.setTranslation(False) + receptor.setRotation(False) if options.regions: - mcopff.setReceptor(rec) - mcopff.setLigand(lig) + mcopff.setReceptor(receptor) + mcopff.setLigand(ligand) else: - forcefield.AddLigand(rec) + forcefield.AddLigand(receptor) forcefield.AddLigand(ligand) rstk=minim['rstk'] #restraint force #if rstk>0.0: #forcefield.SetRestraint(rstk) if options.regions: - print "debug" lbfgs_minimizer=Lbfgs(mcopff) - print "debug2" lbfgs_minimizer.minimize(niter) - print "debug3" lbfgs_minimizer.normalize_weights() - print "debug4" else : lbfgs_minimizer=ff_specs['minimizer_class'](forcefield) lbfgs_minimizer.minimize(niter) @@ -416,8 +426,10 @@ def check_ffversion(reduced): #TODO: test and use CenterToOrigin() ! if options.regions: output=Mcoprigid(ligand) + receptor.updateWeights(X, svptr=6) else: output=AttractRigidbody(ligand) + center=output.FindCenter() output.Translate(Coord3D()-center) output.AttractEulerRotate(surreal(X[0]), surreal(X[1]), surreal(X[2])) @@ -450,11 +462,12 @@ def check_ffversion(reduced): forcefield=ff_specs['ff_class'](ff_specs['ff_file'], surreal(500)) print "%4s %6s %6s %13s %13s" %(" ","Trans", "Rot", "Ener", "RmsdCA_ref") if options.regions: - print "%-4s %6d %6d %13.7f %13s" %("==", transnb, rotnb, mcopff.CalcEnergy(rec,ligand,forcefield,500), str(rms)) + print "%-4s %6d %6d %13.7f %13s" %("==", transnb, rotnb, mcopff.CalcEnergy(receptor,ligand,forcefield,500), str(rms)) output.getCore().PrintMatrix() #getCore because PrintMatrix works on AttractRigidy and not Mcoprigid + printWeights(receptor.getWeights()) else: - pl = AttractPairList(rec, ligand,surreal(500)) - print "%-4s %6d %6d %13.7f %13s" %("==", transnb, rotnb, forcefield.nonbon8(rec,ligand,pl), str(rms)) + pl = AttractPairList(receptor, ligand,surreal(500)) + print "%-4s %6d %6d %13.7f %13s" %("==", transnb, rotnb, forcefield.nonbon8(receptor,ligand,pl), str(rms)) output.PrintMatrix() From 62329da8c1840e8760feb743e341a2d61936f69d Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Fri, 29 Apr 2016 17:11:51 +0200 Subject: [PATCH 68/90] Bugfix: for loops with uint i missing afectation: in denormalize_weights(), normalize_weights(), Derivatives()... --- src/mcopff.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/mcopff.cpp b/src/mcopff.cpp index 83aa318..d36629c 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -23,11 +23,11 @@ Mcoprigid::Mcoprigid(std::string filename){ // Normalized weight initialized at 1/(number of copies) and denormalized weights initialized at 0. void Mcoprigid::iniWeights(){ - for(int i=0; i < _vregion.size(); i++){ + for(uint i=0; i < _vregion.size(); i++){ std::vector newvector; _weights.push_back(newvector); _denorm_weights.push_back(newvector); - for(int j=0; j < _vregion[i].size(); j++){ + for(uint j=0; j < _vregion[i].size(); j++){ dbl weight = 1.0/(double)_vregion[i].size(); _weights[i].push_back(weight); _denorm_weights[i].push_back(0); @@ -154,9 +154,9 @@ uint Mcoprigid::line_to_copy_number(std::string line){ } void Mcoprigid::denormalize_weights(){ - for(uint i; i < _weights.size(); i++){ + for(uint i=0; i < _weights.size(); i++){ dbl max_weight = *max_element(_weights[i].begin(), _weights[i].end()); - for(uint j; j < _weights[i].size(); j++){ + for(uint j=0; j < _weights[i].size(); j++){ _denorm_weights[i][j] = sqrt(_weights[i][j]/max_weight); } } @@ -164,12 +164,12 @@ void Mcoprigid::denormalize_weights(){ void Mcoprigid::normalize_weights(){ - for(uint i; i < _denorm_weights.size(); i++){ + for(uint i=0; i < _denorm_weights.size(); i++){ dbl sum_squared_denorm_weights = 0; - for(uint j; j < _denorm_weights[i].size(); j++){ + for(uint j=0; j < _denorm_weights[i].size(); j++){ sum_squared_denorm_weights += pow(_denorm_weights[i][j], 2); } - for(uint j; j < _denorm_weights[i].size(); j++){ + for(uint j=0; j < _denorm_weights[i].size(); j++){ _weights[i][j] = pow(_denorm_weights[i][j], 2)/sum_squared_denorm_weights; } } @@ -177,8 +177,8 @@ void Mcoprigid::normalize_weights(){ void Mcoprigid::updateWeights(const std::vector& v, int svptr){ //svptr: state variable "pointer" - for (uint loopregion=0; loopregion < _vregion.size() ; loopregion++){ - for (uint copynb = 0; copynb < _vregion[loopregion].size(); copynb++){ + for(uint loopregion=0; loopregion < _vregion.size() ; loopregion++){ + for(uint copynb = 0; copynb < _vregion[loopregion].size(); copynb++){ dbl & d_w = _denorm_weights[loopregion][copynb]; d_w = v[svptr] + d_w; //delta weight + original weight svptr += 1; @@ -254,7 +254,7 @@ bool Mcop::isNewModel(const std::string & line){ AttractMcop::AttractMcop(std::string filename){ Mcop copies(filename); - for(int i=0; i < copies.size(); i++){ + for(uint i=0; i < copies.size(); i++){ Rigidbody copy = copies.getCopy(i); AttractRigidbody attcopy = AttractRigidbody(copy); attract_copies.push_back(attcopy); @@ -265,7 +265,7 @@ AttractMcop::AttractMcop(std::string filename){ AttractMcop::AttractMcop(const Mcop& mcop){ Mcop copies = mcop; - for(int i=0; i < copies.size(); i++){ + for(uint i=0; i < copies.size(); i++){ Rigidbody copy = copies.getCopy(i); AttractRigidbody attcopy = AttractRigidbody(copy); attract_copies.push_back(attcopy); @@ -282,10 +282,10 @@ AttractMcop::AttractMcop(const Mcop& mcop){ void McopForceField::ini_energies(){ - for(int i=0; i < _receptor.getRegions().size(); i++){ + for(uint i=0; i < _receptor.getRegions().size(); i++){ std::vector newvector; _mcop_E.push_back(newvector); - for(int j=0; j < _receptor.getRegions()[i].size(); j++){ + for(uint j=0; j < _receptor.getRegions()[i].size(); j++){ _mcop_E[i].push_back(0); } } @@ -399,7 +399,7 @@ dbl McopForceField::Function(const Vdouble & v) std::vector & denorm_weights_loop = denorm_weights[loopregion]; for (uint copynb = 0; copynb < ref_ensemble.size(); copynb++){ dbl & denorm_weight = denorm_weights_loop[copynb]; - denorm_weight = v[svptr] + denorm_weight; //delta weight + original weight + denorm_weight = v[svptr] + denorm_weight; //delta weight + original weight svptr += 1; } } @@ -455,7 +455,7 @@ dbl McopForceField::Function(const Vdouble & v) //add force to ligand and receptor copy assert(lig._core.Size() == coreforce.size()); - for (uint i=0; i Date: Mon, 2 May 2016 16:58:40 +0200 Subject: [PATCH 69/90] Did math fixes in McopForceField's Derivatives() and Function(). Ignored active_atoms in mcopff for now. --- src/mcopff.cpp | 55 +++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/src/mcopff.cpp b/src/mcopff.cpp index d36629c..7eb125b 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -444,26 +444,23 @@ dbl McopForceField::Function(const Vdouble & v) // dbl e = _ff.nonbon8( lig._core, _receptor._vregion[loopregion][copy] , cpl ); dbl e = _ff.nonbon8_forces(lig._core, copy, cpl, coreforce, copyforce); - _mcop_E[loopregion][copynb] = e; + _mcop_E[loopregion][copynb] = e*pow(denorm_weight, 2); - enercopy += e*pow(denorm_weight, 2);//lig._denorm_weights[loopregion][copy]; - //multiply forces by copy weight: - for(uint i=0; i& ref_weights = _receptor._buffer_weights[loopregion]; dbl max_weight = *max_element(ref_weights.begin(), ref_weights.end()); - for (uint i=0; i< pLigCentered->m_activeAtoms.size(); i++) - { - uint atomIndex = pLigCentered->m_activeAtoms[i]; + //printf("pLigCentered->m_activeAtoms.size() = %d\n", pLigCentered->m_activeAtoms.size()); + //for (uint i=0; i< pLigCentered->m_activeAtoms.size(); i++) + for(uint atomIndex=0; atomIndex<_moved_ligand._core.Size(); atomIndex++){ + //uint atomIndex = pLigCentered->m_activeAtoms[i]; Coord3D coords = pLigCentered->GetCoords(atomIndex); X = coords.x; @@ -574,10 +572,12 @@ if (lig.getCore().hasrotation){ pm[2][2]=-yar*ss ; for(uint j=0; j < 3; j++){ - g[svptr + j] += pm[0][j] * pLigMoved->m_forces[atomIndex].x * max_weight; - g[svptr + j] += pm[1][j] * pLigMoved->m_forces[atomIndex].y * max_weight; - g[svptr + j] += pm[2][j] * pLigMoved->m_forces[atomIndex].z * max_weight; + g[svptr + j] += pm[0][j] * pLigMoved->m_forces[atomIndex].x; + g[svptr + j] += pm[1][j] * pLigMoved->m_forces[atomIndex].y; + g[svptr + j] += pm[2][j] * pLigMoved->m_forces[atomIndex].z; } + //printf("vector v[%d, %d, %d] = %f, %f, %f\n",svptr+0, svptr+1, svptr+2, v[svptr+0], v[svptr+1], v[svptr+2]); + //printf("vector g[%d, %d, %d] = %f, %f, %f\n",svptr+0, svptr+1, svptr+2, g[svptr+0], g[svptr+1], g[svptr+2]); } } @@ -587,12 +587,13 @@ if (lig.getCore().hasrotation){ //sum the forces over x, y and z: calculate de translational forces if (lig.getCore().hastranslation){ + //printf("hastranslation\n"); g[svptr+0] = 0; g[svptr+1] = 0; g[svptr+2] = 0; - for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++){ + for (uint loopregion=0; loopregion < _receptor._vregion.size(); loopregion++){ std::vector& ref_weights = _receptor._buffer_weights[loopregion]; dbl max_weight = *max_element(ref_weights.begin(), ref_weights.end()); @@ -602,9 +603,11 @@ if (lig.getCore().hastranslation){ ligtransForces += _moved_ligand._core.m_forces[i]; } - g[svptr+0] += ligtransForces.x * max_weight; - g[svptr+1] += ligtransForces.y * max_weight; - g[svptr+2] += ligtransForces.z * max_weight; + g[svptr+0] += ligtransForces.x; + g[svptr+1] += ligtransForces.y; + g[svptr+2] += ligtransForces.z; + //printf("vector v[%d, %d, %d] = %f, %f, %f\n",svptr+0, svptr+1, svptr+2, v[svptr+0], v[svptr+1], v[svptr+2]); + //printf("vector g[%d, %d, %d] = %f, %f, %f\n",svptr+0, svptr+1, svptr+2, g[svptr+0], g[svptr+1], g[svptr+2]); } svptr += 3; @@ -625,6 +628,8 @@ for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++){ for(uint copynb=0; copynb < _mcop_E[loopregion].size(); copynb++){ // weight derivative function g[svptr + k] = 2*max_weight*ref_denorm_weights[copynb]*ref_mcop_E[copynb]; + //printf("vector v[%d] = %f\n",svptr+k, v[svptr+k]); + //printf("vector g[%d] = %f\n",svptr+k, g[svptr+k]); k++; } } From 82c760152cc54d7f29574b3e960a651921841ba5 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Mon, 2 May 2016 17:12:21 +0200 Subject: [PATCH 70/90] Fixed reference RMSD calculation for mcop option in attract.py --- PyAttract/attract.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/PyAttract/attract.py b/PyAttract/attract.py index d129737..12db36a 100755 --- a/PyAttract/attract.py +++ b/PyAttract/attract.py @@ -452,7 +452,10 @@ def check_ffversion(reduced): #computes RMSD if reference structure available if (options.reffile): - rms=Rmsd_alias(ref, output) + if(options.regions): + rms=Rmsd_alias(ref, output.getCore()) + else: + rms=Rmsd_alias(ref, output) else: rms="XXXX" From 59b1c1254342ac508fe9624824b95bc4c8258595 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Mon, 2 May 2016 17:32:43 +0200 Subject: [PATCH 71/90] Math fix in Derivatives() --- src/mcopff.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mcopff.cpp b/src/mcopff.cpp index 7eb125b..6e31f59 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -444,9 +444,9 @@ dbl McopForceField::Function(const Vdouble & v) // dbl e = _ff.nonbon8( lig._core, _receptor._vregion[loopregion][copy] , cpl ); dbl e = _ff.nonbon8_forces(lig._core, copy, cpl, coreforce, copyforce); - _mcop_E[loopregion][copynb] = e*pow(denorm_weight, 2); + _mcop_E[loopregion][copynb] = e; - enercopy += e;//lig._denorm_weights[loopregion][copy]; + enercopy += e*pow(denorm_weight, 2);//lig._denorm_weights[loopregion][copy]; //add force to ligand assert(lig._core.Size() == coreforce.size()); From 4f0f7ecbcf6dcc60e7f5ab19faf28881b565ecd3 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 3 May 2016 16:33:14 +0200 Subject: [PATCH 72/90] Attempt at fixing buffer weights problem. --- headers/mcopff.h | 4 ++++ src/mcopff.cpp | 39 ++++++++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/headers/mcopff.h b/headers/mcopff.h index 986e910..4872c7f 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -117,6 +117,8 @@ class Mcoprigid //multicopy rigidbody std::vector > getWeights(){return _weights;}; void denormalize_weights(); void normalize_weights(); + void denormalize_buffer_weights(); + void normalize_buffer_weights(); void updateWeights(const std::vector& v, int svptr); void ReadMcoprigidPDB(const std::string name); @@ -184,6 +186,8 @@ class McopForceField: public ForceField std::vector > getWeights(){return _receptor.getWeights();}; void denormalize_weights(){_receptor.denormalize_weights();}; void normalize_weights(){_receptor.normalize_weights();}; + void denormalize_buffer_weights(){_receptor.denormalize_buffer_weights();}; + void normalize_buffer_weights(){_receptor.normalize_buffer_weights();}; private: diff --git a/src/mcopff.cpp b/src/mcopff.cpp index 6e31f59..1db8ac5 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -34,6 +34,8 @@ void Mcoprigid::iniWeights(){ } } denormalize_weights(); + _buffer_denorm_weights = _denorm_weights; + _buffer_weights = _weights; } void Mcoprigid::setCore(AttractRigidbody& core) { @@ -162,6 +164,15 @@ void Mcoprigid::denormalize_weights(){ } } +void Mcoprigid::denormalize_buffer_weights(){ + for(uint i=0; i < _buffer_weights.size(); i++){ + dbl max_weight = *max_element(_buffer_weights[i].begin(), _buffer_weights[i].end()); + for(uint j=0; j < _buffer_weights[i].size(); j++){ + _buffer_denorm_weights[i][j] = sqrt(_buffer_weights[i][j]/max_weight); + } + } +} + void Mcoprigid::normalize_weights(){ for(uint i=0; i < _denorm_weights.size(); i++){ @@ -175,6 +186,19 @@ void Mcoprigid::normalize_weights(){ } } +void Mcoprigid::normalize_buffer_weights(){ + + for(uint i=0; i < _buffer_denorm_weights.size(); i++){ + dbl sum_squared_denorm_weights = 0; + for(uint j=0; j < _buffer_denorm_weights[i].size(); j++){ + sum_squared_denorm_weights += pow(_buffer_denorm_weights[i][j], 2); + } + for(uint j=0; j < _buffer_denorm_weights[i].size(); j++){ + _buffer_weights[i][j] = pow(_buffer_denorm_weights[i][j], 2)/sum_squared_denorm_weights; + } + } +} + void Mcoprigid::updateWeights(const std::vector& v, int svptr){ //svptr: state variable "pointer" for(uint loopregion=0; loopregion < _vregion.size() ; loopregion++){ @@ -185,6 +209,8 @@ void Mcoprigid::updateWeights(const std::vector& v, int svptr){ } } normalize_weights(); + _buffer_denorm_weights = _denorm_weights; + _buffer_weights = _weights; } @@ -368,7 +394,6 @@ uint McopForceField::ProblemSize() */ dbl McopForceField::Function(const Vdouble & v) { - denormalize_weights(); dbl ener_region = 0.0 ; dbl ener_core = 0.0 ; @@ -392,10 +417,11 @@ dbl McopForceField::Function(const Vdouble & v) uint svptr = 0; // stateVars 'pointer' if (lig.getCore().hasrotation) svptr += 3; if (lig.getCore().hastranslation) svptr += 3; + //dnorm_weights is not a reference therefore we are manipulating a new set of denorm_weights std::vector< std::vector > denorm_weights = _receptor._denorm_weights; for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++){ - assert( ref_ensemble.size() == ref_denorm_weights.size()); AttractMcop& ref_ensemble = _receptor._vregion[loopregion]; + assert( ref_ensemble.size() == ref_denorm_weights.size()); std::vector & denorm_weights_loop = denorm_weights[loopregion]; for (uint copynb = 0; copynb < ref_ensemble.size(); copynb++){ dbl & denorm_weight = denorm_weights_loop[copynb]; @@ -403,9 +429,9 @@ dbl McopForceField::Function(const Vdouble & v) svptr += 1; } } - - normalize_weights(); - std::vector< std::vector > weights = _receptor._weights; + _receptor._buffer_denorm_weights = denorm_weights; + normalize_buffer_weights(); + std::vector< std::vector >& weights = _receptor._buffer_weights; //2) calculates the energy @@ -462,8 +488,7 @@ dbl McopForceField::Function(const Vdouble & v) ener_region += enercopy*max_weight; } - _receptor._buffer_weights = weights; - _receptor._buffer_denorm_weights = denorm_weights; + return ener_core + ener_region; } From ab65a14c7c5291025bc05efb6f2b9131727d92fb Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Mon, 9 May 2016 12:58:53 +0200 Subject: [PATCH 73/90] Normalization/denormalization fix in McopForceField's Funciton(). --- PyAttract/attract.py | 6 +++--- bindings/mcopff.pyx | 5 +++++ headers/mcopff.h | 1 + src/mcopff.cpp | 30 +++++++++++++----------------- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/PyAttract/attract.py b/PyAttract/attract.py index 12db36a..b2c4e62 100755 --- a/PyAttract/attract.py +++ b/PyAttract/attract.py @@ -31,14 +31,14 @@ def PrintVect(vect): print vect[i], " | ", print '' -def printWeights(w): +def printWeights(w, e): print "### WEIGHTS BEGIN" for region in xrange(0, len(w)): sum = 0 print "### Start Region %d" %(region+1) for copy in xrange(0, len(w[region])): sum += w[region][copy] - print "WEIGHT REGION %d COPY %d = %f" %(region+1, copy+1, w[region][copy]) + print "WEIGHT REGION %d COPY %d = %f (Energy = %f)" %(region+1, copy+1, w[region][copy], e[region][copy]) print "WEIGHT SUM OF WEIGHTS = %f" %sum print "### End Region %d" %(region+1) print "### WEIGHTS END" @@ -467,7 +467,7 @@ def check_ffversion(reduced): if options.regions: print "%-4s %6d %6d %13.7f %13s" %("==", transnb, rotnb, mcopff.CalcEnergy(receptor,ligand,forcefield,500), str(rms)) output.getCore().PrintMatrix() #getCore because PrintMatrix works on AttractRigidy and not Mcoprigid - printWeights(receptor.getWeights()) + printWeights(receptor.getWeights(), mcopff.getMcopE()) else: pl = AttractPairList(receptor, ligand,surreal(500)) print "%-4s %6d %6d %13.7f %13s" %("==", transnb, rotnb, forcefield.nonbon8(receptor,ligand,pl), str(rms)) diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx index aca6533..5bc4790 100644 --- a/bindings/mcopff.pyx +++ b/bindings/mcopff.pyx @@ -50,6 +50,7 @@ cdef extern from "mcopff.h" namespace "PTools": cdef cppclass CppMcopForceField "PTools::McopForceField": CppMcopForceField(CppBaseAttractForceField&, double) vector[vector[double]] getWeights() + vector[vector[double]] getMcopE() void denormalize_weights() void normalize_weights() void setReceptor(CppMcoprigid&) @@ -324,6 +325,10 @@ cdef class McopForceField(ForceField): cdef CppMcopForceField* cpp_ptr = self.thisptr return cpp_ptr.getWeights() + def getMcopE(self): + cdef CppMcopForceField* cpp_ptr = self.thisptr + return cpp_ptr.getMcopE() + def denormalize_weights(self): cdef CppMcopForceField* cpp_ptr = self.thisptr cpp_ptr.denormalize_weights() diff --git a/headers/mcopff.h b/headers/mcopff.h index 4872c7f..c06382d 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -184,6 +184,7 @@ class McopForceField: public ForceField void initMinimization(){}; std::vector > getWeights(){return _receptor.getWeights();}; + std::vector > getMcopE(){return _mcop_E;}; void denormalize_weights(){_receptor.denormalize_weights();}; void normalize_weights(){_receptor.normalize_weights();}; void denormalize_buffer_weights(){_receptor.denormalize_buffer_weights();}; diff --git a/src/mcopff.cpp b/src/mcopff.cpp index 1db8ac5..abaaad5 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -30,10 +30,9 @@ void Mcoprigid::iniWeights(){ for(uint j=0; j < _vregion[i].size(); j++){ dbl weight = 1.0/(double)_vregion[i].size(); _weights[i].push_back(weight); - _denorm_weights[i].push_back(0); + _denorm_weights[i].push_back(1); } } - denormalize_weights(); _buffer_denorm_weights = _denorm_weights; _buffer_weights = _weights; } @@ -203,14 +202,14 @@ void Mcoprigid::updateWeights(const std::vector& v, int svptr){ //svptr: state variable "pointer" for(uint loopregion=0; loopregion < _vregion.size() ; loopregion++){ for(uint copynb = 0; copynb < _vregion[loopregion].size(); copynb++){ - dbl & d_w = _denorm_weights[loopregion][copynb]; - d_w = v[svptr] + d_w; //delta weight + original weight + dbl & w = _denorm_weights[loopregion][copynb]; + w = v[svptr] + w; //delta weight + original weight svptr += 1; } } normalize_weights(); - _buffer_denorm_weights = _denorm_weights; - _buffer_weights = _weights; + //_buffer_denorm_weights = _denorm_weights; + //_buffer_weights = _weights; } @@ -410,27 +409,27 @@ dbl McopForceField::Function(const Vdouble & v) lig.AttractEulerRotate(v[0],v[1],v[2]); lig.Translate(Coord3D(v[3],v[4],v[5])); assert(_receptor._vregion.size() == _receptor._weights.size()); - assert(_receptor._vregion.size() == _receptor._denorm_weights.size()); //Update the denormalized weights uint svptr = 0; // stateVars 'pointer' if (lig.getCore().hasrotation) svptr += 3; if (lig.getCore().hastranslation) svptr += 3; - //dnorm_weights is not a reference therefore we are manipulating a new set of denorm_weights + //dnorm_weights is not a reference therefore we are manipulating a new set of weights std::vector< std::vector > denorm_weights = _receptor._denorm_weights; for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++){ AttractMcop& ref_ensemble = _receptor._vregion[loopregion]; - assert( ref_ensemble.size() == ref_denorm_weights.size()); std::vector & denorm_weights_loop = denorm_weights[loopregion]; + assert( ref_ensemble.size() == denorm_weights_loop.size()); for (uint copynb = 0; copynb < ref_ensemble.size(); copynb++){ dbl & denorm_weight = denorm_weights_loop[copynb]; - denorm_weight = v[svptr] + denorm_weight; //delta weight + original weight + denorm_weight = v[svptr] + denorm_weight; //delta weight + original weight (from before minimization) svptr += 1; } } _receptor._buffer_denorm_weights = denorm_weights; normalize_buffer_weights(); + denormalize_buffer_weights(); std::vector< std::vector >& weights = _receptor._buffer_weights; //2) calculates the energy @@ -472,7 +471,8 @@ dbl McopForceField::Function(const Vdouble & v) dbl e = _ff.nonbon8_forces(lig._core, copy, cpl, coreforce, copyforce); _mcop_E[loopregion][copynb] = e; - enercopy += e*pow(denorm_weight, 2);//lig._denorm_weights[loopregion][copy]; + enercopy += e*pow(denorm_weight, 2); + //printf("weight/energy for reg %d copy %d = %f/%f\n", loopregion, copynb, weights_loop[copynb], enercopy); //add force to ligand assert(lig._core.Size() == coreforce.size()); @@ -520,6 +520,7 @@ dbl McopForceField::CalcEnergy(Mcoprigid & receptor, Mcoprigid & ligand, BaseAtt dbl e = ff.nonbon8_forces(ligand._core, copy, cpl, coreforce, copyforce); enercopy += e*weight; + _mcop_E[loopregion][copynb] = enercopy; } ener_region += enercopy; @@ -569,9 +570,6 @@ if (lig.getCore().hasrotation){ for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++){ - std::vector& ref_weights = _receptor._buffer_weights[loopregion]; - dbl max_weight = *max_element(ref_weights.begin(), ref_weights.end()); - //printf("pLigCentered->m_activeAtoms.size() = %d\n", pLigCentered->m_activeAtoms.size()); //for (uint i=0; i< pLigCentered->m_activeAtoms.size(); i++) for(uint atomIndex=0; atomIndex<_moved_ligand._core.Size(); atomIndex++){ @@ -619,9 +617,7 @@ if (lig.getCore().hastranslation){ for (uint loopregion=0; loopregion < _receptor._vregion.size(); loopregion++){ - - std::vector& ref_weights = _receptor._buffer_weights[loopregion]; - dbl max_weight = *max_element(ref_weights.begin(), ref_weights.end()); + Coord3D ligtransForces; //translational forces for the ligand from loopregion for(uint i=0; i<_moved_ligand._core.Size(); i++){ From d67e145436475ade809e94f046177c3c25d2e0d8 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Mon, 23 May 2016 13:02:51 +0200 Subject: [PATCH 74/90] reduce translation forces --- src/mcopff.cpp | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/src/mcopff.cpp b/src/mcopff.cpp index abaaad5..df12487 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -615,25 +615,48 @@ if (lig.getCore().hastranslation){ g[svptr+1] = 0; g[svptr+2] = 0; + dbl flim = 1.0e18; + dbl ftr1, ftr2, ftr3, fbetr; + ftr1=0.0; + ftr2=0.0; + ftr3=0.0; - for (uint loopregion=0; loopregion < _receptor._vregion.size(); loopregion++){ - Coord3D ligtransForces; //translational forces for the ligand from loopregion - - for(uint i=0; i<_moved_ligand._core.Size(); i++){ - ligtransForces += _moved_ligand._core.m_forces[i]; - } - - g[svptr+0] += ligtransForces.x; - g[svptr+1] += ligtransForces.y; - g[svptr+2] += ligtransForces.z; - //printf("vector v[%d, %d, %d] = %f, %f, %f\n",svptr+0, svptr+1, svptr+2, v[svptr+0], v[svptr+1], v[svptr+2]); - //printf("vector g[%d, %d, %d] = %f, %f, %f\n",svptr+0, svptr+1, svptr+2, g[svptr+0], g[svptr+1], g[svptr+2]); + Coord3D ligtransForces; //translational forces for the ligand from loopregion + + for(uint i=0; i<_moved_ligand._core.Size(); i++){ + ligtransForces += _moved_ligand._core.m_forces[i]; } + + ftr1 = ligtransForces.x; + ftr2 = ligtransForces.y; + ftr3 = ligtransForces.z; + //printf("vector v[%d, %d, %d] = %f, %f, %f\n",svptr+0, svptr+1, svptr+2, v[svptr+0], v[svptr+1], v[svptr+2]); + //printf("vector g[%d, %d, %d] = %f, %f, %f\n",svptr+0, svptr+1, svptr+2, g[svptr+0], g[svptr+1], g[svptr+2]); + svptr += 3; + + // force reduction, some times helps in case of very "bad" start structure + for (uint i=0; i<3; i++) + { + fbetr=ftr1*ftr1 +ftr2*ftr2 +ftr3*ftr3; + if (fbetr > flim) + { + ftr1=.01*ftr1; + ftr2=.01*ftr2; + ftr3=.01*ftr3; + } + } + + assert(svptr+2 < g.size()); + g[svptr+0] = ftr1; + g[svptr+1] = ftr2; + g[svptr+2] = ftr3; } + + // Calculate de weight derivative assert(_receptor._vregion.size() == _mcop_E.size()); From 18a9cd2e91c600d8b9005d7e5c22a71dfac15328 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Mon, 23 May 2016 13:03:42 +0200 Subject: [PATCH 75/90] keep tranlation id from translation file --- PyAttract/attract.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/PyAttract/attract.py b/PyAttract/attract.py index b2c4e62..bb9da12 100755 --- a/PyAttract/attract.py +++ b/PyAttract/attract.py @@ -331,6 +331,15 @@ def check_ffversion(reduced): else: Rmsd_alias = rmsdca +firstr = 0 +ff = open("translation.dat",'r') +for line in ff: + if "ATOM" in line: + spl = line.split() + firstr = int(spl[1])-1 + break +ff.close() + if (not options.single): #systematic docking with default translations and rotations # check for rotation.dat and translation.dat @@ -354,16 +363,10 @@ def check_ffversion(reduced): checkFile("rotation.dat", "rotation file is required.") checkFile("translation.dat", "translation file is required.\nFormer users may rename translat.dat into translation.dat.") trans=Rigidbody("translation.dat") - + co=trans.GetCoords(options.transnb) + translations=[[options.transnb+1,co]] transnb=options.transnb - - if options.start1 is True: - transnb -= 1 - - co=trans.getCoords(transnb) - translations=[[transnb+1,co]] - - if transnb!= len(trans)-1: + if transnb!=trans.Size()-1: printFiles=False #don't append ligand, receptor, etc. unless this is the last translation point of the simulation @@ -371,7 +374,7 @@ def check_ffversion(reduced): # core attract algorithm for trans in translations: transnb+=1 - print "@@@@@@@ Translation nb %i @@@@@@@" %(transnb) + print "@@@@@@@ Translation nb %i @@@@@@@" %(transnb+firstr) rotnb=0 for rot in rotations: rotnb+=1 @@ -465,12 +468,12 @@ def check_ffversion(reduced): forcefield=ff_specs['ff_class'](ff_specs['ff_file'], surreal(500)) print "%4s %6s %6s %13s %13s" %(" ","Trans", "Rot", "Ener", "RmsdCA_ref") if options.regions: - print "%-4s %6d %6d %13.7f %13s" %("==", transnb, rotnb, mcopff.CalcEnergy(receptor,ligand,forcefield,500), str(rms)) + print "%-4s %6d %6d %13.7f %13s" %("==", transnb + firstr, rotnb, mcopff.CalcEnergy(receptor,ligand,forcefield,500), str(rms)) output.getCore().PrintMatrix() #getCore because PrintMatrix works on AttractRigidy and not Mcoprigid printWeights(receptor.getWeights(), mcopff.getMcopE()) else: pl = AttractPairList(receptor, ligand,surreal(500)) - print "%-4s %6d %6d %13.7f %13s" %("==", transnb, rotnb, forcefield.nonbon8(receptor,ligand,pl), str(rms)) + print "%-4s %6d %6d %13.7f %13s" %("==", transnb + firstr, rotnb, forcefield.nonbon8(receptor,ligand,pl), str(rms)) output.PrintMatrix() From 8e839b8a1160f345b6123152107a135281689c80 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Thu, 9 Jun 2016 10:40:50 +0200 Subject: [PATCH 76/90] debug prints commented --- src/attractforcefield.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/attractforcefield.cpp b/src/attractforcefield.cpp index 2970e86..bfe284b 100644 --- a/src/attractforcefield.cpp +++ b/src/attractforcefield.cpp @@ -355,10 +355,11 @@ dbl BaseAttractForceField::Function(const Vdouble& stateVars ) //put the ligands to the correct positions defined by stateVars for (uint i=0; im_activeAtoms.size(); i++) { @@ -664,8 +678,12 @@ void BaseAttractForceField::Rota(uint molIndex, dbl phi,dbl ssi, dbl rot, Vdoubl Y = coords.y; Z = coords.z; + //std::cout << "X " << X << std::endl; + xar=X*crot+Y*srot; yar=-X*srot+Y*crot; + + pm[0][0]=-xar*cssp-yar*cp-Z*sssp ; pm[1][0]=xar*cscp-yar*sp+Z*sscp ; pm[2][0]=0.0 ; @@ -678,6 +696,18 @@ void BaseAttractForceField::Rota(uint molIndex, dbl phi,dbl ssi, dbl rot, Vdoubl pm[1][2]=yar*cssp-xar*cp ; pm[2][2]=-yar*ss ; + //std::cout << "xar " << xar << std::endl; + //std::cout << "yar " << yar << std::endl; + //std::cout << "pm[0][0] " << pm[0][0] << std::endl; + //std::cout << "pm[1][0] " << pm[1][0] << std::endl; + //std::cout << "pm[2][0] " << pm[2][0] << std::endl; + //std::cout << "pm[0][1] " << pm[0][1] << std::endl; + //std::cout << "pm[1][1] " << pm[1][1] << std::endl; + //std::cout << "pm[2][1] " << pm[2][1] << std::endl; + //std::cout << "pm[0][2] " << pm[0][2] << std::endl; + //std::cout << "pm[1][2] " << pm[1][2] << std::endl; + //std::cout << "pm[2][2] " << pm[2][2] << std::endl; + for (uint j=0;j<3;j++) { delta[j+shift] += pm[0][j] * pLigMoved->m_forces[atomIndex].x ; @@ -686,6 +716,7 @@ void BaseAttractForceField::Rota(uint molIndex, dbl phi,dbl ssi, dbl rot, Vdoubl } } + if (print) std::cout << "Rotational forces: " << delta[shift] << " " << delta[shift+1] << " " << delta[shift+2] << std::endl; return; From 5e15281e5e259596ec029c25499af73b565e971d Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Thu, 9 Jun 2016 10:42:14 +0200 Subject: [PATCH 77/90] debug prints commented --- src/minimizers/lbfgs_interface.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/minimizers/lbfgs_interface.cpp b/src/minimizers/lbfgs_interface.cpp index 09dc06c..8c02651 100644 --- a/src/minimizers/lbfgs_interface.cpp +++ b/src/minimizers/lbfgs_interface.cpp @@ -116,6 +116,12 @@ void Lbfgs::minimize(int maxiter) break; } else if (rc == 1) { + //for(int i=0; i Date: Thu, 9 Jun 2016 10:43:07 +0200 Subject: [PATCH 78/90] remove debug prints --- src/rigidbody.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rigidbody.cpp b/src/rigidbody.cpp index cfa71c0..2c6510b 100644 --- a/src/rigidbody.cpp +++ b/src/rigidbody.cpp @@ -144,7 +144,9 @@ dbl Rigidbody::Radius() void Rigidbody::Translate(const Coord3D& tr) { + CoordsArray::Translate(tr); + } void Rigidbody::AttractEulerRotate(dbl phi, dbl ssi, dbl rot) From f18bae2d857ce3deb0704ae38e68f0b27f37504e Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Thu, 9 Jun 2016 10:45:10 +0200 Subject: [PATCH 79/90] Add weight evolution in single option and fix bug: minimize with centered ligand in mcop docking. --- PyAttract/attract.py | 16 ++++- headers/mcopff.h | 6 +- src/mcopff.cpp | 142 +++++++++++++++++++++++++++++++------------ 3 files changed, 119 insertions(+), 45 deletions(-) diff --git a/PyAttract/attract.py b/PyAttract/attract.py index bb9da12..ccb4370 100755 --- a/PyAttract/attract.py +++ b/PyAttract/attract.py @@ -319,6 +319,8 @@ def check_ffversion(reduced): trjname = "minimization.trj" if (options.single): ftraj = open(trjname, "w") + if(options.regions): + weight_variation = open("weight_variation.dat", "w") if (options.reffile): checkFile(options.reffile, "") @@ -407,8 +409,8 @@ def check_ffversion(reduced): receptor.setRotation(False) if options.regions: - mcopff.setReceptor(receptor) mcopff.setLigand(ligand) + mcopff.setReceptor(receptor) else: forcefield.AddLigand(receptor) forcefield.AddLigand(ligand) @@ -447,10 +449,18 @@ def check_ffversion(reduced): ntraj=lbfgs_minimizer.GetNumberIter() for iteration in range(ntraj): traj = lbfgs_minimizer.GetMinimizedVarsAtIter(iteration) - for t in traj: + for t in traj[0:6]: ftraj.write("%f "%t) ftraj.write("\n") ftraj.write("~~~~~~~~~~~~~~\n") + if (options.regions): + for iteration in range(ntraj): + traj = lbfgs_minimizer.GetMinimizedVarsAtIter(iteration) + for t in traj[6:]: + weight_variation.write("%f "%t) + weight_variation.write("\n") + weight_variation.write("~~~~~~~~~~~~~~\n") + #computes RMSD if reference structure available @@ -489,6 +499,8 @@ def check_ffversion(reduced): # close trajectory file for single minimization if (options.single): ftraj.close() + if (options.regions): + weight_variation.close() print "Saved all minimization variables (translations/rotations) in %s" %(trjname) # print end and elapsed time diff --git a/headers/mcopff.h b/headers/mcopff.h index c06382d..777c52c 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -111,7 +111,7 @@ class Mcoprigid //multicopy rigidbody void AttractEulerRotate(const dbl& phi, const dbl& ssi, const dbl& rot); void Translate(const Coord3D& c); - Coord3D FindCenter(){_core.FindCenter();}; + Coord3D FindCenter(){return _core.FindCenter();}; void PrintWeights(); std::vector > getWeights(){return _weights;}; @@ -175,8 +175,8 @@ class McopForceField: public ForceField void Derivatives(const Vdouble& v, Vdouble & g ); - void setReceptor(const Mcoprigid& rec) {_receptor = rec; ini_energies();}; - void setLigand(const Mcoprigid& lig) { _centered_ligand = lig;}; + void setReceptor(Mcoprigid& rec); + void setLigand(Mcoprigid& lig); void calculate_weights(Mcoprigid& lig, bool print=false); diff --git a/src/mcopff.cpp b/src/mcopff.cpp index df12487..0367115 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -64,6 +64,7 @@ void Mcoprigid::AttractEulerRotate(const dbl& phi, const dbl& ssi, const dbl& ro void Mcoprigid::Translate(const Coord3D& c) { + //translates the core body: _core.Translate(c); @@ -305,6 +306,29 @@ AttractMcop::AttractMcop(const Mcop& mcop){ // Forcefield implementation /////////////////////////////////////////////////// +void McopForceField::setReceptor( Mcoprigid& rec){ + + Mcoprigid centeredrec = rec; + //Coord3D center = rec.FindCenter(); + //rec._center = center; + Coord3D center = _moved_ligand._center; + + centeredrec.Translate(Coord3D()-center); + _receptor = centeredrec; + + ini_energies(); +} + +void McopForceField::setLigand( Mcoprigid& lig){ + + Mcoprigid centeredlig = lig; + Coord3D center = lig.FindCenter(); + lig._center = center; + _moved_ligand = lig; + + centeredlig.Translate(Coord3D()-center); + _centered_ligand = centeredlig; +} void McopForceField::ini_energies(){ for(uint i=0; i < _receptor.getRegions().size(); i++){ @@ -316,6 +340,8 @@ void McopForceField::ini_energies(){ } } + + void McopForceField::calculate_weights(Mcoprigid& lig, bool print) { @@ -375,6 +401,7 @@ void McopForceField::calculate_weights(Mcoprigid& lig, bool print) uint McopForceField::ProblemSize() { + uint size = 0; if (_centered_ligand.getCore().hastranslation) size += 3; if (_centered_ligand.getCore().hasrotation) size += 3; @@ -398,7 +425,7 @@ dbl McopForceField::Function(const Vdouble & v) dbl ener_core = 0.0 ; // 1) put the objects to the right place - + _moved_ligand = _centered_ligand; Mcoprigid & lig = _moved_ligand ; @@ -550,6 +577,13 @@ if (lig.getCore().hasrotation){ g[svptr+1] = 0; g[svptr+2] = 0; + for (uint i=0; i<3;i++) + { + g[i+svptr]=0.0; + for (uint j=0;j<3;j++) + pm[i][j]=0.0 ; + } + cs=cos(v[svptr+1]); cp=cos(v[svptr+0]); ss=sin(v[svptr+1]); @@ -561,56 +595,84 @@ if (lig.getCore().hasrotation){ crot=cos(v[svptr+2]); srot=sin(v[svptr+2]); + //std::cout << "cs" << cs << std::endl; + //std::cout << "cp" << cp << std::endl; + //std::cout << "ss" << ss << std::endl; + //std::cout << "sp" << sp << std::endl; + //std::cout << "cscp" << cscp << std::endl; + //std::cout << "cssp" << cssp << std::endl; + //std::cout << "sscp" << sscp << std::endl; + //std::cout << "sssp" << sssp << std::endl; + //std::cout << "crot" << crot << std::endl; + //std::cout << "srot" << srot << std::endl; + // for the x, y and z coordinates, we need // the coordinates of the centered, non-translated molecule AttractRigidbody * pLigCentered = & _centered_ligand._core; // pointer to the centered ligand AttractRigidbody * pLigMoved = & _moved_ligand._core; // pointer to the rotated/translated ligand (for forces) - - for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++){ - - //printf("pLigCentered->m_activeAtoms.size() = %d\n", pLigCentered->m_activeAtoms.size()); - //for (uint i=0; i< pLigCentered->m_activeAtoms.size(); i++) - for(uint atomIndex=0; atomIndex<_moved_ligand._core.Size(); atomIndex++){ - //uint atomIndex = pLigCentered->m_activeAtoms[i]; - - Coord3D coords = pLigCentered->GetCoords(atomIndex); - X = coords.x; - Y = coords.y; - Z = coords.z; - - xar=X*crot+Y*srot; - yar=-X*srot+Y*crot; - pm[0][0]=-xar*cssp-yar*cp-Z*sssp ; - pm[1][0]=xar*cscp-yar*sp+Z*sscp ; - pm[2][0]=0.0 ; - - pm[0][1]=-xar*sscp+Z*cscp ; - pm[1][1]=-xar*sssp+Z*cssp ; - pm[2][1]=-xar*cs-Z*ss ; - - pm[0][2]=yar*cscp+xar*sp ; - pm[1][2]=yar*cssp-xar*cp ; - pm[2][2]=-yar*ss ; - - for(uint j=0; j < 3; j++){ - g[svptr + j] += pm[0][j] * pLigMoved->m_forces[atomIndex].x; - g[svptr + j] += pm[1][j] * pLigMoved->m_forces[atomIndex].y; - g[svptr + j] += pm[2][j] * pLigMoved->m_forces[atomIndex].z; - } - //printf("vector v[%d, %d, %d] = %f, %f, %f\n",svptr+0, svptr+1, svptr+2, v[svptr+0], v[svptr+1], v[svptr+2]); - //printf("vector g[%d, %d, %d] = %f, %f, %f\n",svptr+0, svptr+1, svptr+2, g[svptr+0], g[svptr+1], g[svptr+2]); + dbl add = 0; + dbl add2 = 0; + //printf("pLigCentered->m_activeAtoms.size() = %d\n", pLigCentered->m_activeAtoms.size()); + //for (uint i=0; i< pLigCentered->m_activeAtoms.size(); i++) + for(uint atomIndex=0; atomIndex<_moved_ligand._core.Size(); atomIndex++){ + //uint atomIndex = pLigCentered->m_activeAtoms[i]; + + + Coord3D coords = pLigCentered->GetCoords(atomIndex); + + X = coords.x; + Y = coords.y; + Z = coords.z; + + //std::cout << "X " << X << std::endl; + + xar=X*crot+Y*srot; + yar=-X*srot+Y*crot; + + pm[0][0]=-xar*cssp-yar*cp-Z*sssp ; + pm[1][0]=xar*cscp-yar*sp+Z*sscp ; + pm[2][0]=0.0 ; + + pm[0][1]=-xar*sscp+Z*cscp ; + pm[1][1]=-xar*sssp+Z*cssp ; + pm[2][1]=-xar*cs-Z*ss ; + + pm[0][2]=yar*cscp+xar*sp ; + pm[1][2]=yar*cssp-xar*cp ; + pm[2][2]=-yar*ss ; + + //std::cout << "xar " << xar << std::endl; + //std::cout << "yar " << yar << std::endl; + //std::cout << "pm[0][0] " << pm[0][0] << std::endl; + //std::cout << "pm[1][0] " << pm[1][0] << std::endl; + //std::cout << "pm[2][0] " << pm[2][0] << std::endl; + //std::cout << "pm[0][1] " << pm[0][1] << std::endl; + //std::cout << "pm[1][1] " << pm[1][1] << std::endl; + //std::cout << "pm[2][1] " << pm[2][1] << std::endl; + //std::cout << "pm[0][2] " << pm[0][2] << std::endl; + //std::cout << "pm[1][2] " << pm[1][2] << std::endl; + //std::cout << "pm[2][2] " << pm[2][2] << std::endl; + + for(uint j=0; j < 3; j++){ + g[svptr + j] += pm[0][j] * pLigMoved->m_forces[atomIndex].x; + g[svptr + j] += pm[1][j] * pLigMoved->m_forces[atomIndex].y; + g[svptr + j] += pm[2][j] * pLigMoved->m_forces[atomIndex].z; } - + //printf("vector v[%d, %d, %d] = %f, %f, %f\n",svptr+0, svptr+1, svptr+2, v[svptr+0], v[svptr+1], v[svptr+2]); + //printf("vector g[%d, %d, %d] = %f, %f, %f\n",svptr+0, svptr+1, svptr+2, g[svptr+0], g[svptr+1], g[svptr+2]); } + + svptr += 3; + } //sum the forces over x, y and z: calculate de translational forces if (lig.getCore().hastranslation){ - //printf("hastranslation\n"); + g[svptr+0] = 0; g[svptr+1] = 0; g[svptr+2] = 0; @@ -621,7 +683,6 @@ if (lig.getCore().hastranslation){ ftr2=0.0; ftr3=0.0; - Coord3D ligtransForces; //translational forces for the ligand from loopregion for(uint i=0; i<_moved_ligand._core.Size(); i++){ @@ -635,8 +696,6 @@ if (lig.getCore().hastranslation){ //printf("vector g[%d, %d, %d] = %f, %f, %f\n",svptr+0, svptr+1, svptr+2, g[svptr+0], g[svptr+1], g[svptr+2]); - svptr += 3; - // force reduction, some times helps in case of very "bad" start structure for (uint i=0; i<3; i++) { @@ -649,10 +708,13 @@ if (lig.getCore().hastranslation){ } } + assert(svptr+2 < g.size()); g[svptr+0] = ftr1; g[svptr+1] = ftr2; g[svptr+2] = ftr3; + + svptr += 3; } From e4699124411f6852786b00c4923d582ba477c618 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Thu, 9 Jun 2016 13:33:07 +0200 Subject: [PATCH 80/90] Fixed bug: polymorphic CalcEnergy() function in mcopff binding interface. --- PyAttract/attract.py | 2 +- bindings/_ptools.pyx | 2 +- bindings/attractforcefield.pyx | 1 + bindings/mcopff.pyx | 28 +++++++-------------------- bindings/scorpionforcefield.pyx | 34 +++++++++++++++++++++++++-------- 5 files changed, 36 insertions(+), 31 deletions(-) diff --git a/PyAttract/attract.py b/PyAttract/attract.py index ccb4370..27a83a0 100755 --- a/PyAttract/attract.py +++ b/PyAttract/attract.py @@ -258,7 +258,7 @@ def check_ffversion(reduced): allff_specs = { 'SCORPION': {'ff_file': 'scorpion.par', 'ff_class': ScorpionForceField, - 'minimizer_class': ScorpionLbfgs + 'minimizer_class': Lbfgs }, 'ATTRACT1': {'ff_file': 'aminon.par', diff --git a/bindings/_ptools.pyx b/bindings/_ptools.pyx index 87c15da..2d56744 100644 --- a/bindings/_ptools.pyx +++ b/bindings/_ptools.pyx @@ -10,7 +10,7 @@ include "atomselection.pyx" include "attractforcefield.pyx" include "scorpionforcefield.pyx" include "lbfgs.pyx" -include "scorpion_lbfgs.pyx" +#include "scorpion_lbfgs.pyx" include "rmsd.pyx" include "version.pyx" include "coordsarray.pyx" diff --git a/bindings/attractforcefield.pyx b/bindings/attractforcefield.pyx index f41d119..dd28d1f 100644 --- a/bindings/attractforcefield.pyx +++ b/bindings/attractforcefield.pyx @@ -1,6 +1,7 @@ from cython.operator cimport dereference as deref from libcpp.string cimport string + cdef extern from "" namespace "std": cdef cppclass vector[T]: cppclass iterator: diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx index 5bc4790..9b5065f 100644 --- a/bindings/mcopff.pyx +++ b/bindings/mcopff.pyx @@ -55,9 +55,7 @@ cdef extern from "mcopff.h" namespace "PTools": void normalize_weights() void setReceptor(CppMcoprigid&) void setLigand(CppMcoprigid&) - double CalcEnergy(CppMcoprigid&, CppMcoprigid&, CppScorpionForceField&, double) - double CalcEnergy(CppMcoprigid&, CppMcoprigid&, CppAttractForceField1&, double) - double CalcEnergy(CppMcoprigid&, CppMcoprigid&, CppAttractForceField2&, double) + double CalcEnergy(CppMcoprigid&, CppMcoprigid&, CppBaseAttractForceField&, double) cdef class Mcop: cdef CppMcop* thisptr @@ -345,26 +343,14 @@ cdef class McopForceField(ForceField): cdef CppMcopForceField* cpp_ptr = self.thisptr cpp_ptr.setLigand(deref(lig.thisptr)) - - def CalcEnergy(self, Mcoprigid rec, Mcoprigid lig, ScorpionForceField ff, double cutoff): - cdef CppMcopForceField* cpp_ptr = self.thisptr - cdef CppScorpionForceField* cppff_scorp - cppff_scorp = ff.thisptr - return cpp_ptr.CalcEnergy(deref(rec.thisptr), deref(lig.thisptr), deref(cppff_scorp), cutoff) - - def CalcEnergy(self, Mcoprigid rec, Mcoprigid lig, AttractForceField1 ff, double cutoff): - cdef CppMcopForceField* cpp_ptr = self.thisptr - cdef CppAttractForceField1* cppff_att1 - cppff_scorp = ff.thisptr - return cpp_ptr.CalcEnergy(deref(rec.thisptr), deref(lig.thisptr), deref(cppff_att1), cutoff) - - def CalcEnergy(self, Mcoprigid rec, Mcoprigid lig, AttractForceField2 ff, double cutoff): + def CalcEnergy(self, Mcoprigid rec, Mcoprigid lig, BaseAttractForceField ff, double cutoff): + cdef CppMcopForceField* cpp_ptr = self.thisptr - cdef CppAttractForceField2* cppff_att2 - cppff_scorp = ff.thisptr - return cpp_ptr.CalcEnergy(deref(rec.thisptr), deref(lig.thisptr), deref(cppff_att2), cutoff) + cdef CppBaseAttractForceField* cppff + + cppff = ff.thisptr + return cpp_ptr.CalcEnergy(deref(rec.thisptr), deref(lig.thisptr), deref(cppff), cutoff) - \ No newline at end of file diff --git a/bindings/scorpionforcefield.pyx b/bindings/scorpionforcefield.pyx index 0be6502..d172234 100644 --- a/bindings/scorpionforcefield.pyx +++ b/bindings/scorpionforcefield.pyx @@ -2,6 +2,14 @@ from cython.operator cimport dereference as deref from libcpp.string cimport string +cdef extern from "forcefield.h" namespace "PTools": + cdef cppclass CppForceField "PTools::ForceField": + pass + +cdef extern from "attractforcefield.h" namespace "PTools": + cdef cppclass CppBaseAttractForceField "PTools::BaseAttractForceField": + pass + cdef extern from "scorpionforcefield.h" namespace "PTools": cdef cppclass CppScorpionForceField "PTools::ScorpionForceField": CppScorpionForceField(string&, double) @@ -12,38 +20,48 @@ cdef extern from "scorpionforcefield.h" namespace "PTools": double nonbon8(CppAttractRigidbody& , CppAttractRigidbody& , CppAttractPairList & , int) -cdef class ScorpionForceField: +cdef class ScorpionForceField (BaseAttractForceField): - cdef CppScorpionForceField* thisptr + #cdef CppScorpionForceField* thisptr def __cinit__(self, filename, cutoff): + + # deallocate + del self.thisptr + self.thisptr = 0 + cdef char* c_filename cdef string * cppname c_filename = filename cppname = new string(c_filename) - self.thisptr = new CppScorpionForceField(deref(cppname), cutoff) + self.thisptr = new CppScorpionForceField(deref(cppname), cutoff) del cppname def __dealloc__(self): del self.thisptr def AddLigand(self, AttractRigidbody rig): - self.thisptr.AddLigand(deref( rig.thisptr)) + cdef CppBaseAttractForceField* cpp_ptr = self.thisptr + cpp_ptr.AddLigand(deref(rig.thisptr)) def Function(self, vec): cdef vector[double] v for el in vec: v.push_back(el) - return self.thisptr.Function(v) + cdef CppBaseAttractForceField* cpp_ptr = self.thisptr + return cpp_ptr.Function(v) def getVdw(self): - return self.thisptr.getVdw() + cdef CppBaseAttractForceField* cpp_ptr = self.thisptr + return cpp_ptr.getVdw() def getCoulomb(self): - return self.thisptr.getCoulomb() + cdef CppBaseAttractForceField* cpp_ptr = self.thisptr + return cpp_ptr.getCoulomb() def nonbon8(self, AttractRigidbody rec, AttractRigidbody lig, AttractPairList pl, verbose=False): - return self.thisptr.nonbon8(deref(rec.thisptr), deref(lig.thisptr), deref(pl.thisptr), verbose) + cdef CppBaseAttractForceField* cpp_ptr = self.thisptr + return cpp_ptr.nonbon8(deref(rec.thisptr), deref(lig.thisptr), deref(pl.thisptr), verbose) From 5570b90895349c432d8e6f2b9af7a63a398b9c64 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Thu, 9 Jun 2016 13:35:44 +0200 Subject: [PATCH 81/90] No longer need Scorpion_Lbfgs.pyx because same as Lbfgs.pyx --- bindings/scorpion_lbfgs.pyx | 43 ------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 bindings/scorpion_lbfgs.pyx diff --git a/bindings/scorpion_lbfgs.pyx b/bindings/scorpion_lbfgs.pyx deleted file mode 100644 index 0ac2a22..0000000 --- a/bindings/scorpion_lbfgs.pyx +++ /dev/null @@ -1,43 +0,0 @@ -from cython.operator cimport dereference as dereference -from libcpp.string cimport string - -cdef extern from "lbfgs_interface.h" namespace "PTools": - cdef cppclass CppScorpionLbfgs "PTools::Lbfgs": - CppScorpionLbfgs(CppScorpionForceField&) - void minimize(int) - vector[double] GetMinimizedVars() - vector[double] GetMinimizedVarsAtIter(int) - int GetNumberIter() - -cdef class ScorpionLbfgs: - - cdef CppScorpionLbfgs * thisptr - - def __cinit__(self, forcefield): - - ff = forcefield - cdef CppScorpionForceField * ffptr = ff.thisptr - self.thisptr = new CppScorpionLbfgs(deref(ffptr)) - - def __dealloc__(self): - del self.thisptr - - def minimize(self, int maxiter): - self.thisptr.minimize(maxiter) - - def GetMinimizedVars(self): - cdef vector[double] vars = self.thisptr.GetMinimizedVars() - out = [] - for i in xrange(vars.size()): - out.append(vars[i]) - return out - - def GetNumberIter(self): - return self.thisptr.GetNumberIter() - - def GetMinimizedVarsAtIter(self, int iter): - cdef vector[double] vars = self.thisptr.GetMinimizedVarsAtIter(iter) - out = [] - for i in xrange(vars.size()): - out.append(vars[i]) - return out From 1c823dd14ad5851d2f75b66e3891df7e59684cc2 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Mon, 13 Jun 2016 16:32:35 +0200 Subject: [PATCH 82/90] Added --trans and --rot options to attract.py which allows us to do a single docking and create a trajectory file. This is like using the -s single option, but uses the original coordinates rather than the rounded coordinates from the pdb file created by startligand.py. --- PyAttract/attract.py | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/PyAttract/attract.py b/PyAttract/attract.py index 27a83a0..db83df0 100755 --- a/PyAttract/attract.py +++ b/PyAttract/attract.py @@ -95,6 +95,9 @@ def __init__(self): def __iter__(self): return self._rot.__iter__() + def __getitem__(self, i): + return self._rot.__getitem__(i) + class Translation: @@ -195,13 +198,14 @@ def checkFile(name, comment): ## MAIN ATTRACT PROGRAM # ########################### from optparse import OptionParser -parser = OptionParser(usage="%prog -r receptor_file -l ligand_file [-h] [-s] [-t] [--ref]") +parser = OptionParser(usage="%prog -r receptor_file -l ligand_file [-h] [-s] [-trans] [-rot] [--ref]") parser.add_option("-r", "--receptor", action="store", type="string", dest="receptor_name", help="name of the receptor file") parser.add_option("-l", "--ligand", action="store", type="string", dest="ligand_name", help="name of the ligand file") parser.add_option("-s", "--single", action="store_true", dest="single", default=False, help="single minimization mode") parser.add_option("--ref", action="store", type="string", dest="reffile", help="reference ligand for rmsd" ) -parser.add_option("-t", "--translation", action="store", type="int", dest="transnb", help="translation number (distributed mode) starting from 0 for the first one!") -parser.add_option("--start1", action="store_true", default=False, dest="start1", help="(only useful with -t), use 1 for the first translation point") +parser.add_option("--trans", "--translation", action="store", type="int", dest="transnb", help="translation number (distributed mode).") +parser.add_option("--rot", "--rotation", action="store", type="int", dest="rotnb", help="rotation number (distributed mode).") +parser.add_option("--start1", action="store_true", default=False, dest="start1", help="(only useful with -trans), use 1 for the first translation point") parser.add_option("--mcop", action="store_true", default=False, dest="regions", help="mcop option for multi-copy rigid-body docking") (options, args) = parser.parse_args() @@ -312,12 +316,12 @@ def check_ffversion(reduced): print "Reading receptor (fixed): %s with %d particules" %( options.receptor_name, len(rec) ) print "Reading ligand (mobile): %s with %d particules" %( options.ligand_name, len(lig) ) -if (options.single and options.transnb): - parser.error("options -s and -t are mutually exclusive") +if (options.single and (options.transnb or options.rotnb)): + parser.error("options -s and -trans/rot are mutually exclusive") # save all minimization variables in trajectory file trjname = "minimization.trj" -if (options.single): +if (options.single or (options.transnb and options.rotnb)): ftraj = open(trjname, "w") if(options.regions): weight_variation = open("weight_variation.dat", "w") @@ -358,20 +362,21 @@ def check_ffversion(reduced): printFiles=True -# option -t used: define the selected translation +# option -trans used: define the selected translation transnb=0 if (options.transnb!=None): # check for rotation.dat and translation.dat checkFile("rotation.dat", "rotation file is required.") checkFile("translation.dat", "translation file is required.\nFormer users may rename translat.dat into translation.dat.") trans=Rigidbody("translation.dat") - co=trans.GetCoords(options.transnb) - translations=[[options.transnb+1,co]] - transnb=options.transnb - if transnb!=trans.Size()-1: + co=trans.getCoords(options.transnb-1) + translations=[[options.transnb,co]] + transnb=options.transnb-1 + if transnb!=len(trans)-1: printFiles=False #don't append ligand, receptor, etc. unless this is the last translation point of the simulation - +if (options.rotnb!=None): + rotations = [rotations[options.rotnb-1]] # core attract algorithm for trans in translations: @@ -394,6 +399,7 @@ def check_ffversion(reduced): ligand.AttractEulerRotate(surreal(rot[0]),surreal(rot[1]),surreal(rot[2])) ligand.Translate(trans[1]) + for minim in minimlist: minimcounter+=1 cutoff=math.sqrt(minim['squarecutoff']) @@ -417,6 +423,7 @@ def check_ffversion(reduced): rstk=minim['rstk'] #restraint force #if rstk>0.0: #forcefield.SetRestraint(rstk) + if options.regions: lbfgs_minimizer=Lbfgs(mcopff) lbfgs_minimizer.minimize(niter) @@ -445,7 +452,7 @@ def check_ffversion(reduced): ligand=Mcoprigid(output) else: ligand=AttractRigidbody(output) - if (options.single): + if (options.single or (options.transnb and options.rotnb)): ntraj=lbfgs_minimizer.GetNumberIter() for iteration in range(ntraj): traj = lbfgs_minimizer.GetMinimizedVarsAtIter(iteration) @@ -497,7 +504,7 @@ def check_ffversion(reduced): print compress_file("attract.inp") # close trajectory file for single minimization -if (options.single): +if (options.single or (options.transnb and options.rotnb)): ftraj.close() if (options.regions): weight_variation.close() From 81d192dd139a1ce98e1ec3e0f7d891f0775269f4 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Wed, 29 Jun 2016 10:54:42 +0200 Subject: [PATCH 83/90] Remove unused variables. --- src/mcopff.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/mcopff.cpp b/src/mcopff.cpp index 0367115..92e17d7 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -612,8 +612,6 @@ if (lig.getCore().hasrotation){ AttractRigidbody * pLigCentered = & _centered_ligand._core; // pointer to the centered ligand AttractRigidbody * pLigMoved = & _moved_ligand._core; // pointer to the rotated/translated ligand (for forces) - dbl add = 0; - dbl add2 = 0; //printf("pLigCentered->m_activeAtoms.size() = %d\n", pLigCentered->m_activeAtoms.size()); //for (uint i=0; i< pLigCentered->m_activeAtoms.size(); i++) for(uint atomIndex=0; atomIndex<_moved_ligand._core.Size(); atomIndex++){ From fd67fbfb241d38562221afa5063353ec4733c024 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Wed, 29 Jun 2016 11:00:11 +0200 Subject: [PATCH 84/90] remove pow --- src/mcopff.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mcopff.cpp b/src/mcopff.cpp index 92e17d7..386a135 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -498,7 +498,7 @@ dbl McopForceField::Function(const Vdouble & v) dbl e = _ff.nonbon8_forces(lig._core, copy, cpl, coreforce, copyforce); _mcop_E[loopregion][copynb] = e; - enercopy += e*pow(denorm_weight, 2); + enercopy += e*denorm_weight*denorm_weight; //printf("weight/energy for reg %d copy %d = %f/%f\n", loopregion, copynb, weights_loop[copynb], enercopy); //add force to ligand @@ -547,7 +547,7 @@ dbl McopForceField::CalcEnergy(Mcoprigid & receptor, Mcoprigid & ligand, BaseAtt dbl e = ff.nonbon8_forces(ligand._core, copy, cpl, coreforce, copyforce); enercopy += e*weight; - _mcop_E[loopregion][copynb] = enercopy; + _mcop_E[loopregion][copynb] = e; } ener_region += enercopy; From b13f6303b2f41668f4719cce12300c486b71f607 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Wed, 29 Jun 2016 11:04:27 +0200 Subject: [PATCH 85/90] Remove pow calls. Switch corefore copyforce arguments in nonbon8_forces call and in cpl pairlist. --- src/mcopff.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mcopff.cpp b/src/mcopff.cpp index 386a135..409a15f 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -178,10 +178,10 @@ void Mcoprigid::normalize_weights(){ for(uint i=0; i < _denorm_weights.size(); i++){ dbl sum_squared_denorm_weights = 0; for(uint j=0; j < _denorm_weights[i].size(); j++){ - sum_squared_denorm_weights += pow(_denorm_weights[i][j], 2); + sum_squared_denorm_weights += _denorm_weights[i][j]*_denorm_weights[i][j]; } for(uint j=0; j < _denorm_weights[i].size(); j++){ - _weights[i][j] = pow(_denorm_weights[i][j], 2)/sum_squared_denorm_weights; + _weights[i][j] = (_denorm_weights[i][j]*_denorm_weights[i][j])/sum_squared_denorm_weights; } } } @@ -191,10 +191,10 @@ void Mcoprigid::normalize_buffer_weights(){ for(uint i=0; i < _buffer_denorm_weights.size(); i++){ dbl sum_squared_denorm_weights = 0; for(uint j=0; j < _buffer_denorm_weights[i].size(); j++){ - sum_squared_denorm_weights += pow(_buffer_denorm_weights[i][j], 2); + sum_squared_denorm_weights += _buffer_denorm_weights[i][j]*_buffer_denorm_weights[i][j]; } for(uint j=0; j < _buffer_denorm_weights[i].size(); j++){ - _buffer_weights[i][j] = pow(_buffer_denorm_weights[i][j], 2)/sum_squared_denorm_weights; + _buffer_weights[i][j] = (_buffer_denorm_weights[i][j]*_buffer_denorm_weights[i][j])/sum_squared_denorm_weights; } } } @@ -490,12 +490,12 @@ dbl McopForceField::Function(const Vdouble & v) dbl& denorm_weight = denorm_weights_loop[copynb]; AttractRigidbody& copy = ref_ensemble[copynb]; - AttractPairList cpl ( lig._core, copy, _cutoff ); + AttractPairList cpl (copy, lig._core, _cutoff ); std::vector copyforce(copy.Size()); std::vector coreforce(lig._core.Size()); // dbl e = _ff.nonbon8( lig._core, _receptor._vregion[loopregion][copy] , cpl ); - dbl e = _ff.nonbon8_forces(lig._core, copy, cpl, coreforce, copyforce); + dbl e = _ff.nonbon8_forces(copy, lig._core, cpl, copyforce, coreforce); _mcop_E[loopregion][copynb] = e; enercopy += e*denorm_weight*denorm_weight; @@ -505,7 +505,7 @@ dbl McopForceField::Function(const Vdouble & v) assert(lig._core.Size() == coreforce.size()); for(uint i=0; i Date: Sun, 3 Jul 2016 18:32:30 +0200 Subject: [PATCH 86/90] Extreme weight discrimination at last minimization --- PyAttract/attract.py | 6 ++++-- bindings/mcopff.pyx | 6 +++--- headers/mcopff.h | 2 +- src/mcopff.cpp | 16 +++++++++++++--- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/PyAttract/attract.py b/PyAttract/attract.py index db83df0..be46d6d 100755 --- a/PyAttract/attract.py +++ b/PyAttract/attract.py @@ -44,7 +44,6 @@ def printWeights(w, e): print "### WEIGHTS END" - class Rotation: class _Rot: @@ -438,7 +437,10 @@ def check_ffversion(reduced): #TODO: test and use CenterToOrigin() ! if options.regions: output=Mcoprigid(ligand) - receptor.updateWeights(X, svptr=6) + if minim == minimlist[len(minimlist)-2] and len(minimlist)>1: + receptor.updateWeights(X, svptr=6, descriminate = 1) + else: + receptor.updateWeights(X, svptr=6, descriminate = 0) else: output=AttractRigidbody(ligand) diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx index 9b5065f..4f37e0b 100644 --- a/bindings/mcopff.pyx +++ b/bindings/mcopff.pyx @@ -36,7 +36,7 @@ cdef extern from "mcopff.h" namespace "PTools": unsigned int size() void setCore(CppAttractRigidbody&) vector[vector[double]] getWeights() - void updateWeights(vector[double], int) + void updateWeights(vector[double], int, int) void denormalize_weights() void normalize_weights() Coord3D FindCenter() @@ -258,8 +258,8 @@ cdef class Mcoprigid: def getWeights(self): return self.thisptr.getWeights() - def updateWeights(self, vector[double] v, int svptr): - self.thisptr.updateWeights(v, svptr) + def updateWeights(self, vector[double] v, int svptr, int descriminate): + self.thisptr.updateWeights(v, svptr, descriminate) def denormalize_weights(self): self.thisptr.denormalize_weights() diff --git a/headers/mcopff.h b/headers/mcopff.h index 777c52c..17c7586 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -119,7 +119,7 @@ class Mcoprigid //multicopy rigidbody void normalize_weights(); void denormalize_buffer_weights(); void normalize_buffer_weights(); - void updateWeights(const std::vector& v, int svptr); + void updateWeights(const std::vector& v, int svptr, int descriminate); void ReadMcoprigidPDB(const std::string name); void ReadMcoprigidPDB(std::istream& file, AttractRigidbody& core, std::vector& regions); diff --git a/src/mcopff.cpp b/src/mcopff.cpp index 409a15f..5d12355 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -199,7 +199,7 @@ void Mcoprigid::normalize_buffer_weights(){ } } -void Mcoprigid::updateWeights(const std::vector& v, int svptr){ +void Mcoprigid::updateWeights(const std::vector& v, int svptr, int descriminate){ //svptr: state variable "pointer" for(uint loopregion=0; loopregion < _vregion.size() ; loopregion++){ for(uint copynb = 0; copynb < _vregion[loopregion].size(); copynb++){ @@ -209,8 +209,18 @@ void Mcoprigid::updateWeights(const std::vector& v, int svptr){ } } normalize_weights(); - //_buffer_denorm_weights = _denorm_weights; - //_buffer_weights = _weights; + if(descriminate == 1){ + for(uint loopregion=0; loopregion < _vregion.size() ; loopregion++){ + for(uint copynb = 0; copynb < _vregion[loopregion].size(); copynb++){ + dbl & w = _weights[loopregion][copynb]; + if(w == *max_element(_weights[loopregion].begin(), _weights[loopregion].end())) + w = 1; + else + w = 0; + } + } + denormalize_weights(); + } } From 8210494536a9bab64f44dc246a672dd436f3122f Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Wed, 20 Jul 2016 10:04:22 +0200 Subject: [PATCH 87/90] Removed minimization approach using denormalized weights. Implemented a more physical approach to multicopy docking. --- PyAttract/attract.py | 11 +- bindings/lbfgs.pyx | 12 +- bindings/mcopff.pyx | 38 +-- headers/attractforcefield.h | 4 +- headers/forcefield.h | 2 +- headers/lbfgs_interface.h | 4 +- headers/mcopff.h | 45 ++-- src/attractforcefield.cpp | 13 +- src/mcopff.cpp | 369 ++++++++++++++++++++--------- src/minimizers/lbfgs_interface.cpp | 85 +++---- 10 files changed, 369 insertions(+), 214 deletions(-) diff --git a/PyAttract/attract.py b/PyAttract/attract.py index be46d6d..f44ee13 100755 --- a/PyAttract/attract.py +++ b/PyAttract/attract.py @@ -426,7 +426,7 @@ def check_ffversion(reduced): if options.regions: lbfgs_minimizer=Lbfgs(mcopff) lbfgs_minimizer.minimize(niter) - lbfgs_minimizer.normalize_weights() + #lbfgs_minimizer.normalize_weights() else : lbfgs_minimizer=ff_specs['minimizer_class'](forcefield) lbfgs_minimizer.minimize(niter) @@ -437,10 +437,11 @@ def check_ffversion(reduced): #TODO: test and use CenterToOrigin() ! if options.regions: output=Mcoprigid(ligand) - if minim == minimlist[len(minimlist)-2] and len(minimlist)>1: - receptor.updateWeights(X, svptr=6, descriminate = 1) - else: - receptor.updateWeights(X, svptr=6, descriminate = 0) + ##weights = mcopff.getWeights() + #if minim == minimlist[len(minimlist)-2] and len(minimlist)>1: + # receptor.updateWeights(X, svptr=6, descriminate = 0) + #else: + # receptor.updateWeights(X, svptr=6, descriminate = 0) else: output=AttractRigidbody(ligand) diff --git a/bindings/lbfgs.pyx b/bindings/lbfgs.pyx index 862ae34..c486f67 100644 --- a/bindings/lbfgs.pyx +++ b/bindings/lbfgs.pyx @@ -8,8 +8,8 @@ cdef extern from "lbfgs_interface.h" namespace "PTools": vector[double] GetMinimizedVars() vector[double] GetMinimizedVarsAtIter(int) int GetNumberIter() - void denormalize_weights() - void normalize_weights() + #void denormalize_weights() + #void normalize_weights() vector[vector[double]] getWeights() cdef class Lbfgs: @@ -45,11 +45,11 @@ cdef class Lbfgs: out.append(vars[i]) return out - def denormalize_weights(self): - self.thisptr.denormalize_weights() + #def denormalize_weights(self): + # self.thisptr.denormalize_weights() - def normalize_weights(self): - self.thisptr.normalize_weights() + #def normalize_weights(self): + # self.thisptr.normalize_weights() def getWeights(self): self.thisptr.getWeights() \ No newline at end of file diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx index 4f37e0b..a772429 100644 --- a/bindings/mcopff.pyx +++ b/bindings/mcopff.pyx @@ -36,9 +36,10 @@ cdef extern from "mcopff.h" namespace "PTools": unsigned int size() void setCore(CppAttractRigidbody&) vector[vector[double]] getWeights() - void updateWeights(vector[double], int, int) - void denormalize_weights() - void normalize_weights() + #void setWeights(vector[vector[double]]&) + #void updateWeights(vector[double], int, int) + #void denormalize_weights() + #void normalize_weights() Coord3D FindCenter() void setTranslation(int) void setRotation(int) @@ -51,8 +52,8 @@ cdef extern from "mcopff.h" namespace "PTools": CppMcopForceField(CppBaseAttractForceField&, double) vector[vector[double]] getWeights() vector[vector[double]] getMcopE() - void denormalize_weights() - void normalize_weights() + #void denormalize_weights() + #void normalize_weights() void setReceptor(CppMcoprigid&) void setLigand(CppMcoprigid&) double CalcEnergy(CppMcoprigid&, CppMcoprigid&, CppBaseAttractForceField&, double) @@ -258,14 +259,17 @@ cdef class Mcoprigid: def getWeights(self): return self.thisptr.getWeights() - def updateWeights(self, vector[double] v, int svptr, int descriminate): - self.thisptr.updateWeights(v, svptr, descriminate) + #def setWeights(self, weights vector[vector[double]]): + # self.thisptr.setWeights(weights) - def denormalize_weights(self): - self.thisptr.denormalize_weights() + #def updateWeights(self, vector[double] v, int svptr, int descriminate): + # self.thisptr.updateWeights(v, svptr, descriminate) - def normalize_weigths(self): - self.thisptr.normalize_weights() + #def denormalize_weights(self): + # self.thisptr.denormalize_weights() + + #def normalize_weigths(self): + # self.thisptr.normalize_weights() def FindCenter(self): #cdef Coord3D c = Coord3D() @@ -327,13 +331,13 @@ cdef class McopForceField(ForceField): cdef CppMcopForceField* cpp_ptr = self.thisptr return cpp_ptr.getMcopE() - def denormalize_weights(self): - cdef CppMcopForceField* cpp_ptr = self.thisptr - cpp_ptr.denormalize_weights() + #def denormalize_weights(self): + # cdef CppMcopForceField* cpp_ptr = self.thisptr + # cpp_ptr.denormalize_weights() - def normalize_weigths(self): - cdef CppMcopForceField* cpp_ptr = self.thisptr - cpp_ptr.normalize_weights() + #def normalize_weigths(self): + # cdef CppMcopForceField* cpp_ptr = self.thisptr + # cpp_ptr.normalize_weights() def setReceptor(self, Mcoprigid rec): cdef CppMcopForceField* cpp_ptr = self.thisptr diff --git a/headers/attractforcefield.h b/headers/attractforcefield.h index 882b5aa..f924c18 100644 --- a/headers/attractforcefield.h +++ b/headers/attractforcefield.h @@ -24,7 +24,7 @@ class BaseAttractForceField: public ForceField ///analytical derivative void Derivatives(const Vdouble&, Vdouble&); uint ProblemSize(); - dbl Function(const Vdouble&); + dbl Function(Vdouble&); ///add a new ligand to the ligand list... void AddLigand(AttractRigidbody & lig); @@ -137,7 +137,7 @@ class TestForceField: public ForceField return 2; }; - virtual dbl Function(const Vdouble& X) + virtual dbl Function(Vdouble& X) { PrintVec(X); return X[0]*X[0] + (X[1]-2)*(X[1]-2) ; diff --git a/headers/forcefield.h b/headers/forcefield.h index f47408a..1d06831 100644 --- a/headers/forcefield.h +++ b/headers/forcefield.h @@ -23,7 +23,7 @@ class ForceField public: ///the function to optimize - virtual dbl Function(const Vdouble&)=0; + virtual dbl Function(Vdouble&)=0; /// analytical derivative of the function above virtual void Derivatives(const Vdouble& StateVars, Vdouble& delta) diff --git a/headers/lbfgs_interface.h b/headers/lbfgs_interface.h index 655e237..d81ef76 100644 --- a/headers/lbfgs_interface.h +++ b/headers/lbfgs_interface.h @@ -27,8 +27,8 @@ class Lbfgs std::vector GetMinimizedVarsAtIter(uint iter); int GetNumberIter() {return m_opt->niter;} - void denormalize_weights(); - void normalize_weights(); + //void denormalize_weights(); + //void normalize_weights(); std::vector< std::vector > getWeights(); diff --git a/headers/mcopff.h b/headers/mcopff.h index 17c7586..49d6c81 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -115,11 +115,12 @@ class Mcoprigid //multicopy rigidbody void PrintWeights(); std::vector > getWeights(){return _weights;}; - void denormalize_weights(); - void normalize_weights(); - void denormalize_buffer_weights(); - void normalize_buffer_weights(); - void updateWeights(const std::vector& v, int svptr, int descriminate); + //void setWeights(vector[vector[double]]& w){_weights = w;}; + //void denormalize_weights(); + //void normalize_weights(); + //void denormalize_buffer_weights(); + //void normalize_buffer_weights(); + //void updateWeights(const std::vector& v, int svptr, int descriminate); void ReadMcoprigidPDB(const std::string name); void ReadMcoprigidPDB(std::istream& file, AttractRigidbody& core, std::vector& regions); @@ -145,9 +146,9 @@ class Mcoprigid //multicopy rigidbody Coord3D _center ; ///
> _weights; - std::vector< std::vector > _denorm_weights; - std::vector< std::vector > _buffer_weights; - std::vector< std::vector > _buffer_denorm_weights; + //std::vector< std::vector > _denorm_weights; + //std::vector< std::vector > _buffer_weights; + //std::vector< std::vector > _buffer_denorm_weights; friend class McopForceField; @@ -170,25 +171,27 @@ class McopForceField: public ForceField :_ff(ff), _cutoff(cutoff) {}; void ini_energies(); - dbl Function(const Vdouble&); - dbl CalcEnergy(Mcoprigid & receptor,Mcoprigid & ligand, BaseAttractForceField & ff, dbl cutoff); + dbl Function(Vdouble&); + dbl CalcEnergy(Mcoprigid & receptor,Mcoprigid & lig, BaseAttractForceField & ff, dbl cutoff); void Derivatives(const Vdouble& v, Vdouble & g ); void setReceptor(Mcoprigid& rec); void setLigand(Mcoprigid& lig); - void calculate_weights(Mcoprigid& lig, bool print=false); + //void calculate_weights(Mcoprigid& lig, bool print=false); uint ProblemSize(); void initMinimization(){}; std::vector > getWeights(){return _receptor.getWeights();}; - std::vector > getMcopE(){return _mcop_E;}; - void denormalize_weights(){_receptor.denormalize_weights();}; - void normalize_weights(){_receptor.normalize_weights();}; - void denormalize_buffer_weights(){_receptor.denormalize_buffer_weights();}; - void normalize_buffer_weights(){_receptor.normalize_buffer_weights();}; + std::vector > getMcopE(){return _Eik;}; + //void denormalize_weights(){_receptor.denormalize_weights();}; + //void normalize_weights(){_receptor.normalize_weights();}; + //void denormalize_buffer_weights(){_receptor.denormalize_buffer_weights();}; + //void normalize_buffer_weights(){_receptor.normalize_buffer_weights();}; + + private: @@ -200,7 +203,15 @@ class McopForceField: public ForceField Mcoprigid _centered_ligand ; Mcoprigid _moved_ligand ; Mcoprigid _receptor; - std::vector< std::vector > _mcop_E; //Energies + std::vector< std::vector > _Eik; //Loop interaction energies + std::vector< std::vector< std::vector > > _dEik; + dbl _E; //Total interaction energy + std::vector _Eregion; + std::vector _Z; // one Z per loop region + std::vector _Zprime; + std::vector< std::vector > _dz; + std::vector< std::vector > _dzprime; + dbl _beta; diff --git a/src/attractforcefield.cpp b/src/attractforcefield.cpp index bfe284b..f6b5c02 100644 --- a/src/attractforcefield.cpp +++ b/src/attractforcefield.cpp @@ -329,7 +329,7 @@ void AttractForceField2::loadParams(const std::string & filename, dbl cutoff) } -dbl BaseAttractForceField::Function(const Vdouble& stateVars ) +dbl BaseAttractForceField::Function(Vdouble& stateVars ) { assert(m_centeredligand.size() >=1); @@ -398,7 +398,7 @@ dbl BaseAttractForceField::Function(const Vdouble& stateVars ) - + ///std::cout << "Energie totale " << enernon << std::endl; return enernon; @@ -605,6 +605,10 @@ void BaseAttractForceField::Trans(uint molIndex, Vdouble & delta, uint shift, b delta[1+shift]=ftr2; delta[2+shift]=ftr3; + ///std::cout << "Dériv trans " << 1 << " " << delta[0+shift] << std::endl; + ///std::cout << "Dériv trans " << 2 << " " << delta[1+shift] << std::endl; + ///std::cout << "Dériv trans " << 3 << " " << delta[2+shift] << std::endl; + //debug: if (print) std::cout << "translational forces: " << ftr1 <<" "<< ftr2 <<" " << ftr3 << std::endl; return ; @@ -716,6 +720,11 @@ void BaseAttractForceField::Rota(uint molIndex, dbl phi,dbl ssi, dbl rot, Vdoubl } } + ///std::cout << "Dériv rot " << 1 << " " << delta[0+shift] << std::endl; + ///std::cout << "Dériv rot " << 2 << " " << delta[1+shift] << std::endl; + ///std::cout << "Dériv rot " << 3 << " " << delta[2+shift] << std::endl; + + if (print) std::cout << "Rotational forces: " << delta[shift] << " " << delta[shift+1] << " " << delta[shift+2] << std::endl; diff --git a/src/mcopff.cpp b/src/mcopff.cpp index 5d12355..ecfe069 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace PTools { @@ -26,15 +27,15 @@ void Mcoprigid::iniWeights(){ for(uint i=0; i < _vregion.size(); i++){ std::vector newvector; _weights.push_back(newvector); - _denorm_weights.push_back(newvector); + //_denorm_weights.push_back(newvector); for(uint j=0; j < _vregion[i].size(); j++){ dbl weight = 1.0/(double)_vregion[i].size(); _weights[i].push_back(weight); - _denorm_weights[i].push_back(1); + //_denorm_weights[i].push_back(1); } } - _buffer_denorm_weights = _denorm_weights; - _buffer_weights = _weights; + //_buffer_denorm_weights = _denorm_weights; + //_buffer_weights = _weights; } void Mcoprigid::setCore(AttractRigidbody& core) { @@ -155,7 +156,7 @@ uint Mcoprigid::line_to_copy_number(std::string line){ return std::atoi(line.substr(15,line.size()-15).c_str()); } -void Mcoprigid::denormalize_weights(){ +/*void Mcoprigid::denormalize_weights(){ for(uint i=0; i < _weights.size(); i++){ dbl max_weight = *max_element(_weights[i].begin(), _weights[i].end()); for(uint j=0; j < _weights[i].size(); j++){ @@ -223,6 +224,8 @@ void Mcoprigid::updateWeights(const std::vector& v, int svptr, int descrimi } } +*/ + /////////////////// -- Class Mcop -- //////////////////// @@ -343,16 +346,27 @@ void McopForceField::setLigand( Mcoprigid& lig){ void McopForceField::ini_energies(){ for(uint i=0; i < _receptor.getRegions().size(); i++){ std::vector newvector; - _mcop_E.push_back(newvector); - for(uint j=0; j < _receptor.getRegions()[i].size(); j++){ - _mcop_E[i].push_back(0); + std::vector< std::vector > newcoordsvecvec; + std::vector threezeros(3, 0.0); + _Eik.push_back(newvector); + _Z.push_back(0); + _Zprime.push_back(0); + _Eregion.push_back(0); + //_dz.push_back(threezeros); + //_dzprime.push_back(threezeros); + _dEik.push_back(newcoordsvecvec); + for(uint k=0; k < _receptor.getRegions()[i].size(); k++){ + //Coord3D coords; + _Eik[i].push_back(0); + std::vector newcoordsvec; + _dEik[i].push_back(newcoordsvec); } } } -void McopForceField::calculate_weights(Mcoprigid& lig, bool print) +/*void McopForceField::calculate_weights(Mcoprigid& lig, bool print) { @@ -389,7 +403,6 @@ void McopForceField::calculate_weights(Mcoprigid& lig, bool print) sumweights += e ; } - //normalize weights for (uint i=0; i< weights.size(); i++) { @@ -407,7 +420,7 @@ void McopForceField::calculate_weights(Mcoprigid& lig, bool print) } - +*/ uint McopForceField::ProblemSize() { @@ -415,9 +428,9 @@ uint McopForceField::ProblemSize() uint size = 0; if (_centered_ligand.getCore().hastranslation) size += 3; if (_centered_ligand.getCore().hasrotation) size += 3; - for(uint i=0; i<_receptor.getWeights().size(); i++){ + /*for(uint i=0; i<_receptor.getWeights().size(); i++){ size += _receptor.getWeights()[i].size(); - } + }*/ return size; } @@ -428,7 +441,7 @@ uint McopForceField::ProblemSize() * this functions returns nonbonded energy of a receptor with multicopy and a ligand without copy. * */ -dbl McopForceField::Function(const Vdouble & v) +dbl McopForceField::Function(Vdouble & v) { dbl ener_region = 0.0 ; @@ -448,7 +461,7 @@ dbl McopForceField::Function(const Vdouble & v) assert(_receptor._vregion.size() == _receptor._weights.size()); //Update the denormalized weights - + /* uint svptr = 0; // stateVars 'pointer' if (lig.getCore().hasrotation) svptr += 3; if (lig.getCore().hastranslation) svptr += 3; @@ -468,6 +481,8 @@ dbl McopForceField::Function(const Vdouble & v) normalize_buffer_weights(); denormalize_buffer_weights(); std::vector< std::vector >& weights = _receptor._buffer_weights; + */ + //2) calculates the energy @@ -477,7 +492,18 @@ dbl McopForceField::Function(const Vdouble & v) //2.2) core lignd with receptor copies: - + std::vector< std::vector >& weights = _receptor._weights; + std::vector< std::vector >& Eik = _Eik; + std::vector< std::vector< std::vector > >& dEik = _dEik; + std::vector& Z = _Z; + std::vector& Zprime = _Zprime; + dbl& E = _E; + std::vector& Eregion = _Eregion; + ///dbl& beta = _beta; + dbl& beta = v[6]; + //beta = 1.6948; + + for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++) { @@ -485,97 +511,198 @@ dbl McopForceField::Function(const Vdouble & v) // std::vector Eik; dbl enercopy =0.0; + dbl& Z_i = Z[loopregion]; + dbl& Zprime_i = Zprime[loopregion]; + + Z_i = 0.0; + Zprime_i = 0.0; + bool clash = true; + double beta_temp = beta; + AttractMcop& ref_ensemble = _receptor._vregion[loopregion]; - std::vector& denorm_weights_loop = denorm_weights[loopregion]; std::vector& weights_loop = weights[loopregion]; - - assert( ref_ensemble.size() == denorm_weights_loop.size()); + assert( ref_ensemble.size() == weights_loop.size()); - dbl max_weight = *max_element(weights_loop.begin(), weights_loop.end()); - + double Emin = DBL_MAX; for (uint copynb = 0; copynb < ref_ensemble.size(); copynb++) { - dbl& denorm_weight = denorm_weights_loop[copynb]; + AttractRigidbody& copy = ref_ensemble[copynb]; AttractPairList cpl (copy, lig._core, _cutoff ); std::vector copyforce(copy.Size()); std::vector coreforce(lig._core.Size()); -// dbl e = _ff.nonbon8( lig._core, _receptor._vregion[loopregion][copy] , cpl ); - dbl e = _ff.nonbon8_forces(copy, lig._core, cpl, copyforce, coreforce); - _mcop_E[loopregion][copynb] = e; + enercopy = _ff.nonbon8_forces(copy, lig._core, cpl, copyforce, coreforce); + Eik[loopregion][copynb] = enercopy; + if(enercopy < Emin) Emin = enercopy; + + ///std::cout << "Eik" << copynb << " " << enercopy << std::endl; - enercopy += e*denorm_weight*denorm_weight; - //printf("weight/energy for reg %d copy %d = %f/%f\n", loopregion, copynb, weights_loop[copynb], enercopy); + /*if(beta*enercopy > 700){ + if(700/enercopy < beta_temp){ + beta_temp = 700/enercopy; + } + } + else{ + clash = false; + }*/ + + ///Z_i += exp(-beta*enercopy); + ///Zprime_i += -enercopy*exp(-beta*enercopy); + + //add force to ligand assert(lig._core.Size() == coreforce.size()); - for(uint i=0; i >& weights = receptor._weights; + std::vector< std::vector >& Eik = _Eik; + std::vector& Z = _Z; + std::vector& Zprime = _Zprime; + dbl& E = _E; + dbl beta = 1; + + + for (uint loopregion=0; loopregion < receptor._vregion.size() ; loopregion++) + { + + //calculates interaction energy between receptor copies and ligand body: +// std::vector Eik; - //calculates interaction energy between receptor copies and ligand body: - for(uint loopregion=0; loopregion < receptor.getRegions().size(); loopregion++){ - dbl enercopy =0.0; + dbl& Z_i = Z[loopregion]; + dbl& Zprime_i = Zprime[loopregion]; + + Z_i = 0.0; + Zprime_i = 0.0; + + + AttractMcop& ref_ensemble = receptor._vregion[loopregion]; + std::vector& weights_loop = weights[loopregion]; - for(uint copynb=0; copynb < receptor.getRegion(loopregion).size(); copynb++){ - - dbl weight = receptor.getWeights()[loopregion][copynb]; - AttractRigidbody& copy = receptor.getRegion(loopregion).getCopy(copynb); - AttractPairList cpl (ligand._core, copy, cutoff); + assert( ref_ensemble.size() == weights_loop.size()); + + + for (uint copynb = 0; copynb < ref_ensemble.size(); copynb++) + { + AttractRigidbody& copy = ref_ensemble[copynb]; + + AttractPairList cpl (copy, lig._core, cutoff ); std::vector copyforce(copy.Size()); - std::vector coreforce(ligand._core.Size()); - - dbl e = ff.nonbon8_forces(ligand._core, copy, cpl, coreforce, copyforce); - enercopy += e*weight; - _mcop_E[loopregion][copynb] = e; + std::vector coreforce(lig._core.Size()); + + enercopy = ff.nonbon8_forces(copy, lig._core, cpl, copyforce, coreforce); + Eik[loopregion][copynb] = enercopy; + + Z_i += exp(-beta*enercopy); + Zprime_i += -enercopy*exp(-beta*enercopy); + } - - ener_region += enercopy; + for (uint copynb = 0; copynb < ref_ensemble.size(); copynb++) + { + dbl& weight = weights_loop[copynb]; + weight = exp(-beta*Eik[loopregion][copynb])/Z_i; + } + ener_region += -Zprime_i/Z_i; } - return ener_core + ener_region; + E = ener_core + ener_region; + return E; } + void McopForceField::Derivatives(const Vdouble& v, Vdouble & g ) { Mcoprigid & lig = _moved_ligand; uint svptr = 0; // stateVars 'pointer' +//std::vector& Z = _Z; +//std::vector& Zprime = _Zprime; +//std::vector< std::vector >& dz = _dz; +//std::vector< std::vector >& dzprime = _dzprime; +std::vector< std::vector< std::vector > >& dEik = _dEik; +std::vector< std::vector >& Eik = _Eik; +dbl E = _E; +std::vector& Eregion = _Eregion; +std::vector< std::vector > & weights = _receptor._weights; +//dbl beta = _beta; +dbl beta = v[6]; + +std::vector< std::vector > coef; +std::vector newvector; +// iterate through loop regions +for(uint i=0; i < dEik.size(); i++){ + coef.push_back(newvector); + // iterate through loop copies + for(uint k=0; k < dEik[i].size(); k++){ + coef[i].push_back((1+beta*(Eregion[i] - Eik[i][k]))*weights[i][k]); + } +} // calculate de rotational forces: if (lig.getCore().hasrotation){ //printf("hasrotation\n"); - dbl cs,cp,ss,sp,cscp,sscp,sssp,crot,srot,xar,yar,cssp,X,Y,Z ; + dbl cs,cp,ss,sp,cscp,sscp,sssp,crot,srot,xar,yar,cssp,x,y,z; dbl pm[3][3]; // !c calculates orientational force contributions @@ -583,9 +710,9 @@ if (lig.getCore().hasrotation){ // !c component 2: ssi-angle // !c component 3: rot-angle - g[svptr+0] = 0; - g[svptr+1] = 0; - g[svptr+2] = 0; + g[svptr+0] = 0.0; + g[svptr+1] = 0.0; + g[svptr+2] = 0.0; for (uint i=0; i<3;i++) { @@ -622,6 +749,10 @@ if (lig.getCore().hasrotation){ AttractRigidbody * pLigCentered = & _centered_ligand._core; // pointer to the centered ligand AttractRigidbody * pLigMoved = & _moved_ligand._core; // pointer to the rotated/translated ligand (for forces) + //initializing derivative variables + std::vector dEcore(3, 0.0); + std::vector dEloops(3, 0.0); + //printf("pLigCentered->m_activeAtoms.size() = %d\n", pLigCentered->m_activeAtoms.size()); //for (uint i=0; i< pLigCentered->m_activeAtoms.size(); i++) for(uint atomIndex=0; atomIndex<_moved_ligand._core.Size(); atomIndex++){ @@ -630,22 +761,22 @@ if (lig.getCore().hasrotation){ Coord3D coords = pLigCentered->GetCoords(atomIndex); - X = coords.x; - Y = coords.y; - Z = coords.z; + x = coords.x; + y = coords.y; + z = coords.z; //std::cout << "X " << X << std::endl; - xar=X*crot+Y*srot; - yar=-X*srot+Y*crot; + xar=x*crot+y*srot; + yar=-x*srot+y*crot; - pm[0][0]=-xar*cssp-yar*cp-Z*sssp ; - pm[1][0]=xar*cscp-yar*sp+Z*sscp ; + pm[0][0]=-xar*cssp-yar*cp-z*sssp ; + pm[1][0]=xar*cscp-yar*sp+z*sscp ; pm[2][0]=0.0 ; - pm[0][1]=-xar*sscp+Z*cscp ; - pm[1][1]=-xar*sssp+Z*cssp ; - pm[2][1]=-xar*cs-Z*ss ; + pm[0][1]=-xar*sscp+z*cscp ; + pm[1][1]=-xar*sssp+z*cssp ; + pm[2][1]=-xar*cs-z*ss ; pm[0][2]=yar*cscp+xar*sp ; pm[1][2]=yar*cssp-xar*cp ; @@ -663,16 +794,33 @@ if (lig.getCore().hasrotation){ //std::cout << "pm[1][2] " << pm[1][2] << std::endl; //std::cout << "pm[2][2] " << pm[2][2] << std::endl; + //adding the derivatives for the core: for(uint j=0; j < 3; j++){ - g[svptr + j] += pm[0][j] * pLigMoved->m_forces[atomIndex].x; - g[svptr + j] += pm[1][j] * pLigMoved->m_forces[atomIndex].y; - g[svptr + j] += pm[2][j] * pLigMoved->m_forces[atomIndex].z; + dEcore[j] += pm[0][j] * pLigMoved->m_forces[atomIndex].x; + dEcore[j] += pm[1][j] * pLigMoved->m_forces[atomIndex].y; + dEcore[j] += pm[2][j] * pLigMoved->m_forces[atomIndex].z; + } + + // iterate through loop regions + for(uint i=0; i < dEik.size(); i++){ + // iterate through loop copies + for(uint k=0; k < dEik[i].size(); k++){ + // iterate through the three rotation angles + for(uint j=0; j < 3; j++){ + dEloops[j] += coef[i][k] * pm[0][j] * dEik[i][k][atomIndex].x; + dEloops[j] += coef[i][k] * pm[1][j] * dEik[i][k][atomIndex].y; + dEloops[j] += coef[i][k] * pm[2][j] * dEik[i][k][atomIndex].z; + } + } } - //printf("vector v[%d, %d, %d] = %f, %f, %f\n",svptr+0, svptr+1, svptr+2, v[svptr+0], v[svptr+1], v[svptr+2]); - //printf("vector g[%d, %d, %d] = %f, %f, %f\n",svptr+0, svptr+1, svptr+2, g[svptr+0], g[svptr+1], g[svptr+2]); } + for(uint j=0; j < 3; j++){ + g[svptr+j] += dEcore[j] + dEloops[j]; + ///std::cout << "Dériv rot " << j << " " << g[svptr+j] << std::endl; + } + svptr += 3; @@ -681,9 +829,9 @@ if (lig.getCore().hasrotation){ //sum the forces over x, y and z: calculate de translational forces if (lig.getCore().hastranslation){ - g[svptr+0] = 0; - g[svptr+1] = 0; - g[svptr+2] = 0; + g[svptr+0] = 0.0; + g[svptr+1] = 0.0; + g[svptr+2] = 0.0; dbl flim = 1.0e18; dbl ftr1, ftr2, ftr3, fbetr; @@ -693,16 +841,33 @@ if (lig.getCore().hastranslation){ Coord3D ligtransForces; //translational forces for the ligand from loopregion - for(uint i=0; i<_moved_ligand._core.Size(); i++){ - ligtransForces += _moved_ligand._core.m_forces[i]; + //initializing derivative variables + std::vector dEcore(3, 0.0); + std::vector dEloops(3, 0.0); + + //adding derivatives + for(uint atomIndex=0; atomIndex<_moved_ligand._core.Size(); atomIndex++){ + ligtransForces += _moved_ligand._core.m_forces[atomIndex]; + for(uint i=0; i < dEik.size(); i++){ + for(uint k=0; k < dEik[i].size(); k++){ + dEloops[0] += coef[i][k] * dEik[i][k][atomIndex].x; + dEloops[1] += coef[i][k] * dEik[i][k][atomIndex].y; + dEloops[2] += coef[i][k] * dEik[i][k][atomIndex].z; + } + } } - ftr1 = ligtransForces.x; - ftr2 = ligtransForces.y; - ftr3 = ligtransForces.z; - //printf("vector v[%d, %d, %d] = %f, %f, %f\n",svptr+0, svptr+1, svptr+2, v[svptr+0], v[svptr+1], v[svptr+2]); - //printf("vector g[%d, %d, %d] = %f, %f, %f\n",svptr+0, svptr+1, svptr+2, g[svptr+0], g[svptr+1], g[svptr+2]); + dEcore[0] = ligtransForces.x; + dEcore[1] = ligtransForces.y; + dEcore[2] = ligtransForces.z; + + ftr1 = dEcore[0] + dEloops[0]; + ftr2 = dEcore[1] + dEloops[1]; + ftr3 = dEcore[2] + dEloops[2]; + //ftr1 =g[svptr+0]; + //ftr2 =g[svptr+1]; + //ftr3 =g[svptr+2]; // force reduction, some times helps in case of very "bad" start structure for (uint i=0; i<3; i++) @@ -721,7 +886,9 @@ if (lig.getCore().hastranslation){ g[svptr+0] = ftr1; g[svptr+1] = ftr2; g[svptr+2] = ftr3; - + //std::cout << "Dériv trans " << 1 << " " << ftr1 << std::endl; + //std::cout << "Dériv trans " << 2 << " " << ftr2 << std::endl; + //std::cout << "Dériv trans " << 3 << " " << ftr3 << std::endl; svptr += 3; } @@ -729,50 +896,26 @@ if (lig.getCore().hastranslation){ // Calculate de weight derivative -assert(_receptor._vregion.size() == _mcop_E.size()); +/*assert(_receptor._vregion.size() == _Eik.size()); uint k = 0; for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++){ std::vector& ref_weights = _receptor._buffer_weights[loopregion]; std::vector& ref_denorm_weights = _receptor._buffer_denorm_weights[loopregion]; - std::vector& ref_mcop_E = _mcop_E[loopregion]; - assert(ref_weights.size() == ref_mcop_E.size()); + std::vector& ref_Eik = _Eik[loopregion]; + assert(ref_weights.size() == ref_Eik.size()); dbl max_weight = *max_element(ref_weights.begin(), ref_weights.end()); - for(uint copynb=0; copynb < _mcop_E[loopregion].size(); copynb++){ + for(uint copynb=0; copynb < _Eik[loopregion].size(); copynb++){ // weight derivative function - g[svptr + k] = 2*max_weight*ref_denorm_weights[copynb]*ref_mcop_E[copynb]; + g[svptr + k] = 2*max_weight*ref_denorm_weights[copynb]*ref_Eik[copynb]; //printf("vector v[%d] = %f\n",svptr+k, v[svptr+k]); //printf("vector g[%d] = %f\n",svptr+k, g[svptr+k]); k++; } -} - -/*Coord3D receptortransForces; //translational forces for the receptor: -for(uint i=0; i<_receptor._core.Size(); i++) -{ - receptortransForces+= _receptor._core.m_forces[i]; -} - -for (uint i=0; i <_receptor._vregion.size(); i++) -{ - AttractMcop& ens = _receptor._vregion[i]; - std::vector & weights = _receptor._weights[i]; - - for(uint j=0; jmax_iter = maxiter; int last_iter = 0; + int sub_iter = 0; + + double grad = 0; + //double new_beta = 1; + //x.push_back(new_beta); + //double & beta = x[x.size()-1]; /* opt->iprint = 0;*/ while (1) { @@ -116,53 +122,22 @@ void Lbfgs::minimize(int maxiter) break; } else if (rc == 1) { - //for(int i=0; initer) { //this is a new iteration last_iter = m_opt->niter; + sub_iter = 0; //saves the minimizer variables for each iteration (can be useful for generating animations) m_vars_over_time.push_back(x); + ///std::cout << "########################## NEW ITERATION " << m_opt->niter << std::endl; } - + + double sum = 0; + for(int i=0; i < g.size(); i++){ + sum += g[i]*g[i]; + } + std::vector vdblx; tocplx(x,vdblx); @@ -172,17 +147,28 @@ void Lbfgs::minimize(int maxiter) //std::cout << "f = " << f << std::endl; objToMinimize.Derivatives(vdblx,vdblg); g=todbl(vdblg); - //for(int i=0; i -0.0001 && grad - sqrt(sum) < 0.0001){ + //if(sub_iter > 20){ + //f += 10; + //std::cout << "STUCK " << grad - sqrt(sum) << std::endl; + //std::cout << "GRAD " << grad << std::endl; + //beta = 10; + //f += 10; + //grad = 0; + //sub_iter = 15; + } + else{ + //grad = sqrt(sum); + beta = 1; + }*/ + sub_iter ++; } else { assert(!"can not reach here"); @@ -213,7 +199,7 @@ if (iter>=m_vars_over_time.size()) return m_vars_over_time[iter]; } -void Lbfgs::denormalize_weights() +/*void Lbfgs::denormalize_weights() { if (McopForceField * p = dynamic_cast(&objToMinimize)){ // objToMinimize is or is of type McopForceField @@ -237,6 +223,7 @@ void Lbfgs::normalize_weights() //else // objToMinimize is not a McopForceField } +*/ std::vector< std::vector > Lbfgs::getWeights(){ if (McopForceField * p = dynamic_cast(&objToMinimize)){ From 69af583162cfc6d950ac8afaaf583e87f68630ba Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Wed, 20 Jul 2016 10:56:23 +0200 Subject: [PATCH 88/90] Made arguments in Function() const again. (const was removed for a test) --- headers/attractforcefield.h | 4 ++-- headers/forcefield.h | 2 +- headers/mcopff.h | 2 +- src/attractforcefield.cpp | 2 +- src/mcopff.cpp | 9 +++------ 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/headers/attractforcefield.h b/headers/attractforcefield.h index f924c18..882b5aa 100644 --- a/headers/attractforcefield.h +++ b/headers/attractforcefield.h @@ -24,7 +24,7 @@ class BaseAttractForceField: public ForceField ///analytical derivative void Derivatives(const Vdouble&, Vdouble&); uint ProblemSize(); - dbl Function(Vdouble&); + dbl Function(const Vdouble&); ///add a new ligand to the ligand list... void AddLigand(AttractRigidbody & lig); @@ -137,7 +137,7 @@ class TestForceField: public ForceField return 2; }; - virtual dbl Function(Vdouble& X) + virtual dbl Function(const Vdouble& X) { PrintVec(X); return X[0]*X[0] + (X[1]-2)*(X[1]-2) ; diff --git a/headers/forcefield.h b/headers/forcefield.h index 1d06831..f47408a 100644 --- a/headers/forcefield.h +++ b/headers/forcefield.h @@ -23,7 +23,7 @@ class ForceField public: ///the function to optimize - virtual dbl Function(Vdouble&)=0; + virtual dbl Function(const Vdouble&)=0; /// analytical derivative of the function above virtual void Derivatives(const Vdouble& StateVars, Vdouble& delta) diff --git a/headers/mcopff.h b/headers/mcopff.h index 49d6c81..45fb76f 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -171,7 +171,7 @@ class McopForceField: public ForceField :_ff(ff), _cutoff(cutoff) {}; void ini_energies(); - dbl Function(Vdouble&); + dbl Function(const Vdouble&); dbl CalcEnergy(Mcoprigid & receptor,Mcoprigid & lig, BaseAttractForceField & ff, dbl cutoff); void Derivatives(const Vdouble& v, Vdouble & g ); diff --git a/src/attractforcefield.cpp b/src/attractforcefield.cpp index f6b5c02..085b047 100644 --- a/src/attractforcefield.cpp +++ b/src/attractforcefield.cpp @@ -329,7 +329,7 @@ void AttractForceField2::loadParams(const std::string & filename, dbl cutoff) } -dbl BaseAttractForceField::Function(Vdouble& stateVars ) +dbl BaseAttractForceField::Function(const Vdouble& stateVars ) { assert(m_centeredligand.size() >=1); diff --git a/src/mcopff.cpp b/src/mcopff.cpp index ecfe069..683801c 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -441,7 +441,7 @@ uint McopForceField::ProblemSize() * this functions returns nonbonded energy of a receptor with multicopy and a ligand without copy. * */ -dbl McopForceField::Function(Vdouble & v) +dbl McopForceField::Function(const Vdouble & v) { dbl ener_region = 0.0 ; @@ -499,9 +499,8 @@ dbl McopForceField::Function(Vdouble & v) std::vector& Zprime = _Zprime; dbl& E = _E; std::vector& Eregion = _Eregion; - ///dbl& beta = _beta; - dbl& beta = v[6]; - //beta = 1.6948; + dbl& beta = _beta; + beta = 1.6948; for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++) @@ -516,8 +515,6 @@ dbl McopForceField::Function(Vdouble & v) Z_i = 0.0; Zprime_i = 0.0; - bool clash = true; - double beta_temp = beta; AttractMcop& ref_ensemble = _receptor._vregion[loopregion]; std::vector& weights_loop = weights[loopregion]; From 19d2bb52064781dc948b200f3b2b80378a0743c6 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Thu, 21 Jul 2016 16:45:57 +0200 Subject: [PATCH 89/90] Modified weight variation output --- PyAttract/attract.py | 13 ++++++++++--- bindings/mcopff.pyx | 5 +++++ headers/forcefield.h | 4 ++++ headers/mcopff.h | 5 ++++- src/mcopff.cpp | 10 ++++------ src/minimizers/lbfgs_interface.cpp | 1 + 6 files changed, 28 insertions(+), 10 deletions(-) diff --git a/PyAttract/attract.py b/PyAttract/attract.py index f44ee13..1fd75b3 100755 --- a/PyAttract/attract.py +++ b/PyAttract/attract.py @@ -464,10 +464,17 @@ def check_ffversion(reduced): ftraj.write("\n") ftraj.write("~~~~~~~~~~~~~~\n") if (options.regions): + savedWeights = mcopff.getSavedWeights() + for i, region in enumerate(savedWeights[0]): + weight_variation.write("Region %i\t"%(i+1)) + for k, copy in enumerate(region): + weight_variation.write("Copy %i\t"%(k+1)) + weight_variation.write("\n\n") for iteration in range(ntraj): - traj = lbfgs_minimizer.GetMinimizedVarsAtIter(iteration) - for t in traj[6:]: - weight_variation.write("%f "%t) + for region in savedWeights[iteration]: + weight_variation.write("\t\t") + for copy in region: + weight_variation.write("%f\t"%t) weight_variation.write("\n") weight_variation.write("~~~~~~~~~~~~~~\n") diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx index a772429..1cd3eec 100644 --- a/bindings/mcopff.pyx +++ b/bindings/mcopff.pyx @@ -57,6 +57,7 @@ cdef extern from "mcopff.h" namespace "PTools": void setReceptor(CppMcoprigid&) void setLigand(CppMcoprigid&) double CalcEnergy(CppMcoprigid&, CppMcoprigid&, CppBaseAttractForceField&, double) + vector[vector[vector[double]]] getSavedWeights() cdef class Mcop: cdef CppMcop* thisptr @@ -355,6 +356,10 @@ cdef class McopForceField(ForceField): cppff = ff.thisptr return cpp_ptr.CalcEnergy(deref(rec.thisptr), deref(lig.thisptr), deref(cppff), cutoff) + def getSavedWeights(self): + + cdef CppMcopForceField* cpp_ptr = self.thisptr + return cpp_ptr.getSavedWeights() \ No newline at end of file diff --git a/headers/forcefield.h b/headers/forcefield.h index f47408a..b37d1b2 100644 --- a/headers/forcefield.h +++ b/headers/forcefield.h @@ -42,6 +42,10 @@ class ForceField ///virtual destructor (Effective C++ - Scott Meyers - Item 7) virtual ~ForceField(){}; + + /// Saves weights into attribute. Used at each minimization iteration in order to follow + /// the weights' evolution during the docking. Used only for McopForcefield. + virtual void saveWeights(){}; } ; diff --git a/headers/mcopff.h b/headers/mcopff.h index 45fb76f..0b9bdc3 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -168,7 +168,7 @@ class McopForceField: public ForceField public: McopForceField(BaseAttractForceField& ff, dbl cutoff) - :_ff(ff), _cutoff(cutoff) {}; + :_ff(ff), _cutoff(cutoff) { _beta = 1; }; void ini_energies(); dbl Function(const Vdouble&); @@ -183,6 +183,8 @@ class McopForceField: public ForceField uint ProblemSize(); void initMinimization(){}; + virtual void saveWeights(){_savedWeights.push_back(_receptor.getWeights());}; + std::vector< std::vector< std::vector > > getSavedWeights(){ return _savedWeights;} std::vector > getWeights(){return _receptor.getWeights();}; std::vector > getMcopE(){return _Eik;}; @@ -212,6 +214,7 @@ class McopForceField: public ForceField std::vector< std::vector > _dz; std::vector< std::vector > _dzprime; dbl _beta; + std::vector< std::vector< std::vector > > _savedWeights; diff --git a/src/mcopff.cpp b/src/mcopff.cpp index 683801c..b60c200 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -443,7 +443,6 @@ uint McopForceField::ProblemSize() */ dbl McopForceField::Function(const Vdouble & v) { - dbl ener_region = 0.0 ; dbl ener_core = 0.0 ; @@ -500,15 +499,14 @@ dbl McopForceField::Function(const Vdouble & v) dbl& E = _E; std::vector& Eregion = _Eregion; dbl& beta = _beta; - beta = 1.6948; + //std::cout << "BETA " << beta << std::endl; for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++) { //calculates interaction energy between receptor copies and ligand body: // std::vector Eik; - dbl enercopy =0.0; dbl& Z_i = Z[loopregion]; dbl& Zprime_i = Zprime[loopregion]; @@ -618,7 +616,6 @@ dbl McopForceField::CalcEnergy(Mcoprigid & receptor, Mcoprigid & lig, BaseAttrac dbl& E = _E; dbl beta = 1; - for (uint loopregion=0; loopregion < receptor._vregion.size() ; loopregion++) { @@ -659,6 +656,8 @@ dbl McopForceField::CalcEnergy(Mcoprigid & receptor, Mcoprigid & lig, BaseAttrac { dbl& weight = weights_loop[copynb]; weight = exp(-beta*Eik[loopregion][copynb])/Z_i; + ///if(copynb == 0) weight = 1; + ///else weight = 0; } ener_region += -Zprime_i/Z_i; } @@ -682,8 +681,7 @@ std::vector< std::vector >& Eik = _Eik; dbl E = _E; std::vector& Eregion = _Eregion; std::vector< std::vector > & weights = _receptor._weights; -//dbl beta = _beta; -dbl beta = v[6]; +dbl& beta = _beta; std::vector< std::vector > coef; std::vector newvector; diff --git a/src/minimizers/lbfgs_interface.cpp b/src/minimizers/lbfgs_interface.cpp index 015c756..cca9d78 100644 --- a/src/minimizers/lbfgs_interface.cpp +++ b/src/minimizers/lbfgs_interface.cpp @@ -129,6 +129,7 @@ void Lbfgs::minimize(int maxiter) sub_iter = 0; //saves the minimizer variables for each iteration (can be useful for generating animations) m_vars_over_time.push_back(x); + objToMinimize.saveWeights(); //Only saves weights if objToMinimize is McopForceField. ///std::cout << "########################## NEW ITERATION " << m_opt->niter << std::endl; } From b504c21a627cd4432a33555961b346d84ed17127 Mon Sep 17 00:00:00 2001 From: Gilles Lamothe Date: Tue, 26 Jul 2016 15:17:57 +0200 Subject: [PATCH 90/90] change beta and remove comments --- PyAttract/attract.py | 15 +- bindings/mcopff.pyx | 32 ---- headers/mcopff.h | 56 +----- src/attractforcefield.cpp | 37 ---- src/mcopff.cpp | 262 +---------------------------- src/minimizers/lbfgs_interface.cpp | 57 +------ 6 files changed, 18 insertions(+), 441 deletions(-) diff --git a/PyAttract/attract.py b/PyAttract/attract.py index 1fd75b3..237e5e2 100755 --- a/PyAttract/attract.py +++ b/PyAttract/attract.py @@ -208,8 +208,6 @@ def checkFile(name, comment): parser.add_option("--mcop", action="store_true", default=False, dest="regions", help="mcop option for multi-copy rigid-body docking") (options, args) = parser.parse_args() -#receptor_name=args[0] -#ligand_name=args[1] print """ ********************************************************************** @@ -226,7 +224,7 @@ def checkFile(name, comment): #locale.setlocale(locale.LC_ALL, 'fr_FR') time_start = datetime.datetime.now() -#print now,"(",now.strftime("%A %B %d %Y, %H:%M"),")" + print "Start time:", time_start @@ -311,7 +309,7 @@ def check_ffversion(reduced): rec=AttractRigidbody(rec) lig=Rigidbody(options.ligand_name) lig=AttractRigidbody(lig) -# TODO: Redo message for mcop + print "Reading receptor (fixed): %s with %d particules" %( options.receptor_name, len(rec) ) print "Reading ligand (mobile): %s with %d particules" %( options.ligand_name, len(lig) ) @@ -426,7 +424,6 @@ def check_ffversion(reduced): if options.regions: lbfgs_minimizer=Lbfgs(mcopff) lbfgs_minimizer.minimize(niter) - #lbfgs_minimizer.normalize_weights() else : lbfgs_minimizer=ff_specs['minimizer_class'](forcefield) lbfgs_minimizer.minimize(niter) @@ -434,14 +431,8 @@ def check_ffversion(reduced): X=lbfgs_minimizer.GetMinimizedVars() #optimized freedom variables after minimization - #TODO: test and use CenterToOrigin() ! if options.regions: output=Mcoprigid(ligand) - ##weights = mcopff.getWeights() - #if minim == minimlist[len(minimlist)-2] and len(minimlist)>1: - # receptor.updateWeights(X, svptr=6, descriminate = 0) - #else: - # receptor.updateWeights(X, svptr=6, descriminate = 0) else: output=AttractRigidbody(ligand) @@ -474,7 +465,7 @@ def check_ffversion(reduced): for region in savedWeights[iteration]: weight_variation.write("\t\t") for copy in region: - weight_variation.write("%f\t"%t) + weight_variation.write("%f\t"%copy) weight_variation.write("\n") weight_variation.write("~~~~~~~~~~~~~~\n") diff --git a/bindings/mcopff.pyx b/bindings/mcopff.pyx index 1cd3eec..2e4977c 100644 --- a/bindings/mcopff.pyx +++ b/bindings/mcopff.pyx @@ -29,17 +29,12 @@ cdef extern from "mcopff.h" namespace "PTools": cdef cppclass CppMcoprigid "PTools::Mcoprigid": CppMcoprigid() CppMcoprigid(string&) except+ - #CppMcoprigid(CppRigidbody&, vector(CppAttractMcop)) CppMcoprigid(CppMcoprigid&) CppAttractMcop getRegion(unsigned int) CppAttractRigidbody getCore() unsigned int size() void setCore(CppAttractRigidbody&) vector[vector[double]] getWeights() - #void setWeights(vector[vector[double]]&) - #void updateWeights(vector[double], int, int) - #void denormalize_weights() - #void normalize_weights() Coord3D FindCenter() void setTranslation(int) void setRotation(int) @@ -52,8 +47,6 @@ cdef extern from "mcopff.h" namespace "PTools": CppMcopForceField(CppBaseAttractForceField&, double) vector[vector[double]] getWeights() vector[vector[double]] getMcopE() - #void denormalize_weights() - #void normalize_weights() void setReceptor(CppMcoprigid&) void setLigand(CppMcoprigid&) double CalcEnergy(CppMcoprigid&, CppMcoprigid&, CppBaseAttractForceField&, double) @@ -260,25 +253,8 @@ cdef class Mcoprigid: def getWeights(self): return self.thisptr.getWeights() - #def setWeights(self, weights vector[vector[double]]): - # self.thisptr.setWeights(weights) - - #def updateWeights(self, vector[double] v, int svptr, int descriminate): - # self.thisptr.updateWeights(v, svptr, descriminate) - - #def denormalize_weights(self): - # self.thisptr.denormalize_weights() - - #def normalize_weigths(self): - # self.thisptr.normalize_weights() def FindCenter(self): - #cdef Coord3D c = Coord3D() - #cdef CppCoord3D cpp = self.thisptr.FindCenter() - #c.x = cpp.x - #c.y = cpp.y - #c.z = cpp.z - #return c return self.getCore().FindCenter() def setTranslation(self, flag): @@ -332,14 +308,6 @@ cdef class McopForceField(ForceField): cdef CppMcopForceField* cpp_ptr = self.thisptr return cpp_ptr.getMcopE() - #def denormalize_weights(self): - # cdef CppMcopForceField* cpp_ptr = self.thisptr - # cpp_ptr.denormalize_weights() - - #def normalize_weigths(self): - # cdef CppMcopForceField* cpp_ptr = self.thisptr - # cpp_ptr.normalize_weights() - def setReceptor(self, Mcoprigid rec): cdef CppMcopForceField* cpp_ptr = self.thisptr cpp_ptr.setReceptor(deref(rec.thisptr)) diff --git a/headers/mcopff.h b/headers/mcopff.h index 0b9bdc3..6fa915b 100644 --- a/headers/mcopff.h +++ b/headers/mcopff.h @@ -23,23 +23,6 @@ class Mcop std::vector _copies; public: -/* - void AttractEulerRotate(const dbl& phi, const dbl& ssi, const dbl& rot) - { - for (uint i=0; i<_copies.size(); i++) - { - _copies[i].AttractEulerRotate(phi, ssi, rot); - } - - }; - - void Translate(const Coord3D& co) - { - for(uint i =0; i< _copies.size(); ++i) - { - _copies[i].Translate(co); - } - }*/ //Contructor : no arguments Mcop(){ } @@ -115,12 +98,6 @@ class Mcoprigid //multicopy rigidbody void PrintWeights(); std::vector > getWeights(){return _weights;}; - //void setWeights(vector[vector[double]]& w){_weights = w;}; - //void denormalize_weights(); - //void normalize_weights(); - //void denormalize_buffer_weights(); - //void normalize_buffer_weights(); - //void updateWeights(const std::vector& v, int svptr, int descriminate); void ReadMcoprigidPDB(const std::string name); void ReadMcoprigidPDB(std::istream& file, AttractRigidbody& core, std::vector& regions); @@ -142,14 +119,9 @@ class Mcoprigid //multicopy rigidbody AttractRigidbody _core; std::vector< AttractMcop > _vregion ; - bool _complete ; + bool _complete ; //is this used ? Coord3D _center ; ///
> _weights; - //std::vector< std::vector > _denorm_weights; - //std::vector< std::vector > _buffer_weights; - //std::vector< std::vector > _buffer_denorm_weights; - friend class McopForceField; @@ -168,31 +140,23 @@ class McopForceField: public ForceField public: McopForceField(BaseAttractForceField& ff, dbl cutoff) - :_ff(ff), _cutoff(cutoff) { _beta = 1; }; + :_ff(ff), _cutoff(cutoff) { _beta = 0.3; }; void ini_energies(); dbl Function(const Vdouble&); dbl CalcEnergy(Mcoprigid & receptor,Mcoprigid & lig, BaseAttractForceField & ff, dbl cutoff); void Derivatives(const Vdouble& v, Vdouble & g ); - void setReceptor(Mcoprigid& rec); void setLigand(Mcoprigid& lig); - //void calculate_weights(Mcoprigid& lig, bool print=false); - uint ProblemSize(); void initMinimization(){}; virtual void saveWeights(){_savedWeights.push_back(_receptor.getWeights());}; - std::vector< std::vector< std::vector > > getSavedWeights(){ return _savedWeights;} + std::vector< std::vector< std::vector > > getSavedWeights(){return _savedWeights;}; std::vector > getWeights(){return _receptor.getWeights();}; std::vector > getMcopE(){return _Eik;}; - //void denormalize_weights(){_receptor.denormalize_weights();}; - //void normalize_weights(){_receptor.normalize_weights();}; - //void denormalize_buffer_weights(){_receptor.denormalize_buffer_weights();}; - //void normalize_buffer_weights(){_receptor.normalize_buffer_weights();}; - private: @@ -205,16 +169,14 @@ class McopForceField: public ForceField Mcoprigid _centered_ligand ; Mcoprigid _moved_ligand ; Mcoprigid _receptor; - std::vector< std::vector > _Eik; //Loop interaction energies - std::vector< std::vector< std::vector > > _dEik; + std::vector< std::vector > _Eik; //Loop copy interaction energies + std::vector< std::vector< std::vector > > _dEik; //- force applied to the ligand by each loop copy dbl _E; //Total interaction energy - std::vector _Eregion; + std::vector _Eregion; //Loop region interaction energies std::vector _Z; // one Z per loop region - std::vector _Zprime; - std::vector< std::vector > _dz; - std::vector< std::vector > _dzprime; - dbl _beta; - std::vector< std::vector< std::vector > > _savedWeights; + std::vector _Zprime; // one Z' per loop region + dbl _beta; // constant in the energy function + std::vector< std::vector< std::vector > > _savedWeights; //conserved weights throughout minimizations of a docking diff --git a/src/attractforcefield.cpp b/src/attractforcefield.cpp index 085b047..f9413d0 100644 --- a/src/attractforcefield.cpp +++ b/src/attractforcefield.cpp @@ -397,10 +397,6 @@ dbl BaseAttractForceField::Function(const Vdouble& stateVars ) } - - ///std::cout << "Energie totale " << enernon << std::endl; - - return enernon; } @@ -506,7 +502,6 @@ dbl AttractForceField2::nonbon8_forces(AttractRigidbody& rec, AttractRigidbody& dbl charge= rec.m_charge[i]* lig.m_charge[j]; //charge product of the two atoms - //std::cout << "charge: " << charge << std::endl; rec.unsafeGetCoords(i,a); lig.unsafeGetCoords(j,b); @@ -605,10 +600,6 @@ void BaseAttractForceField::Trans(uint molIndex, Vdouble & delta, uint shift, b delta[1+shift]=ftr2; delta[2+shift]=ftr3; - ///std::cout << "Dériv trans " << 1 << " " << delta[0+shift] << std::endl; - ///std::cout << "Dériv trans " << 2 << " " << delta[1+shift] << std::endl; - ///std::cout << "Dériv trans " << 3 << " " << delta[2+shift] << std::endl; - //debug: if (print) std::cout << "translational forces: " << ftr1 <<" "<< ftr2 <<" " << ftr3 << std::endl; return ; @@ -654,17 +645,6 @@ void BaseAttractForceField::Rota(uint molIndex, dbl phi,dbl ssi, dbl rot, Vdoubl crot=cos(rot); srot=sin(rot); - //std::cout << "cs" << cs << std::endl; - //std::cout << "cp" << cp << std::endl; - //std::cout << "ss" << ss << std::endl; - //std::cout << "sp" << sp << std::endl; - //std::cout << "cscp" << cscp << std::endl; - //std::cout << "cssp" << cssp << std::endl; - //std::cout << "sscp" << sscp << std::endl; - //std::cout << "sssp" << sssp << std::endl; - //std::cout << "crot" << crot << std::endl; - //std::cout << "srot" << srot << std::endl; - // for the x, y and z coordinates, we need // the coordinates of the centered, non-translated molecule @@ -682,7 +662,6 @@ void BaseAttractForceField::Rota(uint molIndex, dbl phi,dbl ssi, dbl rot, Vdoubl Y = coords.y; Z = coords.z; - //std::cout << "X " << X << std::endl; xar=X*crot+Y*srot; yar=-X*srot+Y*crot; @@ -700,17 +679,6 @@ void BaseAttractForceField::Rota(uint molIndex, dbl phi,dbl ssi, dbl rot, Vdoubl pm[1][2]=yar*cssp-xar*cp ; pm[2][2]=-yar*ss ; - //std::cout << "xar " << xar << std::endl; - //std::cout << "yar " << yar << std::endl; - //std::cout << "pm[0][0] " << pm[0][0] << std::endl; - //std::cout << "pm[1][0] " << pm[1][0] << std::endl; - //std::cout << "pm[2][0] " << pm[2][0] << std::endl; - //std::cout << "pm[0][1] " << pm[0][1] << std::endl; - //std::cout << "pm[1][1] " << pm[1][1] << std::endl; - //std::cout << "pm[2][1] " << pm[2][1] << std::endl; - //std::cout << "pm[0][2] " << pm[0][2] << std::endl; - //std::cout << "pm[1][2] " << pm[1][2] << std::endl; - //std::cout << "pm[2][2] " << pm[2][2] << std::endl; for (uint j=0;j<3;j++) { @@ -720,11 +688,6 @@ void BaseAttractForceField::Rota(uint molIndex, dbl phi,dbl ssi, dbl rot, Vdoubl } } - ///std::cout << "Dériv rot " << 1 << " " << delta[0+shift] << std::endl; - ///std::cout << "Dériv rot " << 2 << " " << delta[1+shift] << std::endl; - ///std::cout << "Dériv rot " << 3 << " " << delta[2+shift] << std::endl; - - if (print) std::cout << "Rotational forces: " << delta[shift] << " " << delta[shift+1] << " " << delta[shift+2] << std::endl; diff --git a/src/mcopff.cpp b/src/mcopff.cpp index b60c200..a0ff212 100644 --- a/src/mcopff.cpp +++ b/src/mcopff.cpp @@ -27,15 +27,11 @@ void Mcoprigid::iniWeights(){ for(uint i=0; i < _vregion.size(); i++){ std::vector newvector; _weights.push_back(newvector); - //_denorm_weights.push_back(newvector); for(uint j=0; j < _vregion[i].size(); j++){ dbl weight = 1.0/(double)_vregion[i].size(); _weights[i].push_back(weight); - //_denorm_weights[i].push_back(1); } } - //_buffer_denorm_weights = _denorm_weights; - //_buffer_weights = _weights; } void Mcoprigid::setCore(AttractRigidbody& core) { @@ -50,11 +46,9 @@ void Mcoprigid::AttractEulerRotate(const dbl& phi, const dbl& ssi, const dbl& ro //Warning: makes euler rotation without centering //the Mcoprigid object must be centered - //rotates the core body: _core.AttractEulerRotate(phi, ssi, rot); - //for each multicopy region, rotates the copy: for (uint i=0; i < _vregion.size(); i++) for (uint j=0; j<_vregion[i].size(); j++) @@ -156,75 +150,6 @@ uint Mcoprigid::line_to_copy_number(std::string line){ return std::atoi(line.substr(15,line.size()-15).c_str()); } -/*void Mcoprigid::denormalize_weights(){ - for(uint i=0; i < _weights.size(); i++){ - dbl max_weight = *max_element(_weights[i].begin(), _weights[i].end()); - for(uint j=0; j < _weights[i].size(); j++){ - _denorm_weights[i][j] = sqrt(_weights[i][j]/max_weight); - } - } -} - -void Mcoprigid::denormalize_buffer_weights(){ - for(uint i=0; i < _buffer_weights.size(); i++){ - dbl max_weight = *max_element(_buffer_weights[i].begin(), _buffer_weights[i].end()); - for(uint j=0; j < _buffer_weights[i].size(); j++){ - _buffer_denorm_weights[i][j] = sqrt(_buffer_weights[i][j]/max_weight); - } - } -} - -void Mcoprigid::normalize_weights(){ - - for(uint i=0; i < _denorm_weights.size(); i++){ - dbl sum_squared_denorm_weights = 0; - for(uint j=0; j < _denorm_weights[i].size(); j++){ - sum_squared_denorm_weights += _denorm_weights[i][j]*_denorm_weights[i][j]; - } - for(uint j=0; j < _denorm_weights[i].size(); j++){ - _weights[i][j] = (_denorm_weights[i][j]*_denorm_weights[i][j])/sum_squared_denorm_weights; - } - } -} - -void Mcoprigid::normalize_buffer_weights(){ - - for(uint i=0; i < _buffer_denorm_weights.size(); i++){ - dbl sum_squared_denorm_weights = 0; - for(uint j=0; j < _buffer_denorm_weights[i].size(); j++){ - sum_squared_denorm_weights += _buffer_denorm_weights[i][j]*_buffer_denorm_weights[i][j]; - } - for(uint j=0; j < _buffer_denorm_weights[i].size(); j++){ - _buffer_weights[i][j] = (_buffer_denorm_weights[i][j]*_buffer_denorm_weights[i][j])/sum_squared_denorm_weights; - } - } -} - -void Mcoprigid::updateWeights(const std::vector& v, int svptr, int descriminate){ - //svptr: state variable "pointer" - for(uint loopregion=0; loopregion < _vregion.size() ; loopregion++){ - for(uint copynb = 0; copynb < _vregion[loopregion].size(); copynb++){ - dbl & w = _denorm_weights[loopregion][copynb]; - w = v[svptr] + w; //delta weight + original weight - svptr += 1; - } - } - normalize_weights(); - if(descriminate == 1){ - for(uint loopregion=0; loopregion < _vregion.size() ; loopregion++){ - for(uint copynb = 0; copynb < _vregion[loopregion].size(); copynb++){ - dbl & w = _weights[loopregion][copynb]; - if(w == *max_element(_weights[loopregion].begin(), _weights[loopregion].end())) - w = 1; - else - w = 0; - } - } - denormalize_weights(); - } -} - -*/ /////////////////// -- Class Mcop -- //////////////////// @@ -352,11 +277,8 @@ void McopForceField::ini_energies(){ _Z.push_back(0); _Zprime.push_back(0); _Eregion.push_back(0); - //_dz.push_back(threezeros); - //_dzprime.push_back(threezeros); _dEik.push_back(newcoordsvecvec); for(uint k=0; k < _receptor.getRegions()[i].size(); k++){ - //Coord3D coords; _Eik[i].push_back(0); std::vector newcoordsvec; _dEik[i].push_back(newcoordsvec); @@ -365,72 +287,12 @@ void McopForceField::ini_energies(){ } - -/*void McopForceField::calculate_weights(Mcoprigid& lig, bool print) -{ - - -//loop over copies regions - for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++) - { - if (print) - { - std::cout << " Region: " << loopregion << "\n"; - } - - //calculates interaction energy between receptor copies and ligand body: - std::vector Eik; - - for (uint copy = 0; copy < _receptor._vregion[loopregion].size(); copy++) - { - AttractPairList cpl ( lig._core, _receptor._vregion[loopregion][copy], _cutoff ); - dbl e = _ff.nonbon8( lig._core, _receptor._vregion[loopregion][copy] , cpl ); - Eik.push_back(e); - } - - - - const dbl RT = 0.592 * 298.0 ; - - //calculate weights - dbl sumweights = 0.0; - std::vector weights; - - for (uint i=0; i > weights; //TODO: take into account if no rotation or no translation lig.AttractEulerRotate(v[0],v[1],v[2]); lig.Translate(Coord3D(v[3],v[4],v[5])); assert(_receptor._vregion.size() == _receptor._weights.size()); - //Update the denormalized weights - /* - uint svptr = 0; // stateVars 'pointer' - if (lig.getCore().hasrotation) svptr += 3; - if (lig.getCore().hastranslation) svptr += 3; - //dnorm_weights is not a reference therefore we are manipulating a new set of weights - std::vector< std::vector > denorm_weights = _receptor._denorm_weights; - for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++){ - AttractMcop& ref_ensemble = _receptor._vregion[loopregion]; - std::vector & denorm_weights_loop = denorm_weights[loopregion]; - assert( ref_ensemble.size() == denorm_weights_loop.size()); - for (uint copynb = 0; copynb < ref_ensemble.size(); copynb++){ - dbl & denorm_weight = denorm_weights_loop[copynb]; - denorm_weight = v[svptr] + denorm_weight; //delta weight + original weight (from before minimization) - svptr += 1; - } - } - _receptor._buffer_denorm_weights = denorm_weights; - normalize_buffer_weights(); - denormalize_buffer_weights(); - std::vector< std::vector >& weights = _receptor._buffer_weights; - */ - //2) calculates the energy @@ -500,13 +338,10 @@ dbl McopForceField::Function(const Vdouble & v) std::vector& Eregion = _Eregion; dbl& beta = _beta; - //std::cout << "BETA " << beta << std::endl; - for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++) { //calculates interaction energy between receptor copies and ligand body: -// std::vector Eik; dbl enercopy =0.0; dbl& Z_i = Z[loopregion]; dbl& Zprime_i = Zprime[loopregion]; @@ -533,42 +368,14 @@ dbl McopForceField::Function(const Vdouble & v) enercopy = _ff.nonbon8_forces(copy, lig._core, cpl, copyforce, coreforce); Eik[loopregion][copynb] = enercopy; if(enercopy < Emin) Emin = enercopy; - - ///std::cout << "Eik" << copynb << " " << enercopy << std::endl; - - /*if(beta*enercopy > 700){ - if(700/enercopy < beta_temp){ - beta_temp = 700/enercopy; - } - } - else{ - clash = false; - }*/ - - ///Z_i += exp(-beta*enercopy); - ///Zprime_i += -enercopy*exp(-beta*enercopy); - - //add force to ligand assert(lig._core.Size() == coreforce.size()); dEik[loopregion][copynb] = coreforce; - //for(uint bead=0; bead Eik; dbl enercopy =0.0; dbl& Z_i = Z[loopregion]; @@ -656,8 +456,6 @@ dbl McopForceField::CalcEnergy(Mcoprigid & receptor, Mcoprigid & lig, BaseAttrac { dbl& weight = weights_loop[copynb]; weight = exp(-beta*Eik[loopregion][copynb])/Z_i; - ///if(copynb == 0) weight = 1; - ///else weight = 0; } ener_region += -Zprime_i/Z_i; } @@ -672,15 +470,15 @@ void McopForceField::Derivatives(const Vdouble& v, Vdouble & g ) Mcoprigid & lig = _moved_ligand; uint svptr = 0; // stateVars 'pointer' -//std::vector& Z = _Z; -//std::vector& Zprime = _Zprime; -//std::vector< std::vector >& dz = _dz; -//std::vector< std::vector >& dzprime = _dzprime; +// - force applied to the ligand by each loop copy std::vector< std::vector< std::vector > >& dEik = _dEik; +//Interaction nergy between each loop copy and the ligand std::vector< std::vector >& Eik = _Eik; -dbl E = _E; +//Interactino energy between each variable region (sum of its copies) and the ligand. std::vector& Eregion = _Eregion; +//Weight of each loop copy std::vector< std::vector > & weights = _receptor._weights; +//beta coefficient (constant in energy function) dbl& beta = _beta; std::vector< std::vector > coef; @@ -748,11 +546,7 @@ if (lig.getCore().hasrotation){ std::vector dEcore(3, 0.0); std::vector dEloops(3, 0.0); - //printf("pLigCentered->m_activeAtoms.size() = %d\n", pLigCentered->m_activeAtoms.size()); - //for (uint i=0; i< pLigCentered->m_activeAtoms.size(); i++) for(uint atomIndex=0; atomIndex<_moved_ligand._core.Size(); atomIndex++){ - //uint atomIndex = pLigCentered->m_activeAtoms[i]; - Coord3D coords = pLigCentered->GetCoords(atomIndex); @@ -760,8 +554,6 @@ if (lig.getCore().hasrotation){ y = coords.y; z = coords.z; - //std::cout << "X " << X << std::endl; - xar=x*crot+y*srot; yar=-x*srot+y*crot; @@ -777,18 +569,6 @@ if (lig.getCore().hasrotation){ pm[1][2]=yar*cssp-xar*cp ; pm[2][2]=-yar*ss ; - //std::cout << "xar " << xar << std::endl; - //std::cout << "yar " << yar << std::endl; - //std::cout << "pm[0][0] " << pm[0][0] << std::endl; - //std::cout << "pm[1][0] " << pm[1][0] << std::endl; - //std::cout << "pm[2][0] " << pm[2][0] << std::endl; - //std::cout << "pm[0][1] " << pm[0][1] << std::endl; - //std::cout << "pm[1][1] " << pm[1][1] << std::endl; - //std::cout << "pm[2][1] " << pm[2][1] << std::endl; - //std::cout << "pm[0][2] " << pm[0][2] << std::endl; - //std::cout << "pm[1][2] " << pm[1][2] << std::endl; - //std::cout << "pm[2][2] " << pm[2][2] << std::endl; - //adding the derivatives for the core: for(uint j=0; j < 3; j++){ dEcore[j] += pm[0][j] * pLigMoved->m_forces[atomIndex].x; @@ -813,7 +593,6 @@ if (lig.getCore().hasrotation){ for(uint j=0; j < 3; j++){ g[svptr+j] += dEcore[j] + dEloops[j]; - ///std::cout << "Dériv rot " << j << " " << g[svptr+j] << std::endl; } svptr += 3; @@ -881,41 +660,10 @@ if (lig.getCore().hastranslation){ g[svptr+0] = ftr1; g[svptr+1] = ftr2; g[svptr+2] = ftr3; - //std::cout << "Dériv trans " << 1 << " " << ftr1 << std::endl; - //std::cout << "Dériv trans " << 2 << " " << ftr2 << std::endl; - //std::cout << "Dériv trans " << 3 << " " << ftr3 << std::endl; svptr += 3; } - -// Calculate de weight derivative - -/*assert(_receptor._vregion.size() == _Eik.size()); -uint k = 0; -for (uint loopregion=0; loopregion < _receptor._vregion.size() ; loopregion++){ - - std::vector& ref_weights = _receptor._buffer_weights[loopregion]; - std::vector& ref_denorm_weights = _receptor._buffer_denorm_weights[loopregion]; - std::vector& ref_Eik = _Eik[loopregion]; - assert(ref_weights.size() == ref_Eik.size()); - - dbl max_weight = *max_element(ref_weights.begin(), ref_weights.end()); - for(uint copynb=0; copynb < _Eik[loopregion].size(); copynb++){ - // weight derivative function - g[svptr + k] = 2*max_weight*ref_denorm_weights[copynb]*ref_Eik[copynb]; - //printf("vector v[%d] = %f\n",svptr+k, v[svptr+k]); - //printf("vector g[%d] = %f\n",svptr+k, g[svptr+k]); - k++; - } -}*/ - - - - - - - } diff --git a/src/minimizers/lbfgs_interface.cpp b/src/minimizers/lbfgs_interface.cpp index cca9d78..c592740 100644 --- a/src/minimizers/lbfgs_interface.cpp +++ b/src/minimizers/lbfgs_interface.cpp @@ -108,11 +108,7 @@ void Lbfgs::minimize(int maxiter) int sub_iter = 0; double grad = 0; - //double new_beta = 1; - //x.push_back(new_beta); - //double & beta = x[x.size()-1]; - /* opt->iprint = 0;*/ while (1) { rc = lbfgsb_run(m_opt, &x[0], &f, &g[0]); if (rc == 0) { @@ -130,8 +126,6 @@ void Lbfgs::minimize(int maxiter) //saves the minimizer variables for each iteration (can be useful for generating animations) m_vars_over_time.push_back(x); objToMinimize.saveWeights(); //Only saves weights if objToMinimize is McopForceField. - ///std::cout << "########################## NEW ITERATION " << m_opt->niter << std::endl; - } double sum = 0; @@ -145,30 +139,9 @@ void Lbfgs::minimize(int maxiter) std::vector vdblg; tocplx(g,vdblg); f = objToMinimize.Function(vdblx); - //std::cout << "f = " << f << std::endl; objToMinimize.Derivatives(vdblx,vdblg); g=todbl(vdblg); - grad = sqrt(sum); - ///std::cout << "GRAD " << grad << std::endl; - ///std::cout << "ENERGY " << f << std::endl; - - // Too get things moving if the gradient is stuck. - /*if(grad - sqrt(sum) > -0.0001 && grad - sqrt(sum) < 0.0001){ - //if(sub_iter > 20){ - //f += 10; - //std::cout << "STUCK " << grad - sqrt(sum) << std::endl; - //std::cout << "GRAD " << grad << std::endl; - //beta = 10; - //f += 10; - //grad = 0; - //sub_iter = 15; - } - else{ - //grad = sqrt(sum); - beta = 1; - }*/ - sub_iter ++; } else { @@ -200,41 +173,13 @@ if (iter>=m_vars_over_time.size()) return m_vars_over_time[iter]; } -/*void Lbfgs::denormalize_weights() -{ - if (McopForceField * p = dynamic_cast(&objToMinimize)){ - // objToMinimize is or is of type McopForceField - ForceField& r_objToMinimize = objToMinimize; - McopForceField& r_Mcop_objToMinimize = dynamic_cast(r_objToMinimize); - r_Mcop_objToMinimize.denormalize_weights(); - } - //else - // objToMinimize is not a McopForceField - -} - -void Lbfgs::normalize_weights() -{ - if (McopForceField * p = dynamic_cast(&objToMinimize)){ - // objToMinimize is or is of type McopForceField - ForceField& r_objToMinimize = objToMinimize; - McopForceField& r_Mcop_objToMinimize = dynamic_cast(r_objToMinimize); - r_Mcop_objToMinimize.normalize_weights(); - } - //else - // objToMinimize is not a McopForceField -} -*/ - std::vector< std::vector > Lbfgs::getWeights(){ if (McopForceField * p = dynamic_cast(&objToMinimize)){ - // objToMinimize is or is of type McopForceField + // objToMinimize is of type McopForceField ForceField& r_objToMinimize = objToMinimize; McopForceField& r_Mcop_objToMinimize = dynamic_cast(r_objToMinimize); r_Mcop_objToMinimize.getWeights(); } - //else - // objToMinimize is not a McopForceField }