48#include "applications/dynamicProps/ChargeKineticCorrFunc.hpp"
51#include "types/FixedChargeAdapter.hpp"
52#include "types/FluctuatingChargeAdapter.hpp"
55 ChargeKineticCorrFunc::ChargeKineticCorrFunc(
SimInfo* info,
56 const std::string& filename,
57 const std::string& sele1,
58 const std::string& sele2,
59 const RealType cutoff) :
60 ObjectCCF<RealType>(info, filename, sele1, sele2),
62 setCorrFuncType(
"Charge - Kinetic Cross Correlation Function");
63 setOutputName(
getPrefix(dumpFilename_) +
".QKcorr");
65 charges_.resize(nFrames_);
66 kinetic_.resize(nFrames_);
74 void ChargeKineticCorrFunc::validateSelection(SelectionManager& seleMan) {
78 for (sd = seleMan.beginSelected(i); sd != NULL;
79 sd = seleMan.nextSelected(i)) {
80 Atom* atom =
static_cast<Atom*
>(sd);
81 AtomType* atomType = atom->getAtomType();
82 FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atomType);
84 if (!sd->isDirectional() && !fqa.isFluctuatingCharge()) {
85 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
86 "ChargeKineticCorrFunc::validateSelection Error: selection "
88 "\t is not a Directional object\n",
89 sd->getGlobalIndex(), sd->getType().c_str());
96 int ChargeKineticCorrFunc::computeProperty1(
int frame, StuntDouble* sd) {
99 Atom* atom =
static_cast<Atom*
>(sd);
101 AtomType* atomType = atom->getAtomType();
103 FixedChargeAdapter fca = FixedChargeAdapter(atomType);
104 if (fca.isFixedCharge()) { q += fca.getCharge(); }
106 FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atomType);
107 if (fqa.isFluctuatingCharge()) { q += atom->getFlucQPos(); }
110 charges_[frame].push_back(propertyTemp);
111 sumCharge_ += propertyTemp;
113 return charges_[frame].size() - 1;
116 int ChargeKineticCorrFunc::computeProperty2(
int frame, StuntDouble* sd) {
117 RealType kinetic(0.0);
118 pos2_ = sd->getPos();
120 RealType mass = sd->getMass();
121 Vector3d vel = sd->getVel();
123 kinetic += mass * (vel[0] * vel[0] + vel[1] * vel[1] + vel[2] * vel[2]);
129 if (sd->isDirectional()) {
133 if (sd->isLinear()) {
134 i = sd->linearAxis();
138 angMom[j] * angMom[j] / I(j, j) + angMom[k] * angMom[k] / I(k, k);
140 kinetic += angMom[0] * angMom[0] / I(0, 0) +
141 angMom[1] * angMom[1] / I(1, 1) +
142 angMom[2] * angMom[2] / I(2, 2);
145 propertyTemp = 0.5 * kinetic;
146 kinetic_[frame].push_back(propertyTemp);
147 sumKinetic_ += propertyTemp;
149 return kinetic_[frame].size() - 1;
152 RealType ChargeKineticCorrFunc::calcCorrVal(
int frame1,
int frame2,
int id1,
154 Vector3d sep = pos1_ - pos2_;
156 if (distance <= rcut_)
159 return charges_[frame1][id1] * kinetic_[frame2][id2];
162 void ChargeKineticCorrFunc::postCorrelate() {
164 sumCharge_ /= RealType(chargeCount_);
167 sumKinetic_ /= RealType(kineticCount_);
169 RealType correlationOfAverages_ = sumCharge_ * sumKinetic_;
170 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
172 histogram_[i] /= RealType(count_[i]);
176 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.
std::string getPrefix(const std::string &str)
Real distance(const DynamicVector< Real > &v1, const DynamicVector< Real > &v2)
Returns the distance between two DynamicVectors.