RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
GaussianTorsionAngleContribs.h
Go to the documentation of this file.
1//
2// Copyright (C) 2026 ETH Zurich and other RDKit contributors
3// Author: Niels Maeder
4//
5// @@ All Rights Reserved @@
6// This file is part of the RDKit.
7// The contents are covered by the terms of the BSD license
8// which is included in the file license.txt, found at the root
9// of the RDKit source tree.
10//
11
12#include <RDGeneral/export.h>
13#ifndef RD_GAUSSIANTORSIONANGLECONTRIBS_H
14#define RD_GAUSSIANTORSIONANGLECONTRIBS_H
15#include <ForceField/Contrib.h>
16#include <vector>
17
18namespace RDGeom {
19class Point3D;
20}
21
22namespace ForceFields {
23class ForceField;
25} // namespace ForceFields
26
27namespace ForceFields {
28namespace CrystalFF {
29
30//! Size of the energies and gradients lookup table
31//! This is used in `torsionPreferences.cpp`.
32constexpr std::size_t lookup_grid_size = 180;
33
34//! A term to capture all torsion constraint potentials.
35//!
37 std::size_t idx1{0};
38 std::size_t idx2{0};
39 std::size_t idx3{0};
40 std::size_t idx4{0};
41 std::vector<double> energies{};
42 std::vector<double> gradients{};
43 double scaling{1.0};
45 std::size_t idx3, std::size_t idx4,
46 std::vector<double> energies,
47 std::vector<double> gradients,
48 double scaling = 1.0)
49 : idx1(idx1),
50 idx2(idx2),
51 idx3(idx3),
52 idx4(idx4),
53 energies(std::move(energies)),
54 gradients(std::move(gradients)),
56};
57
59 : public ForceFieldContrib {
60 public:
62
63 //! Constructor
64 /*!
65 \param owner pointer to the owning ForceField
66 */
69 //! Add contribution to this collection.
70 //! The caller is responsible that the energies and gradient lookuptables
71 //! have at least to elements each!
72 /*!
73 \param idx1 index of atom1 in the ForceField's positions
74 \param idx2 index of atom2 in the ForceField's positions
75 \param idx3 index of atom3 in the ForceField's positions
76 \param idx4 index of atom4 in the ForceField's positions
77 \param energies lookup table for the energies
78 \param gradients lookup table for the gradients
79 \param scaling Scaling factor for energy and gradient (for K terms)
80 */
81 void addContrib(std::size_t idx1, std::size_t idx2, std::size_t idx3,
82 std::size_t idx4, std::vector<double> energies,
83 std::vector<double> gradients, double scaling = 1.0);
84 //! return the contribution of this contrib to the energy of a given state
85 /*!
86 \param pos positions of the atoms in the current state
87 */
88 double getEnergy(double *pos) const override;
89 //! calculate the contribution of this contrib to the gradient at a given
90 /// state
91 /*!
92 \param pos positions of the atoms in the current state
93 \param grad gradients to be adapted
94 */
95 void getGrad(double *pos, double *grad) const override;
96 //! Copy constructor
98 return new GaussianTorsionAngleContribs(*this);
99 }
100
101 //! Return true if there are no contributions in this contrib
102 bool empty() const { return d_contribs.empty(); }
103
104 //! Get number of contributions in this contrib
105 unsigned int size() const { return d_contribs.size(); }
106
107 private:
108 std::vector<GaussianTorsionAngleContribsParams> d_contribs;
109};
110
111//! Calculate the torsion energy as described in 10.1021/acs.jcim.5b00654, this
112//! can be used with any any number of heights, positions and widths.
113//! The caller is responsible that the size of the three parameter objects are
114//! the same and non zero. `widths` need to be strictly positive.
115/*!
116 \param heights heights of the gaussians
117 \param positions positions of the gaussians
118 \param widths widths of the gaussians
119 \param phi the torsion angle in radians
120*/
122 const std::vector<double> &heights, const std::vector<double> &positions,
123 const std::vector<double> &widths, const double phi);
124
125//! Calculate the torsion gradient as described in 10.1021/acs.jcim.5b00654,
126//! this can be used with any any number of heights, positions and widths. The
127//! caller is responsible that the size of the three parameter objects are the
128//! same and non zero. `widths` need to be strictly positive.
129/*!
130 \param heights heights of the gaussians
131 \param positions positions of the gaussians
132 \param widths widths of the gaussians
133 \param phi the torsion angle in radians
134*/
136 const std::vector<double> &heights, const std::vector<double> &positions,
137 const std::vector<double> &widths, const double phi);
138} // namespace CrystalFF
139} // namespace ForceFields
140
141#endif
void getGrad(double *pos, double *grad) const override
void addContrib(std::size_t idx1, std::size_t idx2, std::size_t idx3, std::size_t idx4, std::vector< double > energies, std::vector< double > gradients, double scaling=1.0)
unsigned int size() const
Get number of contributions in this contrib.
double getEnergy(double *pos) const override
return the contribution of this contrib to the energy of a given state
GaussianTorsionAngleContribs(ForceField *owner)
Constructor.
bool empty() const
Return true if there are no contributions in this contrib.
GaussianTorsionAngleContribs * copy() const override
Copy constructor.
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_FORCEFIELDHELPERS_EXPORT
Definition export.h:261
RDKIT_FORCEFIELDHELPERS_EXPORT double getdEdPhi(const std::vector< double > &heights, const std::vector< double > &positions, const std::vector< double > &widths, const double phi)
RDKIT_FORCEFIELDHELPERS_EXPORT double getEnergy(const std::vector< double > &heights, const std::vector< double > &positions, const std::vector< double > &widths, const double phi)
constexpr std::size_t lookup_grid_size
GaussianTorsionAngleContribsParams(std::size_t idx1, std::size_t idx2, std::size_t idx3, std::size_t idx4, std::vector< double > energies, std::vector< double > gradients, double scaling=1.0)