- changed to prefix "++"
[alexxy/gromacs-spacetimecorr.git] / src / spacetimecorr.cpp
index 32a876f0fd33e222bd2911abe5051df2d9c5334a..8e3d04c65472a37d39fef753b8553f6c4ba31ded 100644 (file)
@@ -95,18 +95,15 @@ class SpaceTimeCorr : public TrajectoryAnalysisModule
 
         SelectionList                                           sel_;
         std::vector< RVec >                                     trajectoryFrame;
-
-        std::vector< std::vector < std::vector < size_t > > >   sels;
-        std::vector< int >                                      index;
+        std::vector< size_t >                                   index;
 
         int                                                     tauJump            {100};  // selectable
-
         int                                                     window             {1000}; // selectable
         int                                                     tau                {500};  // selectable
         float                                                   crlBorder          {0.5};  // selectable
         float                                                   effRad             {1.5};  // selectable
-        std::string                                             outPutName;                 // selectable
-       // может лучше в виде enum?
+        std::string                                             outPutName;                // selectable
+        // может лучше в виде enum?
         int                                                     mode               {1};    // selectable
 
         correlationType                                         corrs;
@@ -180,25 +177,29 @@ void
 SpaceTimeCorr::initAnalysis(const TrajectoryAnalysisSettings &settings, const TopologyInformation &top)
 {
     std::cout << "\tinitAnalysis - start\n";
-    std::vector< std::string >                                  resNms;
-    std::vector< RVec >                                         reference;
+    std::vector< std::string >                              resNms;
+    std::vector< RVec >                                     reference;
+    std::vector< std::vector < std::vector < size_t > > >   sels;
     ArrayRef< const int > atomind {sel_.front().atomIndices()};
     index.resize(0);
-    for (ArrayRef< const int >::iterator ai {atomind.begin()}; (ai < atomind.end()); ai++) {
+    for (ArrayRef< const int >::iterator ai {atomind.begin()}; (ai < atomind.end()); ++ai) {
         index.push_back(*ai);
         resNms.push_back(*(top.atoms()->resinfo[top.atoms()->atom[*ai].resind].name) + std::to_string((top.atoms()->atom[*ai].resind + 1)));
     }
-    std::string str(sel_.back().name());
-    size_t tempSize {std::stoul(str.substr(13, 6)) / static_cast< size_t >(tauJump) + 1};
-    sels.resize(tempSize);
+    std::string tempString(sel_.back().name());
+    size_t tempSize {std::stoul(tempString.substr(13, 6)) / static_cast< size_t >(tauJump) + 1};
     std::vector< size_t > a;
     a.resize(0);
-    for (size_t i {1}; i < sel_.size(); i++) {
-        std::string str(sel_[i].name());
+    sels.resize(tempSize);
+    for (auto &i : sels) {
+        i.resize(0);
+    }
+    for (size_t i {1}; i < sel_.size(); ++i) {
         atomind = sel_[i].atomIndices();
-        sels[std::stoul(str.substr(13, 6)) / static_cast< size_t >(tauJump)].push_back(a);
-        for (ArrayRef< const int >::iterator ai {atomind.begin()}; (ai < atomind.end()); ai++) {
-            sels[std::stoul(str.substr(13, 6)) / static_cast< size_t >(tauJump)].back().push_back(static_cast< size_t >(*ai));
+        tempString = sel_[i].name();
+        sels[std::stoul(tempString.substr(13, 6)) / static_cast< size_t >(tauJump)].push_back(a);
+        for (ArrayRef< const int >::iterator ai {atomind.begin()}; (ai < atomind.end()); ++ai) {
+            sels[std::stoul(tempString.substr(13, 6)) / static_cast< size_t >(tauJump)].back().push_back(static_cast< size_t >(*ai));
         }
     }
     reference.resize(0);
@@ -223,7 +224,7 @@ SpaceTimeCorr::analyzeFrame(int frnr, const t_trxframe &fr, t_pbc *pbc, Trajecto
 {
     trajectoryFrame.resize(0);
     trajectoryFrame.resize(index.size());
-    for (size_t i {0}; i < index.size(); i++) {
+    for (size_t i {0}; i < index.size(); ++i) {
         trajectoryFrame[i] = fr.x[index[i]];
     }
     corrs.update(frnr, trajectoryFrame);