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 <iostream>
16#include "Contrib.h"
17
18namespace ForceFields {
19
21 unsigned int idx1{0}; //!< index of atom1 of the distance constraint
22 unsigned int idx2{0}; //!< index of atom2 of the distance constraint
23 double minLen{0.0}; //!< lower bound of the flat bottom potential
24 double maxLen{0.0}; //!< upper bound of the flat bottom potential
25 double forceConstant{1.0}; //!< force constant for distance constraint
26 DistanceConstraintContribsParams(unsigned int idx1, unsigned int idx2,
27 double minLen, double maxLen,
28 double forceConstant = 1.0)
29 : idx1(idx1),
30 idx2(idx2),
34};
35
36//! A term to capture all flat bottom distance constraint potentials.
38 : public ForceFieldContrib {
39 public:
41
42 //! Constructor
43 /*!
44 \param owner pointer to the owning ForceField
45 */
47 ~DistanceConstraintContribs() override = default;
48 //! Add contribution to this contrib.
49 /*!
50 \param idx1 index of atom1 in the ForceField's positions
51 \param idx2 index of atom2 in the ForceField's positions
52 \param minLen minimum distance
53 \param maxLen maximum distance
54 \param forceConst force Constant
55
56 */
57 void addContrib(unsigned int idx1, unsigned int idx2, double minLen,
58 double maxLen, double forceConstant);
59 //! Add contribution to this contrib.
60 /*!
61 \param idx1 index of atom1 in the ForceField's positions
62 \param idx2 index of atom2 in the ForceField's positions
63 \param relative whether to add the provided distance to the
64 current distance
65 \param minLen minimum distance
66 \param maxLen maximum distance
67 \param forceConst force Constant
68
69 */
70 void addContrib(unsigned int idx1, unsigned int idx2, bool relative,
71 double minLen, double maxLen, double forceConstant);
72
73 //! return the contribution of this contrib to the energy of a given state
74 /*!
75 \param pos positions of the atoms in the current state
76 */
77 double getEnergy(double *pos) const override;
78 //! calculate the contribution of this contrib to the gradient at a given
79 /// state
80 /*!
81 \param pos positions of the atoms in the current state
82 \param grad gradients to be adapted
83 */
84 void getGrad(double *pos, double *grad) const override;
85
86 //! Copy constructor
87 DistanceConstraintContribs *copy() const override {
88 return new DistanceConstraintContribs(*this);
89 }
90
91 //! Return true if there are no contributions in this contrib
92 bool empty() const { return d_contribs.empty(); }
93
94 //! Get number of contributions in this contrib
95 unsigned int size() const { return d_contribs.size(); }
96
97 private:
98 std::vector<DistanceConstraintContribsParams> d_contribs;
99};
100
101} // namespace ForceFields
102
103#endif
A term to capture all flat bottom distance constraint potentials.
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
abstract base class for contributions to ForceFields
Definition Contrib.h:18
A class to store forcefields and handle minimization.
Definition ForceField.h:79
#define RDKIT_FORCEFIELD_EXPORT
Definition export.h:185
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