45#include "applications/staticProps/ObjectCount.hpp"
53#include "utils/simError.h"
57 ObjectCount::ObjectCount(SimInfo* info,
const std::string& filename,
58 const std::string& sele) :
59 StaticAnalyser(info, filename, 1),
60 selectionScript_(sele), seleMan_(info), evaluator_(info) {
61 setOutputName(
getPrefix(filename) +
".counts");
63 evaluator_.loadScriptString(sele);
65 if (!evaluator_.isDynamic()) {
66 seleMan_.setSelectionSet(evaluator_.evaluate());
70 void ObjectCount::process() {
72 counts_.resize(10, 0);
73 DumpReader reader(info_, dumpFilename_);
74 int nFrames = reader.getNFrames();
75 unsigned long int nsum = 0;
76 unsigned long int n2sum = 0;
78 for (
int i = 0; i < nFrames; i += step_) {
80 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
82 if (evaluator_.isDynamic()) {
83 seleMan_.setSelectionSet(evaluator_.evaluate());
86 unsigned int count = seleMan_.getSelectionCount();
88 if (counts_.size() < count + 1) { counts_.resize(count + 1, 0); }
93 n2sum += count * count;
96 int nProcessed = nFrames / step_;
98 nAvg = RealType(nsum) / RealType(nProcessed);
99 n2Avg = RealType(n2sum) / RealType(nProcessed);
100 sDev = sqrt(n2Avg - nAvg * nAvg);
104 void ObjectCount::writeCounts() {
105 std::ofstream ofs(outputFilename_.c_str(), std::ios::binary);
108 ofs <<
"#selection: (" << selectionScript_ <<
")\n";
109 ofs <<
"# <N> = " << std::fixed << std::setw(11) << std::setprecision(6)
111 ofs <<
"# <N^2> = " << std::fixed << std::setw(11) << std::setprecision(6)
113 ofs <<
"# sqrt(<N^2> - <N>^2) = " << sDev <<
"\n";
114 ofs <<
"# N\tcounts[N]\n";
115 for (
unsigned int i = 0; i < counts_.size(); ++i) {
116 ofs << i <<
"\t" << counts_[i] <<
"\n";
120 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
121 "ObjectCount: unable to open %s\n", outputFilename_.c_str());
122 painCave.isFatal = 1;
128 MoleculeCount::MoleculeCount(SimInfo* info,
const std::string& filename,
129 const std::string& sele) :
130 ObjectCount(info, filename, sele) {
131 setOutputName(
getPrefix(filename) +
".mcounts");
133 evaluator_.loadScriptString(sele);
135 if (!evaluator_.isDynamic()) {
136 seleMan_.setSelectionSet(evaluator_.evaluate());
140 void MoleculeCount::process() {
142 counts_.resize(10, 0);
143 DumpReader reader(info_, dumpFilename_);
144 int nFrames = reader.getNFrames();
145 unsigned long int nsum = 0;
146 unsigned long int n2sum = 0;
148 for (
int i = 0; i < nFrames; i += step_) {
150 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
152 if (evaluator_.isDynamic()) {
153 seleMan_.setSelectionSet(evaluator_.evaluate());
156 unsigned int count = seleMan_.getMoleculeSelectionCount();
158 if (counts_.size() < count + 1) { counts_.resize(count + 1, 0); }
163 n2sum += count * count;
166 int nProcessed = nFrames / step_;
168 nAvg = RealType(nsum) / RealType(nProcessed);
169 n2Avg = RealType(n2sum) / RealType(nProcessed);
170 sDev = sqrt(n2Avg - nAvg * nAvg);
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
std::string getPrefix(const std::string &str)