From 8b165a183b91235fbe7f8cf5fc5d99db8f81b6e5 Mon Sep 17 00:00:00 2001
From: Jungho Shin <jungho@physik.hu-berlin.de>
Date: Mon, 11 Sep 2017 18:22:45 +0200
Subject: [PATCH] update main code

---
 .../0.COMMENT_from_Jungho                     |  9 ---
 normalizer/normalizer-repo-tags/0.GIT_ADD.txt |  1 +
 .../calculate_repo_tags.py                    | 31 ++++-----
 .../normalizer-repo-tags/convert_2to3.sh      |  7 +-
 .../normalizer/__init__.py                    |  0
 .../normalizer/manifest.json                  |  1 +
 .../normalizer/normalizer.py                  | 65 +++++++++++++++++++
 .../normalizer-repo-tags/requirements.txt     |  2 +
 .../normalizer-repo-tags/setup_paths.py       |  6 +-
 9 files changed, 94 insertions(+), 28 deletions(-)
 delete mode 100644 normalizer/normalizer-repo-tags/0.COMMENT_from_Jungho
 create mode 100644 normalizer/normalizer-repo-tags/0.GIT_ADD.txt
 create mode 100755 normalizer/normalizer-repo-tags/normalizer/__init__.py
 create mode 100755 normalizer/normalizer-repo-tags/normalizer/manifest.json
 create mode 100644 normalizer/normalizer-repo-tags/normalizer/normalizer.py

diff --git a/normalizer/normalizer-repo-tags/0.COMMENT_from_Jungho b/normalizer/normalizer-repo-tags/0.COMMENT_from_Jungho
deleted file mode 100644
index 2b2a4ad..0000000
--- a/normalizer/normalizer-repo-tags/0.COMMENT_from_Jungho
+++ /dev/null
@@ -1,9 +0,0 @@
-
-(1) New modlue added by Jungho
-NomadRepositoryParser: Entire python module of Repository parser from 'git@gitlab.mpcdf.mpg.de:NoMaD/NomadRepositoryParser.git'. This can be considered as submodule.
-
-(2) New file added by Jungho
-convert_2to3.sh: Python 2.7 scripts from the NomadRepositoryParser module needs to conver to that of Python 3.0. Only need to excute when the related files are updated from the git repository.
-
-(3) New file added by Jungho
-requirements.txt: Requirements to import NomadRepositoryParser.
diff --git a/normalizer/normalizer-repo-tags/0.GIT_ADD.txt b/normalizer/normalizer-repo-tags/0.GIT_ADD.txt
new file mode 100644
index 0000000..2285620
--- /dev/null
+++ b/normalizer/normalizer-repo-tags/0.GIT_ADD.txt
@@ -0,0 +1 @@
+model_base.py?
diff --git a/normalizer/normalizer-repo-tags/calculate_repo_tags.py b/normalizer/normalizer-repo-tags/calculate_repo_tags.py
index 9f9efa5..f1d057d 100644
--- a/normalizer/normalizer-repo-tags/calculate_repo_tags.py
+++ b/normalizer/normalizer-repo-tags/calculate_repo_tags.py
@@ -18,24 +18,21 @@ def calculateTags(inputDict, backend, calcUri):
         backend.openContext(calcUri)
         repoSect = backend.openSection("section_repository_info")
 
-    # fill out i.e. backend.addValue unsing input Dict
-    #  "repository_checksum",
-    #  "repository_chemical_formula",
-    #  "repository_parser_id",
-    #  "repository_atomic_elements",
-    #  "repository_basis_set_type",
-    #  "repository_code_version",
-    #  "repository_crystal_system",
-    #  "repository_program_name",
-    #  "repository_spacegroup_nr",
-    #  "repository_system_type",
-    #  "repository_xc_treatment"
-    # add more?
-    #print("\n*** inputDict %s *** \n", inputDict)
-
     work = API()
