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