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