50#include "applications/staticProps/AngleR.hpp"
53#include "utils/simError.h"
57 AngleR::AngleR(SimInfo* info,
const std::string& filename,
58 const std::string& sele, RealType len,
int nrbins) :
59 StaticAnalyser(info, filename),
60 selectionScript_(sele), evaluator_(info), seleMan_(info), len_(len),
62 evaluator_.loadScriptString(sele);
63 if (!evaluator_.isDynamic()) {
64 seleMan_.setSelectionSet(evaluator_.evaluate());
67 deltaR_ = len_ / nRBins_;
69 histogram_.resize(nRBins_);
70 count_.resize(nRBins_);
71 avgAngleR_.resize(nRBins_);
72 setOutputName(
getPrefix(filename) +
".AngleR");
75 void AngleR::process() {
76 DumpReader reader(info_, dumpFilename_);
77 int nFrames = reader.getNFrames();
78 nProcessed_ = nFrames / step_;
80 std::fill(avgAngleR_.begin(), avgAngleR_.end(), 0.0);
81 std::fill(histogram_.begin(), histogram_.end(), 0.0);
82 std::fill(count_.begin(), count_.end(), 0);
84 for (
int istep = 0; istep < nFrames; istep += step_) {
87 reader.readFrame(istep);
88 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
89 Vector3d CenterOfMass = info_->getCom();
91 if (evaluator_.isDynamic()) {
92 seleMan_.setSelectionSet(evaluator_.evaluate());
96 for (sd = seleMan_.beginSelected(i); sd != NULL;
97 sd = seleMan_.nextSelected(i)) {
98 Vector3d pos = sd->getPos();
99 Vector3d r1 = CenterOfMass - pos;
102 if (sd->isDirectional()) {
103 Vector3d uz = sd->getA().transpose() * V3Z;
109 RealType cosangle =
dot(r1, uz);
111 if (distance < len_) {
113 histogram_[whichBin] += cosangle;
114 count_[whichBin] += 1;
124 void AngleR::processHistogram() {
125 for (
int i = 0; i < histogram_.size(); ++i) {
127 avgAngleR_[i] += histogram_[i] / count_[i];
131 std::cerr <<
" count = " << count_[i] <<
" avgAngle = " << avgAngleR_[i]
136 void AngleR::writeAngleR() {
137 std::ofstream rdfStream(outputFilename_.c_str());
138 if (rdfStream.is_open()) {
139 rdfStream <<
"#radial density function Angle(r)\n";
140 rdfStream <<
"#r\tcorrValue\n";
141 for (
int i = 0; i < avgAngleR_.size(); ++i) {
142 RealType r = deltaR_ * (i + 0.5);
143 rdfStream << r <<
"\t" << avgAngleR_[i] <<
"\n";
147 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
148 "AngleR: unable to open %s\n", outputFilename_.c_str());
149 painCave.isFatal = 1;
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)
Real distance(const DynamicVector< Real > &v1, const DynamicVector< Real > &v2)
Returns the distance between two DynamicVectors.