RDKit: RWMol.h Source File

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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