48#include "applications/dynamicProps/ChargeOrientationCorrFunc.hpp"
52#include "types/FixedChargeAdapter.hpp"
53#include "types/FluctuatingChargeAdapter.hpp"
56 ChargeOrientationCorrFunc::ChargeOrientationCorrFunc(
57 SimInfo* info,
const std::string& filename,
const std::string& sele1,
58 const std::string& sele2,
const RealType dipoleX,
const RealType dipoleY,
59 const RealType dipoleZ,
const RealType cutOff,
const int axis) :
60 ObjectCCF<RealType>(info, filename, sele1, sele2),
63 "Charge - Orientation Order Parameter Cross Correlation Function");
64 setOutputName(
getPrefix(dumpFilename_) +
".QScorr");
66 charges_.resize(nFrames_);
67 CosTheta_.resize(nFrames_);
74 dipoleVector_ = Vector3d(dipoleX, dipoleY, dipoleZ);
75 dipoleVector_.normalize();
80 refAxis_ = Vector3d(1, 0, 0);
84 refAxis_ = Vector3d(0, 1, 0);
89 refAxis_ = Vector3d(0, 0, 1);
94 void ChargeOrientationCorrFunc::validateSelection(SelectionManager& seleMan) {
98 for (sd = seleMan.beginSelected(i); sd != NULL;
99 sd = seleMan.nextSelected(i)) {
100 Atom* atom =
static_cast<Atom*
>(sd);
101 AtomType* atomType = atom->getAtomType();
102 FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atomType);
104 if (!sd->isDirectional() && !fqa.isFluctuatingCharge()) {
106 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
107 "ChargeOrientationCorrFunc::validateSelection Error: selection "
109 "\t is not a Directional object\n",
110 sd->getGlobalIndex(), sd->getType().c_str());
111 painCave.isFatal = 1;
117 int ChargeOrientationCorrFunc::computeProperty1(
int frame, StuntDouble* sd) {
119 Atom* atom =
static_cast<Atom*
>(sd);
121 AtomType* atomType = atom->getAtomType();
123 FixedChargeAdapter fca = FixedChargeAdapter(atomType);
124 if (fca.isFixedCharge()) { q += fca.getCharge(); }
126 FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atomType);
127 if (fqa.isFluctuatingCharge()) { q += atom->getFlucQPos(); }
130 charges_[frame].push_back(propertyTemp);
131 sumCharge_ += propertyTemp;
133 return charges_[frame].size() - 1;
136 int ChargeOrientationCorrFunc::computeProperty2(
int frame, StuntDouble* sd) {
137 SquareMatrix3<RealType> rotMat;
138 Vector3d rotatedDipoleVector;
139 RealType ctheta(0.0);
142 rotatedDipoleVector = rotMat * dipoleVector_;
143 rotatedDipoleVector.normalize();
144 ctheta =
dot(rotatedDipoleVector, refAxis_);
146 propertyTemp = ctheta;
147 CosTheta_[frame].push_back(propertyTemp);
148 sumCosTheta_ += propertyTemp;
150 return CosTheta_[frame].size() - 1;
153 RealType ChargeOrientationCorrFunc::calcCorrVal(
int frame1,
int frame2,
155 return charges_[frame1][id1] * CosTheta_[frame2][id2];
158 void ChargeOrientationCorrFunc::postCorrelate() {
160 sumCharge_ /= RealType(chargeCount_);
163 sumCosTheta_ /= RealType(CosThetaCount_);
165 RealType correlationOfAverages_ = sumCharge_ * sumCosTheta_;
166 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
168 histogram_[i] /= RealType(count_[i]);
172 histogram_[i] -= correlationOfAverages_;
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)