45#include "applications/staticProps/BondAngleDistribution.hpp"
49#include "utils/Constants.hpp"
50#include "utils/Revision.hpp"
51#include "utils/simError.h"
56 BondAngleDistribution::BondAngleDistribution(SimInfo* info,
57 const string& filename,
58 const string& sele,
double rCut,
60 StaticAnalyser(info, filename, nbins),
61 selectionScript_(sele), seleMan_(info), evaluator_(info) {
62 setAnalysisType(
"Bond Angle Distribution");
63 setOutputName(
getPrefix(filename) +
".bad");
65 evaluator_.loadScriptString(sele);
66 if (!evaluator_.isDynamic()) {
67 seleMan_.setSelectionSet(evaluator_.evaluate());
74 std::stringstream params;
75 params <<
" rcut = " << rCut_ <<
", nbins = " << nBins_;
76 const std::string paramString = params.str();
77 setParameterString(paramString);
81 deltaTheta_ = (180.0) / nBins_;
82 histogram_.resize(nBins_);
85 void BondAngleDistribution::initializeHistogram() {
86 for (
int bin = 0; bin < nBins_; bin++) {
91 void BondAngleDistribution::process() {
95 SimInfo::MoleculeIterator mi;
96 Molecule::AtomIterator ai;
99 std::vector<Vector3d> bondvec;
104 bool usePeriodicBoundaryConditions_ =
105 info_->getSimParams()->getUsePeriodicBoundaryConditions();
107 DumpReader reader(info_, dumpFilename_);
108 int nFrames = reader.getNFrames();
113 for (
int istep = 0; istep < nFrames; istep += step_) {
114 reader.readFrame(istep);
116 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
118 if (evaluator_.isDynamic()) {
119 seleMan_.setSelectionSet(evaluator_.evaluate());
124 for (sd = seleMan_.beginSelected(i); sd != NULL;
125 sd = seleMan_.nextSelected(i)) {
126 myIndex = sd->getGlobalIndex();
132 for (mol = info_->beginMolecule(mi); mol != NULL;
133 mol = info_->nextMolecule(mi)) {
134 for (atom = mol->beginAtom(ai); atom != NULL;
135 atom = mol->nextAtom(ai)) {
136 if (atom->getGlobalIndex() != myIndex) {
137 vec = sd->getPos() - atom->getPos();
139 if (usePeriodicBoundaryConditions_)
140 currentSnapshot_->wrapVector(vec);
150 bondvec.push_back(vec);
157 for (
int i = 0; i < nBonds - 1; i++) {
158 Vector3d vec1 = bondvec[i];
160 for (
int j = i + 1; j < nBonds; j++) {
161 Vector3d vec2 = bondvec[j];
165 RealType theta = acos(
dot(vec1, vec2)) * 180.0 / Constants::PI;
167 if (theta > 180.0) { theta = 360.0 - theta; }
168 int whichBin = int(theta / deltaTheta_);
170 histogram_[whichBin] += 2;
177 writeBondAngleDistribution();
180 void BondAngleDistribution::writeBondAngleDistribution() {
181 RealType norm = (RealType)nTotBonds_ * ((RealType)nTotBonds_ - 1.0) / 2.0;
183 std::ofstream ofs(getOutputFileName().c_str());
188 ofs <<
"# " << getAnalysisType() <<
"\n";
189 ofs <<
"# OpenMD " << r.getFullRevision() <<
"\n";
190 ofs <<
"# " << r.getBuildDate() <<
"\n";
191 ofs <<
"# selection script: \"" << selectionScript_ <<
"\"\n";
192 if (!paramString_.empty())
193 ofs <<
"# parameters: " << paramString_ <<
"\n";
196 for (
int i = 0; i < nBins_; ++i) {
197 RealType Thetaval = i * deltaTheta_;
199 ofs <<
"\t" << (RealType)histogram_[i] / norm / frameCounter_;
206 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
207 "BondAngleDistribution: unable to open %s\n",
208 (getOutputFileName() +
"q").c_str());
209 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)