RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
MolTransforms.h
Go to the documentation of this file.
1//
2// Copyright (C) 2003-2006 Rational Discovery LLC
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_MOLTRANSFORMS_H_
12#define _RD_MOLTRANSFORMS_H_
13
14#include <Geometry/point.h>
15#include <Numerics/SymmMatrix.h>
16
17#ifdef RDK_HAS_EIGEN3
18// only the Matrix3d/Vector3d typedefs are needed in the declarations below;
19// Eigen/Core provides them and is far lighter than Eigen/Dense. The
20// implementation (MolTransforms.cpp) pulls in Eigen/Dense for the solver.
21#include <Eigen/Core>
22#endif
23
24namespace RDKit {
25class ROMol;
26class Atom;
27class Conformer;
28} // namespace RDKit
29
30namespace RDGeom {
31class Transform3D;
32}
33
34namespace MolTransforms {
36 RDGeom::Transform3D &tform);
38 RDGeom::Transform3D &tform);
39
40//! Compute the centroid of a conformer
41/*!
42 This is simple the average of the heavy atom locations in the conformer,
43 not attention is paid to hydrogens or the differences in atomic radii
44
45 \param conf Conformer of interest
46 \param ignoreHs If true, ignore hydrogen atoms
47 \param weights If present, used to weigh the atomic coordinates
48*/
50 const RDKit::Conformer &conf, bool ignoreHs = true,
51 const std::vector<double> *weights = nullptr);
52
53#ifdef RDK_HAS_EIGEN3
54//! Compute principal axes and moments of inertia for a conformer
55/*!
56 These values are calculated from the inertia tensor:
57 Iij = - sum_{s=1..N}(w_s * r_{si} * r_{sj}) i != j
58 Iii = sum_{s=1..N} sum_{j!=i} (w_s * r_{sj} * r_{sj})
59 where the coordinates are relative to the center of mass.
60
61
62 \param conf Conformer of interest
63 \param axes used to return the principal axes
64 \param moments used to return the principal moments
65 \param ignoreHs If true, ignore hydrogen atoms
66 \param force If true, the calculation will be carried out even if a
67 cached value is present
68 \param weights If present, used to weigh the atomic coordinates
69
70 \returns whether or not the calculation was successful
71*/
72RDKIT_MOLTRANSFORMS_EXPORT bool computePrincipalAxesAndMoments(
73 const RDKit::Conformer &conf, Eigen::Matrix3d &axes,
74 Eigen::Vector3d &moments, bool ignoreHs = false, bool force = false,
75 const std::vector<double> *weights = nullptr);
76//! Compute principal axes and moments from the gyration matrix of a conformer
77/*!
78
79 These values are calculated from the gyration matrix/tensor:
80 Iij = sum_{s=1..N}(w_s * r_{si} * r_{sj}) i != j
81 Iii = sum_{s=1..N} sum_{t!=s}(w_s * r_{si} * r_{ti})
82 where the coordinates are relative to the center of mass.
83
84 \param conf Conformer of interest
85 \param axes used to return the principal axes
86 \param moments used to return the principal moments
87 \param ignoreHs If true, ignore hydrogen atoms
88 \param force If true, the calculation will be carried out even if a
89 cached value is present
90 \param weights If present, used to weigh the atomic coordinates
91
92 \returns whether or not the calculation was successful
93*/
95computePrincipalAxesAndMomentsFromGyrationMatrix(
96 const RDKit::Conformer &conf, Eigen::Matrix3d &axes,
97 Eigen::Vector3d &moments, bool ignoreHs = false, bool force = false,
98 const std::vector<double> *weights = nullptr);
99#endif
100
101//! Compute the transformation required to orient the conformation
102//! along the principal axes about the center; i.e. center is made to coincide
103/// with the
104//! origin, the largest principal axis with the x-axis, the next largest with
105/// the y-axis
106//! and the smallest with the z-axis
107/*!
108 If center is not specified the centroid of the conformer will be used
109 \param conf Conformer of interest
110 \param center Center to be used for canonicalization, defaults to
111 the centroid of the
112 conformation
113 \param normalizeCovar Normalize the covariance matrix with the number of
114 atoms
115 \param ignoreHs Optionally ignore hydrogens
116 \param eigenVals Optionally return the values for the eigenvalues,
117 sorted in ascending order. If given, must be big enough to hold 3 values.
118*/
120 const RDKit::Conformer &conf, const RDGeom::Point3D *center = nullptr,
121 bool normalizeCovar = false, bool ignoreHs = true,
122 double *eigenVals = nullptr);
123
124//! Transform the conformation using the specified transformation
126 RDKit::Conformer &conf, const RDGeom::Transform3D &trans);
127
128//! Transforms coordinates in a molecule's substance groups
130 RDKit::ROMol &mol, const RDGeom::Transform3D &trans);
131
132//! Canonicalize the orientation of a conformer so that its principal axes
133//! around the specified center point coincide with the x, y, z axes
134/*!
135 \param conf The conformer of interest
136 \param center Optional center point about which the principal axes are
137 computed
138 if not specified the centroid of the conformer will be
139 used
140 \param normalizeCovar Optionally normalize the covariance matrix by the number
141 of atoms
142 \param ignoreHs If true, ignore hydrogen atoms
143
144*/
146 RDKit::Conformer &conf, const RDGeom::Point3D *center = nullptr,
147 bool normalizeCovar = false, bool ignoreHs = true);
148
149//! Canonicalize all the conformations in a molecule
150/*!
151 \param mol the molecule of interest
152 \param normalizeCovar Optionally normalize the covariance matrix by the number
153 of atoms
154 \param ignoreHs If true, ignore hydrogens
155*/
157 bool normalizeCovar = false,
158 bool ignoreHs = true);
159
160//! Get the bond length between the specified atoms i, j
162 unsigned int iAtomId,
163 unsigned int jAtomId);
164
165//! Set the bond length between the specified atoms i, j
166//! (all atoms bonded to atom j are moved)
168 unsigned int iAtomId,
169 unsigned int jAtomId,
170 double value);
171
172//! Get the angle in radians among the specified atoms i, j, k
174 unsigned int iAtomId,
175 unsigned int jAtomId,
176 unsigned int kAtomId);
177
178//! Get the angle in degrees among the specified atoms i, j, k
179inline double getAngleDeg(const RDKit::Conformer &conf, unsigned int iAtomId,
180 unsigned int jAtomId, unsigned int kAtomId) {
181 return (180. / M_PI * getAngleRad(conf, iAtomId, jAtomId, kAtomId));
182}
183
184//! Set the angle in radians among the specified atoms i, j, k
185//! (all atoms bonded to atom k are moved)
187 unsigned int iAtomId,
188 unsigned int jAtomId,
189 unsigned int kAtomId, double value);
190
191//! Set the angle in degrees among the specified atoms i, j, k
192//! (all atoms bonded to atom k are moved)
193inline void setAngleDeg(RDKit::Conformer &conf, unsigned int iAtomId,
194 unsigned int jAtomId, unsigned int kAtomId,
195 double value) {
196 setAngleRad(conf, iAtomId, jAtomId, kAtomId, value / 180. * M_PI);
197}
198
199//! Get the dihedral angle in radians among the specified atoms i, j, k, l
201 unsigned int iAtomId,
202 unsigned int jAtomId,
203 unsigned int kAtomId,
204 unsigned int lAtomId);
205
206//! Get the dihedral angle in degrees among the specified atoms i, j, k, l
207inline double getDihedralDeg(const RDKit::Conformer &conf, unsigned int iAtomId,
208 unsigned int jAtomId, unsigned int kAtomId,
209 unsigned int lAtomId) {
210 return (180. / M_PI *
211 getDihedralRad(conf, iAtomId, jAtomId, kAtomId, lAtomId));
212}
213
214//! Set the dihedral angle in radians among the specified atoms i, j, k, l
215//! (all atoms bonded to atom l are moved)
217 RDKit::Conformer &conf, unsigned int iAtomId, unsigned int jAtomId,
218 unsigned int kAtomId, unsigned int lAtomId, double value);
219
220//! Set the dihedral angle in degrees among the specified atoms i, j, k, l
221//! (all atoms bonded to atom l are moved)
222inline void setDihedralDeg(RDKit::Conformer &conf, unsigned int iAtomId,
223 unsigned int jAtomId, unsigned int kAtomId,
224 unsigned int lAtomId, double value) {
225 setDihedralRad(conf, iAtomId, jAtomId, kAtomId, lAtomId, value / 180. * M_PI);
226}
227} // namespace MolTransforms
228#endif
#define M_PI
Definition MMFF/Params.h:25
The class for representing atoms.
Definition Atom.h:74
The class for representing 2D or 3D conformation of a molecule.
Definition Conformer.h:46
#define RDKIT_MOLTRANSFORMS_EXPORT
Definition export.h:385
RDKIT_MOLTRANSFORMS_EXPORT void transformMolSubstanceGroups(RDKit::ROMol &mol, const RDGeom::Transform3D &trans)
Transforms coordinates in a molecule's substance groups.
RDKIT_MOLTRANSFORMS_EXPORT void canonicalizeConformer(RDKit::Conformer &conf, const RDGeom::Point3D *center=nullptr, bool normalizeCovar=false, bool ignoreHs=true)
RDKIT_MOLTRANSFORMS_EXPORT void setBondLength(RDKit::Conformer &conf, unsigned int iAtomId, unsigned int jAtomId, double value)
RDKIT_MOLTRANSFORMS_EXPORT void setDihedralRad(RDKit::Conformer &conf, unsigned int iAtomId, unsigned int jAtomId, unsigned int kAtomId, unsigned int lAtomId, double value)
RDKIT_MOLTRANSFORMS_EXPORT void transformMolsAtoms(RDKit::ROMol *mol, RDGeom::Transform3D &tform)
double getAngleDeg(const RDKit::Conformer &conf, unsigned int iAtomId, unsigned int jAtomId, unsigned int kAtomId)
Get the angle in degrees among the specified atoms i, j, k.
RDKIT_MOLTRANSFORMS_EXPORT void transformConformer(RDKit::Conformer &conf, const RDGeom::Transform3D &trans)
Transform the conformation using the specified transformation.
RDKIT_MOLTRANSFORMS_EXPORT RDGeom::Transform3D * computeCanonicalTransform(const RDKit::Conformer &conf, const RDGeom::Point3D *center=nullptr, bool normalizeCovar=false, bool ignoreHs=true, double *eigenVals=nullptr)
RDKIT_MOLTRANSFORMS_EXPORT RDGeom::Point3D computeCentroid(const RDKit::Conformer &conf, bool ignoreHs=true, const std::vector< double > *weights=nullptr)
Compute the centroid of a conformer.
RDKIT_MOLTRANSFORMS_EXPORT void canonicalizeMol(RDKit::ROMol &mol, bool normalizeCovar=false, bool ignoreHs=true)
Canonicalize all the conformations in a molecule.
RDKIT_MOLTRANSFORMS_EXPORT double getDihedralRad(const RDKit::Conformer &conf, unsigned int iAtomId, unsigned int jAtomId, unsigned int kAtomId, unsigned int lAtomId)
Get the dihedral angle in radians among the specified atoms i, j, k, l.
void setAngleDeg(RDKit::Conformer &conf, unsigned int iAtomId, unsigned int jAtomId, unsigned int kAtomId, double value)
RDKIT_MOLTRANSFORMS_EXPORT void transformAtom(RDKit::Atom *atom, RDGeom::Transform3D &tform)
RDKIT_MOLTRANSFORMS_EXPORT void setAngleRad(RDKit::Conformer &conf, unsigned int iAtomId, unsigned int jAtomId, unsigned int kAtomId, double value)
RDKIT_MOLTRANSFORMS_EXPORT double getBondLength(const RDKit::Conformer &conf, unsigned int iAtomId, unsigned int jAtomId)
Get the bond length between the specified atoms i, j.
void setDihedralDeg(RDKit::Conformer &conf, unsigned int iAtomId, unsigned int jAtomId, unsigned int kAtomId, unsigned int lAtomId, double value)
double getDihedralDeg(const RDKit::Conformer &conf, unsigned int iAtomId, unsigned int jAtomId, unsigned int kAtomId, unsigned int lAtomId)
Get the dihedral angle in degrees among the specified atoms i, j, k, l.
RDKIT_MOLTRANSFORMS_EXPORT double getAngleRad(const RDKit::Conformer &conf, unsigned int iAtomId, unsigned int jAtomId, unsigned int kAtomId)
Get the angle in radians among the specified atoms i, j, k.
Std stuff.