RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
FourthDimContribs.h
Go to the documentation of this file.
1//
2// Copyright (C) 2024 Greg Landrum 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#include <RDGeneral/export.h>
11#ifndef RD_FOURTHDIMCONTRIBS_H
12#define RD_FOURTHDIMCONTRIBS_H
13
14#include <vector>
15#include <RDGeneral/Invariant.h>
16#include <ForceField/Contrib.h>
18
19namespace DistGeom {
20
22 unsigned int idx{0};
23 double weight{0.0};
24 FourthDimContribsParams(unsigned int idx, double w) : idx(idx), weight(w) {};
25};
26
27//! A term used in penalizing the 4th dimension in order to move from 4D->3D
28//!
31 public:
32 FourthDimContribs() = default;
33
34 //! Constructor
35 /*!
36 \param owner pointer to the owning ForceField
37 \param idx the index of the atom to be considered
38 \param weight (optional) the weight to be used for this contrib
39
40 */
42 PRECONDITION(owner, "bad force field");
43 PRECONDITION(owner->dimension() == 4, "force field has wrong dimension");
44 dp_forceField = owner;
45 }
46
47 void addContrib(unsigned int idx, double weight) {
48 d_contribs.emplace_back(idx, weight);
49 }
50
51 //! return the contribution of this contrib to the energy of a given state
52 double getEnergy(double *pos) const override {
53 PRECONDITION(pos, "bad vector");
54 constexpr unsigned int ffdim = 4;
55 double res = 0.0;
56 for (const auto &contrib : d_contribs) {
57 unsigned int pid = contrib.idx * ffdim + 3;
58 res += contrib.weight * pos[pid] * pos[pid];
59 }
60 return res;
61 }
62
63 //! calculate the contribution of this contrib to the gradient at a given
64 /// state
65 void getGrad(double *pos, double *grad) const override {
66 PRECONDITION(pos, "bad vector");
67 constexpr unsigned int ffdim = 4;
68 for (const auto &contrib : d_contribs) {
69 unsigned int pid = contrib.idx * ffdim + 3;
70 grad[pid] += contrib.weight * pos[pid];
71 }
72 }
73 FourthDimContribs *copy() const override {
74 return new FourthDimContribs(*this);
75 }
76 bool empty() const { return d_contribs.empty(); }
77 unsigned int size() const { return d_contribs.size(); }
78
79 private:
80 std::vector<FourthDimContribsParams> d_contribs;
81};
82} // namespace DistGeom
83
84#endif
#define PRECONDITION(expr, mess)
Definition Invariant.h:109
FourthDimContribs * copy() const override
return a copy
FourthDimContribs(ForceFields::ForceField *owner)
Constructor.
void addContrib(unsigned int idx, double weight)
double getEnergy(double *pos) const override
return the contribution of this contrib to the energy of a given state
void getGrad(double *pos, double *grad) const override
abstract base class for contributions to ForceFields
Definition Contrib.h:18
A class to store forcefields and handle minimization.
Definition ForceField.h:79
unsigned int dimension() const
returns the dimension of the forcefield
Definition ForceField.h:235
#define RDKIT_DISTGEOMETRY_EXPORT
Definition export.h:129
FourthDimContribsParams(unsigned int idx, double w)