48#include "HBondRvol.hpp"
56#include "utils/Constants.hpp"
57#include "utils/simError.h"
61 HBondRvol::HBondRvol(
SimInfo* info,
const std::string& filename,
62 const std::string& sele1,
const std::string& sele2,
63 const std::string& sele3,
double rCut, RealType len,
64 double thetaCut,
int nrbins) :
66 selectionScript1_(sele1), seleMan1_(info), evaluator1_(info),
67 selectionScript2_(sele2), seleMan2_(info), evaluator2_(info),
68 selectionScript3_(sele3), seleMan3_(info), evaluator3_(info), len_(len),
70 ff_ = info_->getForceField();
72 evaluator1_.loadScriptString(sele1);
73 if (!evaluator1_.isDynamic()) {
74 seleMan1_.setSelectionSet(evaluator1_.evaluate());
76 evaluator2_.loadScriptString(sele2);
77 if (!evaluator2_.isDynamic()) {
78 seleMan2_.setSelectionSet(evaluator2_.evaluate());
80 evaluator3_.loadScriptString(sele3);
81 if (!evaluator3_.isDynamic()) {
82 seleMan3_.setSelectionSet(evaluator3_.evaluate());
89 deltaR_ = len_ / nBins_;
94 nHBonds_.resize(nBins_);
95 nDonor_.resize(nBins_);
96 nAcceptor_.resize(nBins_);
97 sliceQ_.resize(nBins_);
98 binvol_.resize(nBins_);
99 sliceCount_.resize(nBins_);
100 std::fill(sliceQ_.begin(), sliceQ_.end(), 0.0);
101 std::fill(sliceCount_.begin(), sliceCount_.end(), 0);
103 setOutputName(
getPrefix(filename) +
".hbondrvol");
106 void HBondRvol::process() {
110 Molecule::HBondDonor* hbd1;
111 Molecule::HBondDonor* hbd2;
112 std::vector<Molecule::HBondDonor*>::iterator hbdi;
113 std::vector<Molecule::HBondDonor*>::iterator hbdj;
114 std::vector<Atom*>::iterator hbai;
115 std::vector<Atom*>::iterator hbaj;
126 RealType DAdist, DHdist, theta, ctheta;
130 DumpReader reader(info_, dumpFilename_);
131 int nFrames = reader.getNFrames();
134 for (
int istep = 0; istep < nFrames; istep += step_) {
135 reader.readFrame(istep);
136 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
138 if (evaluator1_.isDynamic()) {
139 seleMan1_.setSelectionSet(evaluator1_.evaluate());
142 if (evaluator2_.isDynamic()) {
143 seleMan2_.setSelectionSet(evaluator2_.evaluate());
146 if (evaluator3_.isDynamic()) {
147 seleMan3_.setSelectionSet(evaluator3_.evaluate());
150 for (mol1 = seleMan1_.beginSelectedMolecule(ii); mol1 != NULL;
151 mol1 = seleMan1_.nextSelectedMolecule(ii)) {
156 Vector3d mPos = mol1->getCom();
158 for (mol2 = seleMan2_.beginSelectedMolecule(jj); mol2 != NULL;
159 mol2 = seleMan2_.nextSelectedMolecule(jj)) {
161 for (hbd1 = mol1->beginHBondDonor(hbdi); hbd1 != NULL;
162 hbd1 = mol1->nextHBondDonor(hbdi)) {
163 dPos = hbd1->donorAtom->getPos();
164 hPos = hbd1->donatedHydrogen->getPos();
166 currentSnapshot_->wrapVector(DH);
167 DHdist = DH.length();
170 for (hba2 = mol2->beginHBondAcceptor(hbaj); hba2 != NULL;
171 hba2 = mol2->nextHBondAcceptor(hbaj)) {
172 aPos = hba2->getPos();
174 currentSnapshot_->wrapVector(DA);
175 DAdist = DA.length();
179 if (DAdist < rCut_) {
180 ctheta =
dot(DH, DA) / (DHdist * DAdist);
181 theta = acos(ctheta) * 180.0 / Constants::PI;
184 if (theta < thetaCut_) {
189 int binNo = int(r / deltaR_);
191 sliceCount_[binNo] += 1;
198 for (hba1 = mol1->beginHBondAcceptor(hbai); hba1 != NULL;
199 hba1 = mol1->nextHBondAcceptor(hbai)) {
200 aPos = hba1->getPos();
203 for (hbd2 = mol2->beginHBondDonor(hbdj); hbd2 != NULL;
204 hbd2 = mol2->nextHBondDonor(hbdj)) {
205 dPos = hbd2->donorAtom->getPos();
208 currentSnapshot_->wrapVector(DA);
209 DAdist = DA.length();
213 if (DAdist < rCut_) {
214 hPos = hbd2->donatedHydrogen->getPos();
216 currentSnapshot_->wrapVector(DH);
217 DHdist = DH.length();
218 ctheta =
dot(DH, DA) / (DHdist * DAdist);
219 theta = acos(ctheta) * 180.0 / Constants::PI;
221 if (theta < thetaCut_) {
226 int binNo = int(r / deltaR_);
228 sliceCount_[binNo] += 1;
239 void HBondRvol::writeDensityR() {
242 double pi = acos(-1.0);
243 DumpReader reader(info_, dumpFilename_);
244 int nFrames = reader.getNFrames();
245 std::ofstream qRstream(outputFilename_.c_str());
246 if (qRstream.is_open()) {
247 qRstream <<
"# " << getAnalysisType() <<
"\n";
248 qRstream <<
"#selection 1: (" << selectionScript1_ <<
")\n";
249 qRstream <<
"#selection 2: (" << selectionScript2_ <<
")\n";
250 qRstream <<
"#selection 3: (" << selectionScript3_ <<
")\n";
251 if (!paramString_.empty())
252 qRstream <<
"# parameters: " << paramString_ <<
"\n";
254 qRstream <<
"#distance"
256 for (
unsigned int i = 0; i < sliceQ_.size(); ++i) {
257 RealType Rval = (i + 0.5) * deltaR_;
258 binvol_[i] = (4 * pi * (Rval * Rval) * deltaR_);
259 if (sliceCount_[i] != 0 && binvol_[i] != 0) {
260 qRstream << Rval <<
"\t" << sliceQ_[i] / (binvol_[i]) / nFrames
263 qRstream << Rval <<
"\t" << 0 <<
"\n";
268 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
269 "HBondRvol: unable to open %s\n", outputFilename_.c_str());
270 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)