45#include "applications/staticProps/ObjectCount.hpp"
52#include "utils/simError.h"
56 ObjectCount::ObjectCount(SimInfo* info,
const std::string& filename,
57 const std::string& sele) :
58 StaticAnalyser(info, filename, 1),
59 selectionScript_(sele), seleMan_(info), evaluator_(info) {
60 setOutputName(
getPrefix(filename) +
".counts");
62 evaluator_.loadScriptString(sele);
64 if (!evaluator_.isDynamic()) {
65 seleMan_.setSelectionSet(evaluator_.evaluate());
69 void ObjectCount::process() {
71 counts_.resize(10, 0);
72 DumpReader reader(info_, dumpFilename_);
73 int nFrames = reader.getNFrames();
74 unsigned long int nsum = 0;
75 unsigned long int n2sum = 0;
77 for (
int i = 0; i < nFrames; i += step_) {
79 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
81 if (evaluator_.isDynamic()) {
82 seleMan_.setSelectionSet(evaluator_.evaluate());
85 unsigned int count = seleMan_.getSelectionCount();
87 if (counts_.size() < count + 1) { counts_.resize(count + 1, 0); }
92 n2sum += count * count;
95 int nProcessed = nFrames / step_;
97 nAvg = nsum / nProcessed;
98 n2Avg = n2sum / nProcessed;
99 sDev = sqrt(n2Avg - nAvg * nAvg);
103 void ObjectCount::writeCounts() {
104 std::ofstream ofs(outputFilename_.c_str(), std::ios::binary);
107 ofs <<
"#selection: (" << selectionScript_ <<
")\n";
108 ofs <<
"# <N> = " << nAvg <<
"\n";
109 ofs <<
"# <N^2> = " << n2Avg <<
"\n";
110 ofs <<
"# sqrt(<N^2> - <N>^2) = " << sDev <<
"\n";
111 ofs <<
"# N\tcounts[N]\n";
112 for (
unsigned int i = 0; i < counts_.size(); ++i) {
113 ofs << i <<
"\t" << counts_[i] <<
"\n";
117 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
118 "ObjectCount: unable to open %s\n", outputFilename_.c_str());
119 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)