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