50#include "applications/staticProps/P2R.hpp"
57#include "brains/Thermo.hpp"
60#include "utils/Revision.hpp"
61#include "utils/simError.h"
65 P2R::P2R(
SimInfo* info,
const std::string& filename,
const std::string& sele1,
68 doVect_(true), doOffset_(false), selectionScript1_(sele1),
69 seleMan1_(info), seleMan2_(info), evaluator1_(info), evaluator2_(info) {
70 evaluator1_.loadScriptString(sele1);
71 if (!evaluator1_.isDynamic()) {
72 seleMan1_.setSelectionSet(evaluator1_.evaluate());
76 "2nd order Legendre Polynomial Correlation using r as reference axis");
77 setOutputName(
getPrefix(filename) +
".P2R");
78 std::stringstream params;
79 const std::string paramString = params.str();
80 setParameterString(paramString);
83 P2R::P2R(SimInfo* info,
const std::string& filename,
const std::string& sele1,
84 const std::string& sele2,
unsigned int nbins) :
85 StaticAnalyser(info, filename, nbins),
86 doVect_(false), doOffset_(false), selectionScript1_(sele1),
87 selectionScript2_(sele2), seleMan1_(info), seleMan2_(info),
88 evaluator1_(info), evaluator2_(info) {
89 evaluator1_.loadScriptString(sele1);
90 if (!evaluator1_.isDynamic()) {
91 seleMan1_.setSelectionSet(evaluator1_.evaluate());
94 evaluator2_.loadScriptString(sele2);
95 if (!evaluator2_.isDynamic()) {
96 seleMan2_.setSelectionSet(evaluator2_.evaluate());
100 "2nd order Legendre Polynomial Correlation using r as reference axis");
101 setOutputName(
getPrefix(filename) +
".P2R");
102 std::stringstream params;
103 const std::string paramString = params.str();
104 setParameterString(paramString);
107 P2R::P2R(SimInfo* info,
const std::string& filename,
const std::string& sele1,
108 int seleOffset,
unsigned int nbins) :
109 StaticAnalyser(info, filename, nbins),
110 doVect_(false), doOffset_(true), doOffset2_(false),
111 selectionScript1_(sele1), seleMan1_(info), seleMan2_(info),
112 evaluator1_(info), evaluator2_(info), seleOffset_(seleOffset) {
113 evaluator1_.loadScriptString(sele1);
114 if (!evaluator1_.isDynamic()) {
115 seleMan1_.setSelectionSet(evaluator1_.evaluate());
119 "2nd order Legendre Polynomial Correlation using r as reference axis");
120 setOutputName(
getPrefix(filename) +
".P2R");
121 std::stringstream params;
122 const std::string paramString = params.str();
123 setParameterString(paramString);
126 P2R::P2R(SimInfo* info,
const std::string& filename,
const std::string& sele1,
127 int seleOffset,
int seleOffset2,
unsigned int nbins) :
128 StaticAnalyser(info, filename, nbins),
129 doVect_(false), doOffset_(true), doOffset2_(true),
130 selectionScript1_(sele1), seleMan1_(info), seleMan2_(info),
131 evaluator1_(info), evaluator2_(info), seleOffset_(seleOffset),
132 seleOffset2_(seleOffset2) {
133 evaluator1_.loadScriptString(sele1);
134 if (!evaluator1_.isDynamic()) {
135 seleMan1_.setSelectionSet(evaluator1_.evaluate());
139 "2nd order Legendre Polynomial Correlation using r as reference axis");
140 setOutputName(
getPrefix(filename) +
".P2R");
141 std::stringstream params;
142 const std::string paramString = params.str();
143 setParameterString(paramString);
146 void P2R::process() {
151 bool usePeriodicBoundaryConditions_ =
152 info_->getSimParams()->getUsePeriodicBoundaryConditions();
154 Thermo thermo(info_);
155 DumpReader reader(info_, dumpFilename_);
156 int nFrames = reader.getNFrames();
158 nProcessed_ = nFrames / step_;
162 for (
int istep = 0; istep < nFrames; istep += step_) {
163 reader.readFrame(istep);
164 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
166 Vector3d CenterOfMass = thermo.getCom();
168 if (evaluator1_.isDynamic()) {
169 seleMan1_.setSelectionSet(evaluator1_.evaluate());
173 for (sd1 = seleMan1_.beginSelected(ii); sd1 != NULL;
174 sd1 = seleMan1_.nextSelected(ii)) {
175 Vector3d pos = sd1->getPos();
177 Vector3d r1 = CenterOfMass - pos;
180 if (sd1->isDirectional()) {
181 Vector3d vec = sd1->getA().transpose() * V3Z;
184 RealType cosangle =
dot(r1, vec);
186 P2_ += 0.5 * (3.0 * cosangle * cosangle - 1.0);
192 for (sd1 = seleMan1_.beginSelected(ii); sd1 != NULL;
193 sd1 = seleMan1_.nextSelected(ii)) {
200 int sd1Aind = sd1->getGlobalIndex() + seleOffset2_;
201 StuntDouble* sd1A = info_->getIOIndexToIntegrableObject(sd1Aind);
202 r1 = CenterOfMass - sd1A->getPos();
204 r1 = CenterOfMass - sd1->getPos();
207 if (usePeriodicBoundaryConditions_)
208 currentSnapshot_->wrapVector(r1);
210 int sd2Index = sd1->getGlobalIndex() + seleOffset_;
211 sd2 = info_->getIOIndexToIntegrableObject(sd2Index);
213 Vector3d r2 = CenterOfMass - sd2->getPos();
214 if (usePeriodicBoundaryConditions_)
215 currentSnapshot_->wrapVector(r2);
217 Vector3d rc = 0.5 * (r1 + r2);
218 if (usePeriodicBoundaryConditions_)
219 currentSnapshot_->wrapVector(rc);
221 Vector3d vec = r1 - r2;
222 if (usePeriodicBoundaryConditions_)
223 currentSnapshot_->wrapVector(vec);
227 RealType cosangle =
dot(rc, vec);
228 P2_ += 0.5 * (3.0 * cosangle * cosangle - 1.0);
232 if (evaluator2_.isDynamic()) {
233 seleMan2_.setSelectionSet(evaluator2_.evaluate());
236 if (seleMan1_.getSelectionCount() != seleMan2_.getSelectionCount()) {
237 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
238 "In frame %d, the number of selected StuntDoubles are\n"
239 "\tnot the same in --sele1 and sele2\n",
241 painCave.severity = OPENMD_INFO;
242 painCave.isFatal = 0;
246 for (sd1 = seleMan1_.beginSelected(ii),
247 sd2 = seleMan2_.beginSelected(jj);
248 sd1 != NULL && sd2 != NULL; sd1 = seleMan1_.nextSelected(ii),
249 sd2 = seleMan2_.nextSelected(jj)) {
250 Vector3d r1 = CenterOfMass - sd1->getPos();
251 if (usePeriodicBoundaryConditions_)
252 currentSnapshot_->wrapVector(r1);
254 Vector3d r2 = CenterOfMass - sd2->getPos();
255 if (usePeriodicBoundaryConditions_)
256 currentSnapshot_->wrapVector(r2);
258 Vector3d rc = 0.5 * (r1 + r2);
259 if (usePeriodicBoundaryConditions_)
260 currentSnapshot_->wrapVector(rc);
262 Vector3d vec = r1 - r2;
263 if (usePeriodicBoundaryConditions_)
264 currentSnapshot_->wrapVector(vec);
268 RealType cosangle =
dot(rc, vec);
269 P2_ += 0.5 * (3.0 * cosangle * cosangle - 1.0);
279 void P2R::processHistogram() {
280 if (count_ > 0) P2_ /= count_;
283 void P2R::writeP2R() {
284 std::ofstream ofs(outputFilename_.c_str());
288 ofs <<
"# " << getAnalysisType() <<
"\n";
289 ofs <<
"# OpenMD " << rev.getFullRevision() <<
"\n";
290 ofs <<
"# " << rev.getBuildDate() <<
"\n";
291 ofs <<
"#nFrames:\t" << nProcessed_ <<
"\n";
292 ofs <<
"#selection1: (" << selectionScript1_ <<
")";
293 if (!doVect_) { ofs <<
"\tselection2: (" << selectionScript2_ <<
")"; }
295 if (!paramString_.empty())
296 ofs <<
"# parameters: " << paramString_ <<
"\n";
298 ofs <<
"#P2 correlation:\n";
302 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
303 "P2R: unable to open %s\n", outputFilename_.c_str());
304 painCave.isFatal = 1;
311 P2Z::P2Z(SimInfo* info,
const std::string& filename,
const std::string& sele1,
312 unsigned int nbins,
int axis) :
313 P2R(info, filename, sele1, nbins),
328 setAnalysisType(
"2nd order Legendre Polynomial Correlation using " +
329 axisLabel_ +
" as reference axis");
330 setOutputName(
getPrefix(filename) +
".P2Z");
331 std::stringstream params;
332 const std::string paramString = params.str();
333 setParameterString(paramString);
336 P2Z::P2Z(SimInfo* info,
const std::string& filename,
const std::string& sele1,
337 const std::string& sele2,
unsigned int nbins,
int axis) :
338 P2R(info, filename, sele1, sele2, nbins),
353 setAnalysisType(
"2nd order Legendre Polynomial Correlation using " +
354 axisLabel_ +
" as reference axis");
355 setOutputName(
getPrefix(filename) +
".P2Z");
356 std::stringstream params;
357 const std::string paramString = params.str();
358 setParameterString(paramString);
361 P2Z::P2Z(SimInfo* info,
const std::string& filename,
const std::string& sele1,
362 int seleOffset,
unsigned int nbins,
int axis) :
363 P2R(info, filename, sele1, seleOffset, nbins),
378 setAnalysisType(
"2nd order Legendre Polynomial Correlation using " +
379 axisLabel_ +
" as reference axis");
380 setOutputName(
getPrefix(filename) +
".P2Z");
381 std::stringstream params;
382 const std::string paramString = params.str();
383 setParameterString(paramString);
386 P2Z::P2Z(SimInfo* info,
const std::string& filename,
const std::string& sele1,
387 int seleOffset,
int seleOffset2,
unsigned int nbins,
int axis) :
388 P2R(info, filename, sele1, seleOffset, seleOffset2, nbins),
403 setAnalysisType(
"2nd order Legendre Polynomial Correlation using " +
404 axisLabel_ +
" as reference axis");
405 setOutputName(
getPrefix(filename) +
".P2Z");
406 std::stringstream params;
407 const std::string paramString = params.str();
408 setParameterString(paramString);
411 void P2Z::process() {
412 Vector3d zhat = V3Zero;
419 bool usePeriodicBoundaryConditions_ =
420 info_->getSimParams()->getUsePeriodicBoundaryConditions();
422 DumpReader reader(info_, dumpFilename_);
423 int nFrames = reader.getNFrames();
425 nProcessed_ = nFrames / step_;
429 for (
int istep = 0; istep < nFrames; istep += step_) {
430 reader.readFrame(istep);
431 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
433 if (evaluator1_.isDynamic()) {
434 seleMan1_.setSelectionSet(evaluator1_.evaluate());
438 for (sd1 = seleMan1_.beginSelected(ii); sd1 != NULL;
439 sd1 = seleMan1_.nextSelected(ii)) {
442 if (sd1->isDirectional()) {
443 Vector3d vec = sd1->getA().transpose() * V3Z;
445 RealType cosangle =
dot(zhat, vec);
447 P2_ += 0.5 * (3.0 * cosangle * cosangle - 1.0);
453 for (sd1 = seleMan1_.beginSelected(ii); sd1 != NULL;
454 sd1 = seleMan1_.nextSelected(ii)) {
461 int sd1Aind = sd1->getGlobalIndex() + seleOffset2_;
462 StuntDouble* sd1A = info_->getIOIndexToIntegrableObject(sd1Aind);
468 int sd2Index = sd1->getGlobalIndex() + seleOffset_;
469 sd2 = info_->getIOIndexToIntegrableObject(sd2Index);
471 Vector3d r2 = sd2->getPos();
472 Vector3d vec = r1 - r2;
474 if (usePeriodicBoundaryConditions_)
475 currentSnapshot_->wrapVector(vec);
478 RealType cosangle =
dot(zhat, vec);
479 P2_ += 0.5 * (3.0 * cosangle * cosangle - 1.0);
483 if (evaluator2_.isDynamic()) {
484 seleMan2_.setSelectionSet(evaluator2_.evaluate());
487 if (seleMan1_.getSelectionCount() != seleMan2_.getSelectionCount()) {
488 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
489 "In frame %d, the number of selected StuntDoubles are\n"
490 "\tnot the same in --sele1 and sele2\n",
492 painCave.severity = OPENMD_INFO;
493 painCave.isFatal = 0;
497 for (sd1 = seleMan1_.beginSelected(ii),
498 sd2 = seleMan2_.beginSelected(jj);
499 sd1 != NULL && sd2 != NULL; sd1 = seleMan1_.nextSelected(ii),
500 sd2 = seleMan2_.nextSelected(jj)) {
501 Vector3d r1 = sd1->getPos();
502 Vector3d r2 = sd2->getPos();
503 Vector3d vec = r1 - r2;
505 if (usePeriodicBoundaryConditions_)
506 currentSnapshot_->wrapVector(vec);
509 RealType cosangle =
dot(zhat, vec);
510 P2_ += 0.5 * (3.0 * cosangle * cosangle - 1.0);
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
void normalize()
Normalizes this vector in place.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
Real dot(const DynamicVector< Real > &v1, const DynamicVector< Real > &v2)
Returns the dot product of two DynamicVectors.
std::string getPrefix(const std::string &str)