45#include "applications/dynamicProps/RCorrFunc.hpp"
49#include "utils/Revision.hpp"
52 RCorrFunc::RCorrFunc(SimInfo* info,
const std::string& filename,
53 const std::string& sele1,
const std::string& sele2) :
54 ObjectACF<RealType>(info, filename, sele1, sele2) {
55 setCorrFuncType(
"Mean Square Displacement");
56 setOutputName(
getPrefix(dumpFilename_) +
".rcorr");
58 positions_.resize(nFrames_);
61 RCorrFuncZ::RCorrFuncZ(SimInfo* info,
const std::string& filename,
62 const std::string& sele1,
const std::string& sele2,
63 int nZbins,
int axis) :
64 ObjectACF<RealType>(info, filename, sele1, sele2),
66 setCorrFuncType(
"Mean Square Displacement binned by Z");
67 setOutputName(
getPrefix(dumpFilename_) +
".rcorrZ");
69 positions_.resize(nFrames_);
70 zBins_.resize(nFrames_);
86 std::stringstream params;
87 params <<
" nzbins = " << nZBins_;
88 const std::string paramString = params.str();
89 setParameterString(paramString);
91 histograms_.resize(nTimeBins_);
92 counts_.resize(nTimeBins_);
94 idimHistograms_.resize(3);
95 for (
unsigned i = 0; i < idimHistograms_.size(); i++) {
96 idimHistograms_[i].resize(nTimeBins_);
98 for (
unsigned int i = 0; i < nTimeBins_; i++) {
99 histograms_[i].resize(nZBins_);
100 counts_[i].resize(nZBins_);
102 std::fill(histograms_[i].begin(), histograms_[i].end(), 0.0);
103 std::fill(counts_[i].begin(), counts_[i].end(), 0);
105 for (
unsigned j = 0; j < 3; j++) {
106 idimHistograms_[j][i].resize(nZBins_);
107 std::fill(idimHistograms_[j][i].begin(), idimHistograms_[j][i].end(),
113 RCorrFuncR::RCorrFuncR(SimInfo* info,
const std::string& filename,
114 const std::string& sele1,
const std::string& sele2) :
115 ObjectACF<RealType>(info, filename, sele1, sele2) {
118 reader_->setNeedCOMprops(ncp);
119 setCorrFuncType(
"MSD (radial projection)");
120 setOutputName(
getPrefix(dumpFilename_) +
".r_rcorr");
121 positions_.resize(nFrames_);
124 int RCorrFunc::computeProperty1(
int frame, StuntDouble* sd) {
125 positions_[frame].push_back(sd->getPos());
126 return positions_[frame].size() - 1;
129 RealType RCorrFunc::calcCorrVal(
int frame1,
int frame2,
int id1,
int id2) {
130 Vector3d diff = positions_[frame2][id2] - positions_[frame1][id1];
134 void RCorrFuncZ::computeFrame(
int istep) {
135 hmat_ = currentSnapshot_->getHmat();
136 halfBoxZ_ = hmat_(axis_, axis_) / 2.0;
143 if (evaluator1_.isDynamic()) {
144 seleMan1_.setSelectionSet(evaluator1_.evaluate());
147 if (uniqueSelections_ && evaluator2_.isDynamic()) {
148 seleMan2_.setSelectionSet(evaluator2_.evaluate());
151 for (sd = seleMan1_.beginSelected(isd1); sd != NULL;
152 sd = seleMan1_.nextSelected(isd1)) {
153 index = computeProperty1(istep, sd);
154 if (index == sele1ToIndex_[istep].size()) {
155 sele1ToIndex_[istep].push_back(sd->getGlobalIndex());
157 sele1ToIndex_[istep].resize(index + 1);
158 sele1ToIndex_[istep][index] = sd->getGlobalIndex();
162 if (uniqueSelections_) {
163 for (sd = seleMan2_.beginSelected(isd2); sd != NULL;
164 sd = seleMan2_.nextSelected(isd2)) {
165 index = computeProperty1(istep, sd);
167 if (index == sele2ToIndex_[istep].size()) {
168 sele2ToIndex_[istep].push_back(sd->getGlobalIndex());
170 sele2ToIndex_[istep].resize(index + 1);
171 sele2ToIndex_[istep][index] = sd->getGlobalIndex();
177 int RCorrFuncZ::computeProperty1(
int frame, StuntDouble* sd) {
178 Vector3d pos = sd->getPos();
180 positions_[frame].push_back(sd->getPos());
182 if (info_->getSimParams()->getUsePeriodicBoundaryConditions()) {
183 currentSnapshot_->wrapVector(pos);
185 int zBin = int(nZBins_ * (halfBoxZ_ + pos[axis_]) / hmat_(axis_, axis_));
186 zBins_[frame].push_back(zBin);
188 return positions_[frame].size() - 1;
191 void RCorrFuncZ::correlateFrames(
int frame1,
int frame2,
int timeBin) {
195 std::vector<int>::iterator i1;
196 std::vector<int>::iterator i2;
198 s1 = sele1ToIndex_[frame1];
200 if (uniqueSelections_)
201 s2 = sele2ToIndex_[frame2];
203 s2 = sele1ToIndex_[frame2];
205 for (i1 = s1.begin(), i2 = s2.begin(); i1 != s1.end() && i2 != s2.end();
212 while (i1 != s1.end() && *i1 < *i2) {
216 while (i2 != s2.end() && *i2 < *i1) {
220 if (i1 == s1.end() || i2 == s2.end())
break;
222 calcCorrValImpl(frame1, frame2, i1 - s1.begin(), i2 - s2.begin(),
227 RealType RCorrFuncZ::calcCorrValImpl(
int frame1,
int frame2,
int id1,
int id2,
229 int zBin1 = zBins_[frame1][id1];
230 int zBin2 = zBins_[frame2][id2];
232 if (zBin1 == zBin2) {
233 Vector3d diff = positions_[frame2][id2] - positions_[frame1][id1];
236 for (
unsigned i = 0; i < 3; i++) {
238 positions_[frame2][id2][i] - positions_[frame1][id1][i];
239 idimHistograms_[i][timeBin][zBin1] += (iDiff * iDiff);
242 counts_[timeBin][zBin1]++;
247 void RCorrFuncZ::postCorrelate() {
248 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
249 for (
unsigned int j = 0; j < nZBins_; ++j) {
250 if (counts_[i][j] > 0) {
251 histograms_[i][j] /= counts_[i][j];
252 for (
unsigned int k = 0; k < 3; k++) {
253 idimHistograms_[k][i][j] /= counts_[i][j];
256 histograms_[i][j] = 0;
257 for (
unsigned int k = 0; k < 3; k++) {
258 idimHistograms_[k][i][j] = 0;
264 void RCorrFuncZ::writeCorrelate() {
265 std::ofstream ofs(getOutputFileName().c_str());
270 ofs <<
"# " << getCorrFuncType() <<
"\n";
271 ofs <<
"# OpenMD " << r.getFullRevision() <<
"\n";
272 ofs <<
"# " << r.getBuildDate() <<
"\n";
273 ofs <<
"# selection script1: \"" << selectionScript1_;
274 ofs <<
"\"\tselection script2: \"" << selectionScript2_ <<
"\"\n";
275 ofs <<
"# privilegedAxis computed as " << axisLabel_ <<
" axis \n";
276 if (!paramString_.empty())
277 ofs <<
"# parameters: " << paramString_ <<
"\n";
279 ofs <<
"#time\tcorrVal\n";
281 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
282 ofs << times_[i] - times_[0];
284 for (
unsigned int j = 0; j < nZBins_; ++j) {
285 ofs <<
"\t" << histograms_[i][j];
290 ofs <<
"&\n#time\tcorrValXZ\n";
292 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
293 ofs << times_[i] - times_[0];
295 for (
unsigned int j = 0; j < nZBins_; ++j) {
296 ofs <<
"\t" << idimHistograms_[0][i][j];
301 ofs <<
"&\n#time\tcorrValYZ\n";
303 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
304 ofs << times_[i] - times_[0];
306 for (
unsigned int j = 0; j < nZBins_; ++j) {
307 ofs <<
"\t" << idimHistograms_[1][i][j];
312 ofs <<
"&\n#time\tcorrValZZ\n";
314 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
315 ofs << times_[i] - times_[0];
317 for (
unsigned int j = 0; j < nZBins_; ++j) {
318 ofs <<
"\t" << idimHistograms_[2][i][j];
324 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
325 "RCorrFuncZ::writeCorrelate Error: fail to open %s\n",
326 getOutputFileName().c_str());
327 painCave.isFatal = 1;
333 int RCorrFuncR::computeProperty1(
int frame, StuntDouble* sd) {
335 Vector3d coord_t = sd->getPos() - sd->getCOM();
337 positions_[frame].push_back(coord_t.length());
338 return positions_[frame].size() - 1;
341 RealType RCorrFuncR::calcCorrVal(
int frame1,
int frame2,
int id1,
int id2) {
343 dr = positions_[frame2][id2] - positions_[frame1][id1];
Real lengthSquare()
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)