OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
ReplacementVisitor.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/ReplacementVisitor.hpp"
49
50#include <cstring>
51#include <memory>
52
55
56namespace OpenMD {
57
58 void ReplacementVisitor::addReplacedAtomName(const std::string& repName) {
59 myTypes_.insert(repName);
60 }
61
62 bool ReplacementVisitor::isReplacedAtom(const std::string& atomType) {
63 std::set<std::string>::iterator strIter;
64 strIter = myTypes_.find(atomType);
65 return strIter != myTypes_.end() ? true : false;
66 }
67
68 void ReplacementVisitor::addSite(const std::string& name,
69 const Vector3d& refPos) {
70 std::shared_ptr<AtomInfo> atomInfo = std::make_shared<AtomInfo>();
71 atomInfo->atomTypeName = name;
72 atomInfo->pos = refPos;
73 sites_->addAtomInfo(atomInfo);
74 }
75 void ReplacementVisitor::addSite(const std::string& name,
76 const Vector3d& refPos,
77 const Vector3d& refVec) {
78 std::shared_ptr<AtomInfo> atomInfo = std::make_shared<AtomInfo>();
79 atomInfo->atomTypeName = name;
80 atomInfo->pos = refPos;
81 atomInfo->vec = refVec;
82 atomInfo->hasVector = true;
83 sites_->addAtomInfo(atomInfo);
84 }
85
86 void ReplacementVisitor::visit(DirectionalAtom* datom) {
87 RotMat3x3d A;
88 RotMat3x3d Atrans;
89 Mat3x3d I;
90 Vector3d pos;
91 Vector3d vel;
92 Vector3d frc;
93 Vector3d trq;
94 Vector3d j;
95 Mat3x3d skewMat;
96
97 Vector3d newVec;
98 std::shared_ptr<AtomInfo> atomInfo;
99 std::shared_ptr<AtomData> atomData;
100 std::shared_ptr<GenericData> data;
101 bool haveAtomData;
102
103 // if atom is not one of our recognized atom types, just skip it
104 if (!isReplacedAtom(datom->getType())) return;
105
106 data = datom->getPropertyByName("ATOMDATA");
107
108 if (data != nullptr) {
109 atomData = std::dynamic_pointer_cast<AtomData>(data);
110
111 if (atomData == nullptr) {
112 std::cerr << "can not get Atom Data from " << datom->getType()
113 << std::endl;
114 atomData = std::make_shared<AtomData>();
115 haveAtomData = false;
116 } else
117 haveAtomData = true;
118 } else {
119 atomData = std::make_shared<AtomData>();
120 haveAtomData = false;
121 }
122
123 pos = datom->getPos();
124 vel = datom->getVel();
125
126 j = datom->getJ();
127 I = datom->getI();
128 A = datom->getA();
129
130 skewMat(0, 0) = 0;
131 skewMat(0, 1) = j[2] / I(2, 2);
132 skewMat(0, 2) = -j[1] / I(1, 1);
133 skewMat(1, 0) = -j[2] / I(2, 2);
134 skewMat(1, 1) = 0;
135 skewMat(1, 2) = j[0] / I(0, 0);
136 skewMat(2, 0) = j[1] / I(1, 1);
137 skewMat(2, 1) = -j[0] / I(0, 0);
138 skewMat(2, 2) = 0;
139 Mat3x3d mat = (A * skewMat).transpose();
140
141 // We need A^T to convert from body-fixed to space-fixed:
142 Atrans = A.transpose();
143
144 std::shared_ptr<AtomInfo> siteInfo;
145 std::vector<std::shared_ptr<AtomInfo>>::iterator iter;
146
147 for (siteInfo = sites_->beginAtomInfo(iter); siteInfo;
148 siteInfo = sites_->nextAtomInfo(iter)) {
149 newVec = Atrans * siteInfo->pos;
150
151 atomInfo = std::make_shared<AtomInfo>();
152 atomInfo->atomTypeName = siteInfo->atomTypeName;
153 atomInfo->pos = pos + newVec;
154
155 if (siteInfo->hasVector) {
156 newVec = Atrans * siteInfo->vec;
157 atomInfo->vec = newVec;
158 } else {
159 atomInfo->vec = V3Zero;
160 }
161
162 atomInfo->vel = vel + mat * siteInfo->pos;
163 atomInfo->hasVelocity = true;
164
165 atomData->addAtomInfo(atomInfo);
166 }
167 if (!haveAtomData) {
168 atomData->setID("ATOMDATA");
169 datom->addProperty(atomData);
170 }
171
172 setVisited(datom);
173 }
174
175 const std::string ReplacementVisitor::toString() {
176 char buffer[65535];
177 std::string result;
178
179 snprintf(
180 buffer, 65535,
181 "------------------------------------------------------------------\n");
182 result += buffer;
183
184 snprintf(buffer, 65535, "Visitor name: %s\n", visitorName.c_str());
185 result += buffer;
186
187 snprintf(buffer, 65535,
188 "Visitor Description: replace atom with other sites\n");
189 result += buffer;
190
191 snprintf(
192 buffer, 65535,
193 "------------------------------------------------------------------\n");
194 result += buffer;
195
196 return result;
197 }
198} // namespace OpenMD
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.