OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
LipidTransVisitor.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/LipidTransVisitor.hpp"
49
50#include <memory>
51
52#include "types/MultipoleAdapter.hpp"
53#include "utils/simError.h"
54
55namespace OpenMD {
56 LipidTransVisitor::LipidTransVisitor(SimInfo* info,
57 const std::string& originSeleScript,
58 const std::string& refSeleScript) :
60 info_(info), originEvaluator_(info), originSeleMan_(info),
61 refEvaluator_(info), refSeleMan_(info), refSd_(NULL) {
62 visitorName = "LipidTransVisitor";
63
64 originEvaluator_.loadScriptString(originSeleScript);
65 if (!originEvaluator_.isDynamic()) {
66 originSeleMan_.setSelectionSet(originEvaluator_.evaluate());
67 if (originSeleMan_.getSelectionCount() == 1) {
68 int i;
69 originDatom_ =
70 dynamic_cast<DirectionalAtom*>(originSeleMan_.beginSelected(i));
71 if (originDatom_ == NULL) {
72 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
73 "LipidTransVisitor: origin selection must select an "
74 "directional atom");
75 painCave.isFatal = 1;
76 simError();
77 }
78 } else {
79 snprintf(
80 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
81 "LipidTransVisitor: origin selection must select an directional "
82 "atom");
83 painCave.isFatal = 1;
84 simError();
85 }
86 }
87
88 refEvaluator_.loadScriptString(refSeleScript);
89 if (!refEvaluator_.isDynamic()) {
90 refSeleMan_.setSelectionSet(refEvaluator_.evaluate());
91 if (refSeleMan_.getSelectionCount() == 1) {
92 int i;
93 refSd_ = refSeleMan_.beginSelected(i);
94
95 } else {
96 // error
97 }
98 }
99 }
100
101 void LipidTransVisitor::update() {
102 Vector3d ref = refSd_->getPos();
103 origin_ = originDatom_->getPos();
104 Vector3d v1 = ref - origin_;
105 info_->getSnapshotManager()->getCurrentSnapshot()->wrapVector(v1);
106
107 MultipoleAdapter ma = MultipoleAdapter(originDatom_->getAtomType());
108 Vector3d zaxis;
109 if (ma.isDipole()) {
110 zaxis = originDatom_->getDipole();
111 } else {
112 zaxis = originDatom_->getA().transpose() * V3Z;
113 }
114
115 Vector3d xaxis = cross(v1, zaxis);
116 Vector3d yaxis = cross(zaxis, xaxis);
117
118 xaxis.normalize();
119 yaxis.normalize();
120 zaxis.normalize();
121
122 rotMat_.setRow(0, xaxis);
123 rotMat_.setRow(1, yaxis);
124 rotMat_.setRow(2, zaxis);
125 }
126
127 void LipidTransVisitor::internalVisit(StuntDouble* sd) {
128 std::shared_ptr<GenericData> data;
129 std::shared_ptr<AtomData> atomData;
130 std::shared_ptr<AtomInfo> atomInfo;
131 std::vector<std::shared_ptr<AtomInfo>>::iterator i;
132
133 data = sd->getPropertyByName("ATOMDATA");
134
135 if (data != nullptr) {
136 atomData = std::dynamic_pointer_cast<AtomData>(data);
137
138 if (atomData == nullptr) return;
139 } else
140 return;
141
142 Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
143
144 for (atomInfo = atomData->beginAtomInfo(i); atomInfo;
145 atomInfo = atomData->nextAtomInfo(i)) {
146 Vector3d tmp = atomInfo->pos - origin_;
147 currSnapshot->wrapVector(tmp);
148 atomInfo->pos = rotMat_ * tmp;
149 ;
150 atomInfo->vec = rotMat_ * atomInfo->vec;
151 }
152 }
153
154 const std::string LipidTransVisitor::toString() {
155 char buffer[65535];
156 std::string result;
157
158 snprintf(
159 buffer, 65535,
160 "------------------------------------------------------------------\n");
161 result += buffer;
162
163 snprintf(buffer, 65535, "Visitor name: %s\n", visitorName.c_str());
164 result += buffer;
165
166 snprintf(buffer, 65535, "Visitor Description: rotate the whole system\n");
167 result += buffer;
168
169 snprintf(
170 buffer, 65535,
171 "------------------------------------------------------------------\n");
172 result += buffer;
173
174 return result;
175 }
176
177} // 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.
Vector3< Real > cross(const Vector3< Real > &v1, const Vector3< Real > &v2)
Returns the cross product of two Vectors.
Definition Vector3.hpp:139