48#include "applications/staticProps/HBondGeometric.hpp"
54#include "utils/Constants.hpp"
55#include "utils/simError.h"
59 HBondGeometric::HBondGeometric(
SimInfo* info,
const std::string& filename,
60 const std::string& sele1,
61 const std::string& sele2,
double rCut,
62 double thetaCut,
int nbins) :
64 selectionScript1_(sele1), seleMan1_(info), evaluator1_(info),
65 selectionScript2_(sele2), seleMan2_(info), evaluator2_(info) {
66 setOutputName(
getPrefix(filename) +
".hbg");
68 ff_ = info_->getForceField();
70 evaluator1_.loadScriptString(sele1);
71 if (!evaluator1_.isDynamic()) {
72 seleMan1_.setSelectionSet(evaluator1_.evaluate());
74 evaluator2_.loadScriptString(sele2);
75 if (!evaluator2_.isDynamic()) {
76 seleMan2_.setSelectionSet(evaluator2_.evaluate());
84 nHBonds_.resize(nBins_);
85 nDonor_.resize(nBins_);
86 nAcceptor_.resize(nBins_);
88 initializeHistogram();
91 void HBondGeometric::initializeHistogram() {
92 std::fill(nHBonds_.begin(), nHBonds_.end(), 0);
93 std::fill(nDonor_.begin(), nDonor_.end(), 0);
94 std::fill(nAcceptor_.begin(), nAcceptor_.end(), 0);
98 void HBondGeometric::process() {
101 Molecule::HBondDonor* hbd1;
102 Molecule::HBondDonor* hbd2;
103 std::vector<Molecule::HBondDonor*>::iterator hbdi;
104 std::vector<Molecule::HBondDonor*>::iterator hbdj;
105 std::vector<Atom*>::iterator hbai;
106 std::vector<Atom*>::iterator hbaj;
114 RealType DAdist, DHdist, theta, ctheta;
118 DumpReader reader(info_, dumpFilename_);
119 int nFrames = reader.getNFrames();
122 for (
int istep = 0; istep < nFrames; istep += step_) {
123 reader.readFrame(istep);
125 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
127 if (evaluator1_.isDynamic()) {
128 seleMan1_.setSelectionSet(evaluator1_.evaluate());
130 if (evaluator2_.isDynamic()) {
131 seleMan2_.setSelectionSet(evaluator2_.evaluate());
134 for (mol1 = seleMan1_.beginSelectedMolecule(ii); mol1 != NULL;
135 mol1 = seleMan1_.nextSelectedMolecule(ii)) {
141 for (mol2 = seleMan2_.beginSelectedMolecule(jj); mol2 != NULL;
142 mol2 = seleMan2_.nextSelectedMolecule(jj)) {
144 for (hbd1 = mol1->beginHBondDonor(hbdi); hbd1 != NULL;
145 hbd1 = mol1->nextHBondDonor(hbdi)) {
146 dPos = hbd1->donorAtom->getPos();
147 hPos = hbd1->donatedHydrogen->getPos();
149 currentSnapshot_->wrapVector(DH);
150 DHdist = DH.length();
153 for (hba2 = mol2->beginHBondAcceptor(hbaj); hba2 != NULL;
154 hba2 = mol2->nextHBondAcceptor(hbaj)) {
155 aPos = hba2->getPos();
157 currentSnapshot_->wrapVector(DA);
158 DAdist = DA.length();
162 if (DAdist < rCut_) {
163 ctheta =
dot(DH, DA) / (DHdist * DAdist);
164 theta = acos(ctheta) * 180.0 / Constants::PI;
167 if (theta < thetaCut_) {
177 for (hba1 = mol1->beginHBondAcceptor(hbai); hba1 != NULL;
178 hba1 = mol1->nextHBondAcceptor(hbai)) {
179 aPos = hba1->getPos();
182 for (hbd2 = mol2->beginHBondDonor(hbdj); hbd2 != NULL;
183 hbd2 = mol2->nextHBondDonor(hbdj)) {
184 dPos = hbd2->donorAtom->getPos();
187 currentSnapshot_->wrapVector(DA);
188 DAdist = DA.length();
192 if (DAdist < rCut_) {
193 hPos = hbd2->donatedHydrogen->getPos();
195 currentSnapshot_->wrapVector(DH);
196 DHdist = DH.length();
197 ctheta =
dot(DH, DA) / (DHdist * DAdist);
198 theta = acos(ctheta) * 180.0 / Constants::PI;
200 if (theta < thetaCut_) {
209 collectHistogram(nHB, nA, nD);
215 void HBondGeometric::collectHistogram(
int nHB,
int nA,
int nD) {
222 void HBondGeometric::writeHistogram() {
223 std::ofstream osq(getOutputFileName().c_str());
226 osq <<
"# HydrogenBonding Statistics\n";
227 osq <<
"# selection1: (" << selectionScript1_ <<
")"
228 <<
"\tselection2: (" << selectionScript2_ <<
")\n";
229 osq <<
"# molecules in selection1: " << nSelected_ <<
"\n";
231 "nHBonds\tnAcceptor\tnDonor\tp(nHBonds)\tp(nAcceptor)\tp(nDonor)"
234 for (
int i = 0; i < nBins_; ++i) {
236 osq <<
"\t" << nHBonds_[i];
237 osq <<
"\t" << nAcceptor_[i];
238 osq <<
"\t" << nDonor_[i];
239 osq <<
"\t" << (RealType)(nHBonds_[i]) / nSelected_;
240 osq <<
"\t" << (RealType)(nAcceptor_[i]) / nSelected_;
241 osq <<
"\t" << (RealType)(nDonor_[i]) / nSelected_;
247 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
248 "HBondGeometric: unable to open %s\n",
249 (getOutputFileName() +
"q").c_str());
250 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)