OpenMD 3.2
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 following paper when you publish your work:
33 *
34 * [1] Drisko et al., J. Open Source Softw. 9, 7004 (2024).
35 *
36 * Good starting points for code and simulation methodology are:
37 *
38 * [2] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
39 * [3] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
40 * [4] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
41 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
42 * [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
43 * [7] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
44 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
45 * [9] Drisko & Gezelter, J. Chem. Theory Comput. 20, 4986-4997 (2024).
46 */
47
48/**
49 * @file Molecule.hpp
50 * @author tlin
51 * @date 10/25/2004
52 * @version 1.0
53 */
54
55#ifndef PRIMITIVES_MOLECULE_HPP
56#define PRIMITIVES_MOLECULE_HPP
57
58#include <iostream>
59#include <memory>
60#include <vector>
61
62#include "constraints/ConstraintPair.hpp"
63#include "math/Vector3.hpp"
64#include "primitives/Atom.hpp"
65#include "primitives/Bend.hpp"
66#include "primitives/Bond.hpp"
67#include "primitives/CutoffGroup.hpp"
71#include "utils/PropertyMap.hpp"
72
73namespace OpenMD {
74
75 class Constraint;
76
77 /**
78 * @class Molecule Molecule.hpp "primitives/Molecule.hpp"
79 * @brief
80 */
81 class Molecule {
82 public:
83 struct HBondDonor {
84 Atom* donorAtom;
85 Atom* donatedHydrogen;
86 };
87
88 using AtomIterator = std::vector<Atom*>::iterator;
89 using BondIterator = std::vector<Bond*>::iterator;
90 using BendIterator = std::vector<Bend*>::iterator;
91 using TorsionIterator = std::vector<Torsion*>::iterator;
92 using InversionIterator = std::vector<Inversion*>::iterator;
93 using RigidBodyIterator = std::vector<RigidBody*>::iterator;
94 using CutoffGroupIterator = std::vector<CutoffGroup*>::iterator;
95 using IntegrableObjectIterator = std::vector<StuntDouble*>::iterator;
96 using ConstraintPairIterator = std::vector<ConstraintPair*>::iterator;
97 using ConstraintElemIterator = std::vector<ConstraintElem*>::iterator;
98 using FluctuatingChargeIterator = std::vector<Atom*>::iterator;
99 using HBondDonorIterator = std::vector<HBondDonor*>::iterator;
100 using HBondAcceptorIterator = std::vector<Atom*>::iterator;
101
102 Molecule(int globalIndex, MoleculeStamp* molStamp);
103 virtual ~Molecule();
104
105 /**
106 * Returns the global index of this molecule.
107 * @return the global index of this molecule
108 */
109 int getGlobalIndex() { return globalIndex_; }
110
111 /**
112 * Returns the stamp id of this molecule
113 * @note Ideally, every molecule should keep a pointer of its
114 * molecule stamp instead of its stamp id. However, the pointer
115 * will become invalid, if the molecule migrate to other
116 * processor.
117 */
118 int getStampId() { return molStamp_->getIdent(); }
119 int getRegion() { return molStamp_->getRegion(); }
120
121 MoleculeStamp* getMolStamp() const { return molStamp_; }
122
123 /** Returns the name of the molecule */
124 std::string getType() { return molStamp_->getName(); }
125
126 /**
127 * Sets the global index of this molecule.
128 * @param index new global index to be set
129 */
130 void setGlobalIndex(int index) { globalIndex_ = index; }
131
132 void setConstrainTotalCharge(bool ctc) { constrainTotalCharge_ = ctc; }
133
134 bool constrainTotalCharge() { return constrainTotalCharge_; }
135
136 /** add an atom into this molecule */
137 void addAtom(Atom* atom);
138
139 /** add a bond into this molecule */
140 void addBond(Bond* bond);
141
142 /** add a bend into this molecule */
143 void addBend(Bend* bend);
144
145 /** add a torsion into this molecule*/
146 void addTorsion(Torsion* torsion);
147
148 /** add an improper torsion into this molecule*/
149 void addInversion(Inversion* inversion);
150
151 /** add a rigidbody into this molecule */
152 void addRigidBody(RigidBody* rb);
153
154 /** add a cutoff group into this molecule */
155 void addCutoffGroup(CutoffGroup* cp);
156
157 void addConstraintPair(ConstraintPair* consPair);
158
159 void addConstraintElem(ConstraintElem* consElem);
160
161 /** */
162 void complete();
163
164 /** Returns the total number of atoms in this molecule */
165 size_t getNAtoms() { return atoms_.size(); }
166
167 /** Returns the total number of bonds in this molecule */
168 size_t getNBonds() { return bonds_.size(); }
169
170 /** Returns the total number of bends in this molecule */
171 size_t getNBends() { return bends_.size(); }
172
173 /** Returns the total number of torsions in this molecule */
174 size_t getNTorsions() { return torsions_.size(); }
175
176 /** Returns the total number of improper torsions in this molecule */
177 size_t getNInversions() { return inversions_.size(); }
178
179 /** Returns the total number of rigid bodies in this molecule */
180 size_t getNRigidBodies() { return rigidBodies_.size(); }
181
182 /** Returns the total number of integrable objects in this molecule */
183 size_t getNIntegrableObjects() { return integrableObjects_.size(); }
184
185 /** Returns the total number of cutoff groups in this molecule */
186 size_t getNCutoffGroups() { return cutoffGroups_.size(); }
187
188 /** Returns the total number of constraints in this molecule */
189 size_t getNConstraintPairs() { return constraintPairs_.size(); }
190
191 /** Returns the total number of fluctuating charges in this molecule */
192 size_t getNFluctuatingCharges() { return fluctuatingCharges_.size(); }
193 /** Returns the total number of Hydrogen Bond donors in this molecule */
194 size_t getNHBondDonors() { return hBondDonors_.size(); }
195
196 /** Returns the total number of Hydrogen Bond acceptors in this molecule */
197 size_t getNHBondAcceptors() { return hBondAcceptors_.size(); }
198
199 Atom* getAtomAt(unsigned int i) {
200 assert(i < atoms_.size());
201 return atoms_[i];
202 }
203
204 RigidBody* getRigidBodyAt(unsigned int i) {
205 assert(i < rigidBodies_.size());
206 return rigidBodies_[i];
207 }
208
209 Atom* beginAtom(std::vector<Atom*>::iterator& i) {
210 i = atoms_.begin();
211 return (i == atoms_.end()) ? NULL : *i;
212 }
213
214 Atom* nextAtom(std::vector<Atom*>::iterator& i) {
215 ++i;
216 return (i == atoms_.end()) ? NULL : *i;
217 }
218
219 Bond* beginBond(std::vector<Bond*>::iterator& i) {
220 i = bonds_.begin();
221 return (i == bonds_.end()) ? NULL : *i;
222 }
223
224 Bond* nextBond(std::vector<Bond*>::iterator& i) {
225 ++i;
226 return (i == bonds_.end()) ? NULL : *i;
227 }
228
229 Bend* beginBend(std::vector<Bend*>::iterator& i) {
230 i = bends_.begin();
231 return (i == bends_.end()) ? NULL : *i;
232 }
233
234 Bend* nextBend(std::vector<Bend*>::iterator& i) {
235 ++i;
236 return (i == bends_.end()) ? NULL : *i;
237 }
238
239 Torsion* beginTorsion(std::vector<Torsion*>::iterator& i) {
240 i = torsions_.begin();
241 return (i == torsions_.end()) ? NULL : *i;
242 }
243
244 Torsion* nextTorsion(std::vector<Torsion*>::iterator& i) {
245 ++i;
246 return (i == torsions_.end()) ? NULL : *i;
247 }
248
249 Inversion* beginInversion(std::vector<Inversion*>::iterator& i) {
250 i = inversions_.begin();
251 return (i == inversions_.end()) ? NULL : *i;
252 }
253
254 Inversion* nextInversion(std::vector<Inversion*>::iterator& i) {
255 ++i;
256 return (i == inversions_.end()) ? NULL : *i;
257 }
258
259 RigidBody* beginRigidBody(std::vector<RigidBody*>::iterator& i) {
260 i = rigidBodies_.begin();
261 return (i == rigidBodies_.end()) ? NULL : *i;
262 }
263
264 RigidBody* nextRigidBody(std::vector<RigidBody*>::iterator& i) {
265 ++i;
266 return (i == rigidBodies_.end()) ? NULL : *i;
267 }
268
269 StuntDouble* beginIntegrableObject(std::vector<StuntDouble*>::iterator& i) {
270 i = integrableObjects_.begin();
271 return (i == integrableObjects_.end()) ? NULL : *i;
272 }
273
274 StuntDouble* nextIntegrableObject(std::vector<StuntDouble*>::iterator& i) {
275 ++i;
276 return (i == integrableObjects_.end()) ? NULL : *i;
277 }
278
279 CutoffGroup* beginCutoffGroup(std::vector<CutoffGroup*>::iterator& i) {
280 i = cutoffGroups_.begin();
281 return (i == cutoffGroups_.end()) ? NULL : *i;
282 }
283
284 CutoffGroup* nextCutoffGroup(std::vector<CutoffGroup*>::iterator& i) {
285 ++i;
286 return (i == cutoffGroups_.end()) ? NULL : *i;
287 }
288
289 ConstraintPair* beginConstraintPair(
290 std::vector<ConstraintPair*>::iterator& i) {
291 i = constraintPairs_.begin();
292 return (i == constraintPairs_.end()) ? NULL : *i;
293 }
294
295 ConstraintPair* nextConstraintPair(
296 std::vector<ConstraintPair*>::iterator& i) {
297 ++i;
298 return (i == constraintPairs_.end()) ? NULL : *i;
299 }
300
301 ConstraintElem* beginConstraintElem(
302 std::vector<ConstraintElem*>::iterator& i) {
303 i = constraintElems_.begin();
304 return (i == constraintElems_.end()) ? NULL : *i;
305 }
306
307 ConstraintElem* nextConstraintElem(
308 std::vector<ConstraintElem*>::iterator& i) {
309 ++i;
310 return (i == constraintElems_.end()) ? NULL : *i;
311 }
312
313 Atom* beginFluctuatingCharge(std::vector<Atom*>::iterator& i) {
314 i = fluctuatingCharges_.begin();
315 return (i == fluctuatingCharges_.end()) ? NULL : *i;
316 }
317
318 Atom* nextFluctuatingCharge(std::vector<Atom*>::iterator& i) {
319 ++i;
320 return (i == fluctuatingCharges_.end()) ? NULL : *i;
321 }
322
323 HBondDonor* beginHBondDonor(std::vector<HBondDonor*>::iterator& i) {
324 i = hBondDonors_.begin();
325 return (i == hBondDonors_.end()) ? NULL : *i;
326 }
327
328 HBondDonor* nextHBondDonor(std::vector<HBondDonor*>::iterator& i) {
329 ++i;
330 return (i == hBondDonors_.end()) ? NULL : *i;
331 }
332
333 Atom* beginHBondAcceptor(std::vector<Atom*>::iterator& i) {
334 i = hBondAcceptors_.begin();
335 return (i == hBondAcceptors_.end()) ? NULL : *i;
336 }
337
338 Atom* nextHBondAcceptor(std::vector<Atom*>::iterator& i) {
339 ++i;
340 return (i == hBondAcceptors_.end()) ? NULL : *i;
341 }
342
343 /**
344 * Returns the total potential energy of short range interaction
345 * of this molecule
346 */
347 RealType getPotential();
348
349 /** get total mass of this molecule */
350 RealType getMass();
351
352 /** get total fixed charge of this molecule */
353 RealType getFixedCharge();
354
355 /**
356 * Returns the center of mass position of this molecule in
357 * the previous snapshot
358 *
359 * @return the center of mass position of this molecule.
360 */
361 Vector3d getPrevCom();
362
363 /**
364 * Returns the current center of mass position of this molecule.
365 *
366 * @return the center of mass position of this molecule.
367 */
368 Vector3d getCom();
369
370 /**
371 * Returns the center of mass position of this molecule in
372 * specified snapshot
373 *
374 * @return the center of mass position of this molecule
375 * @param snapshotNo
376 */
377 Vector3d getCom(int snapshotNo);
378
379 /** Sets the center of this molecule */
380 void setCom(const Vector3d& newCom);
381
382 /** Moves the center of this molecule */
383 void moveCom(const Vector3d& delta);
384
385 /** Returns the velocity of center of mass of this molecule */
386 Vector3d getComVel();
387
388 friend std::ostream& operator<<(std::ostream& o, Molecule& mol);
389
390 // below functions are just forward functions
391 /**
392 * Adds property into property map
393 * @param genData GenericData to be added into PropertyMap
394 */
395 void addProperty(std::shared_ptr<GenericData> genData);
396
397 /**
398 * Removes property from PropertyMap by name
399 * @param propName the name of property to be removed
400 */
401 void removeProperty(const std::string& propName);
402
403 /**
404 * Returns all names of properties
405 * @return all names of properties
406 */
407 std::vector<std::string> getPropertyNames();
408
409 /**
410 * Returns all of the properties in PropertyMap
411 * @return all of the properties in PropertyMap
412 */
413 std::vector<std::shared_ptr<GenericData>> getProperties();
414
415 /**
416 * Returns property
417 * @param propName name of property
418 * @return a pointer point to property with propName. If no property named
419 * propName exists, return NULL
420 */
421 std::shared_ptr<GenericData> getPropertyByName(const std::string& propName);
422
423 private:
424 int globalIndex_;
425
426 std::vector<Atom*> atoms_;
427 std::vector<Bond*> bonds_;
428 std::vector<Bend*> bends_;
429 std::vector<Torsion*> torsions_;
430 std::vector<Inversion*> inversions_;
431 std::vector<RigidBody*> rigidBodies_;
432 std::vector<StuntDouble*> integrableObjects_;
433 std::vector<CutoffGroup*> cutoffGroups_;
434 std::vector<ConstraintPair*> constraintPairs_;
435 std::vector<ConstraintElem*> constraintElems_;
436 std::vector<Atom*> fluctuatingCharges_;
437 std::vector<HBondDonor*> hBondDonors_;
438 std::vector<Atom*> hBondAcceptors_;
439
440 PropertyMap properties_;
441 bool constrainTotalCharge_;
442 MoleculeStamp* molStamp_;
443 };
444} // namespace OpenMD
445
446#endif //
Vector3d getPrevCom()
Returns the center of mass position of this molecule in the previous snapshot.
Definition Molecule.cpp:296
void addAtom(Atom *atom)
add an atom into this molecule
Definition Molecule.cpp:88
void addInversion(Inversion *inversion)
add an improper torsion into this molecule
Definition Molecule.cpp:113
size_t getNIntegrableObjects()
Returns the total number of integrable objects in this molecule.
Definition Molecule.hpp:183
void setGlobalIndex(int index)
Sets the global index of this molecule.
Definition Molecule.hpp:130
RealType getMass()
get total mass of this molecule
Definition Molecule.cpp:268
size_t getNFluctuatingCharges()
Returns the total number of fluctuating charges in this molecule.
Definition Molecule.hpp:192
std::vector< std::string > getPropertyNames()
Returns all names of properties.
Definition Molecule.cpp:429
size_t getNInversions()
Returns the total number of improper torsions in this molecule.
Definition Molecule.hpp:177
void removeProperty(const std::string &propName)
Removes property from PropertyMap by name.
Definition Molecule.cpp:425
void addBend(Bend *bend)
add a bend into this molecule
Definition Molecule.cpp:100
void addRigidBody(RigidBody *rb)
add a rigidbody into this molecule
Definition Molecule.cpp:120
int getGlobalIndex()
Returns the global index of this molecule.
Definition Molecule.hpp:109
int getStampId()
Returns the stamp id of this molecule.
Definition Molecule.hpp:118
size_t getNHBondDonors()
Returns the total number of Hydrogen Bond donors in this molecule.
Definition Molecule.hpp:194
std::vector< std::shared_ptr< GenericData > > getProperties()
Returns all of the properties in PropertyMap.
Definition Molecule.cpp:433
size_t getNBends()
Returns the total number of bends in this molecule.
Definition Molecule.hpp:171
std::shared_ptr< GenericData > getPropertyByName(const std::string &propName)
Returns property.
Definition Molecule.cpp:437
size_t getNConstraintPairs()
Returns the total number of constraints in this molecule.
Definition Molecule.hpp:189
void addCutoffGroup(CutoffGroup *cp)
add a cutoff group into this molecule
Definition Molecule.cpp:127
Vector3d getComVel()
Returns the velocity of center of mass of this molecule.
Definition Molecule.cpp:368
void addBond(Bond *bond)
add a bond into this molecule
Definition Molecule.cpp:94
size_t getNAtoms()
Returns the total number of atoms in this molecule.
Definition Molecule.hpp:165
size_t getNRigidBodies()
Returns the total number of rigid bodies in this molecule.
Definition Molecule.hpp:180
size_t getNBonds()
Returns the total number of bonds in this molecule.
Definition Molecule.hpp:168
void addProperty(std::shared_ptr< GenericData > genData)
Adds property into property map.
Definition Molecule.cpp:421
RealType getPotential()
Returns the total potential energy of short range interaction of this molecule.
Definition Molecule.cpp:387
void moveCom(const Vector3d &delta)
Moves the center of this molecule.
Definition Molecule.cpp:358
size_t getNCutoffGroups()
Returns the total number of cutoff groups in this molecule.
Definition Molecule.hpp:186
void addTorsion(Torsion *torsion)
add a torsion into this molecule
Definition Molecule.cpp:106
size_t getNTorsions()
Returns the total number of torsions in this molecule.
Definition Molecule.hpp:174
RealType getFixedCharge()
get total fixed charge of this molecule
Definition Molecule.cpp:281
void setCom(const Vector3d &newCom)
Sets the center of this molecule.
Definition Molecule.cpp:353
size_t getNHBondAcceptors()
Returns the total number of Hydrogen Bond acceptors in this molecule.
Definition Molecule.hpp:197
Vector3d getCom()
Returns the current center of mass position of this molecule.
Definition Molecule.cpp:315
std::string getType()
Returns the name of the molecule.
Definition Molecule.hpp:124
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.