45#include "applications/staticProps/TetrahedralityParamDens.hpp"
53#include "utils/simError.h"
57 TetrahedralityParamDens::TetrahedralityParamDens(SimInfo* info,
58 const std::string& filename,
59 const std::string& sele1,
60 const std::string& sele2,
61 double rCut,
int ndensbins) :
62 StaticAnalyser(info, filename, ndensbins),
63 selectionScript1_(sele1), selectionScript2_(sele2), seleMan1_(info),
64 seleMan2_(info), evaluator1_(info), evaluator2_(info), rCut_(rCut) {
65 evaluator1_.loadScriptString(sele1);
66 if (!evaluator1_.isDynamic()) {
67 seleMan1_.setSelectionSet(evaluator1_.evaluate());
69 evaluator2_.loadScriptString(sele2);
70 if (!evaluator2_.isDynamic()) {
71 seleMan2_.setSelectionSet(evaluator2_.evaluate());
77 deltaQ_ = (MaxQ_ - MinQ_) / nBins_;
83 sliceCount_.resize(nBins_);
84 std::fill(sliceCount_.begin(), sliceCount_.end(), 0);
86 setOutputName(
getPrefix(filename) +
".Qdens");
89 void TetrahedralityParamDens::process() {
96 Vector3d ri, rj, rk, rik, rkj;
100 std::vector<std::pair<RealType, StuntDouble*>> myNeighbors;
103 bool usePeriodicBoundaryConditions_ =
104 info_->getSimParams()->getUsePeriodicBoundaryConditions();
106 DumpReader reader(info_, dumpFilename_);
107 int nFrames = reader.getNFrames();
109 for (
int istep = 0; istep < nFrames; istep += step_) {
110 reader.readFrame(istep);
111 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
118 if (evaluator1_.isDynamic()) {
119 seleMan1_.setSelectionSet(evaluator1_.evaluate());
122 if (evaluator2_.isDynamic()) {
123 seleMan2_.setSelectionSet(evaluator2_.evaluate());
127 for (sd = seleMan1_.beginSelected(isd1); sd != NULL;
128 sd = seleMan1_.nextSelected(isd1)) {
129 myIndex = sd->getGlobalIndex();
134 for (sd2 = seleMan2_.beginSelected(isd2); sd2 != NULL;
135 sd2 = seleMan2_.nextSelected(isd2)) {
136 if (sd2->getGlobalIndex() != myIndex) {
137 vec = sd->getPos() - sd2->getPos();
139 if (usePeriodicBoundaryConditions_)
140 currentSnapshot_->wrapVector(vec);
147 myNeighbors.push_back(std::make_pair(r, sd2));
148 if (myIndex == 513) {
156 std::sort(myNeighbors.begin(), myNeighbors.end());
160 int nbors = myNeighbors.size() > 4 ? 4 : myNeighbors.size();
161 int nang = int(0.5 * (nbors * (nbors - 1)));
167 for (
int i = 0; i < nbors - 1; i++) {
168 sdi = myNeighbors[i].second;
171 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(rik);
175 for (
int j = i + 1; j < nbors; j++) {
176 sdj = myNeighbors[j].second;
179 if (usePeriodicBoundaryConditions_)
180 currentSnapshot_->wrapVector(rkj);
183 cospsi =
dot(rik, rkj);
187 Qk -= (pow(cospsi + 1.0 / 3.0, 2) * 2.25 / nang);
200 int binNo = int((Qk - MinQ_) / deltaQ_);
202 if (binNo <
int(sliceCount_.size()) && binNo >= 0) {
203 sliceCount_[binNo] += 1;
205 std::cerr <<
"binNo = " << binNo <<
" Qk = " << Qk <<
"\n";
217 void TetrahedralityParamDens::writeQdens() {
218 std::ofstream qdensstream(outputFilename_.c_str());
219 if (qdensstream.is_open()) {
220 qdensstream <<
"#Tetrahedrality Parameters \n";
221 qdensstream <<
"#nMolecules:\t" << count_ <<
" \n";
222 qdensstream <<
"#selection 1: (" << selectionScript1_ <<
")\n";
223 qdensstream <<
"#selection 2: (" << selectionScript2_ <<
")\n";
224 qdensstream <<
"#Qk\tfractional probability \n";
226 for (
unsigned int i = 0; i < sliceCount_.size(); ++i) {
227 RealType q = MinQ_ + (i + 0.5) * deltaQ_;
229 qdensstream << q <<
"\t" << sliceCount_[i] / RealType(count_) <<
"\n";
234 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
235 "TetrahedralityParamDens: unable to open %s\n",
236 outputFilename_.c_str());
237 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)