RDKit
Open-source cheminformatics and machine learning.
FourthDimContrib.h
Go to the documentation of this file.
1 //
2 // Created by Santosh Putta, Nov 2006
3 //
4 #include <RDGeneral/export.h>
5 #ifndef __RD_FOURTHDIMCONTRIB_H__
6 #define __RD_FOURTHDIMCONTRIB_H__
7 
8 #include <RDGeneral/Invariant.h>
9 #include <ForceField/Contrib.h>
10 #include <ForceField/ForceField.h>
11 
12 namespace DistGeom {
13 //! A term used in penalizing chirality violations
14 //!
16  public:
17  FourthDimContrib() : d_idx(0), d_weight(0.0){};
18 
19  //! Constructor
20  /*!
21  \param owner pointer to the owning ForceField
22  \param idx the index of the atom to be considered
23  \param weight (optional) the weight to be used for this contrib
24 
25  */
26  FourthDimContrib(ForceFields::ForceField *owner, unsigned int idx,
27  double weight)
28  : d_idx(idx), d_weight(weight) {
29  PRECONDITION(owner, "bad force field");
30  PRECONDITION(owner->dimension() == 4, "force field has wrong dimension");
31  dp_forceField = owner;
32  };
33 
34  //! return the contribution of this contrib to the energy of a given state
35  double getEnergy(double *pos) const {
36  PRECONDITION(dp_forceField, "no owner");
37  PRECONDITION(dp_forceField->dimension() == 4,
38  "force field has wrong dimension");
39  PRECONDITION(pos, "bad vector");
40  unsigned int pid = d_idx * dp_forceField->dimension() + 3;
41  return d_weight * pos[pid] * pos[pid];
42  }
43 
44  //! calculate the contribution of this contrib to the gradient at a given
45  //state
46  void getGrad(double *pos, double *grad) const {
47  PRECONDITION(dp_forceField, "no owner");
48  PRECONDITION(dp_forceField->dimension() == 4,
49  "force field has wrong dimension");
50  PRECONDITION(pos, "bad vector");
51  unsigned int pid = d_idx * dp_forceField->dimension() + 3;
52  grad[pid] += d_weight * pos[pid];
53  }
54  virtual FourthDimContrib *copy() const {
55  return new FourthDimContrib(*this);
56  };
57 
58  private:
59  unsigned int d_idx;
60  double d_weight;
61 };
62 }
63 
64 #endif
unsigned int dimension() const
returns the dimension of the forcefield
Definition: ForceField.h:200
virtual FourthDimContrib * copy() const
return a copy
#define RDKIT_DISTGEOMETRY_EXPORT
Definition: export.h:164
double getEnergy(double *pos) const
return the contribution of this contrib to the energy of a given state
abstract base class for contributions to ForceFields
Definition: Contrib.h:18
void getGrad(double *pos, double *grad) const
calculate the contribution of this contrib to the gradient at a given
FourthDimContrib(ForceFields::ForceField *owner, unsigned int idx, double weight)
Constructor.
#define PRECONDITION(expr, mess)
Definition: Invariant.h:108
A class to store forcefields and handle minimization.
Definition: ForceField.h:58