50#include "applications/staticProps/CurrentDensity.hpp"
57#include "brains/Thermo.hpp"
60#include "types/FixedChargeAdapter.hpp"
61#include "types/FluctuatingChargeAdapter.hpp"
63#include "utils/simError.h"
67 CurrentDensity::CurrentDensity(
SimInfo* info,
const std::string& filename,
68 const std::string& sele,
int nbins,
int axis) :
70 selectionScript_(sele), evaluator_(info), seleMan_(info), thermo_(info),
72 evaluator_.loadScriptString(sele);
73 if (!evaluator_.isDynamic()) {
74 seleMan_.setSelectionSet(evaluator_.evaluate());
78 sliceSDLists_.resize(nBins_);
79 currentDensity_.resize(nBins_);
94 setOutputName(
getPrefix(filename) +
".Jc");
97 void CurrentDensity::process() {
101 bool usePeriodicBoundaryConditions_ =
102 info_->getSimParams()->getUsePeriodicBoundaryConditions();
105 int nFrames = reader.getNFrames();
106 nProcessed_ = nFrames / step_;
107 overallCurrentDensity_ = 0;
109 for (
int istep = 0; istep < nFrames; istep += step_) {
110 reader.readFrame(istep);
114 for (
unsigned int i = 0; i < nBins_; i++) {
115 sliceSDLists_[i].clear();
118 RealType sliceVolume = currentSnapshot_->getVolume() / nBins_;
120 zBox_.push_back(hmat(axis_, axis_));
123 seleMan_.setSelectionSet(evaluator_.evaluate());
132 if (usePeriodicBoundaryConditions_) {
135 int(nBins_ * (pos[axis_] / hmat(axis_, axis_) + 0.5)) % nBins_;
136 sliceSDLists_[binNo].push_back(sd);
141 for (
unsigned int i = 0; i < nBins_; i++) {
144 for (
unsigned int j = 0; j < sliceSDLists_[i].size(); ++j) {
146 Atom* atom =
static_cast<Atom*
>(sliceSDLists_[i][j]);
150 if (sliceSDLists_[i][j]->isAtom()) {
152 if (fca.isFixedCharge()) q = fca.getCharge();
155 if (fqa.isFluctuatingCharge()) q += atom->
getFlucQPos();
157 Vector3d vel = sliceSDLists_[i][j]->getVel();
158 binJc += q * (vel[axis_] - COMvel[axis_]);
163 currentDensity_[i] += binJc / sliceVolume;
164 overallCurrentDensity_ += currentDensity_[i];
168 writeCurrentDensity();
171 void CurrentDensity::writeCurrentDensity() {
173 std::vector<RealType>::iterator j;
175 for (j = zBox_.begin(); j != zBox_.end(); ++j) {
178 RealType zAve = zSum / zBox_.size();
180 std::ofstream rdfStream(outputFilename_.c_str());
181 if (rdfStream.is_open()) {
182 rdfStream <<
"#Current Density = "
183 << overallCurrentDensity_ / (nBins_ * nProcessed_)
184 <<
" e / Ang^2 / fs.\n";
185 rdfStream <<
"#J_c(" << axisLabel_ <<
")\n";
186 rdfStream <<
"#nFrames:\t" << nProcessed_ <<
"\n";
187 rdfStream <<
"#selection: (" << selectionScript_ <<
")\n";
188 rdfStream <<
"#" << axisLabel_ <<
"\tcurrent density\n";
190 for (
unsigned int i = 0; i < currentDensity_.size(); ++i) {
191 RealType z = zAve * (i + 0.5) / currentDensity_.size();
192 rdfStream << z <<
"\t" << currentDensity_[i] / nProcessed_ <<
"\n";
196 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
197 "CurrentDensity: unable to open %s\n", outputFilename_.c_str());
198 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.
Mat3x3d getHmat()
Returns the H-Matrix.
void wrapVector(Vector3d &v)
Wrapping the vector according to periodic boundary condition.
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.
Vector3d getComVel()
Returns the velocity of center of mass of the whole system.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
std::string getPrefix(const std::string &str)