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