conformersearch.h
Go to the documentation of this file.
00001 /********************************************************************** 00002 conformersearch.h - Conformer searching using genetic algorithm. 00003 00004 Copyright (C) 2010 Tim Vandermeersch 00005 00006 This file is part of the Open Babel project. 00007 For more information, see <http://openbabel.org/> 00008 00009 This program is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation version 2 of the License. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 ***********************************************************************/ 00018 00019 #ifndef OB_CONFORMERSEARCH_H 00020 #define OB_CONFORMERSEARCH_H 00021 00022 #include <openbabel/mol.h> 00023 #include <openbabel/rotor.h> 00024 #include <openbabel/rotamer.h> 00025 00026 namespace OpenBabel { 00027 00028 typedef std::vector<int> RotorKey; 00029 typedef std::vector<RotorKey> RotorKeys; 00030 00033 00035 // 00036 // OBConformerFilter(s) 00037 // 00039 00052 class OBAPI OBConformerFilter 00053 { 00054 public: 00061 virtual bool IsGood(const OBMol &mol, const RotorKey &key, double *coords) = 0; 00062 }; 00063 00076 class OBAPI OBConformerFilters : public OBConformerFilter 00077 { 00078 public: 00082 OBConformerFilters(const std::vector<OBConformerFilter*> &filters) : m_filters(filters) 00083 { 00084 } 00089 bool IsGood(const OBMol &mol, const RotorKey &key, double *coords) 00090 { 00091 for (unsigned int i = 0; i < m_filters.size(); ++i) 00092 if (!m_filters[i]->IsGood(mol, key, coords)) 00093 return false; 00094 return true; 00095 } 00096 protected: 00097 std::vector<OBConformerFilter*> m_filters; 00098 }; 00099 00109 class OBAPI OBStericConformerFilter : public OBConformerFilter 00110 { 00111 public: 00112 OBStericConformerFilter(double cutoff) : m_cutoff(cutoff) {} 00113 bool IsGood(const OBMol &mol, const RotorKey &key, double *coords); 00114 private: 00115 double m_cutoff; 00116 }; 00117 00119 // 00120 // OBConformerScore(s) 00121 // 00123 00137 class OBAPI OBConformerScore 00138 { 00139 public: 00143 enum Preferred { HighScore, LowScore }; 00147 virtual Preferred GetPreferred() = 0; 00151 enum Convergence { Highest, Lowest, Sum, Average }; 00155 virtual Convergence GetConvergence() = 0; 00159 virtual double Score(OBMol &mol, unsigned int index, const RotorKeys &keys, 00160 const std::vector<double*> &conformers) = 0; 00161 }; 00162 00171 class OBAPI OBRMSDConformerScore : public OBConformerScore 00172 { 00173 public: 00174 Preferred GetPreferred() { return HighScore; } 00175 Convergence GetConvergence() { return Average; } 00176 double Score(OBMol &mol, unsigned int index, const RotorKeys &keys, 00177 const std::vector<double*> &conformers); 00178 }; 00179 00185 class OBAPI OBEnergyConformerScore : public OBConformerScore 00186 { 00187 public: 00188 Preferred GetPreferred() { return LowScore; } 00189 Convergence GetConvergence() { return Lowest; } 00190 double Score(OBMol &mol, unsigned int index, const RotorKeys &keys, 00191 const std::vector<double*> &conformers); 00192 }; 00193 00199 class OBAPI OBMinimizingEnergyConformerScore : public OBConformerScore 00200 { 00201 public: 00202 Preferred GetPreferred() { return LowScore; } 00203 Convergence GetConvergence() { return Lowest; } 00204 double Score(OBMol &mol, unsigned int index, const RotorKeys &keys, 00205 const std::vector<double*> &conformers); 00206 }; 00207 00209 // 00210 // OBConformerSearch 00211 // 00213 00220 class OBAPI OBConformerSearch 00221 { 00222 public: 00223 OBConformerSearch(); 00224 ~OBConformerSearch(); 00238 bool Setup(const OBMol &mol, int numConformers = 30, int numChildren = 5, 00239 int mutability = 5, int convergence = 25); 00243 void SetNumConformers(int numConformers) { m_numConformers = numConformers; } 00247 void SetNumChildren(int numChildren) { m_numChildren = numChildren; } 00251 void SetMutability(int mutability) { m_mutability = mutability; } 00256 void SetConvergence(int convergence) { m_convergence = convergence; } 00260 void SetFixedBonds(const OBBitVec &fixedBonds) { m_fixedBonds = fixedBonds; } 00261 00262 00271 void SetFilter(OBConformerFilter *filter) 00272 { 00273 delete m_filter; 00274 m_filter = filter; 00275 } 00285 void SetScore(OBConformerScore *score) 00286 { 00287 delete m_score; 00288 m_score = score; 00289 } 00290 00294 void Search(); 00295 00296 const RotorKeys& GetRotorKeys() const 00297 { 00298 return m_rotorKeys; 00299 } 00300 00301 void GetConformers(OBMol &mol); 00302 private: 00306 void NextGeneration(); 00310 double MakeSelection(); 00314 bool IsUniqueKey(const RotorKeys &keys, const RotorKey &key) const; 00318 bool IsGood(const RotorKey &key); 00319 00320 int m_numConformers; 00321 int m_numChildren; 00322 int m_mutability; 00323 int m_convergence; 00324 00325 OBBitVec m_fixedBonds; 00326 OBMol m_mol; 00327 OBRotorList m_rotorList; 00328 RotorKeys m_rotorKeys; 00329 00330 OBConformerFilter *m_filter; 00331 OBConformerScore *m_score; 00332 00333 00334 }; 00335 00442 00443 }; 00444 00445 #endif 00446


