51#include "applications/staticProps/ChargeHistogram.hpp" 
   59#include "types/FixedChargeAdapter.hpp" 
   60#include "types/FluctuatingChargeAdapter.hpp" 
   61#include "utils/simError.h" 
   65  ChargeHistogram::ChargeHistogram(
SimInfo* info, 
const std::string& filename,
 
   66                                   const std::string& sele, 
int nbins) :
 
   68      selectionScript_(sele), evaluator_(info), seleMan_(info), nBins_(nbins) {
 
   69    evaluator_.loadScriptString(sele);
 
   70    if (!evaluator_.isDynamic()) {
 
   71      seleMan_.setSelectionSet(evaluator_.evaluate());
 
   74    setOutputName(
getPrefix(filename) + 
".Chargehist");
 
   77  void ChargeHistogram::process() {
 
   82      seleMan_.setSelectionSet(evaluator_.evaluate());
 
   86    int nFrames = reader.getNFrames();
 
   87    nProcessed_ = nFrames / step_;
 
   88    vector<RealType> charge;
 
   90    nProcessed_ = nFrames / step_;
 
   92    for (
int istep = 0; istep < nFrames; istep += step_) {
 
   93      reader.readFrame(istep);
 
  104        if (fca.isFixedCharge()) { q += fca.getCharge(); }
 
  107        if (fqa.isFluctuatingCharge()) { q += atom->
getFlucQPos(); }
 
  113    if (charge.empty()) {
 
  114      snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
 
  115               "Selected atom not found.\n");
 
  116      painCave.isFatal = 1;
 
  120    std::sort(charge.begin(), charge.end());
 
  122    RealType min = charge.front();
 
  123    RealType max = charge.back();
 
  125    RealType delta_charge = (max - min) / (nBins_);
 
  127    if (delta_charge == 0) {
 
  128      bincenter_.push_back(min);
 
  129      histList_.push_back(1);
 
  132      for (
int j = 0; j < nBins_ + 3; ++j) {
 
  133        bincenter_.push_back(min + (j - 1) * delta_charge);
 
  134        histList_.push_back(0);
 
  137      int bin_center_pos = 0;
 
  138      vector<RealType>::iterator index;
 
  139      RealType charge_length = 
static_cast<RealType
>(charge.size());
 
  142      for (index = charge.begin(); index < charge.end(); index++) {
 
  144        while (hist_update) {
 
  145          if (*index >= bincenter_[bin_center_pos] &&
 
  146              *index < bincenter_[bin_center_pos + 1]) {
 
  147            histList_[bin_center_pos] += 1.0 / charge_length;
 
  159  void ChargeHistogram::writeCharge() {
 
  160    std::ofstream rdfStream(outputFilename_.c_str());
 
  161    if (rdfStream.is_open()) {
 
  162      rdfStream << 
"#Charges for selection\n";
 
  163      rdfStream << 
"#nFrames:\t" << nProcessed_ << 
"\n";
 
  164      rdfStream << 
"#selection: (" << selectionScript_ << 
")\n";
 
  168      for (
unsigned int i = 0; i < histList_.size(); ++i) {
 
  169        rdfStream << bincenter_[i] << 
"\t" << histList_[i] << 
"\n";
 
  172      snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
 
  173               "ChargeHistogram: unable to open %s\n", outputFilename_.c_str());
 
  174      painCave.isFatal = 1;
 
AtomType * getAtomType()
Returns the AtomType of this Atom.
AtomType is what OpenMD looks to for unchanging data about an atom.
bool isDynamic()
Tests if the result from evaluation of script is dynamic.
StuntDouble * nextSelected(int &i)
Finds the next selected StuntDouble in the selection.
StuntDouble * beginSelected(int &i)
Finds the first selected StuntDouble in the selection.
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
SnapshotManager * getSnapshotManager()
Returns the snapshot manager.
Snapshot * getCurrentSnapshot()
Returns the pointer of current snapshot.
"Don't move, or you're dead! Stand up! Captain, we've got them!"
RealType getFlucQPos()
Returns the current fluctuating charge of this stuntDouble.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
std::string getPrefix(const std::string &str)