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
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),
33};
34
35//! A term to capture all flat bottom distance constraint potentials.
37 : public ForceFieldContrib {
38 public:
40
41 //! Constructor
42 /*!
43 \param owner pointer to the owning ForceField
44 */
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
bool empty() const
Return true if there are no contributions in this contrib.
void getGrad(double *pos, double *grad) const override
DistanceConstraintContribs(ForceField *owner)
Constructor.
unsigned int size() const
Get number of contributions in this contrib.
void addContrib(unsigned int idx1, unsigned int idx2, bool relative, double minLen, double maxLen, double forceConstant)
Add contribution to this contrib.
void addContrib(unsigned int idx1, unsigned int idx2, double minLen, double maxLen, double forceConstant)
Add contribution to this contrib.
~DistanceConstraintContribs() override=default
DistanceConstraintContribs * copy() const override
Copy constructor.
double getEnergy(double *pos) const override
return the contribution of this contrib to the energy of a given state
#define RDKIT_FORCEFIELD_EXPORT
Definition export.h:201
unsigned int idx2
index of atom2 of the distance constraint
DistanceConstraintContribsParams(unsigned int idx1, unsigned int idx2, double minLen, double maxLen, double forceConstant=1.0)
double minLen
lower bound of the flat bottom potential
unsigned int idx1
index of atom1 of the distance constraint
double forceConstant
force constant for distance constraint
double maxLen
upper bound of the flat bottom potential