48#include "applications/staticProps/ObjectCount.hpp"
56#include "utils/simError.h"
60 ObjectCount::ObjectCount(
SimInfo* info,
const std::string& filename,
61 const std::string& sele) :
63 selectionScript_(sele), seleMan_(info), evaluator_(info) {
64 setOutputName(
getPrefix(filename) +
".counts");
66 evaluator_.loadScriptString(sele);
68 if (!evaluator_.isDynamic()) {
69 seleMan_.setSelectionSet(evaluator_.evaluate());
73 void ObjectCount::process() {
75 counts_.resize(10, 0);
76 DumpReader reader(info_, dumpFilename_);
77 int nFrames = reader.getNFrames();
78 unsigned long int nsum = 0;
79 unsigned long int n2sum = 0;
81 for (
int i = 0; i < nFrames; i += step_) {
83 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
85 if (evaluator_.isDynamic()) {
86 seleMan_.setSelectionSet(evaluator_.evaluate());
89 unsigned int count = seleMan_.getSelectionCount();
91 if (counts_.size() < count + 1) { counts_.resize(count + 1, 0); }
96 n2sum += count * count;
99 int nProcessed = nFrames / step_;
101 nAvg = RealType(nsum) / RealType(nProcessed);
102 n2Avg = RealType(n2sum) / RealType(nProcessed);
103 sDev = sqrt(n2Avg - nAvg * nAvg);
107 void ObjectCount::writeCounts() {
108 std::ofstream ofs(outputFilename_.c_str(), std::ios::binary);
111 ofs <<
"#selection: (" << selectionScript_ <<
")\n";
112 ofs <<
"# <N> = " << std::fixed << std::setw(11) << std::setprecision(6)
114 ofs <<
"# <N^2> = " << std::fixed << std::setw(11) << std::setprecision(6)
116 ofs <<
"# sqrt(<N^2> - <N>^2) = " << sDev <<
"\n";
117 ofs <<
"# N\tcounts[N]\n";
118 for (
unsigned int i = 0; i < counts_.size(); ++i) {
119 ofs << i <<
"\t" << counts_[i] <<
"\n";
123 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
124 "ObjectCount: unable to open %s\n", outputFilename_.c_str());
125 painCave.isFatal = 1;
131 MoleculeCount::MoleculeCount(SimInfo* info,
const std::string& filename,
132 const std::string& sele) :
133 ObjectCount(info, filename, sele) {
134 setOutputName(
getPrefix(filename) +
".mcounts");
136 evaluator_.loadScriptString(sele);
138 if (!evaluator_.isDynamic()) {
139 seleMan_.setSelectionSet(evaluator_.evaluate());
143 void MoleculeCount::process() {
145 counts_.resize(10, 0);
146 DumpReader reader(info_, dumpFilename_);
147 int nFrames = reader.getNFrames();
148 unsigned long int nsum = 0;
149 unsigned long int n2sum = 0;
151 for (
int i = 0; i < nFrames; i += step_) {
153 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
155 if (evaluator_.isDynamic()) {
156 seleMan_.setSelectionSet(evaluator_.evaluate());
159 unsigned int count = seleMan_.getMoleculeSelectionCount();
161 if (counts_.size() < count + 1) { counts_.resize(count + 1, 0); }
166 n2sum += count * count;
169 int nProcessed = nFrames / step_;
171 nAvg = RealType(nsum) / RealType(nProcessed);
172 n2Avg = RealType(n2sum) / RealType(nProcessed);
173 sDev = sqrt(n2Avg - nAvg * nAvg);
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.
std::string getPrefix(const std::string &str)