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