# | Line 1 | Line 1 | |
---|---|---|
1 | < | /* |
1 | > | /* |
2 | * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. | |
3 | * | |
4 | * The University of Notre Dame grants you ("Licensee") a | |
# | Line 6 | Line 6 | |
6 | * redistribute this software in source and binary code form, provided | |
7 | * that the following conditions are met: | |
8 | * | |
9 | < | * 1. Acknowledgement of the program authors must be made in any |
10 | < | * publication of scientific results based in part on use of the |
11 | < | * program. An acceptable form of acknowledgement is citation of |
12 | < | * the article in which the program was described (Matthew |
13 | < | * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
14 | < | * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
15 | < | * Parallel Simulation Engine for Molecular Dynamics," |
16 | < | * J. Comput. Chem. 26, pp. 252-271 (2005)) |
17 | < | * |
18 | < | * 2. Redistributions of source code must retain the above copyright |
9 | > | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | < | * 3. Redistributions in binary form must reproduce the above copyright |
12 | > | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the | |
15 | * distribution. | |
# | Line 37 | Line 28 | |
28 | * arising out of the use of or inability to use software, even if the | |
29 | * University of Notre Dame has been advised of the possibility of | |
30 | * such damages. | |
31 | + | * |
32 | + | * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your |
33 | + | * research, please cite the appropriate papers when you publish your |
34 | + | * work. Good starting points are: |
35 | + | * |
36 | + | * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
37 | + | * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
38 | + | * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). |
39 | + | * [4] Vardeman & Gezelter, in progress (2009). |
40 | */ | |
41 | ||
42 | /** | |
# | Line 53 | Line 53 | |
53 | #include "utils/MemoryUtils.hpp" | |
54 | #include "utils/simError.h" | |
55 | ||
56 | < | namespace oopse { |
57 | < | Molecule::Molecule(int stampId, int globalIndex, const std::string& molName) |
56 | > | namespace OpenMD { |
57 | > | Molecule::Molecule(int stampId, int globalIndex, const std::string& molName) |
58 | : stampId_(stampId), globalIndex_(globalIndex), moleculeName_(molName) { | |
59 | < | |
60 | < | } |
61 | < | |
62 | < | Molecule::~Molecule() { |
63 | < | |
64 | < | MemoryUtils::deleteVectorOfPointer(atoms_); |
65 | < | MemoryUtils::deleteVectorOfPointer(bonds_); |
66 | < | MemoryUtils::deleteVectorOfPointer(bends_); |
67 | < | MemoryUtils::deleteVectorOfPointer(torsions_); |
68 | < | MemoryUtils::deleteVectorOfPointer(rigidBodies_); |
69 | < | MemoryUtils::deleteVectorOfPointer(cutoffGroups_); |
70 | < | MemoryUtils::deleteVectorOfPointer(constraintPairs_); |
71 | < | MemoryUtils::deleteVectorOfPointer(constraintElems_); |
72 | < | //integrableObjects_ don't own the objects |
59 | > | } |
60 | > | |
61 | > | Molecule::~Molecule() { |
62 | > | |
63 | > | MemoryUtils::deletePointers(atoms_); |
64 | > | MemoryUtils::deletePointers(bonds_); |
65 | > | MemoryUtils::deletePointers(bends_); |
66 | > | MemoryUtils::deletePointers(torsions_); |
67 | > | MemoryUtils::deletePointers(inversions_); |
68 | > | MemoryUtils::deletePointers(rigidBodies_); |
69 | > | MemoryUtils::deletePointers(cutoffGroups_); |
70 | > | MemoryUtils::deletePointers(constraintPairs_); |
71 | > | MemoryUtils::deletePointers(constraintElems_); |
72 | > | // integrableObjects_ don't own the objects |
73 | integrableObjects_.clear(); | |
74 | ||
75 | < | } |
76 | < | |
77 | < | void Molecule::addAtom(Atom* atom) { |
75 | > | } |
76 | > | |
77 | > | void Molecule::addAtom(Atom* atom) { |
78 | if (std::find(atoms_.begin(), atoms_.end(), atom) == atoms_.end()) { | |
79 | < | atoms_.push_back(atom); |
79 | > | atoms_.push_back(atom); |
80 | } | |
81 | < | } |
82 | < | |
83 | < | void Molecule::addBond(Bond* bond) { |
81 | > | } |
82 | > | |
83 | > | void Molecule::addBond(Bond* bond) { |
84 | if (std::find(bonds_.begin(), bonds_.end(), bond) == bonds_.end()) { | |
85 | < | bonds_.push_back(bond); |
85 | > | bonds_.push_back(bond); |
86 | } | |
87 | < | } |
88 | < | |
89 | < | void Molecule::addBend(Bend* bend) { |
87 | > | } |
88 | > | |
89 | > | void Molecule::addBend(Bend* bend) { |
90 | if (std::find(bends_.begin(), bends_.end(), bend) == bends_.end()) { | |
91 | < | bends_.push_back(bend); |
91 | > | bends_.push_back(bend); |
92 | } | |
93 | < | } |
94 | < | |
95 | < | void Molecule::addTorsion(Torsion* torsion) { |
96 | < | if (std::find(torsions_.begin(), torsions_.end(), torsion) == torsions_.end()) { |
97 | < | torsions_.push_back(torsion); |
93 | > | } |
94 | > | |
95 | > | void Molecule::addTorsion(Torsion* torsion) { |
96 | > | if (std::find(torsions_.begin(), torsions_.end(), torsion) == |
97 | > | torsions_.end()) { |
98 | > | torsions_.push_back(torsion); |
99 | } | |
100 | < | } |
100 | > | } |
101 | ||
102 | < | void Molecule::addRigidBody(RigidBody *rb) { |
103 | < | if (std::find(rigidBodies_.begin(), rigidBodies_.end(), rb) == rigidBodies_.end()) { |
104 | < | rigidBodies_.push_back(rb); |
102 | > | void Molecule::addInversion(Inversion* inversion) { |
103 | > | if (std::find(inversions_.begin(), inversions_.end(), inversion) == |
104 | > | inversions_.end()) { |
105 | > | inversions_.push_back(inversion); |
106 | } | |
107 | < | } |
108 | < | |
109 | < | void Molecule::addCutoffGroup(CutoffGroup* cp) { |
110 | < | if (std::find(cutoffGroups_.begin(), cutoffGroups_.end(), cp) == cutoffGroups_.end()) { |
111 | < | cutoffGroups_.push_back(cp); |
107 | > | } |
108 | > | |
109 | > | void Molecule::addRigidBody(RigidBody *rb) { |
110 | > | if (std::find(rigidBodies_.begin(), rigidBodies_.end(), rb) == |
111 | > | rigidBodies_.end()) { |
112 | > | rigidBodies_.push_back(rb); |
113 | } | |
114 | < | |
115 | < | } |
116 | < | |
117 | < | void Molecule::addConstraintPair(ConstraintPair* cp) { |
118 | < | if (std::find(constraintPairs_.begin(), constraintPairs_.end(), cp) == constraintPairs_.end()) { |
119 | < | constraintPairs_.push_back(cp); |
114 | > | } |
115 | > | |
116 | > | void Molecule::addCutoffGroup(CutoffGroup* cp) { |
117 | > | if (std::find(cutoffGroups_.begin(), cutoffGroups_.end(), cp) == |
118 | > | cutoffGroups_.end()) { |
119 | > | cutoffGroups_.push_back(cp); |
120 | > | } |
121 | > | } |
122 | > | |
123 | > | void Molecule::addConstraintPair(ConstraintPair* cp) { |
124 | > | if (std::find(constraintPairs_.begin(), constraintPairs_.end(), cp) == |
125 | > | constraintPairs_.end()) { |
126 | > | constraintPairs_.push_back(cp); |
127 | > | } |
128 | > | } |
129 | > | |
130 | > | void Molecule::addConstraintElem(ConstraintElem* cp) { |
131 | > | if (std::find(constraintElems_.begin(), constraintElems_.end(), cp) == |
132 | > | constraintElems_.end()) { |
133 | > | constraintElems_.push_back(cp); |
134 | } | |
135 | < | |
136 | < | } |
137 | < | |
121 | < | void Molecule::addConstraintElem(ConstraintElem* cp) { |
122 | < | if (std::find(constraintElems_.begin(), constraintElems_.end(), cp) == constraintElems_.end()) { |
123 | < | constraintElems_.push_back(cp); |
124 | < | } |
125 | < | |
126 | < | } |
127 | < | |
128 | < | void Molecule::complete() { |
135 | > | } |
136 | > | |
137 | > | void Molecule::complete() { |
138 | ||
139 | std::set<Atom*> rigidAtoms; | |
140 | RigidBody* rb; | |
# | Line 133 | Line 142 | void Molecule::complete() { | |
142 | ||
143 | ||
144 | for (rb = beginRigidBody(rbIter); rb != NULL; rb = nextRigidBody(rbIter)) { | |
145 | < | rigidAtoms.insert(rb->getBeginAtomIter(), rb->getEndAtomIter()); |
145 | > | rigidAtoms.insert(rb->getBeginAtomIter(), rb->getEndAtomIter()); |
146 | } | |
147 | < | |
147 | > | |
148 | Atom* atom; | |
149 | AtomIterator ai; | |
150 | for (atom = beginAtom(ai); atom != NULL; atom = nextAtom(ai)) { | |
151 | < | |
152 | < | if (rigidAtoms.find(*ai) == rigidAtoms.end()) { |
144 | < | //if an atom does not belong to a rigid body, it is an integrable object |
145 | < | integrableObjects_.push_back(*ai); |
146 | < | } |
147 | < | } |
151 | > | |
152 | > | if (rigidAtoms.find(*ai) == rigidAtoms.end()) { |
153 | ||
154 | + | // If an atom does not belong to a rigid body, it is an |
155 | + | // integrable object |
156 | + | |
157 | + | integrableObjects_.push_back(*ai); |
158 | + | } |
159 | + | } |
160 | + | |
161 | //find all free atoms (which do not belong to rigid bodies) | |
162 | < | //performs the "difference" operation from set theory, the output range contains a copy of every |
163 | < | //element that is contained in [allAtoms.begin(), allAtoms.end()) and not contained in |
164 | < | //[rigidAtoms.begin(), rigidAtoms.end()). |
162 | > | // performs the "difference" operation from set theory, the output |
163 | > | // range contains a copy of every element that is contained in |
164 | > | // [allAtoms.begin(), allAtoms.end()) and not contained in |
165 | > | // [rigidAtoms.begin(), rigidAtoms.end()). |
166 | //std::set_difference(allAtoms.begin(), allAtoms.end(), rigidAtoms.begin(), rigidAtoms.end(), | |
167 | // std::back_inserter(integrableObjects_)); | |
168 | ||
# | Line 164 | Line 177 | void Molecule::complete() { | |
177 | integrableObjects_.push_back(rb); | |
178 | } | |
179 | //integrableObjects_.insert(integrableObjects_.end(), rigidBodies_.begin(), rigidBodies_.end()); | |
180 | < | } |
180 | > | } |
181 | ||
182 | < | double Molecule::getMass() { |
182 | > | RealType Molecule::getMass() { |
183 | StuntDouble* sd; | |
184 | std::vector<StuntDouble*>::iterator i; | |
185 | < | double mass = 0.0; |
186 | < | |
187 | < | for (sd = beginIntegrableObject(i); sd != NULL; sd = nextIntegrableObject(i)){ |
188 | < | mass += sd->getMass(); |
185 | > | RealType mass = 0.0; |
186 | > | |
187 | > | for (sd = beginIntegrableObject(i); sd != NULL; sd = |
188 | > | nextIntegrableObject(i)){ |
189 | > | mass += sd->getMass(); |
190 | } | |
191 | + | |
192 | + | return mass; |
193 | + | } |
194 | ||
195 | < | return mass; |
179 | < | |
180 | < | } |
181 | < | |
182 | < | Vector3d Molecule::getCom() { |
195 | > | Vector3d Molecule::getCom() { |
196 | StuntDouble* sd; | |
197 | std::vector<StuntDouble*>::iterator i; | |
198 | Vector3d com; | |
199 | < | double totalMass = 0; |
200 | < | double mass; |
199 | > | RealType totalMass = 0; |
200 | > | RealType mass; |
201 | ||
202 | < | for (sd = beginIntegrableObject(i); sd != NULL; sd = nextIntegrableObject(i)){ |
203 | < | mass = sd->getMass(); |
204 | < | totalMass += mass; |
205 | < | com += sd->getPos() * mass; |
202 | > | for (sd = beginIntegrableObject(i); sd != NULL; sd = |
203 | > | nextIntegrableObject(i)){ |
204 | > | mass = sd->getMass(); |
205 | > | totalMass += mass; |
206 | > | com += sd->getPos() * mass; |
207 | } | |
208 | < | |
208 | > | |
209 | com /= totalMass; | |
210 | ||
211 | return com; | |
212 | < | } |
212 | > | } |
213 | ||
214 | < | void Molecule::moveCom(const Vector3d& delta) { |
214 | > | void Molecule::moveCom(const Vector3d& delta) { |
215 | StuntDouble* sd; | |
216 | std::vector<StuntDouble*>::iterator i; | |
217 | ||
218 | < | for (sd = beginIntegrableObject(i); sd != NULL; sd = nextIntegrableObject(i)){ |
219 | < | sd->setPos(sd->getPos() + delta); |
220 | < | } |
218 | > | for (sd = beginIntegrableObject(i); sd != NULL; sd = |
219 | > | nextIntegrableObject(i)){ |
220 | > | sd->setPos(sd->getPos() + delta); |
221 | > | } |
222 | > | } |
223 | ||
224 | < | } |
209 | < | |
210 | < | Vector3d Molecule::getComVel() { |
224 | > | Vector3d Molecule::getComVel() { |
225 | StuntDouble* sd; | |
226 | std::vector<StuntDouble*>::iterator i; | |
227 | Vector3d velCom; | |
228 | < | double totalMass = 0; |
229 | < | double mass; |
228 | > | RealType totalMass = 0; |
229 | > | RealType mass; |
230 | ||
231 | < | for (sd = beginIntegrableObject(i); sd != NULL; sd = nextIntegrableObject(i)){ |
232 | < | mass = sd->getMass(); |
233 | < | totalMass += mass; |
234 | < | velCom += sd->getVel() * mass; |
231 | > | for (sd = beginIntegrableObject(i); sd != NULL; sd = |
232 | > | nextIntegrableObject(i)){ |
233 | > | mass = sd->getMass(); |
234 | > | totalMass += mass; |
235 | > | velCom += sd->getVel() * mass; |
236 | } | |
237 | < | |
237 | > | |
238 | velCom /= totalMass; | |
239 | < | |
239 | > | |
240 | return velCom; | |
241 | < | } |
241 | > | } |
242 | ||
243 | < | double Molecule::getPotential() { |
243 | > | RealType Molecule::getPotential() { |
244 | ||
245 | Bond* bond; | |
246 | Bend* bend; | |
247 | Torsion* torsion; | |
248 | + | Inversion* inversion; |
249 | Molecule::BondIterator bondIter;; | |
250 | Molecule::BendIterator bendIter; | |
251 | Molecule::TorsionIterator torsionIter; | |
252 | + | Molecule::InversionIterator inversionIter; |
253 | ||
254 | < | double potential = 0.0; |
254 | > | RealType potential = 0.0; |
255 | ||
256 | for (bond = beginBond(bondIter); bond != NULL; bond = nextBond(bondIter)) { | |
257 | < | potential += bond->getPotential(); |
257 | > | potential += bond->getPotential(); |
258 | } | |
259 | ||
260 | for (bend = beginBend(bendIter); bend != NULL; bend = nextBend(bendIter)) { | |
261 | < | potential += bend->getPotential(); |
261 | > | potential += bend->getPotential(); |
262 | } | |
263 | ||
264 | < | for (torsion = beginTorsion(torsionIter); torsion != NULL; torsion = nextTorsion(torsionIter)) { |
265 | < | potential += torsion->getPotential(); |
264 | > | for (torsion = beginTorsion(torsionIter); torsion != NULL; torsion = |
265 | > | nextTorsion(torsionIter)) { |
266 | > | potential += torsion->getPotential(); |
267 | } | |
268 | < | |
268 | > | |
269 | > | for (inversion = beginInversion(inversionIter); torsion != NULL; |
270 | > | inversion = nextInversion(inversionIter)) { |
271 | > | potential += inversion->getPotential(); |
272 | > | } |
273 | > | |
274 | return potential; | |
275 | + | |
276 | + | } |
277 | + | |
278 | + | void Molecule::addProperty(GenericData* genData) { |
279 | + | properties_.addProperty(genData); |
280 | + | } |
281 | ||
282 | < | } |
282 | > | void Molecule::removeProperty(const std::string& propName) { |
283 | > | properties_.removeProperty(propName); |
284 | > | } |
285 | ||
286 | < | std::ostream& operator <<(std::ostream& o, Molecule& mol) { |
286 | > | void Molecule::clearProperties() { |
287 | > | properties_.clearProperties(); |
288 | > | } |
289 | > | |
290 | > | std::vector<std::string> Molecule::getPropertyNames() { |
291 | > | return properties_.getPropertyNames(); |
292 | > | } |
293 | > | |
294 | > | std::vector<GenericData*> Molecule::getProperties() { |
295 | > | return properties_.getProperties(); |
296 | > | } |
297 | > | |
298 | > | GenericData* Molecule::getPropertyByName(const std::string& propName) { |
299 | > | return properties_.getPropertyByName(propName); |
300 | > | } |
301 | > | |
302 | > | |
303 | > | |
304 | > | |
305 | > | std::ostream& operator <<(std::ostream& o, Molecule& mol) { |
306 | o << std::endl; | |
307 | o << "Molecule " << mol.getGlobalIndex() << "has: " << std::endl; | |
308 | o << mol.getNAtoms() << " atoms" << std::endl; | |
309 | o << mol.getNBonds() << " bonds" << std::endl; | |
310 | o << mol.getNBends() << " bends" << std::endl; | |
311 | o << mol.getNTorsions() << " torsions" << std::endl; | |
312 | + | o << mol.getNInversions() << " inversions" << std::endl; |
313 | o << mol.getNRigidBodies() << " rigid bodies" << std::endl; | |
314 | o << mol.getNIntegrableObjects() << "integrable objects" << std::endl; | |
315 | o << mol.getNCutoffGroups() << "cutoff groups" << std::endl; | |
316 | o << mol.getNConstraintPairs() << "constraint pairs" << std::endl; | |
317 | return o; | |
318 | < | } |
319 | < | |
320 | < | }//end namespace oopse |
318 | > | } |
319 | > | |
320 | > | }//end namespace OpenMD |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |