RDKit: DistanceConstraints.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
DistanceConstraints.h
Go to the documentation of this file.
1//
2// Copyright (C) 2024 Niels Maeder and other RDKit contributors
3//
4// @@ All Rights Reserved @@
5// This file is part of the RDKit.
6// The contents are covered by the terms of the BSD license
7// which is included in the file license.txt, found at the root
8// of the RDKit source tree.
9//
10
11#include <RDGeneral/export.h>
12#ifndef RD_DISTANCECONSTRAINTS_H
13#define RD_DISTANCECONSTRAINTS_H
14#include <vector>
15#include "Contrib.h"
16
17namespace ForceFields {
18
19 struct DistanceConstraintContribsParams {
20 unsigned int idx1{0}; //!< index of atom1 of the distance constraint
21 unsigned int idx2{0}; //!< index of atom2 of the distance constraint
22 double minLen{0.0}; //!< lower bound of the flat bottom potential
23 double maxLen{0.0}; //!< upper bound of the flat bottom potential
24 double forceConstant{1.0}; //!< force constant for distance constraint
25 DistanceConstraintContribsParams(unsigned int idx1, unsigned int idx2,
26 double minLen, double maxLen,
27 double forceConstant = 1.0)
28 : idx1(idx1),
29 idx2(idx2),
30 minLen(minLen),
31 maxLen(maxLen),
32 forceConstant(forceConstant) {};
33};
34
35//! A term to capture all flat bottom distance constraint potentials.
36 class RDKIT_FORCEFIELD_EXPORT DistanceConstraintContribs
37 : public ForceFieldContrib {
38 public:
39 DistanceConstraintContribs() = default;
40
41 //! Constructor
42 /*!
43 \param owner pointer to the owning ForceField
44 */
45 DistanceConstraintContribs(ForceField *owner);
46 ~DistanceConstraintContribs() override = default;
47 //! Add contribution to this contrib.
48 /*!
49 \param idx1 index of atom1 in the ForceField's positions
50 \param idx2 index of atom2 in the ForceField's positions
51 \param minLen minimum distance
52 \param maxLen maximum distance
53 \param forceConst force Constant
54
55 */
56 void addContrib(unsigned int idx1, unsigned int idx2, double minLen,
57 double maxLen, double forceConstant);
58 //! Add contribution to this contrib.
59 /*!
60 \param idx1 index of atom1 in the ForceField's positions
61 \param idx2 index of atom2 in the ForceField's positions
62 \param relative whether to add the provided distance to the
63 current distance
64 \param minLen minimum distance
65 \param maxLen maximum distance
66 \param forceConst force Constant
67
68 */
69 void addContrib(unsigned int idx1, unsigned int idx2, bool relative,
70 double minLen, double maxLen, double forceConstant);
71
72 //! return the contribution of this contrib to the energy of a given state
73 /*!
74 \param pos positions of the atoms in the current state
75 */
76 double getEnergy(double *pos) const override;
77 //! calculate the contribution of this contrib to the gradient at a given
78 /// state
79 /*!
80 \param pos positions of the atoms in the current state
81 \param grad gradients to be adapted
82 */
83 void getGrad(double *pos, double *grad) const override;
84
85 //! Copy constructor
86 DistanceConstraintContribs *copy() const override {
87 return new DistanceConstraintContribs(*this);
88 }
89
90 //! Return true if there are no contributions in this contrib
91 bool empty() const { return d_contribs.empty(); }
92
93 //! Get number of contributions in this contrib
94 unsigned int size() const { return d_contribs.size(); }
95
96 private:
97 std::vector<DistanceConstraintContribsParams> d_contribs;
98};
99
100} // namespace ForceFields
101
102#endif
Contrib.h
ForceFields::DistanceConstraintContribs::empty
bool empty() const
Return true if there are no contributions in this contrib.
Definition DistanceConstraints.h:91
ForceFields::DistanceConstraintContribs::getGrad
void getGrad(double *pos, double *grad) const override
ForceFields::DistanceConstraintContribs::DistanceConstraintContribs
DistanceConstraintContribs(ForceField *owner)
Constructor.
ForceFields::DistanceConstraintContribs::size
unsigned int size() const
Get number of contributions in this contrib.
Definition DistanceConstraints.h:94
ForceFields::DistanceConstraintContribs::addContrib
void addContrib(unsigned int idx1, unsigned int idx2, bool relative, double minLen, double maxLen, double forceConstant)
Add contribution to this contrib.
ForceFields::DistanceConstraintContribs::addContrib
void addContrib(unsigned int idx1, unsigned int idx2, double minLen, double maxLen, double forceConstant)
Add contribution to this contrib.
ForceFields::DistanceConstraintContribs::~DistanceConstraintContribs
~DistanceConstraintContribs() override=default
ForceFields::DistanceConstraintContribs::copy
DistanceConstraintContribs * copy() const override
Copy constructor.
Definition DistanceConstraints.h:86
ForceFields::DistanceConstraintContribs::DistanceConstraintContribs
DistanceConstraintContribs()=default
ForceFields::DistanceConstraintContribs::getEnergy
double getEnergy(double *pos) const override
return the contribution of this contrib to the energy of a given state
ForceFields::ForceFieldContrib::ForceField
friend class ForceField
Definition Contrib.h:20
ForceFields::ForceFieldContrib::ForceFieldContrib
ForceFieldContrib()
Definition Contrib.h:22
export.h
RDKIT_FORCEFIELD_EXPORT
#define RDKIT_FORCEFIELD_EXPORT
Definition export.h:201
ForceFields
Definition TorsionAngleContribs.h:21
ForceFields::DistanceConstraintContribsParams::idx2
unsigned int idx2
index of atom2 of the distance constraint
Definition DistanceConstraints.h:21
ForceFields::DistanceConstraintContribsParams::DistanceConstraintContribsParams
DistanceConstraintContribsParams(unsigned int idx1, unsigned int idx2, double minLen, double maxLen, double forceConstant=1.0)
Definition DistanceConstraints.h:25
ForceFields::DistanceConstraintContribsParams::minLen
double minLen
lower bound of the flat bottom potential
Definition DistanceConstraints.h:22
ForceFields::DistanceConstraintContribsParams::idx1
unsigned int idx1
index of atom1 of the distance constraint
Definition DistanceConstraints.h:20
ForceFields::DistanceConstraintContribsParams::forceConstant
double forceConstant
force constant for distance constraint
Definition DistanceConstraints.h:24
ForceFields::DistanceConstraintContribsParams::maxLen
double maxLen
upper bound of the flat bottom potential
Definition DistanceConstraints.h:23