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