RDKit: TorsionAngleContribs.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
TorsionAngleContribs.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_TORSIONANGLECONTRIBS_H
13#define RD_TORSIONANGLECONTRIBS_H
14#include <ForceField/Contrib.h>
15#include <vector>
16
17 namespace RDGeom {
18class Point3D;
19}
20
21 namespace ForceFields {
22class ForceField;
23class ForceFieldContrib;
24} // namespace ForceFields
25
26namespace ForceFields {
27 namespace CrystalFF {
28
29//! A term to capture all torsion constraint potentials.
30//!
31 struct RDKIT_FORCEFIELDHELPERS_EXPORT TorsionAngleContribsParams {
32 unsigned int idx1{0};
33 unsigned int idx2{0};
34 unsigned int idx3{0};
35 unsigned int idx4{0};
36 std::vector<double> forceConstants{6, 1.0};
37 std::vector<int> signs{6, 1};
38 TorsionAngleContribsParams(unsigned int idx1, unsigned int idx2,
39 unsigned int idx3, unsigned int idx4,
40 std::vector<double> forceConstants,
41 std::vector<int> signs)
42 : idx1(idx1),
43 idx2(idx2),
44 idx3(idx3),
45 idx4(idx4),
46 forceConstants(forceConstants),
47 signs(signs) {}
48};
49
50 class RDKIT_FORCEFIELDHELPERS_EXPORT TorsionAngleContribs
51 : public ForceFieldContrib {
52 public:
53 TorsionAngleContribs() = default;
54
55 //! Constructor
56 /*!
57 \param owner pointer to the owning ForceField
58 */
59 TorsionAngleContribs(ForceField *owner);
60 ~TorsionAngleContribs() override = default;
61 //! Add contribution to this collection.
62 /*!
63 \param idx1 index of atom1 in the ForceField's positions
64 \param idx2 index of atom2 in the ForceField's positions
65 \param idx3 index of atom3 in the ForceField's positions
66 \param idx4 index of atom4 in the ForceField's positions
67 \param forceConstants force constants for the torsion potentials
68 \param signs phase for the torsion potentials (-1 or 1)
69
70 */
71 void addContrib(unsigned int idx1, unsigned int idx2, unsigned int idx3,
72 unsigned int idx4, std::vector<double> forceConstants,
73 std::vector<int> signs);
74 //! return the contribution of this contrib to the energy of a given state
75 /*!
76 \param pos positions of the atoms in the current state
77 */
78 double getEnergy(double *pos) const override;
79 //! calculate the contribution of this contrib to the gradient at a given
80 /// state
81 /*!
82 \param pos positions of the atoms in the current state
83 \param grad gradients to be adapted
84 */
85 void getGrad(double *pos, double *grad) const override;
86 //! Copy constructor
87 TorsionAngleContribs *copy() const override {
88 return new TorsionAngleContribs(*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<TorsionAngleContribsParams> d_contribs;
99};
100
101//! Calculate the torsion energy as described in 10.1021/acs.jcim.5b00654, this
102//! can be used with any i > 0.
103/*!
104 \param forceConstants Force constants for the different cosine fits
105 \param signs Phases of the cosine fits
106 \param cosPhi cosine of the torsion angle phi
107*/
108 RDKIT_FORCEFIELDHELPERS_EXPORT double calcTorsionEnergy(
109 const std::vector<double> &forceConstants, const std::vector<int> &signs,
110 const double cosPhi);
111
112} // namespace CrystalFF
113} // namespace ForceFields
114
115#endif
Contrib.h
ForceFields::CrystalFF::TorsionAngleContribs::size
unsigned int size() const
Get number of contributions in this contrib.
Definition TorsionAngleContribs.h:95
ForceFields::CrystalFF::TorsionAngleContribs::TorsionAngleContribs
TorsionAngleContribs()=default
ForceFields::CrystalFF::TorsionAngleContribs::addContrib
void addContrib(unsigned int idx1, unsigned int idx2, unsigned int idx3, unsigned int idx4, std::vector< double > forceConstants, std::vector< int > signs)
Add contribution to this collection.
ForceFields::CrystalFF::TorsionAngleContribs::getEnergy
double getEnergy(double *pos) const override
return the contribution of this contrib to the energy of a given state
ForceFields::CrystalFF::TorsionAngleContribs::copy
TorsionAngleContribs * copy() const override
Copy constructor.
Definition TorsionAngleContribs.h:87
ForceFields::CrystalFF::TorsionAngleContribs::getGrad
void getGrad(double *pos, double *grad) const override
ForceFields::CrystalFF::TorsionAngleContribs::~TorsionAngleContribs
~TorsionAngleContribs() override=default
ForceFields::CrystalFF::TorsionAngleContribs::TorsionAngleContribs
TorsionAngleContribs(ForceField *owner)
Constructor.
ForceFields::CrystalFF::TorsionAngleContribs::empty
bool empty() const
Return true if there are no contributions in this contrib.
Definition TorsionAngleContribs.h:92
ForceFields::ForceFieldContrib
abstract base class for contributions to ForceFields
Definition Contrib.h:18
ForceFields::ForceFieldContrib::ForceField
friend class ForceField
Definition Contrib.h:20
ForceFields::ForceFieldContrib::ForceFieldContrib
ForceFieldContrib()
Definition Contrib.h:22
ForceFields::ForceField
A class to store forcefields and handle minimization.
Definition ForceField.h:79
RDGeom::Point3D
Definition point.h:53
export.h
RDKIT_FORCEFIELDHELPERS_EXPORT
#define RDKIT_FORCEFIELDHELPERS_EXPORT
Definition export.h:209
ForceFields::CrystalFF
Definition TorsionAngleContribs.h:27
ForceFields::CrystalFF::calcTorsionEnergy
RDKIT_FORCEFIELDHELPERS_EXPORT double calcTorsionEnergy(const std::vector< double > &forceConstants, const std::vector< int > &signs, const double cosPhi)
ForceFields
Definition TorsionAngleContribs.h:21
RDGeom
Definition TorsionAngleContribs.h:17
ForceFields::CrystalFF::TorsionAngleContribsParams::signs
std::vector< int > signs
Definition TorsionAngleContribs.h:37
ForceFields::CrystalFF::TorsionAngleContribsParams::idx4
unsigned int idx4
Definition TorsionAngleContribs.h:35
ForceFields::CrystalFF::TorsionAngleContribsParams::idx1
unsigned int idx1
Definition TorsionAngleContribs.h:32
ForceFields::CrystalFF::TorsionAngleContribsParams::TorsionAngleContribsParams
TorsionAngleContribsParams(unsigned int idx1, unsigned int idx2, unsigned int idx3, unsigned int idx4, std::vector< double > forceConstants, std::vector< int > signs)
Definition TorsionAngleContribs.h:38
ForceFields::CrystalFF::TorsionAngleContribsParams::forceConstants
std::vector< double > forceConstants
Definition TorsionAngleContribs.h:36
ForceFields::CrystalFF::TorsionAngleContribsParams::idx3
unsigned int idx3
Definition TorsionAngleContribs.h:34
ForceFields::CrystalFF::TorsionAngleContribsParams::idx2
unsigned int idx2
Definition TorsionAngleContribs.h:33