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