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