1 |
tim |
1692 |
/* |
2 |
|
|
* Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project |
3 |
|
|
* |
4 |
|
|
* Contact: oopse@oopse.org |
5 |
|
|
* |
6 |
|
|
* This program is free software; you can redistribute it and/or |
7 |
|
|
* modify it under the terms of the GNU Lesser General Public License |
8 |
|
|
* as published by the Free Software Foundation; either version 2.1 |
9 |
|
|
* of the License, or (at your option) any later version. |
10 |
|
|
* All we ask is that proper credit is given for our work, which includes |
11 |
|
|
* - but is not limited to - adding the above copyright notice to the beginning |
12 |
|
|
* of your source code files, and to any copyright notice that you may distribute |
13 |
|
|
* with programs based on this work. |
14 |
|
|
* |
15 |
|
|
* This program is distributed in the hope that it will be useful, |
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
|
|
* GNU Lesser General Public License for more details. |
19 |
|
|
* |
20 |
|
|
* You should have received a copy of the GNU Lesser General Public License |
21 |
|
|
* along with this program; if not, write to the Free Software |
22 |
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 |
|
|
* |
24 |
|
|
*/ |
25 |
gezelter |
1490 |
|
26 |
tim |
1692 |
/** |
27 |
|
|
* @file Molecule.hpp |
28 |
|
|
* @author tlin |
29 |
|
|
* @date 10/25/2004 |
30 |
|
|
* @version 1.0 |
31 |
|
|
*/ |
32 |
|
|
|
33 |
|
|
#ifndef PRIMITIVES_MOLECULE_HPP |
34 |
|
|
#define PRIMITIVES_MOLECULE_HPP |
35 |
gezelter |
1490 |
#include <vector> |
36 |
tim |
1692 |
#include <iostream> |
37 |
gezelter |
1490 |
|
38 |
tim |
1901 |
#include "constraints/ConstraintPair.hpp" |
39 |
tim |
1692 |
#include "math/Vector3.hpp" |
40 |
tim |
1492 |
#include "primitives/Atom.hpp" |
41 |
|
|
#include "primitives/RigidBody.hpp" |
42 |
tim |
1782 |
#include "primitives/Bond.hpp" |
43 |
|
|
#include "primitives/Bend.hpp" |
44 |
|
|
#include "primitives/Torsion.hpp" |
45 |
tim |
1695 |
#include "primitives/CutoffGroup.hpp" |
46 |
gezelter |
1490 |
|
47 |
tim |
1692 |
namespace oopse{ |
48 |
gezelter |
1490 |
|
49 |
tim |
1701 |
class Constraint; |
50 |
|
|
|
51 |
tim |
1692 |
/** |
52 |
|
|
* @class Molecule Molecule.hpp "primitives/Molecule.hpp" |
53 |
|
|
* @brief |
54 |
|
|
*/ |
55 |
|
|
class Molecule { |
56 |
|
|
public: |
57 |
gezelter |
1490 |
|
58 |
tim |
1725 |
typedef std::vector<Atom*>::iterator AtomIterator; |
59 |
|
|
typedef std::vector<Bond*>::iterator BondIterator; |
60 |
|
|
typedef std::vector<Bend*>::iterator BendIterator; |
61 |
|
|
typedef std::vector<Torsion*>::iterator TorsionIterator; |
62 |
|
|
typedef std::vector<RigidBody*>::iterator RigidBodyIterator; |
63 |
|
|
typedef std::vector<CutoffGroup*>::iterator CutoffGroupIterator; |
64 |
|
|
typedef std::vector<StuntDouble*>::iterator IntegrableObjectIterator; |
65 |
tim |
1907 |
typedef std::vector<ConstraintPair*>::iterator ConstraintPairIterator; |
66 |
|
|
typedef std::vector<ConstraintElem*>::iterator ConstraintElemIterator; |
67 |
|
|
|
68 |
tim |
1725 |
|
69 |
tim |
1733 |
Molecule(int stampId, int globalIndex, const std::string& molName); |
70 |
tim |
1692 |
virtual ~Molecule(); |
71 |
gezelter |
1490 |
|
72 |
tim |
1692 |
/** |
73 |
|
|
* Returns the global index of this molecule. |
74 |
|
|
* @return the global index of this molecule |
75 |
|
|
*/ |
76 |
|
|
int getGlobalIndex() { |
77 |
|
|
return globalIndex_; |
78 |
|
|
} |
79 |
gezelter |
1490 |
|
80 |
tim |
1692 |
/** |
81 |
tim |
1733 |
* Returns the stamp id of this molecule |
82 |
|
|
* @note Ideally, every molecule should keep a pointer of its molecule stamp instead of its |
83 |
|
|
* stamp id. However, the pointer will become invalid, if the molecule migrate to other processor. |
84 |
|
|
*/ |
85 |
|
|
int getStampId() { |
86 |
|
|
return stampId_; |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
/** Returns the name of the molecule */ |
90 |
|
|
std::string getType() { |
91 |
|
|
return moleculeName_; |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
/** |
95 |
tim |
1692 |
* Sets the global index of this molecule. |
96 |
|
|
* @param new global index to be set |
97 |
|
|
*/ |
98 |
tim |
1695 |
int setGlobalIndex(int index) { |
99 |
tim |
1692 |
return globalIndex_; |
100 |
|
|
} |
101 |
gezelter |
1490 |
|
102 |
tim |
1733 |
|
103 |
tim |
1692 |
/** add an atom into this molecule */ |
104 |
|
|
void addAtom(Atom* atom); |
105 |
gezelter |
1490 |
|
106 |
tim |
1692 |
/** add a bond into this molecule */ |
107 |
|
|
void addBond(Bond* bond); |
108 |
gezelter |
1490 |
|
109 |
tim |
1692 |
/** add a bend into this molecule */ |
110 |
|
|
void addBend(Bend* bend); |
111 |
gezelter |
1490 |
|
112 |
tim |
1692 |
/** add a torsion into this molecule*/ |
113 |
|
|
void addTorsion(Torsion* torsion); |
114 |
gezelter |
1490 |
|
115 |
tim |
1692 |
/** add a rigidbody into this molecule */ |
116 |
|
|
void addRigidBody(RigidBody *rb); |
117 |
gezelter |
1490 |
|
118 |
tim |
1692 |
/** add a cutoff group into this molecule */ |
119 |
tim |
1901 |
void addCutoffGroup(CutoffGroup* cp); |
120 |
gezelter |
1490 |
|
121 |
tim |
1901 |
void addConstraintPair(ConstraintPair* consPair); |
122 |
tim |
1907 |
|
123 |
|
|
void addConstraintElem(ConstraintElem* consElem); |
124 |
tim |
1901 |
|
125 |
tim |
1692 |
/** */ |
126 |
|
|
void complete(); |
127 |
gezelter |
1490 |
|
128 |
tim |
1692 |
/** Returns the total number of atoms in this molecule */ |
129 |
|
|
unsigned int getNAtoms() { |
130 |
|
|
return atoms_.size(); |
131 |
|
|
} |
132 |
gezelter |
1490 |
|
133 |
tim |
1692 |
/** Returns the total number of bonds in this molecule */ |
134 |
|
|
unsigned int getNBonds(){ |
135 |
|
|
return bonds_.size(); |
136 |
|
|
} |
137 |
gezelter |
1490 |
|
138 |
tim |
1692 |
/** Returns the total number of bends in this molecule */ |
139 |
|
|
unsigned int getNBends() { |
140 |
|
|
return bends_.size(); |
141 |
|
|
} |
142 |
gezelter |
1490 |
|
143 |
tim |
1692 |
/** Returns the total number of torsions in this molecule */ |
144 |
|
|
unsigned int getNTorsions() { |
145 |
|
|
return torsions_.size(); |
146 |
|
|
} |
147 |
gezelter |
1490 |
|
148 |
tim |
1692 |
/** Returns the total number of rigid bodies in this molecule */ |
149 |
|
|
unsigned int getNRigidBodies() { |
150 |
|
|
return rigidBodies_.size(); |
151 |
|
|
} |
152 |
gezelter |
1490 |
|
153 |
tim |
1692 |
/** Returns the total number of integrable objects in this molecule */ |
154 |
|
|
unsigned int getNIntegrableObjects() { |
155 |
|
|
return integrableObjects_.size(); |
156 |
|
|
} |
157 |
|
|
|
158 |
|
|
/** Returns the total number of cutoff groups in this molecule */ |
159 |
|
|
unsigned int getNCutoffGroups() { |
160 |
|
|
return cutoffGroups_.size(); |
161 |
|
|
} |
162 |
|
|
|
163 |
tim |
1696 |
/** Returns the total number of constraints in this molecule */ |
164 |
tim |
1901 |
unsigned int getNConstraintPairs() { |
165 |
|
|
return constraintPairs_.size(); |
166 |
tim |
1696 |
} |
167 |
tim |
1719 |
|
168 |
|
|
Atom* getAtomAt(unsigned int i) { |
169 |
|
|
assert(i < atoms_.size()); |
170 |
|
|
return atoms_[i]; |
171 |
|
|
} |
172 |
tim |
1692 |
|
173 |
tim |
1910 |
Atom* beginAtom(std::vector<Atom*>::iterator& i) { |
174 |
tim |
1907 |
i = atoms_.begin(); |
175 |
|
|
return (i == atoms_.end()) ? NULL : *i; |
176 |
|
|
} |
177 |
tim |
1692 |
|
178 |
tim |
1910 |
Atom* nextAtom(std::vector<Atom*>::iterator& i) { |
179 |
tim |
1907 |
++i; |
180 |
|
|
return (i == atoms_.end()) ? NULL : *i; |
181 |
|
|
} |
182 |
tim |
1692 |
|
183 |
tim |
1910 |
Bond* beginBond(std::vector<Bond*>::iterator& i) { |
184 |
tim |
1907 |
i = bonds_.begin(); |
185 |
|
|
return (i == bonds_.end()) ? NULL : *i; |
186 |
|
|
} |
187 |
tim |
1692 |
|
188 |
tim |
1910 |
Bond* nextBond(std::vector<Bond*>::iterator& i) { |
189 |
tim |
1907 |
++i; |
190 |
|
|
return (i == bonds_.end()) ? NULL : *i; |
191 |
tim |
1692 |
|
192 |
tim |
1907 |
} |
193 |
tim |
1692 |
|
194 |
tim |
1910 |
Bend* beginBend(std::vector<Bend*>::iterator& i) { |
195 |
tim |
1907 |
i = bends_.begin(); |
196 |
|
|
return (i == bends_.end()) ? NULL : *i; |
197 |
|
|
} |
198 |
tim |
1692 |
|
199 |
tim |
1910 |
Bend* nextBend(std::vector<Bend*>::iterator& i) { |
200 |
tim |
1907 |
++i; |
201 |
|
|
return (i == bends_.end()) ? NULL : *i; |
202 |
|
|
} |
203 |
tim |
1692 |
|
204 |
tim |
1910 |
Torsion* beginTorsion(std::vector<Torsion*>::iterator& i) { |
205 |
tim |
1907 |
i = torsions_.begin(); |
206 |
|
|
return (i == torsions_.end()) ? NULL : *i; |
207 |
|
|
} |
208 |
tim |
1692 |
|
209 |
tim |
1910 |
Torsion* nextTorsion(std::vector<Torsion*>::iterator& i) { |
210 |
tim |
1907 |
++i; |
211 |
|
|
return (i == torsions_.end()) ? NULL : *i; |
212 |
|
|
} |
213 |
tim |
1692 |
|
214 |
tim |
1910 |
RigidBody* beginRigidBody(std::vector<RigidBody*>::iterator& i) { |
215 |
tim |
1907 |
i = rigidBodies_.begin(); |
216 |
|
|
return (i == rigidBodies_.end()) ? NULL : *i; |
217 |
|
|
} |
218 |
tim |
1692 |
|
219 |
tim |
1910 |
RigidBody* nextRigidBody(std::vector<RigidBody*>::iterator& i) { |
220 |
tim |
1907 |
++i; |
221 |
|
|
return (i == rigidBodies_.end()) ? NULL : *i; |
222 |
|
|
} |
223 |
tim |
1692 |
|
224 |
tim |
1910 |
StuntDouble* beginIntegrableObject(std::vector<StuntDouble*>::iterator& i) { |
225 |
tim |
1907 |
i = integrableObjects_.begin(); |
226 |
|
|
return (i == integrableObjects_.end()) ? NULL : *i; |
227 |
|
|
} |
228 |
tim |
1696 |
|
229 |
tim |
1910 |
StuntDouble* nextIntegrableObject(std::vector<StuntDouble*>::iterator& i) { |
230 |
tim |
1907 |
++i; |
231 |
|
|
return (i == integrableObjects_.end()) ? NULL : *i; |
232 |
|
|
} |
233 |
|
|
|
234 |
tim |
1910 |
CutoffGroup* beginCutoffGroup(std::vector<CutoffGroup*>::iterator& i) { |
235 |
tim |
1907 |
i = cutoffGroups_.begin(); |
236 |
|
|
return (i == cutoffGroups_.end()) ? NULL : *i; |
237 |
|
|
} |
238 |
|
|
|
239 |
tim |
1910 |
CutoffGroup* nextCutoffGroup(std::vector<CutoffGroup*>::iterator& i) { |
240 |
tim |
1907 |
++i; |
241 |
|
|
return (i == cutoffGroups_.end()) ? NULL : *i; |
242 |
|
|
} |
243 |
|
|
|
244 |
tim |
1910 |
ConstraintPair* beginConstraintPair(std::vector<ConstraintPair*>::iterator& i) { |
245 |
tim |
1907 |
i = constraintPairs_.begin(); |
246 |
|
|
return (i == constraintPairs_.end()) ? NULL : *i; |
247 |
|
|
} |
248 |
|
|
|
249 |
tim |
1910 |
ConstraintPair* nextConstraintPair(std::vector<ConstraintPair*>::iterator& i) { |
250 |
tim |
1907 |
++i; |
251 |
|
|
return (i == constraintPairs_.end()) ? NULL : *i; |
252 |
|
|
} |
253 |
|
|
|
254 |
tim |
1910 |
ConstraintElem* beginConstraintElem(std::vector<ConstraintElem*>::iterator& i) { |
255 |
tim |
1907 |
i = constraintElems_.begin(); |
256 |
|
|
return (i == constraintElems_.end()) ? NULL : *i; |
257 |
|
|
} |
258 |
|
|
|
259 |
tim |
1910 |
ConstraintElem* nextConstraintElem(std::vector<ConstraintElem*>::iterator& i) { |
260 |
tim |
1907 |
++i; |
261 |
|
|
return (i == constraintElems_.end()) ? NULL : *i; |
262 |
|
|
} |
263 |
tim |
1696 |
|
264 |
tim |
1692 |
/** return the total potential energy of short range interaction of this molecule */ |
265 |
|
|
double getPotential(); |
266 |
|
|
|
267 |
tim |
1843 |
/** get total mass of this molecule */ |
268 |
|
|
double getMass(); |
269 |
tim |
1692 |
|
270 |
|
|
/** return the center of mass of this molecule */ |
271 |
|
|
Vector3d getCom(); |
272 |
|
|
|
273 |
|
|
/** Moves the center of this molecule */ |
274 |
tim |
1695 |
void moveCom(const Vector3d& delta); |
275 |
tim |
1692 |
|
276 |
|
|
/** Returns the velocity of center of mass of this molecule */ |
277 |
|
|
Vector3d getComVel(); |
278 |
|
|
|
279 |
tim |
1695 |
friend std::ostream& operator <<(std::ostream& o, Molecule& mol); |
280 |
tim |
1692 |
|
281 |
|
|
private: |
282 |
tim |
1725 |
|
283 |
tim |
1692 |
int globalIndex_; |
284 |
|
|
|
285 |
|
|
std::vector<Atom*> atoms_; |
286 |
|
|
std::vector<Bond*> bonds_; |
287 |
|
|
std::vector<Bend*> bends_; |
288 |
|
|
std::vector<Torsion*> torsions_; |
289 |
|
|
std::vector<RigidBody*> rigidBodies_; |
290 |
|
|
std::vector<StuntDouble*> integrableObjects_; |
291 |
|
|
std::vector<CutoffGroup*> cutoffGroups_; |
292 |
tim |
1901 |
std::vector<ConstraintPair*> constraintPairs_; |
293 |
tim |
1907 |
std::vector<ConstraintElem*> constraintElems_; |
294 |
tim |
1733 |
int stampId_; |
295 |
|
|
std::string moleculeName_; |
296 |
gezelter |
1490 |
}; |
297 |
|
|
|
298 |
tim |
1692 |
} //namespace oopse |
299 |
|
|
#endif // |