48#include "applications/staticProps/ChargeR.hpp"
53#include "brains/Thermo.hpp"
56#include "types/FixedChargeAdapter.hpp"
57#include "types/FluctuatingChargeAdapter.hpp"
58#include "utils/simError.h"
62 ChargeR::ChargeR(
SimInfo* info,
const std::string& filename,
63 const std::string& sele, RealType len,
int nrbins) :
65 selectionScript_(sele), evaluator_(info), seleMan_(info), thermo_(info),
67 evaluator_.loadScriptString(sele);
68 if (!evaluator_.isDynamic()) {
69 seleMan_.setSelectionSet(evaluator_.evaluate());
72 deltaR_ = len_ / nBins_;
76 sliceSDLists_.resize(nBins_);
77 sliceSDCount_.resize(nBins_);
78 std::fill(sliceSDCount_.begin(), sliceSDCount_.end(), 0);
80 chargeR_.resize(nBins_);
81 setOutputName(
getPrefix(filename) +
".ChargeR");
82 std::stringstream params;
83 params <<
" len = " << len_ <<
", nrbins = " << nBins_;
84 const std::string paramString = params.str();
85 setParameterString(paramString);
88 void ChargeR::process() {
92 DumpReader reader(info_, dumpFilename_);
93 int nFrames = reader.getNFrames();
94 nProcessed_ = nFrames / step_;
96 for (
int istep = 0; istep < nFrames; istep += step_) {
97 reader.readFrame(istep);
98 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
100 for (
unsigned int i = 0; i < nBins_; i++) {
101 sliceSDLists_[i].clear();
104 if (evaluator_.isDynamic()) {
105 seleMan_.setSelectionSet(evaluator_.evaluate());
109 for (sd = seleMan_.beginSelected(ii); sd != NULL;
110 sd = seleMan_.nextSelected(ii)) {
111 Vector3d pos = sd->getPos();
114 if (distance < len_) {
115 int binNo = int(distance / deltaR_);
116 sliceSDLists_[binNo].push_back(sd);
117 sliceSDCount_[binNo]++;
122 for (
unsigned int i = 0; i < nBins_; i++) {
124 for (
unsigned int k = 0; k < sliceSDLists_[i].size(); ++k) {
126 Atom* atom =
static_cast<Atom*
>(sliceSDLists_[i][k]);
128 AtomType* atomType = atom->getAtomType();
130 if (sliceSDLists_[i][k]->isAtom()) {
131 FixedChargeAdapter fca = FixedChargeAdapter(atomType);
132 if (fca.isFixedCharge()) { q += fca.getCharge(); }
134 FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atomType);
135 if (fqa.isFluctuatingCharge()) { q += atom->getFlucQPos(); }
148 void ChargeR::writeChargeR() {
149 std::ofstream rdfStream(outputFilename_.c_str());
150 if (rdfStream.is_open()) {
151 rdfStream <<
"#ChargeR "
153 rdfStream <<
"#selection: (" << selectionScript_ <<
")\n";
157 for (
unsigned int i = 0; i < chargeR_.size(); ++i) {
158 RealType rLower = i * deltaR_;
159 RealType rUpper = rLower + deltaR_;
161 (4.0 * Constants::PI) * (pow(rUpper, 3) - pow(rLower, 3)) / 3.0;
163 RealType r = deltaR_ * (i + 0.5);
165 binCharge = chargeR_[i] / (volShell * nProcessed_);
167 rdfStream << r <<
"\t" << binCharge <<
"\n";
171 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
172 "ChargeR: unable to open %s\n", outputFilename_.c_str());
173 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)
Real distance(const DynamicVector< Real > &v1, const DynamicVector< Real > &v2)
Returns the distance between two DynamicVectors.