OpenMD 3.0
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
CutoffGroup.hpp
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#ifndef PRIMITIVES_CUTOFFGROUP_HPP
46
47#define PRIMITIVES_CUTOFFGROUP_HPP
48
49#include "math/Vector3.hpp"
50#include "primitives/Atom.hpp"
51
52namespace OpenMD {
54 public:
55 CutoffGroup() : globalIndex(-1), localIndex_(-1), snapshotMan_(NULL) {
56 storage_ = &Snapshot::cgData;
57 haveTotalMass = false;
58 totalMass = 0.0;
59 }
60
61 /**
62 * Sets the Snapshot Manager of this cutoffGroup
63 */
64 void setSnapshotManager(SnapshotManager* sman) { snapshotMan_ = sman; }
65
66 void addAtom(Atom* atom) { cutoffAtomList.push_back(atom); }
67
68 Atom* beginAtom(std::vector<Atom*>::iterator& i) {
69 i = cutoffAtomList.begin();
70 return i != cutoffAtomList.end() ? *i : NULL;
71 }
72
73 Atom* nextAtom(std::vector<Atom*>::iterator& i) {
74 i++;
75 return i != cutoffAtomList.end() ? *i : NULL;
76 }
77
78 std::vector<Atom*> getAtoms() { return cutoffAtomList; }
79 RealType getMass() {
80 if (!haveTotalMass) {
81 totalMass = 0.0;
82
83 std::vector<Atom*>::iterator i;
84 for (Atom* atom = beginAtom(i); atom != NULL; atom = nextAtom(i)) {
85 RealType mass = atom->getMass();
86 totalMass += mass;
87 }
88
89 haveTotalMass = true;
90 }
91
92 return totalMass;
93 }
94
95 void updateCOM() {
96 DataStorage& data = snapshotMan_->getCurrentSnapshot()->*storage_;
97 bool needsVel = false;
98 if (data.getStorageLayout() & DataStorage::dslVelocity) needsVel = true;
99
100 if (cutoffAtomList.size() == 1) {
101 data.position[localIndex_] = cutoffAtomList[0]->getPos();
102 if (needsVel) data.velocity[localIndex_] = cutoffAtomList[0]->getVel();
103 } else {
104 std::vector<Atom*>::iterator i;
105 Atom* atom;
106 RealType totalMass = getMass();
107 data.position[localIndex_] = V3Zero;
108 if (needsVel) data.velocity[localIndex_] = V3Zero;
109
110 for (atom = beginAtom(i); atom != NULL; atom = nextAtom(i)) {
111 data.position[localIndex_] += atom->getMass() * atom->getPos();
112 if (needsVel)
113 data.velocity[localIndex_] += atom->getMass() * atom->getVel();
114 }
115 data.position[localIndex_] /= totalMass;
116 if (needsVel) data.velocity[localIndex_] /= totalMass;
117 }
118 }
119
120 Vector3d getPos() {
121 return ((snapshotMan_->getCurrentSnapshot())->*storage_)
122 .position[localIndex_];
123 }
124 Vector3d getVel() {
125 return ((snapshotMan_->getCurrentSnapshot())->*storage_)
126 .velocity[localIndex_];
127 }
128
129 size_t getNumAtom() { return cutoffAtomList.size(); }
130
131 int getGlobalIndex() { return globalIndex; }
132
133 void setGlobalIndex(int id) { this->globalIndex = id; }
134
135 /**
136 * Returns the local index of this cutoffGroup
137 * @return the local index of this cutoffGroup
138 */
139 int getLocalIndex() { return localIndex_; }
140
141 /**
142 * Sets the local index of this cutoffGroup
143 * @param index new index to be set
144 */
145 void setLocalIndex(int index) { localIndex_ = index; }
146
147 private:
148 std::vector<Atom*> cutoffAtomList;
149 bool haveTotalMass;
150 RealType totalMass;
151 int globalIndex;
152
153 int localIndex_;
154 DataStoragePointer storage_;
155 SnapshotManager* snapshotMan_;
156 };
157} // namespace OpenMD
158
159#endif // PRIMITIVES_CUTOFFGROUP_HPP
void setLocalIndex(int index)
Sets the local index of this cutoffGroup.
int getLocalIndex()
Returns the local index of this cutoffGroup.
void setSnapshotManager(SnapshotManager *sman)
Sets the Snapshot Manager of this cutoffGroup.
SnapshotManager class is an abstract class which maintains a series of snapshots.
Snapshot * getCurrentSnapshot()
Returns the pointer of current snapshot.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.