RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
DistGeomUtils.h
Go to the documentation of this file.
1//
2// Copyright (C) 2004-2026 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_DISTGEOMUTILS_H_
12#define _RD_DISTGEOMUTILS_H_
13
14#include "BoundsMatrix.h"
15#include "ZMatrix.h"
16#include <Numerics/SymmMatrix.h>
17#include <map>
18#include <Geometry/point.h>
20#include "ChiralSet.h"
21#include <RDGeneral/utils.h>
22#include <boost/dynamic_bitset.hpp>
23
24namespace ForceFields {
25class ForceField;
26} // namespace ForceFields
27
28namespace DistGeom {
29
30//! Pick a distance matrix at random such that the
31//! distance satisfy the bounds in the BoundsMatrix
32/*!
33 \param mmat Bounds matrix
34 \param distmat Storage for randomly chosen distances
35 \param seed the random number seed to use
36
37 \return the largest element of the distance matrix
38 */
40 const BoundsMatrix &mmat, RDNumeric::SymmMatrix<double> &distmat,
41 int seed = -1);
42//! \overload
44 const BoundsMatrix &mmat, RDNumeric::SymmMatrix<double> &distmat,
46
47//! Compute an initial embedded in 3D based on a distance matrix
48/*!
49 This function follows the embed algorithm mentioned in
50 "Distance Geometry and Molecular Conformation" by G.M.Crippen and T.F.Havel
51 (pages 312-313)
52
53 \param distmat Distance matrix
54 \param positions A vector of pointers to Points to write out the resulting
55 coordinates
56 \param randNegEig If set to true and if any of the eigen values are negative,
57 we will
58 pick the corresponding components of the coordinates at
59 random
60 \param numZeroFail Fail embedding is more this many (or more) eigen values are
61 zero
62 \param seed the random number seed to use
63
64 \return true if the embedding was successful
65*/
67 const RDNumeric::SymmMatrix<double> &distmat,
68 RDGeom::PointPtrVect &positions, bool randNegEig = false,
69 unsigned int numZeroFail = 2, int seed = -1);
70//! \overload
72 const RDNumeric::SymmMatrix<double> &distmat,
74 bool randNegEig = false, unsigned int numZeroFail = 2);
75
76//! places atoms randomly in a box
77/*!
78 \param positions A vector of pointers to Points to write out the resulting
79 coordinates
80 \param boxSize the side-length of the cubic box
81 \param seed the random number seed to use
82
83 \return true if the coordinate generation was successful
84*/
86 RDGeom::PointPtrVect &positions, double boxSize, int seed = -1);
87//! \overload
89 RDGeom::PointPtrVect &positions, double boxSize,
91
92//! places atoms from a given Z-Matrix
93/*!
94 \param zmat The Z-Matrix
95 \param positions A vector of pointers to Points to write out the resulting
96 coordinates
97
98 \return true if the coordinate generation was successful (which is always the
99case here)
100*/
102 ZMatrix &zmat, RDGeom::PointPtrVect &positions, int seed = -1);
103//! \overload
105 ZMatrix &zmat, RDGeom::PointPtrVect &positions,
107
108//! Setup the error function for violation of distance bounds as a forcefield
109/*!
110 This is based on function E3 on page 311 of "Distance Geometry in Molecular
111 Modeling" Jeffrey M.Blaney and J.Scott Dixon, Review in Computational
112 Chemistry,
113 Volume V
114
115 \param mmat Distance bounds matrix
116 \param positions A vector of pointers to Points to write out the
117 resulting coordinates
118 \param csets The vector of chiral points (type: ChiralSet)
119 \param weightDistance weight to be used for distance bounds
120 \param weightChiral weight to be used to enforce chirality
121 \param weightFourthDim another chiral weight
122 \param extraWeights an optional set of weights for distance bounds
123 violations
124 \param basinSizeTol Optional: any distance bound with a basin (distance
125 between max and
126 min bounds) larger than this value will not be included
127 in the force
128 field used to cleanup the structure.
129
130 \return a pointer to a ForceField suitable for cleaning up the violations.
131 <b>NOTE:</b> the caller is responsible for deleting this force field.
132
133*/
135 const BoundsMatrix &mmat, const RDGeom::PointPtrVect &positions,
136 const VECT_CHIRALSET &csets, const double weightDistance = 1.0,
137 const double weightChiral = 1.0, const double weightFourthDim = 0.1,
138 const std::map<std::pair<int, int>, double> *extraWeights = nullptr,
139 const double basinSizeTol = 5.0,
140 const boost::dynamic_bitset<> *fixedPts = nullptr);
141
142//! Setup the error function for violation of distance bounds as a forcefield
143/*!
144 This is based on function E3 on page 311 of "Distance Geometry in Molecular
145 Modeling" Jeffrey M.Blaney and J.Scott Dixon, Review in Computational
146 Chemistry,
147 Volume V
148
149 \param mmat Distance bounds matrix
150 \param positions A vector of pointers to Points to write out the
151 resulting coordinates
152 \param csets The vector of chiral points (type: ChiralSet)
153 \param weightChiral weight to be used to enforce chirality
154 \param weightFourthDim another chiral weight
155 \param extraWeights an optional set of weights for distance bounds
156 violations
157 \param basinSizeTol Optional: any distance bound with a basin (distance
158 between max and
159 min bounds) larger than this value will not be included
160 in the force
161 field used to cleanup the structure.
162
163 \return a pointer to a ForceField suitable for cleaning up the violations.
164 <b>NOTE:</b> the caller is responsible for deleting this force field.
165
166*/
168 const BoundsMatrix &mmat, const RDGeom::PointPtrVect &positions,
169 const VECT_CHIRALSET &csets, const double weightChiral = 1.0,
170 const double weightFourthDim = 0.1,
171 const std::map<std::pair<int, int>, double> *extraWeights = nullptr,
172 const double basinSizeTol = 5.0,
173 const boost::dynamic_bitset<> *fixedPts = nullptr);
174
175//! Force field with experimental torsion angle preferences and 1-2/1-3 distance
176/// constraints
177/*!
178
179 \param mmat Distance bounds matrix
180 \param positions A vector of pointers to 3D Points to write out the
181 resulting coordinates
182 \param etkdgDetails Contains information about the ETKDG force field
183
184 <b>NOTE:</b> the caller is responsible for deleting this force field.
185
186*/
188 const BoundsMatrix &mmat, RDGeom::Point3DPtrVect &positions,
189 const ForceFields::CrystalFF::CrystalFFDetails &etkdgDetails);
190//! Force field with experimental torsion angle preferences and 1-2/1-3 distance
191/// constraints, as well as atom pairwise Columbic interactions
192/*!
193
194 \param mmat Distance bounds matrix
195 \param positions A vector of pointers to 3D Points to write out the
196 resulting coordinates
197 \param etkdgDetails Contains information about the ETKDG force field
198 \param CPCI Contains which atom pair(s) have what strength of
199 attractive/repulsive electrostatic interaction(s)
200
201 <b>NOTE:</b> the caller is responsible for deleting this force field.
202
203*/
205 const BoundsMatrix &mmat, RDGeom::Point3DPtrVect &positions,
207 const std::map<std::pair<unsigned int, unsigned int>, double> &CPCI);
208//! Force field with experimental torsion angle preferences and 1-2/1-3 distance
209/// constraints
210/*!
211
212 \param mmat Distance bounds matrix
213 \param positions A vector of pointers to 3D Points to write out the
214 resulting coordinates
215 \param etkdgDetails Contains information about the ETKDG force field
216
217 <b>NOTE:</b> the caller is responsible for deleting this force field.
218
219*/
221 const BoundsMatrix &mmat, RDGeom::Point3DPtrVect &positions,
222 const ForceFields::CrystalFF::CrystalFFDetails &etkdgDetails);
223
224//! Force field with improper terms and SP linearity contributions
225/*!
226
227 \param mmat Distance bounds matrix
228 \param positions A vector of pointers to 3D Points to write out the
229 resulting coordinates
230 \param improperAtoms A list of groups of 4 atom indices for inversion terms
231 \param angles List of lists with the three angle indices and whether
232 the center atom in the angle is SP hybridized for every angle in the molecule.
233 \param atomNums A list of atomic numbers for all atoms in the molecule,
234no longer used.
235
236 \return a pointer to a ForceField with improper terms
237 <b>NOTE:</b> the caller is responsible for deleting this force field.
238
239*/
242 const BoundsMatrix &mmat, RDGeom::Point3DPtrVect &positions,
243 const std::vector<std::vector<int>> &improperAtoms,
244 const std::vector<std::vector<int>> &angles,
245 const std::vector<int> &atomNums);
246
247//! Force field with improper terms and SP linearity contributions
248/*!
249
250 \param mmat Distance bounds matrix
251 \param positions A vector of pointers to 3D Points to write out the
252 resulting coordinates
253 \param etkdgDetails Contains information about the ETKDG force field
254
255 \return a pointer to a ForceField with improper terms
256 <b>NOTE:</b> the caller is responsible for deleting this force field.
257
258*/
259//! \overload
261 const BoundsMatrix &mmat, RDGeom::Point3DPtrVect &positions,
262 const ForceFields::CrystalFF::CrystalFFDetails &etkdgDetails) {
264 mmat, positions, etkdgDetails.improperAtoms, etkdgDetails.angles,
265 etkdgDetails.atomNums);
266}
267
268//! Force Field for All-In-One Minimization
269/*!
270
271 \param mmat Distance bounds matrix
272 \param positions A vector of pointers to Points to place in the field
273 \param etkdgDetails Contains information about the ETKDG force field
274 \param csets The vector of chiral points (type: ChiralSet)
275 \param extraWeights mapping from atom pair indices to double to overwrite the
276 force constants for the distance terms
277
278 \return a pointer to a ForceField for the All in One optimization
279 <b>NOTE:</b> the caller is responsible for deleting this force field.
280
281*/
283 const BoundsMatrix &mmat, RDGeom::PointPtrVect &positions,
285 const VECT_CHIRALSET *csets,
286 const std::map<std::pair<unsigned int, unsigned int>, double>
287 *extraWeights = nullptr,
288 const boost::dynamic_bitset<> *fixedPts = nullptr);
289
291 const BoundsMatrix &mmat, RDGeom::PointPtrVect &positions,
293 const VECT_CHIRALSET *csets,
294 const std::map<std::pair<unsigned int, unsigned int>, double> &CPCI,
295 const std::map<std::pair<unsigned int, unsigned int>, double>
296 *extraWeights = nullptr,
297 const boost::dynamic_bitset<> *fixedPts = nullptr);
298
302 const bool doK, const bool doET);
303
304} // namespace DistGeom
305
306#endif
Class to store the distance bound.
A class to store forcefields and handle minimization.
Definition ForceField.h:79
A symmetric matrix class.
Definition SymmMatrix.h:30
#define RDKIT_DISTGEOMETRY_EXPORT
Definition export.h:171
RDKIT_DISTGEOMETRY_EXPORT ForceFields::ForceField * constructAllInOneForceField(const BoundsMatrix &mmat, RDGeom::PointPtrVect &positions, const ForceFields::CrystalFF::CrystalFFDetails &etkdgDetails, const VECT_CHIRALSET *csets, const std::map< std::pair< unsigned int, unsigned int >, double > *extraWeights=nullptr, const boost::dynamic_bitset<> *fixedPts=nullptr)
Force Field for All-In-One Minimization.
RDKIT_DISTGEOMETRY_EXPORT ForceFields::ForceField * construct3DForceField(const BoundsMatrix &mmat, RDGeom::Point3DPtrVect &positions, const ForceFields::CrystalFF::CrystalFFDetails &etkdgDetails)
RDKIT_DISTGEOMETRY_EXPORT ForceFields::ForceField * construct3DImproperForceField(const BoundsMatrix &mmat, RDGeom::Point3DPtrVect &positions, const std::vector< std::vector< int > > &improperAtoms, const std::vector< std::vector< int > > &angles, const std::vector< int > &atomNums)
Force field with improper terms and SP linearity contributions.
RDKIT_DISTGEOMETRY_EXPORT ForceFields::ForceField * constructPlain3DForceField(const BoundsMatrix &mmat, RDGeom::Point3DPtrVect &positions, const ForceFields::CrystalFF::CrystalFFDetails &etkdgDetails)
std::vector< boost::shared_ptr< ChiralSet > > VECT_CHIRALSET
Definition Embedder.h:27
RDKIT_DISTGEOMETRY_EXPORT bool computeRandomCoords(RDGeom::PointPtrVect &positions, double boxSize, int seed=-1)
places atoms randomly in a box
RDKIT_DISTGEOMETRY_EXPORT bool computeInitialCoords(const RDNumeric::SymmMatrix< double > &distmat, RDGeom::PointPtrVect &positions, bool randNegEig=false, unsigned int numZeroFail=2, int seed=-1)
Compute an initial embedded in 3D based on a distance matrix.
RDKIT_DISTGEOMETRY_EXPORT void addTorsionTerms(ForceFields::ForceField *field, const ForceFields::CrystalFF::CrystalFFDetails &etkdgDetails, const bool doK, const bool doET)
RDKIT_DISTGEOMETRY_EXPORT double pickRandomDistMat(const BoundsMatrix &mmat, RDNumeric::SymmMatrix< double > &distmat, int seed=-1)
RDKIT_DISTGEOMETRY_EXPORT ForceFields::ForceField * constructForceField(const BoundsMatrix &mmat, const RDGeom::PointPtrVect &positions, const VECT_CHIRALSET &csets, const double weightDistance=1.0, const double weightChiral=1.0, const double weightFourthDim=0.1, const std::map< std::pair< int, int >, double > *extraWeights=nullptr, const double basinSizeTol=5.0, const boost::dynamic_bitset<> *fixedPts=nullptr)
Setup the error function for violation of distance bounds as a forcefield.
RDKIT_DISTGEOMETRY_EXPORT bool computeZMatrixCoords(ZMatrix &zmat, RDGeom::PointPtrVect &positions, int seed=-1)
places atoms from a given Z-Matrix
std::vector< RDGeom::Point * > PointPtrVect
Definition point.h:547
std::vector< RDGeom::Point3D * > Point3DPtrVect
Definition point.h:551
boost::variate_generator< rng_type &, uniform_double > double_source_type
Definition utils.h:49
std::vector< std::vector< int > > improperAtoms
std::vector< std::vector< int > > angles