RDCode: Conformer.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories

# Conformer.h

Go to the documentation of this file.

    00001 //
    00002 //  Copyright (C) 2001-2008 Greg Landrum and Rational Discovery LLC
    00003 //
    00004 //   @@ All Rights Reserved  @@
    00005 //
    00006 #ifndef _RD_CONFORMER_H
    00007 #define _RD_CONFORMER_H
    00008
    00009 #include <Geometry/point.h>
    00010 #include <RDGeneral/types.h>
    00011 #include <boost/smart_ptr.hpp>
    00012
    00013 namespace RDKit {
    00014   class ROMol;
    00015
    00016   //! used to indicate errors from incorrect confomer access
    00017   class ConformerException : public std::exception {
    00018   public:
    00019     //! construct with an error message
    00020     ConformerException(const char *msg) : _msg(msg) {};
    00021     //! construct with an error message
    00022     ConformerException(const std::string msg) : _msg(msg) {};
    00023     //! get the error message
    00024     const char *message () const { return _msg.c_str(); };
    00025     ~ConformerException () throw () {};
    00026   private:
    00027     std::string _msg;
    00028   };
    00029
    00030
    00031   //! The class for representing 2D or 3D conformation of a molecule
    00032   /*!
    00033     This class contains
    00034     - a pointer to the owing molecule
    00035     - a vector of 3D points (positions of atoms)
    00036   */
    00037   class Conformer {
    00038   public:
    00039
    00040     friend class ROMol;
    00041
    00042     //! Constructor
    00043     Conformer() : df_is3D(true), d_id(0), dp_mol(NULL) {
    00044       d_positions.clear();
    00045     };
    00046
    00047     //! Constructor with number of atoms specified ID specification
    00048     Conformer(unsigned int numAtoms) : df_is3D(true), d_id(0), dp_mol(NULL) {
    00049       if(numAtoms){
    00050         d_positions.resize(numAtoms, RDGeom::Point3D(0.0, 0.0, 0.0));
    00051       } else {
    00052         d_positions.resize(0);
    00053         d_positions.clear();
    00054       }
    00055     };
    00056
    00057     //! Copy COnstructor: initialize from a second conformation.
    00058     Conformer(const Conformer &other);
    00059
    00060     //! Destructor
    00061     ~Conformer() {};
    00062
    00063     //! Resize the conformer so that more atoms location can be added.
    00064     //! Useful, for e.g., when adding hydrogens
    00065     void resize(unsigned int size) {
    00066       d_positions.resize(size);
    00067     }
    00068
    00069     //! Reserve more space for atom position
    00070     void reserve(unsigned int size) {
    00071       d_positions.reserve(size);
    00072     }
    00073
    00074     //! Get the molecule that oqns this conformation
    00075     ROMol &getOwningMol() const {return *dp_mol;}
    00076
    00077     //! Get a const reference to the vector of atom positions
    00078     const RDGeom::POINT3D_VECT &getPositions() const;
    00079
    00080     //! Get a reference to the atom positions
    00081     RDGeom::POINT3D_VECT &getPositions();
    00082
    00083     //! Get the position of the specified atom
    00084     const RDGeom::Point3D &getAtomPos(unsigned int atomId) const;
    00085
    00086     //! Get the position of the specified atom
    00087     RDGeom::Point3D &getAtomPos(unsigned int atomId);
    00088
    00089     //! Set the position of the specified atom
    00090     inline void setAtomPos(unsigned int atomId, const RDGeom::Point3D &position) {
    00091       //RANGE_CHECK(0,atomId,d_positions.size()-1);
    00092       if (atomId >= d_positions.size()) {
    00093         d_positions.resize(atomId+1, RDGeom::Point3D(0.0, 0.0, 0.0));
    00094       }
    00095       d_positions[atomId] = position;
    00096     }
    00097
    00098     //! get the ID of this conformer
    00099     inline unsigned int getId() const {return d_id;}
    00100
    00101     //! set the ID of this conformer
    00102     inline void setId(unsigned int id) {
    00103       d_id = id;
    00104     }
    00105
    00106     //! Get the number of atoms
    00107     inline unsigned int getNumAtoms() const {
    00108       return d_positions.size();
    00109     }
    00110
    00111     inline bool is3D() const {
    00112       return df_is3D;
    00113     }
    00114     inline void set3D(bool v) {
    00115       df_is3D=v;
    00116     }
    00117   protected:
    00118     //! Set owning moelcule
    00119     void setOwningMol(ROMol *mol);
    00120
    00121     //! Set owning moelcule
    00122     void setOwningMol(ROMol &mol);
    00123
    00124   private:
    00125     bool df_is3D; // is this a 3D conformation?
    00126     unsigned int d_id; // id is the conformation
    00127     ROMol *dp_mol; // owning molecule
    00128     RDGeom::POINT3D_VECT d_positions; // positions of the atoms
    00129   };
    00130
    00131   typedef boost::shared_ptr<Conformer>    CONFORMER_SPTR;
    00132 }
    00133
    00134 #endif