45#include "applications/sequentialProps/GCNSeq.hpp" 
   52#include "utils/Revision.hpp" 
   53#include "utils/simError.h" 
   57  GCNSeq::GCNSeq(SimInfo* info, 
const std::string& filename,
 
   58                 const std::string& sele1, 
const std::string& sele2,
 
   59                 RealType rCut, 
int bins) :
 
   60      SequentialAnalyzer(info, filename, sele1, sele2),
 
   61      rCut_(rCut), bins_(bins) {
 
   62    setSequenceType(
"Generalized Coordination Number Distribution");
 
   63    setOutputName(
getPrefix(filename) + 
".gcnSeq");
 
   66    RealType binMax_ = nnMax_ * 1.5;
 
   67    delta_           = binMax_ / bins_;
 
   68    usePBC_          = info->getSimParams()->getUsePeriodicBoundaryConditions();
 
   70    std::stringstream params;
 
   71    params << 
" rcut = " << rCut_ << 
", nbins = " << bins_
 
   72           << 
", max neighbors = " << nnMax_;
 
   73    const std::string paramString = params.str();
 
   74    setParameterString(paramString);
 
   77  void GCNSeq::doFrame(
int istep) {
 
   78    SelectionManager common(info_);
 
   80    std::vector<std::vector<int>> listNN;
 
   81    std::vector<int> globalToLocal;
 
   88    unsigned int mapIndex1(0);
 
   89    unsigned int mapIndex2(0);
 
   90    unsigned int tempIndex(0);
 
   91    unsigned int whichBin(0);
 
  100    selectionCount1_ = seleMan1_.getSelectionCount();
 
  101    selectionCount2_ = seleMan2_.getSelectionCount();
 
  104    common          = seleMan1_ | seleMan2_;
 
  105    int commonCount = common.getSelectionCount();
 
  107    globalToLocal.clear();
 
  108    globalToLocal.resize(
 
  109        info_->getNGlobalAtoms() + info_->getNGlobalRigidBodies(), -1);
 
  110    for (
unsigned int i = 0; i < listNN.size(); i++)
 
  111      listNN.at(i).clear();
 
  113    listNN.resize(commonCount);
 
  114    std::vector<RealType> histo;
 
  115    histo.resize(bins_, 0.0);
 
  118    for (sd1 = common.beginSelected(iterator1); sd1 != NULL;
 
  119         sd1 = common.nextSelected(iterator1)) {
 
  120      globalToLocal.at(sd1->getGlobalIndex()) = mapIndex1;
 
  122      pos1 = sd1->getPos();
 
  125      for (sd2 = common.beginSelected(iterator2); sd2 != NULL;
 
  126           sd2 = common.nextSelected(iterator2)) {
 
  127        if (mapIndex1 < mapIndex2) {
 
  128          pos2 = sd2->getPos();
 
  130          if (usePBC_) currentSnapshot_->wrapVector(diff);
 
  132          if (distance < rCut_) {
 
  133            listNN.at(mapIndex1).push_back(mapIndex2);
 
  134            listNN.at(mapIndex2).push_back(mapIndex1);
 
  143    for (sd1 = seleMan1_.beginSelected(iterator1); sd1 != NULL;
 
  144         sd1 = seleMan1_.nextSelected(iterator1)) {
 
  145      mapIndex1 = globalToLocal.at(sd1->getGlobalIndex());
 
  147      for (
unsigned int i = 0; i < listNN.at(mapIndex1).size(); i++) {
 
  149        tempIndex = listNN.at(mapIndex1).at(i);
 
  150        gcn += listNN.at(tempIndex).size();
 
  154      whichBin = int(gcn / delta_);
 
  155      if (whichBin < histo.size()) {
 
  156        histo[whichBin] += 1;
 
  158        cerr << 
"In frame " << istep << 
", object " << sd1->getGlobalIndex()
 
  159             << 
" has GCN value = " << gcn << 
"\n";
 
  163    for (
unsigned int n = 0; n < histo.size(); n++) {
 
  164      if (selectionCount1_ > 0)
 
  165        histo[n] /= RealType(selectionCount1_);
 
  170    count_.push_back(selectionCount1_);
 
  171    histogram_.push_back(histo);
 
  174  void GCNSeq::writeSequence() {
 
  175    std::ofstream ofs(outputFilename_.c_str(), std::ios::binary);
 
  179      RealType binValue(0.0);
 
  181      ofs << 
"# " << getSequenceType() << 
"\n";
 
  182      ofs << 
"# OpenMD " << r.getFullRevision() << 
"\n";
 
  183      ofs << 
"# " << r.getBuildDate() << 
"\n";
 
  184      ofs << 
"# selection script1: \"" << selectionScript1_;
 
  185      ofs << 
"\"\tselection script2: \"" << selectionScript2_ << 
"\"\n";
 
  186      if (!paramString_.empty())
 
  187        ofs << 
"# parameters: " << paramString_ << 
"\n";
 
  189      ofs << 
"#time\tvalue\n";
 
  191      for (
unsigned int i = 0; i < times_.size(); ++i) {
 
  192        ofs << 
"#Frame " << i << 
"\n";
 
  193        ofs << 
"#Selection 1 Count: " << count_[i] << 
"\n";
 
  195        for (
unsigned int n = 0; n < histogram_[i].size(); n++) {
 
  196          binValue = n * delta_;
 
  197          ofs << binValue << 
"\t" << histogram_[i][n] << 
"\n";
 
  201      snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
 
  202               "GCN::writeSequence Error: failed to open %s\n",
 
  203               outputFilename_.c_str());
 
  204      painCave.isFatal = 1;
 
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.