45#include "applications/staticProps/TranslationalOrderParamZ.hpp"
53#include "utils/simError.h"
57 TranslationalOrderParamZ::TranslationalOrderParamZ(
58 SimInfo* info,
const std::string& filename,
const std::string& sele1,
59 const std::string& sele2,
double rCut,
int nrbins,
int nzbins,
60 RealType len, RealType zlen,
int axis) :
61 RadialDistrFunc(info, filename, sele1, sele2, nrbins),
62 rCut_(rCut), nZBins_(nzbins), len_(len), zLen_(zlen), axis_(axis) {
63 setOutputName(
getPrefix(filename) +
".Tz");
65 deltaR_ = len_ / (double)nBins_;
66 deltaZ_ = zLen_ / (double)nZBins_;
68 histogram_.resize(nBins_);
69 avgGofr_.resize(nBins_);
70 for (
unsigned int i = 0; i < nBins_; ++i) {
71 histogram_[i].resize(nZBins_);
72 avgGofr_[i].resize(nZBins_);
80 xaxis_ = (axis_ + 1) % 3;
81 yaxis_ = (axis_ + 2) % 3;
98 void TranslationalOrderParamZ::preProcess() {
99 for (
unsigned int i = 0; i < avgGofr_.size(); ++i) {
100 std::fill(avgGofr_[i].begin(), avgGofr_[i].end(), 0);
102 std::fill(Tz_.begin(), Tz_.end(), 0);
105 void TranslationalOrderParamZ::initializeHistogram() {
106 for (
unsigned int i = 0; i < histogram_.size(); ++i) {
107 std::fill(histogram_[i].begin(), histogram_[i].end(), 0);
109 Mat3x3d hmat = currentSnapshot_->getHmat();
110 zBox_.push_back(hmat(axis_, axis_));
113 void TranslationalOrderParamZ::collectHistogram(StuntDouble* sd1,
115 if (sd1 == sd2) {
return; }
117 bool usePeriodicBoundaryConditions_ =
118 info_->getSimParams()->getUsePeriodicBoundaryConditions();
119 RealType boxZ = zBox_.back();
121 Vector3d pos1 = sd1->getPos();
122 Vector3d pos2 = sd2->getPos();
123 Vector3d r12 = pos2 - pos1;
124 if (usePeriodicBoundaryConditions_) {
125 currentSnapshot_->wrapVector(r12);
126 currentSnapshot_->wrapVector(pos1);
127 currentSnapshot_->wrapVector(pos2);
132 if (distance < len_) {
133 int whichBin = int(distance / deltaR_);
134 int zBin1 = int(nZBins_ * (0.5 * boxZ + pos1[axis_]) / boxZ);
135 int zBin2 = int(nZBins_ * (0.5 * boxZ + pos2[axis_]) / boxZ);
137 histogram_[whichBin][zBin1] += 1;
138 histogram_[whichBin][zBin2] += 1;
142 void TranslationalOrderParamZ::processHistogram() {
143 int nPairs = getNPairs();
145 info_->getSnapshotManager()->getCurrentSnapshot()->getVolume();
146 RealType pairDensity = 2 * nPairs / volume;
148 for (
unsigned int i = 0; i < histogram_.size(); ++i) {
149 RealType rLower = i * deltaR_;
150 RealType rUpper = rLower + deltaR_;
152 4.0 * Constants::PI * (pow(rUpper, 3) - pow(rLower, 3)) / 3.0;
153 RealType nIdeal = volSlice * pairDensity / nZBins_;
155 for (
unsigned int j = 0; j < histogram_[i].size(); ++j) {
156 avgGofr_[i][j] += histogram_[i][j] / nIdeal;
161 void TranslationalOrderParamZ::postProcess() {
162 for (
unsigned int i = 0; i < avgGofr_.size(); ++i) {
163 for (
unsigned int j = 0; j < avgGofr_[i].size(); ++j) {
164 avgGofr_[i][j] /= nProcessed_;
168 for (
unsigned int i = 0; i < avgGofr_.size(); ++i) {
169 RealType rLower = i * deltaR_;
170 RealType rUpper = rLower + deltaR_;
172 for (
unsigned int j = 0; j < avgGofr_[i].size(); ++j) {
173 if (rUpper < rCut_) Tz_[j] += std::fabs(avgGofr_[i][j] - 1.0) * deltaR_;
178 for (
unsigned int j = 0; j < Tz_.size(); ++j) {
183 void TranslationalOrderParamZ::writeRdf() {
187 for (std::vector<RealType>::iterator j = zBox_.begin(); j != zBox_.end();
191 RealType zAve = zSum / zBox_.size();
193 std::ofstream tZstream(outputFilename_.c_str());
194 if (tZstream.is_open()) {
195 tZstream <<
"#Translational Order Parameters (" << axisLabel_ <<
")\n";
197 tZstream <<
"#nFrames:\t" << zBox_.size() <<
"\n";
198 tZstream <<
"#selection 1: (" << selectionScript1_ <<
")\n";
199 tZstream <<
"#selection 2: (" << selectionScript2_ <<
")\n";
200 tZstream <<
"#" << axisLabel_ <<
"\tT\n";
211 for (
unsigned int i = 0; i < Tz_.size(); ++i) {
212 RealType z = zAve * (i + 0.5) / Tz_.size();
213 tZstream << z <<
"\t" << Tz_[i] <<
"\n";
217 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
218 "TranslationalOrderParamZ: unable to open %s\n",
219 outputFilename_.c_str());
220 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.