RDKit
Open-source cheminformatics and machine learning.
AlignMolecules.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-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_ALIGNMOLECULES_H_
12 #define _RD_ALIGNMOLECULES_H_
13 
14 #include <Geometry/Transform3D.h>
15 #include <Numerics/Vector.h>
16 #include <vector>
17 
18 namespace RDKit {
19 typedef std::vector<std::pair<int, int>> MatchVectType;
20 
21 class Conformer;
22 class ROMol;
23 namespace MolAlign {
24 class RDKIT_MOLALIGN_EXPORT MolAlignException : public std::exception {
25  public:
26  //! construct with an error message
27  MolAlignException(const char *msg) : _msg(msg){};
28  //! construct with an error message
29  MolAlignException(const std::string msg) : _msg(msg){};
30  //! get the error message
31  const char *what() const noexcept override { return _msg.c_str(); };
32  const char *message() const noexcept { return what(); };
33  ~MolAlignException() noexcept {};
34 
35  private:
36  std::string _msg;
37 };
38 
39 //! Alignment functions
40 
41 //! Compute the transformation required to align a molecule
42 /*!
43  The 3D transformation required to align the specied conformation in the probe
44  molecule
45  to a specified conformation in the reference molecule is computed so that the
46  root mean
47  squared distance between a specified set of atoms is minimized
48 
49  \param prbMol molecule that is to be aligned
50  \param refMol molecule used as the reference for the alignment
51  \param trans storage for the computed transform
52  \param prbCid ID of the conformation in the probe to be used
53  for the alignment (defaults to first conformation)
54  \param refCid ID of the conformation in the ref molecule to which
55  the alignment is computed (defaults to first conformation)
56  \param atomMap a vector of pairs of atom IDs (probe AtomId, ref AtomId)
57  used to compute the alignments. If this mapping is
58  not specified an attempt is made to generate on by
59  substructure matching
60  \param weights Optionally specify weights for each of the atom pairs
61  \param reflect if true reflect the conformation of the probe molecule
62  \param maxIters maximum number of iteration used in mimizing the RMSD
63 
64  <b>Returns</b>
65  RMSD value
66 */
68  const ROMol &prbMol, const ROMol &refMol, RDGeom::Transform3D &trans,
69  int prbCid = -1, int refCid = -1, const MatchVectType *atomMap = 0,
70  const RDNumeric::DoubleVector *weights = 0, bool reflect = false,
71  unsigned int maxIters = 50);
72 
73 //! Optimally (minimum RMSD) align a molecule to another molecule
74 /*!
75  The 3D transformation required to align the specied conformation in the probe
76  molecule
77  to a specified conformation in the reference molecule is computed so that the
78  root mean
79  squared distance between a specified set of atoms is minimized. This
80  transforms is them
81  applied to the specified conformation in the probe molecule
82 
83  \param prbMol molecule that is to be aligned
84  \param refMol molecule used as the reference for the alignment
85  \param prbCid ID of the conformation in the probe to be used
86  for the alignment (defaults to first conformation)
87  \param refCid ID of the conformation in the ref molecule to which
88  the alignment is computed (defaults to first conformation)
89  \param atomMap a vector of pairs of atom IDs (probe AtomId, ref AtomId)
90  used to compute the alignments. If this mapping is
91  not specified an attempt is made to generate on by
92  substructure matching
93  \param weights Optionally specify weights for each of the atom pairs
94  \param reflect if true reflect the conformation of the probe molecule
95  \param maxIters maximum number of iteration used in mimizing the RMSD
96 
97  <b>Returns</b>
98  RMSD value
99 */
101  ROMol &prbMol, const ROMol &refMol, int prbCid = -1, int refCid = -1,
102  const MatchVectType *atomMap = 0,
103  const RDNumeric::DoubleVector *weights = 0, bool reflect = false,
104  unsigned int maxIters = 50);
105 
106 //! Returns the optimal RMS for aligning two molecules, taking
107 // symmetry into account. As a side-effect, the probe molecule is
108 // left in the aligned state.
109 /*!
110  This function will attempt to align all permutations of matching atom
111  orders in both molecules, for some molecules it will lead to 'combinatorial
112  explosion' especially if hydrogens are present.
113  Use 'RDKit::MolAlign::alignMol' to align molecules without changing the
114  atom order.
115 
116  \param probeMol the molecule to be aligned to the reference
117  \param refMol the reference molecule
118  \param probeId (optional) probe conformation to use
119  \param refId (optional) reference conformation to use
120  \param map (optional) a vector of vectors of pairs of atom IDs
121  (probe AtomId, ref AtomId) used to compute the alignments.
122  If not provided, these will be generated using a
123  substructure search.
124  \param maxMatches (optional) if map is empty, this will be the max number of
125  matches found in a SubstructMatch().
126 
127  <b>Returns</b>
128  Best RMSD value found
129 */
131  ROMol &probeMol, ROMol &refMol, int probeId = -1, int refId = -1,
132  const std::vector<MatchVectType> &map = std::vector<MatchVectType>(),
133  int maxMatches = 1e6);
134 
135 //! Align the conformations of a molecule using a common set of atoms. If
136 // the molecules contains queries, then the queries must also match exactly.
137 
138 /*!
139  \param mol The molecule of interest.
140  \param atomIds vector of atoms to be used to generate the alignment.
141  All atoms will be used is not specified
142  \param confIds vector of conformations to align - defaults to all
143  \param weights vector of weights to applied to particular atom pairs
144  defaults to all weights = 1
145  \param reflect toggles reflecting (about the origin) the alignment
146  \param maxIters the maximum number of iterations to attempt
147  \param RMSlist if nonzero, this will be used to return the RMS values
148  between the reference conformation and the other aligned
149  conformations
150 */
152  ROMol &mol, const std::vector<unsigned int> *atomIds = 0,
153  const std::vector<unsigned int> *confIds = 0,
154  const RDNumeric::DoubleVector *weights = 0, bool reflect = false,
155  unsigned int maxIters = 50, std::vector<double> *RMSlist = 0);
156 } // namespace MolAlign
157 } // namespace RDKit
158 #endif
RDKit::MolAlign::MolAlignException::MolAlignException
MolAlignException(const char *msg)
construct with an error message
Definition: AlignMolecules.h:27
RDKit::MolAlign::alignMol
RDKIT_MOLALIGN_EXPORT double alignMol(ROMol &prbMol, const ROMol &refMol, int prbCid=-1, int refCid=-1, const MatchVectType *atomMap=0, const RDNumeric::DoubleVector *weights=0, bool reflect=false, unsigned int maxIters=50)
Optimally (minimum RMSD) align a molecule to another molecule.
Vector.h
RDKIT_MOLALIGN_EXPORT
#define RDKIT_MOLALIGN_EXPORT
Definition: export.h:359
RDKit::MolAlign::MolAlignException::MolAlignException
MolAlignException(const std::string msg)
construct with an error message
Definition: AlignMolecules.h:29
RDKit::MolAlign::MolAlignException
Definition: AlignMolecules.h:24
RDKit::MolAlign::MolAlignException::message
const char * message() const noexcept
Definition: AlignMolecules.h:32
RDNumeric::Vector
A class to represent vectors of numbers.
Definition: Vector.h:29
RDKit::ROMol
Definition: ROMol.h:171
RDKit::MolAlign::reflect
RDKIT_MOLALIGN_EXPORT const RDGeom::POINT3D_VECT * reflect(const Conformer &conf)
RDKit::MolAlign::alignMolConformers
RDKIT_MOLALIGN_EXPORT void alignMolConformers(ROMol &mol, const std::vector< unsigned int > *atomIds=0, const std::vector< unsigned int > *confIds=0, const RDNumeric::DoubleVector *weights=0, bool reflect=false, unsigned int maxIters=50, std::vector< double > *RMSlist=0)
Align the conformations of a molecule using a common set of atoms. If.
Transform3D.h
RDKit
Std stuff.
Definition: Atom.h:30
RDKit::MolAlign::getAlignmentTransform
RDKIT_MOLALIGN_EXPORT double getAlignmentTransform(const ROMol &prbMol, const ROMol &refMol, RDGeom::Transform3D &trans, int prbCid=-1, int refCid=-1, const MatchVectType *atomMap=0, const RDNumeric::DoubleVector *weights=0, bool reflect=false, unsigned int maxIters=50)
Alignment functions.
RDGeom::Transform3D
Definition: Transform3D.h:23
RDKit::MolAlign::MolAlignException::~MolAlignException
~MolAlignException() noexcept
Definition: AlignMolecules.h:33
RDKit::MolAlign::getBestRMS
RDKIT_MOLALIGN_EXPORT double getBestRMS(ROMol &probeMol, ROMol &refMol, int probeId=-1, int refId=-1, const std::vector< MatchVectType > &map=std::vector< MatchVectType >(), int maxMatches=1e6)
Returns the optimal RMS for aligning two molecules, taking.
RDKit::MolAlign::MolAlignException::what
const char * what() const noexcept override
get the error message
Definition: AlignMolecules.h:31
RDKit::MatchVectType
std::vector< std::pair< int, int > > MatchVectType
used to return matches from substructure searching, The format is (queryAtomIdx, molAtomIdx)
Definition: FragFPGenerator.h:24
export.h