45#include "applications/dynamicProps/Displacement.hpp"
49#include "utils/Revision.hpp"
52 Displacement::Displacement(SimInfo* info,
const std::string& filename,
53 const std::string& sele1,
54 const std::string& sele2) :
55 ObjectACF<Vector3d>(info, filename, sele1, sele2) {
56 setCorrFuncType(
"Displacement");
57 setOutputName(
getPrefix(dumpFilename_) +
".disp");
59 positions_.resize(nFrames_);
62 DisplacementZ::DisplacementZ(SimInfo* info,
const std::string& filename,
63 const std::string& sele1,
64 const std::string& sele2,
int nZbins,
int axis) :
65 ObjectACF<Vector3d>(info, filename, sele1, sele2) {
66 setCorrFuncType(
"Displacement binned by Z");
67 setOutputName(
getPrefix(dumpFilename_) +
".dispZ");
69 positions_.resize(nFrames_);
70 zBins_.resize(nFrames_);
87 std::stringstream params;
88 params <<
" nzbins = " << nZBins_;
89 const std::string paramString = params.str();
90 setParameterString(paramString);
92 histograms_.resize(nTimeBins_);
93 counts_.resize(nTimeBins_);
94 for (
unsigned int i = 0; i < nTimeBins_; i++) {
95 histograms_[i].resize(nZBins_);
96 counts_[i].resize(nZBins_);
97 std::fill(histograms_[i].begin(), histograms_[i].end(), Vector3d(0.0));
98 std::fill(counts_[i].begin(), counts_[i].end(), 0);
102 int Displacement::computeProperty1(
int frame, StuntDouble* sd) {
103 positions_[frame].push_back(sd->getPos());
104 return positions_[frame].size() - 1;
107 Vector3d Displacement::calcCorrVal(
int frame1,
int frame2,
int id1,
int id2) {
108 return positions_[frame2][id2] - positions_[frame1][id1];
111 void DisplacementZ::computeFrame(
int istep) {
112 hmat_ = currentSnapshot_->getHmat();
113 halfBoxZ_ = hmat_(axis_, axis_) / 2.0;
120 if (evaluator1_.isDynamic()) {
121 seleMan1_.setSelectionSet(evaluator1_.evaluate());
124 if (uniqueSelections_ && evaluator2_.isDynamic()) {
125 seleMan2_.setSelectionSet(evaluator2_.evaluate());
128 for (sd = seleMan1_.beginSelected(isd1); sd != NULL;
129 sd = seleMan1_.nextSelected(isd1)) {
130 index = computeProperty1(istep, sd);
131 if (index == sele1ToIndex_[istep].size()) {
132 sele1ToIndex_[istep].push_back(sd->getGlobalIndex());
134 sele1ToIndex_[istep].resize(index + 1);
135 sele1ToIndex_[istep][index] = sd->getGlobalIndex();
139 if (uniqueSelections_) {
140 for (sd = seleMan2_.beginSelected(isd2); sd != NULL;
141 sd = seleMan2_.nextSelected(isd2)) {
142 index = computeProperty1(istep, sd);
144 if (index == sele2ToIndex_[istep].size()) {
145 sele2ToIndex_[istep].push_back(sd->getGlobalIndex());
147 sele2ToIndex_[istep].resize(index + 1);
148 sele2ToIndex_[istep][index] = sd->getGlobalIndex();
154 int DisplacementZ::computeProperty1(
int frame, StuntDouble* sd) {
155 Vector3d pos = sd->getPos();
157 positions_[frame].push_back(sd->getPos());
159 if (info_->getSimParams()->getUsePeriodicBoundaryConditions()) {
160 currentSnapshot_->wrapVector(pos);
162 int zBin = int(nZBins_ * (halfBoxZ_ + pos[axis_]) / hmat_(axis_, axis_));
163 zBins_[frame].push_back(zBin);
165 return positions_[frame].size() - 1;
168 void DisplacementZ::correlateFrames(
int frame1,
int frame2,
int timeBin) {
172 std::vector<int>::iterator i1;
173 std::vector<int>::iterator i2;
175 s1 = sele1ToIndex_[frame1];
177 if (uniqueSelections_)
178 s2 = sele2ToIndex_[frame2];
180 s2 = sele1ToIndex_[frame2];
182 for (i1 = s1.begin(), i2 = s2.begin(); i1 != s1.end() && i2 != s2.end();
189 while (i1 != s1.end() && *i1 < *i2) {
193 while (i2 != s2.end() && *i2 < *i1) {
197 if (i1 == s1.end() || i2 == s2.end())
break;
199 calcCorrValImpl(frame1, frame2, i1 - s1.begin(), i2 - s2.begin(),
204 Vector3d DisplacementZ::calcCorrValImpl(
int frame1,
int frame2,
int id1,
205 int id2,
int timeBin) {
206 int zBin1 = zBins_[frame1][id1];
207 int zBin2 = zBins_[frame2][id2];
209 if (zBin1 == zBin2) {
210 Vector3d diff = positions_[frame2][id2] - positions_[frame1][id1];
211 histograms_[timeBin][zBin1] += diff;
212 counts_[timeBin][zBin1]++;
214 return Vector3d(0.0);
217 void DisplacementZ::postCorrelate() {
218 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
219 for (
unsigned int j = 0; j < nZBins_; ++j) {
220 if (counts_[i][j] > 0) {
221 histograms_[i][j] /= counts_[i][j];
223 histograms_[i][j] = Vector3d(0.0);
228 void DisplacementZ::writeCorrelate() {
229 std::ofstream ofs(getOutputFileName().c_str());
234 ofs <<
"# " << getCorrFuncType() <<
"\n";
235 ofs <<
"# OpenMD " << r.getFullRevision() <<
"\n";
236 ofs <<
"# " << r.getBuildDate() <<
"\n";
237 ofs <<
"# selection script1: \"" << selectionScript1_;
238 ofs <<
"\"\tselection script2: \"" << selectionScript2_ <<
"\"\n";
239 ofs <<
"# privilegedAxis computed as " << axisLabel_ <<
" axis \n";
240 if (!paramString_.empty())
241 ofs <<
"# parameters: " << paramString_ <<
"\n";
243 ofs <<
"#time\tcorrVal\n";
245 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
246 ofs << times_[i] - times_[0] <<
"\t";
248 for (
unsigned int j = 0; j < nZBins_; ++j) {
249 for (
int k = 0; k < 3; k++) {
250 ofs << histograms_[i][j](k) <<
'\t';
258 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
259 "DisplacementZ::writeCorrelate Error: fail to open %s\n",
260 getOutputFileName().c_str());
261 painCave.isFatal = 1;
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
std::string getPrefix(const std::string &str)