Loading...
Searching...
No Matches
rotor.h
Go to the documentation of this file.
/**********************************************************************
rotor.h - Rotate torsional according to rotor rules.
Copyright (C) 1998-2000 by OpenEye Scientific Software, Inc.
Some portions Copyright (C) 2001-2005 by Geoffrey R. Hutchison
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_ROTOR_H
#define OB_ROTOR_H
#include <openbabel/parsmart.h>
#include <openbabel/typer.h>
#include <openbabel/bitvec.h>
#ifdef UNUSED
#elif (__GNUC__ == 4)
# define UNUSED(x) UNUSED_ ## x __attribute__((unused))
#elif defined(__LCLINT__)
# define UNUSED(x) /*@unused@*/ x
#else
# define UNUSED(x) x
#endif
namespace OpenBabel
{
class OBRing;
#ifndef SQUARE
#define SQUARE(x) ((x)*(x))
#endif
class OBAPI OBRotorRule
{
int _ref[4];
double _delta;
std::string _s;
OBSmartsPattern* _sp;
std::vector<double> _vals;
public:
OBRotorRule(char *buffer,int ref[4],std::vector<double> &vals,double d):
_delta(d), _s(buffer), _vals(vals)
{
_sp = new OBSmartsPattern;
_sp->Init(buffer);
memcpy(_ref,ref,sizeof(int)*4);
}
~OBRotorRule()
{
if (_sp)
{
delete _sp;
_sp = nullptr;
}
}
bool IsValid() { return(_sp->IsValid()); }
void GetReferenceAtoms(int ref[4]) { memcpy(ref,_ref,sizeof(int)*4); }
void SetDelta(double d) { _delta = d; }
double GetDelta() { return(_delta); }
std::vector<double> &GetTorsionVals() { return(_vals); }
std::string &GetSmartsString(){ return(_s); }
OBSmartsPattern *GetSmartsPattern() { return(_sp); }
};
class OBAPI OBRotorRules : public OBGlobalDataBase
{
bool _quiet;
std::vector<OBRotorRule*> _vr;
std::vector<double> _sp3sp3;
std::vector<double> _sp3sp2;
std::vector<double> _sp2sp2;
public:
OBRotorRules();
~OBRotorRules();
void ParseLine(const char*);
size_t GetSize() { return _vr.size();}
void SetFilename(std::string &s) { _filename = s; }
void GetRotorIncrements(OBMol& mol,OBBond* bond,int refs[4],
std::vector<double> &vals,double &delta);
void Quiet() { _quiet=true; }
};
class OBAPI OBRotor
{
int _idx;
std::vector<int> _rotatoms;
double _imag, _refang;
OBBond *_bond;
std::vector<int> _ref, _torsion;
OBBitVec _fixedatoms,_fixedbonds, _evalatoms;
std::vector<double> _torsionAngles;
std::vector<double> _invmag;
std::vector<std::vector<double> > _sn,_cs,_t;
std::vector<OBRing *> _rings;
public:
OBRotor();
~OBRotor()
{
}
void SetBond(OBBond *bond)
{
_bond = bond;
SetRings();
}
void SetRings();
void SetIdx(int idx)
{
_idx = idx;
}
void SetDihedralAtoms(std::vector<int> &ref);
void SetDihedralAtoms(int ref[4]);
void SetRotAtoms(std::vector<int> &atoms);
void SetTorsionValues(std::vector<double> &angles)
{
_torsionAngles = angles;
}
void SetFixedBonds(OBBitVec &bv)
{
_fixedbonds = bv;
}
inline void SetToAngle(double *coordinates, double setang)
{
double /*dx,dy,dz,*/ sn,cs,t,ang,mag;
// compute the angle to rotate (radians)
ang = setang - CalcTorsion(coordinates);
// if the angle to rotate is too small, we're done
if (fabs(ang) < 1e-5)
return;
// compute the bond length
mag = CalcBondLength(coordinates);
// compute some rotation matrix elements
sn = sin(ang);
cs = cos(ang);
t = 1 - cs;
// perform rotation
Set(coordinates, sn, cs, t, 1.0 / mag);
}
void SetRotor(double *coordinates, int next, int prev = -1);
void Set(double *coordinates, double sine, double cosine, double translation, double invmag);
void Precompute(double *coordinates);
void Set(double *coordinates, int idx);
void Precalc(std::vector<double*> &conformers);
void Set(double *coordinates, int conformer, int idx)
{
Set(coordinates, _sn[conformer][idx], _cs[conformer][idx], _t[conformer][idx], _invmag[conformer]);
}
OBBond *GetBond()
{
return(_bond);
}
size_t Size()
{
return _torsionAngles.size();
}
int GetIdx() const
{
return _idx;
}
void GetDihedralAtoms(int ref[4])
{
for (int i = 0; i < 4; ++i)
ref[i] = _ref[i];
}
std::vector<int> &GetDihedralAtoms()
{
return _ref;
}
const std::vector<int>& GetRotAtoms() const
{
return _rotatoms;
}
const std::vector<double> &GetTorsionValues() const
{
return _torsionAngles;
}
OBBitVec &GetFixedBonds()
{
return _fixedbonds;
}
double CalcTorsion(double *coordinates);
double CalcBondLength(double *coordinates);
std::vector<double>::iterator BeginTorIncrement()
{
return _torsionAngles.begin();
}
std::vector<double>::iterator EndTorIncrement()
{
return _torsionAngles.end();
}
void RemoveSymTorsionValues(int);
void SetDelta(double UNUSED(d)) {}
double GetDelta() { return 10.0; }
OBBitVec &GetFixedAtoms() { return _fixedatoms; }
void SetFixedAtoms(OBBitVec &bv) { _fixedatoms = bv; }
OBBitVec &GetEvalAtoms() { return _evalatoms; }
void SetEvalAtoms(OBBitVec &bv) { _evalatoms = bv; }
void* GetRotAtoms() { return &_rotatoms; }
std::vector<double> &GetResolution() { return _torsionAngles; }
void SetNumCoords(int UNUSED(nc)) {}
};
typedef std::vector<OBRotor*>::iterator OBRotorIterator;
class OBAPI OBRotorList
{
bool _quiet;
bool _removesym;
bool _ringRotors;
OBBitVec _fixedatoms, _fixedbonds;
OBRotorRules _rr;
std::vector<int> _dffv;
std::vector<OBRotor*> _rotor;
std::vector<std::pair<OBSmartsPattern*,std::pair<int,int> > > _vsym2;
std::vector<std::pair<OBSmartsPattern*,std::pair<int,int> > > _vsym3;
public:
OBRotorList();
~OBRotorList();
void Clear();
size_t Size()
{
return _rotor.size();
}
bool IsFixedBond(OBBond*);
bool HasFixedBonds()
{
return !_fixedbonds.IsEmpty();
}
void RemoveSymVals(OBMol&);
bool HasRingRotors()
{ return _ringRotors; }
bool Setup(OBMol &mol, bool sampleRings = false);
void SetFixedBonds(OBBitVec &fix)
{
_fixedbonds = fix;
_fixedatoms.Clear();
}
void Init(std::string &fname)
{
_rr.SetFilename(fname);
_rr.Init();
}
void SetQuiet() {
_quiet=true;
_rr.Quiet();
}
bool SetRotAtoms(OBMol&);
bool FindRotors(OBMol &mol, bool sampleRingBonds = false);
bool SetEvalAtoms(OBMol&);
bool AssignTorVals(OBMol &);
OBRotor *BeginRotor(OBRotorIterator &i)
{
i = _rotor.begin();
return((i ==_rotor.end()) ? nullptr:*i);
}
OBRotor *NextRotor(OBRotorIterator &i)
{
++i;
return((i ==_rotor.end()) ? nullptr:*i);
}
OBRotorIterator BeginRotors() { return(_rotor.begin()); }
OBRotorIterator EndRotors() { return(_rotor.end()); }
// Not declared
bool IdentifyEvalAtoms(OBMol &mol) { return SetEvalAtoms(mol); }
void SetFixAtoms(OBBitVec &fix)
{
_fixedatoms = fix;
_fixedbonds.Clear();
}
bool HasFixedAtoms()
{
return(!_fixedatoms.IsEmpty());
}
void IgnoreSymmetryRemoval() { _removesym = false;}
void SetRotAtomsByFix(OBMol&);
};
class rotor_digit {
public:
rotor_digit(unsigned int rs)
{
resolution_size = rs;
state = 0;
}
rotor_digit()
{
resolution_size = 0;
state = 0;
}
void set_size(unsigned int rs)
{
resolution_size = rs;
state = 0;
}
void set_state(int st)
{
state = st;
}
int get_state()
{
return state;
}
unsigned int size()
{
return resolution_size;
}
bool next()
{
if (state < static_cast<int>(resolution_size - 1)) {
++state;
return false;
} else
state = 0;
return true;
}
private:
unsigned int resolution_size;
int state;
#ifndef SWIG
} typedef rotor_digit;
#else
};
#endif
class OBAPI OBRotorKeys
{
public:
OBRotorKeys()
{
_vr.clear();
}
void Clear(){
_vr.clear();
}
unsigned int NumKeys()
{
unsigned int numKeys = 0;
while (Next())
numKeys++;
return numKeys;
}
void AddRotor(unsigned int size)
{
rotor_digit rd(size);
_vr.push_back(rd);
}
bool Next()
{
if(_vr.size() == 0)
return false;
bool carry = _vr[0].next();
unsigned int i = 1;
while (carry) {
if(i == _vr.size())
return false;
carry = _vr[i].next();
i++;
}
return true;
}
std::vector<int> GetKey()
{
std::vector<int> rt;
rt.clear();
rt.push_back(0);
for(unsigned int i = 0; i < _vr.size(); i++){
rt.push_back(_vr[i].get_state());
}
return rt;
}
private:
std::vector<rotor_digit> _vr;
};
} // end namespace OpenBabel
#endif // OB_ROTOR_H
bitvec.h
Fast and efficient bitstring class.
OpenBabel::OBBitVec
A speed-optimized vector of bits.
Definition bitvec.h:58
OpenBabel::OBBitVec::Clear
void Clear()
Set all bits to zero.
Definition bitvec.cpp:381
OpenBabel::OBBond
Bond class.
Definition bond.h:59
OpenBabel::OBGlobalDataBase::OBGlobalDataBase
OBGlobalDataBase()
Constructor.
Definition data.h:60
OpenBabel::OBGlobalDataBase::_filename
std::string _filename
File to search for.
Definition data.h:53
OpenBabel::OBMol
Molecule Class.
Definition mol.h:121
OpenBabel::OBRing
Stores information on rings in a molecule from SSSR perception.
Definition ring.h:41
OpenBabel::OBRotorKeys::OBRotorKeys
OBRotorKeys()
A class to generate all possible rotorKeys.
Definition rotor.h:752
OpenBabel::OBRotorKeys::Next
bool Next()
Definition rotor.h:783
OpenBabel::OBRotorKeys::NumKeys
unsigned int NumKeys()
Number of rotor keys (= number of possible conformers).
Definition rotor.h:763
OpenBabel::OBRotorKeys::AddRotor
void AddRotor(unsigned int size)
Definition rotor.h:775
OpenBabel::OBRotorKeys::Clear
void Clear()
Clear all rotors.
Definition rotor.h:758
OpenBabel::OBRotorKeys::GetKey
std::vector< int > GetKey()
Definition rotor.h:802
OpenBabel::OBRotorList::NextRotor
OBRotor * NextRotor(OBRotorIterator &i)
Definition rotor.h:597
OpenBabel::OBRotorList::BeginRotor
OBRotor * BeginRotor(OBRotorIterator &i)
Definition rotor.h:588
OpenBabel::OBRotorList::SetQuiet
void SetQuiet()
Definition rotor.h:545
OpenBabel::OBRotorList::SetEvalAtoms
bool SetEvalAtoms(OBMol &)
Definition rotor.cpp:290
OpenBabel::OBRotorList::Size
size_t Size()
Definition rotor.h:487
OpenBabel::OBRotorList::BeginRotors
OBRotorIterator BeginRotors()
Definition rotor.h:605
OpenBabel::OBRotorList::HasFixedBonds
bool HasFixedBonds()
Definition rotor.h:501
OpenBabel::OBRotorList::Clear
void Clear()
Definition rotor.cpp:472
OpenBabel::OBRotorList::HasRingRotors
bool HasRingRotors()
Definition rotor.h:514
OpenBabel::OBRotorList::SetFixAtoms
void SetFixAtoms(OBBitVec &fix)
Definition rotor.h:621
OpenBabel::OBRotorList::EndRotors
OBRotorIterator EndRotors()
Definition rotor.h:609
OpenBabel::OBRotorList::OBRotorList
OBRotorList()
Definition rotor.cpp:457
OpenBabel::OBRotorList::HasFixedAtoms
bool HasFixedAtoms()
Definition rotor.h:630
OpenBabel::OBRotorList::IgnoreSymmetryRemoval
void IgnoreSymmetryRemoval()
Definition rotor.h:636
OpenBabel::OBRotorList::Init
void Init(std::string &fname)
Definition rotor.h:537
OpenBabel::OBRotorList::SetFixedBonds
void SetFixedBonds(OBBitVec &fix)
Definition rotor.h:529
OpenBabel::OBRotorList::IdentifyEvalAtoms
bool IdentifyEvalAtoms(OBMol &mol)
Definition rotor.h:616
OpenBabel::OBRotorRule::~OBRotorRule
~OBRotorRule()
Definition rotor.h:68
OpenBabel::OBRotorRule::GetSmartsPattern
OBSmartsPattern * GetSmartsPattern()
Definition rotor.h:92
OpenBabel::OBRotorRule::GetSmartsString
std::string & GetSmartsString()
Definition rotor.h:90
OpenBabel::OBRotorRule::GetReferenceAtoms
void GetReferenceAtoms(int ref[4])
Definition rotor.h:82
OpenBabel::OBRotorRule::SetDelta
void SetDelta(double d)
Set the resolution (delta) of a torsional step in degrees.
Definition rotor.h:84
OpenBabel::OBRotorRule::IsValid
bool IsValid()
Definition rotor.h:78
OpenBabel::OBRotorRule::GetTorsionVals
std::vector< double > & GetTorsionVals()
Definition rotor.h:88
OpenBabel::OBRotorRule::GetDelta
double GetDelta()
Definition rotor.h:86
OpenBabel::OBRotorRule::OBRotorRule
OBRotorRule(char *buffer, int ref[4], std::vector< double > &vals, double d)
Definition rotor.h:60
OpenBabel::OBRotorRules
Database of default hybridization torsional rules and SMARTS-defined OBRotorRule objects.
Definition rotor.h:102
OpenBabel::OBRotorRules::OBRotorRules
OBRotorRules()
Definition rotor.cpp:801
OpenBabel::OBRotorRules::Quiet
void Quiet()
Turn off debugging output from GetRotorIncrements().
Definition rotor.h:128
OpenBabel::OBRotorRules::GetSize
size_t GetSize()
Definition rotor.h:114
OpenBabel::OBRotorRules::SetFilename
void SetFilename(std::string &s)
Set the filename to be used for the database. Default = torlib.txt.
Definition rotor.h:117
OpenBabel::OBRotorRules::ParseLine
void ParseLine(const char *)
Specified by particular table classes (parses an individual data line).
Definition rotor.cpp:812
OpenBabel::OBRotor
A single rotatable OBBond as part of rotamer searching.
Definition rotor.h:136
OpenBabel::OBRotor::SetToAngle
void SetToAngle(double *coordinates, double setang)
Definition rotor.h:220
OpenBabel::OBRotor::SetTorsionValues
void SetTorsionValues(std::vector< double > &angles)
Definition rotor.h:200
OpenBabel::OBRotor::GetIdx
int GetIdx() const
Definition rotor.h:355
OpenBabel::OBRotor::Set
void Set(double *coordinates, int conformer, int idx)
Definition rotor.h:328
OpenBabel::OBRotor::CalcBondLength
double CalcBondLength(double *coordinates)
Definition rotor.cpp:566
OpenBabel::OBRotor::GetEvalAtoms
OBBitVec & GetEvalAtoms()
Definition rotor.h:436
OpenBabel::OBRotor::SetEvalAtoms
void SetEvalAtoms(OBBitVec &bv)
Definition rotor.h:438
OpenBabel::OBRotor::GetFixedBonds
OBBitVec & GetFixedBonds()
Definition rotor.h:393
OpenBabel::OBRotor::GetDihedralAtoms
void GetDihedralAtoms(int ref[4])
Definition rotor.h:362
OpenBabel::OBRotor::GetRotAtoms
const std::vector< int > & GetRotAtoms() const
Definition rotor.h:378
OpenBabel::OBRotor::SetNumCoords
void SetNumCoords(int nc)
Definition rotor.h:444
OpenBabel::OBRotor::SetFixedAtoms
void SetFixedAtoms(OBBitVec &bv)
Definition rotor.h:434
OpenBabel::OBRotor::GetRotAtoms
void * GetRotAtoms()
Definition rotor.h:440
OpenBabel::OBRotor::GetDihedralAtoms
std::vector< int > & GetDihedralAtoms()
Definition rotor.h:370
OpenBabel::OBRotor::OBRotor
OBRotor()
Definition rotor.cpp:492
OpenBabel::OBRotor::GetResolution
std::vector< double > & GetResolution()
Definition rotor.h:442
OpenBabel::OBRotor::~OBRotor
~OBRotor()
Definition rotor.h:155
OpenBabel::OBRotor::GetBond
OBBond * GetBond()
Definition rotor.h:340
OpenBabel::OBRotor::SetBond
void SetBond(OBBond *bond)
Definition rotor.h:164
OpenBabel::OBRotor::Size
size_t Size()
Definition rotor.h:348
OpenBabel::OBRotor::SetDelta
void SetDelta(double d)
Definition rotor.h:428
OpenBabel::OBRotor::GetFixedAtoms
OBBitVec & GetFixedAtoms()
Definition rotor.h:432
OpenBabel::OBRotor::SetRings
void SetRings()
Definition rotor.cpp:496
OpenBabel::OBRotor::SetFixedBonds
void SetFixedBonds(OBBitVec &bv)
Definition rotor.h:207
OpenBabel::OBRotor::SetIdx
void SetIdx(int idx)
Definition rotor.h:177
OpenBabel::OBRotor::GetDelta
double GetDelta()
Definition rotor.h:430
OpenBabel::OBRotor::CalcTorsion
double CalcTorsion(double *coordinates)
Definition rotor.cpp:517
OpenBabel::OBRotor::BeginTorIncrement
std::vector< double >::iterator BeginTorIncrement()
Definition rotor.h:413
OpenBabel::OBRotor::GetTorsionValues
const std::vector< double > & GetTorsionValues() const
Definition rotor.h:385
OpenBabel::OBRotor::EndTorIncrement
std::vector< double >::iterator EndTorIncrement()
Definition rotor.h:417
OpenBabel::OBRotor::Set
void Set(double *coordinates, double sine, double cosine, double translation, double invmag)
Definition rotor.cpp:696
OpenBabel::OBSmartsPattern
SMARTS (SMiles ARbitrary Target Specification) substructure searching.
Definition parsmart.h:155
OpenBabel::OBSmartsPattern::Init
bool Init(const char *pattern)
Definition parsmart.cpp:1710
OpenBabel
Global namespace for all Open Babel code.
Definition alias.h:23
OpenBabel::OBRotorIterator
std::vector< OBRotor * >::iterator OBRotorIterator
A standard iterator over a vector of rotors.
Definition rotor.h:451
parsmart.h
Daylight SMARTS parser.
typer.h
Open Babel atom and aromaticity typer.