48#include "applications/sequentialProps/GCNSeq.hpp"
55#include "utils/Revision.hpp"
56#include "utils/simError.h"
60 GCNSeq::GCNSeq(
SimInfo* info,
const std::string& filename,
61 const std::string& sele1,
const std::string& sele2,
62 RealType rCut,
int bins) :
64 rCut_(rCut), bins_(bins) {
65 setSequenceType(
"Generalized Coordination Number Distribution");
66 setOutputName(
getPrefix(filename) +
".gcnSeq");
69 RealType binMax_ = nnMax_ * 1.5;
70 delta_ = binMax_ / bins_;
71 usePBC_ = info->getSimParams()->getUsePeriodicBoundaryConditions();
73 std::stringstream params;
74 params <<
" rcut = " << rCut_ <<
", nbins = " << bins_
75 <<
", max neighbors = " << nnMax_;
76 const std::string paramString = params.str();
77 setParameterString(paramString);
80 void GCNSeq::doFrame(
int istep) {
81 SelectionManager common(info_);
83 std::vector<std::vector<int>> listNN;
84 std::vector<int> globalToLocal;
91 unsigned int mapIndex1(0);
92 unsigned int mapIndex2(0);
93 unsigned int tempIndex(0);
94 unsigned int whichBin(0);
103 selectionCount1_ = seleMan1_.getSelectionCount();
104 selectionCount2_ = seleMan2_.getSelectionCount();
107 common = seleMan1_ | seleMan2_;
108 int commonCount = common.getSelectionCount();
110 globalToLocal.clear();
111 globalToLocal.resize(
112 info_->getNGlobalAtoms() + info_->getNGlobalRigidBodies(), -1);
113 for (
unsigned int i = 0; i < listNN.size(); i++)
114 listNN.at(i).clear();
116 listNN.resize(commonCount);
117 std::vector<RealType> histo;
118 histo.resize(bins_, 0.0);
121 for (sd1 = common.beginSelected(iterator1); sd1 != NULL;
122 sd1 = common.nextSelected(iterator1)) {
123 globalToLocal.at(sd1->getGlobalIndex()) = mapIndex1;
125 pos1 = sd1->getPos();
128 for (sd2 = common.beginSelected(iterator2); sd2 != NULL;
129 sd2 = common.nextSelected(iterator2)) {
130 if (mapIndex1 < mapIndex2) {
131 pos2 = sd2->getPos();
133 if (usePBC_) currentSnapshot_->wrapVector(diff);
135 if (distance < rCut_) {
136 listNN.at(mapIndex1).push_back(mapIndex2);
137 listNN.at(mapIndex2).push_back(mapIndex1);
146 for (sd1 = seleMan1_.beginSelected(iterator1); sd1 != NULL;
147 sd1 = seleMan1_.nextSelected(iterator1)) {
148 mapIndex1 = globalToLocal.at(sd1->getGlobalIndex());
150 for (
unsigned int i = 0; i < listNN.at(mapIndex1).size(); i++) {
152 tempIndex = listNN.at(mapIndex1).at(i);
153 gcn += listNN.at(tempIndex).size();
157 whichBin = int(gcn / delta_);
158 if (whichBin < histo.size()) {
159 histo[whichBin] += 1;
161 cerr <<
"In frame " << istep <<
", object " << sd1->getGlobalIndex()
162 <<
" has GCN value = " << gcn <<
"\n";
166 for (
unsigned int n = 0; n < histo.size(); n++) {
167 if (selectionCount1_ > 0)
168 histo[n] /= RealType(selectionCount1_);
173 count_.push_back(selectionCount1_);
174 histogram_.push_back(histo);
177 void GCNSeq::writeSequence() {
178 std::ofstream ofs(outputFilename_.c_str(), std::ios::binary);
182 RealType binValue(0.0);
184 ofs <<
"# " << getSequenceType() <<
"\n";
185 ofs <<
"# OpenMD " << r.getFullRevision() <<
"\n";
186 ofs <<
"# " << r.getBuildDate() <<
"\n";
187 ofs <<
"# selection script1: \"" << selectionScript1_;
188 ofs <<
"\"\tselection script2: \"" << selectionScript2_ <<
"\"\n";
189 if (!paramString_.empty())
190 ofs <<
"# parameters: " << paramString_ <<
"\n";
192 ofs <<
"#time\tvalue\n";
194 for (
unsigned int i = 0; i < times_.size(); ++i) {
195 ofs <<
"#Frame " << i <<
"\n";
196 ofs <<
"#Selection 1 Count: " << count_[i] <<
"\n";
198 for (
unsigned int n = 0; n < histogram_[i].size(); n++) {
199 binValue = n * delta_;
200 ofs << binValue <<
"\t" << histogram_[i][n] <<
"\n";
204 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
205 "GCN::writeSequence Error: failed to open %s\n",
206 outputFilename_.c_str());
207 painCave.isFatal = 1;
"applications/sequentialProps/SequentialAnalyzer"
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.
std::string getPrefix(const std::string &str)
Real distance(const DynamicVector< Real > &v1, const DynamicVector< Real > &v2)
Returns the distance between two DynamicVectors.