added new working mode when crls are evaluated
authorAnatoly <Titov_AI@pnpi.nrcki.ru>
Mon, 10 Jun 2019 13:41:24 +0000 (16:41 +0300)
committerAnatoly <Titov_AI@pnpi.nrcki.ru>
Mon, 10 Jun 2019 13:41:24 +0000 (16:41 +0300)
src/spacetimecorr.cpp

index 0d8018de68f48f6a695fe7d90805cb4a71d871f1..da2ddbbf3bc637e711a279b2a9fe720eb122e65a 100644 (file)
@@ -47,6 +47,7 @@
 #include <math.h>
 #include <omp.h>
 #include <string>
+#include <sstream>
 
 #include <gromacs/trajectoryanalysis.h>
 #include <gromacs/utility/smalloc.h>
@@ -57,6 +58,27 @@ using namespace gmx;
 
 using gmx::RVec;
 
+void read_correlation_matrix_file(std::vector< std::vector< std::vector< float > > > &crrlts, const char* file_name, int size)
+{
+    FILE *file;
+    file = std::fopen(file_name, "r+");
+    crrlts.resize(0);
+    char *a;
+    float temp = 0;
+    while (!std::feof(file)) {
+        std::fscanf(file, "%s\n", a);
+        crrlts.resize(crrlts.size() + 1);
+        for (int j = 0; j < size; j++) {
+            crrlts.back().resize(crrlts.back().size() + 1);
+            for (int f = 0; f < size; f++) {
+                std::fscanf(file, "%f", temp);
+                crrlts.back()[j].push_back(temp);
+            }
+        }
+    }
+    std::fclose(file);
+}
+
 void make_correlation_matrix_file(std::vector< std::vector< std::vector< float > > > correlations, const char* file_name, int start)
 {
     FILE *file;
@@ -410,10 +432,12 @@ class SpaceTimeCorr : public TrajectoryAnalysisModule
 
         std::vector< int >                                          index;
         int                                                         frames              = 0;
-        int                                                         tau                 = 0; // selectable
-        float                                                       crl_border          = 0; // selectable
-        float                                                       eff_rad             = 1.5; // selectable
-        std::string                                                 OutPutName; // selectable
+        int                                                         tau                 = 0;    // selectable
+        float                                                       crl_border          = 0;    // selectable
+        float                                                       eff_rad             = 1.5;  // selectable
+        std::string                                                 OutPutName;                 // selectable
+        int                                                         mode                = 0;    // selectable
+        std::string                                                 MtrxNm;                     // selectable
         // Copy and assign disallowed by base.
 };
 
@@ -438,6 +462,14 @@ SpaceTimeCorr::initOptions(IOptionsContainer          *options,
     //options->addOption(FileNameOption("on").filetype(eftIndex).outputFile()
     //                        .store(&fnNdx_).defaultBasename("domains")
     //                        .description("Index file from the domains"));
+    // Add option for working mode
+    options->addOption(gmx::IntegerOption("mode")
+                            .store(&mode)
+                            .description("default 0 | rdy correlation matrixes 1, need extra params"));
+    // Add option for Matrix Input file names
+    options->addOption(StringOption("Mtrx_in_put")
+                            .store(&MtrxNm)
+                            .description("mandatory if work mode == 1"));
     // Add option for tau constant
     options->addOption(gmx::IntegerOption("tau")
                             .store(&tau)
@@ -454,6 +486,7 @@ SpaceTimeCorr::initOptions(IOptionsContainer          *options,
     options->addOption(SelectionOption("select_domains_and_residue").storeVector(&sel_)
                            .required().dynamicMask().multiValue()
                            .description("Domains to form rigid skeleton"));
+    // Add option for output file names
     options->addOption(StringOption("out_put")
                             .store(&OutPutName)
                             .description("<your name here> + <local file tag>.txt"));
@@ -524,17 +557,21 @@ SpaceTimeCorr::finishAnalysis(int nframes)
         k = tau;
     }
 
-    std::cout << "\nCorrelation's evaluation - start\n";
+    if (mode == 0) {
+        std::cout << "\nCorrelation's evaluation - start\n";
 
-    correlation_evaluation(reference, trajectory, crltns, m, k);
+        correlation_evaluation(reference, trajectory, crltns, m, k);
 
-    make_correlation_matrix_file(crltns, (OutPutName + "_matrix.txt").c_str(), 0);
-    std::cout << "corelation matrix printed\n";
+        make_correlation_matrix_file(crltns, (OutPutName + "_matrix.txt").c_str(), 0);
+        std::cout << "corelation matrix printed\n";
 
-    make_correlation_pairs_file(crltns, (OutPutName + "_pairs.txt").c_str(), 0);
-    std::cout << "corelation pairs printed\n";
+        make_correlation_pairs_file(crltns, (OutPutName + "_pairs.txt").c_str(), 0);
+        std::cout << "corelation pairs printed\n";
 
-    std::cout << "Correlation's evaluation - end\n" << "graph evaluation: start\n";
+        std::cout << "Correlation's evaluation - end\n" << "graph evaluation: start\n";
+    } else if (mode == 1) {
+        read_correlation_matrix_file(crltns, (MtrxNm).c_str(), index.size());
+    }
 
     graph_calculation(graph, sub_graph, sub_graph_rbr, trajectory, reference, crltns, crl_border, eff_rad, k);
     std::cout << "graph evaluation: end\n" << "routs evaluation: start\n";