From 43954fc74e47f0a891d729e6e2fedcb2448183a0 Mon Sep 17 00:00:00 2001
From: Lauri Himanen <lauri.himanen@aalto.fi>
Date: Wed, 20 Jul 2016 19:35:19 +0300
Subject: [PATCH] Fixed issue that created only one section_system in geo_opt.

---
 .../cpmdparser/versions/cpmd41/commonparser.py       | 12 +++++++-----
 .../cpmdparser/versions/cpmd41/geooptparser.py       |  9 +++++++--
 .../cpmdparser/versions/cpmd41/singlepointparser.py  |  3 +++
 test/unittests/cpmd_4.1/run_tests.py                 |  2 +-
 4 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/parser/parser-cpmd/cpmdparser/versions/cpmd41/commonparser.py b/parser/parser-cpmd/cpmdparser/versions/cpmd41/commonparser.py
index 46a9221..154ecf8 100644
--- a/parser/parser-cpmd/cpmdparser/versions/cpmd41/commonparser.py
+++ b/parser/parser-cpmd/cpmdparser/versions/cpmd41/commonparser.py
@@ -21,7 +21,10 @@ class CPMDCommonParser(CommonParser):
 
         #=======================================================================
         # Globally cached values
-        self.cache_service.add("initial_positions")
+        self.cache_service.add("initial_positions", single=False, update=False)
+        self.cache_service.add("atom_labels", single=False, update=False)
+        self.cache_service.add("number_of_atoms", single=False, update=False)
+        self.cache_service.add("simulation_cell", single=False, update=False)
 
     #===========================================================================
     # Common SimpleMatchers
@@ -235,7 +238,7 @@ class CPMDCommonParser(CommonParser):
         A2_array = self.vector_from_string(A2)
         A3_array = self.vector_from_string(A3)
         cell = np.vstack((A1_array, A2_array, A3_array))
-        backend.addArrayValues("simulation_cell", cell, unit="bohr")
+        self.cache_service["simulation_cell"] = cell
 
         # Plane wave basis
         cutoff = section.get_latest_value("x_cpmd_wave_function_cutoff")
@@ -291,9 +294,8 @@ class CPMDCommonParser(CommonParser):
             # If anything found, push the results to the correct section
             if len(coordinates) != 0:
                 self.cache_service["initial_positions"] = coordinates
-                # parser.backend.addArrayValues("atom_positions", coordinates, unit="bohr")
-                parser.backend.addArrayValues("atom_labels", labels)
-                parser.backend.addValue("number_of_atoms", coordinates.shape[0])
+                self.cache_service["atom_labels"] = labels
+                self.cache_service["number_of_atoms"] = coordinates.shape[0]
 
         return wrapper
 
diff --git a/parser/parser-cpmd/cpmdparser/versions/cpmd41/geooptparser.py b/parser/parser-cpmd/cpmdparser/versions/cpmd41/geooptparser.py
index 75b7d0f..546e4fa 100644
--- a/parser/parser-cpmd/cpmdparser/versions/cpmd41/geooptparser.py
+++ b/parser/parser-cpmd/cpmdparser/versions/cpmd41/geooptparser.py
@@ -35,7 +35,7 @@ class CPMDGeoOptParser(MainHierarchicalParser):
         # Main structure
         self.root_matcher = SM("",
             forwardMatch=True,
-            sections=['section_run', "section_frame_sequence", "section_sampling_method", "section_system", "section_method"],
+            sections=['section_run', "section_frame_sequence", "section_sampling_method",  "section_method"],
             subMatchers=[
                 self.cm.header(),
                 self.cm.method(),
@@ -65,7 +65,7 @@ class CPMDGeoOptParser(MainHierarchicalParser):
                             forwardMatch=True,
                             endReStr=re.escape(" *** CNSTR="),
                             repeats=True,
-                            sections=["section_single_configuration_calculation", "x_cpmd_section_geo_opt_step"],
+                            sections=["section_single_configuration_calculation", "section_system", "x_cpmd_section_geo_opt_step"],
                             subMatchers=[
                                 SM( "\s+(?P<x_cpmd_geo_opt_scf_nfi>{0})\s+(?P<x_cpmd_geo_opt_scf_gemax>{1})\s+(?P<x_cpmd_geo_opt_scf_cnorm>{1})\s+(?P<x_cpmd_geo_opt_scf_etot__hartree>{1})\s+(?P<x_cpmd_geo_opt_scf_detot__hartree>{1})\s+(?P<x_cpmd_geo_opt_scf_tcpu__s>{1})".format(self.regexs.int, self.regexs.float),
                                     sections=["x_cpmd_section_geo_opt_scf_iteration"],
@@ -129,5 +129,10 @@ class CPMDGeoOptParser(MainHierarchicalParser):
         self.sampling_method_gid = gIndex
         backend.addValue("sampling_method", "geometry_optimization")
 
+    def onClose_section_system(self, backend, gIndex, section):
+        self.cache_service.addArrayValues("atom_labels")
+        self.cache_service.addArrayValues("simulation_cell", unit="bohr")
+        self.cache_service.addValue("number_of_atoms")
+
     #=======================================================================
     # adHoc
diff --git a/parser/parser-cpmd/cpmdparser/versions/cpmd41/singlepointparser.py b/parser/parser-cpmd/cpmdparser/versions/cpmd41/singlepointparser.py
index 829f6f3..f8b007d 100644
--- a/parser/parser-cpmd/cpmdparser/versions/cpmd41/singlepointparser.py
+++ b/parser/parser-cpmd/cpmdparser/versions/cpmd41/singlepointparser.py
@@ -84,6 +84,9 @@ class CPMDSinglePointParser(MainHierarchicalParser):
 
     def onClose_section_system(self, backend, gIndex, section):
         self.cache_service.addArrayValues("atom_positions", "initial_positions", unit="bohr")
+        self.cache_service.addArrayValues("atom_labels")
+        self.cache_service.addArrayValues("simulation_cell", unit="bohr")
+        self.cache_service.addValue("number_of_atoms")
 
     #=======================================================================
     # adHoc
diff --git a/test/unittests/cpmd_4.1/run_tests.py b/test/unittests/cpmd_4.1/run_tests.py
index 0c1d1fe..da888cf 100644
--- a/test/unittests/cpmd_4.1/run_tests.py
+++ b/test/unittests/cpmd_4.1/run_tests.py
@@ -73,7 +73,7 @@ class TestInputParser(unittest.TestCase):
         self.assertEqual(result, "*H_MT_LDA.psp\nLMAX=S\n2\n4.371   4.000   4.000\n3.629   4.000   4.000")
 
     def test_x_cpmd_input_optimize_wavefunction(self):
-        result = self.results["x_cpmd_section_input_CPMD.OPTIMIZE_WAVEFUNCTION"]
+        self.results["x_cpmd_section_input_CPMD.OPTIMIZE_WAVEFUNCTION"]
 
 
 #===============================================================================
-- 
GitLab