RWMol.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (C) 2003-2009 Greg Landrum and Rational Discovery LLC
00003 //
00004 //   @@ All Rights Reserved  @@
00005 //
00006 /*! \file RWMol.h
00007 
00008   \brief Defines the editable molecule class \c RWMol
00009 
00010 */  
00011 
00012 #ifndef __RD_RWMOL_H__
00013 #define __RD_RWMOL_H__
00014 
00015 // our stuff
00016 #include "ROMol.h"
00017 
00018 namespace RDKit{
00019 
00020   //! RWMol is a molecule class that is intended to be edited
00021   /*!
00022       See documentation for ROMol for general remarks
00023 
00024    */
00025   class RWMol : public ROMol {
00026   public:
00027   
00028     RWMol() { d_partialBonds.clear(); }
00029 
00030     //! copy constructor with a twist
00031     /*!
00032       \param other     the molecule to be copied
00033       \param quickCopy (optional) if this is true, the resulting ROMol will not
00034            copy any of the properties or bookmarks and conformers from \c other.  This can
00035            make the copy substantially faster (thus the name).
00036     */
00037     RWMol(const ROMol &other,bool quickCopy=false) {d_partialBonds.clear(); initFromOther(other,quickCopy);};
00038 
00039 
00040     //! insert the atoms and bonds from \c other into this molecule
00041     void insertMol( const ROMol &other);
00042   
00043 
00044     //! \name Atoms
00045     //@{
00046 
00047     //! adds an empty Atom to our collection
00048     /*!
00049       \param updateLabel   (optional) if this is true, the new Atom will be
00050                            our \c activeAtom
00051 
00052       \return the new number of atoms
00053 
00054     */
00055     unsigned int addAtom(bool updateLabel=true);
00056 
00057     //! adds an Atom to our collection
00058     /*!
00059       \param atom          pointer to the Atom to add
00060       \param updateLabel   (optional) if this is true, the new Atom will be
00061                            our \c activeAtom
00062       \param takeOwnership (optional) if this is true, we take ownership of \c atom
00063                            instead of copying it.
00064 
00065       \return the new number of atoms
00066     */
00067     unsigned int addAtom(Atom *atom,bool updateLabel=true,bool takeOwnership=false){
00068       return ROMol::addAtom(atom,updateLabel,takeOwnership);
00069     };
00070 
00071     //! adds an Atom to our collection
00072     /*!
00073       \param atom          pointer to the Atom to add
00074       \param updateLabel   (optional) if this is true, the new Atom will be
00075                            our \c activeAtom
00076 
00077 
00078       \return the new number of atoms
00079 
00080       <b>Note:</b> since this is using a smart pointer, we don't need to worry about
00081       issues of ownership.
00082 
00083     */
00084     unsigned int addAtom(ATOM_SPTR atom,bool updateLabel=true){
00085       return ROMol::addAtom(atom,updateLabel);
00086     };
00087 
00088     //! replaces a particular Atom
00089     /*!
00090       \param idx          the index of the Atom to replace
00091       \param atom         the new atom, which will be copied.
00092       \param updateLabel   (optional) if this is true, the new Atom will be
00093                            our \c activeAtom
00094 
00095     */
00096     void replaceAtom(unsigned int idx,Atom *atom,bool updateLabel=false);
00097     //! returns a pointer to the highest-numbered Atom
00098     Atom *getLastAtom() { return getAtomWithIdx(getNumAtoms()-1); };
00099     //! returns a pointer to the "active" Atom
00100     /*!
00101        If we have an \c activeAtom, it will be returned,
00102        otherwise the results of getLastAtom() will be returned.
00103      */
00104     Atom *getActiveAtom();
00105     //! sets our \c activeAtom
00106     void setActiveAtom(Atom *atom);
00107     //! \overload
00108     void setActiveAtom(unsigned int idx);
00109     //! removes an Atom from the molecule
00110     void removeAtom(unsigned int idx);
00111     //! \overload
00112     void removeAtom(Atom *atom);
00113 
00114     //@}
00115 
00116 
00117     //! \name Bonds
00118     //@{
00119 
00120     //! adds a Bond between the indicated Atoms
00121     /*!
00122        \return the number of Bonds
00123     */
00124     unsigned int addBond(unsigned int beginAtomIdx,unsigned int endAtomIdx,
00125                          Bond::BondType order=Bond::UNSPECIFIED);
00126     //! \overload
00127     unsigned int addBond(ATOM_SPTR beginAtom,ATOM_SPTR endAtom,
00128                          Bond::BondType order=Bond::UNSPECIFIED);
00129     //! \overload
00130     unsigned int addBond(Atom *beginAtom, Atom *endAtom,
00131                          Bond::BondType order=Bond::UNSPECIFIED);
00132 
00133 
00134     //! adds a Bond to our collection
00135     /*!
00136       \param bond          pointer to the Bond to add
00137       \param takeOwnership (optional) if this is true, we take ownership of \c bond
00138                            instead of copying it.
00139 
00140       \return the new number of bonds
00141     */
00142     unsigned int addBond(Bond *bond,bool takeOwnership=false){
00143       return ROMol::addBond(bond,takeOwnership);
00144     };
00145     //! adds a Bond to our collection
00146     /*!
00147       \param bond          pointer to the Bond to add
00148 
00149       \return the new number of bonds
00150 
00151       <b>Note:</b> since this is using a smart pointer, we don't need to worry about
00152       issues of ownership.
00153     */
00154     unsigned int addBond(BOND_SPTR bsp){
00155       return ROMol::addBond(bsp);
00156     };
00157 
00158 
00159     //! starts a Bond and sets its beginAtomIdx
00160     /*!
00161       \return a pointer to the new bond
00162 
00163       The caller should set a bookmark to the returned Bond in order
00164       to be able to later complete it:
00165 
00166       \verbatim
00167         Bond *pBond = mol->createPartialBond(1);
00168         mol->setBondBookmark(pBond,666);
00169         ... do some other stuff ...
00170         mol->finishPartialBond(2,666,Bond::SINGLE);
00171         mol->clearBondBookmark(666,pBond);
00172       \endverbatim
00173 
00174       or, if we want to set the \c BondType initially:
00175       \verbatim
00176         Bond *pBond = mol->createPartialBond(1,Bond::DOUBLE);
00177         mol->setBondBookmark(pBond,666);
00178         ... do some other stuff ...
00179         mol->finishPartialBond(2,666);
00180         mol->clearBondBookmark(666,pBond);
00181       \endverbatim
00182 
00183       the call to finishPartialBond() will take priority if you set the
00184       \c BondType in both calls.
00185       
00186     */
00187     Bond *createPartialBond(unsigned int beginAtomIdx,
00188                             Bond::BondType order=Bond::UNSPECIFIED);
00189     //! finishes a partially constructed bond
00190     /*!
00191       \return the final number of Bonds
00192 
00193       See the documentation for createPartialBond() for more details
00194     */
00195     unsigned int finishPartialBond(unsigned int endAtomIdx,int bondBookmark,
00196                                    Bond::BondType order=Bond::UNSPECIFIED);
00197 
00198     //! removes a bond from the molecule
00199     void removeBond(unsigned int beginAtomIdx, unsigned int endAtomIdx);
00200     //@}
00201 
00202   private:
00203     std::vector<BOND_SPTR> d_partialBonds;
00204     void destroy();
00205     ROMol &operator=(const ROMol &); // disable assignment
00206 
00207   };
00208 
00209   typedef boost::shared_ptr<RWMol>    RWMOL_SPTR;
00210   typedef std::vector< RWMOL_SPTR > RWMOL_SPTR_VECT;
00211 
00212 }; // end of RDKit namespace
00213 
00214 #endif

Generated on Fri Apr 3 06:03:02 2009 for RDCode by  doxygen 1.5.6