OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
RotAngleDisplacement.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 "applications/dynamicProps/RotAngleDisplacement.hpp"
49
50#include <sstream>
51
52#include "utils/Revision.hpp"
53#include "utils/simError.h"
54
55namespace OpenMD {
56 RotAngleDisplacement::RotAngleDisplacement(SimInfo* info,
57 const std::string& filename,
58 const std::string& sele1,
59 const std::string& sele2) :
60 MoleculeACF<Vector3d>(info, filename, sele1, sele2) {
61 setCorrFuncType("Rotational Angle Displacement Function");
62 setOutputName(getPrefix(dumpFilename_) + ".rotAngDisp");
63
64 if (!uniqueSelections_) { seleMan2_ = seleMan1_; }
65
66 rotMats_.resize(nTimeBins_);
67 histogram_.resize(nTimeBins_);
68 counts_.resize(nTimeBins_);
69 std::fill(histogram_.begin(), histogram_.end(), 0.0);
70 std::fill(counts_.begin(), counts_.end(), 0);
71 }
72
73 void RotAngleDisplacement::computeFrame(int frame) {
74 MoleculeACF<Vector3d>::computeFrame(frame);
75 }
76
77 int RotAngleDisplacement::computeProperty1(int frame, Molecule* mol) {
78 RotMat3x3d A = mol->getRigidBodyAt(0)->getA();
79 rotMats_[frame].push_back(A);
80 return rotMats_[frame].size() - 1;
81 }
82
83 Vector3d RotAngleDisplacement::calcCorrVal(int frame1, int frame2, int id1,
84 int id2) {
85 RotMat3x3d A1 = rotMats_[frame1][id1];
86 RotMat3x3d A2 = rotMats_[frame2][id2];
87
88 RotMat3x3d A21 = A1.transpose() * A2;
89 Vector3d rpy = A21.toRPY();
90
91 return rpy;
92 }
93
94 void RotAngleDisplacement::correlateFrames(int frame1, int frame2,
95 int timeBin) {
96 std::vector<int> s1;
97 std::vector<int> s2;
98
99 std::vector<int>::iterator i1;
100 std::vector<int>::iterator i2;
101
102 Vector3d corrVal(0.0);
103
104 s1 = sele1ToIndex_[frame1];
105
106 if (uniqueSelections_)
107 s2 = sele2ToIndex_[frame2];
108 else
109 s2 = sele1ToIndex_[frame2];
110
111 for (i1 = s1.begin(), i2 = s2.begin(); i1 != s1.end() && i2 != s2.end();
112 ++i1, ++i2) {
113 // If the selections are dynamic, they might not have the
114 // same objects in both frames, so we need to roll either of
115 // the selections until we have the same object to
116 // correlate.
117
118 while (i1 != s1.end() && *i1 < *i2) {
119 ++i1;
120 }
121
122 while (i2 != s2.end() && *i2 < *i1) {
123 ++i2;
124 }
125
126 if (i1 == s1.end() || i2 == s2.end()) break;
127
128 corrVal = calcCorrVal(frame1, frame2, i1 - s1.begin(), i2 - s2.begin());
129
130 histogram_[timeBin] += corrVal;
131 counts_[timeBin]++;
132 }
133 }
134
135 void RotAngleDisplacement::postCorrelate() {
136 for (unsigned int i = 0; i < nTimeBins_; ++i) {
137 if (counts_[i] > 0) { histogram_[i] /= counts_[i]; }
138 }
139 }
140
141 void RotAngleDisplacement::validateSelection(SelectionManager&) {
142 Molecule* mol;
143 int i;
144 for (mol = seleMan1_.beginSelectedMolecule(i); mol != NULL;
145 mol = seleMan1_.nextSelectedMolecule(i)) {
146 if (mol->getNRigidBodies() < 1) {
147 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
148 "RotAngleDisplacement::validateSelection Error: "
149 "at least one selected molecule does not have a rigid body\n");
150 painCave.isFatal = 1;
151 simError();
152 }
153 }
154 if (seleMan1_.getMoleculeSelectionCount() < 1) {
155 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
156 "RotAngleDisplacement::validateSelection Error: "
157 "There needs to be at least one selected molecule.\n");
158 painCave.isFatal = 1;
159 simError();
160 }
161 }
162
163 void RotAngleDisplacement::writeCorrelate() {
164 std::string Anglefile = getOutputFileName();
165 std::ofstream ofs1(Anglefile.c_str());
166
167 if (ofs1.is_open()) {
168 Revision r;
169
170 ofs1 << "# " << getCorrFuncType() << "\n";
171 ofs1 << "# OpenMD " << r.getFullRevision() << "\n";
172 ofs1 << "# " << r.getBuildDate() << "\n";
173 ofs1 << "# selection script1: \"" << selectionScript1_;
174 ofs1 << "\"\tselection script2: \"" << selectionScript2_ << "\"\n";
175
176 ofs1 << "#time\troll\tpitch\tyaw\n";
177
178 for (unsigned int i = 0; i < nTimeBins_; ++i) {
179 ofs1 << times_[i] - times_[0];
180
181 ofs1 << "\t" << histogram_[i][0];
182 ofs1 << "\t" << histogram_[i][1];
183 ofs1 << "\t" << histogram_[i][2] << "\n";
184 }
185
186 } else {
187 snprintf(
188 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
189 "RotAngleDisplacement::writeCorrelate Error: failed to open %s\n",
190 Anglefile.c_str());
191 painCave.isFatal = 1;
192 simError();
193 }
194 ofs1.close();
195 }
196} // 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.
std::string getPrefix(const std::string &str)