RDKit
Open-source cheminformatics and machine learning.
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 #include <Eigen/Dense>
19 #endif
20 
21 namespace RDKit {
22 class ROMol;
23 class Atom;
24 class Conformer;
25 }
26 
27 namespace RDGeom {
28 class Transform3D;
29 }
30 
31 namespace MolTransforms {
34 
35 //! Compute the centroid of a conformer
36 /*!
37  This is simple the average of the heavy atom locations in the conformer,
38  not attention is paid to hydrogens or the differences in atomic radii
39 
40  \param conf Conformer of interest
41  \param ignoreHs If true, ignore hydrogen atoms
42 */
44  bool ignoreHs = true);
45 
46 #ifdef RDK_HAS_EIGEN3
47 //! Compute principal axes and moments of inertia for a conformer
48 /*!
49  These values are calculated from the inertia tensor:
50  Iij = - sum_{s=1..N}(w_s * r_{si} * r_{sj}) i != j
51  Iii = sum_{s=1..N} sum_{j!=i} (w_s * r_{sj} * r_{sj})
52  where the coordinates are relative to the center of mass.
53 
54 
55  \param conf Conformer of interest
56  \param axes used to return the principal axes
57  \param moments used to return the principal moments
58  \param ignoreHs If true, ignore hydrogen atoms
59  \param force If true, the calculation will be carried out even if a
60  cached value is present
61  \param weights If present used to weight the atomic coordinates
62 
63  \returns whether or not the calculation was successful
64 */
65 RDKIT_MOLTRANSFORMS_EXPORT bool computePrincipalAxesAndMoments(const RDKit::Conformer &conf,
66  Eigen::Matrix3d &axes,
67  Eigen::Vector3d &moments,
68  bool ignoreHs = false, bool force = false,
69  const std::vector<double> *weights = NULL);
70 //! Compute principal axes and moments from the gyration matrix of a conformer
71 /*!
72 
73  These values are calculated from the gyration matrix/tensor:
74  Iij = sum_{s=1..N}(w_s * r_{si} * r_{sj}) i != j
75  Iii = sum_{s=1..N} sum_{t!=s}(w_s * r_{si} * r_{ti})
76  where the coordinates are relative to the center of mass.
77 
78  \param conf Conformer of interest
79  \param axes used to return the principal axes
80  \param moments used to return the principal moments
81  \param ignoreHs If true, ignore hydrogen atoms
82  \param force If true, the calculation will be carried out even if a
83  cached value is present
84  \param weights If present used to weight the atomic coordinates
85 
86  \returns whether or not the calculation was successful
87 */
88 RDKIT_MOLTRANSFORMS_EXPORT bool computePrincipalAxesAndMomentsFromGyrationMatrix(
89  const RDKit::Conformer &conf, Eigen::Matrix3d &axes,
90  Eigen::Vector3d &moments, bool ignoreHs = false, bool force = false,
91  const std::vector<double> *weights = NULL);
92 #endif
93 
94 //! Compute the transformation require to orient the conformation
95 //! along the principal axes about the center; i.e. center is made to coincide
96 // with the
97 //! origin, the largest princiapl axis with the x-axis, the next largest with
98 // the y-axis
99 //! and the smallest with the z-axis
100 /*!
101  If center is not specified the the centroid of the conformer will be used
102  \param conf Conformer of interest
103  \param center Center to be used for canonicalization, defaults to
104  the centroid of the
105  conformation
106  \param normalizeCovar Normalize the covariance matrix with the number of
107  atoms
108  \param ignoreHs Optinally ignore hydrogens
109 */
111  const RDKit::Conformer &conf, const RDGeom::Point3D *center = 0,
112  bool normalizeCovar = false, bool ignoreHs = true);
113 
114 //! Transform the conformation using the specified transformation
116  const RDGeom::Transform3D &trans);
117 
118 //! Canonicalize the orientation of a conformer so that its principal axes
119 //! around the specified center point coincide with the x, y, z axes
120 /*!
121  \param conf The conformer of interest
122  \param center Optional center point about which the principal axes are
123  computed
124  if not specified the centroid of the conformer will be
125  used
126  \param normalizeCovar Optionally normalize the covariance matrix by the number
127  of atoms
128  \param ignoreHs If true, ignore hydrogen atoms
129 
130 */
132  const RDGeom::Point3D *center = 0,
133  bool normalizeCovar = false, bool ignoreHs = true);
134 
135 //! Canonicalize all the conformations in a molecule
136 /*!
137  \param mol the molecule of interest
138  \param normalizeCovar Optionally normalize the covariance matrix by the number
139  of atoms
140  \param ignoreHs If true, ignore hydrogens
141 */
142 RDKIT_MOLTRANSFORMS_EXPORT void canonicalizeMol(RDKit::ROMol &mol, bool normalizeCovar = false,
143  bool ignoreHs = true);
144 
145 //! Get the bond length between the specified atoms i, j
146 RDKIT_MOLTRANSFORMS_EXPORT double getBondLength(const RDKit::Conformer &conf, unsigned int iAtomId,
147  unsigned int jAtomId);
148 
149 //! Set the bond length between the specified atoms i, j
150 //! (all atoms bonded to atom j are moved)
151 RDKIT_MOLTRANSFORMS_EXPORT void setBondLength(RDKit::Conformer &conf, unsigned int iAtomId,
152  unsigned int jAtomId, double value);
153 
154 //! Get the angle in radians among the specified atoms i, j, k
155 RDKIT_MOLTRANSFORMS_EXPORT double getAngleRad(const RDKit::Conformer &conf, unsigned int iAtomId,
156  unsigned int jAtomId, unsigned int kAtomId);
157 
158 //! Get the angle in degrees among the specified atoms i, j, k
159 inline double getAngleDeg(const RDKit::Conformer &conf, unsigned int iAtomId,
160  unsigned int jAtomId, unsigned int kAtomId) {
161  return (180. / M_PI * getAngleRad(conf, iAtomId, jAtomId, kAtomId));
162 }
163 
164 //! Set the angle in radians among the specified atoms i, j, k
165 //! (all atoms bonded to atom k are moved)
166 RDKIT_MOLTRANSFORMS_EXPORT void setAngleRad(RDKit::Conformer &conf, unsigned int iAtomId,
167  unsigned int jAtomId, unsigned int kAtomId, double value);
168 
169 //! Set the angle in degrees among the specified atoms i, j, k
170 //! (all atoms bonded to atom k are moved)
171 inline void setAngleDeg(RDKit::Conformer &conf, unsigned int iAtomId,
172  unsigned int jAtomId, unsigned int kAtomId,
173  double value) {
174  setAngleRad(conf, iAtomId, jAtomId, kAtomId, value / 180. * M_PI);
175 }
176 
177 //! Get the dihedral angle in radians among the specified atoms i, j, k, l
178 RDKIT_MOLTRANSFORMS_EXPORT double getDihedralRad(const RDKit::Conformer &conf, unsigned int iAtomId,
179  unsigned int jAtomId, unsigned int kAtomId,
180  unsigned int lAtomId);
181 
182 //! Get the dihedral angle in degrees among the specified atoms i, j, k, l
183 inline double getDihedralDeg(const RDKit::Conformer &conf, unsigned int iAtomId,
184  unsigned int jAtomId, unsigned int kAtomId,
185  unsigned int lAtomId) {
186  return (180. / M_PI *
187  getDihedralRad(conf, iAtomId, jAtomId, kAtomId, lAtomId));
188 }
189 
190 //! Set the dihedral angle in radians among the specified atoms i, j, k, l
191 //! (all atoms bonded to atom l are moved)
192 RDKIT_MOLTRANSFORMS_EXPORT void setDihedralRad(RDKit::Conformer &conf, unsigned int iAtomId,
193  unsigned int jAtomId, unsigned int kAtomId,
194  unsigned int lAtomId, double value);
195 
196 //! Set the dihedral angle in degrees among the specified atoms i, j, k, l
197 //! (all atoms bonded to atom l are moved)
198 inline void setDihedralDeg(RDKit::Conformer &conf, unsigned int iAtomId,
199  unsigned int jAtomId, unsigned int kAtomId,
200  unsigned int lAtomId, double value) {
201  setDihedralRad(conf, iAtomId, jAtomId, kAtomId, lAtomId, value / 180. * M_PI);
202 }
203 }
204 #endif
RDKIT_MOLTRANSFORMS_EXPORT void canonicalizeConformer(RDKit::Conformer &conf, const RDGeom::Point3D *center=0, bool normalizeCovar=false, bool ignoreHs=true)
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.
RDKIT_MOLTRANSFORMS_EXPORT void transformConformer(RDKit::Conformer &conf, const RDGeom::Transform3D &trans)
Transform the conformation using the specified transformation.
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 void transformAtom(RDKit::Atom *atom, RDGeom::Transform3D &tform)
RDKIT_MOLTRANSFORMS_EXPORT void canonicalizeMol(RDKit::ROMol &mol, bool normalizeCovar=false, bool ignoreHs=true)
Canonicalize all the conformations in a molecule.
void setDihedralDeg(RDKit::Conformer &conf, unsigned int iAtomId, unsigned int jAtomId, unsigned int kAtomId, unsigned int lAtomId, double value)
RDKIT_MOLTRANSFORMS_EXPORT void setBondLength(RDKit::Conformer &conf, unsigned int iAtomId, unsigned int jAtomId, double value)
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.
#define RDKIT_MOLTRANSFORMS_EXPORT
Definition: export.h:437
void setAngleDeg(RDKit::Conformer &conf, unsigned int iAtomId, unsigned int jAtomId, unsigned int kAtomId, double value)
RDKIT_MOLTRANSFORMS_EXPORT RDGeom::Transform3D * computeCanonicalTransform(const RDKit::Conformer &conf, const RDGeom::Point3D *center=0, bool normalizeCovar=false, bool ignoreHs=true)
origin, the largest princiapl axis with the x-axis, the next largest with
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.
Std stuff.
Definition: Atom.h:30
RDKIT_MOLTRANSFORMS_EXPORT RDGeom::Point3D computeCentroid(const RDKit::Conformer &conf, bool ignoreHs=true)
Compute the centroid of a conformer.
RDKIT_MOLTRANSFORMS_EXPORT void setAngleRad(RDKit::Conformer &conf, unsigned int iAtomId, unsigned int jAtomId, unsigned int kAtomId, double value)
The class for representing 2D or 3D conformation of a molecule.
Definition: Conformer.h:42
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 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.
The class for representing atoms.
Definition: Atom.h:69
#define M_PI
Definition: MMFF/Params.h:26
RDKIT_MOLTRANSFORMS_EXPORT void transformMolsAtoms(RDKit::ROMol *mol, RDGeom::Transform3D &tform)