OpenMD 3.0
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
Molecule.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2004-present, The University of Notre Dame. All rights
3 * reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
32 * research, please cite the appropriate papers when you publish your
33 * work. Good starting points are:
34 *
35 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
36 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
37 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
38 * [4] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
39 * [5] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
40 * [6] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
41 * [7] Lamichhane, Newman & Gezelter, J. Chem. Phys. 141, 134110 (2014).
42 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
43 */
44
45/**
46 * @file Molecule.hpp
47 * @author tlin
48 * @date 10/25/2004
49 * @version 1.0
50 */
51
52#ifndef PRIMITIVES_MOLECULE_HPP
53#define PRIMITIVES_MOLECULE_HPP
54
55#include <iostream>
56#include <memory>
57#include <vector>
58
59#include "constraints/ConstraintPair.hpp"
60#include "math/Vector3.hpp"
61#include "primitives/Atom.hpp"
62#include "primitives/Bend.hpp"
63#include "primitives/Bond.hpp"
64#include "primitives/CutoffGroup.hpp"
68#include "utils/PropertyMap.hpp"
69
70namespace OpenMD {
71
72 class Constraint;
73
74 /**
75 * @class Molecule Molecule.hpp "primitives/Molecule.hpp"
76 * @brief
77 */
78 class Molecule {
79 public:
80 struct HBondDonor {
81 Atom* donorAtom;
82 Atom* donatedHydrogen;
83 };
84
85 using AtomIterator = std::vector<Atom*>::iterator;
86 using BondIterator = std::vector<Bond*>::iterator;
87 using BendIterator = std::vector<Bend*>::iterator;
88 using TorsionIterator = std::vector<Torsion*>::iterator;
89 using InversionIterator = std::vector<Inversion*>::iterator;
90 using RigidBodyIterator = std::vector<RigidBody*>::iterator;
91 using CutoffGroupIterator = std::vector<CutoffGroup*>::iterator;
92 using IntegrableObjectIterator = std::vector<StuntDouble*>::iterator;
93 using ConstraintPairIterator = std::vector<ConstraintPair*>::iterator;
94 using ConstraintElemIterator = std::vector<ConstraintElem*>::iterator;
95 using FluctuatingChargeIterator = std::vector<Atom*>::iterator;
96 using HBondDonorIterator = std::vector<HBondDonor*>::iterator;
97 using HBondAcceptorIterator = std::vector<Atom*>::iterator;
98
99 Molecule(int stampId, int globalIndex, const std::string& molName,
100 int region);
101 virtual ~Molecule();
102
103 /**
104 * Returns the global index of this molecule.
105 * @return the global index of this molecule
106 */
107 int getGlobalIndex() { return globalIndex_; }
108
109 /**
110 * Returns the stamp id of this molecule
111 * @note Ideally, every molecule should keep a pointer of its
112 * molecule stamp instead of its stamp id. However, the pointer
113 * will become invalid, if the molecule migrate to other
114 * processor.
115 */
116 int getStampId() { return stampId_; }
117 int getRegion() { return region_; }
118
119 /** Returns the name of the molecule */
120 std::string getType() { return moleculeName_; }
121
122 /**
123 * Sets the global index of this molecule.
124 * @param index new global index to be set
125 */
126 void setGlobalIndex(int index) { globalIndex_ = index; }
127
128 void setConstrainTotalCharge(bool ctc) { constrainTotalCharge_ = ctc; }
129
130 bool constrainTotalCharge() { return constrainTotalCharge_; }
131
132 /** add an atom into this molecule */
133 void addAtom(Atom* atom);
134
135 /** add a bond into this molecule */
136 void addBond(Bond* bond);
137
138 /** add a bend into this molecule */
139 void addBend(Bend* bend);
140
141 /** add a torsion into this molecule*/
142 void addTorsion(Torsion* torsion);
143
144 /** add an improper torsion into this molecule*/
145 void addInversion(Inversion* inversion);
146
147 /** add a rigidbody into this molecule */
148 void addRigidBody(RigidBody* rb);
149
150 /** add a cutoff group into this molecule */
151 void addCutoffGroup(CutoffGroup* cp);
152
153 void addConstraintPair(ConstraintPair* consPair);
154
155 void addConstraintElem(ConstraintElem* consElem);
156
157 /** */
158 void complete();
159
160 /** Returns the total number of atoms in this molecule */
161 size_t getNAtoms() { return atoms_.size(); }
162
163 /** Returns the total number of bonds in this molecule */
164 size_t getNBonds() { return bonds_.size(); }
165
166 /** Returns the total number of bends in this molecule */
167 size_t getNBends() { return bends_.size(); }
168
169 /** Returns the total number of torsions in this molecule */
170 size_t getNTorsions() { return torsions_.size(); }
171
172 /** Returns the total number of improper torsions in this molecule */
173 size_t getNInversions() { return inversions_.size(); }
174
175 /** Returns the total number of rigid bodies in this molecule */
176 size_t getNRigidBodies() { return rigidBodies_.size(); }
177
178 /** Returns the total number of integrable objects in this molecule */
179 size_t getNIntegrableObjects() { return integrableObjects_.size(); }
180
181 /** Returns the total number of cutoff groups in this molecule */
182 size_t getNCutoffGroups() { return cutoffGroups_.size(); }
183
184 /** Returns the total number of constraints in this molecule */
185 size_t getNConstraintPairs() { return constraintPairs_.size(); }
186
187 /** Returns the total number of fluctuating charges in this molecule */
188 size_t getNFluctuatingCharges() { return fluctuatingCharges_.size(); }
189 /** Returns the total number of Hydrogen Bond donors in this molecule */
190 size_t getNHBondDonors() { return hBondDonors_.size(); }
191
192 /** Returns the total number of Hydrogen Bond acceptors in this molecule */
193 size_t getNHBondAcceptors() { return hBondAcceptors_.size(); }
194
195 Atom* getAtomAt(unsigned int i) {
196 assert(i < atoms_.size());
197 return atoms_[i];
198 }
199
200 RigidBody* getRigidBodyAt(unsigned int i) {
201 assert(i < rigidBodies_.size());
202 return rigidBodies_[i];
203 }
204
205 Atom* beginAtom(std::vector<Atom*>::iterator& i) {
206 i = atoms_.begin();
207 return (i == atoms_.end()) ? NULL : *i;
208 }
209
210 Atom* nextAtom(std::vector<Atom*>::iterator& i) {
211 ++i;
212 return (i == atoms_.end()) ? NULL : *i;
213 }
214
215 Bond* beginBond(std::vector<Bond*>::iterator& i) {
216 i = bonds_.begin();
217 return (i == bonds_.end()) ? NULL : *i;
218 }
219
220 Bond* nextBond(std::vector<Bond*>::iterator& i) {
221 ++i;
222 return (i == bonds_.end()) ? NULL : *i;
223 }
224
225 Bend* beginBend(std::vector<Bend*>::iterator& i) {
226 i = bends_.begin();
227 return (i == bends_.end()) ? NULL : *i;
228 }
229
230 Bend* nextBend(std::vector<Bend*>::iterator& i) {
231 ++i;
232 return (i == bends_.end()) ? NULL : *i;
233 }
234
235 Torsion* beginTorsion(std::vector<Torsion*>::iterator& i) {
236 i = torsions_.begin();
237 return (i == torsions_.end()) ? NULL : *i;
238 }
239
240 Torsion* nextTorsion(std::vector<Torsion*>::iterator& i) {
241 ++i;
242 return (i == torsions_.end()) ? NULL : *i;
243 }
244
245 Inversion* beginInversion(std::vector<Inversion*>::iterator& i) {
246 i = inversions_.begin();
247 return (i == inversions_.end()) ? NULL : *i;
248 }
249
250 Inversion* nextInversion(std::vector<Inversion*>::iterator& i) {
251 ++i;
252 return (i == inversions_.end()) ? NULL : *i;
253 }
254
255 RigidBody* beginRigidBody(std::vector<RigidBody*>::iterator& i) {
256 i = rigidBodies_.begin();
257 return (i == rigidBodies_.end()) ? NULL : *i;
258 }
259
260 RigidBody* nextRigidBody(std::vector<RigidBody*>::iterator& i) {
261 ++i;
262 return (i == rigidBodies_.end()) ? NULL : *i;
263 }
264
265 StuntDouble* beginIntegrableObject(std::vector<StuntDouble*>::iterator& i) {
266 i = integrableObjects_.begin();
267 return (i == integrableObjects_.end()) ? NULL : *i;
268 }
269
270 StuntDouble* nextIntegrableObject(std::vector<StuntDouble*>::iterator& i) {
271 ++i;
272 return (i == integrableObjects_.end()) ? NULL : *i;
273 }
274
275 CutoffGroup* beginCutoffGroup(std::vector<CutoffGroup*>::iterator& i) {
276 i = cutoffGroups_.begin();
277 return (i == cutoffGroups_.end()) ? NULL : *i;
278 }
279
280 CutoffGroup* nextCutoffGroup(std::vector<CutoffGroup*>::iterator& i) {
281 ++i;
282 return (i == cutoffGroups_.end()) ? NULL : *i;
283 }
284
285 ConstraintPair* beginConstraintPair(
286 std::vector<ConstraintPair*>::iterator& i) {
287 i = constraintPairs_.begin();
288 return (i == constraintPairs_.end()) ? NULL : *i;
289 }
290
291 ConstraintPair* nextConstraintPair(
292 std::vector<ConstraintPair*>::iterator& i) {
293 ++i;
294 return (i == constraintPairs_.end()) ? NULL : *i;
295 }
296
297 ConstraintElem* beginConstraintElem(
298 std::vector<ConstraintElem*>::iterator& i) {
299 i = constraintElems_.begin();
300 return (i == constraintElems_.end()) ? NULL : *i;
301 }
302
303 ConstraintElem* nextConstraintElem(
304 std::vector<ConstraintElem*>::iterator& i) {
305 ++i;
306 return (i == constraintElems_.end()) ? NULL : *i;
307 }
308
309 Atom* beginFluctuatingCharge(std::vector<Atom*>::iterator& i) {
310 i = fluctuatingCharges_.begin();
311 return (i == fluctuatingCharges_.end()) ? NULL : *i;
312 }
313
314 Atom* nextFluctuatingCharge(std::vector<Atom*>::iterator& i) {
315 ++i;
316 return (i == fluctuatingCharges_.end()) ? NULL : *i;
317 }
318
319 HBondDonor* beginHBondDonor(std::vector<HBondDonor*>::iterator& i) {
320 i = hBondDonors_.begin();
321 return (i == hBondDonors_.end()) ? NULL : *i;
322 }
323
324 HBondDonor* nextHBondDonor(std::vector<HBondDonor*>::iterator& i) {
325 ++i;
326 return (i == hBondDonors_.end()) ? NULL : *i;
327 }
328
329 Atom* beginHBondAcceptor(std::vector<Atom*>::iterator& i) {
330 i = hBondAcceptors_.begin();
331 return (i == hBondAcceptors_.end()) ? NULL : *i;
332 }
333
334 Atom* nextHBondAcceptor(std::vector<Atom*>::iterator& i) {
335 ++i;
336 return (i == hBondAcceptors_.end()) ? NULL : *i;
337 }
338
339 /**
340 * Returns the total potential energy of short range interaction
341 * of this molecule
342 */
343 RealType getPotential();
344
345 /** get total mass of this molecule */
346 RealType getMass();
347
348 /**
349 * Returns the center of mass position of this molecule in
350 * the previous snapshot
351 *
352 * @return the center of mass position of this molecule.
353 */
354 Vector3d getPrevCom();
355
356 /**
357 * Returns the current center of mass position of this molecule.
358 *
359 * @return the center of mass position of this molecule.
360 */
361 Vector3d getCom();
362
363 /**
364 * Returns the center of mass position of this molecule in
365 * specified snapshot
366 *
367 * @return the center of mass position of this molecule
368 * @param snapshotNo
369 */
370 Vector3d getCom(int snapshotNo);
371
372 /** Sets the center of this molecule */
373 void setCom(const Vector3d& newCom);
374
375 /** Moves the center of this molecule */
376 void moveCom(const Vector3d& delta);
377
378 /** Returns the velocity of center of mass of this molecule */
379 Vector3d getComVel();
380
381 std::string getMoleculeName() { return moleculeName_; }
382
383 friend std::ostream& operator<<(std::ostream& o, Molecule& mol);
384
385 // below functions are just forward functions
386 /**
387 * Adds property into property map
388 * @param genData GenericData to be added into PropertyMap
389 */
390 void addProperty(std::shared_ptr<GenericData> genData);
391
392 /**
393 * Removes property from PropertyMap by name
394 * @param propName the name of property to be removed
395 */
396 void removeProperty(const std::string& propName);
397
398 /**
399 * Returns all names of properties
400 * @return all names of properties
401 */
402 std::vector<std::string> getPropertyNames();
403
404 /**
405 * Returns all of the properties in PropertyMap
406 * @return all of the properties in PropertyMap
407 */
408 std::vector<std::shared_ptr<GenericData>> getProperties();
409
410 /**
411 * Returns property
412 * @param propName name of property
413 * @return a pointer point to property with propName. If no property named
414 * propName exists, return NULL
415 */
416 std::shared_ptr<GenericData> getPropertyByName(const std::string& propName);
417
418 private:
419 int globalIndex_;
420
421 std::vector<Atom*> atoms_;
422 std::vector<Bond*> bonds_;
423 std::vector<Bend*> bends_;
424 std::vector<Torsion*> torsions_;
425 std::vector<Inversion*> inversions_;
426 std::vector<RigidBody*> rigidBodies_;
427 std::vector<StuntDouble*> integrableObjects_;
428 std::vector<CutoffGroup*> cutoffGroups_;
429 std::vector<ConstraintPair*> constraintPairs_;
430 std::vector<ConstraintElem*> constraintElems_;
431 std::vector<Atom*> fluctuatingCharges_;
432 std::vector<HBondDonor*> hBondDonors_;
433 std::vector<Atom*> hBondAcceptors_;
434
435 int stampId_;
436 int region_;
437 std::string moleculeName_;
438 PropertyMap properties_;
439 bool constrainTotalCharge_;
440 };
441} // namespace OpenMD
442
443#endif //
Vector3d getPrevCom()
Returns the center of mass position of this molecule in the previous snapshot.
Definition Molecule.cpp:279
void addAtom(Atom *atom)
add an atom into this molecule
Definition Molecule.cpp:86
void addInversion(Inversion *inversion)
add an improper torsion into this molecule
Definition Molecule.cpp:111
size_t getNIntegrableObjects()
Returns the total number of integrable objects in this molecule.
Definition Molecule.hpp:179
void setGlobalIndex(int index)
Sets the global index of this molecule.
Definition Molecule.hpp:126
RealType getMass()
get total mass of this molecule
Definition Molecule.cpp:266
size_t getNFluctuatingCharges()
Returns the total number of fluctuating charges in this molecule.
Definition Molecule.hpp:188
std::vector< std::string > getPropertyNames()
Returns all names of properties.
Definition Molecule.cpp:412
size_t getNInversions()
Returns the total number of improper torsions in this molecule.
Definition Molecule.hpp:173
void removeProperty(const std::string &propName)
Removes property from PropertyMap by name.
Definition Molecule.cpp:408
void addBend(Bend *bend)
add a bend into this molecule
Definition Molecule.cpp:98
void addRigidBody(RigidBody *rb)
add a rigidbody into this molecule
Definition Molecule.cpp:118
int getGlobalIndex()
Returns the global index of this molecule.
Definition Molecule.hpp:107
int getStampId()
Returns the stamp id of this molecule.
Definition Molecule.hpp:116
size_t getNHBondDonors()
Returns the total number of Hydrogen Bond donors in this molecule.
Definition Molecule.hpp:190
std::vector< std::shared_ptr< GenericData > > getProperties()
Returns all of the properties in PropertyMap.
Definition Molecule.cpp:416
size_t getNBends()
Returns the total number of bends in this molecule.
Definition Molecule.hpp:167
std::shared_ptr< GenericData > getPropertyByName(const std::string &propName)
Returns property.
Definition Molecule.cpp:420
size_t getNConstraintPairs()
Returns the total number of constraints in this molecule.
Definition Molecule.hpp:185
void addCutoffGroup(CutoffGroup *cp)
add a cutoff group into this molecule
Definition Molecule.cpp:125
Vector3d getComVel()
Returns the velocity of center of mass of this molecule.
Definition Molecule.cpp:351
void addBond(Bond *bond)
add a bond into this molecule
Definition Molecule.cpp:92
size_t getNAtoms()
Returns the total number of atoms in this molecule.
Definition Molecule.hpp:161
size_t getNRigidBodies()
Returns the total number of rigid bodies in this molecule.
Definition Molecule.hpp:176
size_t getNBonds()
Returns the total number of bonds in this molecule.
Definition Molecule.hpp:164
void addProperty(std::shared_ptr< GenericData > genData)
Adds property into property map.
Definition Molecule.cpp:404
RealType getPotential()
Returns the total potential energy of short range interaction of this molecule.
Definition Molecule.cpp:370
void moveCom(const Vector3d &delta)
Moves the center of this molecule.
Definition Molecule.cpp:341
size_t getNCutoffGroups()
Returns the total number of cutoff groups in this molecule.
Definition Molecule.hpp:182
void addTorsion(Torsion *torsion)
add a torsion into this molecule
Definition Molecule.cpp:104
size_t getNTorsions()
Returns the total number of torsions in this molecule.
Definition Molecule.hpp:170
void setCom(const Vector3d &newCom)
Sets the center of this molecule.
Definition Molecule.cpp:336
size_t getNHBondAcceptors()
Returns the total number of Hydrogen Bond acceptors in this molecule.
Definition Molecule.hpp:193
Vector3d getCom()
Returns the current center of mass position of this molecule.
Definition Molecule.cpp:298
std::string getType()
Returns the name of the molecule.
Definition Molecule.hpp:120
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.