Victor
 All Data Structures Functions Variables Friends Pages
Group.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 #ifndef _GROUP_H_
18 #define _GROUP_H_
19 
20 // Includes:
21 #include <vector>
22 #include <Atom.h>
23 #include <Monomer.h>
24 #include <matrix3.h>
25 #include <Visitor.h>
26 
27 namespace Victor { namespace Biopool {
28 
33  // Global constants, typedefs, etc. (to avoid):
34 
35  class Group : public Monomer {
36  public:
37 
38  // CONSTRUCTORS/DESTRUCTOR:
39  Group(unsigned int mI = 1, unsigned int mO = 4);
40  Group(const Group& orig);
41  virtual ~Group();
42 
43  virtual string getClassName() const {
44  return "Group";
45  }
46 
47  // PREDICATES:
48  virtual unsigned int getCode() const;
49  virtual unsigned int size() const;
50 
51  Atom& getAtom(unsigned int n);
52  const Atom& getAtom(unsigned int n) const;
53 
54  virtual void save(Saver& s); // data saver
55  vector<Atom>& giveAtoms();
56 
57  vgVector3<double> getTrans() const;
58  vgMatrix3<double> getRot() const;
59 
60  virtual bool isMember(const AtomCode& ac) const;
61 
62  // MODIFIERS:
63  void copy(const Group& orig);
64  void setAtom(unsigned int n, Atom& at);
65  void addAtom(Atom& a);
66  void removeAtom(Atom& a);
67 
68  virtual void load(Loader& l); // data loader
69 
70  void setTrans(vgVector3<double> t);
71  void addTrans(vgVector3<double> t);
72  void setRot(vgMatrix3<double> r);
73  void addRot(vgMatrix3<double> r);
74  virtual void sync(); // synchronize coords with structure
75  virtual void setModified();
76 
77  virtual const Group& getInBond(unsigned int n) const;
78  virtual Group& getInBond(unsigned int n);
79  virtual const Group& getOutBond(unsigned int n) const;
80  virtual Group& getOutBond(unsigned int n);
81 
82  virtual void acceptCalculator(EnergyVisitor* v);
83  virtual void acceptOptimizer(OptimizationVisitor* v);
84 
85  // OPERATORS:
86 
87  Group& operator=(const Group& orig);
88  virtual Atom& operator[](unsigned int n);
89  virtual const Atom& operator[](unsigned int n) const;
90  virtual Atom& operator[](const AtomCode& ac);
91  virtual const Atom& operator[](const AtomCode& ac) const;
92 
93  protected:
94 
95  // HELPERS:
96  void resetBoundaries();
97  Atom* pGetAtom(const AtomCode& ac) const;
98 
99  private:
100 
101  // HELPERS:
102  unsigned int pGetIndex(const unsigned long cmp) const;
103 
104  // ATTRIBUTES:
105  vector<Atom> atoms;
106  vgVector3<double> trans; // group translation
107  vgMatrix3<double> rot; // group rotation
108 
109  };
110 
111  // ---------------------------------------------------------------------------
112  // Group
113  // -----------------x-------------------x-------------------x-----------------
114 
115  // PREDICATES:
116 
117  inline unsigned int
118  Group::getCode() const {
119  ERROR("Group::getCode() undefined.", exception);
120  return 0;
121  }
122 
123  inline unsigned int
124  Group::size() const {
125  return atoms.size();
126  }
127 
128  inline void
129  Group::save(Saver& s) {
130  s.saveGroup(*this);
131  }
132 
133  inline vector<Atom>&
134  Group::giveAtoms() {
135  return atoms;
136  }
137 
138  inline Atom&
139  Group::getAtom(unsigned int n) {
140  PRECOND(n < atoms.size(), exception);
141  return atoms[n];
142  }
143 
144  inline const Atom&
145  Group::getAtom(unsigned int n) const {
146  PRECOND(n < atoms.size(), exception);
147  return atoms[n];
148  }
149 
150  inline vgVector3<double>
151  Group::getTrans() const {
152  return trans;
153  }
154 
155  inline vgMatrix3<double>
156  Group::getRot() const {
157  return rot;
158  }
159 
160  inline bool
161  Group::isMember(const AtomCode& ac) const {
162  return (pGetAtom(ac) != NULL);
163  }
164 
165  // MODIFIERS:
166 
167  inline void
168  Group::setAtom(unsigned int n, Atom& at) {
169  PRECOND(n < atoms.size(), exception);
170  atoms[n] = at;
171  atoms[n].setSuperior(this);
172  Group::setModified();
173  }
174 
175  inline void
176  Group::load(Loader& l) {
177  l.loadGroup(*this);
178  resetBoundaries();
179  }
180 
181  inline void
182  Group::setTrans(vgVector3<double> t) {
183  trans = t;
184  Group::setModified();
185  }
186 
187  inline void
188  Group::addTrans(vgVector3<double> t) {
189  trans += t;
190  Group::setModified();
191  }
192 
193  inline void
194  Group::setRot(vgMatrix3<double> r) {
195 #ifndef NDEBUG
196 #endif
197  rot = r;
198  Group::setModified();
199  }
200 
201  inline void
202  Group::addRot(vgMatrix3<double> r) {
203 #ifndef NDEBUG
204 #endif
205  rot = r * rot;
206  Group::setModified();
207  }
208 
209  inline const Group&
210  Group::getInBond(unsigned int n) const {
211  return dynamic_cast<const Group&> (Bond::getInBond(n));
212  }
213 
214  inline Group&
215  Group::getInBond(unsigned int n) {
216  return dynamic_cast<Group&> (Bond::getInBond(n));
217  }
218 
219  inline const Group&
220  Group::getOutBond(unsigned int n) const {
221  return dynamic_cast<const Group&> (Bond::getOutBond(n));
222  }
223 
224  inline Group&
225  Group::getOutBond(unsigned int n) {
226  return dynamic_cast<Group&> (Bond::getOutBond(n));
227  }
228 
229  inline void
230  Group::acceptCalculator(EnergyVisitor* v) {
231  v->PrepareGroup(*this);
232  }
233 
234  inline void
235  Group::acceptOptimizer(OptimizationVisitor* v) {
236  v->PrepareGroup(*this);
237  }
238 
239 
240  // OPERATORS:
241 
242  inline Atom&
243  Group::operator[](unsigned int n) {
244  PRECOND(n < atoms.size(), exception);
245  return atoms[n];
246  }
247 
248  inline const Atom&
249  Group::operator[](unsigned int n) const {
250  PRECOND(n < atoms.size(), exception);
251  return atoms[n];
252  }
253 
254  inline Atom&
255  Group::operator[](const AtomCode& ac) {
256  Atom* a = pGetAtom(ac);
257  INVARIANT(a != NULL, exception);
258  if (a == NULL)
259  ERROR("Inexistent atom requested.", exception);
260  return *a;
261  }
262 
263  inline const Atom&
264  Group::operator[](const AtomCode& ac) const {
265  Atom* a = pGetAtom(ac);
266  INVARIANT(a != NULL, exception);
267  if (a == NULL)
268  ERROR("Inexistent atom requested.", exception);
269  return *a;
270  }
271 
272  // HELPERS:
273 
274 }} //namespace
275 #endif //_GROUP_H_
virtual void sync()
Definition: Group.cc:150
Base class for saving components (Atoms, Groups, etc.).
Definition: Saver.h:39
void removeAtom(Atom &a)
Definition: Group.cc:85
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 copy(const Group &orig)
Definition: Group.cc:110
This class implements a simple chemical group.
Definition: Group.h:35
void resetBoundaries()
Definition: Group.cc:50
virtual const Group & getInBond(unsigned int n) const
Definition: Group.h:210
Base class for loading components (Atoms, Groups, etc.).
Definition: Loader.h:39
Base class implementing the visitor pattern.
Definition: Visitor.h:38
Atom * pGetAtom(const AtomCode &ac) const
Definition: Group.cc:200
Base class for components without elements.
Definition: Monomer.h:32
Base class Optimizacion Patter.
Definition: Visitor.h:66
virtual const Group & getOutBond(unsigned int n) const
Definition: Group.h:220
Implements a simple atom type.
Definition: Atom.h:39
void addAtom(Atom &a)
Definition: Group.cc:169