Loading...
Searching...
No Matches
conformersearch.h
Go to the documentation of this file.
/**********************************************************************
conformersearch.h - Conformer searching using genetic algorithm.
Copyright (C) 2010 Tim Vandermeersch
Some portions Copyright (C) 2012 Materials Design, Inc.
Some portions Copyright (C) 2016 Torsten Sachse
This file is part of the Open Babel project.
For more information, see <http://openbabel.org/>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
***********************************************************************/
#ifndef OB_CONFORMERSEARCH_H
#define OB_CONFORMERSEARCH_H
#include <openbabel/mol.h>
#include <openbabel/rotor.h>
#include <openbabel/rotamer.h>
namespace OpenBabel {
typedef std::vector<int> RotorKey;
typedef std::vector<RotorKey> RotorKeys;
typedef std::map<std::vector<int>,double> mapRotorEnergy;
//
// OBConformerFilter(s)
//
class OBAPI OBConformerFilter
{
public:
virtual bool IsGood(const OBMol &mol, const RotorKey &key, double *coords) = 0;
virtual ~OBConformerFilter() = 0;
};
class OBAPI OBConformerFilters : public OBConformerFilter
{
public:
OBConformerFilters(const std::vector<OBConformerFilter*> &filters) : m_filters(filters)
{
}
bool IsGood(const OBMol &mol, const RotorKey &key, double *coords)
{
for (unsigned int i = 0; i < m_filters.size(); ++i)
if (!m_filters[i]->IsGood(mol, key, coords))
return false;
return true;
}
protected:
std::vector<OBConformerFilter*> m_filters;
};
class OBAPI OBStericConformerFilter : public OBConformerFilter
{
public:
OBStericConformerFilter ();
OBStericConformerFilter (double cutoff, double vdw_factor = 0.5, bool check_hydrogens = true);
bool IsGood(const OBMol &mol, const RotorKey &key, double *coords);
private:
double m_cutoff;
double m_vdw_factor;
bool m_check_hydrogens;
};
//
// OBConformerScore(s)
//
class OBAPI OBConformerScore
{
public:
enum Preferred { HighScore, LowScore };
virtual Preferred GetPreferred() = 0;
enum Convergence { Highest, Lowest, Sum, Average };
virtual Convergence GetConvergence() = 0;
virtual double Score(OBMol &mol, unsigned int index, const RotorKeys &keys,
const std::vector<double*> &conformers) = 0;
virtual ~OBConformerScore() = 0;
};
class OBAPI OBRMSDConformerScore : public OBConformerScore
{
public:
Preferred GetPreferred() { return HighScore; }
Convergence GetConvergence() { return Average; }
double Score(OBMol &mol, unsigned int index, const RotorKeys &keys,
const std::vector<double*> &conformers);
};
class OBAPI OBEnergyConformerScore : public OBConformerScore
{
public:
OBEnergyConformerScore () {
energy_map.clear ();
energy_ncompute = 0;
energy_nrequest = 0;
}
long unsigned int GetNbEnergyCompute () {return energy_ncompute;}
long unsigned int GetNbEnergyRequest () {return energy_nrequest;}
Preferred GetPreferred() { return LowScore; }
Convergence GetConvergence() { return Lowest; }
double Score(OBMol &mol, unsigned int index, const RotorKeys &keys,
const std::vector<double*> &conformers);
private:
mapRotorEnergy energy_map;
long unsigned int energy_ncompute;
long unsigned int energy_nrequest;
};
class OBAPI OBMinimizingEnergyConformerScore : public OBConformerScore
{
public:
OBMinimizingEnergyConformerScore () {
energy_map.clear ();
energy_ncompute = 0;
energy_nrequest = 0;
}
long unsigned int GetNbEnergyCompute () {return energy_ncompute;}
long unsigned int GetNbEnergyRequest () {return energy_nrequest;}
Preferred GetPreferred() { return LowScore; }
Convergence GetConvergence() { return Lowest; }
double Score(OBMol &mol, unsigned int index, const RotorKeys &keys,
const std::vector<double*> &conformers);
private:
mapRotorEnergy energy_map;
long unsigned int energy_ncompute;
long unsigned int energy_nrequest;
};
class OBAPI OBMinimizingRMSDConformerScore : public OBConformerScore
{
public:
Preferred GetPreferred() { return HighScore; }
Convergence GetConvergence() { return Average; }
double Score(OBMol &mol, unsigned int index, const RotorKeys &keys,
const std::vector<double*> &conformers);
};
//
// OBConformerSearch
//
class OBAPI OBConformerSearch
{
public:
OBConformerSearch();
~OBConformerSearch();
bool Setup(const OBMol &mol, int numConformers = 30, int numChildren = 5,
int mutability = 5, int convergence = 25);
void SetNumConformers(int numConformers) { m_numConformers = numConformers; }
void SetNumChildren(int numChildren) { m_numChildren = numChildren; }
void SetMutability(int mutability) { m_mutability = mutability; }
void SetConvergence(int convergence) { m_convergence = convergence; }
void SetFixedBonds(const OBBitVec &fixedBonds) { m_fixedBonds = fixedBonds; }
void SetFilter(OBConformerFilter *filter)
{
delete m_filter;
m_filter = filter;
}
void SetScore(OBConformerScore *score)
{
delete m_score;
m_score = score;
}
void PrintRotors(bool printrotors) { m_printrotors = printrotors; }
void Search();
const RotorKeys& GetRotorKeys() const
{
return m_rotorKeys;
}
void GetConformers(OBMol &mol);
/* @brief Set an output stream for logging. If NULL pointer is provided, logging is disabled. */
void SetLogStream (std::ostream *sptr) {m_logstream = sptr;}
/*************************************************/
/* Methods related to fitness sharing parameters */
/* @brief Set the use of fitness sharing ON (default) or OFF*/
void SetSharing (bool value = true) {use_sharing = value;}
/* @brief Get the targeted number of niches, for dynamic niche sharing */
int GetNbNiches () {return nb_niches;}
/* @brief Set the targeted number of niches, for dynamic niche sharing */
void SetNbNiches (int value) {nb_niches = value;}
/* @brief Get niches radius, for dynamic niche sharing.*/
double GetNicheRadius () {return niche_radius;}
/* @brief Set niches radius, for dynamic niche sharing.*/
void SetNicheRadius (double value) {niche_radius = value;}
/* @brief Get the alpha sharing parameter */
double GetAlphaSharing () {return alpha_share;}
/* @brief Set the alpha sharing parameter */
void SetAlphaSharing (double value) {alpha_share = value;}
/* @brief Get the sigma sharing parameter */
double GetSigmaSharing () {return sigma_share;}
/* @brief Set the sigma sharing parameter */
void SetSigmaSharing (double value) {sigma_share = value;}
/* @brief Get the (uniform) crossover probability */
double GetCrossoverProbability () {return p_crossover;}
/* @brief Set the (uniform) crossover probability */
void SetCrossoverProbability (double value) {p_crossover = value;}
/* @brief Get the niche mating probability, for dynamic niche sharing */
double GetNicheMating () {return niche_mating;}
/* @brief Set the (uniform) crossover probability */
void SetNicheMating (double value) {niche_mating = value;}
/* @brief Set the local optimization rate */
void SetLocalOptRate (int value) {local_opt_rate = value;}
/* @brief Get the local optimization rate*/
int SetLocalOptRate() {return local_opt_rate;}
private:
void NextGeneration();
double MakeSelection();
bool IsUniqueKey(const RotorKeys &keys, const RotorKey &key) const;
bool IsGood(const RotorKey &key);
int key_distance (const RotorKey &key1, const RotorKey &key2);
int local_opt ();
int reproduce (RotorKey &key1, RotorKey &key2);
int score_population ();
int share_fitness ();
double sharing_generation ();
unsigned int m_numConformers;
int m_numChildren;
int m_mutability;
int m_convergence;
std::vector<double> vscores;
std::vector<double> vshared_fitnes;
std::vector<std::vector <int> > dynamic_niches;
std::vector<int> niche_map;
void *d; // Opaque pointer - currently for storing OBRandom* which may be removed in future
bool use_sharing;
double alpha_share;
double sigma_share;
int nb_niches;
double niche_radius;
double p_crossover;
double niche_mating;
int local_opt_rate;
OBBitVec m_fixedBonds;
OBMol m_mol;
OBRotorList m_rotorList;
RotorKeys m_rotorKeys;
bool m_printrotors;
OBConformerFilter *m_filter;
OBConformerScore *m_score;
std::ostream *m_logstream;
};
};
#endif
OpenBabel::OBBitVec
A speed-optimized vector of bits.
Definition bitvec.h:58
OpenBabel::OBConformerFilter
Interface used by OBConformerSearch for filtering conformers.
Definition conformersearch.h:56
OpenBabel::OBConformerFilter::IsGood
virtual bool IsGood(const OBMol &mol, const RotorKey &key, double *coords)=0
OpenBabel::OBConformerFilters::m_filters
std::vector< OBConformerFilter * > m_filters
Definition conformersearch.h:101
OpenBabel::OBConformerFilters::OBConformerFilters
OBConformerFilters(const std::vector< OBConformerFilter * > &filters)
Definition conformersearch.h:86
OpenBabel::OBConformerFilters::IsGood
bool IsGood(const OBMol &mol, const RotorKey &key, double *coords)
Definition conformersearch.h:93
OpenBabel::OBConformerScore
Interface used by OBConformerSearch for scoring conformers.
Definition conformersearch.h:145
OpenBabel::OBConformerScore::Convergence
Convergence
Definition conformersearch.h:158
OpenBabel::OBConformerScore::Highest
@ Highest
Definition conformersearch.h:158
OpenBabel::OBConformerScore::Sum
@ Sum
Definition conformersearch.h:158
OpenBabel::OBConformerScore::Lowest
@ Lowest
Definition conformersearch.h:158
OpenBabel::OBConformerScore::Average
@ Average
Definition conformersearch.h:158
OpenBabel::OBConformerScore::GetConvergence
virtual Convergence GetConvergence()=0
OpenBabel::OBConformerScore::Score
virtual double Score(OBMol &mol, unsigned int index, const RotorKeys &keys, const std::vector< double * > &conformers)=0
OpenBabel::OBConformerScore::GetPreferred
virtual Preferred GetPreferred()=0
OpenBabel::OBConformerScore::Preferred
Preferred
Definition conformersearch.h:150
OpenBabel::OBConformerScore::HighScore
@ HighScore
Definition conformersearch.h:150
OpenBabel::OBConformerScore::LowScore
@ LowScore
Definition conformersearch.h:150
OpenBabel::OBConformerSearch::SetFixedBonds
void SetFixedBonds(const OBBitVec &fixedBonds)
Definition conformersearch.h:308
OpenBabel::OBConformerSearch::SetConvergence
void SetConvergence(int convergence)
Definition conformersearch.h:304
OpenBabel::OBConformerSearch::SetNumChildren
void SetNumChildren(int numChildren)
Definition conformersearch.h:295
OpenBabel::OBConformerSearch::SetMutability
void SetMutability(int mutability)
Definition conformersearch.h:299
OpenBabel::OBConformerSearch::GetCrossoverProbability
double GetCrossoverProbability()
Definition conformersearch.h:390
OpenBabel::OBConformerSearch::OBConformerSearch
OBConformerSearch()
Definition conformersearch.cpp:296
OpenBabel::OBConformerSearch::PrintRotors
void PrintRotors(bool printrotors)
Definition conformersearch.h:342
OpenBabel::OBConformerSearch::GetNbNiches
int GetNbNiches()
Definition conformersearch.h:366
OpenBabel::OBConformerSearch::SetNbNiches
void SetNbNiches(int value)
Definition conformersearch.h:369
OpenBabel::OBConformerSearch::SetNicheMating
void SetNicheMating(double value)
Definition conformersearch.h:399
OpenBabel::OBConformerSearch::SetNumConformers
void SetNumConformers(int numConformers)
Definition conformersearch.h:291
OpenBabel::OBConformerSearch::SetSharing
void SetSharing(bool value=true)
Definition conformersearch.h:363
OpenBabel::OBConformerSearch::Setup
bool Setup(const OBMol &mol, int numConformers=30, int numChildren=5, int mutability=5, int convergence=25)
Definition conformersearch.cpp:332
OpenBabel::OBConformerSearch::SetFilter
void SetFilter(OBConformerFilter *filter)
Definition conformersearch.h:319
OpenBabel::OBConformerSearch::GetSigmaSharing
double GetSigmaSharing()
Definition conformersearch.h:384
OpenBabel::OBConformerSearch::SetSigmaSharing
void SetSigmaSharing(double value)
Definition conformersearch.h:387
OpenBabel::OBConformerSearch::SetScore
void SetScore(OBConformerScore *score)
Definition conformersearch.h:333
OpenBabel::OBConformerSearch::GetNicheRadius
double GetNicheRadius()
Definition conformersearch.h:372
OpenBabel::OBConformerSearch::SetLocalOptRate
void SetLocalOptRate(int value)
Definition conformersearch.h:402
OpenBabel::OBConformerSearch::SetLocalOptRate
int SetLocalOptRate()
Definition conformersearch.h:405
OpenBabel::OBConformerSearch::SetNicheRadius
void SetNicheRadius(double value)
Definition conformersearch.h:375
OpenBabel::OBConformerSearch::SetCrossoverProbability
void SetCrossoverProbability(double value)
Definition conformersearch.h:393
OpenBabel::OBConformerSearch::GetAlphaSharing
double GetAlphaSharing()
Definition conformersearch.h:378
OpenBabel::OBConformerSearch::GetRotorKeys
const RotorKeys & GetRotorKeys() const
Definition conformersearch.h:349
OpenBabel::OBConformerSearch::GetNicheMating
double GetNicheMating()
Definition conformersearch.h:396
OpenBabel::OBConformerSearch::SetLogStream
void SetLogStream(std::ostream *sptr)
Definition conformersearch.h:357
OpenBabel::OBConformerSearch::SetAlphaSharing
void SetAlphaSharing(double value)
Definition conformersearch.h:381
OpenBabel::OBEnergyConformerScore::OBEnergyConformerScore
OBEnergyConformerScore()
Definition conformersearch.h:196
OpenBabel::OBEnergyConformerScore::GetNbEnergyCompute
long unsigned int GetNbEnergyCompute()
Definition conformersearch.h:201
OpenBabel::OBEnergyConformerScore::GetConvergence
Convergence GetConvergence()
Definition conformersearch.h:204
OpenBabel::OBEnergyConformerScore::GetPreferred
Preferred GetPreferred()
Definition conformersearch.h:203
OpenBabel::OBEnergyConformerScore::GetNbEnergyRequest
long unsigned int GetNbEnergyRequest()
Definition conformersearch.h:202
OpenBabel::OBMinimizingEnergyConformerScore::GetNbEnergyCompute
long unsigned int GetNbEnergyCompute()
Definition conformersearch.h:226
OpenBabel::OBMinimizingEnergyConformerScore::OBMinimizingEnergyConformerScore
OBMinimizingEnergyConformerScore()
Definition conformersearch.h:221
OpenBabel::OBMinimizingEnergyConformerScore::GetConvergence
Convergence GetConvergence()
Definition conformersearch.h:229
OpenBabel::OBMinimizingEnergyConformerScore::GetPreferred
Preferred GetPreferred()
Definition conformersearch.h:228
OpenBabel::OBMinimizingEnergyConformerScore::GetNbEnergyRequest
long unsigned int GetNbEnergyRequest()
Definition conformersearch.h:227
OpenBabel::OBMinimizingRMSDConformerScore
An RMSD conformer scoring class, after a short minimization.
Definition conformersearch.h:248
OpenBabel::OBMinimizingRMSDConformerScore::GetConvergence
Convergence GetConvergence()
Definition conformersearch.h:251
OpenBabel::OBMinimizingRMSDConformerScore::GetPreferred
Preferred GetPreferred()
Definition conformersearch.h:250
OpenBabel::OBMol
Molecule Class.
Definition mol.h:121
OpenBabel::OBRMSDConformerScore
A RMSD conformer scoring class.
Definition conformersearch.h:180
OpenBabel::OBRMSDConformerScore::GetConvergence
Convergence GetConvergence()
Definition conformersearch.h:183
OpenBabel::OBRMSDConformerScore::GetPreferred
Preferred GetPreferred()
Definition conformersearch.h:182
OpenBabel::OBRotorList
Given an OBMol, set up a list of possibly rotatable torsions,.
Definition rotor.h:458
OpenBabel::OBStericConformerFilter::OBStericConformerFilter
OBStericConformerFilter()
Definition conformersearch.cpp:42
OpenBabel::OBStericConformerFilter::IsGood
bool IsGood(const OBMol &mol, const RotorKey &key, double *coords)
Definition conformersearch.cpp:58
mol.h
Handle molecules. Declarations of OBMol, OBAtom, OBBond, OBResidue. (the main header for Open Babel).
OpenBabel
Global namespace for all Open Babel code.
Definition alias.h:23
OpenBabel::RotorKey
std::vector< int > RotorKey
Definition conformersearch.h:30
OpenBabel::mapRotorEnergy
std::map< std::vector< int >, double > mapRotorEnergy
Definition conformersearch.h:32
OpenBabel::RotorKeys
std::vector< RotorKey > RotorKeys
Definition conformersearch.h:31
rotamer.h
Handle rotamer list data.
rotor.h
Rotate torsional according to rotor rules.