48#include "applications/dynamicProps/Displacement.hpp"
52#include "utils/Revision.hpp"
55 Displacement::Displacement(
SimInfo* info,
const std::string& filename,
56 const std::string& sele1,
57 const std::string& sele2) :
58 ObjectACF<Vector3d>(info, filename, sele1, sele2) {
59 setCorrFuncType(
"Displacement");
60 setOutputName(
getPrefix(dumpFilename_) +
".disp");
62 positions_.resize(nFrames_);
65 DisplacementZ::DisplacementZ(SimInfo* info,
const std::string& filename,
66 const std::string& sele1,
67 const std::string& sele2,
int nZbins,
int axis) :
68 ObjectACF<Vector3d>(info, filename, sele1, sele2) {
69 setCorrFuncType(
"Displacement binned by Z");
70 setOutputName(
getPrefix(dumpFilename_) +
".dispZ");
72 positions_.resize(nFrames_);
73 zBins_.resize(nFrames_);
90 std::stringstream params;
91 params <<
" nzbins = " << nZBins_;
92 const std::string paramString = params.str();
93 setParameterString(paramString);
95 histograms_.resize(nTimeBins_);
96 counts_.resize(nTimeBins_);
97 for (
unsigned int i = 0; i < nTimeBins_; i++) {
98 histograms_[i].resize(nZBins_);
99 counts_[i].resize(nZBins_);
100 std::fill(histograms_[i].begin(), histograms_[i].end(), Vector3d(0.0));
101 std::fill(counts_[i].begin(), counts_[i].end(), 0);
105 int Displacement::computeProperty1(
int frame, StuntDouble* sd) {
106 positions_[frame].push_back(sd->getPos());
107 return positions_[frame].size() - 1;
110 Vector3d Displacement::calcCorrVal(
int frame1,
int frame2,
int id1,
int id2) {
111 return positions_[frame2][id2] - positions_[frame1][id1];
114 void DisplacementZ::computeFrame(
int istep) {
115 hmat_ = currentSnapshot_->getHmat();
116 halfBoxZ_ = hmat_(axis_, axis_) / 2.0;
123 if (evaluator1_.isDynamic()) {
124 seleMan1_.setSelectionSet(evaluator1_.evaluate());
127 if (uniqueSelections_ && evaluator2_.isDynamic()) {
128 seleMan2_.setSelectionSet(evaluator2_.evaluate());
131 for (sd = seleMan1_.beginSelected(isd1); sd != NULL;
132 sd = seleMan1_.nextSelected(isd1)) {
133 index = computeProperty1(istep, sd);
134 if (index == sele1ToIndex_[istep].size()) {
135 sele1ToIndex_[istep].push_back(sd->getGlobalIndex());
137 sele1ToIndex_[istep].resize(index + 1);
138 sele1ToIndex_[istep][index] = sd->getGlobalIndex();
142 if (uniqueSelections_) {
143 for (sd = seleMan2_.beginSelected(isd2); sd != NULL;
144 sd = seleMan2_.nextSelected(isd2)) {
145 index = computeProperty1(istep, sd);
147 if (index == sele2ToIndex_[istep].size()) {
148 sele2ToIndex_[istep].push_back(sd->getGlobalIndex());
150 sele2ToIndex_[istep].resize(index + 1);
151 sele2ToIndex_[istep][index] = sd->getGlobalIndex();
157 int DisplacementZ::computeProperty1(
int frame, StuntDouble* sd) {
158 Vector3d pos = sd->getPos();
160 positions_[frame].push_back(sd->getPos());
162 if (info_->getSimParams()->getUsePeriodicBoundaryConditions()) {
163 currentSnapshot_->wrapVector(pos);
165 int zBin = int(nZBins_ * (halfBoxZ_ + pos[axis_]) / hmat_(axis_, axis_));
166 zBins_[frame].push_back(zBin);
168 return positions_[frame].size() - 1;
171 void DisplacementZ::correlateFrames(
int frame1,
int frame2,
int timeBin) {
175 std::vector<int>::iterator i1;
176 std::vector<int>::iterator i2;
178 s1 = sele1ToIndex_[frame1];
180 if (uniqueSelections_)
181 s2 = sele2ToIndex_[frame2];
183 s2 = sele1ToIndex_[frame2];
185 for (i1 = s1.begin(), i2 = s2.begin(); i1 != s1.end() && i2 != s2.end();
192 while (i1 != s1.end() && *i1 < *i2) {
196 while (i2 != s2.end() && *i2 < *i1) {
200 if (i1 == s1.end() || i2 == s2.end())
break;
202 calcCorrValImpl(frame1, frame2, i1 - s1.begin(), i2 - s2.begin(),
207 Vector3d DisplacementZ::calcCorrValImpl(
int frame1,
int frame2,
int id1,
208 int id2,
int timeBin) {
209 int zBin1 = zBins_[frame1][id1];
210 int zBin2 = zBins_[frame2][id2];
212 if (zBin1 == zBin2) {
213 Vector3d diff = positions_[frame2][id2] - positions_[frame1][id1];
214 histograms_[timeBin][zBin1] += diff;
215 counts_[timeBin][zBin1]++;
217 return Vector3d(0.0);
220 void DisplacementZ::postCorrelate() {
221 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
222 for (
unsigned int j = 0; j < nZBins_; ++j) {
223 if (counts_[i][j] > 0) {
224 histograms_[i][j] /= counts_[i][j];
226 histograms_[i][j] = Vector3d(0.0);
231 void DisplacementZ::writeCorrelate() {
232 std::ofstream ofs(getOutputFileName().c_str());
237 ofs <<
"# " << getCorrFuncType() <<
"\n";
238 ofs <<
"# OpenMD " << r.getFullRevision() <<
"\n";
239 ofs <<
"# " << r.getBuildDate() <<
"\n";
240 ofs <<
"# selection script1: \"" << selectionScript1_;
241 ofs <<
"\"\tselection script2: \"" << selectionScript2_ <<
"\"\n";
242 ofs <<
"# privilegedAxis computed as " << axisLabel_ <<
" axis \n";
243 if (!paramString_.empty())
244 ofs <<
"# parameters: " << paramString_ <<
"\n";
246 ofs <<
"#time\tcorrVal\n";
248 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
249 ofs << times_[i] - times_[0] <<
"\t";
251 for (
unsigned int j = 0; j < nZBins_; ++j) {
252 for (
int k = 0; k < 3; k++) {
253 ofs << histograms_[i][j](k) <<
'\t';
261 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
262 "DisplacementZ::writeCorrelate Error: fail to open %s\n",
263 getOutputFileName().c_str());
264 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)