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