48#include "applications/staticProps/BondAngleDistribution.hpp"
52#include "utils/Constants.hpp"
53#include "utils/Revision.hpp"
54#include "utils/simError.h"
59 BondAngleDistribution::BondAngleDistribution(
SimInfo* info,
60 const string& filename,
61 const string& sele,
double rCut,
64 selectionScript_(sele), seleMan_(info), evaluator_(info) {
65 setAnalysisType(
"Bond Angle Distribution");
66 setOutputName(
getPrefix(filename) +
".bad");
68 evaluator_.loadScriptString(sele);
69 if (!evaluator_.isDynamic()) {
70 seleMan_.setSelectionSet(evaluator_.evaluate());
77 std::stringstream params;
78 params <<
" rcut = " << rCut_ <<
", nbins = " << nBins_;
79 const std::string paramString = params.str();
80 setParameterString(paramString);
84 deltaTheta_ = (180.0) / nBins_;
85 histogram_.resize(nBins_);
88 void BondAngleDistribution::initializeHistogram() {
89 for (
int bin = 0; bin < nBins_; bin++) {
94 void BondAngleDistribution::process() {
98 SimInfo::MoleculeIterator mi;
99 Molecule::AtomIterator ai;
102 std::vector<Vector3d> bondvec;
107 bool usePeriodicBoundaryConditions_ =
108 info_->getSimParams()->getUsePeriodicBoundaryConditions();
110 DumpReader reader(info_, dumpFilename_);
111 int nFrames = reader.getNFrames();
116 for (
int istep = 0; istep < nFrames; istep += step_) {
117 reader.readFrame(istep);
119 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
121 if (evaluator_.isDynamic()) {
122 seleMan_.setSelectionSet(evaluator_.evaluate());
127 for (sd = seleMan_.beginSelected(i); sd != NULL;
128 sd = seleMan_.nextSelected(i)) {
129 myIndex = sd->getGlobalIndex();
135 for (mol = info_->beginMolecule(mi); mol != NULL;
136 mol = info_->nextMolecule(mi)) {
137 for (atom = mol->beginAtom(ai); atom != NULL;
138 atom = mol->nextAtom(ai)) {
139 if (atom->getGlobalIndex() != myIndex) {
140 vec = sd->getPos() - atom->getPos();
142 if (usePeriodicBoundaryConditions_)
143 currentSnapshot_->wrapVector(vec);
153 bondvec.push_back(vec);
160 for (
int i = 0; i < nBonds - 1; i++) {
161 Vector3d vec1 = bondvec[i];
163 for (
int j = i + 1; j < nBonds; j++) {
164 Vector3d vec2 = bondvec[j];
168 RealType theta = acos(
dot(vec1, vec2)) * 180.0 / Constants::PI;
170 if (theta > 180.0) { theta = 360.0 - theta; }
171 int whichBin = int(theta / deltaTheta_);
173 histogram_[whichBin] += 2;
180 writeBondAngleDistribution();
183 void BondAngleDistribution::writeBondAngleDistribution() {
184 RealType norm = (RealType)nTotBonds_ * ((RealType)nTotBonds_ - 1.0) / 2.0;
186 std::ofstream ofs(getOutputFileName().c_str());
191 ofs <<
"# " << getAnalysisType() <<
"\n";
192 ofs <<
"# OpenMD " << r.getFullRevision() <<
"\n";
193 ofs <<
"# " << r.getBuildDate() <<
"\n";
194 ofs <<
"# selection script: \"" << selectionScript_ <<
"\"\n";
195 if (!paramString_.empty())
196 ofs <<
"# parameters: " << paramString_ <<
"\n";
199 for (
int i = 0; i < nBins_; ++i) {
200 RealType Thetaval = i * deltaTheta_;
202 ofs <<
"\t" << (RealType)histogram_[i] / norm / frameCounter_;
209 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
210 "BondAngleDistribution: unable to open %s\n",
211 (getOutputFileName() +
"q").c_str());
212 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)