RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
Embedder.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
11#include <RDGeneral/export.h>
12#ifndef RD_EMBEDDER_H_GUARD
13#define RD_EMBEDDER_H_GUARD
14
15#include <map>
16#include <utility>
17#include <Geometry/point.h>
18#include <GraphMol/ROMol.h>
19#include <boost/shared_ptr.hpp>
21
22namespace RDKit {
23namespace DGeomHelpers {
24
43
44//! Parameter object for controlling embedding
45/*!
46 numConfs Number of conformations to be generated
47 numThreads Sets the number of threads to use (more than one thread
48 will only be used if the RDKit was build with multithread
49 support) If set to zero, the max supported by the system will
50 be used.
51 maxIterations Max. number of times the embedding will be tried if
52 coordinates are not obtained successfully. The default
53 value is 10x the number of atoms.
54 randomSeed provides a seed for the random number generator (so that
55 the same coordinates can be obtained for a
56 molecule on multiple runs) If -1, the
57 RNG will not be seeded.
58 clearConfs Clear all existing conformations on the molecule
59 useRandomCoords Start the embedding from random coordinates instead of
60 using eigenvalues of the distance matrix.
61 boxSizeMult Determines the size of the box that is used for
62 random coordinates. If this is a positive number, the
63 side length will equal the largest element of the distance
64 matrix times \c boxSizeMult. If this is a negative number,
65 the side length will equal \c -boxSizeMult (i.e. independent
66 of the elements of the distance matrix).
67 randNegEig Picks coordinates at random when a embedding process produces
68 negative eigenvalues
69 numZeroFail Fail embedding if we find this many or more zero eigenvalues
70 (within a tolerance)
71 pruneRmsThresh Retain only the conformations out of 'numConfs' after
72 embedding that are at least this far apart from each other.
73 RMSD is computed on the heavy atoms.
74 Prunining is greedy; i.e. the first embedded conformation is
75 retained and from then on only those that are at least
76 \c pruneRmsThresh away from already
77 retained conformations are kept. The pruning is done
78 after embedding and bounds violation minimization.
79 No pruning by default.
80 coordMap a map of int to Point3D, between atom IDs and their locations
81 their locations. If this container is provided, the
82 coordinates are used to set distance constraints on the
83 embedding. The resulting conformer(s) should have distances
84 between the specified atoms that reproduce those between the
85 points in \c coordMap. Because the embedding produces a
86 molecule in an arbitrary reference frame, an alignment step
87 is required to actually reproduce the provided coordinates.
88 optimizerForceTol set the tolerance on forces in the DGeom optimizer
89 (this shouldn't normally be altered in client code).
90 ignoreSmoothingFailures try to embed the molecule even if triangle bounds
91 smoothing fails
92 enforceChirality enforce the correct chirality if chiral centers are present
93 useExpTorsionAnglePrefs impose experimental torsion-angle preferences
94 useBasicKnowledge impose "basic knowledge" terms such as flat
95 aromatic rings, ketones, etc.
96 ETversion version of the experimental torsion-angle preferences
97 verbose print output of experimental torsion-angle preferences
98 basinThresh set the basin threshold for the DGeom force field,
99 (this shouldn't normally be altered in client code).
100 onlyHeavyAtomsForRMS only use the heavy atoms when doing RMS filtering
101 boundsMat custom bound matrix to specify upper and lower bounds of atom
102 pairs
103 embedFragmentsSeparately embed each fragment of molecule in turn
104 useSmallRingTorsions optional torsions to improve small ring conformer
105 sampling
106 useMacrocycleTorsions optional torsions to improve macrocycle conformer
107 sampling
108 useMacrocycle14config If 1-4 distances bound heuristics for
109 macrocycles is used
110 timeout time out in seconds
111 CPCI custom columbic interactions between atom pairs
112 callback void pointer to a function for reporting progress,
113 will be called with the current iteration number.
114 forceTransAmides constrain amide bonds to be trans.
115 useSymmetryForPruning use molecule symmetry when doing the RMSD pruning.
116 NOTE that for reasons of computational efficiency,
117 setting this will also set onlyHeavyAtomsForRMS to
118 true.
119 trackFailures keep track of which checks during the embedding process fail
120 failures if trackFailures is true, this is used to track the number
121 of times each embedding check fails
122 enableSequentialRandomSeeds handle the random number seeds so that
123 conformer generation can be restarted
124*/
126 unsigned int maxIterations{0};
128 int randomSeed{-1};
129 bool clearConfs{true};
130 bool useRandomCoords{false};
131 double boxSizeMult{2.0};
132 bool randNegEig{true};
133 unsigned int numZeroFail{1};
134 const std::map<int, RDGeom::Point3D> *coordMap{nullptr};
135 double optimizerForceTol{1e-3};
139 bool useBasicKnowledge{false};
140 bool verbose{false};
141 double basinThresh{5.0};
142 double pruneRmsThresh{-1.0};
144 unsigned int ETversion{2};
145 boost::shared_ptr<const DistGeom::BoundsMatrix> boundsMat{nullptr};
150 unsigned int timeout{0};
152 std::shared_ptr<std::map<std::pair<unsigned int, unsigned int>, double>> CPCI{
153 nullptr};
154 void (*callback)(unsigned int){nullptr};
158 bool trackFailures{false};
159 std::vector<unsigned int> failures{};
162};
163
164//! update parameters from a JSON string
166 EmbedParameters &params, const std::string &json);
167
168//! export parameters to JSON string
170 const EmbedParameters &params);
171
172//! Embed multiple conformations for a molecule
174 unsigned int numConfs,
175 EmbedParameters &params);
176inline INT_VECT EmbedMultipleConfs(ROMol &mol, unsigned int numConfs,
177 EmbedParameters &params) {
178 INT_VECT res;
179 EmbedMultipleConfs(mol, res, numConfs, params);
180 return res;
181}
182
183//! Compute an embedding (in 3D) for the specified molecule using Distance
184/// Geometry
185inline int EmbedMolecule(ROMol &mol, EmbedParameters &params) {
186 INT_VECT confIds;
187 EmbedMultipleConfs(mol, confIds, 1, params);
188
189 int res;
190 if (confIds.size()) {
191 res = confIds[0];
192 } else {
193 res = -1;
194 }
195 return res;
196}
197
198//! Compute an embedding (in 3D) for the specified molecule using Distance
199/// Geometry
200/*!
201 The following operations are performed (in order) here:
202 -# Build a distance bounds matrix based on the topology, including 1-5
203 distances but not VDW scaling
204 -# Triangle smooth this bounds matrix
205 -# If step 2 fails - repeat step 1, this time without 1-5 bounds and with vdW
206 scaling, and repeat step 2
207 -# Pick a distance matrix at random using the bounds matrix
208 -# Compute initial coordinates from the distance matrix
209 -# Repeat steps 3 and 4 until maxIterations is reached or embedding is
210 successful
211 -# Adjust initial coordinates by minimizing a Distance Violation error
212 function
213 **NOTE**: if the molecule has multiple fragments, they will be embedded
214 separately,
215 this means that they will likely occupy the same region of space.
216 \param mol Molecule of interest
217 \param maxIterations Max. number of times the embedding will be tried if
218 coordinates are not obtained successfully. The default
219 value is 10x the number of atoms.
220 \param seed provides a seed for the random number generator (so that
221 the same coordinates can be obtained for a molecule on
222 multiple runs). If negative, the RNG will not be seeded.
223 \param clearConfs Clear all existing conformations on the molecule
224 \param useRandomCoords Start the embedding from random coordinates instead of
225 using eigenvalues of the distance matrix.
226 \param boxSizeMult Determines the size of the box that is used for
227 random coordinates. If this is a positive number, the
228 side length will equal the largest element of the
229 distance matrix times \c boxSizeMult. If this is a
230 negative number, the side length will equal
231 \c -boxSizeMult (i.e. independent of the elements of the
232 distance matrix).
233 \param randNegEig Picks coordinates at random when a embedding process
234 produces negative eigenvalues
235 \param numZeroFail Fail embedding if we find this many or more zero
236 eigenvalues (within a tolerance)
237 \param coordMap a map of int to Point3D, between atom IDs and their locations
238 their locations. If this container is provided, the
239 coordinates are used to set distance constraints on the
240 embedding. The resulting conformer(s) should have distances
241 between the specified atoms that reproduce those between the
242 points in \c coordMap. Because the embedding produces a
243 molecule in an arbitrary reference frame, an alignment step
244 is required to actually reproduce the provided coordinates.
245 \param optimizerForceTol set the tolerance on forces in the distgeom optimizer
246 (this shouldn't normally be altered in client code).
247 \param ignoreSmoothingFailures try to embed the molecule even if triangle
248 bounds smoothing fails
249 \param enforceChirality enforce the correct chirality if chiral centers are
250 present
251 \param useExpTorsionAnglePrefs impose experimental torsion-angle preferences
252 \param useBasicKnowledge impose "basic knowledge" terms such as flat
253 aromatic rings, ketones, etc.
254 \param verbose print output of experimental torsion-angle preferences
255 \param basinThresh set the basin threshold for the DGeom force field,
256 (this shouldn't normally be altered in client code).
257 \param onlyHeavyAtomsForRMS only use the heavy atoms when doing RMS filtering
258 \param ETversion version of torsion preferences to use
259 \param useSmallRingTorsions optional torsions to improve small ring
260 conformer sampling
261 \param useMacrocycleTorsions optional torsions to improve macrocycle
262 conformer sampling
263 \param useMacrocycle14config If 1-4 distances bound heuristics for
264 macrocycles is used
265
266 \return ID of the conformer added to the molecule, -1 if the emdedding failed
267*/
268inline int EmbedMolecule(
269 ROMol &mol, unsigned int maxIterations = 0, int seed = -1,
270 bool clearConfs = true, bool useRandomCoords = false,
271 double boxSizeMult = 2.0, bool randNegEig = true,
272 unsigned int numZeroFail = 1,
273 const std::map<int, RDGeom::Point3D> *coordMap = nullptr,
274 double optimizerForceTol = 1e-3, bool ignoreSmoothingFailures = false,
275 bool enforceChirality = true, bool useExpTorsionAnglePrefs = false,
276 bool useBasicKnowledge = false, bool verbose = false,
277 double basinThresh = 5.0, bool onlyHeavyAtomsForRMS = false,
278 unsigned int ETversion = 2, bool useSmallRingTorsions = false,
279 bool useMacrocycleTorsions = true, bool useMacrocycle14config = true) {
280 EmbedParameters params{.maxIterations = maxIterations,
281 .randomSeed = seed,
282 .clearConfs = clearConfs,
283 .useRandomCoords = useRandomCoords,
284 .boxSizeMult = boxSizeMult,
285 .randNegEig = randNegEig,
286 .numZeroFail = numZeroFail,
287 .coordMap = coordMap,
288 .optimizerForceTol = optimizerForceTol,
289 .ignoreSmoothingFailures = ignoreSmoothingFailures,
290 .enforceChirality = enforceChirality,
291 .useExpTorsionAnglePrefs = useExpTorsionAnglePrefs,
292 .useBasicKnowledge = useBasicKnowledge,
293 .verbose = verbose,
294 .basinThresh = basinThresh,
295 .onlyHeavyAtomsForRMS = onlyHeavyAtomsForRMS,
296 .ETversion = ETversion,
297 .useSmallRingTorsions = useSmallRingTorsions,
298 .useMacrocycleTorsions = useMacrocycleTorsions,
299 .useMacrocycle14config = useMacrocycle14config};
300
301 return EmbedMolecule(mol, params);
302};
303
304//*! Embed multiple conformations for a molecule
305/*!
306 This is kind of equivalent to calling EmbedMolecule multiple times - just that
307 the bounds
308 matrix is computed only once from the topology
309 **NOTE**: if the molecule has multiple fragments, they will be embedded
310 separately,
311 this means that they will likely occupy the same region of space.
312 \param mol Molecule of interest
313 \param res Used to return the resulting conformer ids
314 \param numConfs Number of conformations to be generated
315 \param numThreads Sets the number of threads to use (more than one thread
316 will only be used if the RDKit was built with
317 multithread
318 support). If set to zero, the max supported by the
319 system
320 will be used.
321 \param maxIterations Max. number of times the embedding will be tried if
322 coordinates are not obtained successfully. The default
323 value is 10x the number of atoms.
324 \param seed provides a seed for the random number generator (so that
325 the same coordinates can be obtained for a molecule on
326 multiple runs). If negative, the RNG will not be seeded.
327 \param clearConfs Clear all existing conformations on the molecule
328 \param useRandomCoords Start the embedding from random coordinates instead of
329 using eigenvalues of the distance matrix.
330 \param boxSizeMult Determines the size of the box that is used for
331 random coordinates. If this is a positive number, the
332 side length will equal the largest element of the
333 distance matrix times \c boxSizeMult. If this is a
334 negative number, the side length will equal
335 \c -boxSizeMult (i.e. independent of the elements of the
336 distance matrix).
337 \param randNegEig Picks coordinates at random when a embedding process
338 produces negative eigenvalues
339 \param numZeroFail Fail embedding if we find this many or more zero
340 eigenvalues (within a tolerance)
341 \param pruneRmsThresh Retain only the conformations out of 'numConfs' after
342 embedding that are at least this far apart from each
343 other. RMSD is computed on the heavy atoms.
344 Pruning is greedy; i.e. the first embedded conformation
345 is retained and from then on only those that are at
346 least
347 pruneRmsThresh away from already retained conformations
348 are kept. The pruning is done after embedding and
349 bounds violation minimization. No pruning by default.
350 \param coordMap a map of int to Point3D, between atom IDs and their locations
351 their locations. If this container is provided, the
352 coordinates are used to set distance constraints on the
353 embedding. The resulting conformer(s) should have distances
354 between the specified atoms that reproduce those between the
355 points in \c coordMap. Because the embedding produces a
356 molecule in an arbitrary reference frame, an alignment step
357 is required to actually reproduce the provided coordinates.
358 \param optimizerForceTol set the tolerance on forces in the DGeom optimizer
359 (this shouldn't normally be altered in client code).
360 \param ignoreSmoothingFailures try to embed the molecule even if triangle
361 bounds smoothing fails
362 \param enforceChirality enforce the correct chirality if chiral centers are
363 present
364 \param useExpTorsionAnglePrefs impose experimental torsion-angle preferences
365 \param useBasicKnowledge impose "basic knowledge" terms such as flat
366 aromatic rings, ketones, etc.
367 \param verbose print output of experimental torsion-angle preferences
368 \param basinThresh set the basin threshold for the DGeom force field,
369 (this shouldn't normally be altered in client code).
370 \param onlyHeavyAtomsForRMS only use the heavy atoms when doing RMS filtering
371 \param ETversion version of torsion preferences to use
372 \param useSmallRingTorsions optional torsions to improve small ring
373 conformer sampling
374 \param useMacrocycleTorsions optional torsions to improve macrocycle
375 conformer sampling
376 \param useMacrocycle14config If 1-4 distances bound heuristics for
377 macrocycles is used
378
379*/
381 ROMol &mol, INT_VECT &res, unsigned int numConfs = 10, int numThreads = 1,
382 unsigned int maxIterations = 30, int seed = -1, bool clearConfs = true,
383 bool useRandomCoords = false, double boxSizeMult = 2.0,
384 bool randNegEig = true, unsigned int numZeroFail = 1,
385 double pruneRmsThresh = -1.0,
386 const std::map<int, RDGeom::Point3D> *coordMap = nullptr,
387 double optimizerForceTol = 1e-3, bool ignoreSmoothingFailures = false,
388 bool enforceChirality = true, bool useExpTorsionAnglePrefs = false,
389 bool useBasicKnowledge = false, bool verbose = false,
390 double basinThresh = 5.0, bool onlyHeavyAtomsForRMS = false,
391 unsigned int ETversion = 2, bool useSmallRingTorsions = false,
392 bool useMacrocycleTorsions = true, bool useMacrocycle14config = true,
393 unsigned int timeout = 0) {
394 EmbedParameters params{.maxIterations = maxIterations,
395 .numThreads = numThreads,
396 .randomSeed = seed,
397 .clearConfs = clearConfs,
398 .useRandomCoords = useRandomCoords,
399 .boxSizeMult = boxSizeMult,
400 .randNegEig = randNegEig,
401 .numZeroFail = numZeroFail,
402 .coordMap = coordMap,
403 .optimizerForceTol = optimizerForceTol,
404 .ignoreSmoothingFailures = ignoreSmoothingFailures,
405 .enforceChirality = enforceChirality,
406 .useExpTorsionAnglePrefs = useExpTorsionAnglePrefs,
407 .useBasicKnowledge = useBasicKnowledge,
408 .verbose = verbose,
409 .basinThresh = basinThresh,
410 .pruneRmsThresh = pruneRmsThresh,
411 .onlyHeavyAtomsForRMS = onlyHeavyAtomsForRMS,
412 .ETversion = ETversion,
413 .useSmallRingTorsions = useSmallRingTorsions,
414 .useMacrocycleTorsions = useMacrocycleTorsions,
415 .useMacrocycle14config = useMacrocycle14config,
416 .timeout = timeout};
417 EmbedMultipleConfs(mol, res, numConfs, params);
418};
419//! \overload
421 ROMol &mol, unsigned int numConfs = 10, unsigned int maxIterations = 30,
422 int seed = -1, bool clearConfs = true, bool useRandomCoords = false,
423 double boxSizeMult = 2.0, bool randNegEig = true,
424 unsigned int numZeroFail = 1, double pruneRmsThresh = -1.0,
425 const std::map<int, RDGeom::Point3D> *coordMap = nullptr,
426 double optimizerForceTol = 1e-3, bool ignoreSmoothingFailures = false,
427 bool enforceChirality = true, bool useExpTorsionAnglePrefs = false,
428 bool useBasicKnowledge = false, bool verbose = false,
429 double basinThresh = 5.0, bool onlyHeavyAtomsForRMS = false,
430 unsigned int ETversion = 2, bool useSmallRingTorsions = false,
431 bool useMacrocycleTorsions = false, bool useMacrocycle14config = false,
432 unsigned int timeout = 0) {
433 EmbedParameters params{.maxIterations = maxIterations,
434 .numThreads = 1,
435 .randomSeed = seed,
436 .clearConfs = clearConfs,
437 .useRandomCoords = useRandomCoords,
438 .boxSizeMult = boxSizeMult,
439 .randNegEig = randNegEig,
440 .numZeroFail = numZeroFail,
441 .coordMap = coordMap,
442 .optimizerForceTol = optimizerForceTol,
443 .ignoreSmoothingFailures = ignoreSmoothingFailures,
444 .enforceChirality = enforceChirality,
445 .useExpTorsionAnglePrefs = useExpTorsionAnglePrefs,
446 .useBasicKnowledge = useBasicKnowledge,
447 .verbose = verbose,
448 .basinThresh = basinThresh,
449 .pruneRmsThresh = pruneRmsThresh,
450 .onlyHeavyAtomsForRMS = onlyHeavyAtomsForRMS,
451 .ETversion = ETversion,
452 .useSmallRingTorsions = useSmallRingTorsions,
453 .useMacrocycleTorsions = useMacrocycleTorsions,
454 .useMacrocycle14config = useMacrocycle14config,
455 .timeout = timeout};
456 INT_VECT res;
457 EmbedMultipleConfs(mol, res, numConfs, params);
458 return res;
459};
460
461//! Parameters corresponding to plain Distance Geometry
462RDKIT_DISTGEOMHELPERS_EXPORT extern const EmbedParameters DG;
463//! Parameters corresponding to Sereina Riniker's KDG approach
464RDKIT_DISTGEOMHELPERS_EXPORT extern const EmbedParameters KDG;
465//! Parameters corresponding to Sereina Riniker's ETDG approach
466RDKIT_DISTGEOMHELPERS_EXPORT extern const EmbedParameters ETDG;
467//! Parameters corresponding to Sereina Riniker's ETDG approach - version 2
468RDKIT_DISTGEOMHELPERS_EXPORT extern const EmbedParameters ETDGv2;
469//! Parameters corresponding to Sereina Riniker's ETKDG approach
470RDKIT_DISTGEOMHELPERS_EXPORT extern const EmbedParameters ETKDG;
471//! Parameters corresponding to Sereina Riniker's ETKDG approach - version 2
472RDKIT_DISTGEOMHELPERS_EXPORT extern const EmbedParameters ETKDGv2;
473//! Parameters corresponding improved ETKDG by Wang, Witek, Landrum and Riniker
474//! (10.1021/acs.jcim.0c00025) - the macrocycle part
475RDKIT_DISTGEOMHELPERS_EXPORT extern const EmbedParameters ETKDGv3;
476//! Parameters corresponding improved ETKDG by Wang, Witek, Landrum and Riniker
477//! (10.1021/acs.jcim.0c00025) - the small ring part
478RDKIT_DISTGEOMHELPERS_EXPORT extern const EmbedParameters srETKDGv3;
479} // namespace DGeomHelpers
480} // namespace RDKit
481
482#endif
Defines the primary molecule class ROMol as well as associated typedefs.
#define RDKIT_DISTGEOMHELPERS_EXPORT
Definition export.h:129
RDKIT_DISTGEOMHELPERS_EXPORT const EmbedParameters ETKDGv2
Parameters corresponding to Sereina Riniker's ETKDG approach - version 2.
RDKIT_DISTGEOMHELPERS_EXPORT const EmbedParameters ETDG
Parameters corresponding to Sereina Riniker's ETDG approach.
RDKIT_DISTGEOMHELPERS_EXPORT const EmbedParameters ETKDGv3
RDKIT_DISTGEOMHELPERS_EXPORT const EmbedParameters DG
Parameters corresponding to plain Distance Geometry.
RDKIT_DISTGEOMHELPERS_EXPORT void updateEmbedParametersFromJSON(EmbedParameters &params, const std::string &json)
update parameters from a JSON string
RDKIT_DISTGEOMHELPERS_EXPORT const EmbedParameters ETKDG
Parameters corresponding to Sereina Riniker's ETKDG approach.
RDKIT_DISTGEOMHELPERS_EXPORT void EmbedMultipleConfs(ROMol &mol, INT_VECT &res, unsigned int numConfs, EmbedParameters &params)
Embed multiple conformations for a molecule.
RDKIT_DISTGEOMHELPERS_EXPORT std::string embedParametersToJSON(const EmbedParameters &params)
export parameters to JSON string
int EmbedMolecule(ROMol &mol, EmbedParameters &params)
Definition Embedder.h:185
RDKIT_DISTGEOMHELPERS_EXPORT const EmbedParameters srETKDGv3
RDKIT_DISTGEOMHELPERS_EXPORT const EmbedParameters KDG
Parameters corresponding to Sereina Riniker's KDG approach.
RDKIT_DISTGEOMHELPERS_EXPORT const EmbedParameters ETDGv2
Parameters corresponding to Sereina Riniker's ETDG approach - version 2.
Std stuff.
std::vector< int > INT_VECT
Definition types.h:224
Parameter object for controlling embedding.
Definition Embedder.h:125
void(* callback)(unsigned int)
Definition Embedder.h:154
std::vector< unsigned int > failures
Definition Embedder.h:159
const std::map< int, RDGeom::Point3D > * coordMap
Definition Embedder.h:134
boost::shared_ptr< const DistGeom::BoundsMatrix > boundsMat
Definition Embedder.h:145
std::shared_ptr< std::map< std::pair< unsigned int, unsigned int >, double > > CPCI
Definition Embedder.h:152