RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
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
11
12namespace DistGeom {
13//! A term used in penalizing chirality violations
14//!
17 public:
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 override {
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 override {
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 FourthDimContrib *copy() const override {
56 return new FourthDimContrib(*this);
57 }
58
59 private:
60 unsigned int d_idx{0};
61 double d_weight{0.0};
62};
63} // namespace DistGeom
64
65#endif
#define PRECONDITION(expr, mess)
Definition Invariant.h:109
FourthDimContrib(ForceFields::ForceField *owner, unsigned int idx, double weight)
Constructor.
FourthDimContrib * copy() const override
return a copy
void getGrad(double *pos, double *grad) const override
double getEnergy(double *pos) const override
return the contribution of this contrib to the energy of a given state
abstract base class for contributions to ForceFields
Definition Contrib.h:18
A class to store forcefields and handle minimization.
Definition ForceField.h:79
unsigned int dimension() const
returns the dimension of the forcefield
Definition ForceField.h:220
#define RDKIT_DISTGEOMETRY_EXPORT
Definition export.h:129