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 #include <RDGeneral/export.h>
17 #ifndef __RD_RWMOL_H__
18 #define __RD_RWMOL_H__
19 
20 // our stuff
21 #include "ROMol.h"
22 #include "RingInfo.h"
23 
24 namespace RDKit {
25 
26 //! RWMol is a molecule class that is intended to be edited
27 /*!
28  See documentation for ROMol for general remarks
29 
30  */
32  public:
33  RWMol() : ROMol() { 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.
40  This can
41  make the copy substantially faster (thus the name).
42  \param confId if this is >=0, the resulting ROMol will contain only
43  the specified conformer from \c other.
44  */
45  RWMol(const ROMol &other, bool quickCopy = false, int confId = -1)
46  : ROMol(other, quickCopy, confId) {
47  d_partialBonds.clear();
48  };
49  RWMol(const RWMol &other) : ROMol(other){};
50  RWMol &operator=(const RWMol &);
51 
52  //! insert the atoms and bonds from \c other into this molecule
53  void insertMol(const ROMol &other);
54 
55  //! \name Atoms
56  //@{
57 
58  //! adds an empty Atom to our collection
59  /*!
60  \param updateLabel (optional) if this is true, the new Atom will be
61  our \c activeAtom
62 
63  \return the index of the added atom
64 
65  */
66  unsigned int addAtom(bool updateLabel = true);
67 
68  //! adds an Atom to our collection
69  /*!
70  \param atom pointer to the Atom to add
71  \param updateLabel (optional) if this is true, the new Atom will be
72  our \c activeAtom
73  \param takeOwnership (optional) if this is true, we take ownership of \c
74  atom
75  instead of copying it.
76 
77  \return the index of the added atom
78  */
79  unsigned int addAtom(Atom *atom, bool updateLabel = true,
80  bool takeOwnership = false) {
81  return ROMol::addAtom(atom, updateLabel, takeOwnership);
82  };
83 
84  //! adds an Atom to our collection
85 
86  //! replaces a particular Atom
87  /*!
88  \param idx the index of the Atom to replace
89  \param atom the new atom, which will be copied.
90  \param updateLabel (optional) if this is true, the new Atom will be
91  our \c activeAtom
92  \param preserveProps if true preserve the original atom property data
93 
94  */
95  void replaceAtom(unsigned int idx, Atom *atom, bool updateLabel = false,
96  bool preserveProps = false);
97  //! returns a pointer to the highest-numbered Atom
98  Atom *getLastAtom() { return getAtomWithIdx(getNumAtoms() - 1); };
99  //! returns a pointer to the "active" Atom
100  /*!
101  If we have an \c activeAtom, it will be returned,
102  otherwise the results of getLastAtom() will be returned.
103  */
104  Atom *getActiveAtom();
105  //! sets our \c activeAtom
106  void setActiveAtom(Atom *atom);
107  //! \overload
108  void setActiveAtom(unsigned int idx);
109  //! removes an Atom from the molecule
110  void removeAtom(unsigned int idx);
111  //! \overload
112  void removeAtom(Atom *atom);
113 
114  //@}
115 
116  //! \name Bonds
117  //@{
118 
119  //! adds a Bond between the indicated Atoms
120  /*!
121  \return the number of Bonds
122  */
123  unsigned int addBond(unsigned int beginAtomIdx, unsigned int endAtomIdx,
125  //! \overload
126  unsigned int addBond(Atom *beginAtom, Atom *endAtom,
128 
129  //! adds a Bond to our collection
130  /*!
131  \param bond pointer to the Bond to add
132  \param takeOwnership (optional) if this is true, we take ownership of \c
133  bond
134  instead of copying it.
135 
136  \return the new number of bonds
137  */
138  unsigned int addBond(Bond *bond, bool takeOwnership = false) {
139  return ROMol::addBond(bond, takeOwnership);
140  };
141 
142  //! starts a Bond and sets its beginAtomIdx
143  /*!
144  \return a pointer to the new bond
145 
146  The caller should set a bookmark to the returned Bond in order
147  to be able to later complete it:
148 
149  \verbatim
150  Bond *pBond = mol->createPartialBond(1);
151  mol->setBondBookmark(pBond,666);
152  ... do some other stuff ...
153  mol->finishPartialBond(2,666,Bond::SINGLE);
154  mol->clearBondBookmark(666,pBond);
155  \endverbatim
156 
157  or, if we want to set the \c BondType initially:
158  \verbatim
159  Bond *pBond = mol->createPartialBond(1,Bond::DOUBLE);
160  mol->setBondBookmark(pBond,666);
161  ... do some other stuff ...
162  mol->finishPartialBond(2,666);
163  mol->clearBondBookmark(666,pBond);
164  \endverbatim
165 
166  the call to finishPartialBond() will take priority if you set the
167  \c BondType in both calls.
168 
169  */
170  Bond *createPartialBond(unsigned int beginAtomIdx,
172  //! finishes a partially constructed bond
173  /*!
174  \return the final number of Bonds
175 
176  See the documentation for createPartialBond() for more details
177  */
178  unsigned int finishPartialBond(unsigned int endAtomIdx, int bondBookmark,
180 
181  //! removes a bond from the molecule
182  void removeBond(unsigned int beginAtomIdx, unsigned int endAtomIdx);
183 
184  //! replaces a particular Bond
185  /*!
186  \param idx the index of the Bond to replace
187  \param bond the new bond, which will be copied.
188  \param preserveProps if true preserve the original bond property data
189 
190  */
191  void replaceBond(unsigned int idx, Bond *bond, bool preserveProps = false);
192 
193  //@}
194 
195  //! Sets groups of atoms with relative stereochemistry
196  /*!
197  \param stereo_groups the new set of stereo groups. All will be replaced.
198 
199  Stereo groups are also called enhanced stereochemistry in the SDF/Mol3000
200  file format. stereo_groups should be std::move()ed into this function.
201  */
202  void setStereoGroups(std::vector<StereoGroup> &&stereo_groups) {
203  return ROMol::setStereoGroups(std::move(stereo_groups));
204  };
205 
206  //! removes all atoms, bonds, properties, bookmarks, etc.
207  void clear() {
208  destroy();
209  d_confs.clear();
210  ROMol::initMol(); // make sure we have a "fresh" ready to go copy
211  numBonds = 0;
212  };
213 
214  private:
215  std::vector<Bond *> d_partialBonds;
216  void destroy();
217 };
218 
219 typedef boost::shared_ptr<RWMol> RWMOL_SPTR;
220 typedef std::vector<RWMOL_SPTR> RWMOL_SPTR_VECT;
221 
222 }; // namespace RDKit
223 
224 #endif
RDKit::RWMol::RWMol
RWMol(const RWMol &other)
Definition: RWMol.h:49
ROMol.h
Defines the primary molecule class ROMol as well as associated typedefs.
RDKit::Bond
class for representing a bond
Definition: Bond.h:47
RDKit::RWMol
RWMol is a molecule class that is intended to be edited.
Definition: RWMol.h:31
RDKit::Bond::BondType
BondType
the type of Bond
Definition: Bond.h:56
RDKit::RWMOL_SPTR
boost::shared_ptr< RWMol > RWMOL_SPTR
Definition: RWMol.h:219
RDKit::Atom
The class for representing atoms.
Definition: Atom.h:69
RDKit::ROMol
Definition: ROMol.h:171
RDKIT_GRAPHMOL_EXPORT
#define RDKIT_GRAPHMOL_EXPORT
Definition: export.h:307
RDKit::RWMol::RWMol
RWMol()
Definition: RWMol.h:33
RDKit::RWMol::getLastAtom
Atom * getLastAtom()
returns a pointer to the highest-numbered Atom
Definition: RWMol.h:98
RDKit::RWMol::addAtom
unsigned int addAtom(Atom *atom, bool updateLabel=true, bool takeOwnership=false)
adds an Atom to our collection
Definition: RWMol.h:79
RDKit::RDProps::clear
void clear()
Definition: RDProps.h:25
RDKit
Std stuff.
Definition: Atom.h:30
RDKit::RWMOL_SPTR_VECT
std::vector< RWMOL_SPTR > RWMOL_SPTR_VECT
Definition: FileParsers.h:46
RDKit::Bond::UNSPECIFIED
@ UNSPECIFIED
Definition: Bond.h:57
RDKit::RWMol::setStereoGroups
void setStereoGroups(std::vector< StereoGroup > &&stereo_groups)
Sets groups of atoms with relative stereochemistry.
Definition: RWMol.h:202
RDKit::RWMol::addBond
unsigned int addBond(Bond *bond, bool takeOwnership=false)
adds a Bond to our collection
Definition: RWMol.h:138
RDKit::RWMol::RWMol
RWMol(const ROMol &other, bool quickCopy=false, int confId=-1)
copy constructor with a twist
Definition: RWMol.h:45
RDKit::RWMol::clear
void clear()
removes all atoms, bonds, properties, bookmarks, etc.
Definition: RWMol.h:207
RingInfo.h
export.h