-    for calc, error in work._parse(inputDict, "normalizerRepo")
-        print("\n*** calc %s *** \n", calc)
+    for calc, error in work._parse("/nomad/jshin/work/normalizer/scalaOut1.txt", "normalizerRepo"):
+        calc, error = work.classify(calc)
+
+    backend.addValue("repository_checksum", calc.get_checksum())
+    backend.addValue("repository_chemical_formula", calc.info['formula']
+    #backend.addValue("repository_parser_id", value)
+    backend.addValue("repository_atomic_elements", calc.info['elements'])
+    backend.addValue("repository_basis_set_type", calc.info['ansatz'])
+    #backend.addValue("repository_code_version", value)
+    backend.addValue("repository_crystal_system", calc.info['symmetry'])
+    #backend.addValue("repository_program_name", calc.info[''])
+    backend.addValue("repository_spacegroup_nr", calc.info['ng'])
+    backend.addValue("repository_system_type", calc.info['periodicity'])
+    backend.addValue("repository_xc_treatment", calc.info['H_types'])
 
     if repoSectUri:
         backend.closeContext(repoSectUri)
diff --git a/normalizer/normalizer-repo-tags/convert_2to3.sh b/normalizer/normalizer-repo-tags/convert_2to3.sh
index 7a882e5..3f78ed0 100755
--- a/normalizer/normalizer-repo-tags/convert_2to3.sh
+++ b/normalizer/normalizer-repo-tags/convert_2to3.sh
@@ -1 +1,6 @@
-2to3 -w NomadRepositoryParser/python/nomadrepo/core/settings.py
+#!/bin/bash
+
+for python_file in NomadRepositoryParser/python/nomadrepo/core/settings.py NomadRepositoryParser/python/nomadrepo/core/symmetry.py
+do
+  2to3 -w $python_file
+done
diff --git a/normalizer/normalizer-repo-tags/normalizer/__init__.py b/normalizer/normalizer-repo-tags/normalizer/__init__.py
new file mode 100755
index 0000000..e69de29
diff --git a/normalizer/normalizer-repo-tags/normalizer/manifest.json b/normalizer/normalizer-repo-tags/normalizer/manifest.json
new file mode 100755
index 0000000..9d14f69
--- /dev/null
+++ b/normalizer/normalizer-repo-tags/normalizer/manifest.json
@@ -0,0 +1 @@
+{"enabled": 1}
diff --git a/normalizer/normalizer-repo-tags/normalizer/normalizer.py b/normalizer/normalizer-repo-tags/normalizer/normalizer.py
new file mode 100644
index 0000000..be188ae
--- /dev/null
+++ b/normalizer/normalizer-repo-tags/normalizer/normalizer.py
@@ -0,0 +1,65 @@
+from ase import Atoms
+from nomadrepo.parsers import Output
+from numpy import array
+
+class normalizerRepo(Output):
+
+    def __init__(self, filename, **kwargs):
+        Output.__init__(self, filename)
+
+        # fill out i.e. backend.addValue unsing input Dict
+        #  "repository_checksum",
+        #  "repository_chemical_formula",
+        #  "repository_parser_id",
+        #  "repository_atomic_elements",
+        #  "repository_basis_set_type",
+        #  "repository_code_version",
+        #  "repository_crystal_system",
+        #  "repository_program_name",
+        #  "repository_spacegroup_nr",
+        #  "repository_system_type",
+        #  "repository_xc_treatment"
+        # add more?
+
+        filename_f = open(filename, 'r')
+        import json
+        inputDict = json.load(filename_f)[0]
+        filename_f.close()
+ 
+        atom_symbols = inputDict['section_system.last']['atom_labels']['flatData']
+ 
+        ## Change these ##
+        simulation_cell = [50.0, 50.0, 50.0]
+        configuration_periodic_dimensions = [False, False, False]
+        ####
+
+        atom_positions_flat = inputDict['section_system.last']['atom_positions']['flatData']
+        atom_positions_shape = inputDict['section_system.last']['atom_positions']['shape']
+
+        atom_positions_list = []
+        for atom_i in range(0, atom_positions_shape[0]):
+            atom_i_start = atom_i*atom_positions_shape[1]
+            atom_positions_list.append(atom_positions_flat[atom_i_start:atom_i_start+atom_positions_shape[1]])
+        atom_positions = array(atom_positions_list)
+
+        self.structures.append(Atoms(symbols   = atom_symbols,
+                                     cell      = simulation_cell,
+                                     positions = atom_positions,
+                                     pbc       = configuration_periodic_dimensions))
+
+        self.info['energy'] = inputDict['energy_total.last']
+        self.info['prog'] = inputDict['program_name'][0] + ' ' + inputDict['program_version'][0]
+        ## Need the path of mainly parsed file.
+
+        from nomadrepo.parsers.LAB.LAB import ParsingContext
+        from nomadrepo.parsers.LAB.LAB import save_xcFunctional
+        context = ParsingContext()
+        self.electrons['type'] = context.toDict_bs_type()[inputDict['program_name'][0]]
+        save_xcFunctional(self, inputDict['XC_functional_name'])
+
+        #  "repository_xc_treatment"
+
+    @staticmethod
+    def fingerprints(test_string, file=None):
+        # fake method
+        return False
diff --git a/normalizer/normalizer-repo-tags/requirements.txt b/normalizer/normalizer-repo-tags/requirements.txt
index c9e1328..477ad42 100755
--- a/normalizer/normalizer-repo-tags/requirements.txt
+++ b/normalizer/normalizer-repo-tags/requirements.txt
@@ -1 +1,3 @@
 sqlalchemy == 1.0.6
+httplib2
+bcrypt
diff --git a/normalizer/normalizer-repo-tags/setup_paths.py b/normalizer/normalizer-repo-tags/setup_paths.py
index a683d3f..b3214e6 100644
--- a/normalizer/normalizer-repo-tags/setup_paths.py
+++ b/normalizer/normalizer-repo-tags/setup_paths.py
@@ -1,10 +1,14 @@
 import sys, os, os.path
 baseDir = os.path.dirname(os.path.abspath(__file__))
 commonDir = os.path.normpath(os.path.join(baseDir,"../../../../python-common/common/python"))
-repoParserDir = os.path.normpath(os.path.join(baseDir,"NomadRepositoryParser/python/"))
+repoParserDir = os.path.normpath(os.path.join(baseDir,"/u/jungho/myscratch/NomadRepositoryParser/python/"))
+#repoParserCoreDir = os.path.normpath(os.path.join(baseDir,"NomadRepositoryParser/python/nomadrepo/core/"))
 
 if not commonDir in sys.path:
     sys.path.insert(0, commonDir)
 
 if not repoParserDir in sys.path:
     sys.path.insert(0, repoParserDir)
+
+#if not repoParserCoreDir in sys.path:
+#    sys.path.insert(0, repoParserCoreDir)
-- 
GitLab