53#include "applications/staticProps/AngleR.hpp"
56#include "utils/simError.h"
60 AngleR::AngleR(
SimInfo* info,
const std::string& filename,
61 const std::string& sele, RealType len,
int nrbins) :
63 selectionScript_(sele), evaluator_(info), seleMan_(info), len_(len),
65 evaluator_.loadScriptString(sele);
66 if (!evaluator_.isDynamic()) {
67 seleMan_.setSelectionSet(evaluator_.evaluate());
70 deltaR_ = len_ / nRBins_;
72 histogram_.resize(nRBins_);
73 count_.resize(nRBins_);
74 avgAngleR_.resize(nRBins_);
75 setOutputName(
getPrefix(filename) +
".AngleR");
78 void AngleR::process() {
79 DumpReader reader(info_, dumpFilename_);
80 int nFrames = reader.getNFrames();
81 nProcessed_ = nFrames / step_;
83 std::fill(avgAngleR_.begin(), avgAngleR_.end(), 0.0);
84 std::fill(histogram_.begin(), histogram_.end(), 0.0);
85 std::fill(count_.begin(), count_.end(), 0);
87 for (
int istep = 0; istep < nFrames; istep += step_) {
90 reader.readFrame(istep);
91 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
92 Vector3d CenterOfMass = info_->getCom();
94 if (evaluator_.isDynamic()) {
95 seleMan_.setSelectionSet(evaluator_.evaluate());
99 for (sd = seleMan_.beginSelected(i); sd != NULL;
100 sd = seleMan_.nextSelected(i)) {
101 Vector3d pos = sd->getPos();
102 Vector3d r1 = CenterOfMass - pos;
105 if (sd->isDirectional()) {
106 Vector3d uz = sd->getA().transpose() * V3Z;
112 RealType cosangle =
dot(r1, uz);
114 if (distance < len_) {
116 histogram_[whichBin] += cosangle;
117 count_[whichBin] += 1;
127 void AngleR::processHistogram() {
128 for (
int i = 0; i < histogram_.size(); ++i) {
130 avgAngleR_[i] += histogram_[i] / count_[i];
134 std::cerr <<
" count = " << count_[i] <<
" avgAngle = " << avgAngleR_[i]
139 void AngleR::writeAngleR() {
140 std::ofstream rdfStream(outputFilename_.c_str());
141 if (rdfStream.is_open()) {
142 rdfStream <<
"#radial density function Angle(r)\n";
143 rdfStream <<
"#r\tcorrValue\n";
144 for (
int i = 0; i < avgAngleR_.size(); ++i) {
145 RealType r = deltaR_ * (i + 0.5);
146 rdfStream << r <<
"\t" << avgAngleR_[i] <<
"\n";
150 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
151 "AngleR: unable to open %s\n", outputFilename_.c_str());
152 painCave.isFatal = 1;
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
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.