48#include "applications/dynamicProps/RCorrFunc.hpp"
52#include "utils/Revision.hpp"
55 RCorrFunc::RCorrFunc(
SimInfo* info,
const std::string& filename,
56 const std::string& sele1,
const std::string& sele2) :
57 ObjectACF<RealType>(info, filename, sele1, sele2) {
58 setCorrFuncType(
"Mean Square Displacement");
59 setOutputName(
getPrefix(dumpFilename_) +
".rcorr");
61 positions_.resize(nFrames_);
64 RCorrFuncZ::RCorrFuncZ(SimInfo* info,
const std::string& filename,
65 const std::string& sele1,
const std::string& sele2,
66 int nZbins,
int axis) :
67 ObjectACF<RealType>(info, filename, sele1, sele2),
69 setCorrFuncType(
"Mean Square Displacement binned by Z");
70 setOutputName(
getPrefix(dumpFilename_) +
".rcorrZ");
72 positions_.resize(nFrames_);
73 zBins_.resize(nFrames_);
89 std::stringstream params;
90 params <<
" nzbins = " << nZBins_;
91 const std::string paramString = params.str();
92 setParameterString(paramString);
94 histograms_.resize(nTimeBins_);
95 counts_.resize(nTimeBins_);
97 idimHistograms_.resize(3);
98 for (
unsigned i = 0; i < idimHistograms_.size(); i++) {
99 idimHistograms_[i].resize(nTimeBins_);
101 for (
unsigned int i = 0; i < nTimeBins_; i++) {
102 histograms_[i].resize(nZBins_);
103 counts_[i].resize(nZBins_);
105 std::fill(histograms_[i].begin(), histograms_[i].end(), 0.0);
106 std::fill(counts_[i].begin(), counts_[i].end(), 0);
108 for (
unsigned j = 0; j < 3; j++) {
109 idimHistograms_[j][i].resize(nZBins_);
110 std::fill(idimHistograms_[j][i].begin(), idimHistograms_[j][i].end(),
116 RCorrFuncR::RCorrFuncR(SimInfo* info,
const std::string& filename,
117 const std::string& sele1,
const std::string& sele2) :
118 ObjectACF<RealType>(info, filename, sele1, sele2) {
121 reader_->setNeedCOMprops(ncp);
122 setCorrFuncType(
"MSD (radial projection)");
123 setOutputName(
getPrefix(dumpFilename_) +
".r_rcorr");
124 positions_.resize(nFrames_);
127 int RCorrFunc::computeProperty1(
int frame, StuntDouble* sd) {
128 positions_[frame].push_back(sd->getPos());
129 return positions_[frame].size() - 1;
132 RealType RCorrFunc::calcCorrVal(
int frame1,
int frame2,
int id1,
int id2) {
133 Vector3d diff = positions_[frame2][id2] - positions_[frame1][id1];
137 void RCorrFuncZ::computeFrame(
int istep) {
138 hmat_ = currentSnapshot_->getHmat();
139 halfBoxZ_ = hmat_(axis_, axis_) / 2.0;
146 if (evaluator1_.isDynamic()) {
147 seleMan1_.setSelectionSet(evaluator1_.evaluate());
150 if (uniqueSelections_ && evaluator2_.isDynamic()) {
151 seleMan2_.setSelectionSet(evaluator2_.evaluate());
154 for (sd = seleMan1_.beginSelected(isd1); sd != NULL;
155 sd = seleMan1_.nextSelected(isd1)) {
156 index = computeProperty1(istep, sd);
157 if (index == sele1ToIndex_[istep].size()) {
158 sele1ToIndex_[istep].push_back(sd->getGlobalIndex());
160 sele1ToIndex_[istep].resize(index + 1);
161 sele1ToIndex_[istep][index] = sd->getGlobalIndex();
165 if (uniqueSelections_) {
166 for (sd = seleMan2_.beginSelected(isd2); sd != NULL;
167 sd = seleMan2_.nextSelected(isd2)) {
168 index = computeProperty1(istep, sd);
170 if (index == sele2ToIndex_[istep].size()) {
171 sele2ToIndex_[istep].push_back(sd->getGlobalIndex());
173 sele2ToIndex_[istep].resize(index + 1);
174 sele2ToIndex_[istep][index] = sd->getGlobalIndex();
180 int RCorrFuncZ::computeProperty1(
int frame, StuntDouble* sd) {
181 Vector3d pos = sd->getPos();
183 positions_[frame].push_back(sd->getPos());
185 if (info_->getSimParams()->getUsePeriodicBoundaryConditions()) {
186 currentSnapshot_->wrapVector(pos);
188 int zBin = int(nZBins_ * (halfBoxZ_ + pos[axis_]) / hmat_(axis_, axis_));
189 zBins_[frame].push_back(zBin);
191 return positions_[frame].size() - 1;
194 void RCorrFuncZ::correlateFrames(
int frame1,
int frame2,
int timeBin) {
198 std::vector<int>::iterator i1;
199 std::vector<int>::iterator i2;
201 s1 = sele1ToIndex_[frame1];
203 if (uniqueSelections_)
204 s2 = sele2ToIndex_[frame2];
206 s2 = sele1ToIndex_[frame2];
208 for (i1 = s1.begin(), i2 = s2.begin(); i1 != s1.end() && i2 != s2.end();
215 while (i1 != s1.end() && *i1 < *i2) {
219 while (i2 != s2.end() && *i2 < *i1) {
223 if (i1 == s1.end() || i2 == s2.end())
break;
225 calcCorrValImpl(frame1, frame2, i1 - s1.begin(), i2 - s2.begin(),
230 RealType RCorrFuncZ::calcCorrValImpl(
int frame1,
int frame2,
int id1,
int id2,
232 int zBin1 = zBins_[frame1][id1];
233 int zBin2 = zBins_[frame2][id2];
235 if (zBin1 == zBin2) {
236 Vector3d diff = positions_[frame2][id2] - positions_[frame1][id1];
239 for (
unsigned i = 0; i < 3; i++) {
241 positions_[frame2][id2][i] - positions_[frame1][id1][i];
242 idimHistograms_[i][timeBin][zBin1] += (iDiff * iDiff);
245 counts_[timeBin][zBin1]++;
250 void RCorrFuncZ::postCorrelate() {
251 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
252 for (
unsigned int j = 0; j < nZBins_; ++j) {
253 if (counts_[i][j] > 0) {
254 histograms_[i][j] /= counts_[i][j];
255 for (
unsigned int k = 0; k < 3; k++) {
256 idimHistograms_[k][i][j] /= counts_[i][j];
259 histograms_[i][j] = 0;
260 for (
unsigned int k = 0; k < 3; k++) {
261 idimHistograms_[k][i][j] = 0;
267 void RCorrFuncZ::writeCorrelate() {
268 std::ofstream ofs(getOutputFileName().c_str());
273 ofs <<
"# " << getCorrFuncType() <<
"\n";
274 ofs <<
"# OpenMD " << r.getFullRevision() <<
"\n";
275 ofs <<
"# " << r.getBuildDate() <<
"\n";
276 ofs <<
"# selection script1: \"" << selectionScript1_;
277 ofs <<
"\"\tselection script2: \"" << selectionScript2_ <<
"\"\n";
278 ofs <<
"# privilegedAxis computed as " << axisLabel_ <<
" axis \n";
279 if (!paramString_.empty())
280 ofs <<
"# parameters: " << paramString_ <<
"\n";
282 ofs <<
"#time\tcorrVal\n";
284 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
285 ofs << times_[i] - times_[0];
287 for (
unsigned int j = 0; j < nZBins_; ++j) {
288 ofs <<
"\t" << histograms_[i][j];
293 ofs <<
"&\n#time\tcorrValXZ\n";
295 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
296 ofs << times_[i] - times_[0];
298 for (
unsigned int j = 0; j < nZBins_; ++j) {
299 ofs <<
"\t" << idimHistograms_[0][i][j];
304 ofs <<
"&\n#time\tcorrValYZ\n";
306 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
307 ofs << times_[i] - times_[0];
309 for (
unsigned int j = 0; j < nZBins_; ++j) {
310 ofs <<
"\t" << idimHistograms_[1][i][j];
315 ofs <<
"&\n#time\tcorrValZZ\n";
317 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
318 ofs << times_[i] - times_[0];
320 for (
unsigned int j = 0; j < nZBins_; ++j) {
321 ofs <<
"\t" << idimHistograms_[2][i][j];
327 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
328 "RCorrFuncZ::writeCorrelate Error: fail to open %s\n",
329 getOutputFileName().c_str());
330 painCave.isFatal = 1;
336 int RCorrFuncR::computeProperty1(
int frame, StuntDouble* sd) {
338 Vector3d coord_t = sd->getPos() - sd->getCOM();
340 positions_[frame].push_back(coord_t.length());
341 return positions_[frame].size() - 1;
344 RealType RCorrFuncR::calcCorrVal(
int frame1,
int frame2,
int id1,
int id2) {
346 dr = positions_[frame2][id2] - positions_[frame1][id1];
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Real lengthSquare() const
Returns the squared length of this vector.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
std::string getPrefix(const std::string &str)