53#include "applications/staticProps/ChargeZ.hpp"
58#include "brains/Thermo.hpp"
61#include "types/FixedChargeAdapter.hpp"
62#include "types/FluctuatingChargeAdapter.hpp"
63#include "utils/simError.h"
67 ChargeZ::ChargeZ(
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 sliceSDLists_.resize(nBins_);
80 sliceSDCount_.resize(nBins_);
81 std::fill(sliceSDCount_.begin(), sliceSDCount_.end(), 0);
83 chargeZ_.resize(nBins_);
98 setOutputName(
getPrefix(filename) +
".ChargeZ");
101 void ChargeZ::process() {
105 bool usePeriodicBoundaryConditions_ =
106 info_->getSimParams()->getUsePeriodicBoundaryConditions();
108 DumpReader reader(info_, dumpFilename_);
109 int nFrames = reader.getNFrames();
110 nProcessed_ = nFrames / step_;
112 for (
int istep = 0; istep < nFrames; istep += step_) {
113 reader.readFrame(istep);
114 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
116 for (
unsigned int i = 0; i < nBins_; i++) {
117 sliceSDLists_[i].clear();
120 Mat3x3d hmat = currentSnapshot_->getHmat();
121 zBox_.push_back(hmat(axis_, axis_));
123 RealType halfBoxZ_ = hmat(axis_, axis_) / 2.0;
127 area = currentSnapshot_->getYZarea();
130 area = currentSnapshot_->getXZarea();
134 area = currentSnapshot_->getXYarea();
138 areas_.push_back(area);
140 if (evaluator_.isDynamic()) {
141 seleMan_.setSelectionSet(evaluator_.evaluate());
145 for (sd = seleMan_.beginSelected(ii); sd != NULL;
146 sd = seleMan_.nextSelected(ii)) {
147 Vector3d pos = sd->getPos();
148 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(pos);
153 for (sd = seleMan_.beginSelected(ii); sd != NULL;
154 sd = seleMan_.nextSelected(ii)) {
155 Vector3d pos = sd->getPos();
157 int binNo = int(nBins_ * (halfBoxZ_ + pos[axis_]) / hmat(axis_, axis_));
158 sliceSDLists_[binNo].push_back(sd);
159 sliceSDCount_[binNo]++;
163 for (
unsigned int i = 0; i < nBins_; i++) {
165 for (
unsigned int k = 0; k < sliceSDLists_[i].size(); ++k) {
167 Atom* atom =
static_cast<Atom*
>(sliceSDLists_[i][k]);
169 AtomType* atomType = atom->getAtomType();
171 if (sliceSDLists_[i][k]->isAtom()) {
172 FixedChargeAdapter fca = FixedChargeAdapter(atomType);
173 if (fca.isFixedCharge()) { q += fca.getCharge(); }
175 FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atomType);
176 if (fqa.isFluctuatingCharge()) { q += atom->getFlucQPos(); }
189 void ChargeZ::writeChargeZ() {
191 std::vector<RealType>::iterator j;
193 for (j = zBox_.begin(); j != zBox_.end(); ++j) {
196 RealType zAve = zSum / zBox_.size();
198 RealType areaSum = 0.0;
199 for (j = areas_.begin(); j != areas_.end(); ++j) {
202 RealType areaAve = areaSum / areas_.size();
204 std::ofstream rdfStream(outputFilename_.c_str());
205 if (rdfStream.is_open()) {
206 rdfStream <<
"#ChargeZ "
208 rdfStream <<
"#selection: (" << selectionScript_ <<
")\n";
209 rdfStream <<
"#" << axisLabel_ <<
"\tcharge\n";
211 for (
unsigned int i = 0; i < chargeZ_.size(); ++i) {
212 RealType z = zAve * (i + 0.5) / chargeZ_.size();
214 RealType volSlice = areaAve * zAve / zBox_.size();
216 binCharge = chargeZ_[i] / (volSlice * nProcessed_);
218 rdfStream << z <<
"\t" << binCharge <<
"\n";
222 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
223 "ChargeZ: unable to open %s\n", outputFilename_.c_str());
224 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)