45#include "applications/staticProps/TetrahedralityParamZ.hpp"
53#include "utils/simError.h"
57 TetrahedralityParamZ::TetrahedralityParamZ(
58 SimInfo* info,
const std::string& filename,
const std::string& sele1,
59 const std::string& sele2,
double rCut,
int nzbins,
int axis) :
60 StaticAnalyser(info, filename, nzbins),
61 selectionScript1_(sele1), selectionScript2_(sele2), seleMan1_(info),
62 seleMan2_(info), evaluator1_(info), evaluator2_(info), axis_(axis) {
63 evaluator1_.loadScriptString(sele1);
64 if (!evaluator1_.isDynamic()) {
65 seleMan1_.setSelectionSet(evaluator1_.evaluate());
67 evaluator2_.loadScriptString(sele2);
68 if (!evaluator2_.isDynamic()) {
69 seleMan2_.setSelectionSet(evaluator2_.evaluate());
89 sliceQ_.resize(nBins_);
90 sliceCount_.resize(nBins_);
91 std::fill(sliceQ_.begin(), sliceQ_.end(), 0.0);
92 std::fill(sliceCount_.begin(), sliceCount_.end(), 0);
94 setOutputName(
getPrefix(filename) +
".Qz");
97 void TetrahedralityParamZ::process() {
104 Vector3d ri, rj, rk, rik, rkj;
108 std::vector<std::pair<RealType, StuntDouble*>> myNeighbors;
111 bool usePeriodicBoundaryConditions_ =
112 info_->getSimParams()->getUsePeriodicBoundaryConditions();
114 DumpReader reader(info_, dumpFilename_);
115 int nFrames = reader.getNFrames();
117 for (
int istep = 0; istep < nFrames; istep += step_) {
118 reader.readFrame(istep);
119 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
121 Mat3x3d hmat = currentSnapshot_->getHmat();
122 zBox_.push_back(hmat(axis_, axis_));
124 RealType halfBoxZ_ = hmat(axis_, axis_) / 2.0;
126 if (evaluator1_.isDynamic()) {
127 seleMan1_.setSelectionSet(evaluator1_.evaluate());
130 if (evaluator2_.isDynamic()) {
131 seleMan2_.setSelectionSet(evaluator2_.evaluate());
135 for (sd = seleMan1_.beginSelected(isd1); sd != NULL;
136 sd = seleMan1_.nextSelected(isd1)) {
137 myIndex = sd->getGlobalIndex();
142 for (sd2 = seleMan2_.beginSelected(isd2); sd2 != NULL;
143 sd2 = seleMan2_.nextSelected(isd2)) {
144 if (sd2->getGlobalIndex() != myIndex) {
145 vec = sd->getPos() - sd2->getPos();
147 if (usePeriodicBoundaryConditions_)
148 currentSnapshot_->wrapVector(vec);
154 if (r < rCut_) { myNeighbors.push_back(std::make_pair(r, sd2)); }
159 std::sort(myNeighbors.begin(), myNeighbors.end());
163 int nbors = myNeighbors.size() > 4 ? 4 : myNeighbors.size();
164 int nang = int(0.5 * (nbors * (nbors - 1)));
168 for (
int i = 0; i < nbors - 1; i++) {
169 sdi = myNeighbors[i].second;
172 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(rik);
176 for (
int j = i + 1; j < nbors; j++) {
177 sdj = myNeighbors[j].second;
180 if (usePeriodicBoundaryConditions_)
181 currentSnapshot_->wrapVector(rkj);
184 cospsi =
dot(rik, rkj);
188 Qk -= (pow(cospsi + 1.0 / 3.0, 2) * 2.25 / nang);
193 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(rk);
196 int(nBins_ * (halfBoxZ_ + rk[axis_]) / hmat(axis_, axis_));
197 sliceQ_[binNo] += Qk;
198 sliceCount_[binNo] += 1;
205 void TetrahedralityParamZ::writeQz() {
209 for (std::vector<RealType>::iterator j = zBox_.begin(); j != zBox_.end();
213 RealType zAve = zSum / zBox_.size();
215 std::ofstream qZstream(outputFilename_.c_str());
216 if (qZstream.is_open()) {
217 qZstream <<
"#Tetrahedrality Parameters (" << axisLabel_ <<
")\n";
219 qZstream <<
"#nFrames:\t" << zBox_.size() <<
"\n";
220 qZstream <<
"#selection 1: (" << selectionScript1_ <<
")\n";
221 qZstream <<
"#selection 2: (" << selectionScript2_ <<
")\n";
222 qZstream <<
"#" << axisLabel_ <<
"\tQk\n";
223 for (
unsigned int i = 0; i < sliceQ_.size(); ++i) {
224 RealType z = zAve * (i + 0.5) / sliceQ_.size();
225 if (sliceCount_[i] != 0) {
226 qZstream << z <<
"\t" << sliceQ_[i] / sliceCount_[i] <<
"\n";
231 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
232 "TetrahedralityParamZ: unable to open %s\n",
233 outputFilename_.c_str());
234 painCave.isFatal = 1;
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)