50#include "applications/staticProps/NumberZ.hpp"
55#include "brains/Thermo.hpp"
58#include "utils/simError.h"
62 NumberZ::NumberZ(SimInfo* info,
const std::string& filename,
63 const std::string& sele,
int nzbins,
int axis) :
64 StaticAnalyser(info, filename, nzbins),
65 selectionScript_(sele), evaluator_(info), seleMan_(info), thermo_(info),
67 evaluator_.loadScriptString(sele);
68 if (!evaluator_.isDynamic()) {
69 seleMan_.setSelectionSet(evaluator_.evaluate());
72 numberZ_.resize(nBins_);
87 setOutputName(
getPrefix(filename) +
".NumberZ");
90 void NumberZ::process() {
94 bool usePeriodicBoundaryConditions_ =
95 info_->getSimParams()->getUsePeriodicBoundaryConditions();
97 DumpReader reader(info_, dumpFilename_);
98 int nFrames = reader.getNFrames();
99 nProcessed_ = nFrames / step_;
101 for (
int istep = 0; istep < nFrames; istep += step_) {
102 reader.readFrame(istep);
103 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
105 Mat3x3d hmat = currentSnapshot_->getHmat();
106 zBox_.push_back(hmat(axis_, axis_));
108 RealType halfBoxZ_ = hmat(axis_, axis_) / 2.0;
112 area = currentSnapshot_->getYZarea();
115 area = currentSnapshot_->getXZarea();
119 area = currentSnapshot_->getXYarea();
123 areas_.push_back(area);
125 if (evaluator_.isDynamic()) {
126 seleMan_.setSelectionSet(evaluator_.evaluate());
129 for (mol = seleMan_.beginSelectedMolecule(ii); mol != NULL;
130 mol = seleMan_.nextSelectedMolecule(ii)) {
131 Vector3d pos = mol->getCom();
132 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(pos);
134 int binNo = int(nBins_ * (halfBoxZ_ + pos[axis_]) / hmat(axis_, axis_));
141 void NumberZ::writeNumberZ() {
143 std::vector<RealType>::iterator j;
145 for (j = zBox_.begin(); j != zBox_.end(); ++j) {
148 RealType zAve = zSum / zBox_.size();
150 RealType areaSum = 0.0;
151 for (j = areas_.begin(); j != areas_.end(); ++j) {
154 RealType areaAve = areaSum / areas_.size();
156 std::ofstream rdfStream(outputFilename_.c_str());
157 if (rdfStream.is_open()) {
158 rdfStream <<
"#NumberZ "
160 rdfStream <<
"#selection: (" << selectionScript_ <<
")\n";
161 rdfStream <<
"#" << axisLabel_ <<
"\tnumber\n";
163 for (
unsigned int i = 0; i < numberZ_.size(); ++i) {
164 RealType z = zAve * (i + 0.5) / nBins_;
166 RealType volSlice = areaAve * zAve / nBins_;
168 binNumber = numberZ_[i] / (volSlice * nProcessed_);
170 rdfStream << z <<
"\t" << binNumber <<
"\n";
174 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
175 "NumberZ: unable to open %s\n", outputFilename_.c_str());
176 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)