RDKit
Open-source cheminformatics and machine learning.
Bond.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-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 #include <RDGeneral/export.h>
11 #ifndef _RD_BOND_H
12 #define _RD_BOND_H
13 
14 // std stuff
15 #include <iostream>
16 
17 // Ours
18 #include <RDGeneral/Invariant.h>
19 #include <Query/QueryObjects.h>
20 #include <RDGeneral/types.h>
21 #include <RDGeneral/RDProps.h>
22 #include <GraphMol/details.h>
23 #include <boost/foreach.hpp>
24 
25 namespace RDKit {
26 class ROMol;
27 class RWMol;
28 class Atom;
29 
30 //! class for representing a bond
31 /*!
32 
33  <b>Notes:</b>
34  - many of the methods of Atom require that the Atom be associated
35  with a molecule (an ROMol).
36  - each Bond maintains a Dict of \c properties:
37  - Each \c property is keyed by name and can store an
38  arbitrary type.
39  - \c Properties can be marked as \c calculated, in which case
40  they will be cleared when the \c clearComputedProps() method
41  is called.
42  - Because they have no impact upon chemistry, all \c property
43  operations are \c const, this allows extra flexibility for
44  clients who need to store extra data on Bond objects.
45 
46 */
48  friend class RWMol;
49  friend class ROMol;
50 
51  public:
52  // FIX: grn...
54 
55  //! the type of Bond
56  typedef enum {
57  UNSPECIFIED = 0,
73  DATIVEONE, //!< one-electron dative (e.g. from a C in a Cp ring to a metal)
74  DATIVE, //!< standard two-electron dative
75  DATIVEL, //!< standard two-electron dative
76  DATIVER, //!< standard two-electron dative
78  ZERO //!< Zero-order bond (from
79  // http://pubs.acs.org/doi/abs/10.1021/ci200488k)
80  } BondType;
81 
82  //! the bond's direction (for chirality)
83  typedef enum {
84  NONE = 0, //!< no special style
85  BEGINWEDGE, //!< wedged: narrow at begin
86  BEGINDASH, //!< dashed: narrow at begin
87  // FIX: this may not really be adequate
88  ENDDOWNRIGHT, //!< for cis/trans
89  ENDUPRIGHT, //!< ditto
90  EITHERDOUBLE, //!< a "crossed" double bond
91  UNKNOWN, //!< intentionally unspecified stereochemistry
92  } BondDir;
93 
94  //! the nature of the bond's stereochem (for cis/trans)
95  typedef enum { // stereochemistry of double bonds
96  STEREONONE = 0, // no special style
97  STEREOANY, // intentionally unspecified
98  // -- Put any true specifications about this point so
99  // that we can do comparisons like if(bond->getStereo()>Bond::STEREOANY)
100  STEREOZ, // Z double bond
101  STEREOE, // E double bond
102  STEREOCIS, // cis double bond
103  STEREOTRANS // trans double bond
104  } BondStereo;
105 
106  Bond();
107  //! construct with a particular BondType
108  explicit Bond(BondType bT);
109  Bond(const Bond &other);
110  virtual ~Bond();
111  Bond &operator=(const Bond &other);
112 
113  //! returns a copy
114  /*!
115  <b>Note:</b> the caller is responsible for <tt>delete</tt>ing
116  the returned pointer.
117  */
118  virtual Bond *copy() const;
119 
120  //! returns our \c bondType
121  BondType getBondType() const { return static_cast<BondType>(d_bondType); };
122  //! sets our \c bondType
123  void setBondType(BondType bT) { d_bondType = bT; };
124  //! \brief returns our \c bondType as a double
125  //! (e.g. SINGLE->1.0, AROMATIC->1.5, etc.)
126  double getBondTypeAsDouble() const;
127 
128  //! returns our contribution to the explicit valence of an Atom
129  /*!
130  <b>Notes:</b>
131  - requires an owning molecule
132  */
133  double getValenceContrib(const Atom *at) const;
134 
135  //! sets our \c isAromatic flag
136  void setIsAromatic(bool what) { df_isAromatic = what; };
137  //! returns the status of our \c isAromatic flag
138  bool getIsAromatic() const { return df_isAromatic; };
139 
140  //! sets our \c isConjugated flag
141  void setIsConjugated(bool what) { df_isConjugated = what; };
142  //! returns the status of our \c isConjugated flag
143  bool getIsConjugated() const { return df_isConjugated; };
144 
145  //! returns a reference to the ROMol that owns this Bond
146  ROMol &getOwningMol() const {
147  PRECONDITION(dp_mol, "no owner");
148  return *dp_mol;
149  };
150  //! sets our owning molecule
151  void setOwningMol(ROMol *other);
152  //! sets our owning molecule
153  void setOwningMol(ROMol &other) { setOwningMol(&other); };
154 
155  //! returns our index within the ROMol
156  /*!
157  <b>Notes:</b>
158  - this makes no sense if we do not have an owning molecule
159 
160  */
161  unsigned int getIdx() const { return d_index; };
162  //! sets our index within the ROMol
163  /*!
164  <b>Notes:</b>
165  - this makes no sense if we do not have an owning molecule
166  - the index should be <tt>< this->getOwningMol()->getNumBonds()</tt>
167  */
168  void setIdx(unsigned int index) { d_index = index; };
169 
170  //! returns the index of our begin Atom
171  /*!
172  <b>Notes:</b>
173  - this makes no sense if we do not have an owning molecule
174  */
175  unsigned int getBeginAtomIdx() const { return d_beginAtomIdx; };
176 
177  //! returns the index of our end Atom
178  /*!
179  <b>Notes:</b>
180  - this makes no sense if we do not have an owning molecule
181  */
182  unsigned int getEndAtomIdx() const { return d_endAtomIdx; };
183 
184  //! given the index of one Atom, returns the index of the other
185  /*!
186  <b>Notes:</b>
187  - this makes no sense if we do not have an owning molecule
188  */
189  unsigned int getOtherAtomIdx(unsigned int thisIdx) const;
190 
191  //! sets the index of our begin Atom
192  /*!
193  <b>Notes:</b>
194  - requires an owning molecule
195  */
196  void setBeginAtomIdx(unsigned int what);
197  //! sets the index of our end Atom
198  /*!
199  <b>Notes:</b>
200  - requires an owning molecule
201  */
202  void setEndAtomIdx(unsigned int what);
203 
204  //! sets our begin Atom
205  /*!
206  <b>Notes:</b>
207  - requires an owning molecule
208  */
209  void setBeginAtom(Atom *at);
210  //! sets our end Atom
211  /*!
212  <b>Notes:</b>
213  - requires an owning molecule
214  */
215  void setEndAtom(Atom *at);
216 
217  //! returns a pointer to our begin Atom
218  /*!
219  <b>Notes:</b>
220  - requires an owning molecule
221  */
222  Atom *getBeginAtom() const;
223  //! returns a pointer to our end Atom
224  /*!
225  <b>Notes:</b>
226  - requires an owning molecule
227  */
228  Atom *getEndAtom() const;
229  //! returns a pointer to the other Atom
230  /*!
231  <b>Notes:</b>
232  - requires an owning molecule
233  */
234  Atom *getOtherAtom(Atom const *what) const;
235 
236  // ------------------------------------
237  // Please see the note in Atom.h for some explanation
238  // of these methods
239  // ------------------------------------
240 
241  // This method can be used to distinguish query bonds from standard bonds
242  virtual bool hasQuery() const { return false; };
243 
244  // FIX: the const crap here is all mucked up.
245  //! NOT CALLABLE
246  virtual void setQuery(QUERYBOND_QUERY *what);
247  //! NOT CALLABLE
248  virtual QUERYBOND_QUERY *getQuery() const;
249 
250  //! NOT CALLABLE
251  virtual void expandQuery(
252  QUERYBOND_QUERY *what,
254  bool maintainOrder = true);
255 
256  //! returns whether or not we match the argument
257  /*!
258  <b>Notes:</b>
259  - for Bond objects, "match" means that either one of the Bonds
260  has \c bondType Bond::UNSPECIFIED or both Bonds have the
261  same \c bondType.
262  */
263  virtual bool Match(Bond const *what) const;
264 
265  //! sets our direction
266  void setBondDir(BondDir what) { d_dirTag = what; };
267  //! returns our direction
268  BondDir getBondDir() const { return static_cast<BondDir>(d_dirTag); };
269 
270  //! sets our stereo code
271  /*!
272  STEREONONE, STEREOANY, STEREOE and STEREOZ can be set without
273  neighboring atoms specified in getStereoAtoms since they are
274  defined by the topology of the molecular graph. In order to set
275  STEREOCIS or STEREOTRANS the neighboring atoms must be set first
276  (using setStereoBonds()) to know what atoms are being considered.
277 
278  <b>Notes:</b>
279  - MolOps::findPotentialStereoBonds can be used to set
280  getStereoAtoms before setting CIS/TRANS
281  */
282  void setStereo(BondStereo what) {
283  PRECONDITION(what <= STEREOE || getStereoAtoms().size() == 2,
284  "Stereo atoms should be specified before specifying CIS/TRANS "
285  "bond stereochemistry")
286  d_stereo = what;
287  };
288  //! returns our stereo code
289  BondStereo getStereo() const { return static_cast<BondStereo>(d_stereo); };
290 
291  //! sets the atoms to be considered as reference points for bond stereo
292  /*!
293  These do not necessarily need to be the highest 'ranking' atoms
294  like CIP stereo requires. They can be any arbitrary atoms
295  neighboring the begin and end atoms of this bond
296  respectively. STEREOCIS or STEREOTRANS is then set relative to
297  only these atoms.
298 
299  If CIP rankings are desired, use
300  MolOps::findPotentialStereoBonds, but this is a more costly
301  function as it takes the whole molecule topology into account.
302  */
303  void setStereoAtoms(unsigned int bgnIdx, unsigned int endIdx);
304 
305  //! returns the indices of our stereo atoms
306  const INT_VECT &getStereoAtoms() const {
307  if (!dp_stereoAtoms) {
308  const_cast<Bond *>(this)->dp_stereoAtoms = new INT_VECT();
309  }
310  return *dp_stereoAtoms;
311  };
312  //! \overload
314  if (!dp_stereoAtoms) dp_stereoAtoms = new INT_VECT();
315  return *dp_stereoAtoms;
316  };
317 
318  //! calculates any of our lazy \c properties
319  /*!
320  <b>Notes:</b>
321  - requires an owning molecule
322  */
323  void updatePropertyCache(bool strict = true) { (void)strict; }
324 
325  protected:
326  //! sets our owning molecule
327  // void setOwningMol(ROMol *other);
328  //! sets our owning molecule
329  // void setOwningMol(ROMol &other) {setOwningMol(&other);};
332  boost::uint8_t d_bondType;
333  boost::uint8_t d_dirTag;
334  boost::uint8_t d_stereo;
336  atomindex_t d_beginAtomIdx, d_endAtomIdx;
339 
340  void initBond();
341 };
342 };
343 
344 //! allows Bond objects to be dumped to streams
345 RDKIT_GRAPHMOL_EXPORT extern std::ostream &operator<<(std::ostream &target, const RDKit::Bond &b);
346 
347 #endif
boost::uint8_t d_stereo
Definition: Bond.h:334
BondStereo getStereo() const
returns our stereo code
Definition: Bond.h:289
ROMol & getOwningMol() const
returns a reference to the ROMol that owns this Bond
Definition: Bond.h:146
CompositeQueryType
Definition: QueryObjects.h:36
RWMol is a molecule class that is intended to be edited.
Definition: RWMol.h:31
virtual bool hasQuery() const
Definition: Bond.h:242
RDKIT_GRAPHMOL_EXPORT std::ostream & operator<<(std::ostream &target, const RDKit::Bond &b)
allows Bond objects to be dumped to streams
bool df_isAromatic
sets our owning molecule
Definition: Bond.h:330
Queries::Query< int, Bond const *, true > QUERYBOND_QUERY
Definition: Bond.h:53
ROMol * dp_mol
Definition: Bond.h:337
BondStereo
the nature of the bond&#39;s stereochem (for cis/trans)
Definition: Bond.h:95
void setIsConjugated(bool what)
sets our isConjugated flag
Definition: Bond.h:141
BondType
the type of Bond
Definition: Bond.h:56
void setBondType(BondType bT)
sets our bondType
Definition: Bond.h:123
intentionally unspecified stereochemistry
Definition: Bond.h:91
standard two-electron dative
Definition: Bond.h:76
BondDir getBondDir() const
returns our direction
Definition: Bond.h:268
#define RDKIT_GRAPHMOL_EXPORT
Definition: export.h:294
void setIdx(unsigned int index)
sets our index within the ROMol
Definition: Bond.h:168
bool getIsAromatic() const
returns the status of our isAromatic flag
Definition: Bond.h:138
INT_VECT * dp_stereoAtoms
Definition: Bond.h:338
bool getIsConjugated() const
returns the status of our isConjugated flag
Definition: Bond.h:143
std::vector< int > INT_VECT
Definition: types.h:247
void setIsAromatic(bool what)
sets our isAromatic flag
Definition: Bond.h:136
boost::uint8_t d_bondType
Definition: Bond.h:332
unsigned int getEndAtomIdx() const
returns the index of our end Atom
Definition: Bond.h:182
Std stuff.
Definition: Atom.h:30
void updatePropertyCache(bool strict=true)
calculates any of our lazy properties
Definition: Bond.h:323
INT_VECT & getStereoAtoms()
Definition: Bond.h:313
atomindex_t d_index
Definition: Bond.h:335
void setStereo(BondStereo what)
sets our stereo code
Definition: Bond.h:282
standard two-electron dative
Definition: Bond.h:74
bool df_isConjugated
Definition: Bond.h:331
class for representing a bond
Definition: Bond.h:47
standard two-electron dative
Definition: Bond.h:75
BondDir
the bond&#39;s direction (for chirality)
Definition: Bond.h:83
unsigned int getBeginAtomIdx() const
returns the index of our begin Atom
Definition: Bond.h:175
void setOwningMol(ROMol &other)
sets our owning molecule
Definition: Bond.h:153
one-electron dative (e.g. from a C in a Cp ring to a metal)
Definition: Bond.h:73
boost::uint8_t d_dirTag
Definition: Bond.h:333
#define PRECONDITION(expr, mess)
Definition: Invariant.h:108
wedged: narrow at begin
Definition: Bond.h:85
a "crossed" double bond
Definition: Bond.h:90
BondType getBondType() const
returns our bondType
Definition: Bond.h:121
Pulls in all the query types.
const INT_VECT & getStereoAtoms() const
returns the indices of our stereo atoms
Definition: Bond.h:306
void setBondDir(BondDir what)
sets our direction
Definition: Bond.h:266
boost::uint32_t atomindex_t
Definition: details.h:14
Base class for all queries.
Definition: Query.h:46
dashed: narrow at begin
Definition: Bond.h:86
unsigned int getIdx() const
returns our index within the ROMol
Definition: Bond.h:161
The class for representing atoms.
Definition: Atom.h:69
atomindex_t d_endAtomIdx
Definition: Bond.h:336
for cis/trans
Definition: Bond.h:88