48#include "applications/staticProps/OHFrequencyMap.hpp"
57#include "utils/simError.h"
61 OHFrequencyMap::OHFrequencyMap(
SimInfo* info,
const std::string& filename,
62 const std::string& sele1,
int nbins) :
64 selectionScript1_(sele1), seleMan1_(info_), evaluator1_(info_) {
66 setOutputName(
getPrefix(filename) +
".OHfreqs");
68 dumpHasElectricFields_ = info_->getSimParams()->getOutputElectricField();
73 if(!dumpHasElectricFields_) {
74 int atomStorageLayout = info_->getAtomStorageLayout();
75 int rigidBodyStorageLayout = info->getRigidBodyStorageLayout();
76 int cutoffGroupStorageLayout = info->getCutoffGroupStorageLayout();
78 atomStorageLayout |= DataStorage::dslElectricField;
79 rigidBodyStorageLayout |= DataStorage::dslElectricField;
80 info_->setAtomStorageLayout(atomStorageLayout);
81 info_->setRigidBodyStorageLayout(rigidBodyStorageLayout);
82 info_->setCutoffGroupStorageLayout(cutoffGroupStorageLayout);
84 info_->setSnapshotManager(
new SimSnapshotManager(info_, atomStorageLayout,
85 rigidBodyStorageLayout,
86 cutoffGroupStorageLayout));
89 info_->getSimParams()->setOutputElectricField(
true);
91 evaluator1_.loadScriptString(sele1);
92 if (!evaluator1_.isDynamic()) {
93 seleMan1_.setSelectionSet(evaluator1_.evaluate());
96 count_.resize(nBins_);
97 histogram_.resize(nBins_);
119 w10_[
"H_SPCE"] = std::make_tuple(3761.6, -5060.4, -86225.0);
120 w21_[
"H_SPCE"] = std::make_tuple(3614.1, -5493.7, -115670.0);
121 x10_[
"H_SPCE"] = std::make_pair(0.1024, -0.927e-5);
122 x21_[
"H_SPCE"] = std::make_pair(0.1428, -1.29e-5);
123 p10_[
"H_SPCE"] = std::make_pair(1.611, 5.893e-4);
124 p21_[
"H_SPCE"] = std::make_pair(1.611, 5.893e-4);
125 muprime_[
"H_SPCE"] = std::make_tuple(0.71116, 75.591, 0.0);
126 wintra_[
"H_SPCE"] = std::make_tuple(-1789, 23852, -1.966);
134 w10_[
"H_TIP4P"] = std::make_tuple(3760.2, -3541.7, -152677.0);
135 w21_[
"H_TIP4P"] = std::make_tuple(3606.0, -3498.6, -198715.0);
136 x10_[
"H_TIP4P"] = std::make_pair(0.19285, -1.7261e-5);
137 x21_[
"H_TIP4P"] = std::make_pair(0.26836, -2.3788e-5);
138 p10_[
"H_TIP4P"] = std::make_pair(1.6466, 5.7692e-4);
139 p21_[
"H_TIP4P"] = std::make_pair(2.0160, 8.7684e-4);
140 muprime_[
"H_TIP4P"] = std::make_tuple(0.1646, 11.39, 63.41);
141 wintra_[
"H_TIP4P"] = std::make_tuple(-1361, 27165, -1.887);
150 w10_[
"H_TIP4P-Ice"] = w10_[
"H_TIP4P"];
151 w21_[
"H_TIP4P-Ice"] = w21_[
"H_TIP4P"];
152 x10_[
"H_TIP4P-Ice"] = x10_[
"H_TIP4P"];
153 x21_[
"H_TIP4P-Ice"] = x21_[
"H_TIP4P"];
154 p10_[
"H_TIP4P-Ice"] = p10_[
"H_TIP4P"];
155 p21_[
"H_TIP4P-Ice"] = p21_[
"H_TIP4P"];
156 muprime_[
"H_TIP4P-Ice"] = muprime_[
"H_TIP4P"];
157 wintra_[
"H_TIP4P-Ice"] = wintra_[
"H_TIP4P"];
159 ForceField* forceField_ = info_->getForceField();
160 AtomTypeSet atypes = info_->getSimulatedAtomTypes();
162 info->getSnapshotManager()->getCurrentSnapshot()->getNumberOfAtoms();
166 std::vector<RealType> ef;
169 if (info_->getSimParams()->haveElectricField()) {
171 ef = info_->getSimParams()->getElectricField();
173 if (info_->getSimParams()->haveUniformField()) {
175 ef = info_->getSimParams()->getUniformField();
178 if (ef.size() != 3) {
180 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
181 "OHFrequencyMap: Incorrect number of parameters specified for "
183 "\tthere should be 3 parameters, but %zu were specified.\n",
185 painCave.isFatal = 1;
194 void OHFrequencyMap::process() {
195 ForceManager* forceMan;
199 SimInfo::MoleculeIterator mi;
203 RealType a0(0.0), a1(0.0), a2(0.0);
207 map<string, std::tuple<RealType, RealType, RealType>>::iterator fi;
208 const RealType chrgToKcal = 23.060548;
209 const RealType kcalToAU = 0.0008432975573;
211 DumpReader reader(info_, dumpFilename_);
212 int nFrames = reader.getNFrames();
213 nProcessed_ = nFrames / step_;
215 if (!dumpHasElectricFields_) {
217 forceMan =
new ForceManager(info_);
218 forceMan->setDoElectricField(
true);
219 forceMan->initialize();
222 std::fill(histogram_.begin(), histogram_.end(), 0.0);
223 std::fill(count_.begin(), count_.end(), 0);
225 for (
int istep = 0; istep < nFrames; istep += step_) {
226 reader.readFrame(istep);
227 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
229 if (!dumpHasElectricFields_) {
230 forceMan->setDoElectricField(
true);
231 forceMan->calcForces();
234 if (evaluator1_.isDynamic()) {
235 seleMan1_.setSelectionSet(evaluator1_.evaluate());
238 for (sd1 = seleMan1_.beginSelected(ii); sd1 != NULL;
239 sd1 = seleMan1_.nextSelected(ii)) {
240 sdID = sd1->getGlobalIndex();
241 molID = info_->getGlobalMolMembership(sdID);
242 mol = info_->getMoleculeByGlobalIndex(molID);
244 Vector3d Opos = mol->getAtomAt(0)->getPos();
245 Vector3d Hpos = sd1->getPos();
247 Vector3d rOH = Hpos - Opos;
251 atom =
dynamic_cast<Atom*
>(sd1);
252 atype = atom->getAtomType();
253 name = atype->getName();
255 fi = w10_.find(name);
256 if (fi != w10_.end()) {
257 a0 = get<0>((*fi).second);
258 a1 = get<1>((*fi).second);
259 a2 = get<2>((*fi).second);
261 sE = sd1->getElectricField();
265 sE += EF_ * chrgToKcal;
271 RealType E =
dot(rOH, sE);
273 freq = a0 + a1 * E + a2 * E*E;
276 int(nBins_ * (freq - minFreq_) / (maxFreq_ - minFreq_));
277 if (binNo >= 0 && binNo < nBins_) {
280 std::cerr <<
"freq = " << freq
281 <<
" is outside histogram range: (" << minFreq_ <<
", "
282 << maxFreq_ <<
")\n";
293 void OHFrequencyMap::processHistogram() {
295 for (
unsigned int i = 0; i < count_.size(); ++i)
298 for (
unsigned int i = 0; i < count_.size(); ++i) {
299 histogram_[i] = double(count_[i] /
double(atot));
303 void OHFrequencyMap::writeProbs() {
304 std::ofstream rdfStream(outputFilename_.c_str());
305 if (rdfStream.is_open()) {
306 rdfStream <<
"#OHFrequencyMap\n";
307 rdfStream <<
"#nFrames:\t" << nProcessed_ <<
"\n";
308 rdfStream <<
"#selection1: (" << selectionScript1_ <<
")";
310 rdfStream <<
"#nu\tp(nu))\n";
311 for (
unsigned int i = 0; i < histogram_.size(); ++i) {
312 RealType freq = minFreq_ + (RealType)(i) * (maxFreq_ - minFreq_) /
313 (RealType)histogram_.size();
314 rdfStream << freq <<
"\t" << histogram_[i] <<
"\n";
318 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
319 "OHFrequencyMap: unable to open %s\n",
320 outputFilename_.c_str());
321 painCave.isFatal = 1;
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
void normalize()
Normalizes this vector in place.
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)