48#include "applications/staticProps/NitrileFrequencyMap.hpp"
53#include "brains/Thermo.hpp"
56#include "utils/simError.h"
60 NitrileFrequencyMap::NitrileFrequencyMap(
SimInfo* info,
61 const std::string& filename,
62 const std::string& sele1,
65 info_(info), selectionScript1_(sele1), seleMan1_(info_),
67 setOutputName(
getPrefix(filename) +
".freqs");
69 evaluator1_.loadScriptString(sele1);
70 if (!evaluator1_.isDynamic()) {
71 seleMan1_.setSelectionSet(evaluator1_.evaluate());
74 count_.resize(nBins_);
75 histogram_.resize(nBins_);
77 freqs_.resize(info_->getNGlobalMolecules());
89 frequencyMap_[
"CN"] = 0.0801;
90 frequencyMap_[
"NC"] = 0.00521;
91 frequencyMap_[
"RCHar3"] = -0.00182;
92 frequencyMap_[
"SigmaN"] = 0.00157;
93 frequencyMap_[
"PiN"] = -0.00167;
94 frequencyMap_[
"PiC"] = -0.00896;
96 ForceField* forceField_ = info_->getForceField();
97 AtomTypeSet atypes = info_->getSimulatedAtomTypes();
98 PairList* excludes = info_->getExcludedInteractions();
100 info->getSnapshotManager()->getCurrentSnapshot()->getNumberOfAtoms();
103 if (info_->getSimParams()->haveCutoffRadius()) {
104 rcut = info_->getSimParams()->getCutoffRadius();
111 std::vector<RealType> ef;
114 if (info_->getSimParams()->haveElectricField()) {
116 ef = info_->getSimParams()->getElectricField();
118 if (info_->getSimParams()->haveUniformField()) {
120 ef = info_->getSimParams()->getUniformField();
123 if (ef.size() != 3) {
125 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
126 "NitrileFrequencyMap: Incorrect number of parameters specified for "
128 "\tthere should be 3 parameters, but %zu were specified.\n",
130 painCave.isFatal = 1;
138 excludesForAtom.clear();
139 excludesForAtom.resize(nAtoms);
141 for (
int i = 0; i < nAtoms; i++) {
142 for (
int j = 0; j < nAtoms; j++) {
143 if (excludes->hasPair(i, j)) excludesForAtom[i].push_back(j);
147 electrostatic_ =
new Electrostatic();
148 electrostatic_->setSimInfo(info_);
149 electrostatic_->setForceField(forceField_);
150 electrostatic_->setSimulatedAtomTypes(atypes);
151 electrostatic_->setCutoffRadius(rcut);
154 bool NitrileFrequencyMap::excludeAtomPair(
int atom1,
int atom2) {
155 for (vector<int>::iterator i = excludesForAtom[atom1].begin();
156 i != excludesForAtom[atom1].end(); ++i) {
157 if ((*i) == atom2)
return true;
163 void NitrileFrequencyMap::process() {
167 SimInfo::MoleculeIterator mi;
168 Molecule::AtomIterator ai2;
171 int ii, sdID, molID, sdID2;
173 RealType sPot, s1, s2;
176 map<string, RealType>::iterator fi;
178 const RealType chrgToKcal = 23.0609;
180 DumpReader reader(info_, dumpFilename_);
181 int nFrames = reader.getNFrames();
183 nProcessed_ = nFrames / step_;
185 std::fill(histogram_.begin(), histogram_.end(), 0.0);
186 std::fill(count_.begin(), count_.end(), 0);
188 for (
int istep = 0; istep < nFrames; istep += step_) {
189 reader.readFrame(istep);
190 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
192 std::fill(freqs_.begin(), freqs_.end(), 0.0);
194 if (evaluator1_.isDynamic()) {
195 seleMan1_.setSelectionSet(evaluator1_.evaluate());
198 for (sd1 = seleMan1_.beginSelected(ii); sd1 != NULL;
199 sd1 = seleMan1_.nextSelected(ii)) {
200 sdID = sd1->getGlobalIndex();
201 molID = info_->getGlobalMolMembership(sdID);
202 mol = info_->getMoleculeByGlobalIndex(molID);
204 Vector3d CNcentroid = mol->getRigidBodyAt(2)->getPos();
205 Vector3d ra = sd1->getPos();
207 atom =
dynamic_cast<Atom*
>(sd1);
208 atype = atom->getAtomType();
209 name = atype->getName();
210 fi = frequencyMap_.find(name);
211 if (fi != frequencyMap_.end()) {
215 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
216 "NitrileFrequencyMap::process: Unknown atype requested.\n"
217 "\t(Selection specified %s .)\n",
219 painCave.isFatal = 1;
223 sPot = sd1->getSitePotential();
227 for (atom2 = mol->beginAtom(ai2); atom2 != NULL;
228 atom2 = mol->nextAtom(ai2)) {
229 sdID2 = atom2->getGlobalIndex();
233 excluded = excludeAtomPair(sdID, sdID2);
236 electrostatic_->getSitePotentials(atom, atom2, excluded, s1, s2);
243 sPot +=
dot(EF_, ra - CNcentroid) * chrgToKcal;
245 freqShift = sPot * li;
248 freqShift *= 349.757;
250 freqs_[molID] += freqShift;
253 for (
int i = 0; i < info_->getNGlobalMolecules(); ++i) {
255 int(nBins_ * (freqs_[i] - minFreq_) / (maxFreq_ - minFreq_));
265 void NitrileFrequencyMap::processHistogram() {
267 for (
unsigned int i = 0; i < count_.size(); ++i)
270 for (
unsigned int i = 0; i < count_.size(); ++i) {
271 histogram_[i] = double(count_[i] /
double(atot));
275 void NitrileFrequencyMap::writeProbs() {
276 std::ofstream rdfStream(outputFilename_.c_str());
277 if (rdfStream.is_open()) {
278 rdfStream <<
"#NitrileFrequencyMap\n";
279 rdfStream <<
"#nFrames:\t" << nProcessed_ <<
"\n";
280 rdfStream <<
"#selection1: (" << selectionScript1_ <<
")";
282 rdfStream <<
"#nu\tp(nu))\n";
283 for (
unsigned int i = 0; i < histogram_.size(); ++i) {
284 RealType freq = minFreq_ + (RealType)(i) * (maxFreq_ - minFreq_) /
285 (RealType)histogram_.size();
286 rdfStream << freq <<
"\t" << histogram_[i] <<
"\n";
290 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
291 "NitrileFrequencyMap: unable to open %s\n",
292 outputFilename_.c_str());
293 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)