48#include "applications/staticProps/TetrahedralityParamZ.hpp"
56#include "utils/simError.h"
60 TetrahedralityParamZ::TetrahedralityParamZ(
61 SimInfo* info,
const std::string& filename,
const std::string& sele1,
62 const std::string& sele2,
double rCut,
int nzbins,
int axis) :
64 selectionScript1_(sele1), selectionScript2_(sele2), seleMan1_(info),
65 seleMan2_(info), evaluator1_(info), evaluator2_(info), axis_(axis) {
66 evaluator1_.loadScriptString(sele1);
67 if (!evaluator1_.isDynamic()) {
68 seleMan1_.setSelectionSet(evaluator1_.evaluate());
70 evaluator2_.loadScriptString(sele2);
71 if (!evaluator2_.isDynamic()) {
72 seleMan2_.setSelectionSet(evaluator2_.evaluate());
92 sliceQ_.resize(nBins_);
93 sliceQ2_.resize(nBins_);
94 sliceCount_.resize(nBins_);
95 std::fill(sliceQ_.begin(), sliceQ_.end(), 0.0);
96 std::fill(sliceQ2_.begin(), sliceQ2_.end(), 0.0);
97 std::fill(sliceCount_.begin(), sliceCount_.end(), 0);
99 setOutputName(
getPrefix(filename) +
".Qz");
102 void TetrahedralityParamZ::process() {
109 Vector3d ri, rj, rk, rik, rkj;
113 std::vector<std::pair<RealType, StuntDouble*>> myNeighbors;
116 bool usePeriodicBoundaryConditions_ =
117 info_->getSimParams()->getUsePeriodicBoundaryConditions();
119 DumpReader reader(info_, dumpFilename_);
120 int nFrames = reader.getNFrames();
122 for (
int istep = 0; istep < nFrames; istep += step_) {
123 reader.readFrame(istep);
124 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
126 Mat3x3d hmat = currentSnapshot_->getHmat();
127 zBox_.push_back(hmat(axis_, axis_));
129 RealType halfBoxZ_ = hmat(axis_, axis_) / 2.0;
131 if (evaluator1_.isDynamic()) {
132 seleMan1_.setSelectionSet(evaluator1_.evaluate());
135 if (evaluator2_.isDynamic()) {
136 seleMan2_.setSelectionSet(evaluator2_.evaluate());
140 for (sd = seleMan1_.beginSelected(isd1); sd != NULL;
141 sd = seleMan1_.nextSelected(isd1)) {
142 myIndex = sd->getGlobalIndex();
147 for (sd2 = seleMan2_.beginSelected(isd2); sd2 != NULL;
148 sd2 = seleMan2_.nextSelected(isd2)) {
149 if (sd2->getGlobalIndex() != myIndex) {
150 vec = sd->getPos() - sd2->getPos();
152 if (usePeriodicBoundaryConditions_)
153 currentSnapshot_->wrapVector(vec);
159 if (r < rCut_) { myNeighbors.push_back(std::make_pair(r, sd2)); }
164 std::sort(myNeighbors.begin(), myNeighbors.end());
168 int nbors = myNeighbors.size() > 4 ? 4 : myNeighbors.size();
169 int nang = int(0.5 * (nbors * (nbors - 1)));
173 for (
int i = 0; i < nbors - 1; i++) {
174 sdi = myNeighbors[i].second;
177 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(rik);
181 for (
int j = i + 1; j < nbors; j++) {
182 sdj = myNeighbors[j].second;
185 if (usePeriodicBoundaryConditions_)
186 currentSnapshot_->wrapVector(rkj);
189 cospsi =
dot(rik, rkj);
193 Qk -= (pow(cospsi + 1.0 / 3.0, 2) * 2.25 / nang);
198 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(rk);
201 int(nBins_ * (halfBoxZ_ + rk[axis_]) / hmat(axis_, axis_));
202 sliceQ_[binNo] += Qk;
203 sliceQ2_[binNo] += Qk * Qk;
204 sliceCount_[binNo] += 1;
211 void TetrahedralityParamZ::writeQz() {
215 for (std::vector<RealType>::iterator j = zBox_.begin(); j != zBox_.end();
219 RealType zAve = zSum / zBox_.size();
221 std::ofstream qZstream(outputFilename_.c_str());
222 if (qZstream.is_open()) {
223 qZstream <<
"#Tetrahedrality Parameters (" << axisLabel_ <<
")\n";
225 qZstream <<
"#nFrames:\t" << zBox_.size() <<
"\n";
226 qZstream <<
"#selection 1: (" << selectionScript1_ <<
")\n";
227 qZstream <<
"#selection 2: (" << selectionScript2_ <<
")\n";
228 qZstream <<
"#" << axisLabel_ <<
"\tQk\n";
229 for (
unsigned int i = 0; i < sliceQ_.size(); ++i) {
230 RealType z = zAve * (i + 0.5) / sliceQ_.size();
231 if (sliceCount_[i] != 0) {
232 RealType mean = sliceQ_[i] / sliceCount_[i];
233 RealType stdDev = sqrt(sliceQ2_[i] / sliceCount_[i] - mean * mean);
234 if (sliceCount_[i] == 1) {
235 qZstream << z <<
"\t" << mean <<
"\n";
237 RealType e95 = 1.96 * stdDev / sqrt(sliceCount_[i] - 1);
238 qZstream << z <<
"\t" << mean <<
"\t" << e95 <<
"\n";
244 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
245 "TetrahedralityParamZ: unable to open %s\n",
246 outputFilename_.c_str());
247 painCave.isFatal = 1;
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.
Real dot(const DynamicVector< Real > &v1, const DynamicVector< Real > &v2)
Returns the dot product of two DynamicVectors.
std::string getPrefix(const std::string &str)