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