53#include "applications/staticProps/PositionZ.hpp"
58#include "brains/Thermo.hpp"
61#include "types/FixedChargeAdapter.hpp"
62#include "types/FluctuatingChargeAdapter.hpp"
63#include "utils/simError.h"
67 PositionZ::PositionZ(
SimInfo* info,
const std::string& filename,
68 const std::string& sele,
int nzbins,
int axis) :
70 selectionScript_(sele), evaluator_(info), seleMan_(info), thermo_(info),
72 evaluator_.loadScriptString(sele);
73 if (!evaluator_.isDynamic()) {
74 seleMan_.setSelectionSet(evaluator_.evaluate());
79 sliceSDCount_.resize(nBins_);
80 flucSliceSDCount_.resize(nBins_);
81 std::fill(sliceSDCount_.begin(), sliceSDCount_.end(), 0);
82 std::fill(flucSliceSDCount_.begin(), flucSliceSDCount_.end(), 0);
84 positionZ_.resize(nBins_);
99 setOutputName(
getPrefix(filename) +
".CountZ");
102 void PositionZ::process() {
106 bool usePeriodicBoundaryConditions_ =
107 info_->getSimParams()->getUsePeriodicBoundaryConditions();
109 DumpReader reader(info_, dumpFilename_);
110 int nFrames = reader.getNFrames();
111 nProcessed_ = nFrames / step_;
113 for (
int istep = 0; istep < nFrames; istep += step_) {
114 reader.readFrame(istep);
115 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
117 Mat3x3d hmat = currentSnapshot_->getHmat();
118 zBox_.push_back(hmat(axis_, axis_));
120 RealType halfBoxZ_ = hmat(axis_, axis_) / 2.0;
122 if (evaluator_.isDynamic()) {
123 seleMan_.setSelectionSet(evaluator_.evaluate());
127 for (sd = seleMan_.beginSelected(ii); sd != NULL;
128 sd = seleMan_.nextSelected(ii)) {
129 Vector3d pos = sd->getPos();
130 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(pos);
135 for (sd = seleMan_.beginSelected(ii); sd != NULL;
136 sd = seleMan_.nextSelected(ii)) {
137 Vector3d pos = sd->getPos();
139 int binNo = int(nBins_ * (halfBoxZ_ + pos[axis_]) / hmat(axis_, axis_));
140 sliceSDCount_[binNo]++;
146 for (
int istep = 0; istep < nFrames; istep += step_) {
147 std::map<int, RealType> countInBin;
149 reader.readFrame(istep);
150 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
151 Mat3x3d hmat = currentSnapshot_->getHmat();
152 RealType halfBoxZ_ = hmat(axis_, axis_) / 2.0;
155 for (sd = seleMan_.beginSelected(ii); sd != NULL;
156 sd = seleMan_.nextSelected(ii)) {
157 Vector3d pos = sd->getPos();
159 int binNo = int(nBins_ * (halfBoxZ_ + pos[axis_]) / hmat(axis_, axis_));
165 for (
unsigned int index = 0; index < flucSliceSDCount_.size(); ++index) {
167 (countInBin[index] - (sliceSDCount_[index] / nProcessed_));
168 flucSliceSDCount_[index] += flucCount * flucCount;
175 void PositionZ::writePositionZ() {
177 std::vector<RealType>::iterator j;
179 for (j = zBox_.begin(); j != zBox_.end(); ++j) {
182 RealType zAve = zSum / zBox_.size();
184 std::ofstream rdfStream(outputFilename_.c_str());
185 if (rdfStream.is_open()) {
186 rdfStream <<
"#position count "
188 rdfStream <<
"#selection: (" << selectionScript_ <<
")\n";
189 rdfStream <<
"#" << axisLabel_
190 <<
"\tAverage Number\tFluctations_in_count\n";
191 for (
unsigned int i = 0; i < positionZ_.size(); ++i) {
192 RealType z = zAve * (i + 0.5) / positionZ_.size();
193 rdfStream << z <<
"\t" << sliceSDCount_[i] / nProcessed_ <<
"\t"
194 << sqrt(flucSliceSDCount_[i]) / nProcessed_ <<
"\n";
198 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
199 "ChargeZ: unable to open %s\n", outputFilename_.c_str());
200 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)