53#include "utils/Constants.hpp"
54#include "utils/simError.h"
58 HBondR::HBondR(SimInfo* info,
const std::string& filename,
59 const std::string& sele1,
const std::string& sele2,
60 const std::string& sele3,
double rCut, RealType len,
61 double thetaCut,
int nrbins) :
62 StaticAnalyser(info, filename, nrbins),
63 selectionScript1_(sele1), seleMan1_(info), evaluator1_(info),
64 selectionScript2_(sele2), seleMan2_(info), evaluator2_(info),
65 selectionScript3_(sele3), seleMan3_(info), evaluator3_(info), len_(len),
67 ff_ = info_->getForceField();
69 evaluator1_.loadScriptString(sele1);
70 if (!evaluator1_.isDynamic()) {
71 seleMan1_.setSelectionSet(evaluator1_.evaluate());
73 evaluator2_.loadScriptString(sele2);
74 if (!evaluator2_.isDynamic()) {
75 seleMan2_.setSelectionSet(evaluator2_.evaluate());
77 evaluator3_.loadScriptString(sele3);
78 if (!evaluator3_.isDynamic()) {
79 seleMan3_.setSelectionSet(evaluator3_.evaluate());
86 deltaR_ = len_ / nBins_;
90 nHBonds_.resize(nBins_);
91 nDonor_.resize(nBins_);
92 nAcceptor_.resize(nBins_);
93 sliceQ_.resize(nBins_);
94 sliceCount_.resize(nBins_);
95 std::fill(sliceQ_.begin(), sliceQ_.end(), 0.0);
96 std::fill(sliceCount_.begin(), sliceCount_.end(), 0);
98 setOutputName(
getPrefix(filename) +
".hbondr");
101 void HBondR::process() {
105 Molecule::HBondDonor* hbd1;
106 Molecule::HBondDonor* hbd2;
107 std::vector<Molecule::HBondDonor*>::iterator hbdi;
108 std::vector<Molecule::HBondDonor*>::iterator hbdj;
109 std::vector<Atom*>::iterator hbai;
110 std::vector<Atom*>::iterator hbaj;
121 RealType DAdist, DHdist, theta, ctheta;
125 DumpReader reader(info_, dumpFilename_);
126 int nFrames = reader.getNFrames();
129 for (
int istep = 0; istep < nFrames; istep += step_) {
130 reader.readFrame(istep);
131 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
133 if (evaluator1_.isDynamic()) {
134 seleMan1_.setSelectionSet(evaluator1_.evaluate());
137 if (evaluator2_.isDynamic()) {
138 seleMan2_.setSelectionSet(evaluator2_.evaluate());
141 if (evaluator3_.isDynamic()) {
142 seleMan3_.setSelectionSet(evaluator3_.evaluate());
145 for (mol1 = seleMan1_.beginSelectedMolecule(ii); mol1 != NULL;
146 mol1 = seleMan1_.nextSelectedMolecule(ii)) {
151 Vector3d mPos = mol1->getCom();
153 for (mol2 = seleMan2_.beginSelectedMolecule(jj); mol2 != NULL;
154 mol2 = seleMan2_.nextSelectedMolecule(jj)) {
156 for (hbd1 = mol1->beginHBondDonor(hbdi); hbd1 != NULL;
157 hbd1 = mol1->nextHBondDonor(hbdi)) {
158 dPos = hbd1->donorAtom->getPos();
159 hPos = hbd1->donatedHydrogen->getPos();
161 currentSnapshot_->wrapVector(DH);
165 for (hba2 = mol2->beginHBondAcceptor(hbaj); hba2 != NULL;
166 hba2 = mol2->nextHBondAcceptor(hbaj)) {
167 aPos = hba2->getPos();
169 currentSnapshot_->wrapVector(DA);
170 DAdist = DA.length();
174 if (DAdist < rCut_) {
175 ctheta =
dot(DH, DA) / (DHdist * DAdist);
176 theta = acos(ctheta) * 180.0 / Constants::PI;
179 if (theta < thetaCut_) {
189 for (hba1 = mol1->beginHBondAcceptor(hbai); hba1 != NULL;
190 hba1 = mol1->nextHBondAcceptor(hbai)) {
191 aPos = hba1->getPos();
194 for (hbd2 = mol2->beginHBondDonor(hbdj); hbd2 != NULL;
195 hbd2 = mol2->nextHBondDonor(hbdj)) {
196 dPos = hbd2->donorAtom->getPos();
199 currentSnapshot_->wrapVector(DA);
200 DAdist = DA.length();
204 if (DAdist < rCut_) {
205 hPos = hbd2->donatedHydrogen->getPos();
207 currentSnapshot_->wrapVector(DH);
208 DHdist = DH.length();
209 ctheta =
dot(DH, DA) / (DHdist * DAdist);
210 theta = acos(ctheta) * 180.0 / Constants::PI;
212 if (theta < thetaCut_) {
222 int binNo = int(r / deltaR_);
223 sliceQ_[binNo] += nHB;
224 sliceCount_[binNo] += 1;
230 void HBondR::writeDensityR() {
233 std::ofstream qRstream(outputFilename_.c_str());
234 if (qRstream.is_open()) {
235 qRstream <<
"# " << getAnalysisType() <<
"\n";
236 qRstream <<
"#selection 1: (" << selectionScript1_ <<
")\n";
237 qRstream <<
"#selection 2: (" << selectionScript2_ <<
")\n";
238 qRstream <<
"#selection 3: (" << selectionScript3_ <<
")\n";
239 if (!paramString_.empty())
240 qRstream <<
"# parameters: " << paramString_ <<
"\n";
242 qRstream <<
"#distance"
244 for (
unsigned int i = 0; i < sliceQ_.size(); ++i) {
245 RealType Rval = (i + 0.5) * deltaR_;
246 if (sliceCount_[i] != 0) {
247 qRstream << Rval <<
"\t" << sliceQ_[i] / (RealType)sliceCount_[i]
253 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
254 "HBondR: unable to open %s\n", outputFilename_.c_str());
255 painCave.isFatal = 1;
Real length()
Returns the length of this vector.
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)