Open Babel  3.0
forcefield.h
Go to the documentation of this file.
1 /**********************************************************************
2 forcefield.h - Handle OBForceField class.
3 
4 Copyright (C) 2006-2007 by Tim Vandermeersch <[email protected]>
5 
6 This file is part of the Open Babel project.
7 For more information, see <http://openbabel.org/>
8 
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation version 2 of the License.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 ***********************************************************************/
18 
19 #ifndef OB_FORCEFIELD_H
20 #define OB_FORCEFIELD_H
21 
22 #include <vector>
23 #include <string>
24 
25 #include <openbabel/babelconfig.h>
26 #include <openbabel/mol.h> // TODO: Move OBMol code out of the header (use OBMol*)
27 #include <openbabel/atom.h> // TODO: Move OBAtom code out of the header
28 #include <openbabel/plugin.h>
29 #include <openbabel/bitvec.h>
30 #include <float.h>
31 
32 namespace OpenBabel
33 {
34  class OBGridData;
35 
36  // log levels
37 #define OBFF_LOGLVL_NONE 0
38 #define OBFF_LOGLVL_LOW 1
39 #define OBFF_LOGLVL_MEDIUM 2
40 #define OBFF_LOGLVL_HIGH 3
41 
42  // terms
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)
51 
52  // constraint types
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)
62 
63  // mode arguments for SteepestDescent, ConjugateGradients, ...
64 #define OBFF_NUMERICAL_GRADIENT (1 << 0)
65 #define OBFF_ANALYTICAL_GRADIENT (1 << 1)
66 
67 const double KCAL_TO_KJ = 4.1868;
68 const double GAS_CONSTANT = 8.31446261815324e-3 / KCAL_TO_KJ;
69 
70  // inline if statements for logging.
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)
74 
77  {
78  enum {
80  };
81  };
82  /*
83  struct ConstraintType
84  {
85  enum {
86  Ignore, Atom, AtomX, AtomY, AtomZ, Distance, Angle, Torsion, Chiral
87  };
88  };
89  */
90 
93  class OBFPRT OBFFParameter {
94  public:
96  int a, b, c, d;
98  std::string _a, _b, _c, _d;
99 
101  std::vector<int> _ipar;
103  std::vector<double> _dpar;
104 
107  {
108  if (this != &ai) {
109  a = ai.a;
110  b = ai.b;
111  c = ai.c;
112  d = ai.d;
113  _a = ai._a;
114  _b = ai._b;
115  _c = ai._c;
116  _d = ai._d;
117  _ipar = ai._ipar;
118  _dpar = ai._dpar;
119  }
120 
121  return *this;
122  }
123 
125  void clear ()
126  {
127  a = b = c = d = 0;
128  _ipar.clear();
129  _dpar.clear();
130  }
131  }; // class OBFFParameter
132 
133  // specific class introductions in forcefieldYYYY.cpp (for YYYY calculations)
134 
137  class OBFPRT OBFFCalculation2
138  {
139  public:
141  double energy;
143  OBAtom *a, *b;
145  int idx_a, idx_b;
147  double *pos_a, *pos_b;
149  double force_a[3], force_b[3];
152  {
153  }
156  virtual void SetupPointers()
157  {
158  if (!a || !b) return;
159  pos_a = a->GetCoordinate();
160  idx_a = a->GetIdx();
161  pos_b = b->GetCoordinate();
162  idx_b = b->GetIdx();
163  }
164  };
165 
168  class OBFPRT OBFFCalculation3: public OBFFCalculation2
169  {
170  public:
174  int idx_c;
176  double *pos_c;
178  double force_c[3];
181  {
182  }
185  virtual void SetupPointers()
186  {
187  if (!a || !b || !c) return;
188  pos_a = a->GetCoordinate();
189  idx_a = a->GetIdx();
190  pos_b = b->GetCoordinate();
191  idx_b = b->GetIdx();
192  pos_c = c->GetCoordinate();
193  idx_c = c->GetIdx();
194  }
195  };
196 
199  class OBFPRT OBFFCalculation4: public OBFFCalculation3
200  {
201  public:
205  int idx_d;
207  double *pos_d;
209  double force_d[3];
212  {
213  }
217  {
218  if (!a || !b || !c || !d) return;
219  pos_a = a->GetCoordinate();
220  idx_a = a->GetIdx();
221  pos_b = b->GetCoordinate();
222  idx_b = b->GetIdx();
223  pos_c = c->GetCoordinate();
224  idx_c = c->GetIdx();
225  pos_d = d->GetCoordinate();
226  idx_d = d->GetIdx();
227  }
228  };
229 
233  class OBFPRT OBFFConstraint
234  {
235  public:
237  double factor, constraint_value;
238  double rab0, rbc0;
240  int type, ia, ib, ic, id;
242  OBAtom *a, *b, *c, *d;
244  vector3 grada, gradb, gradc, gradd;
245 
248  {
249  a = b = c = d = NULL;
250  ia = ib = ic = id = 0;
251  constraint_value = 0.0;
252  factor = 0.0;
253  }
256  {
257  }
258 
260  {
261  if (a == ia)
262  return grada;
263  else if (a == ib)
264  return gradb;
265  else if (a == ic)
266  return gradc;
267  else if (a == id)
268  return gradd;
269  else
270  return VZero;
271  }
272  };
273 
277  class OBFPRT OBFFConstraints
278  {
279  public:
281  OBFFConstraints();
284  {
285  _constraints.clear();
286  _ignored.Clear();
287  _fixed.Clear();
288  _Xfixed.Clear();
289  _Yfixed.Clear();
290  _Zfixed.Clear();
291  }
293  void Clear();
295  double GetConstraintEnergy();
297  vector3 GetGradient(int a);
300  {
301  if (this != &ai) {
302  _constraints = ai._constraints;
303  _ignored = ai._ignored;
304  _fixed = ai._fixed;
305  _Xfixed = ai._Xfixed;
306  _Yfixed = ai._Yfixed;
307  _Zfixed = ai._Zfixed;
308  }
309  return *this;
310  }
311 
315  void Setup(OBMol &mol);
316 
318  // Set Constraints //
321 
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);
344  // Get Constraints //
348 
349  double GetFactor();
352  int Size() const;
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);
384  bool IsFixed(int a);
387  bool IsXFixed(int a);
390  bool IsYFixed(int a);
393  bool IsZFixed(int a);
397  OBBitVec GetIgnoredBitVec() { return _ignored; }
400  OBBitVec GetFixedBitVec() { return _fixed; }
402 
403  private:
404  std::vector<OBFFConstraint> _constraints;
405  OBBitVec _ignored;
406  OBBitVec _fixed;
407  OBBitVec _Xfixed;
408  OBBitVec _Yfixed;
409  OBBitVec _Zfixed;
410  double _factor;
411  };
412 
413  // Class OBForceField
414  // class introduction in forcefield.cpp
415  class OBFPRT OBForceField : public OBPlugin
416  {
418 
419  protected:
420 
462  OBFFParameter* GetParameter(int a, int b, int c, int d, std::vector<OBFFParameter> &parameter);
464  OBFFParameter* GetParameter(const char* a, const char* b, const char* c, const char* d,
465  std::vector<OBFFParameter> &parameter);
467  int GetParameterIdx(int a, int b, int c, int d, std::vector<OBFFParameter> &parameter);
468 
477  vector3 NumericalDerivative(OBAtom *a, int terms = OBFF_ENERGY);
479  vector3 NumericalSecondDerivative(OBAtom *a, int terms = OBFF_ENERGY);
480 
481  /*
482  * NEW gradients functions
483  */
484 
487  void SetGradient(double *grad, int idx)
488  {
489  const int coordIdx = (idx - 1) * 3;
490  for (unsigned int i = 0; i < 3; ++i) {
491  _gradientPtr[coordIdx + i] = grad[i];
492  }
493  }
494 
497  void AddGradient(double *grad, int idx)
498  {
499  const int coordIdx = (idx - 1) * 3;
500  for (unsigned int i = 0; i < 3; ++i) {
501  _gradientPtr[coordIdx + i] += grad[i];
502  }
503  }
504 
507  virtual void ClearGradients()
508  {
509  // We cannot use memset because IEEE floating point representations
510  // are not guaranteed by C/C++ standard, but this loop can be
511  // unrolled or vectorized by compilers
512  for (unsigned int i = 0; i < _ncoords; ++i)
513  _gradientPtr[i] = 0.0;
514  // memset(_gradientPtr, '\0', sizeof(double)*_ncoords);
515  }
516 
524  bool IsInSameRing(OBAtom* a, OBAtom* b);
525 
526  // general variables
528  bool _init;
529  std::string _parFile;
530  bool _validSetup;
531  double *_gradientPtr;
532  // logging variables
533  std::ostream* _logos;
534  char _logbuf[BUFF_SIZE+1];
535  int _loglvl;
537  // conformer genereation (rotor search) variables
539  std::vector<double> _energies;
540  // minimization variables
541  double _econv, _gconv, _e_n1;
542  int _cstep, _nsteps;
543  double *_grad1;
544  unsigned int _ncoords;
546  // molecular dynamics variables
547  double _timestep;
548  double _temp;
549  double *_velocityPtr;
550  // contraint varibles
552  static unsigned int _fixAtom;
553  static unsigned int _ignoreAtom;
554  // cut-off variables
555  bool _cutoff;
556  double _rvdw;
557  double _rele;
558  double _epsilon;
561  int _pairfreq;
562  // group variables
563  std::vector<OBBitVec> _intraGroup;
564  std::vector<OBBitVec> _interGroup;
565  std::vector<std::pair<OBBitVec, OBBitVec> > _interGroups;
566  public:
571  virtual OBForceField* MakeNewInstance()=0;
572 
574  virtual ~OBForceField()
575  {
576  if (_grad1 != NULL) {
577  delete [] _grad1;
578  _grad1 = NULL;
579  }
580  if (_gradientPtr != NULL) {
581  delete [] _gradientPtr;
582  _gradientPtr = NULL;
583  }
584  }
585 
587  const char* TypeID()
588  {
589  return "forcefields";
590  }
591 
595  static OBForceField* FindForceField(const std::string& ID)
596  {
597  return FindType(ID.c_str());
598  }
602  static OBForceField* FindForceField(const char *ID)
603  {
604  return FindType(ID);
605  }
606  /*
607  *
608  */
609  void SetParameterFile(const std::string &filename)
610  {
611  _parFile = filename;
612  _init = false;
613  }
616  virtual std::string GetUnit() { return std::string("au"); }
617  /* Does this force field have analytical gradients defined for all
618  * calculation components (bonds, angles, non-bonded, etc.)
619  * If this is true, code should default to using OBFF_ANALYTICAL_GRADIENT
620  * for SteepestDescent() or ConjugateGradients().
621  * \return True if all analytical gradients are implemented.
622  */
623  virtual bool HasAnalyticalGradients() { return false; }
628  bool Setup(OBMol &mol);
634  bool Setup(OBMol &mol, OBFFConstraints &constraints);
638  // move to protected in future version
639  virtual bool ParseParamFile() { return false; }
643  // move to protected in future version
644  virtual bool SetTypes() { return false; }
648  // move to protected in future version
649  virtual bool SetFormalCharges() { return false; }
653  // move to protected in future version
654  virtual bool SetPartialCharges() { return false; }
658  // move to protected in future version
659  virtual bool SetupCalculations() { return false; }
664  // move to protected in future version
665  virtual bool SetupPointers() { return false; }
671  bool IsSetupNeeded(OBMol &mol);
687  bool GetAtomTypes(OBMol &mol);
703  bool GetPartialCharges(OBMol &mol);
704 
705 
706 
711  bool GetCoordinates(OBMol &mol);
713  bool UpdateCoordinates(OBMol &mol) {return GetCoordinates(mol); }
718  bool GetConformers(OBMol &mol);
720  bool UpdateConformers(OBMol &mol) { return GetConformers(mol); }
725  bool SetCoordinates(OBMol &mol);
730  bool SetConformers(OBMol &mol);
740  OBGridData *GetGrid(double step, double padding, const char *type, double pchg);
741 
743  // Interacting groups //
745 
747 
748 
752  void AddIntraGroup(OBBitVec &group);
757  void AddInterGroup(OBBitVec &group);
765  void AddInterGroups(OBBitVec &group1, OBBitVec &group2);
768  void ClearGroups();
771  bool HasGroups();
773 
775  // Cut-off //
777 
779 
780 
783  void EnableCutOff(bool enable)
784  {
785  _cutoff = enable;
786  }
790  {
791  return _cutoff;
792  }
796  void SetVDWCutOff(double r)
797  {
798  _rvdw = r;
799  }
803  double GetVDWCutOff()
804  {
805  return _rvdw;
806  }
811  void SetElectrostaticCutOff(double r)
812  {
813  _rele = r;
814  }
819  {
820  return _rele;
821  }
825  void SetDielectricConstant(double epsilon)
826  {
827  _epsilon = epsilon;
828  }
829  /* Get the dielectric permittivity used for electrostatic calculations
830  * \rreturn The current relative permittivity
831  */
833  {
834  return _epsilon;
835  }
841  void SetUpdateFrequency(int f)
842  {
843  _pairfreq = f;
844  }
849  {
850  return _pairfreq;
851  }
856  void UpdatePairsSimple();
857 
858  //void UpdatePairsGroup(); TODO
859 
863  unsigned int GetNumPairs();
867  unsigned int GetNumElectrostaticPairs();
871  unsigned int GetNumVDWPairs();
876  {
877  // TODO: OBBitVec doesn't seem to be allocating it's memory correctly
878  //_vdwpairs.SetRangeOn(0, _numpairs-1);
879  //_elepairs.SetRangeOn(0, _numpairs-1);
880  }
882 
885  virtual vector3 GetGradient(OBAtom *a, int /*terms*/ = OBFF_ENERGY)
886  {
887  const int coordIdx = (a->GetIdx() - 1) * 3;
888  return _gradientPtr + coordIdx;
889  }
890 
893  double* GetGradientPtr()
894  {
895  return _gradientPtr;
896  }
897 
899  // Energy Evaluation //
901 
903 
904 
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; }
962  virtual double E_Electrostatic(bool UNUSED(gradients) = true) { return 0.0f; }
964 
966  // Logging //
968 
970 
971 
973  void PrintTypes();
977  void PrintFormalCharges();
980  void PrintPartialCharges();
983  void PrintVelocities();
988  bool SetLogFile(std::ostream *pos);
1013  bool SetLogLevel(int level);
1016  int GetLogLevel() { return _loglvl; }
1020  void OBFFLog(std::string msg)
1021  {
1022  if (!_logos)
1023  return;
1024 
1025  *_logos << msg;
1026  }
1030  void OBFFLog(const char *msg)
1031  {
1032  if (!_logos)
1033  return;
1034 
1035  *_logos << msg;
1036  }
1038 
1040  // Structure Generation //
1042 
1044 
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);
1190 
1191 #ifdef HAVE_EIGEN
1192  int DiverseConfGen(double rmsd, unsigned int nconfs = 0, double energy_gap = 50, bool verbose = false);
1194 #endif
1195 
1197  // Energy Minimization //
1199 
1201 
1202 
1205  void SetLineSearchType(int type)
1206  {
1207  _linesearch = type;
1208  }
1213  {
1214  return _linesearch;
1215  }
1219  vector3 LineSearch(OBAtom *atom, vector3 &direction);
1233  double LineSearch(double *currentCoords, double *direction);
1246  double Newton2NumLineSearch(double *direction);
1252  void LineSearchTakeStep(double *origCoords, double *direction, double step);
1268  void SteepestDescent(int steps, double econv = 1e-6f, int method = OBFF_ANALYTICAL_GRADIENT);
1295  void SteepestDescentInitialize(int steps = 1000, double econv = 1e-6f, int method = OBFF_ANALYTICAL_GRADIENT);
1310  bool SteepestDescentTakeNSteps(int n);
1326  void ConjugateGradients(int steps, double econv = 1e-6f, int method = OBFF_ANALYTICAL_GRADIENT);
1354  void ConjugateGradientsInitialize(int steps = 1000, double econv = 1e-6f, int method = OBFF_ANALYTICAL_GRADIENT);
1370  bool ConjugateGradientsTakeNSteps(int n);
1372 
1374  // Molecular Dynamics //
1376 
1378 
1379 
1381  void GenerateVelocities();
1401  void CorrectVelocities();
1417  void MolecularDynamicsTakeNSteps(int n, double T, double timestep = 0.001, int method = OBFF_ANALYTICAL_GRADIENT);
1419 
1421  // Constraints //
1423 
1425 
1426 
1429  OBFFConstraints& GetConstraints();
1433  void SetConstraints(OBFFConstraints& constraints);
1441  void SetFixAtom(int index);
1445  void UnsetFixAtom();
1454  void SetIgnoreAtom(int index);
1458  void UnsetIgnoreAtom();
1459 
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);
1467 
1468 
1470  // Validation //
1472 
1474 
1475  bool DetectExplosion();
1478  vector3 ValidateLineSearch(OBAtom *atom, vector3 &direction);
1480  void ValidateSteepestDescent(int steps);
1482  void ValidateConjugateGradients(int steps);
1484  virtual bool Validate() { return false; }
1489  virtual bool ValidateGradients() { return false; }
1494  vector3 ValidateGradientError(vector3 &numgrad, vector3 &anagrad);
1496 
1498  // Vector Analysis //
1500 
1502 
1503 
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);
1519  static double VectorLengthDerivative(vector3 &a, vector3 &b);
1520 
1531  static double VectorAngleDerivative(double *pos_a, double *pos_b, double *pos_c,
1532  double *force_a, double *force_b, double *force_c);
1534  static double VectorAngleDerivative(vector3 &a, vector3 &b, vector3 &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);
1550  static double VectorOOPDerivative(vector3 &a, vector3 &b, vector3 &c, vector3 &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);
1565  static double VectorTorsionDerivative(vector3 &a, vector3 &b, vector3 &c, vector3 &d);
1566 
1572  static void VectorSubtract(double *i, double *j, double *result)
1573  {
1574  for (unsigned int c = 0; c < 3; ++c)
1575  result[c] = i[c] - j[c];
1576  }
1577 
1578  static void VectorSubtract(const double* const i, const double* const j, double *result)
1579  {
1580  for (unsigned int c = 0; c < 3; ++c)
1581  result[c] = i[c] - j[c];
1582  }
1583 
1589  static void VectorAdd(double *i, double *j, double *result)
1590  {
1591  for (unsigned int c = 0; c < 3; ++c)
1592  result[c] = i[c] + j[c];
1593  }
1594 
1600  static void VectorDivide(double *i, double n, double *result)
1601  {
1602  for (unsigned int c = 0; c < 3; ++c)
1603  result[c] = i[c] / n;
1604  }
1605 
1611  static void VectorMultiply(double *i, double n, double *result)
1612  {
1613  for (unsigned int c = 0; c < 3; ++c)
1614  result[c] = i[c] * n;
1615  }
1616 
1617  static void VectorMultiply(const double* const i, const double n, double *result)
1618  {
1619  for (unsigned int c = 0; c < 3; ++c)
1620  result[c] = i[c] * n;
1621  }
1622 
1627  static void VectorSelfMultiply(double *i, double n)
1628  {
1629  for (unsigned int c = 0; c < 3; ++c)
1630  i[c] *= n;
1631  }
1632 
1636  static void VectorNormalize(double *i)
1637  {
1638  double length = VectorLength(i);
1639  for (unsigned int c = 0; c < 3; ++c)
1640  i[c] /= length;
1641  }
1642 
1647  static void VectorCopy(double *from, double *to)
1648  {
1649  for (unsigned int c = 0; c < 3; ++c)
1650  to[c] = from[c];
1651  }
1652 
1657  static double VectorLength(double *i)
1658  {
1659  return sqrt( i[0]*i[0] + i[1]*i[1] + i[2]*i[2] );
1660  }
1661 
1662  static double VectorDistance(double *pos_i, double *pos_j)
1663  {
1664  double ij[3];
1665  VectorSubtract(pos_i, pos_j, ij);
1666  const double rij = VectorLength(ij);
1667  return rij;
1668  }
1669 
1676  static double VectorAngle(double *i, double *j, double *k);
1677 
1685  static double VectorTorsion(double *i, double *j, double *k, double *l);
1686 
1694  static double VectorOOP(double *i, double *j, double *k, double *l);
1695 
1699  static void VectorClear(double *i)
1700  {
1701  for (unsigned int c = 0; c < 3; ++c)
1702  i[c] = 0.0;
1703  }
1704 
1710  static double VectorDot(double *i, double *j)
1711  {
1712  double result = 0.0;
1713  // Written as a loop for vectorization
1714  // Loop will be unrolled by compiler otherwise
1715  for (unsigned int c = 0; c < 3; ++c)
1716  result += i[c]*j[c];
1717  return result;
1718  }
1719 
1725  static void VectorCross(double *i, double *j, double *result)
1726  {
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];
1730  }
1731 
1732  static void PrintVector(double *i)
1733  {
1734  std::cout << "<" << i[0] << ", " << i[1] << ", " << i[2] << ">" << std::endl;
1735  }
1737 
1738  }; // class OBForceField
1739 
1740 }// namespace OpenBabel
1741 
1742 #endif // OB_FORCEFIELD_H
1743 
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 &#39;plugin&#39; 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
Handle atoms.
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