45#include "applications/staticProps/HBondGeometric.hpp"
51#include "utils/Constants.hpp"
52#include "utils/simError.h"
56 HBondGeometric::HBondGeometric(SimInfo* info,
const std::string& filename,
57 const std::string& sele1,
58 const std::string& sele2,
double rCut,
59 double thetaCut,
int nbins) :
60 StaticAnalyser(info, filename, nbins),
61 selectionScript1_(sele1), seleMan1_(info), evaluator1_(info),
62 selectionScript2_(sele2), seleMan2_(info), evaluator2_(info) {
63 setOutputName(
getPrefix(filename) +
".hbg");
65 ff_ = info_->getForceField();
67 evaluator1_.loadScriptString(sele1);
68 if (!evaluator1_.isDynamic()) {
69 seleMan1_.setSelectionSet(evaluator1_.evaluate());
71 evaluator2_.loadScriptString(sele2);
72 if (!evaluator2_.isDynamic()) {
73 seleMan2_.setSelectionSet(evaluator2_.evaluate());
81 nHBonds_.resize(nBins_);
82 nDonor_.resize(nBins_);
83 nAcceptor_.resize(nBins_);
85 initializeHistogram();
88 void HBondGeometric::initializeHistogram() {
89 std::fill(nHBonds_.begin(), nHBonds_.end(), 0);
90 std::fill(nDonor_.begin(), nDonor_.end(), 0);
91 std::fill(nAcceptor_.begin(), nAcceptor_.end(), 0);
95 void HBondGeometric::process() {
98 Molecule::HBondDonor* hbd1;
99 Molecule::HBondDonor* hbd2;
100 std::vector<Molecule::HBondDonor*>::iterator hbdi;
101 std::vector<Molecule::HBondDonor*>::iterator hbdj;
102 std::vector<Atom*>::iterator hbai;
103 std::vector<Atom*>::iterator hbaj;
111 RealType DAdist, DHdist, theta, ctheta;
115 DumpReader reader(info_, dumpFilename_);
116 int nFrames = reader.getNFrames();
119 for (
int istep = 0; istep < nFrames; istep += step_) {
120 reader.readFrame(istep);
122 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
124 if (evaluator1_.isDynamic()) {
125 seleMan1_.setSelectionSet(evaluator1_.evaluate());
127 if (evaluator2_.isDynamic()) {
128 seleMan2_.setSelectionSet(evaluator2_.evaluate());
131 for (mol1 = seleMan1_.beginSelectedMolecule(ii); mol1 != NULL;
132 mol1 = seleMan1_.nextSelectedMolecule(ii)) {
138 for (mol2 = seleMan2_.beginSelectedMolecule(jj); mol2 != NULL;
139 mol2 = seleMan2_.nextSelectedMolecule(jj)) {
141 for (hbd1 = mol1->beginHBondDonor(hbdi); hbd1 != NULL;
142 hbd1 = mol1->nextHBondDonor(hbdi)) {
143 dPos = hbd1->donorAtom->getPos();
144 hPos = hbd1->donatedHydrogen->getPos();
146 currentSnapshot_->wrapVector(DH);
147 DHdist = DH.length();
150 for (hba2 = mol2->beginHBondAcceptor(hbaj); hba2 != NULL;
151 hba2 = mol2->nextHBondAcceptor(hbaj)) {
152 aPos = hba2->getPos();
154 currentSnapshot_->wrapVector(DA);
155 DAdist = DA.length();
159 if (DAdist < rCut_) {
160 ctheta =
dot(DH, DA) / (DHdist * DAdist);
161 theta = acos(ctheta) * 180.0 / Constants::PI;
164 if (theta < thetaCut_) {
174 for (hba1 = mol1->beginHBondAcceptor(hbai); hba1 != NULL;
175 hba1 = mol1->nextHBondAcceptor(hbai)) {
176 aPos = hba1->getPos();
179 for (hbd2 = mol2->beginHBondDonor(hbdj); hbd2 != NULL;
180 hbd2 = mol2->nextHBondDonor(hbdj)) {
181 dPos = hbd2->donorAtom->getPos();
184 currentSnapshot_->wrapVector(DA);
185 DAdist = DA.length();
189 if (DAdist < rCut_) {
190 hPos = hbd2->donatedHydrogen->getPos();
192 currentSnapshot_->wrapVector(DH);
193 DHdist = DH.length();
194 ctheta =
dot(DH, DA) / (DHdist * DAdist);
195 theta = acos(ctheta) * 180.0 / Constants::PI;
197 if (theta < thetaCut_) {
206 collectHistogram(nHB, nA, nD);
212 void HBondGeometric::collectHistogram(
int nHB,
int nA,
int nD) {
219 void HBondGeometric::writeHistogram() {
220 std::ofstream osq(getOutputFileName().c_str());
223 osq <<
"# HydrogenBonding Statistics\n";
224 osq <<
"# selection1: (" << selectionScript1_ <<
")"
225 <<
"\tselection2: (" << selectionScript2_ <<
")\n";
226 osq <<
"# molecules in selection1: " << nSelected_ <<
"\n";
228 "nHBonds\tnAcceptor\tnDonor\tp(nHBonds)\tp(nAcceptor)\tp(nDonor)"
231 for (
int i = 0; i < nBins_; ++i) {
233 osq <<
"\t" << nHBonds_[i];
234 osq <<
"\t" << nAcceptor_[i];
235 osq <<
"\t" << nDonor_[i];
236 osq <<
"\t" << (RealType)(nHBonds_[i]) / nSelected_;
237 osq <<
"\t" << (RealType)(nAcceptor_[i]) / nSelected_;
238 osq <<
"\t" << (RealType)(nDonor_[i]) / nSelected_;
244 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
245 "HBondGeometric: unable to open %s\n",
246 (getOutputFileName() +
"q").c_str());
247 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)