45#include "applications/staticProps/SpatialStatistics.hpp" 
   50#include "applications/staticProps/StaticAnalyser.hpp" 
   53#include "io/Globals.hpp" 
   56#include "rnemd/RNEMDParameters.hpp" 
   57#include "utils/Accumulator.hpp" 
   58#include "utils/AccumulatorView.hpp" 
   63  SpatialStatistics::SpatialStatistics(SimInfo* info,
 
   64                                       const std::string& filename,
 
   65                                       const std::string& sele, 
int nbins) :
 
   66      StaticAnalyser(info, filename, nbins),
 
   67      selectionScript_(sele), evaluator_(info), seleMan_(info) {
 
   68    evaluator_.loadScriptString(sele);
 
   69    if (!evaluator_.isDynamic()) {
 
   70      seleMan_.setSelectionSet(evaluator_.evaluate());
 
   73    setOutputName(
getPrefix(filename) + 
".spst");
 
   76  void SpatialStatistics::process() {
 
   77    DumpReader reader(info_, dumpFilename_);
 
   78    int nFrames = reader.getNFrames();
 
   79    nProcessed_ = nFrames / step_;
 
   81    for (
int istep = 0; istep < nFrames; istep += step_) {
 
   82      reader.readFrame(istep);
 
   83      currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
 
   90  void SpatialStatistics::processFrame(
int) {
 
   94    if (evaluator_.isDynamic()) {
 
   95      seleMan_.setSelectionSet(evaluator_.evaluate());
 
   99    for (sd = seleMan_.beginSelected(i); sd != NULL;
 
  100         sd = seleMan_.nextSelected(i)) {
 
  102      Vector3d pos = sd->getPos();
 
  104      int bin = getBin(pos);
 
  107      processStuntDouble(sd, bin);
 
  111  SlabStatistics::SlabStatistics(SimInfo* info, 
const std::string& filename,
 
  112                                 const std::string& sele, 
int nbins, 
int axis) :
 
  113      SpatialStatistics(info, filename, sele, nbins),
 
  130  void SlabStatistics::processFrame(
int istep) {
 
  132    hmat_ = currentSnapshot_->getHmat();
 
  134    volume_ = currentSnapshot_->getVolume();
 
  136    SpatialStatistics::processFrame(istep);
 
  139  int SlabStatistics::getBin(Vector3d pos) {
 
  140    currentSnapshot_->wrapVector(pos);
 
  146    return int(nBins_ * (pos[axis_] / hmat_(axis_, axis_) + 0.5)) % nBins_;
 
  149  ShellStatistics::ShellStatistics(SimInfo* info, 
const std::string& filename,
 
  150                                   const std::string& sele,
 
  151                                   const std::string& comsele, 
int nbins,
 
  153      SpatialStatistics(info, filename, sele, nbins),
 
  154      coordinateOrigin_(V3Zero), comSele_(comsele), comSeleMan_(info),
 
  155      comEvaluator_(info), binWidth_(binWidth) {
 
  156    Globals* simParams                  = info->getSimParams();
 
  157    RNEMD::RNEMDParameters* rnemdParams = simParams->getRNEMDParameters();
 
  158    bool hasCoordinateOrigin            = rnemdParams->haveCoordinateOrigin();
 
  160    if (hasCoordinateOrigin) {
 
  161      std::vector<RealType> co = rnemdParams->getCoordinateOrigin();
 
  162      if (co.size() != 3) {
 
  164            painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
 
  165            "ShellStatistics: Incorrect number of parameters specified for " 
  166            "coordinateOrigin.\n" 
  167            "\tthere should be 3 parameters, but %lu were specified.\n",
 
  169        painCave.isFatal = 1;
 
  172      coordinateOrigin_.x() = co[0];
 
  173      coordinateOrigin_.y() = co[1];
 
  174      coordinateOrigin_.z() = co[2];
 
  176      if (!comSele_.empty()) {
 
  177        comEvaluator_.loadScriptString(comSele_);
 
  178        if (!comEvaluator_.isDynamic()) {
 
  179          comSeleMan_.setSelectionSet(comEvaluator_.evaluate());
 
  180          if (comSeleMan_.getSelectionCount() != 1) {
 
  181            snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
 
  182                     "ShellStatistics: More than one selected object in " 
  184                     "\tThere are %d selected objects.\n",
 
  185                     comSeleMan_.getSelectionCount());
 
  186            painCave.isFatal = 1;
 
  190          StuntDouble* sd   = comSeleMan_.beginSelected(isd);
 
  191          coordinateOrigin_ = sd->getPos();
 
  194        coordinateOrigin_ = V3Zero;
 
  199  void ShellStatistics::processFrame(
int istep) {
 
  200    if (comEvaluator_.isDynamic()) {
 
  201      comSeleMan_.setSelectionSet(comEvaluator_.evaluate());
 
  202      if (comSeleMan_.getSelectionCount() != 1) {
 
  203        snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
 
  204                 "ShellStatistics: More than one selected object in " 
  206                 "\tThere are %d selected objects.\n",
 
  207                 comSeleMan_.getSelectionCount());
 
  208        painCave.isFatal = 1;
 
  212      StuntDouble* sd   = comSeleMan_.beginSelected(isd);
 
  213      coordinateOrigin_ = sd->getPos();
 
  215      SpatialStatistics::processFrame(istep);
 
  219  int ShellStatistics::getBin(Vector3d pos) {
 
  220    Vector3d rPos = pos - coordinateOrigin_;
 
  221    return int(rPos.length() / binWidth_);
 
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
 
std::string getPrefix(const std::string &str)