48#include "HBondZvol.hpp"
56#include "utils/Constants.hpp"
57#include "utils/simError.h"
61 HBondZvol::HBondZvol(
SimInfo* info,
const std::string& filename,
62 const std::string& sele1,
const std::string& sele2,
63 double rCut,
double thetaCut,
int nzbins,
int axis) :
65 selectionScript1_(sele1), seleMan1_(info), evaluator1_(info),
66 selectionScript2_(sele2), seleMan2_(info), evaluator2_(info),
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());
86 nHBonds_.resize(nBins_);
87 nDonor_.resize(nBins_);
88 nAcceptor_.resize(nBins_);
89 sliceQ_.resize(nBins_);
90 sliceCount_.resize(nBins_);
92 std::fill(sliceQ_.begin(), sliceQ_.end(), 0.0);
93 std::fill(sliceCount_.begin(), sliceCount_.end(), 0);
108 setOutputName(
getPrefix(filename) +
".hbondzvol");
111 void HBondZvol::process() {
114 Molecule::HBondDonor* hbd1;
115 Molecule::HBondDonor* hbd2;
116 std::vector<Molecule::HBondDonor*>::iterator hbdi;
117 std::vector<Molecule::HBondDonor*>::iterator hbdj;
118 std::vector<Atom*>::iterator hbai;
119 std::vector<Atom*>::iterator hbaj;
127 RealType DAdist, DHdist, theta, ctheta;
132 bool usePeriodicBoundaryConditions_ =
133 info_->getSimParams()->getUsePeriodicBoundaryConditions();
135 DumpReader reader(info_, dumpFilename_);
136 int nFrames = reader.getNFrames();
139 for (
int istep = 0; istep < nFrames; istep += step_) {
140 reader.readFrame(istep);
141 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
143 Mat3x3d hmat = currentSnapshot_->getHmat();
145 RealType Lx = hmat(0, 0);
146 RealType Ly = hmat(1, 1);
147 RealType Lz = hmat(2, 2);
149 zBox_.push_back(hmat(axis_, axis_));
150 sliceVol = currentSnapshot_->getVolume() / nBins_;
152 RealType halfBoxZ_ = hmat(axis_, axis_) / 2.0;
154 if (evaluator1_.isDynamic()) {
155 seleMan1_.setSelectionSet(evaluator1_.evaluate());
158 if (evaluator2_.isDynamic()) {
159 seleMan2_.setSelectionSet(evaluator2_.evaluate());
162 for (mol1 = seleMan1_.beginSelectedMolecule(ii); mol1 != NULL;
163 mol1 = seleMan1_.nextSelectedMolecule(ii)) {
168 Vector3d mPos = mol1->getCom();
170 for (mol2 = seleMan2_.beginSelectedMolecule(jj); mol2 != NULL;
171 mol2 = seleMan2_.nextSelectedMolecule(jj)) {
173 for (hbd1 = mol1->beginHBondDonor(hbdi); hbd1 != NULL;
174 hbd1 = mol1->nextHBondDonor(hbdi)) {
175 dPos = hbd1->donorAtom->getPos();
176 hPos = hbd1->donatedHydrogen->getPos();
178 currentSnapshot_->wrapVector(DH);
179 DHdist = DH.length();
182 for (hba2 = mol2->beginHBondAcceptor(hbaj); hba2 != NULL;
183 hba2 = mol2->nextHBondAcceptor(hbaj)) {
184 aPos = hba2->getPos();
186 currentSnapshot_->wrapVector(DA);
187 DAdist = DA.length();
191 if (DAdist < rCut_) {
192 ctheta =
dot(DH, DA) / (DHdist * DAdist);
193 theta = acos(ctheta) * 180.0 / Constants::PI;
196 if (theta < thetaCut_) {
200 if (usePeriodicBoundaryConditions_)
201 currentSnapshot_->wrapVector(hPos);
202 int binNo = int(nBins_ * (halfBoxZ_ + hPos[axis_]) /
204 sliceQ_[binNo] += 1 / sliceVol;
205 sliceCount_[binNo] += 1;
212 for (hba1 = mol1->beginHBondAcceptor(hbai); hba1 != NULL;
213 hba1 = mol1->nextHBondAcceptor(hbai)) {
214 aPos = hba1->getPos();
217 for (hbd2 = mol2->beginHBondDonor(hbdj); hbd2 != NULL;
218 hbd2 = mol2->nextHBondDonor(hbdj)) {
219 dPos = hbd2->donorAtom->getPos();
222 currentSnapshot_->wrapVector(DA);
223 DAdist = DA.length();
227 if (DAdist < rCut_) {
228 hPos = hbd2->donatedHydrogen->getPos();
230 currentSnapshot_->wrapVector(DH);
231 DHdist = DH.length();
232 ctheta =
dot(DH, DA) / (DHdist * DAdist);
233 theta = acos(ctheta) * 180.0 / Constants::PI;
235 if (theta < thetaCut_) {
239 if (usePeriodicBoundaryConditions_)
240 currentSnapshot_->wrapVector(hPos);
241 int binNo = int(nBins_ * (halfBoxZ_ + hPos[axis_]) /
243 sliceQ_[binNo] += 1 / sliceVol;
244 sliceCount_[binNo] += 1;
255 void HBondZvol::writeDensity() {
259 for (std::vector<RealType>::iterator j = zBox_.begin(); j != zBox_.end();
263 RealType zAve = zSum / zBox_.size();
265 DumpReader reader(info_, dumpFilename_);
266 int nFrames = reader.getNFrames();
268 std::ofstream qZstream(outputFilename_.c_str());
269 if (qZstream.is_open()) {
270 qZstream <<
"#Hydrogen Bonds (" << axisLabel_ <<
")\n";
272 qZstream <<
"#nFrames:\t" << zBox_.size() <<
"\n";
273 qZstream <<
"#selection 1: (" << selectionScript1_ <<
")\n";
274 qZstream <<
"#selection 2: (" << selectionScript2_ <<
")\n";
275 qZstream <<
"#" << axisLabel_
276 <<
"\tHydrogen Bond Density (molecules/A^3)\n";
277 for (
unsigned int i = 0; i < sliceQ_.size(); ++i) {
278 RealType z = zAve * (i + 0.5) / sliceQ_.size();
279 if (sliceCount_[i] != 0) {
280 qZstream << z <<
"\t" << sliceQ_[i] / nFrames <<
"\n";
282 qZstream << z <<
"\t" << 0 <<
"\n";
286 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
287 "HBondZvol: unable to open %s\n", outputFilename_.c_str());
288 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)