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