Victor
 All Data Structures Functions Variables Friends Pages
Atom.h
1 /* This file is part of Victor.
2 
3  Victor is free software: you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation, either version 3 of the License, or
6  (at your option) any later version.
7 
8  Victor is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with Victor. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 
18 #ifndef _ATOM_H_
19 #define _ATOM_H_
20 
21 // Includes:
22 #include <AtomCode.h>
23 #include <vector3.h>
24 #include <matrix3.h>
25 #include <SimpleBond.h>
26 
27 namespace Victor { namespace Biopool {
28 
29 
30  // Global constants, typedefs, etc. (to avoid):
31 
32  class Group;
33 
39  class Atom : public SimpleBond {
40  public:
41 
42  // CONSTRUCTORS/DESTRUCTOR:
43  Atom(unsigned int mI = 1, unsigned int mO = 4);
44  Atom(const Atom& orig);
45  virtual ~Atom();
46 
47  // PREDICATES:
48  AtomCode getCode() const;
49  unsigned long getNumber() const;
50 
51  vgVector3<double> getCoords();
52 
53  double getBFac() {
54  return Bfac;
55  }
56 
57  double distance(Atom& other);
58 
59  bool hasSuperior();
60  Group& getSuperior();
61  const Group& getSuperior() const;
62 
63  vgVector3<double> getTrans() const;
64  vgMatrix3<double> getRot() const;
65  virtual bool inSync(); // coords in-sync with changes?
66 
67  // MODIFIERS:
68  void clear();
69  void copy(const Atom& orig);
70  void bindStructure(Atom& before, bool connect);
71  // sets this relative to before if connect == true, otherwise like bindIn
72  virtual void bindIn(SimpleBond& c);
73  virtual void bindOut(SimpleBond& c);
74  virtual void unbindIn(SimpleBond& c);
75  virtual void unbindOut(SimpleBond& c);
76  void setType(string _name);
77  void setCode(AtomCode ac);
78  void setNumber(unsigned long _number);
79 
80  void setCoords(double _x, double _y, double _z);
81  void setCoords(vgVector3<double> c);
82 
83  void setBFac(double _b) {
84  Bfac = _b;
85  }
86 
87  void setTrans(vgVector3<double> t);
88  void addTrans(vgVector3<double> t);
89  void setRot(vgMatrix3<double> r);
90  void addRot(vgMatrix3<double> r);
91  virtual void sync(); // synchronize coords with structure
92 
93  virtual const Atom& getInBond(unsigned n) const;
94  virtual Atom& getInBond(unsigned n);
95  virtual const Atom& getOutBond(unsigned n) const;
96  virtual Atom& getOutBond(unsigned n);
97 
98  void setSuperior(Group* gr);
99  void setModified();
100  void setUnModified(); //used in Qmean: this flag cause problem there.
101 
102  // OPERATORS:
103  Atom& operator=(const Atom& orig);
104 
105  protected:
106 
107  private:
108 
109  // HELPERS:
110  bool isNotFirstAtomInStructure();
111  void propagateRotation(); // pass on rotation matrix to following atoms
112 
113 
114  // ATTRIBUTES:
115  Group* superior; // structure to which atom belongs,
116  AtomCode type; // Atom type
117  vgVector3<double> coords; // xyz-Coords
118 
119  double Bfac; // B-factor
120 
121  vgVector3<double> trans; // relative translation
122  vgMatrix3<double> rot; // relative rotation
123  bool modified; // --""-- modified?
124  };
125 
126 
127 
128  // ---------------------------------------------------------------------------
129  // Atom
130  // -----------------x-------------------x-------------------x-----------------
131 
132  // PREDICATES:
133 
134  inline AtomCode
135  Atom::getCode() const {
136  return type;
137  }
138 
139  inline unsigned long
140  Atom::getNumber() const {
141  return id;
142  }
143 
144  inline vgVector3<double>
145  Atom::getCoords() {
146  if (!inSync())
147  sync();
148  return coords;
149  }
150 
151  inline Group&
152  Atom::getSuperior() {
153  PRECOND(superior != NULL, exception);
154  return *superior;
155  }
156 
157  inline const Group&
158  Atom::getSuperior() const {
159  PRECOND(superior != NULL, exception);
160  return *superior;
161  }
162 
163  inline bool
164  Atom::hasSuperior() {
165  return (superior != NULL);
166  }
167 
168  inline vgVector3<double>
169  Atom::getTrans() const {
170  return trans;
171  }
172 
173  inline vgMatrix3<double>
174  Atom::getRot() const {
175  return rot;
176  }
177 
178  inline bool
179  Atom::inSync() {
180  return (!modified);
181  }
182 
183  // MODIFIERS:
184 
185  inline void
186  Atom::bindStructure(Atom& before, bool connect) {
187  if (connect)
188  this->setTrans(this->getCoords() - before.getCoords());
189  this->bindIn(before);
190  }
191 
192  inline void
195  setModified();
196  }
197 
198  inline void
201  setModified();
202  }
203 
204  inline void
207  setModified();
208  }
209 
210  inline void
213  setModified();
214  }
215 
216  inline void
217  Atom::setType(string _name) {
218  id.setName(_name);
219  type = AtomTranslator(_name);
220  }
221 
222  inline void
223  Atom::setCode(AtomCode ac) {
224  type = ac;
225  id.setName(AtomTranslator(ac));
226  }
227 
228  inline void
229  Atom::setNumber(unsigned long _number) {
230  id.setNumber(_number);
231  }
232 
233  inline void
234  Atom::setTrans(vgVector3<double> t) {
235  trans = t;
236  setModified();
237  }
238 
239  inline void
240  Atom::addTrans(vgVector3<double> t) {
241  trans += t;
242  setModified();
243  }
244 
245  inline void
246  Atom::setRot(vgMatrix3<double> r) {
247  rot = r;
248  setModified();
249  }
250 
251  inline void
252  Atom::addRot(vgMatrix3<double> r) {
253  rot = r * rot;
254  setModified();
255  }
256 
257  inline const Atom&
258  Atom::getInBond(unsigned n) const {
259  return dynamic_cast<const Atom&> (SimpleBond::getInBond(n));
260  }
261 
262  inline Atom&
263  Atom::getInBond(unsigned n) {
264  return dynamic_cast<Atom&> (SimpleBond::getInBond(n));
265  }
266 
267  inline const Atom&
268  Atom::getOutBond(unsigned n) const {
269  return dynamic_cast<const Atom&> (SimpleBond::getOutBond(n));
270  }
271 
272  inline Atom&
273  Atom::getOutBond(unsigned n) {
274  return dynamic_cast<Atom&> (SimpleBond::getOutBond(n));
275  }
276 
277  inline void
278  Atom::setSuperior(Group* gr) {
279  this->superior = gr;
280  }
281 
282  // OPERATORS:
283 
284 
285 }} //namespace
286 #endif //_ATOM_H_
virtual void bindIn(SimpleBond &c)
Definition: SimpleBond.cc:115
virtual ~Atom()
Definition: Atom.cc:54
virtual void unbindIn(SimpleBond &c)
Definition: SimpleBond.cc:141
virtual const SimpleBond & getInBond(unsigned int n) const
Definition: SimpleBond.h:176
virtual const SimpleBond & getOutBond(unsigned int n) const
Definition: SimpleBond.h:184
void setType(string _name)
Definition: Atom.h:217
This class implements a simple chemical group.
Definition: Group.h:35
void setCoords(double _x, double _y, double _z)
Definition: Atom.cc:88
double distance(Atom &other)
Definition: Atom.cc:66
void setModified()
Definition: Atom.cc:181
virtual void bindOut(SimpleBond &c)
Definition: Atom.h:199
virtual void unbindOut(SimpleBond &c)
Definition: Atom.h:211
Defines chemical and abstract bonds between objects. eg.: covalent bonds. Attention: copy() strips or...
Definition: SimpleBond.h:39
void copy(const Atom &orig)
Definition: Atom.cc:126
Atom(unsigned int mI=1, unsigned int mO=4)
Definition: Atom.cc:35
void setUnModified()
Definition: Atom.cc:196
virtual void bindOut(SimpleBond &c)
Definition: SimpleBond.cc:128
virtual void unbindIn(SimpleBond &c)
Definition: Atom.h:205
virtual void unbindOut(SimpleBond &c)
Definition: SimpleBond.cc:150
Implements a simple atom type.
Definition: Atom.h:39
virtual void sync()
Definition: Atom.cc:148
virtual void bindIn(SimpleBond &c)
Definition: Atom.h:193