48#include "applications/staticProps/TetrahedralityParamDens.hpp"
56#include "utils/simError.h"
60 TetrahedralityParamDens::TetrahedralityParamDens(
SimInfo* info,
61 const std::string& filename,
62 const std::string& sele1,
63 const std::string& sele2,
64 double rCut,
int ndensbins) :
66 selectionScript1_(sele1), selectionScript2_(sele2), seleMan1_(info),
67 seleMan2_(info), evaluator1_(info), evaluator2_(info), rCut_(rCut) {
68 evaluator1_.loadScriptString(sele1);
69 if (!evaluator1_.isDynamic()) {
70 seleMan1_.setSelectionSet(evaluator1_.evaluate());
72 evaluator2_.loadScriptString(sele2);
73 if (!evaluator2_.isDynamic()) {
74 seleMan2_.setSelectionSet(evaluator2_.evaluate());
80 deltaQ_ = (MaxQ_ - MinQ_) / nBins_;
86 sliceCount_.resize(nBins_);
87 std::fill(sliceCount_.begin(), sliceCount_.end(), 0);
89 setOutputName(
getPrefix(filename) +
".Qdens");
92 void TetrahedralityParamDens::process() {
99 Vector3d ri, rj, rk, rik, rkj;
103 std::vector<std::pair<RealType, StuntDouble*>> myNeighbors;
106 bool usePeriodicBoundaryConditions_ =
107 info_->getSimParams()->getUsePeriodicBoundaryConditions();
109 DumpReader reader(info_, dumpFilename_);
110 int nFrames = reader.getNFrames();
112 for (
int istep = 0; istep < nFrames; istep += step_) {
113 reader.readFrame(istep);
114 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
121 if (evaluator1_.isDynamic()) {
122 seleMan1_.setSelectionSet(evaluator1_.evaluate());
125 if (evaluator2_.isDynamic()) {
126 seleMan2_.setSelectionSet(evaluator2_.evaluate());
130 for (sd = seleMan1_.beginSelected(isd1); sd != NULL;
131 sd = seleMan1_.nextSelected(isd1)) {
132 myIndex = sd->getGlobalIndex();
137 for (sd2 = seleMan2_.beginSelected(isd2); sd2 != NULL;
138 sd2 = seleMan2_.nextSelected(isd2)) {
139 if (sd2->getGlobalIndex() != myIndex) {
140 vec = sd->getPos() - sd2->getPos();
142 if (usePeriodicBoundaryConditions_)
143 currentSnapshot_->wrapVector(vec);
150 myNeighbors.push_back(std::make_pair(r, sd2));
151 if (myIndex == 513) {
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)));
170 for (
int i = 0; i < nbors - 1; i++) {
171 sdi = myNeighbors[i].second;
174 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(rik);
178 for (
int j = i + 1; j < nbors; j++) {
179 sdj = myNeighbors[j].second;
182 if (usePeriodicBoundaryConditions_)
183 currentSnapshot_->wrapVector(rkj);
186 cospsi =
dot(rik, rkj);
190 Qk -= (pow(cospsi + 1.0 / 3.0, 2) * 2.25 / nang);
203 int binNo = int((Qk - MinQ_) / deltaQ_);
205 if (binNo <
int(sliceCount_.size()) && binNo >= 0) {
206 sliceCount_[binNo] += 1;
208 std::cerr <<
"binNo = " << binNo <<
" Qk = " << Qk <<
"\n";
220 void TetrahedralityParamDens::writeQdens() {
221 std::ofstream qdensstream(outputFilename_.c_str());
222 if (qdensstream.is_open()) {
223 qdensstream <<
"#Tetrahedrality Parameters \n";
224 qdensstream <<
"#nMolecules:\t" << count_ <<
" \n";
225 qdensstream <<
"#selection 1: (" << selectionScript1_ <<
")\n";
226 qdensstream <<
"#selection 2: (" << selectionScript2_ <<
")\n";
227 qdensstream <<
"#Qk\tfractional probability \n";
229 for (
unsigned int i = 0; i < sliceCount_.size(); ++i) {
230 RealType q = MinQ_ + (i + 0.5) * deltaQ_;
232 qdensstream << q <<
"\t" << sliceCount_[i] / RealType(count_) <<
"\n";
237 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
238 "TetrahedralityParamDens: unable to open %s\n",
239 outputFilename_.c_str());
240 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)