48#include "applications/staticProps/SpatialStatistics.hpp"
53#include "applications/staticProps/StaticAnalyser.hpp"
56#include "io/Globals.hpp"
59#include "rnemd/RNEMDParameters.hpp"
60#include "utils/Accumulator.hpp"
61#include "utils/AccumulatorView.hpp"
66 SpatialStatistics::SpatialStatistics(
SimInfo* info,
67 const std::string& filename,
68 const std::string& sele,
int nbins) :
70 selectionScript_(sele), evaluator_(info), seleMan_(info) {
71 evaluator_.loadScriptString(sele);
72 if (!evaluator_.isDynamic()) {
73 seleMan_.setSelectionSet(evaluator_.evaluate());
76 setOutputName(
getPrefix(filename) +
".spst");
79 void SpatialStatistics::process() {
80 DumpReader reader(info_, dumpFilename_);
81 int nFrames = reader.getNFrames();
82 nProcessed_ = nFrames / step_;
84 for (
int istep = 0; istep < nFrames; istep += step_) {
85 reader.readFrame(istep);
86 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
93 void SpatialStatistics::processFrame(
int) {
97 if (evaluator_.isDynamic()) {
98 seleMan_.setSelectionSet(evaluator_.evaluate());
102 for (sd = seleMan_.beginSelected(i); sd != NULL;
103 sd = seleMan_.nextSelected(i)) {
105 Vector3d pos = sd->getPos();
107 int bin = getBin(pos);
110 processStuntDouble(sd, bin);
114 SlabStatistics::SlabStatistics(SimInfo* info,
const std::string& filename,
115 const std::string& sele,
int nbins,
int axis) :
116 SpatialStatistics(info, filename, sele, nbins),
133 void SlabStatistics::processFrame(
int istep) {
135 hmat_ = currentSnapshot_->getHmat();
137 volume_ = currentSnapshot_->getVolume();
139 SpatialStatistics::processFrame(istep);
142 int SlabStatistics::getBin(Vector3d pos) {
143 currentSnapshot_->wrapVector(pos);
149 return int(nBins_ * (pos[axis_] / hmat_(axis_, axis_) + 0.5)) % nBins_;
152 ShellStatistics::ShellStatistics(SimInfo* info,
const std::string& filename,
153 const std::string& sele,
154 const std::string& comsele,
int nbins,
156 SpatialStatistics(info, filename, sele, nbins),
157 coordinateOrigin_(V3Zero), comSele_(comsele), comSeleMan_(info),
158 comEvaluator_(info), binWidth_(binWidth) {
159 Globals* simParams = info->getSimParams();
160 RNEMD::RNEMDParameters* rnemdParams = simParams->getRNEMDParameters();
161 bool hasCoordinateOrigin = rnemdParams->haveCoordinateOrigin();
163 if (hasCoordinateOrigin) {
164 std::vector<RealType> co = rnemdParams->getCoordinateOrigin();
165 if (co.size() != 3) {
167 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
168 "ShellStatistics: Incorrect number of parameters specified for "
169 "coordinateOrigin.\n"
170 "\tthere should be 3 parameters, but %zu were specified.\n",
172 painCave.isFatal = 1;
175 coordinateOrigin_.x() = co[0];
176 coordinateOrigin_.y() = co[1];
177 coordinateOrigin_.z() = co[2];
179 if (!comSele_.empty()) {
180 comEvaluator_.loadScriptString(comSele_);
181 if (!comEvaluator_.isDynamic()) {
182 comSeleMan_.setSelectionSet(comEvaluator_.evaluate());
183 if (comSeleMan_.getSelectionCount() != 1) {
184 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
185 "ShellStatistics: More than one selected object in "
187 "\tThere are %d selected objects.\n",
188 comSeleMan_.getSelectionCount());
189 painCave.isFatal = 1;
193 StuntDouble* sd = comSeleMan_.beginSelected(isd);
194 coordinateOrigin_ = sd->getPos();
197 coordinateOrigin_ = V3Zero;
202 void ShellStatistics::processFrame(
int istep) {
203 if (comEvaluator_.isDynamic()) {
204 comSeleMan_.setSelectionSet(comEvaluator_.evaluate());
205 if (comSeleMan_.getSelectionCount() != 1) {
206 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
207 "ShellStatistics: More than one selected object in "
209 "\tThere are %d selected objects.\n",
210 comSeleMan_.getSelectionCount());
211 painCave.isFatal = 1;
215 StuntDouble* sd = comSeleMan_.beginSelected(isd);
216 coordinateOrigin_ = sd->getPos();
218 SpatialStatistics::processFrame(istep);
222 int ShellStatistics::getBin(Vector3d pos) {
223 Vector3d rPos = pos - coordinateOrigin_;
224 return int(rPos.length() / binWidth_);
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)