48#include "applications/staticProps/GofR.hpp"
54#include "utils/Revision.hpp"
55#include "utils/simError.h"
59 GofR::GofR(
SimInfo* info,
const std::string& filename,
60 const std::string& sele1,
const std::string& sele2, RealType len,
64 setAnalysisType(
"Radial Distribution Function");
65 setOutputName(
getPrefix(filename) +
".gofr");
67 deltaR_ = len_ / nBins_;
69 histogram_.resize(nBins_);
70 avgGofr_.resize(nBins_);
71 sumGofr1_.resize(nBins_);
72 sumGofr2_.resize(nBins_);
73 std::stringstream params;
74 params <<
" len = " << len_ <<
", nrbins = " << nBins_;
75 const std::string paramString = params.str();
76 setParameterString(paramString);
79 void GofR::preProcess() {
80 std::fill(avgGofr_.begin(), avgGofr_.end(), 0.0);
81 std::fill(sumGofr1_.begin(), sumGofr1_.end(), 0.0);
82 std::fill(sumGofr2_.begin(), sumGofr2_.end(), 0.0);
85 void GofR::initializeHistogram() {
86 std::fill(histogram_.begin(), histogram_.end(), 0);
89 void GofR::processHistogram() {
90 int nPairs = getNPairs();
92 info_->getSnapshotManager()->getCurrentSnapshot()->getVolume();
93 RealType pairDensity = nPairs / volume * 2.0;
94 RealType pairConstant = (4.0 * Constants::PI * pairDensity) / 3.0;
96 for (
unsigned int i = 0; i < histogram_.size(); ++i) {
97 RealType rLower = i * deltaR_;
98 RealType rUpper = rLower + deltaR_;
100 (rUpper * rUpper * rUpper) - (rLower * rLower * rLower);
101 RealType nIdeal = volSlice * pairConstant;
103 avgGofr_[i] += histogram_[i] / nIdeal;
107 void GofR::postProcess() {
108 int nSelected1 = getNSelected1();
109 int nSelected2 = getNSelected2();
111 info_->getSnapshotManager()->getCurrentSnapshot()->getVolume();
112 RealType constant = (4.0 * Constants::PI) / (3.0 * volume);
115 for (
unsigned int i = 0; i < avgGofr_.size(); ++i) {
116 RealType rLower = i * deltaR_;
117 RealType rUpper = rLower + deltaR_;
119 sum += avgGofr_[i] * constant * (pow(rUpper, 3) - pow(rLower, 3));
120 sumGofr1_[i] = nSelected1 * sum;
121 sumGofr2_[i] = nSelected2 * sum;
125 void GofR::collectHistogram(StuntDouble* sd1, StuntDouble* sd2) {
126 if (sd1 == sd2) {
return; }
128 bool usePeriodicBoundaryConditions_ =
129 info_->getSimParams()->getUsePeriodicBoundaryConditions();
131 Vector3d pos1 = sd1->getPos();
132 Vector3d pos2 = sd2->getPos();
133 Vector3d r12 = pos2 - pos1;
134 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(r12);
138 if (distance < len_) {
139 int whichBin = int(distance / deltaR_);
140 histogram_[whichBin] += 2;
144 void GofR::writeRdf() {
145 std::ofstream ofs(outputFilename_.c_str());
148 ofs <<
"# " << getAnalysisType() <<
"\n";
149 ofs <<
"# OpenMD " << r.getFullRevision() <<
"\n";
150 ofs <<
"# " << r.getBuildDate() <<
"\n";
151 ofs <<
"# selection script1: \"" << selectionScript1_;
152 ofs <<
"\"\tselection script2: \"" << selectionScript2_ <<
"\"\n";
153 if (!paramString_.empty())
154 ofs <<
"# parameters: " << paramString_ <<
"\n";
156 ofs <<
"#r\tcorrValue\n";
157 for (
unsigned int i = 0; i < avgGofr_.size(); ++i) {
158 RealType r = deltaR_ * (i + 0.5);
159 ofs << r <<
"\t" << avgGofr_[i] / nProcessed_ <<
"\n";
162 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
163 "GofR: unable to open %s\n", outputFilename_.c_str());
164 painCave.isFatal = 1;
Radial Distribution Function.
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.