50#include "applications/staticProps/pAngle.hpp"
55#include "brains/Thermo.hpp"
58#include "utils/simError.h"
62 pAngle::pAngle(
SimInfo* info,
const std::string& filename,
63 const std::string& sele1,
int nthetabins) :
65 doVect_(true), doOffset_(false), selectionScript1_(sele1),
66 seleMan1_(info), seleMan2_(info), evaluator1_(info), evaluator2_(info),
67 nThetaBins_(nthetabins) {
68 setOutputName(
getPrefix(filename) +
".pAngle");
70 evaluator1_.loadScriptString(sele1);
71 if (!evaluator1_.isDynamic()) {
72 seleMan1_.setSelectionSet(evaluator1_.evaluate());
75 count_.resize(nThetaBins_);
76 histogram_.resize(nThetaBins_);
79 pAngle::pAngle(SimInfo* info,
const std::string& filename,
80 const std::string& sele1,
const std::string& sele2,
82 StaticAnalyser(info, filename, nthetabins),
83 doVect_(false), doOffset_(false), selectionScript1_(sele1),
84 selectionScript2_(sele2), seleMan1_(info), seleMan2_(info),
85 evaluator1_(info), evaluator2_(info), nThetaBins_(nthetabins) {
86 setOutputName(
getPrefix(filename) +
".pAngle");
88 evaluator1_.loadScriptString(sele1);
89 if (!evaluator1_.isDynamic()) {
90 seleMan1_.setSelectionSet(evaluator1_.evaluate());
93 evaluator2_.loadScriptString(sele2);
94 if (!evaluator2_.isDynamic()) {
95 seleMan2_.setSelectionSet(evaluator2_.evaluate());
98 count_.resize(nThetaBins_);
99 histogram_.resize(nThetaBins_);
102 pAngle::pAngle(SimInfo* info,
const std::string& filename,
103 const std::string& sele1,
int seleOffset,
int nthetabins) :
104 StaticAnalyser(info, filename, nthetabins),
105 doVect_(false), doOffset_(true), doOffset2_(false),
106 selectionScript1_(sele1), seleMan1_(info), seleMan2_(info),
107 evaluator1_(info), evaluator2_(info), seleOffset_(seleOffset),
108 nThetaBins_(nthetabins) {
109 setOutputName(
getPrefix(filename) +
".pAngle");
111 evaluator1_.loadScriptString(sele1);
112 if (!evaluator1_.isDynamic()) {
113 seleMan1_.setSelectionSet(evaluator1_.evaluate());
116 count_.resize(nThetaBins_);
117 histogram_.resize(nThetaBins_);
120 pAngle::pAngle(SimInfo* info,
const std::string& filename,
121 const std::string& sele1,
int seleOffset,
int seleOffset2,
123 StaticAnalyser(info, filename, nthetabins),
124 doVect_(false), doOffset_(true), doOffset2_(true),
125 selectionScript1_(sele1), seleMan1_(info), seleMan2_(info),
126 evaluator1_(info), evaluator2_(info), seleOffset_(seleOffset),
127 seleOffset2_(seleOffset2), nThetaBins_(nthetabins) {
128 setOutputName(
getPrefix(filename) +
".pAngle");
130 evaluator1_.loadScriptString(sele1);
131 if (!evaluator1_.isDynamic()) {
132 seleMan1_.setSelectionSet(evaluator1_.evaluate());
135 count_.resize(nThetaBins_);
136 histogram_.resize(nThetaBins_);
139 void pAngle::process() {
144 bool usePeriodicBoundaryConditions_ =
145 info_->getSimParams()->getUsePeriodicBoundaryConditions();
147 Thermo thermo(info_);
148 DumpReader reader(info_, dumpFilename_);
149 int nFrames = reader.getNFrames();
151 nProcessed_ = nFrames / step_;
153 std::fill(histogram_.begin(), histogram_.end(), 0.0);
154 std::fill(count_.begin(), count_.end(), 0);
156 for (
int istep = 0; istep < nFrames; istep += step_) {
157 reader.readFrame(istep);
158 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
160 Vector3d CenterOfMass = thermo.getCom();
162 if (evaluator1_.isDynamic()) {
163 seleMan1_.setSelectionSet(evaluator1_.evaluate());
167 for (sd1 = seleMan1_.beginSelected(ii); sd1 != NULL;
168 sd1 = seleMan1_.nextSelected(ii)) {
169 Vector3d pos = sd1->getPos();
171 Vector3d r1 = CenterOfMass - pos;
174 if (sd1->isDirectional()) {
175 Vector3d vec = sd1->getA().transpose() * V3Z;
178 RealType cosangle =
dot(r1, vec);
180 int binNo = int(nThetaBins_ * (1.0 + cosangle) / 2.0);
186 for (sd1 = seleMan1_.beginSelected(ii); sd1 != NULL;
187 sd1 = seleMan1_.nextSelected(ii)) {
194 int sd1Aind = sd1->getGlobalIndex() + seleOffset2_;
195 StuntDouble* sd1A = info_->getIOIndexToIntegrableObject(sd1Aind);
196 r1 = CenterOfMass - sd1A->getPos();
198 r1 = CenterOfMass - sd1->getPos();
201 if (usePeriodicBoundaryConditions_)
202 currentSnapshot_->wrapVector(r1);
204 int sd2Index = sd1->getGlobalIndex() + seleOffset_;
205 sd2 = info_->getIOIndexToIntegrableObject(sd2Index);
207 Vector3d r2 = CenterOfMass - sd2->getPos();
208 if (usePeriodicBoundaryConditions_)
209 currentSnapshot_->wrapVector(r1);
211 Vector3d rc = 0.5 * (r1 + r2);
212 if (usePeriodicBoundaryConditions_)
213 currentSnapshot_->wrapVector(rc);
215 Vector3d vec = r1 - r2;
216 if (usePeriodicBoundaryConditions_)
217 currentSnapshot_->wrapVector(vec);
221 RealType cosangle =
dot(rc, vec);
222 int binNo = int(nThetaBins_ * (1.0 + cosangle) / 2.0);
226 if (evaluator2_.isDynamic()) {
227 seleMan2_.setSelectionSet(evaluator2_.evaluate());
230 if (seleMan1_.getSelectionCount() != seleMan2_.getSelectionCount()) {
231 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
232 "In frame %d, the number of selected StuntDoubles are\n"
233 "\tnot the same in --sele1 and sele2\n",
235 painCave.severity = OPENMD_INFO;
236 painCave.isFatal = 0;
240 for (sd1 = seleMan1_.beginSelected(ii),
241 sd2 = seleMan2_.beginSelected(jj);
242 sd1 != NULL && sd2 != NULL; sd1 = seleMan1_.nextSelected(ii),
243 sd2 = seleMan2_.nextSelected(jj)) {
244 Vector3d r1 = CenterOfMass - sd1->getPos();
245 if (usePeriodicBoundaryConditions_)
246 currentSnapshot_->wrapVector(r1);
248 Vector3d r2 = CenterOfMass - sd2->getPos();
249 if (usePeriodicBoundaryConditions_)
250 currentSnapshot_->wrapVector(r1);
252 Vector3d rc = 0.5 * (r1 + r2);
253 if (usePeriodicBoundaryConditions_)
254 currentSnapshot_->wrapVector(rc);
256 Vector3d vec = r1 - r2;
257 if (usePeriodicBoundaryConditions_)
258 currentSnapshot_->wrapVector(vec);
262 RealType cosangle =
dot(rc, vec);
263 int binNo = int(nThetaBins_ * (1.0 + cosangle) / 2.0);
274 void pAngle::processHistogram() {
276 for (
unsigned int i = 0; i < count_.size(); ++i)
279 for (
unsigned int i = 0; i < count_.size(); ++i) {
280 histogram_[i] = double(count_[i] /
double(atot));
284 void pAngle::writeProbs() {
285 std::ofstream rdfStream(outputFilename_.c_str());
286 if (rdfStream.is_open()) {
287 rdfStream <<
"#pAngle\n";
288 rdfStream <<
"#nFrames:\t" << nProcessed_ <<
"\n";
289 rdfStream <<
"#selection1: (" << selectionScript1_ <<
")";
291 rdfStream <<
"\tselection2: (" << selectionScript2_ <<
")";
294 rdfStream <<
"#cos(theta)\tp(cos(theta))\n";
295 RealType dct = 2.0 / histogram_.size();
296 for (
unsigned int i = 0; i < histogram_.size(); ++i) {
297 RealType ct = -1.0 + (2.0 * i + 1) / (histogram_.size());
298 rdfStream << ct <<
"\t" << histogram_[i] / dct <<
"\n";
302 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
303 "pAngle: unable to open %s\n", outputFilename_.c_str());
304 painCave.isFatal = 1;
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)