--- trunk/src/applications/staticProps/GofRAngle.cpp 2009/11/25 20:02:06 1390 +++ trunk/src/applications/staticProps/GofRAngle.cpp 2014/02/20 16:27:30 1968 @@ -35,13 +35,16 @@ * * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). - * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). - * [4] Vardeman & Gezelter, in progress (2009). + * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). + * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). + * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). */ #include #include #include "applications/staticProps/GofRAngle.hpp" +#include "primitives/Atom.hpp" +#include "types/MultipoleAdapter.hpp" #include "utils/simError.h" namespace OpenMD { @@ -62,14 +65,14 @@ namespace OpenMD { void GofRAngle::preProcess() { - for (int i = 0; i < avgGofr_.size(); ++i) { + for (unsigned int i = 0; i < avgGofr_.size(); ++i) { std::fill(avgGofr_[i].begin(), avgGofr_[i].end(), 0); } } - void GofRAngle::initalizeHistogram() { + void GofRAngle::initializeHistogram() { npairs_ = 0; - for (int i = 0; i < histogram_.size(); ++i){ + for (unsigned int i = 0; i < histogram_.size(); ++i){ std::fill(histogram_[i].begin(), histogram_[i].end(), 0); } } @@ -80,14 +83,14 @@ namespace OpenMD { RealType pairDensity = nPairs /volume; RealType pairConstant = ( 4.0 * NumericConstant::PI * pairDensity ) / 3.0; - for(int i = 0 ; i < histogram_.size(); ++i){ + for(unsigned int i = 0 ; i < histogram_.size(); ++i){ RealType rLower = i * deltaR_; RealType rUpper = rLower + deltaR_; RealType volSlice = ( rUpper * rUpper * rUpper ) - ( rLower * rLower * rLower ); RealType nIdeal = volSlice * pairConstant; - for (int j = 0; j < histogram_[i].size(); ++j){ + for (unsigned int j = 0; j < histogram_[i].size(); ++j){ avgGofr_[i][j] += histogram_[i][j] / nIdeal; } } @@ -106,13 +109,13 @@ namespace OpenMD { currentSnapshot_->wrapVector(r12); RealType distance = r12.length(); - int whichRBin = distance / deltaR_; + int whichRBin = int(distance / deltaR_); if (distance <= len_) { RealType cosAngle = evaluateAngle(sd1, sd2); RealType halfBin = (nAngleBins_ - 1) * 0.5; - int whichThetaBin = halfBin * (cosAngle + 1.0); + int whichThetaBin = int(halfBin * (cosAngle + 1.0)); ++histogram_[whichRBin][whichThetaBin]; ++npairs_; @@ -127,11 +130,11 @@ namespace OpenMD { rdfStream << "selection2: (" << selectionScript2_ << ")\n"; rdfStream << "#nRBins = " << nRBins_ << "\t maxLen = " << len_ << "deltaR = " << deltaR_ <<"\n"; rdfStream << "#nAngleBins =" << nAngleBins_ << "deltaCosAngle = " << deltaCosAngle_ << "\n"; - for (int i = 0; i < avgGofr_.size(); ++i) { - RealType r = deltaR_ * (i + 0.5); + for (unsigned int i = 0; i < avgGofr_.size(); ++i) { + // RealType r = deltaR_ * (i + 0.5); - for(int j = 0; j < avgGofr_[i].size(); ++j) { - RealType cosAngle = -1.0 + (j + 0.5)*deltaCosAngle_; + for(unsigned int j = 0; j < avgGofr_[i].size(); ++j) { + // RealType cosAngle = -1.0 + (j + 0.5)*deltaCosAngle_; rdfStream << avgGofr_[i][j]/nProcessed_ << "\t"; } @@ -156,14 +159,52 @@ namespace OpenMD { currentSnapshot_->wrapVector(r12); r12.normalize(); - Vector3d dipole = sd1->getElectroFrame().getColumn(2); - dipole.normalize(); - return dot(r12, dipole); + + Vector3d vec; + + if (sd1->isAtom()) { + AtomType* atype1 = static_cast(sd1)->getAtomType(); + MultipoleAdapter ma1 = MultipoleAdapter(atype1); + + if (ma1.isDipole() ) + vec = sd1->getDipole(); + else + vec = sd1->getA().transpose() * V3Z; + } else { + vec = sd1->getA().transpose() * V3Z; + } + + vec.normalize(); + + return dot(r12, vec); } RealType GofROmega::evaluateAngle(StuntDouble* sd1, StuntDouble* sd2) { - Vector3d v1 = sd1->getElectroFrame().getColumn(2); - Vector3d v2 = sd2->getElectroFrame().getColumn(2); + Vector3d v1, v2; + + if (sd1->isAtom()){ + AtomType* atype1 = static_cast(sd1)->getAtomType(); + MultipoleAdapter ma1 = MultipoleAdapter(atype1); + if (ma1.isDipole() ) + v1 = sd1->getDipole(); + else + v1 = sd1->getA().transpose() * V3Z; + } else { + v1 = sd1->getA().transpose() * V3Z; + } + + if (sd2->isAtom()) { + AtomType* atype2 = static_cast(sd2)->getAtomType(); + MultipoleAdapter ma2 = MultipoleAdapter(atype2); + + if (ma2.isDipole() ) + v2 = sd2->getDipole(); + else + v2 = sd2->getA().transpose() * V3Z; + } else { + v2 = sd2->getA().transpose() * V3Z; + } + v1.normalize(); v2.normalize(); return dot(v1, v2);