- fixed an issue with output and color stacking
[alexxy/gromacs-colorvec.git] / src / colorvec.cpp
index 4acc2657bb4707a75b5fb512ccadb3b38774a9e0..8847698c3405543f64e37f466af3021e336b6acc 100644 (file)
@@ -287,19 +287,22 @@ void colorsStackingSearch(const t_pbc *inputPBC, const std::vector< gmx::RVec >
         outputTemp[i].resize(colorsIndex.size(), 0);
     }
     gmx::RVec temp;
+    bool flag {false};
     #pragma omp parallel for ordered schedule(dynamic)
     for (size_t i = 0; i < colorsIndex.size(); ++i) {
         for (size_t j {0}; j < colorsIndex.size(); ++j) {
-            if (i != j) {
+           if (i != j) {
                 for (size_t k1 {0}; k1 < colorsIndex[i].size(); ++k1) {
-                    for (size_t k2 {0}; k2 < colorsIndex[j].size(); ++k2) {
+                    flag = false;
+                   for (size_t k2 {0}; k2 < colorsIndex[j].size() && !flag; ++k2) {
                         pbc_dx(inputPBC, inputFrame[colorsIndex[i][k1].second], inputFrame[colorsIndex[j][k2].second], temp);
                         if (temp.norm() <= radius) {
-                            ++outputTemp[i][j];
+                                flag = true;
+                                ++outputTemp[i][j];
                         }
-                    }
+                   }
                 }
-            }
+           }
         }
     }
     #pragma omp barrier
@@ -352,7 +355,7 @@ void anglesFileDump(const int frameNum, const std::string       &output,
     std::ofstream   file(output, std::ofstream::app);
     file << "frame =" << std::setw(8) << frameNum << std::endl;
     for (size_t i {0}; i < colorFormation.size(); ++i) {
-        file << "color #" << std::setw(3) << i + 1;
+        file << "color #" << std::setw(3) << i;
         if (toPeptide[i]) {
             file << std::setw(4) << "yes";
         } else {
@@ -385,17 +388,17 @@ void anglesFileDump(const int frameNum, const std::string       &output,
             file << " ] ";
         }
         if (inputStack[i].size() == 0) {
-            file << std::setw(4) << "no []";
+            file << std::setw(5) << "no [] ";
         } else {
-            file << std::setw(4) << "yes [";
-            file << std::setw(4) << inputStack[i].size();
+            file << std::setw(5) << "yes";
+            file << std::setw(4) << inputStack[i].size() << " [";
             for (size_t j {0}; j < inputStack[i].size(); ++j) {
                 file << std::setw(4) << inputStack[i][j];
             }
             file << " ] ";
         }
         if (dipoleBetaAngles[i].size() == 0) {
-            file << "no []";
+            file << std::setw(5) << "no [] ";
         } else {
             double tempDBangle {0.};
             for (size_t j {0}; j < dipoleBetaAngles[i].size(); ++j) {
@@ -405,8 +408,9 @@ void anglesFileDump(const int frameNum, const std::string       &output,
             for (size_t j {0}; j < dipoleBetaAngles[i].size(); ++j) {
                 file << std::setw(8) << std::setprecision(2) << dipoleBetaAngles[i][j];
             }
+            file << " ]";
         }
-        file << " ]" << std::endl;
+        file << std::endl;
     }
     file.close();
 }