19 #ifndef OB_FORCEFIELD_H 20 #define OB_FORCEFIELD_H 25 #include <openbabel/babelconfig.h> 37 #define OBFF_LOGLVL_NONE 0 38 #define OBFF_LOGLVL_LOW 1 39 #define OBFF_LOGLVL_MEDIUM 2 40 #define OBFF_LOGLVL_HIGH 3 43 #define OBFF_ENERGY (1 << 0) 44 #define OBFF_EBOND (1 << 1) 45 #define OBFF_EANGLE (1 << 2) 46 #define OBFF_ESTRBND (1 << 3) 47 #define OBFF_ETORSION (1 << 4) 48 #define OBFF_EOOP (1 << 5) 49 #define OBFF_EVDW (1 << 6) 50 #define OBFF_EELECTROSTATIC (1 << 7) 53 #define OBFF_CONST_IGNORE (1 << 0) 54 #define OBFF_CONST_ATOM (1 << 1) 55 #define OBFF_CONST_ATOM_X (1 << 2) 56 #define OBFF_CONST_ATOM_Y (1 << 3) 57 #define OBFF_CONST_ATOM_Z (1 << 4) 58 #define OBFF_CONST_DISTANCE (1 << 5) 59 #define OBFF_CONST_ANGLE (1 << 6) 60 #define OBFF_CONST_TORSION (1 << 7) 61 #define OBFF_CONST_CHIRAL (1 << 8) 64 #define OBFF_NUMERICAL_GRADIENT (1 << 0) 65 #define OBFF_ANALYTICAL_GRADIENT (1 << 1) 71 #define IF_OBFF_LOGLVL_LOW if(_loglvl >= OBFF_LOGLVL_LOW) 72 #define IF_OBFF_LOGLVL_MEDIUM if(_loglvl >= OBFF_LOGLVL_MEDIUM) 73 #define IF_OBFF_LOGLVL_HIGH if(_loglvl >= OBFF_LOGLVL_HIGH) 98 std::string _a, _b, _c,
_d;
149 double force_a[3], force_b[3];
158 if (!a || !b)
return;
187 if (!a || !b || !c)
return;
188 pos_a = a->GetCoordinate();
190 pos_b = b->GetCoordinate();
218 if (!a || !b || !c || !d)
return;
219 pos_a = a->GetCoordinate();
221 pos_b = b->GetCoordinate();
223 pos_c = c->GetCoordinate();
249 a = b = c = d = NULL;
250 ia = ib = ic =
id = 0;
251 constraint_value = 0.0;
285 _constraints.clear();
295 double GetConstraintEnergy();
302 _constraints = ai._constraints;
303 _ignored = ai._ignored;
305 _Xfixed = ai._Xfixed;
306 _Yfixed = ai._Yfixed;
307 _Zfixed = ai._Zfixed;
315 void Setup(
OBMol &mol);
322 void SetFactor(
double factor);
325 void AddIgnore(
int a);
327 void AddAtomConstraint(
int a);
329 void AddAtomXConstraint(
int a);
331 void AddAtomYConstraint(
int a);
333 void AddAtomZConstraint(
int a);
335 void AddDistanceConstraint(
int a,
int b,
double length);
337 void AddAngleConstraint(
int a,
int b,
int c,
double angle);
339 void AddTorsionConstraint(
int a,
int b,
int c,
int d,
double torsion);
342 void DeleteConstraint(
int index);
362 int GetConstraintType(
int index)
const;
366 double GetConstraintValue(
int index)
const;
369 int GetConstraintAtomA(
int index)
const;
372 int GetConstraintAtomB(
int index)
const;
375 int GetConstraintAtomC(
int index)
const;
378 int GetConstraintAtomD(
int index)
const;
381 bool IsIgnored(
int a);
387 bool IsXFixed(
int a);
390 bool IsYFixed(
int a);
393 bool IsZFixed(
int a);
404 std::vector<OBFFConstraint> _constraints;
462 OBFFParameter* GetParameter(
int a,
int b,
int c,
int d, std::vector<OBFFParameter> ¶meter);
464 OBFFParameter* GetParameter(
const char* a,
const char* b,
const char* c,
const char* d,
465 std::vector<OBFFParameter> ¶meter);
467 int GetParameterIdx(
int a,
int b,
int c,
int d, std::vector<OBFFParameter> ¶meter);
489 const int coordIdx = (idx - 1) * 3;
490 for (
unsigned int i = 0; i < 3; ++i) {
491 _gradientPtr[coordIdx + i] = grad[i];
499 const int coordIdx = (idx - 1) * 3;
500 for (
unsigned int i = 0; i < 3; ++i) {
501 _gradientPtr[coordIdx + i] += grad[i];
512 for (
unsigned int i = 0; i < _ncoords; ++i)
513 _gradientPtr[i] = 0.0;
576 if (_grad1 != NULL) {
580 if (_gradientPtr != NULL) {
581 delete [] _gradientPtr;
589 return "forcefields";
597 return FindType(ID.c_str());
616 virtual std::string
GetUnit() {
return std::string(
"au"); }
628 bool Setup(
OBMol &mol);
671 bool IsSetupNeeded(
OBMol &mol);
687 bool GetAtomTypes(
OBMol &mol);
703 bool GetPartialCharges(
OBMol &mol);
711 bool GetCoordinates(
OBMol &mol);
718 bool GetConformers(
OBMol &mol);
725 bool SetCoordinates(
OBMol &mol);
730 bool SetConformers(
OBMol &mol);
740 OBGridData *GetGrid(
double step,
double padding,
const char *type,
double pchg);
752 void AddIntraGroup(
OBBitVec &group);
757 void AddInterGroup(
OBBitVec &group);
856 void UpdatePairsSimple();
863 unsigned int GetNumPairs();
867 unsigned int GetNumElectrostaticPairs();
871 unsigned int GetNumVDWPairs();
887 const int coordIdx = (a->
GetIdx() - 1) * 3;
888 return _gradientPtr + coordIdx;
913 virtual double Energy(
bool UNUSED(gradients) =
true) {
return 0.0f; }
920 virtual double E_Bond(
bool UNUSED(gradients) =
true) {
return 0.0f; }
927 virtual double E_Angle(
bool UNUSED(gradients) =
true) {
return 0.0f; }
934 virtual double E_StrBnd(
bool UNUSED(gradients) =
true) {
return 0.0f; }
941 virtual double E_Torsion(
bool UNUSED(gradients) =
true) {
return 0.0f; }
948 virtual double E_OOP(
bool UNUSED(gradients) =
true) {
return 0.0f; }
955 virtual double E_VDW(
bool UNUSED(gradients) =
true) {
return 0.0f; }
977 void PrintFormalCharges();
980 void PrintPartialCharges();
983 void PrintVelocities();
988 bool SetLogFile(std::ostream *pos);
1013 bool SetLogLevel(
int level);
1045 void DistanceGeometry();
1068 void SystematicRotorSearch(
unsigned int geomSteps = 2500,
bool sampleRingBonds =
false);
1087 int SystematicRotorSearchInitialize(
unsigned int geomSteps = 2500,
bool sampleRingBonds =
false);
1092 bool SystematicRotorSearchNextConformer(
unsigned int geomSteps = 2500);
1114 void RandomRotorSearch(
unsigned int conformers,
unsigned int geomSteps = 2500,
1115 bool sampleRingBonds =
false);
1134 void RandomRotorSearchInitialize(
unsigned int conformers,
unsigned int geomSteps = 2500,
1135 bool sampleRingBonds =
false);
1140 bool RandomRotorSearchNextConformer(
unsigned int geomSteps = 2500);
1163 void WeightedRotorSearch(
unsigned int conformers,
unsigned int geomSteps,
1164 bool sampleRingBonds =
false);
1189 int FastRotorSearch(
bool permute =
true);
1192 int DiverseConfGen(
double rmsd,
unsigned int nconfs = 0,
double energy_gap = 50,
bool verbose =
false);
1233 double LineSearch(
double *currentCoords,
double *direction);
1246 double Newton2NumLineSearch(
double *direction);
1252 void LineSearchTakeStep(
double *origCoords,
double *direction,
double step);
1310 bool SteepestDescentTakeNSteps(
int n);
1370 bool ConjugateGradientsTakeNSteps(
int n);
1381 void GenerateVelocities();
1401 void CorrectVelocities();
1441 void SetFixAtom(
int index);
1445 void UnsetFixAtom();
1454 void SetIgnoreAtom(
int index);
1458 void UnsetIgnoreAtom();
1461 static bool IgnoreCalculation(
int a,
int b);
1463 static bool IgnoreCalculation(
int a,
int b,
int c);
1465 static bool IgnoreCalculation(
int a,
int b,
int c,
int d);
1475 bool DetectExplosion();
1480 void ValidateSteepestDescent(
int steps);
1482 void ValidateConjugateGradients(
int steps);
1511 static double VectorBondDerivative(
double *pos_a,
double *pos_b,
1512 double *force_a,
double *force_b);
1516 static double VectorDistanceDerivative(
const double*
const pos_i,
const double*
const pos_j,
1517 double *force_i,
double *force_j);
1531 static double VectorAngleDerivative(
double *pos_a,
double *pos_b,
double *pos_c,
1532 double *force_a,
double *force_b,
double *force_c);
1547 static double VectorOOPDerivative(
double *pos_a,
double *pos_b,
double *pos_c,
double *pos_d,
1548 double *force_a,
double *force_b,
double *force_c,
double *force_d);
1562 static double VectorTorsionDerivative(
double *pos_a,
double *pos_b,
double *pos_c,
double *pos_d,
1563 double *force_a,
double *force_b,
double *force_c,
double *force_d);
1574 for (
unsigned int c = 0; c < 3; ++c)
1575 result[c] = i[c] - j[c];
1578 static void VectorSubtract(
const double*
const i,
const double*
const j,
double *result)
1580 for (
unsigned int c = 0; c < 3; ++c)
1581 result[c] = i[c] - j[c];
1591 for (
unsigned int c = 0; c < 3; ++c)
1592 result[c] = i[c] + j[c];
1602 for (
unsigned int c = 0; c < 3; ++c)
1603 result[c] = i[c] / n;
1613 for (
unsigned int c = 0; c < 3; ++c)
1614 result[c] = i[c] * n;
1619 for (
unsigned int c = 0; c < 3; ++c)
1620 result[c] = i[c] * n;
1629 for (
unsigned int c = 0; c < 3; ++c)
1638 double length = VectorLength(i);
1639 for (
unsigned int c = 0; c < 3; ++c)
1649 for (
unsigned int c = 0; c < 3; ++c)
1659 return sqrt( i[0]*i[0] + i[1]*i[1] + i[2]*i[2] );
1665 VectorSubtract(pos_i, pos_j, ij);
1666 const double rij = VectorLength(ij);
1676 static double VectorAngle(
double *i,
double *j,
double *k);
1685 static double VectorTorsion(
double *i,
double *j,
double *k,
double *l);
1694 static double VectorOOP(
double *i,
double *j,
double *k,
double *l);
1701 for (
unsigned int c = 0; c < 3; ++c)
1712 double result = 0.0;
1715 for (
unsigned int c = 0; c < 3; ++c)
1716 result += i[c]*j[c];
1727 result[0] = i[1]*j[2] - i[2]*j[1];
1728 result[1] = - i[0]*j[2] + i[2]*j[0];
1729 result[2] = i[0]*j[1] - i[1]*j[0];
1734 std::cout <<
"<" << i[0] <<
", " << i[1] <<
", " << i[2] <<
">" << std::endl;
1742 #endif // OB_FORCEFIELD_H const vector3 VZero
The zero vector: <0.0, 0.0, 0.0>
virtual double E_Electrostatic(bool gradients=true)
Definition: forcefield.h:962
void clear()
Reset the atom types and set all parameters to zero.
Definition: forcefield.h:125
virtual ~OBFFCalculation4()
Destructor.
Definition: forcefield.h:211
OBMol _mol
Molecule to be evaluated or minimized.
Definition: forcefield.h:527
virtual double E_OOP(bool gradients=true)
Definition: forcefield.h:948
Internal class for OBForceField to hold forcefield parameters.
Definition: forcefield.h:93
vector3 gradd
Definition: forcefield.h:244
double GetDielectricConstant()
Definition: forcefield.h:832
Definition: residue.h:336
virtual ~OBFFCalculation3()
Destructor.
Definition: forcefield.h:180
void AddGradient(double *grad, int idx)
Definition: forcefield.h:497
void SetUpdateFrequency(int f)
Definition: forcefield.h:841
static void VectorDivide(double *i, double n, double *result)
Definition: forcefield.h:1600
virtual bool ValidateGradients()
Definition: forcefield.h:1489
int _loglvl
Log level for output.
Definition: forcefield.h:535
static double VectorDistance(double *pos_i, double *pos_j)
Definition: forcefield.h:1662
static OBForceField * FindForceField(const std::string &ID)
Definition: forcefield.h:595
double _timestep
Molecular dynamics time step in picoseconds.
Definition: forcefield.h:547
double _gconv
Definition: forcefield.h:541
double _epsilon
Dielectric constant for electrostatics.
Definition: forcefield.h:558
void SetParameterFile(const std::string &filename)
Definition: forcefield.h:609
virtual vector3 GetGradient(OBAtom *a, int=OBFF_ENERGY)
Definition: forcefield.h:885
Internal class for OBForceField to hold energy and gradient calculations on specific force fields...
Definition: forcefield.h:199
int _linesearch
LineSearch type.
Definition: forcefield.h:545
const double GAS_CONSTANT
kcal mol^-1 K^-1 (2018 CODATA recommended value)
Definition: forcefield.h:68
OBBitVec GetFixedBitVec()
Definition: forcefield.h:400
double * _grad1
Used for conjugate gradients and steepest descent(Initialize and TakeNSteps)
Definition: forcefield.h:543
void SetLineSearchType(int type)
Definition: forcefield.h:1205
int idx_b
Definition: forcefield.h:145
OBBitVec GetIgnoredBitVec()
Definition: forcefield.h:397
Base class for all types of dynamic classes discovered at runtime.
Definition: plugin.h:52
static void VectorSubtract(double *i, double *j, double *result)
Definition: forcefield.h:1572
virtual void SetupPointers()
Definition: forcefield.h:185
static unsigned int _fixAtom
SetFixAtom()/UnsetFixAtom()
Definition: forcefield.h:552
std::vector< OBBitVec > _interGroup
groups for which intra-molecular interactions should be calculated
Definition: forcefield.h:564
virtual double E_Bond(bool gradients=true)
Definition: forcefield.h:920
const char * TypeID()
Definition: forcefield.h:587
double * _gradientPtr
pointer to the gradients (used by AddGradient(), minimization functions, ...)
Definition: forcefield.h:531
OBFFParameter & operator=(const OBFFParameter &ai)
Assignment.
Definition: forcefield.h:106
bool IsCutOffEnabled()
Definition: forcefield.h:789
std::string _a
used to store string atom types
Definition: forcefield.h:98
static unsigned int _ignoreAtom
SetIgnoreAtom()/UnsetIgnoreAtom()
Definition: forcefield.h:553
double * GetCoordinate()
Definition: atom.h:242
std::string _d
Definition: forcefield.h:98
static void VectorSubtract(const double *const i, const double *const j, double *result)
Definition: forcefield.h:1578
void SetDielectricConstant(double epsilon)
Definition: forcefield.h:825
Molecule Class.
Definition: mol.h:118
static void VectorMultiply(double *i, double n, double *result)
Definition: forcefield.h:1611
OBAtom * c
Used to store the atoms for this OBFFCalculation.
Definition: forcefield.h:172
static double VectorLength(double *i)
Definition: forcefield.h:1657
OBAtom * d
Used to store the atoms for this OBFFCalculation.
Definition: forcefield.h:203
virtual bool SetTypes()
Definition: forcefield.h:644
void EnableCutOff(bool enable)
Definition: forcefield.h:783
void SetElectrostaticCutOff(double r)
Definition: forcefield.h:811
void SetVDWCutOff(double r)
Definition: forcefield.h:796
double rbc0
Definition: forcefield.h:238
std::vector< std::pair< OBBitVec, OBBitVec > > _interGroups
Definition: forcefield.h:565
The type of line search to be used for optimization – simple or Newton numeric.
Definition: forcefield.h:76
virtual bool HasAnalyticalGradients()
Definition: forcefield.h:623
int _origLogLevel
Definition: forcefield.h:536
virtual bool SetupPointers()
Definition: forcefield.h:665
virtual double E_VDW(bool gradients=true)
Definition: forcefield.h:955
const double KCAL_TO_KJ
Definition: forcefield.h:67
Handle molecules. Declarations of OBMol, OBAtom, OBBond, OBResidue. (the main header for Open Babel) ...
virtual double Energy(bool gradients=true)
Definition: forcefield.h:913
double GetElectrostaticCutOff()
Definition: forcefield.h:818
Internal class for OBForceField to hold energy and gradient calculations on specific force fields...
Definition: forcefield.h:137
virtual bool SetPartialCharges()
Definition: forcefield.h:654
void EnableAllPairs()
Definition: forcefield.h:875
A speed-optimized vector of bits.
Definition: bitvec.h:57
int GetLogLevel()
Definition: forcefield.h:1016
int GetUpdateFrequency()
Definition: forcefield.h:848
bool _cutoff
true = cut-off enabled
Definition: forcefield.h:555
virtual double E_Angle(bool gradients=true)
Definition: forcefield.h:927
OBAtom * d
Definition: forcefield.h:242
double * pos_d
Pointer to atom coordinates as double[3].
Definition: forcefield.h:207
static void VectorAdd(double *i, double *j, double *result)
Definition: forcefield.h:1589
static void VectorNormalize(double *i)
Definition: forcefield.h:1636
Internal class for OBForceField to handle constraints.
Definition: forcefield.h:277
double energy
Used to store the energy for this OBFFCalculation.
Definition: forcefield.h:141
~OBFFConstraints()
Destructor.
Definition: forcefield.h:283
Definition: forcefield.h:79
double _rvdw
VDW cut-off distance.
Definition: forcefield.h:556
int idx_c
Used to store the index of atoms for this OBFFCalculation.
Definition: forcefield.h:174
std::ostream * _logos
Output for logfile.
Definition: forcefield.h:533
int _pairfreq
The frequence to update non-bonded pairs.
Definition: forcefield.h:561
double * GetGradientPtr()
Definition: forcefield.h:893
static void PrintVector(double *i)
Definition: forcefield.h:1732
double * pos_c
Pointer to atom coordinates as double[3].
Definition: forcefield.h:176
static void VectorClear(double *i)
Definition: forcefield.h:1699
#define MAKE_PLUGIN(BaseClass)
Definition: plugin.h:195
static OBFFConstraints _constraints
Constraints.
Definition: forcefield.h:551
Simplify 'plugin' classes to be discovered and/or loaded at runtime.
std::vector< double > _dpar
Used to store double type parameters (force constants, bond lengths, angles, ...) ...
Definition: forcefield.h:103
bool UpdateConformers(OBMol &mol)
Definition: forcefield.h:720
bool _init
Used to make sure we only parse the parameter file once, when needed.
Definition: forcefield.h:528
virtual double E_Torsion(bool gradients=true)
Definition: forcefield.h:941
Represents a vector in 3-dimensional real space.
Definition: vector3.h:44
double _rele
Electrostatic cut-off distance.
Definition: forcefield.h:557
int idx_d
Used to store the index of atoms for this OBFFCalculation.
Definition: forcefield.h:205
int a
Used to store integer atom types.
Definition: forcefield.h:96
static void VectorCross(double *i, double *j, double *result)
Definition: forcefield.h:1725
double _temp
Molecular dynamics temperature in Kelvin.
Definition: forcefield.h:548
virtual void SetupPointers()
Definition: forcefield.h:156
std::string _b
Definition: forcefield.h:98
#define OBFF_ANALYTICAL_GRADIENT
use analytical gradients
Definition: forcefield.h:65
Internal class for OBForceField to hold constraints.
Definition: forcefield.h:233
virtual bool ParseParamFile()
Definition: forcefield.h:639
int GetLineSearchType()
Definition: forcefield.h:1212
static void VectorSelfMultiply(double *i, double n)
Definition: forcefield.h:1627
unsigned int _ncoords
Number of coordinates for conjugate gradients.
Definition: forcefield.h:544
void OBFFLog(const char *msg)
Definition: forcefield.h:1030
unsigned int GetIdx() const
Definition: atom.h:189
Internal class for OBForceField to hold energy and gradient calculations on specific force fields...
Definition: forcefield.h:168
OBBitVec _vdwpairs
VDW pairs that should be calculated.
Definition: forcefield.h:559
void SetupPointers()
Definition: forcefield.h:216
double * _velocityPtr
pointer to the velocities
Definition: forcefield.h:549
#define BUFF_SIZE
Definition: mol.h:731
int _nsteps
Used for conjugate gradients and steepest descent(Initialize and TakeNSteps)
Definition: forcefield.h:542
std::string _parFile
Definition: forcefield.h:529
std::vector< OBBitVec > _intraGroup
groups for which intra-molecular interactions should be calculated
Definition: forcefield.h:563
Base class for molecular mechanics force fields.
Definition: forcefield.h:415
OBFFConstraints & operator=(const OBFFConstraints &ai)
Get the constrain gradient for the atom.
Definition: forcefield.h:299
virtual ~OBForceField()
Destructor.
Definition: forcefield.h:574
static void VectorCopy(double *from, double *to)
Definition: forcefield.h:1647
bool _validSetup
< parameter file name
Definition: forcefield.h:530
int _current_conformer
used to hold i for current conformer (needed by UpdateConformers)
Definition: forcefield.h:538
void SetGradient(double *grad, int idx)
Definition: forcefield.h:487
OBFFConstraint()
Constructor.
Definition: forcefield.h:247
virtual std::string GetUnit()
Definition: forcefield.h:616
std::vector< double > _energies
used to hold the energies for all conformers
Definition: forcefield.h:539
std::string _c
Definition: forcefield.h:98
static double VectorDot(double *i, double *j)
Definition: forcefield.h:1710
virtual ~OBFFCalculation2()
Destructor.
Definition: forcefield.h:151
Fast and efficient bitstring class.
static OBForceField * FindForceField(const char *ID)
Definition: forcefield.h:602
virtual bool SetFormalCharges()
Definition: forcefield.h:649
vector3 GetGradient(int a)
Definition: forcefield.h:259
int c
Definition: forcefield.h:96
#define OBFF_ENERGY
all terms
Definition: forcefield.h:43
virtual bool Validate()
Validate the force field implementation (debugging)
Definition: forcefield.h:1484
double GetVDWCutOff()
Definition: forcefield.h:803
int d
Definition: forcefield.h:96
std::vector< int > _ipar
Used to store integer type parameters (bondtypes, multiplicity, ...)
Definition: forcefield.h:101
virtual double E_StrBnd(bool gradients=true)
Definition: forcefield.h:934
Definition: forcefield.h:79
OBAtom * b
Definition: forcefield.h:143
virtual bool SetupCalculations()
Definition: forcefield.h:659
Store values for numeric grids such as orbitals or electrostatic potential.
Definition: griddata.h:39
~OBFFConstraint()
Destructor.
Definition: forcefield.h:255
OBBitVec _elepairs
Electrostatic pairs that should be calculated.
Definition: forcefield.h:560
double factor
Used to store the contraint energy for this OBFFConstraint.
Definition: forcefield.h:237
void OBFFLog(std::string msg)
Definition: forcefield.h:1020
double * pos_b
Definition: forcefield.h:147
bool UpdateCoordinates(OBMol &mol)
Definition: forcefield.h:713
virtual void ClearGradients()
Definition: forcefield.h:507
static void VectorMultiply(const double *const i, const double n, double *result)
Definition: forcefield.h:1617
int b
Definition: forcefield.h:96
int type
Used to store the contraint type for this OBFFConstraint.
Definition: forcefield.h:240
Global namespace for all Open Babel code.
Definition: alias.h:22
Atom class.
Definition: atom.h:71