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