45#include "applications/staticProps/GofZ.hpp"
50#include "utils/simError.h"
54 GofZ::GofZ(SimInfo* info,
const std::string& filename,
55 const std::string& sele1,
const std::string& sele2, RealType len,
56 RealType maxz,
int nrbins,
int axis) :
57 RadialDistrFunc(info, filename, sele1, sele2, nrbins),
59 deltaZ_ = maxz / nBins_;
62 histogram_.resize(nBins_);
63 avgGofz_.resize(nBins_);
65 setOutputName(
getPrefix(filename) +
".gofz");
82 void GofZ::preProcess() { std::fill(avgGofz_.begin(), avgGofz_.end(), 0.0); }
84 void GofZ::initializeHistogram() {
85 std::fill(histogram_.begin(), histogram_.end(), 0);
88 void GofZ::processHistogram() {
89 int nPairs = getNPairs();
91 info_->getSnapshotManager()->getCurrentSnapshot()->getVolume();
92 RealType pairDensity = nPairs / volume * 2.0;
93 RealType pairConstant = (2.0 * Constants::PI * pairDensity);
95 for (
unsigned int i = 0; i < histogram_.size(); ++i) {
96 RealType zLower = i * deltaZ_;
97 RealType zUpper = zLower + deltaZ_;
98 RealType cylSlice = (zUpper - zLower) * rC_ * rC_;
99 RealType nIdeal = cylSlice * pairConstant;
101 avgGofz_[i] += histogram_[i] / nIdeal;
105 void GofZ::collectHistogram(StuntDouble* sd1, StuntDouble* sd2) {
106 if (sd1 == sd2) {
return; }
107 bool usePeriodicBoundaryConditions_ =
108 info_->getSimParams()->getUsePeriodicBoundaryConditions();
110 Vector3d pos1 = sd1->getPos();
111 Vector3d pos2 = sd2->getPos();
112 Vector3d r12 = pos2 - pos1;
113 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(r12);
116 RealType z2 = r12[axis_] * r12[axis_];
117 RealType xydist = sqrt(distance * distance - z2);
120 RealType thisZ = abs(r12[axis_]);
121 int whichBin = int(thisZ / deltaZ_);
122 if (whichBin <
int(nBins_)) histogram_[whichBin] += 2;
126 void GofZ::writeRdf() {
127 std::ofstream rdfStream(outputFilename_.c_str());
128 if (rdfStream.is_open()) {
129 rdfStream <<
"#" << axisLabel_ <<
"-separation distribution function\n";
130 rdfStream <<
"#selection1: (" << selectionScript1_ <<
")\t";
131 rdfStream <<
"selection2: (" << selectionScript2_ <<
")\n";
132 rdfStream <<
"#r\tcorrValue\n";
133 for (
unsigned int i = 0; i < avgGofz_.size(); ++i) {
134 RealType z = deltaZ_ * (i + 0.5);
135 rdfStream << z <<
"\t" << avgGofz_[i] / nProcessed_ <<
"\n";
138 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
139 "GofZ: unable to open %s\n", outputFilename_.c_str());
140 painCave.isFatal = 1;
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.