OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
RigidBodyVisitor.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/RigidBodyVisitor.hpp"
46
47#include <memory>
48
50
51namespace OpenMD {
52
53 void LipidHeadVisitor::visit(RigidBody* rb) {
54 int globalID;
55 Vector3d pos;
56 Vector3d u(0, 0, 1);
57 Vector3d newVec;
58 std::shared_ptr<GenericData> data;
59 std::shared_ptr<AtomData> atomData;
60 std::shared_ptr<AtomInfo> atomInfo;
61 bool haveAtomData;
62 RotMat3x3d rotMatrix;
63
64 if (!canVisit(rb->getType())) return;
65
66 globalID = rb->getGlobalIndex();
67 pos = rb->getPos();
68 rotMatrix = rb->getA();
69 // matVecMul3(rotMatrix, u, newVec);
70 newVec = rotMatrix * u;
71
72 data = rb->getPropertyByName("ATOMDATA");
73
74 if (data != nullptr) {
75 atomData = std::dynamic_pointer_cast<AtomData>(data);
76
77 if (atomData == nullptr) {
78 std::cerr << "can not get Atom Data from " << rb->getType()
79 << std::endl;
80
81 atomData = std::make_shared<AtomData>();
82 haveAtomData = false;
83
84 } else
85 haveAtomData = true;
86
87 } else {
88 atomData = std::make_shared<AtomData>();
89 haveAtomData = false;
90 }
91
92 atomInfo = std::make_shared<AtomInfo>();
93 atomInfo->atomTypeName = "X";
94 atomInfo->globalID = globalID;
95 atomInfo->pos[0] = pos[0];
96 atomInfo->pos[1] = pos[1];
97 atomInfo->pos[2] = pos[2];
98 atomInfo->vec[0] = newVec[0];
99 atomInfo->vec[1] = newVec[1];
100 atomInfo->vec[2] = newVec[2];
101
102 atomData->addAtomInfo(atomInfo);
103
104 if (!haveAtomData) {
105 atomData->setID("ATOMDATA");
106 rb->addProperty(atomData);
107 }
108 }
109
110 void LipidHeadVisitor::addLipidHeadName(const std::string& name) {
111 lipidHeadName.insert(name);
112 }
113
114 bool LipidHeadVisitor::canVisit(const std::string& name) {
115 return lipidHeadName.find(name) != lipidHeadName.end() ? true : false;
116 }
117
118 const std::string LipidHeadVisitor::toString() {
119 char buffer[65535];
120 std::string result;
121 std::set<std::string>::iterator i;
122
123 snprintf(
124 buffer, 65535,
125 "------------------------------------------------------------------\n");
126 result += buffer;
127
128 snprintf(buffer, 65535, "Visitor name: %s\n", visitorName.c_str());
129 result += buffer;
130
131 // print the ignore type list
132 snprintf(buffer, 65535, "lipidHeadName list contains below types:\n");
133 result += buffer;
134
135 for (i = lipidHeadName.begin(); i != lipidHeadName.end(); ++i) {
136 snprintf(buffer, 65535, "%s\t", i->c_str());
137 result += buffer;
138 }
139
140 snprintf(buffer, 65535, "\n");
141 result += buffer;
142
143 snprintf(
144 buffer, 65535,
145 "------------------------------------------------------------------\n");
146 result += buffer;
147
148 return result;
149 }
150
151 void RBCOMVisitor::visit(RigidBody* rb) {
152 std::shared_ptr<AtomData> atomData;
153 std::shared_ptr<AtomInfo> atomInfo;
154 Vector3d pos;
155 pos = rb->getPos();
156
157 atomInfo = std::make_shared<AtomInfo>();
158 atomInfo->atomTypeName = "X";
159 atomInfo->pos[0] = pos[0];
160 atomInfo->pos[1] = pos[1];
161 atomInfo->pos[2] = pos[2];
162 atomInfo->vec[0] = 0;
163 atomInfo->vec[1] = 0;
164 atomInfo->vec[2] = 0;
165
166 atomData = std::make_shared<AtomData>();
167 atomData->setID("ATOMDATA");
168 atomData->addAtomInfo(atomInfo);
169
170 rb->addProperty(atomData);
171 }
172
173 const std::string RBCOMVisitor::toString() {
174 char buffer[65535];
175 std::string result;
176
177 snprintf(
178 buffer, 65535,
179 "------------------------------------------------------------------\n");
180 result += buffer;
181
182 snprintf(buffer, 65535, "Visitor name: %s\n", visitorName.c_str());
183 result += buffer;
184
185 // print the ignore type list
186 snprintf(buffer, 65535,
187 "Visitor Description: add a pseudo atom at the center of "
188 "the mass of the "
189 "rigidbody\n");
190 result += buffer;
191
192 snprintf(
193 buffer, 65535,
194 "------------------------------------------------------------------\n");
195 result += buffer;
196
197 return result;
198 }
199
200} // namespace OpenMD
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.