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