48#include "applications/dynamicProps/RotAngleDisplacement.hpp"
52#include "utils/Revision.hpp"
53#include "utils/simError.h"
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");
64 if (!uniqueSelections_) { seleMan2_ = seleMan1_; }
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);
73 void RotAngleDisplacement::computeFrame(
int frame) {
74 MoleculeACF<Vector3d>::computeFrame(frame);
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;
83 Vector3d RotAngleDisplacement::calcCorrVal(
int frame1,
int frame2,
int id1,
85 RotMat3x3d A1 = rotMats_[frame1][id1];
86 RotMat3x3d A2 = rotMats_[frame2][id2];
88 RotMat3x3d A21 = A1.transpose() * A2;
89 Vector3d rpy = A21.toRPY();
94 void RotAngleDisplacement::correlateFrames(
int frame1,
int frame2,
99 std::vector<int>::iterator i1;
100 std::vector<int>::iterator i2;
102 Vector3d corrVal(0.0);
104 s1 = sele1ToIndex_[frame1];
106 if (uniqueSelections_)
107 s2 = sele2ToIndex_[frame2];
109 s2 = sele1ToIndex_[frame2];
111 for (i1 = s1.begin(), i2 = s2.begin(); i1 != s1.end() && i2 != s2.end();
118 while (i1 != s1.end() && *i1 < *i2) {
122 while (i2 != s2.end() && *i2 < *i1) {
126 if (i1 == s1.end() || i2 == s2.end())
break;
128 corrVal = calcCorrVal(frame1, frame2, i1 - s1.begin(), i2 - s2.begin());
130 histogram_[timeBin] += corrVal;
135 void RotAngleDisplacement::postCorrelate() {
136 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
137 if (counts_[i] > 0) { histogram_[i] /= counts_[i]; }
141 void RotAngleDisplacement::validateSelection(SelectionManager&) {
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;
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;
163 void RotAngleDisplacement::writeCorrelate() {
164 std::string Anglefile = getOutputFileName();
165 std::ofstream ofs1(Anglefile.c_str());
167 if (ofs1.is_open()) {
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";
176 ofs1 <<
"#time\troll\tpitch\tyaw\n";
178 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
179 ofs1 << times_[i] - times_[0];
181 ofs1 <<
"\t" << histogram_[i][0];
182 ofs1 <<
"\t" << histogram_[i][1];
183 ofs1 <<
"\t" << histogram_[i][2] <<
"\n";
188 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
189 "RotAngleDisplacement::writeCorrelate Error: failed to open %s\n",
191 painCave.isFatal = 1;
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
std::string getPrefix(const std::string &str)