45#include "applications/staticProps/NumberR.hpp"
50#include "brains/Thermo.hpp"
53#include "utils/simError.h"
57 NumberR::NumberR(SimInfo* info,
const std::string& filename,
58 const std::string& sele, RealType len,
int nrbins) :
59 StaticAnalyser(info, filename, nrbins),
60 selectionScript_(sele), evaluator_(info), seleMan_(info), thermo_(info),
62 evaluator_.loadScriptString(sele);
63 if (!evaluator_.isDynamic()) {
64 seleMan_.setSelectionSet(evaluator_.evaluate());
67 deltaR_ = len_ / nBins_;
71 numberR_.resize(nBins_);
72 setOutputName(
getPrefix(filename) +
".NumberR");
73 std::stringstream params;
74 params <<
" len = " << len_ <<
", nrbins = " << nBins_;
75 const std::string paramString = params.str();
76 setParameterString(paramString);
79 void NumberR::process() {
83 DumpReader reader(info_, dumpFilename_);
84 int nFrames = reader.getNFrames();
85 nProcessed_ = nFrames / step_;
87 for (
int istep = 0; istep < nFrames; istep += step_) {
88 reader.readFrame(istep);
89 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
91 if (evaluator_.isDynamic()) {
92 seleMan_.setSelectionSet(evaluator_.evaluate());
96 for (mol = seleMan_.beginSelectedMolecule(ii); mol != NULL;
97 mol = seleMan_.nextSelectedMolecule(ii)) {
98 Vector3d pos = mol->getCom();
101 if (distance < len_) {
102 int binNo = int(distance / deltaR_);
110 void NumberR::writeNumberR() {
111 std::ofstream rdfStream(outputFilename_.c_str());
112 if (rdfStream.is_open()) {
113 rdfStream <<
"#NumberR "
115 rdfStream <<
"#selection: (" << selectionScript_ <<
")\n";
119 for (
unsigned int i = 0; i < numberR_.size(); ++i) {
120 RealType rLower = i * deltaR_;
121 RealType rUpper = rLower + deltaR_;
123 (4.0 * Constants::PI) * (pow(rUpper, 3) - pow(rLower, 3)) / 3.0;
125 RealType r = deltaR_ * (i + 0.5);
127 binNumber = numberR_[i] / (volShell * nProcessed_);
129 rdfStream << r <<
"\t" << binNumber <<
"\n";
133 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
134 "NumberR: unable to open %s\n", outputFilename_.c_str());
135 painCave.isFatal = 1;
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
std::string getPrefix(const std::string &str)
Real distance(const DynamicVector< Real > &v1, const DynamicVector< Real > &v2)
Returns the distance between two DynamicVectors.