RDKit
Open-source cheminformatics and machine learning.
ROMol.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2003-2015 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 /*! \file ROMol.h
11 
12  \brief Defines the primary molecule class \c ROMol as well as associated
13  typedefs
14 
15 */
16 
17 #ifndef __RD_ROMOL_H__
18 #define __RD_ROMOL_H__
19 
20 /// Std stuff
21 #include <utility>
22 #include <map>
23 
24 // boost stuff
26 #include <boost/graph/adjacency_list.hpp>
27 #include <boost/smart_ptr.hpp>
29 
30 // our stuff
31 #include <RDGeneral/types.h>
32 #include <RDGeneral/RDProps.h>
33 #include "Atom.h"
34 #include "Bond.h"
35 
36 #include "Conformer.h"
37 
38 namespace RDKit {
39 class Atom;
40 class Bond;
41 typedef boost::shared_ptr<Atom> ATOM_SPTR;
42 typedef boost::shared_ptr<Bond> BOND_SPTR;
43 
44 //! This is the BGL type used to store the topology:
45 typedef boost::adjacency_list<
46  boost::vecS,
47  boost::vecS,
48  boost::undirectedS,
49  ATOM_SPTR, BOND_SPTR>
51 class MolPickler;
52 class RWMol;
53 class QueryAtom;
54 class QueryBond;
55 class RingInfo;
56 
57 template <class T1, class T2>
58 class AtomIterator_;
59 class BondIterator_;
60 class ConstBondIterator_;
61 
62 template <class T1, class T2>
64 template <class T1, class T2>
66 template <class T1, class T2>
67 class QueryAtomIterator_;
68 template <class T1, class T2>
70 
71 extern const int ci_RIGHTMOST_ATOM;
72 extern const int ci_LEADING_BOND;
73 extern const int ci_ATOM_HOLDER;
74 
75 //! ROMol is a molecule class that is intended to have a fixed topology
76 /*!
77  This is the primary class for most molecule operations.
78 
79  If you need to be manipulating the molecule (e.g. adding or deleting
80  atoms or bonds, use an RWMol instead.
81 
82  <b>Notes:</b>
83  - each ROMol maintains a Dict of \c properties:
84  - Each \c property is keyed by name and can store an
85  arbitrary type.
86  - \c Properties can be marked as \c calculated, in which case
87  they will be cleared when the \c clearComputedProps() method
88  is called.
89  - Because they have no impact upon chemistry, all \c property
90  operations are \c const, this allows extra flexibility for
91  clients who need to store extra data on ROMol objects.
92 
93  - each ROMol has collections of \c bookmarks for Atoms and Bonds:
94  - the Atom bookmarks and Bond bookmarks are stored separately
95  from each other
96  - each \c bookmark, an integer, can map to more than one
97  Atom or Bond
98  - these are currently used in molecule construction, but
99  could also be useful for reaction mapping and the like
100 
101  - information about rings (SSSR and the like) is stored in the
102  molecule's RingInfo pointer.
103 
104  */
105 
106 class ROMol : public RDProps {
107  public:
108  friend class MolPickler;
109  friend class RWMol;
110 
111  //! \cond TYPEDEFS
112 
113  //! \name typedefs
114  //@{
115  typedef MolGraph::vertex_descriptor vertex_descriptor;
116  typedef MolGraph::edge_descriptor edge_descriptor;
117 
118  typedef MolGraph::edge_iterator EDGE_ITER;
119  typedef MolGraph::out_edge_iterator OEDGE_ITER;
120  typedef MolGraph::vertex_iterator VERTEX_ITER;
121  typedef MolGraph::adjacency_iterator ADJ_ITER;
122  typedef std::pair<EDGE_ITER, EDGE_ITER> BOND_ITER_PAIR;
123  typedef std::pair<OEDGE_ITER, OEDGE_ITER> OBOND_ITER_PAIR;
124  typedef std::pair<VERTEX_ITER, VERTEX_ITER> ATOM_ITER_PAIR;
125  typedef std::pair<ADJ_ITER, ADJ_ITER> ADJ_ITER_PAIR;
126 
127  typedef std::vector<ATOM_SPTR> ATOM_SPTR_VECT;
128  typedef ATOM_SPTR_VECT::iterator ATOM_SPTR_VECT_I;
129  typedef ATOM_SPTR_VECT::const_iterator ATOM_SPTR_VECT_CI;
130  typedef std::vector<BOND_SPTR> BOND_SPTR_VECT;
131  typedef BOND_SPTR_VECT::iterator BOND_SPTR_VECT_I;
132  typedef BOND_SPTR_VECT::const_iterator BOND_SPTR_VECT_CI;
133 
134  typedef std::vector<Atom *> ATOM_PTR_VECT;
135  typedef ATOM_PTR_VECT::iterator ATOM_PTR_VECT_I;
136  typedef ATOM_PTR_VECT::const_iterator ATOM_PTR_VECT_CI;
137  typedef std::vector<Bond *> BOND_PTR_VECT;
138  typedef BOND_PTR_VECT::iterator BOND_PTR_VECT_I;
139  typedef BOND_PTR_VECT::const_iterator BOND_PTR_VECT_CI;
140 
141  typedef std::list<Atom *> ATOM_PTR_LIST;
142  typedef ATOM_PTR_LIST::iterator ATOM_PTR_LIST_I;
143  typedef ATOM_PTR_LIST::const_iterator ATOM_PTR_LIST_CI;
144  typedef std::list<Bond *> BOND_PTR_LIST;
145  typedef BOND_PTR_LIST::iterator BOND_PTR_LIST_I;
146  typedef BOND_PTR_LIST::const_iterator BOND_PTR_LIST_CI;
147 
148  // list of conformations
149  typedef std::list<CONFORMER_SPTR> CONF_SPTR_LIST;
150  typedef CONF_SPTR_LIST::iterator CONF_SPTR_LIST_I;
151  typedef CONF_SPTR_LIST::const_iterator CONF_SPTR_LIST_CI;
152  typedef std::pair<CONF_SPTR_LIST_I, CONF_SPTR_LIST_I> CONFS_I_PAIR;
153 
154  // ROFIX: these will need to be readonly somehow?
155  typedef std::map<int, ATOM_PTR_LIST> ATOM_BOOKMARK_MAP;
156  typedef std::map<int, BOND_PTR_LIST> BOND_BOOKMARK_MAP;
157 
158  typedef class AtomIterator_<Atom, ROMol> AtomIterator;
159  typedef class AtomIterator_<const Atom, const ROMol> ConstAtomIterator;
160  typedef class BondIterator_ BondIterator;
161  typedef class ConstBondIterator_ ConstBondIterator;
162  typedef class AromaticAtomIterator_<Atom, ROMol> AromaticAtomIterator;
163  typedef class AromaticAtomIterator_<const Atom, const ROMol>
164  ConstAromaticAtomIterator;
165  typedef class HeteroatomIterator_<Atom, ROMol> HeteroatomIterator;
166  typedef class HeteroatomIterator_<const Atom, const ROMol>
167  ConstHeteroatomIterator;
168  typedef class QueryAtomIterator_<Atom, ROMol> QueryAtomIterator;
169  typedef class QueryAtomIterator_<const Atom, const ROMol>
170  ConstQueryAtomIterator;
171  typedef class MatchingAtomIterator_<Atom, ROMol> MatchingAtomIterator;
172  typedef class MatchingAtomIterator_<const Atom, const ROMol>
173  ConstMatchingAtomIterator;
174 
175  typedef CONF_SPTR_LIST_I ConformerIterator;
176  typedef CONF_SPTR_LIST_CI ConstConformerIterator;
177 
178  //@}
179  //! \endcond
180 
181  ROMol() : RDProps(), numBonds(0) { initMol(); }
182 
183  //! copy constructor with a twist
184  /*!
185  \param other the molecule to be copied
186  \param quickCopy (optional) if this is true, the resulting ROMol will not
187  copy any of the properties or bookmarks and conformers from \c other.
188  This can
189  make the copy substantially faster (thus the name).
190  \param confId (optional) if this is >=0, the resulting ROMol will contain
191  only
192  the specified conformer from \c other.
193  */
194  ROMol(const ROMol &other, bool quickCopy = false, int confId = -1) : RDProps() {
195  dp_ringInfo = 0;
196  initFromOther(other, quickCopy, confId);
197  numBonds = rdcast<unsigned int>(boost::num_edges(d_graph));
198  };
199  //! construct a molecule from a pickle string
200  ROMol(const std::string &binStr);
201 
202  virtual ~ROMol() { destroy(); };
203 
204  //@}
205  //! \name Atoms
206  //@{
207 
208  //! returns our number of atoms
209  unsigned int getNumAtoms(bool onlyExplicit = 1) const;
210  //! returns our number of heavy atoms (atomic number > 1)
211  unsigned int getNumHeavyAtoms() const;
212  //! returns a pointer to a particular Atom
213  Atom *getAtomWithIdx(unsigned int idx);
214  //! \overload
215  const Atom *getAtomWithIdx(unsigned int idx) const;
216  //! \overload
217  template <class U>
218  Atom *getAtomWithIdx(const U idx) {
219  return getAtomWithIdx(rdcast<unsigned int>(idx));
220  }
221  //! \overload
222  template <class U>
223  const Atom *getAtomWithIdx(const U idx) const {
224  return getAtomWithIdx(rdcast<unsigned int>(idx));
225  }
226  //! returns the degree (number of neighbors) of an Atom in the graph
227  unsigned int getAtomDegree(const Atom *at) const;
228  //! \overload
229  unsigned int getAtomDegree(ATOM_SPTR at) const;
230  //@}
231 
232  //! \name Bonds
233  //@{
234 
235  //! returns our number of Bonds
236  unsigned int getNumBonds(bool onlyHeavy = 1) const;
237  //! returns a pointer to a particular Bond
238  Bond *getBondWithIdx(unsigned int idx);
239  //! \overload
240  const Bond *getBondWithIdx(unsigned int idx) const;
241  //! \overload
242  template <class U>
243  Bond *getBondWithIdx(const U idx) {
244  return getBondWithIdx(rdcast<unsigned int>(idx));
245  }
246  //! \overload
247  template <class U>
248  const Bond *getBondWithIdx(const U idx) const {
249  return getBondWithIdx(rdcast<unsigned int>(idx));
250  }
251  //! returns a pointer to the bond between two atoms, Null on failure
252  Bond *getBondBetweenAtoms(unsigned int idx1, unsigned int idx2);
253  //! \overload
254  const Bond *getBondBetweenAtoms(unsigned int idx1, unsigned int idx2) const;
255  //! \overload
256  template <class U, class V>
257  Bond *getBondBetweenAtoms(const U idx1, const V idx2) {
258  return getBondBetweenAtoms(rdcast<unsigned int>(idx1),
259  rdcast<unsigned int>(idx2));
260  }
261  //! \overload
262  template <class U, class V>
263  const Bond *getBondBetweenAtoms(const U idx1, const V idx2) const {
264  return getBondBetweenAtoms(rdcast<unsigned int>(idx1),
265  rdcast<unsigned int>(idx2));
266  }
267 
268  //@}
269 
270  //! \name Bookmarks
271  //@{
272 
273  //! associates an Atom pointer with a bookmark
274  void setAtomBookmark(ATOM_SPTR at, int mark) {
275  d_atomBookmarks[mark].push_back(at.get());
276  };
277  //! \overload
278  void setAtomBookmark(Atom *at, int mark) {
279  d_atomBookmarks[mark].push_back(at);
280  };
281  //! associates an Atom pointer with a bookmark
282  void replaceAtomBookmark(ATOM_SPTR at, int mark) {
283  d_atomBookmarks[mark].clear();
284  d_atomBookmarks[mark].push_back(at.get());
285  };
286  //! \overload
287  void replaceAtomBookmark(Atom *at, int mark) {
288  d_atomBookmarks[mark].clear();
289  d_atomBookmarks[mark].push_back(at);
290  };
291  //! returns the first Atom associated with the \c bookmark provided
292  Atom *getAtomWithBookmark(int mark);
293  //! returns all Atoms associated with the \c bookmark provided
294  ATOM_PTR_LIST &getAllAtomsWithBookmark(int mark);
295  //! removes a \c bookmark from our collection
296  void clearAtomBookmark(const int mark);
297  //! removes a particular Atom from the list associated with the \c bookmark
298  void clearAtomBookmark(const int mark, const Atom *atom);
299  //! \overload
300  void clearAtomBookmark(const int mark, ATOM_SPTR atom) {
301  clearAtomBookmark(mark, atom.get());
302  };
303  //! blows out all atomic \c bookmarks
304  void clearAllAtomBookmarks() { d_atomBookmarks.clear(); };
305  //! queries whether or not any atoms are associated with a \c bookmark
306  bool hasAtomBookmark(int mark) const { return d_atomBookmarks.count(mark); };
307  //! returns a pointer to all of our atom \c bookmarks
308  ATOM_BOOKMARK_MAP *getAtomBookmarks() { return &d_atomBookmarks; };
309 
310  //! associates a Bond pointer with a bookmark
311  void setBondBookmark(BOND_SPTR bond, int mark) {
312  d_bondBookmarks[mark].push_back(bond.get());
313  };
314  //! \overload
315  void setBondBookmark(Bond *bond, int mark) {
316  d_bondBookmarks[mark].push_back(bond);
317  };
318  //! returns the first Bond associated with the \c bookmark provided
319  Bond *getBondWithBookmark(int mark);
320  //! returns all bonds associated with the \c bookmark provided
321  BOND_PTR_LIST &getAllBondsWithBookmark(int mark);
322  //! removes a \c bookmark from our collection
323  void clearBondBookmark(int mark);
324  //! removes a particular Bond from the list associated with the \c bookmark
325  void clearBondBookmark(int mark, const Bond *bond);
326  //! \overload
327  void clearBondBookmark(int mark, BOND_SPTR bond) {
328  clearBondBookmark(mark, bond.get());
329  };
330  //! blows out all bond \c bookmarks
331  void clearAllBondBookmarks() { d_bondBookmarks.clear(); };
332  //! queries whether or not any bonds are associated with a \c bookmark
333  bool hasBondBookmark(int mark) const { return d_bondBookmarks.count(mark); };
334  //! returns a pointer to all of our bond \c bookmarks
335  BOND_BOOKMARK_MAP *getBondBookmarks() { return &d_bondBookmarks; };
336 
337  //@}
338 
339  //! \name Conformers
340  //@{
341 
342  //! return the conformer with a specified ID
343  //! if the ID is negative the first conformation will be returned
344  const Conformer &getConformer(int id = -1) const;
345 
346  //! return the conformer with a specified ID
347  //! if the ID is negative the first conformation will be returned
348  Conformer &getConformer(int id = -1);
349 
350  //! Delete the conformation with the specified ID
351  void removeConformer(unsigned int id);
352 
353  //! Clear all the conformations on the molecule
354  void clearConformers() { d_confs.clear(); }
355 
356  //! Add a new conformation to the molecule
357  /*!
358  \param conf - conformation to be added to the molecule, this molecule takes
359  ownership
360  of the conformer
361  \param assignId - a unique ID will be assigned to the the conformation if
362  true
363  otherwise it is assumed that the conformation already has
364  an (unique) ID set
365  */
366  unsigned int addConformer(Conformer *conf, bool assignId = false);
367 
368  inline unsigned int getNumConformers() const {
369  return rdcast<unsigned int>(d_confs.size());
370  }
371 
372  //@}
373 
374  //! \name Topology
375  //@{
376 
377  //! returns a pointer to our RingInfo structure
378  //! <b>Note:</b> the client should not delete this.
379  RingInfo *getRingInfo() const { return dp_ringInfo; };
380 
381  //! provides access to all neighbors around an Atom
382  /*!
383  \param at the atom whose neighbors we are looking for
384 
385  <b>Usage</b>
386  \code
387  ... molPtr is a const ROMol & ...
388  ... atomPtr is a const Atom * ...
389  ROMol::ADJ_ITER nbrIdx,endNbrs;
390  boost::tie(nbrIdx,endNbrs) = molPtr.getAtomNeighbors(atomPtr);
391  while(nbrIdx!=endNbrs){
392  const ATOM_SPTR at=molPtr[*nbrIdx];
393  ... do something with the Atom ...
394  ++nbrIdx;
395  }
396  \endcode
397 
398  */
399  ADJ_ITER_PAIR getAtomNeighbors(Atom const *at) const;
400  //! \overload
401  ADJ_ITER_PAIR getAtomNeighbors(ATOM_SPTR at) const;
402 
403  //! provides access to all Bond objects connected to an Atom
404  /*!
405  \param at the atom whose neighbors we are looking for
406 
407  <b>Usage</b>
408  \code
409  ... molPtr is a const ROMol * ...
410  ... atomPtr is a const Atom * ...
411  ROMol::OEDGE_ITER beg,end;
412  boost::tie(beg,end) = molPtr->getAtomBonds(atomPtr);
413  while(beg!=end){
414  const BOND_SPTR bond=(*molPtr)[*beg];
415  ... do something with the Bond ...
416  ++beg;
417  }
418  \endcode
419  or, if you need a non-const Bond *:
420  \code
421  ... molPtr is a ROMol * ...
422  ... atomPtr is a const Atom * ...
423  ROMol::OEDGE_ITER beg,end;
424  boost::tie(beg,end) = molPtr->getAtomBonds(atomPtr);
425  while(beg!=end){
426  BOND_SPTR bond=(*molPtr)[*beg];
427  ... do something with the Bond ...
428  ++beg;
429  }
430  \endcode
431 
432 
433  */
434  OBOND_ITER_PAIR getAtomBonds(Atom const *at) const;
435 
436  //! returns an iterator pair for looping over all Atoms
437  /*!
438 
439  <b>Usage</b>
440  \code
441 
442  ROMol::VERTEX_ITER atBegin,atEnd;
443  boost::tie(atBegin,atEnd) = mol.getVertices();
444  while(atBegin!=atEnd){
445  ATOM_SPTR at2=mol[*atBegin];
446  ... do something with the Atom ...
447  ++atBegin;
448  }
449  \endcode
450  */
451  ATOM_ITER_PAIR getVertices();
452  //! returns an iterator pair for looping over all Bonds
453  /*!
454 
455  <b>Usage</b>
456  \code
457 
458  ROMol::EDGE_ITER firstB,lastB;
459  boost::tie(firstB,lastB) = mol.getEdges();
460  while(firstB!=lastB){
461  BOND_SPTR bond = mol[*firstB];
462  ... do something with the Bond ...
463  ++firstB;
464  }
465  \endcode
466  */
467  BOND_ITER_PAIR getEdges();
468  //! \overload
469  ATOM_ITER_PAIR getVertices() const;
470  //! \overload
471  BOND_ITER_PAIR getEdges() const;
472 
473  //! brief returns a pointer to our underlying BGL object
474  /*!
475  This can be useful if you need to call other BGL algorithms:
476 
477  Here's an example:
478  \code
479  ... mol is a const ROMol ...
480  ... mapping is an INT_VECT ...
481  mapping.resize(mol.getNumAtoms());
482  const MolGraph &G_p = mol.getTopology();
483  int res = boost::connected_components(G_p,&mapping[0]);
484  \endcode
485  */
486  MolGraph const &getTopology() const { return d_graph; };
487  //@}
488 
489  //! \name Iterators
490  //@{
491 
492  //! get an AtomIterator pointing at our first Atom
493  AtomIterator beginAtoms();
494  //! \overload
495  ConstAtomIterator beginAtoms() const;
496  //! get an AtomIterator pointing at the end of our Atoms
497  AtomIterator endAtoms();
498  //! \overload
499  ConstAtomIterator endAtoms() const;
500  //! get a BondIterator pointing at our first Bond
501  BondIterator beginBonds();
502  //! \overload
503  ConstBondIterator beginBonds() const;
504  //! get a BondIterator pointing at the end of our Bonds
505  BondIterator endBonds();
506  //! \overload
507  ConstBondIterator endBonds() const;
508 
509  //! get an AtomIterator pointing at our first aromatic Atom
510  AromaticAtomIterator beginAromaticAtoms();
511  //! \overload
512  ConstAromaticAtomIterator beginAromaticAtoms() const;
513  //! get an AtomIterator pointing at the end of our Atoms
514  AromaticAtomIterator endAromaticAtoms();
515  //! \overload
516  ConstAromaticAtomIterator endAromaticAtoms() const;
517 
518  //! get an AtomIterator pointing at our first hetero Atom
519  HeteroatomIterator beginHeteros();
520  //! \overload
521  ConstHeteroatomIterator beginHeteros() const;
522  //! get an AtomIterator pointing at the end of our Atoms
523  HeteroatomIterator endHeteros();
524  //! \overload
525  ConstHeteroatomIterator endHeteros() const;
526 
527  //! get an AtomIterator pointing at our first Atom that matches \c query
528  QueryAtomIterator beginQueryAtoms(QueryAtom const *query);
529  //! \overload
530  ConstQueryAtomIterator beginQueryAtoms(QueryAtom const *) const;
531  //! get an AtomIterator pointing at the end of our Atoms
532  QueryAtomIterator endQueryAtoms();
533  //! \overload
534  ConstQueryAtomIterator endQueryAtoms() const;
535 
536  //! get an AtomIterator pointing at our first Atom that matches \c query
537  MatchingAtomIterator beginMatchingAtoms(bool (*query)(Atom *));
538  //! \overload
539  ConstMatchingAtomIterator beginMatchingAtoms(
540  bool (*query)(const Atom *)) const;
541  //! get an AtomIterator pointing at the end of our Atoms
542  MatchingAtomIterator endMatchingAtoms();
543  //! \overload
544  ConstMatchingAtomIterator endMatchingAtoms() const;
545 
546  inline ConformerIterator beginConformers() { return d_confs.begin(); }
547 
548  inline ConformerIterator endConformers() { return d_confs.end(); }
549 
550  inline ConstConformerIterator beginConformers() const {
551  return d_confs.begin();
552  }
553 
554  inline ConstConformerIterator endConformers() const { return d_confs.end(); }
555 
556  //@}
557 
558  //! \name Properties
559  //@{
560 
561  //! clears all of our \c computed \c properties
562  void clearComputedProps(bool includeRings = true) const;
563  //! calculates any of our lazy \c properties
564  /*!
565  <b>Notes:</b>
566  - this calls \c updatePropertyCache() on each of our Atoms and Bonds
567  */
568  void updatePropertyCache(bool strict = true);
569 
570  bool needsUpdatePropertyCache() const;
571 
572  //@}
573 
574  //! \name Misc
575  //@{
576  //! sends some debugging info to a stream
577  void debugMol(std::ostream &str) const;
578  //@}
579 
580  ATOM_SPTR operator[](const vertex_descriptor &v) { return d_graph[v]; };
581  const ATOM_SPTR operator[](const vertex_descriptor &v) const {
582  return d_graph[v];
583  };
584 
585  BOND_SPTR operator[](const edge_descriptor &e) { return d_graph[e]; };
586  const BOND_SPTR operator[](const edge_descriptor &e) const {
587  return d_graph[e];
588  };
589 
590  private:
591  MolGraph d_graph;
592  ATOM_BOOKMARK_MAP d_atomBookmarks;
593  BOND_BOOKMARK_MAP d_bondBookmarks;
594  RingInfo *dp_ringInfo;
595  CONF_SPTR_LIST d_confs;
596  ROMol &operator=(
597  const ROMol &); // disable assignment, RWMol's support assignment
598 
599 protected:
600  unsigned int numBonds;
601 #ifndef WIN32
602 private:
603 
604 
605 #endif
606  void initMol();
607  virtual void destroy();
608  //! adds an Atom to our collection
609  /*!
610  \param atom pointer to the Atom to add
611  \param updateLabel (optional) if this is true, the new Atom will be
612  our \c activeAtom
613  \param takeOwnership (optional) if this is true, we take ownership of \c
614  atom
615  instead of copying it.
616 
617  \return the new number of atoms
618  */
619  unsigned int addAtom(Atom *atom, bool updateLabel = true,
620  bool takeOwnership = false);
621  //! adds an Atom to our collection
622  /*!
623  \param atom pointer to the Atom to add
624  \param updateLabel (optional) if this is true, the new Atom will be
625  our \c activeAtom
626 
627 
628  \return the new number of atoms
629 
630  <b>Note:</b> since this is using a smart pointer, we don't need to worry
631  about
632  issues of ownership.
633 
634  */
635  unsigned int addAtom(ATOM_SPTR, bool updateLabel = true);
636  //! adds a Bond to our collection
637  /*!
638  \param bond pointer to the Bond to add
639  \param takeOwnership (optional) if this is true, we take ownership of \c
640  bond
641  instead of copying it.
642 
643  \return the new number of bonds
644  */
645  unsigned int addBond(Bond *bond, bool takeOwnership = false);
646  //! adds a Bond to our collection
647  /*!
648  \param bond pointer to the Bond to add
649 
650  \return the new number of bonds
651 
652  <b>Note:</b> since this is using a smart pointer, we don't need to worry
653  about
654  issues of ownership.
655  */
656  unsigned int addBond(BOND_SPTR bsp);
657 
658  //! initializes from the contents of another molecule
659  /*!
660  \param other the molecule to be copied
661  \param quickCopy if this is true, we will not
662  copy any of the properties or bookmarks and conformers from \c other.
663  This can
664  make the copy substantially faster (thus the name).
665  \param confId if this is >=0, the resulting ROMol will contain only
666  the specified conformer from \c other.
667  */
668  void initFromOther(const ROMol &other, bool quickCopy, int confId);
669 };
670 
671 typedef std::vector<ROMol> MOL_VECT;
672 typedef boost::shared_ptr<ROMol> ROMOL_SPTR;
673 typedef std::vector<ROMol *> MOL_PTR_VECT;
674 typedef std::vector<ROMOL_SPTR> MOL_SPTR_VECT;
675 
676 typedef MOL_PTR_VECT::const_iterator MOL_PTR_VECT_CI;
677 typedef MOL_PTR_VECT::iterator MOL_PTR_VECT_I;
678 
679 }; // end of RDKit namespace
680 #endif
Bond * getBondWithBookmark(int mark)
returns the first Bond associated with the bookmark provided
boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, ATOM_SPTR, BOND_SPTR > MolGraph
This is the BGL type used to store the topology:
Definition: ROMol.h:50
AtomIterator endAtoms()
get an AtomIterator pointing at the end of our Atoms
boost::shared_ptr< Bond > BOND_SPTR
Definition: ROMol.h:42
bool hasBondBookmark(int mark) const
queries whether or not any bonds are associated with a bookmark
Definition: ROMol.h:333
ATOM_PTR_LIST & getAllAtomsWithBookmark(int mark)
returns all Atoms associated with the bookmark provided
void clearComputedProps() const
clears all of our computed properties
Definition: RDProps.h:140
unsigned int getNumConformers() const
Definition: ROMol.h:368
void removeConformer(unsigned int id)
Delete the conformation with the specified ID.
ATOM_ITER_PAIR getVertices()
returns an iterator pair for looping over all Atoms
const int ci_RIGHTMOST_ATOM
ATOM_BOOKMARK_MAP * getAtomBookmarks()
returns a pointer to all of our atom bookmarks
Definition: ROMol.h:308
void setBondBookmark(BOND_SPTR bond, int mark)
associates a Bond pointer with a bookmark
Definition: ROMol.h:311
std::vector< ROMol > MOL_VECT
Definition: ROMol.h:671
void replaceAtomBookmark(Atom *at, int mark)
Definition: ROMol.h:287
Iterate over aromatic atoms, this is bidirectional.
MOL_PTR_VECT::iterator MOL_PTR_VECT_I
Definition: ROMol.h:677
void setBondBookmark(Bond *bond, int mark)
Definition: ROMol.h:315
std::vector< ROMol * > MOL_PTR_VECT
Definition: ROMol.h:673
void setAtomBookmark(Atom *at, int mark)
Definition: ROMol.h:278
RWMol is a molecule class that is intended to be edited.
Definition: RWMol.h:30
BondIterator endBonds()
get a BondIterator pointing at the end of our Bonds
Iterate over atoms matching a query. This is bidirectional.
const int ci_ATOM_HOLDER
AromaticAtomIterator beginAromaticAtoms()
get an AtomIterator pointing at our first aromatic Atom
ROMol(const ROMol &other, bool quickCopy=false, int confId=-1)
copy constructor with a twist
Definition: ROMol.h:194
boost::shared_ptr< Atom > ATOM_SPTR
Definition: Bond.h:27
ADJ_ITER_PAIR getAtomNeighbors(Atom const *at) const
provides access to all neighbors around an Atom
Class for storing atomic queries.
Definition: QueryAtom.h:26
HeteroatomIterator beginHeteros()
get an AtomIterator pointing at our first hetero Atom
unsigned int getNumAtoms(bool onlyExplicit=1) const
returns our number of atoms
void clearBondBookmark(int mark)
removes a bookmark from our collection
iterator for a molecule&#39;s bonds, currently BiDirectional, but it theoretically ought to be RandomAcce...
Definition: BondIterators.h:26
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:106
std::vector< boost::shared_ptr< ROMol > > MOL_SPTR_VECT
Definition: FragCatParams.h:19
const Atom * getAtomWithIdx(const U idx) const
Definition: ROMol.h:223
void clearBondBookmark(int mark, BOND_SPTR bond)
Definition: ROMol.h:327
QueryAtomIterator endQueryAtoms()
get an AtomIterator pointing at the end of our Atoms
const ATOM_SPTR operator[](const vertex_descriptor &v) const
Definition: ROMol.h:581
const Conformer & getConformer(int id=-1) const
BOND_SPTR operator[](const edge_descriptor &e)
Definition: ROMol.h:585
MOL_PTR_VECT::const_iterator MOL_PTR_VECT_CI
Definition: ROMol.h:676
Bond * getBondBetweenAtoms(unsigned int idx1, unsigned int idx2)
returns a pointer to the bond between two atoms, Null on failure
QueryAtomIterator beginQueryAtoms(QueryAtom const *query)
get an AtomIterator pointing at our first Atom that matches query
unsigned int numBonds
Definition: ROMol.h:600
const BOND_SPTR operator[](const edge_descriptor &e) const
Definition: ROMol.h:586
unsigned int getNumBonds(bool onlyHeavy=1) const
returns our number of Bonds
void updatePropertyCache(bool strict=true)
calculates any of our lazy properties
const Bond * getBondBetweenAtoms(const U idx1, const V idx2) const
Definition: ROMol.h:263
BOND_PTR_LIST & getAllBondsWithBookmark(int mark)
returns all bonds associated with the bookmark provided
MatchingAtomIterator endMatchingAtoms()
get an AtomIterator pointing at the end of our Atoms
MolGraph const & getTopology() const
brief returns a pointer to our underlying BGL object
Definition: ROMol.h:486
const Bond * getBondWithIdx(const U idx) const
Definition: ROMol.h:248
MatchingAtomIterator beginMatchingAtoms(bool(*query)(Atom *))
get an AtomIterator pointing at our first Atom that matches query
void debugMol(std::ostream &str) const
sends some debugging info to a stream
Bond * getBondWithIdx(unsigned int idx)
returns a pointer to a particular Bond
const iterator for a molecule&#39;s bonds, currently BiDirectional, but it theoretically ought to be Rand...
Definition: BondIterators.h:51
boost::shared_ptr< ROMol > ROMOL_SPTR
virtual ~ROMol()
Definition: ROMol.h:202
BOND_BOOKMARK_MAP * getBondBookmarks()
returns a pointer to all of our bond bookmarks
Definition: ROMol.h:335
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:29
A general random access iterator.
Definition: AtomIterators.h:30
A class to store information about a molecule&#39;s rings.
Definition: RingInfo.h:21
void clearConformers()
Clear all the conformations on the molecule.
Definition: ROMol.h:354
void replaceAtomBookmark(ATOM_SPTR at, int mark)
associates an Atom pointer with a bookmark
Definition: ROMol.h:282
bool needsUpdatePropertyCache() const
ConstConformerIterator endConformers() const
Definition: ROMol.h:554
void clearAtomBookmark(const int mark, ATOM_SPTR atom)
Definition: ROMol.h:300
ATOM_SPTR operator[](const vertex_descriptor &v)
Definition: ROMol.h:580
const int ci_LEADING_BOND
class for representing a bond
Definition: Bond.h:47
void clearAllAtomBookmarks()
blows out all atomic bookmarks
Definition: ROMol.h:304
HeteroatomIterator endHeteros()
get an AtomIterator pointing at the end of our Atoms
Iterate over atoms matching a query function. This is bidirectional.
RingInfo * getRingInfo() const
Definition: ROMol.h:379
BondIterator beginBonds()
get a BondIterator pointing at our first Bond
BOND_ITER_PAIR getEdges()
returns an iterator pair for looping over all Bonds
handles pickling (serializing) molecules
Definition: MolPickler.h:60
AtomIterator beginAtoms()
get an AtomIterator pointing at our first Atom
Atom * getAtomWithIdx(const U idx)
Definition: ROMol.h:218
The class for representing 2D or 3D conformation of a molecule.
Definition: Conformer.h:41
Bond * getBondBetweenAtoms(const U idx1, const V idx2)
Definition: ROMol.h:257
ConformerIterator endConformers()
Definition: ROMol.h:548
void clearAtomBookmark(const int mark)
removes a bookmark from our collection
Atom * getAtomWithIdx(unsigned int idx)
returns a pointer to a particular Atom
Defines the Atom class and associated typedefs.
bool hasAtomBookmark(int mark) const
queries whether or not any atoms are associated with a bookmark
Definition: ROMol.h:306
ConformerIterator beginConformers()
Definition: ROMol.h:546
Atom * getAtomWithBookmark(int mark)
returns the first Atom associated with the bookmark provided
unsigned int getAtomDegree(const Atom *at) const
returns the degree (number of neighbors) of an Atom in the graph
Bond * getBondWithIdx(const U idx)
Definition: ROMol.h:243
void clearAllBondBookmarks()
blows out all bond bookmarks
Definition: ROMol.h:331
Class for storing Bond queries.
Definition: QueryBond.h:27
OBOND_ITER_PAIR getAtomBonds(Atom const *at) const
provides access to all Bond objects connected to an Atom
unsigned int getNumHeavyAtoms() const
returns our number of heavy atoms (atomic number > 1)
ConstConformerIterator beginConformers() const
Definition: ROMol.h:550
Iterate over heteroatoms, this is bidirectional.
Definition: AtomIterators.h:72
The class for representing atoms.
Definition: Atom.h:68
AromaticAtomIterator endAromaticAtoms()
get an AtomIterator pointing at the end of our Atoms
void setAtomBookmark(ATOM_SPTR at, int mark)
associates an Atom pointer with a bookmark
Definition: ROMol.h:274
unsigned int addConformer(Conformer *conf, bool assignId=false)
Add a new conformation to the molecule.