48#include "applications/staticProps/TranslationalOrderParamZ.hpp"
56#include "utils/simError.h"
60 TranslationalOrderParamZ::TranslationalOrderParamZ(
61 SimInfo* info,
const std::string& filename,
const std::string& sele1,
62 const std::string& sele2,
double rCut,
int nrbins,
int nzbins,
63 RealType len, RealType zlen,
int axis) :
65 rCut_(rCut), nZBins_(nzbins), len_(len), zLen_(zlen), axis_(axis) {
66 setOutputName(
getPrefix(filename) +
".Tz");
68 deltaR_ = len_ / (double)nBins_;
69 deltaZ_ = zLen_ / (double)nZBins_;
71 histogram_.resize(nBins_);
72 avgGofr_.resize(nBins_);
73 for (
unsigned int i = 0; i < nBins_; ++i) {
74 histogram_[i].resize(nZBins_);
75 avgGofr_[i].resize(nZBins_);
83 xaxis_ = (axis_ + 1) % 3;
84 yaxis_ = (axis_ + 2) % 3;
101 void TranslationalOrderParamZ::preProcess() {
102 for (
unsigned int i = 0; i < avgGofr_.size(); ++i) {
103 std::fill(avgGofr_[i].begin(), avgGofr_[i].end(), 0);
105 std::fill(Tz_.begin(), Tz_.end(), 0);
108 void TranslationalOrderParamZ::initializeHistogram() {
109 for (
unsigned int i = 0; i < histogram_.size(); ++i) {
110 std::fill(histogram_[i].begin(), histogram_[i].end(), 0);
112 Mat3x3d hmat = currentSnapshot_->getHmat();
113 zBox_.push_back(hmat(axis_, axis_));
116 void TranslationalOrderParamZ::collectHistogram(StuntDouble* sd1,
118 if (sd1 == sd2) {
return; }
120 bool usePeriodicBoundaryConditions_ =
121 info_->getSimParams()->getUsePeriodicBoundaryConditions();
122 RealType boxZ = zBox_.back();
124 Vector3d pos1 = sd1->getPos();
125 Vector3d pos2 = sd2->getPos();
126 Vector3d r12 = pos2 - pos1;
127 if (usePeriodicBoundaryConditions_) {
128 currentSnapshot_->wrapVector(r12);
129 currentSnapshot_->wrapVector(pos1);
130 currentSnapshot_->wrapVector(pos2);
135 if (distance < len_) {
136 int whichBin = int(distance / deltaR_);
137 int zBin1 = int(nZBins_ * (0.5 * boxZ + pos1[axis_]) / boxZ);
138 int zBin2 = int(nZBins_ * (0.5 * boxZ + pos2[axis_]) / boxZ);
140 histogram_[whichBin][zBin1] += 1;
141 histogram_[whichBin][zBin2] += 1;
145 void TranslationalOrderParamZ::processHistogram() {
146 int nPairs = getNPairs();
148 info_->getSnapshotManager()->getCurrentSnapshot()->getVolume();
149 RealType pairDensity = 2 * nPairs / volume;
151 for (
unsigned int i = 0; i < histogram_.size(); ++i) {
152 RealType rLower = i * deltaR_;
153 RealType rUpper = rLower + deltaR_;
155 4.0 * Constants::PI * (pow(rUpper, 3) - pow(rLower, 3)) / 3.0;
156 RealType nIdeal = volSlice * pairDensity / nZBins_;
158 for (
unsigned int j = 0; j < histogram_[i].size(); ++j) {
159 avgGofr_[i][j] += histogram_[i][j] / nIdeal;
164 void TranslationalOrderParamZ::postProcess() {
165 for (
unsigned int i = 0; i < avgGofr_.size(); ++i) {
166 for (
unsigned int j = 0; j < avgGofr_[i].size(); ++j) {
167 avgGofr_[i][j] /= nProcessed_;
171 for (
unsigned int i = 0; i < avgGofr_.size(); ++i) {
172 RealType rLower = i * deltaR_;
173 RealType rUpper = rLower + deltaR_;
175 for (
unsigned int j = 0; j < avgGofr_[i].size(); ++j) {
176 if (rUpper < rCut_) Tz_[j] += std::fabs(avgGofr_[i][j] - 1.0) * deltaR_;
181 for (
unsigned int j = 0; j < Tz_.size(); ++j) {
186 void TranslationalOrderParamZ::writeRdf() {
190 for (std::vector<RealType>::iterator j = zBox_.begin(); j != zBox_.end();
194 RealType zAve = zSum / zBox_.size();
196 std::ofstream tZstream(outputFilename_.c_str());
197 if (tZstream.is_open()) {
198 tZstream <<
"#Translational Order Parameters (" << axisLabel_ <<
")\n";
200 tZstream <<
"#nFrames:\t" << zBox_.size() <<
"\n";
201 tZstream <<
"#selection 1: (" << selectionScript1_ <<
")\n";
202 tZstream <<
"#selection 2: (" << selectionScript2_ <<
")\n";
203 tZstream <<
"#" << axisLabel_ <<
"\tT\n";
214 for (
unsigned int i = 0; i < Tz_.size(); ++i) {
215 RealType z = zAve * (i + 0.5) / Tz_.size();
216 tZstream << z <<
"\t" << Tz_[i] <<
"\n";
220 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
221 "TranslationalOrderParamZ: unable to open %s\n",
222 outputFilename_.c_str());
223 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.