RDKit
Open-source cheminformatics and machine learning.
RDDepictor.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2003-2017 Greg Landrum and 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 
11 #ifndef RDDEPICTOR_H
12 #define RDDEPICTOR_H
13 
14 #include <RDGeneral/types.h>
15 #include <Geometry/point.h>
16 #include <boost/smart_ptr.hpp>
17 
18 namespace RDKit {
19 class ROMol;
20 }
21 
22 namespace RDDepict {
23 typedef boost::shared_array<double> DOUBLE_SMART_PTR;
24 
25 class DepictException : public std::exception {
26  public:
27  DepictException(const char *msg) : _msg(msg){};
28  DepictException(const std::string msg) : _msg(msg){};
29  const char *message() const { return _msg.c_str(); };
30  ~DepictException() throw(){};
31 
32  private:
33  std::string _msg;
34 };
35 
36 //! \brief Generate 2D coordinates (a depiction) for a molecule
37 /*!
38 
39  \param mol the molecule were are interested in
40 
41  \param coordMap a map of int to Point2D, between atom IDs and
42  their locations. This is the container the user needs to fill if
43  he/she wants to specify coordinates for a portion of the molecule,
44  defaults to 0
45 
46  \param canonOrient canonicalize the orientation so that the long
47  axes align with the x-axis etc.
48 
49  \param clearConfs clear all existing conformations on the molecule
50  before adding the 2D coordinates instead of simply adding to the
51  list
52 
53  \param nFlipsPerSample - the number of rotatable bonds that are
54  flipped at random for each sample
55 
56  \param nSamples - the number of samples
57 
58  \param sampleSeed - seed for the random sampling process
59 
60  \param permuteDeg4Nodes - try permuting the drawing order of bonds around
61  atoms with four neighbors in order to improve the depiction
62 
63  \return ID of the conformation added to the molecule cotaining the
64  2D coordinates
65 
66 */
67 unsigned int compute2DCoords(RDKit::ROMol &mol,
68  const RDGeom::INT_POINT2D_MAP *coordMap = 0,
69  bool canonOrient = false, bool clearConfs = true,
70  unsigned int nFlipsPerSample = 0,
71  unsigned int nSamples = 0, int sampleSeed = 0,
72  bool permuteDeg4Nodes = false);
73 
74 //! \brief Compute the 2D coordinates such the interatom distances
75 // mimic those in a distance matrix
76 /*!
77 
78  This function generates 2D coordinates such that the inter-atom
79  distances mimic those specified via dmat. This is done by randomly
80  sampling(flipping) the rotatable bonds in the molecule and
81  evaluating a cost function which contains two components. The
82  first component is the sum of inverse of the squared inter-atom
83  distances, this helps in spreading the atoms far from each
84  other. The second component is the sum of squares of the
85  difference in distance between those in dmat and the generated
86  structure. The user can adjust the relative importance of the two
87  components via a adjustable paramter (see below)
88 
89  ARGUMENTS:
90 
91  \param mol - molecule to generate coordinates for
92 
93  \param dmat - the distance matrix we want to mimic, this is a
94  symmetric N by N matrix where N is the number of atoms in mol. All
95  negative entries in dmat are ignored.
96 
97  \param canonOrient - canonicalize the orientation after the 2D
98  embedding is done
99 
100  \param clearConfs - clear any previously existing conformations on
101  mol before adding a conformation
102 
103  \param weightDistMat - A value between 0.0 and 1.0, this
104  determines the importance of mimicing the the inter atoms
105  distances in dmat. (1.0 - weightDistMat) is the weight associated
106  to spreading out the structure (density) in the cost function
107 
108  \param nFlipsPerSample - the number of rotatable bonds that are
109  flipped at random for each sample
110 
111  \param nSamples - the number of samples
112 
113  \param sampleSeed - seed for the random sampling process
114 
115  \param permuteDeg4Nodes - try permuting the drawing order of bonds around
116  atoms with four neighbors in order to improve the depiction
117 
118  \return ID of the conformation added to the molecule cotaining the
119  2D coordinates
120 
121 
122 */
123 unsigned int compute2DCoordsMimicDistMat(
124  RDKit::ROMol &mol, const DOUBLE_SMART_PTR *dmat = 0,
125  bool canonOrient = true, bool clearConfs = true, double weightDistMat = 0.5,
126  unsigned int nFlipsPerSample = 3, unsigned int nSamples = 100,
127  int sampleSeed = 25, bool permuteDeg4Nodes = true);
128 
129 //! \brief Compute 2D coordinates where a piece of the molecule is
130 // constrained to have the same coordinates as a reference.
131 /*!
132  This function generates a depiction for a molecule where a piece of the
133  molecule is constrained to have the same coordinates as a reference.
134 
135  This is useful for, for example, generating depictions of SAR data
136  sets so that the cores of the molecules are all oriented the same way.
137 
138  ARGUMENTS:
139 
140  \param mol - the molecule to be aligned, this will come back
141  with a single conformer.
142  \param reference - a molecule with the reference atoms to align to;
143  this should have a depiction.
144  \param confId - (optional) the id of the reference conformation to use
145  \param referencePattern - (optional) a query molecule to be used to
146  generate the atom mapping between the molecule
147  and the reference.
148  \param acceptFailure - (optional) if True, standard depictions will be
149  generated
150  for molecules that don't have a substructure match to
151  the
152  reference; if false, throws a DepictException.
153 
154 */
156  RDKit::ROMol &mol, const RDKit::ROMol &reference, int confId = -1,
157  RDKit::ROMol *referencePattern = static_cast<RDKit::ROMol *>(0),
158  bool acceptFailure = false);
159 
160 //! \brief Generate a 2D depiction for a molecule where all or part of
161 // it mimics the coordinates of a 3D reference structure.
162 /*!
163  Generates a depiction for a molecule where a piece of the molecule
164  is constrained to have coordinates similar to those of a 3D reference
165  structure.
166 
167  ARGUMENTS:
168  \param mol - the molecule to be aligned, this will come back
169  with a single conformer containing 2D coordinates
170  \param reference - a molecule with the reference atoms to align to.
171  By default this should be the same as mol, but with
172  3D coordinates
173  \param confId - (optional) the id of the reference conformation to use
174  \param refPattern - (optional) a query molecule to map a subset of
175  the reference onto the mol, so that only some of the
176  atoms are aligned.
177  \param acceptFailure - (optional) if true, standard depictions will be
178  generated
179  for molecules that don't match the reference or the
180  referencePattern; if false, throws a DepictException.
181 */
183  const RDKit::ROMol &reference,
184  int confId = -1,
185  RDKit::ROMol *referencePattern = 0,
186  bool acceptFailure = false);
187 };
188 
189 #endif
unsigned int compute2DCoordsMimicDistMat(RDKit::ROMol &mol, const DOUBLE_SMART_PTR *dmat=0, bool canonOrient=true, bool clearConfs=true, double weightDistMat=0.5, unsigned int nFlipsPerSample=3, unsigned int nSamples=100, int sampleSeed=25, bool permuteDeg4Nodes=true)
Compute the 2D coordinates such the interatom distances.
DepictException(const std::string msg)
Definition: RDDepictor.h:28
DepictException(const char *msg)
Definition: RDDepictor.h:27
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:106
std::map< int, Point2D > INT_POINT2D_MAP
Definition: point.h:511
void generateDepictionMatching3DStructure(RDKit::ROMol &mol, const RDKit::ROMol &reference, int confId=-1, RDKit::ROMol *referencePattern=0, bool acceptFailure=false)
Generate a 2D depiction for a molecule where all or part of.
boost::shared_array< double > DOUBLE_SMART_PTR
Definition: EmbeddedFrag.h:25
void generateDepictionMatching2DStructure(RDKit::ROMol &mol, const RDKit::ROMol &reference, int confId=-1, RDKit::ROMol *referencePattern=static_cast< RDKit::ROMol * >(0), bool acceptFailure=false)
Compute 2D coordinates where a piece of the molecule is.
const char * message() const
Definition: RDDepictor.h:29
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:29
unsigned int compute2DCoords(RDKit::ROMol &mol, const RDGeom::INT_POINT2D_MAP *coordMap=0, bool canonOrient=false, bool clearConfs=true, unsigned int nFlipsPerSample=0, unsigned int nSamples=0, int sampleSeed=0, bool permuteDeg4Nodes=false)
Generate 2D coordinates (a depiction) for a molecule.