OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
AtomVisitor.cpp
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#include "visitors/AtomVisitor.hpp"
49
50#include <cstring>
51#include <memory>
52
55#include "types/FixedChargeAdapter.hpp"
56#include "types/FluctuatingChargeAdapter.hpp"
57#include "types/GayBerneAdapter.hpp"
58#include "types/MultipoleAdapter.hpp"
59
60namespace OpenMD {
61
62 BaseAtomVisitor::BaseAtomVisitor(SimInfo* info) : BaseVisitor() {
63 storageLayout_ = info->getAtomStorageLayout();
64 }
65
66 void BaseAtomVisitor::visit(RigidBody*) {
67 // vector<Atom*> myAtoms;
68 // vector<Atom*>::iterator atomIter;
69
70 // myAtoms = rb->getAtoms();
71
72 // for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter)
73 // (*atomIter)->accept(this);
74 }
75
76 void BaseAtomVisitor::setVisited(Atom* atom) {
77 std::shared_ptr<GenericData> data;
78 data = atom->getPropertyByName("VISITED");
79
80 // if visited property is not existed, add it as new property
81 if (data == nullptr) {
82 data = std::make_shared<GenericData>();
83 data->setID("VISITED");
84 atom->addProperty(data);
85 }
86 }
87
88 bool BaseAtomVisitor::isVisited(Atom* atom) {
89 std::shared_ptr<GenericData> data;
90 data = atom->getPropertyByName("VISITED");
91 return data == nullptr ? false : true;
92 }
93
94 //------------------------------------------------------------------------//
95
96 void DefaultAtomVisitor::visit(Atom* atom) {
97 std::shared_ptr<AtomData> atomData;
98 std::shared_ptr<AtomInfo> atomInfo;
99 AtomType* atype = atom->getAtomType();
100
101 if (isVisited(atom)) return;
102
103 atomInfo = std::make_shared<AtomInfo>();
104 atomInfo->atomTypeName = atom->getType();
105 atomInfo->globalID = atom->getGlobalIndex();
106 atomInfo->pos = atom->getPos();
107 atomInfo->vel = atom->getVel();
108 atomInfo->frc = atom->getFrc();
109 atomInfo->vec = V3Zero;
110 atomInfo->hasVelocity = true;
111 atomInfo->hasForce = true;
112 atomInfo->hasGlobalID = true;
113
114 FixedChargeAdapter fca = FixedChargeAdapter(atype);
115 if (fca.isFixedCharge()) {
116 atomInfo->hasCharge = true;
117 atomInfo->charge = fca.getCharge();
118 }
119
120 FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atype);
121 if (fqa.isFluctuatingCharge()) {
122 atomInfo->hasCharge = true;
123 atomInfo->charge += atom->getFlucQPos();
124 }
125
126 if ((storageLayout_ & DataStorage::dslElectricField) &&
127 (atype->isElectrostatic())) {
128 atomInfo->hasElectricField = true;
129 atomInfo->eField = atom->getElectricField();
130 }
131
132 atomData = std::make_shared<AtomData>();
133 atomData->setID("ATOMDATA");
134 atomData->addAtomInfo(atomInfo);
135
136 atom->addProperty(atomData);
137
138 setVisited(atom);
139 }
140
141 void DefaultAtomVisitor::visit(DirectionalAtom* datom) {
142 std::shared_ptr<AtomData> atomData;
143 std::shared_ptr<AtomInfo> atomInfo;
144 AtomType* atype = datom->getAtomType();
145
146 if (isVisited(datom)) return;
147
148 atomInfo = std::make_shared<AtomInfo>();
149 atomInfo->atomTypeName = datom->getType();
150 atomInfo->globalID = datom->getGlobalIndex();
151 atomInfo->pos = datom->getPos();
152 atomInfo->vel = datom->getVel();
153 atomInfo->frc = datom->getFrc();
154 atomInfo->hasVelocity = true;
155 atomInfo->hasForce = true;
156 atomInfo->hasGlobalID = true;
157
158 FixedChargeAdapter fca = FixedChargeAdapter(atype);
159 if (fca.isFixedCharge()) {
160 atomInfo->hasCharge = true;
161 atomInfo->charge = fca.getCharge();
162 }
163
164 FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atype);
165 if (fqa.isFluctuatingCharge()) {
166 atomInfo->hasCharge = true;
167 atomInfo->charge += datom->getFlucQPos();
168 }
169
170 if ((storageLayout_ & DataStorage::dslElectricField) &&
171 (atype->isElectrostatic())) {
172 atomInfo->hasElectricField = true;
173 atomInfo->eField = datom->getElectricField();
174 }
175
176 GayBerneAdapter gba = GayBerneAdapter(atype);
177 MultipoleAdapter ma = MultipoleAdapter(atype);
178
179 if (gba.isGayBerne()) {
180 atomInfo->hasVector = true;
181 atomInfo->vec = datom->getA().transpose() * V3Z;
182 } else if (ma.isDipole()) {
183 atomInfo->hasVector = true;
184 atomInfo->vec = datom->getDipole();
185 } else if (ma.isQuadrupole()) {
186 atomInfo->hasVector = true;
187 atomInfo->vec = datom->getA().transpose() * V3Z;
188 }
189
190 atomData = std::make_shared<AtomData>();
191 atomData->setID("ATOMDATA");
192 atomData->addAtomInfo(atomInfo);
193
194 datom->addProperty(atomData);
195
196 setVisited(datom);
197 }
198
199 const std::string DefaultAtomVisitor::toString() {
200 char buffer[65535];
201 std::string result;
202
203 snprintf(
204 buffer, 65535,
205 "--------------------------------------------------------------\n");
206 result += buffer;
207
208 snprintf(buffer, 65535, "Visitor name: %s\n", visitorName.c_str());
209 result += buffer;
210
211 snprintf(buffer, 65535,
212 "Visitor Description: copy atom infomation into atom data\n");
213 result += buffer;
214
215 snprintf(
216 buffer, 65535,
217 "--------------------------------------------------------------\n");
218 result += buffer;
219
220 return result;
221 }
222} // namespace OpenMD
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Definition SimInfo.hpp:96
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.