RDKit
Open-source cheminformatics and machine learning.
RWMol.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2003-2009 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 RWMol.h
11 
12  \brief Defines the editable molecule class \c RWMol
13 
14 */
15 
16 #ifndef __RD_RWMOL_H__
17 #define __RD_RWMOL_H__
18 
19 // our stuff
20 #include "ROMol.h"
21 #include "RingInfo.h"
22 
23 namespace RDKit{
24 
25  //! RWMol is a molecule class that is intended to be edited
26  /*!
27  See documentation for ROMol for general remarks
28 
29  */
30  class RWMol : public ROMol {
31  public:
32 
33  RWMol() { d_partialBonds.clear(); }
34 
35  //! copy constructor with a twist
36  /*!
37  \param other the molecule to be copied
38  \param quickCopy (optional) if this is true, the resulting ROMol will not
39  copy any of the properties or bookmarks and conformers from \c other. This can
40  make the copy substantially faster (thus the name).
41  \param confId if this is >=0, the resulting ROMol will contain only
42  the specified conformer from \c other.
43  */
44  RWMol(const ROMol &other,bool quickCopy=false,int confId=-1) {
45  d_partialBonds.clear();
46  initFromOther(other,quickCopy,confId);
47  };
48  RWMol &operator=(const RWMol &);
49 
50  //! insert the atoms and bonds from \c other into this molecule
51  void insertMol( const ROMol &other);
52 
53 
54  //! \name Atoms
55  //@{
56 
57  //! adds an empty Atom to our collection
58  /*!
59  \param updateLabel (optional) if this is true, the new Atom will be
60  our \c activeAtom
61 
62  \return the new number of atoms
63 
64  */
65  unsigned int addAtom(bool updateLabel=true);
66 
67  //! adds an Atom to our collection
68  /*!
69  \param atom pointer to the Atom to add
70  \param updateLabel (optional) if this is true, the new Atom will be
71  our \c activeAtom
72  \param takeOwnership (optional) if this is true, we take ownership of \c atom
73  instead of copying it.
74 
75  \return the new number of atoms
76  */
77  unsigned int addAtom(Atom *atom,bool updateLabel=true,bool takeOwnership=false){
78  return ROMol::addAtom(atom,updateLabel,takeOwnership);
79  };
80 
81  //! adds an Atom to our collection
82  /*!
83  \param atom pointer to the Atom to add
84  \param updateLabel (optional) if this is true, the new Atom will be
85  our \c activeAtom
86 
87 
88  \return the new number of atoms
89 
90  <b>Note:</b> since this is using a smart pointer, we don't need to worry about
91  issues of ownership.
92 
93  */
94  unsigned int addAtom(ATOM_SPTR atom,bool updateLabel=true){
95  return ROMol::addAtom(atom,updateLabel);
96  };
97 
98  //! replaces a particular Atom
99  /*!
100  \param idx the index of the Atom to replace
101  \param atom the new atom, which will be copied.
102  \param updateLabel (optional) if this is true, the new Atom will be
103  our \c activeAtom
104 
105  */
106  void replaceAtom(unsigned int idx,Atom *atom,bool updateLabel=false);
107  //! returns a pointer to the highest-numbered Atom
109  //! returns a pointer to the "active" Atom
110  /*!
111  If we have an \c activeAtom, it will be returned,
112  otherwise the results of getLastAtom() will be returned.
113  */
114  Atom *getActiveAtom();
115  //! sets our \c activeAtom
116  void setActiveAtom(Atom *atom);
117  //! \overload
118  void setActiveAtom(unsigned int idx);
119  //! removes an Atom from the molecule
120  void removeAtom(unsigned int idx);
121  //! \overload
122  void removeAtom(Atom *atom);
123 
124  //@}
125 
126 
127  //! \name Bonds
128  //@{
129 
130  //! adds a Bond between the indicated Atoms
131  /*!
132  \return the number of Bonds
133  */
134  unsigned int addBond(unsigned int beginAtomIdx,unsigned int endAtomIdx,
136  //! \overload
137  unsigned int addBond(ATOM_SPTR beginAtom,ATOM_SPTR endAtom,
139  //! \overload
140  unsigned int addBond(Atom *beginAtom, Atom *endAtom,
142 
143 
144  //! adds a Bond to our collection
145  /*!
146  \param bond pointer to the Bond to add
147  \param takeOwnership (optional) if this is true, we take ownership of \c bond
148  instead of copying it.
149 
150  \return the new number of bonds
151  */
152  unsigned int addBond(Bond *bond,bool takeOwnership=false){
153  return ROMol::addBond(bond,takeOwnership);
154  };
155  //! adds a Bond to our collection
156  /*!
157  \param bsp smart pointer to the Bond to add
158 
159  \return the new number of bonds
160 
161  <b>Note:</b> since this is using a smart pointer, we don't need to worry about
162  issues of ownership.
163  */
164  unsigned int addBond(BOND_SPTR bsp){
165  return ROMol::addBond(bsp);
166  };
167 
168 
169  //! starts a Bond and sets its beginAtomIdx
170  /*!
171  \return a pointer to the new bond
172 
173  The caller should set a bookmark to the returned Bond in order
174  to be able to later complete it:
175 
176  \verbatim
177  Bond *pBond = mol->createPartialBond(1);
178  mol->setBondBookmark(pBond,666);
179  ... do some other stuff ...
180  mol->finishPartialBond(2,666,Bond::SINGLE);
181  mol->clearBondBookmark(666,pBond);
182  \endverbatim
183 
184  or, if we want to set the \c BondType initially:
185  \verbatim
186  Bond *pBond = mol->createPartialBond(1,Bond::DOUBLE);
187  mol->setBondBookmark(pBond,666);
188  ... do some other stuff ...
189  mol->finishPartialBond(2,666);
190  mol->clearBondBookmark(666,pBond);
191  \endverbatim
192 
193  the call to finishPartialBond() will take priority if you set the
194  \c BondType in both calls.
195 
196  */
197  Bond *createPartialBond(unsigned int beginAtomIdx,
199  //! finishes a partially constructed bond
200  /*!
201  \return the final number of Bonds
202 
203  See the documentation for createPartialBond() for more details
204  */
205  unsigned int finishPartialBond(unsigned int endAtomIdx,int bondBookmark,
207 
208  //! removes a bond from the molecule
209  void removeBond(unsigned int beginAtomIdx, unsigned int endAtomIdx);
210  //@}
211 
212  //! removes all atoms, bonds, properties, bookmarks, etc.
213  void clear() {
214  d_atomBookmarks.clear();
215  d_bondBookmarks.clear();
216  d_graph.clear();
217  d_confs.clear();
218  if(dp_props){
219  dp_props->reset();
220  STR_VECT computed;
221  dp_props->setVal(detail::computedPropName, computed);
222  }
223  if(dp_ringInfo) dp_ringInfo->reset();
224  };
225 
226 
227  private:
228  std::vector<BOND_SPTR> d_partialBonds;
229  void destroy();
230 
231  };
232 
233  typedef boost::shared_ptr<RWMol> RWMOL_SPTR;
234  typedef std::vector< RWMOL_SPTR > RWMOL_SPTR_VECT;
235 
236 }; // end of RDKit namespace
237 
238 #endif
boost::shared_ptr< Bond > BOND_SPTR
Definition: ROMol.h:38
void clear()
removes all atoms, bonds, properties, bookmarks, etc.
Definition: RWMol.h:213
std::vector< RWMOL_SPTR > RWMOL_SPTR_VECT
Definition: FileParsers.h:30
void insertMol(const ROMol &other)
insert the atoms and bonds from other into this molecule
RWMol is a molecule class that is intended to be edited.
Definition: RWMol.h:30
unsigned int addAtom(bool updateLabel=true)
adds an empty Atom to our collection
unsigned int addBond(BOND_SPTR bsp)
adds a Bond to our collection
Definition: RWMol.h:164
Defines the primary molecule class ROMol as well as associated typedefs.
boost::shared_ptr< Atom > ATOM_SPTR
Definition: Bond.h:26
void replaceAtom(unsigned int idx, Atom *atom, bool updateLabel=false)
replaces a particular Atom
unsigned int getNumAtoms(bool onlyExplicit=1) const
returns our number of atoms
BondType
the type of Bond
Definition: Bond.h:55
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:105
RWMol(const ROMol &other, bool quickCopy=false, int confId=-1)
copy constructor with a twist
Definition: RWMol.h:44
unsigned int finishPartialBond(unsigned int endAtomIdx, int bondBookmark, Bond::BondType order=Bond::UNSPECIFIED)
finishes a partially constructed bond
Bond * createPartialBond(unsigned int beginAtomIdx, Bond::BondType order=Bond::UNSPECIFIED)
starts a Bond and sets its beginAtomIdx
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:28
boost::shared_ptr< RWMol > RWMOL_SPTR
Definition: RWMol.h:233
unsigned int addAtom(ATOM_SPTR atom, bool updateLabel=true)
adds an Atom to our collection
Definition: RWMol.h:94
const std::string computedPropName
Definition: types.h:25
void removeBond(unsigned int beginAtomIdx, unsigned int endAtomIdx)
removes a bond from the molecule
class for representing a bond
Definition: Bond.h:46
unsigned int addBond(Bond *bond, bool takeOwnership=false)
adds a Bond to our collection
Definition: RWMol.h:152
void removeAtom(unsigned int idx)
removes an Atom from the molecule
void setActiveAtom(Atom *atom)
sets our activeAtom
RWMol & operator=(const RWMol &)
Atom * getAtomWithIdx(unsigned int idx)
returns a pointer to a particular Atom
Atom * getActiveAtom()
returns a pointer to the "active" Atom
unsigned int addAtom(Atom *atom, bool updateLabel=true, bool takeOwnership=false)
adds an Atom to our collection
Definition: RWMol.h:77
The class for representing atoms.
Definition: Atom.h:67
Atom * getLastAtom()
returns a pointer to the highest-numbered Atom
Definition: RWMol.h:108
std::vector< std::string > STR_VECT
Definition: Dict.h:26
unsigned int addBond(unsigned int beginAtomIdx, unsigned int endAtomIdx, Bond::BondType order=Bond::UNSPECIFIED)
adds a Bond between the indicated Atoms