RDKit
Open-source cheminformatics and machine learning.
Conformer.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2008 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 #ifndef _RD_CONFORMER_H
11 #define _RD_CONFORMER_H
12 
13 #include <Geometry/point.h>
14 #include <RDGeneral/types.h>
15 #include <boost/smart_ptr.hpp>
16 
17 namespace RDKit {
18  class ROMol;
19 
20  //! used to indicate errors from incorrect confomer access
21  class ConformerException : public std::exception {
22  public:
23  //! construct with an error message
24  ConformerException(const char *msg) : _msg(msg) {};
25  //! construct with an error message
26  ConformerException(const std::string msg) : _msg(msg) {};
27  //! get the error message
28  const char *message () const { return _msg.c_str(); };
29  ~ConformerException () throw () {};
30  private:
31  std::string _msg;
32  };
33 
34 
35  //! The class for representing 2D or 3D conformation of a molecule
36  /*!
37  This class contains
38  - a pointer to the owing molecule
39  - a vector of 3D points (positions of atoms)
40  */
41  class Conformer {
42  public:
43 
44  friend class ROMol;
45 
46  //! Constructor
47  Conformer() : df_is3D(true), d_id(0), dp_mol(NULL) {
48  d_positions.clear();
49  };
50 
51  //! Constructor with number of atoms specified ID specification
52  Conformer(unsigned int numAtoms) : df_is3D(true), d_id(0), dp_mol(NULL) {
53  if(numAtoms){
54  d_positions.resize(numAtoms, RDGeom::Point3D(0.0, 0.0, 0.0));
55  } else {
56  d_positions.resize(0);
57  d_positions.clear();
58  }
59  };
60 
61  //! Copy Constructor: initialize from a second conformation.
62  Conformer(const Conformer &other);
63 
64  //! Destructor
65  ~Conformer() {};
66 
67  //! Resize the conformer so that more atoms location can be added.
68  //! Useful, for e.g., when adding hydrogens
69  void resize(unsigned int size) {
70  d_positions.resize(size);
71  }
72 
73  //! Reserve more space for atom position
74  void reserve(unsigned int size) {
75  d_positions.reserve(size);
76  }
77 
78  //! Get the molecule that oqns this conformation
79  ROMol &getOwningMol() const {return *dp_mol;}
80 
81  //! Get a const reference to the vector of atom positions
82  const RDGeom::POINT3D_VECT &getPositions() const;
83 
84  //! Get a reference to the atom positions
85  RDGeom::POINT3D_VECT &getPositions();
86 
87  //! Get the position of the specified atom
88  const RDGeom::Point3D &getAtomPos(unsigned int atomId) const;
89 
90  //! Get the position of the specified atom
91  RDGeom::Point3D &getAtomPos(unsigned int atomId);
92 
93  //! Set the position of the specified atom
94  inline void setAtomPos(unsigned int atomId, const RDGeom::Point3D &position) {
95  //RANGE_CHECK(0,atomId,d_positions.size()-1);
96  if (atomId >= d_positions.size()) {
97  d_positions.resize(atomId+1, RDGeom::Point3D(0.0, 0.0, 0.0));
98  }
99  d_positions[atomId] = position;
100  }
101 
102  //! get the ID of this conformer
103  inline unsigned int getId() const {return d_id;}
104 
105  //! set the ID of this conformer
106  inline void setId(unsigned int id) {
107  d_id = id;
108  }
109 
110  //! Get the number of atoms
111  inline unsigned int getNumAtoms() const {
112  return d_positions.size();
113  }
114 
115  inline bool is3D() const {
116  return df_is3D;
117  }
118  inline void set3D(bool v) {
119  df_is3D=v;
120  }
121  protected:
122  //! Set owning moelcule
123  void setOwningMol(ROMol *mol);
124 
125  //! Set owning moelcule
126  void setOwningMol(ROMol &mol);
127 
128  private:
129  bool df_is3D; // is this a 3D conformation?
130  unsigned int d_id; // id is the conformation
131  ROMol *dp_mol; // owning molecule
132  RDGeom::POINT3D_VECT d_positions; // positions of the atoms
133  };
134 
135  typedef boost::shared_ptr<Conformer> CONFORMER_SPTR;
136 }
137 
138 #endif
used to indicate errors from incorrect confomer access
Definition: Conformer.h:21
void setId(unsigned int id)
set the ID of this conformer
Definition: Conformer.h:106
const char * message() const
get the error message
Definition: Conformer.h:28
ConformerException(const char *msg)
construct with an error message
Definition: Conformer.h:24
bool is3D() const
Definition: Conformer.h:115
ROMol & getOwningMol() const
Get the molecule that oqns this conformation.
Definition: Conformer.h:79
void setAtomPos(unsigned int atomId, const RDGeom::Point3D &position)
Set the position of the specified atom.
Definition: Conformer.h:94
std::vector< Point3D > POINT3D_VECT
Definition: point.h:529
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:105
void reserve(unsigned int size)
Reserve more space for atom position.
Definition: Conformer.h:74
Conformer()
Constructor.
Definition: Conformer.h:47
~Conformer()
Destructor.
Definition: Conformer.h:65
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:28
unsigned int getId() const
get the ID of this conformer
Definition: Conformer.h:103
boost::shared_ptr< Conformer > CONFORMER_SPTR
Definition: Conformer.h:135
unsigned int getNumAtoms() const
Get the number of atoms.
Definition: Conformer.h:111
The class for representing 2D or 3D conformation of a molecule.
Definition: Conformer.h:41
ConformerException(const std::string msg)
construct with an error message
Definition: Conformer.h:26
void set3D(bool v)
Definition: Conformer.h:118
Conformer(unsigned int numAtoms)
Constructor with number of atoms specified ID specification.
Definition: Conformer.h:52
void resize(unsigned int size)
Definition: Conformer.h:69