45#include "HBondRvol.hpp"
53#include "utils/Constants.hpp"
54#include "utils/simError.h"
58 HBondRvol::HBondRvol(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_;
91 nHBonds_.resize(nBins_);
92 nDonor_.resize(nBins_);
93 nAcceptor_.resize(nBins_);
94 sliceQ_.resize(nBins_);
95 binvol_.resize(nBins_);
96 sliceCount_.resize(nBins_);
97 std::fill(sliceQ_.begin(), sliceQ_.end(), 0.0);
98 std::fill(sliceCount_.begin(), sliceCount_.end(), 0);
100 setOutputName(
getPrefix(filename) +
".hbondrvol");
103 void HBondRvol::process() {
107 Molecule::HBondDonor* hbd1;
108 Molecule::HBondDonor* hbd2;
109 std::vector<Molecule::HBondDonor*>::iterator hbdi;
110 std::vector<Molecule::HBondDonor*>::iterator hbdj;
111 std::vector<Atom*>::iterator hbai;
112 std::vector<Atom*>::iterator hbaj;
123 RealType DAdist, DHdist, theta, ctheta;
127 DumpReader reader(info_, dumpFilename_);
128 int nFrames = reader.getNFrames();
131 for (
int istep = 0; istep < nFrames; istep += step_) {
132 reader.readFrame(istep);
133 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
135 if (evaluator1_.isDynamic()) {
136 seleMan1_.setSelectionSet(evaluator1_.evaluate());
139 if (evaluator2_.isDynamic()) {
140 seleMan2_.setSelectionSet(evaluator2_.evaluate());
143 if (evaluator3_.isDynamic()) {
144 seleMan3_.setSelectionSet(evaluator3_.evaluate());
147 for (mol1 = seleMan1_.beginSelectedMolecule(ii); mol1 != NULL;
148 mol1 = seleMan1_.nextSelectedMolecule(ii)) {
153 Vector3d mPos = mol1->getCom();
155 for (mol2 = seleMan2_.beginSelectedMolecule(jj); mol2 != NULL;
156 mol2 = seleMan2_.nextSelectedMolecule(jj)) {
158 for (hbd1 = mol1->beginHBondDonor(hbdi); hbd1 != NULL;
159 hbd1 = mol1->nextHBondDonor(hbdi)) {
160 dPos = hbd1->donorAtom->getPos();
161 hPos = hbd1->donatedHydrogen->getPos();
163 currentSnapshot_->wrapVector(DH);
167 for (hba2 = mol2->beginHBondAcceptor(hbaj); hba2 != NULL;
168 hba2 = mol2->nextHBondAcceptor(hbaj)) {
169 aPos = hba2->getPos();
171 currentSnapshot_->wrapVector(DA);
172 DAdist = DA.length();
176 if (DAdist < rCut_) {
177 ctheta =
dot(DH, DA) / (DHdist * DAdist);
178 theta = acos(ctheta) * 180.0 / Constants::PI;
181 if (theta < thetaCut_) {
186 int binNo = int(r / deltaR_);
188 sliceCount_[binNo] += 1;
195 for (hba1 = mol1->beginHBondAcceptor(hbai); hba1 != NULL;
196 hba1 = mol1->nextHBondAcceptor(hbai)) {
197 aPos = hba1->getPos();
200 for (hbd2 = mol2->beginHBondDonor(hbdj); hbd2 != NULL;
201 hbd2 = mol2->nextHBondDonor(hbdj)) {
202 dPos = hbd2->donorAtom->getPos();
205 currentSnapshot_->wrapVector(DA);
206 DAdist = DA.length();
210 if (DAdist < rCut_) {
211 hPos = hbd2->donatedHydrogen->getPos();
213 currentSnapshot_->wrapVector(DH);
214 DHdist = DH.length();
215 ctheta =
dot(DH, DA) / (DHdist * DAdist);
216 theta = acos(ctheta) * 180.0 / Constants::PI;
218 if (theta < thetaCut_) {
223 int binNo = int(r / deltaR_);
225 sliceCount_[binNo] += 1;
236 void HBondRvol::writeDensityR() {
239 double pi = acos(-1.0);
240 DumpReader reader(info_, dumpFilename_);
241 int nFrames = reader.getNFrames();
242 std::ofstream qRstream(outputFilename_.c_str());
243 if (qRstream.is_open()) {
244 qRstream <<
"# " << getAnalysisType() <<
"\n";
245 qRstream <<
"#selection 1: (" << selectionScript1_ <<
")\n";
246 qRstream <<
"#selection 2: (" << selectionScript2_ <<
")\n";
247 qRstream <<
"#selection 3: (" << selectionScript3_ <<
")\n";
248 if (!paramString_.empty())
249 qRstream <<
"# parameters: " << paramString_ <<
"\n";
251 qRstream <<
"#distance"
253 for (
unsigned int i = 0; i < sliceQ_.size(); ++i) {
254 RealType Rval = (i + 0.5) * deltaR_;
255 binvol_[i] = (4 * pi * (Rval * Rval) * deltaR_);
256 if (sliceCount_[i] != 0 && binvol_[i] != 0) {
257 qRstream << Rval <<
"\t" << sliceQ_[i] / (binvol_[i]) / nFrames
260 qRstream << Rval <<
"\t" << 0 <<
"\n";
265 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
266 "HBondRvol: unable to open %s\n", outputFilename_.c_str());
267 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)