45#include "applications/staticProps/ChargeR.hpp"
50#include "brains/Thermo.hpp"
53#include "types/FixedChargeAdapter.hpp"
54#include "types/FluctuatingChargeAdapter.hpp"
55#include "utils/simError.h"
59 ChargeR::ChargeR(
SimInfo* info,
const std::string& filename,
60 const std::string& sele, RealType len,
int nrbins) :
62 selectionScript_(sele), evaluator_(info), seleMan_(info), thermo_(info),
64 evaluator_.loadScriptString(sele);
65 if (!evaluator_.isDynamic()) {
66 seleMan_.setSelectionSet(evaluator_.evaluate());
69 deltaR_ = len_ / nBins_;
73 sliceSDLists_.resize(nBins_);
74 sliceSDCount_.resize(nBins_);
75 std::fill(sliceSDCount_.begin(), sliceSDCount_.end(), 0);
77 chargeR_.resize(nBins_);
78 setOutputName(
getPrefix(filename) +
".ChargeR");
79 std::stringstream params;
80 params <<
" len = " << len_ <<
", nrbins = " << nBins_;
81 const std::string paramString = params.str();
82 setParameterString(paramString);
85 void ChargeR::process() {
90 int nFrames = reader.getNFrames();
91 nProcessed_ = nFrames / step_;
93 for (
int istep = 0; istep < nFrames; istep += step_) {
94 reader.readFrame(istep);
97 for (
unsigned int i = 0; i < nBins_; i++) {
98 sliceSDLists_[i].clear();
102 seleMan_.setSelectionSet(evaluator_.evaluate());
112 int binNo = int(
distance / deltaR_);
113 sliceSDLists_[binNo].push_back(sd);
114 sliceSDCount_[binNo]++;
119 for (
unsigned int i = 0; i < nBins_; i++) {
121 for (
unsigned int k = 0; k < sliceSDLists_[i].size(); ++k) {
123 Atom* atom =
static_cast<Atom*
>(sliceSDLists_[i][k]);
127 if (sliceSDLists_[i][k]->isAtom()) {
129 if (fca.isFixedCharge()) { q += fca.getCharge(); }
132 if (fqa.isFluctuatingCharge()) { q += atom->
getFlucQPos(); }
145 void ChargeR::writeChargeR() {
146 std::ofstream rdfStream(outputFilename_.c_str());
147 if (rdfStream.is_open()) {
148 rdfStream <<
"#ChargeR "
150 rdfStream <<
"#selection: (" << selectionScript_ <<
")\n";
154 for (
unsigned int i = 0; i < chargeR_.size(); ++i) {
155 RealType rLower = i * deltaR_;
156 RealType rUpper = rLower + deltaR_;
158 (4.0 * Constants::PI) * (pow(rUpper, 3) - pow(rLower, 3)) / 3.0;
160 RealType r = deltaR_ * (i + 0.5);
162 binCharge = chargeR_[i] / (volShell * nProcessed_);
164 rdfStream << r <<
"\t" << binCharge <<
"\n";
168 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
169 "ChargeR: unable to open %s\n", outputFilename_.c_str());
170 painCave.isFatal = 1;
AtomType * getAtomType()
Returns the AtomType of this Atom.
AtomType is what OpenMD looks to for unchanging data about an atom.
bool isDynamic()
Tests if the result from evaluation of script is dynamic.
StuntDouble * nextSelected(int &i)
Finds the next selected StuntDouble in the selection.
StuntDouble * beginSelected(int &i)
Finds the first selected StuntDouble in the selection.
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
SnapshotManager * getSnapshotManager()
Returns the snapshot manager.
Snapshot * getCurrentSnapshot()
Returns the pointer of current snapshot.
"Don't move, or you're dead! Stand up! Captain, we've got them!"
Vector3d getPos()
Returns the current position of this stuntDouble.
RealType getFlucQPos()
Returns the current fluctuating charge of this stuntDouble.
Real length()
Returns the length of this vector.
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.