53#include "applications/staticProps/NumberZ.hpp"
58#include "brains/Thermo.hpp"
61#include "utils/simError.h"
65 NumberZ::NumberZ(
SimInfo* info,
const std::string& filename,
66 const std::string& sele,
int nzbins,
int axis) :
68 selectionScript_(sele), evaluator_(info), seleMan_(info), thermo_(info),
70 evaluator_.loadScriptString(sele);
71 if (!evaluator_.isDynamic()) {
72 seleMan_.setSelectionSet(evaluator_.evaluate());
75 numberZ_.resize(nBins_);
90 setOutputName(
getPrefix(filename) +
".NumberZ");
93 void NumberZ::process() {
97 bool usePeriodicBoundaryConditions_ =
98 info_->getSimParams()->getUsePeriodicBoundaryConditions();
100 DumpReader reader(info_, dumpFilename_);
101 int nFrames = reader.getNFrames();
102 nProcessed_ = nFrames / step_;
104 for (
int istep = 0; istep < nFrames; istep += step_) {
105 reader.readFrame(istep);
106 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
108 Mat3x3d hmat = currentSnapshot_->getHmat();
109 zBox_.push_back(hmat(axis_, axis_));
111 RealType halfBoxZ_ = hmat(axis_, axis_) / 2.0;
115 area = currentSnapshot_->getYZarea();
118 area = currentSnapshot_->getXZarea();
122 area = currentSnapshot_->getXYarea();
126 areas_.push_back(area);
128 if (evaluator_.isDynamic()) {
129 seleMan_.setSelectionSet(evaluator_.evaluate());
132 for (mol = seleMan_.beginSelectedMolecule(ii); mol != NULL;
133 mol = seleMan_.nextSelectedMolecule(ii)) {
134 Vector3d pos = mol->getCom();
135 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(pos);
137 int binNo = int(nBins_ * (halfBoxZ_ + pos[axis_]) / hmat(axis_, axis_));
144 void NumberZ::writeNumberZ() {
146 std::vector<RealType>::iterator j;
148 for (j = zBox_.begin(); j != zBox_.end(); ++j) {
151 RealType zAve = zSum / zBox_.size();
153 RealType areaSum = 0.0;
154 for (j = areas_.begin(); j != areas_.end(); ++j) {
157 RealType areaAve = areaSum / areas_.size();
159 std::ofstream rdfStream(outputFilename_.c_str());
160 if (rdfStream.is_open()) {
161 rdfStream <<
"#NumberZ "
163 rdfStream <<
"#selection: (" << selectionScript_ <<
")\n";
164 rdfStream <<
"#" << axisLabel_ <<
"\tnumber\n";
166 for (
unsigned int i = 0; i < numberZ_.size(); ++i) {
167 RealType z = zAve * (i + 0.5) / nBins_;
169 RealType volSlice = areaAve * zAve / nBins_;
171 binNumber = numberZ_[i] / (volSlice * nProcessed_);
173 rdfStream << z <<
"\t" << binNumber <<
"\n";
177 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
178 "NumberZ: unable to open %s\n", outputFilename_.c_str());
179 painCave.isFatal = 1;
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)