From 83a4de4efa40731f7e192c795fc1e82f00f27fc8 Mon Sep 17 00:00:00 2001
From: speckhard <dts@stanford.edu>
Date: Fri, 22 Feb 2019 12:34:16 +0100
Subject: [PATCH] Added Orca to Nomad-Faird framework.

---
 .gitignore                                    |  2 +
 orcaparser.egg-info/PKG-INFO                  | 10 +++
 orcaparser.egg-info/SOURCES.txt               | 10 +++
 orcaparser.egg-info/dependency_links.txt      |  1 +
 orcaparser.egg-info/requires.txt              |  1 +
 orcaparser.egg-info/top_level.txt             |  1 +
 orcaparser/__init__.py                        | 15 +++++
 .../orca_parser.py => orcaparser/parser.py    | 46 ++++++++++----
 .../parser-orca => orcaparser}/setup_paths.py |  0
 setup.py                                      | 33 ++++++++++
 .../eu/nomad_lab/parsers/OrcaParser.scala     | 61 -------------------
 .../eu/nomad_lab/parsers/OrcaParserSpec.scala | 30 ---------
 12 files changed, 106 insertions(+), 104 deletions(-)
 create mode 100644 orcaparser.egg-info/PKG-INFO
 create mode 100644 orcaparser.egg-info/SOURCES.txt
 create mode 100644 orcaparser.egg-info/dependency_links.txt
 create mode 100644 orcaparser.egg-info/requires.txt
 create mode 100644 orcaparser.egg-info/top_level.txt
 create mode 100644 orcaparser/__init__.py
 rename parser/parser-orca/orca_parser.py => orcaparser/parser.py (97%)
 rename {parser/parser-orca => orcaparser}/setup_paths.py (100%)
 create mode 100644 setup.py
 delete mode 100644 src/main/scala/eu/nomad_lab/parsers/OrcaParser.scala
 delete mode 100644 src/test/scala/eu/nomad_lab/parsers/OrcaParserSpec.scala

diff --git a/.gitignore b/.gitignore
index a6cb8b6..5f92ac3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,6 +9,8 @@ syntax: glob
 *.pyc
 *.bk
 *.swp
+*.egg-info
+
 .DS_Store
 
 # logging files
diff --git a/orcaparser.egg-info/PKG-INFO b/orcaparser.egg-info/PKG-INFO
new file mode 100644
index 0000000..cfdc984
--- /dev/null
+++ b/orcaparser.egg-info/PKG-INFO
@@ -0,0 +1,10 @@
+Metadata-Version: 1.0
+Name: orcaparser
+Version: 0.1
+Summary: NOMAD parser implementation for Orca.
+Home-page: UNKNOWN
+Author: UNKNOWN
+Author-email: UNKNOWN
+License: APACHE 2.0
+Description: UNKNOWN
+Platform: UNKNOWN
diff --git a/orcaparser.egg-info/SOURCES.txt b/orcaparser.egg-info/SOURCES.txt
new file mode 100644
index 0000000..acef332
--- /dev/null
+++ b/orcaparser.egg-info/SOURCES.txt
@@ -0,0 +1,10 @@
+README.md
+setup.py
+./orcaparser/__init__.py
+./orcaparser/parser.py
+./orcaparser/setup_paths.py
+./orcaparser.egg-info/PKG-INFO
+./orcaparser.egg-info/SOURCES.txt
+./orcaparser.egg-info/dependency_links.txt
+./orcaparser.egg-info/requires.txt
+./orcaparser.egg-info/top_level.txt
\ No newline at end of file
diff --git a/orcaparser.egg-info/dependency_links.txt b/orcaparser.egg-info/dependency_links.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/orcaparser.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/orcaparser.egg-info/requires.txt b/orcaparser.egg-info/requires.txt
new file mode 100644
index 0000000..f23d347
--- /dev/null
+++ b/orcaparser.egg-info/requires.txt
@@ -0,0 +1 @@
+nomadcore
diff --git a/orcaparser.egg-info/top_level.txt b/orcaparser.egg-info/top_level.txt
new file mode 100644
index 0000000..9a96c6e
--- /dev/null
+++ b/orcaparser.egg-info/top_level.txt
@@ -0,0 +1 @@
+orcaparser
diff --git a/orcaparser/__init__.py b/orcaparser/__init__.py
new file mode 100644
index 0000000..31bf698
--- /dev/null
+++ b/orcaparser/__init__.py
@@ -0,0 +1,15 @@
+# Copyright 2015-2018 Lauri Himanen, Fawzi Mohamed, Ankit Kariryaa
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+from orcaparser.parser import OrcaParser
diff --git a/parser/parser-orca/orca_parser.py b/orcaparser/parser.py
similarity index 97%
rename from parser/parser-orca/orca_parser.py
rename to orcaparser/parser.py
index c3f9546..88b958b 100644
--- a/parser/parser-orca/orca_parser.py
+++ b/orcaparser/parser.py
@@ -1,11 +1,11 @@
 # Copyright 2016-2018 Sebastian Alarcon Villaseca, Sebastián Alarcón Villaseca, Fawzi Mohamed, Micael Oliveira, Ankit Kariryaa, Danio Brambila
-# 
+#
 #   Licensed under the Apache License, Version 2.0 (the "License");
 #   you may not use this file except in compliance with the License.
 #   You may obtain a copy of the License at
-# 
+#
 #     http://www.apache.org/licenses/LICENSE-2.0
-# 
+#
 #   Unless required by applicable law or agreed to in writing, software
 #   distributed under the License is distributed on an "AS IS" BASIS,
 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -14,7 +14,6 @@
 
 # -*- coding: utf-8 -*
 from builtins import object
-import setup_paths
 import numpy as np
 from nomadcore.simple_parser import SimpleMatcher, mainFunction
 from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
@@ -88,7 +87,7 @@ class OrcaContext(object):
 		#***************************************
 		# Local functionals
 		#***************************************
-		# HFS: Hartree-Fock Slater 
+		# HFS: Hartree-Fock Slater
                 "HF":     ["HF_X"],
                 "HFS":    ["HF_X"],
 		# XAlpha: The famous old Slater Xa theory
@@ -151,7 +150,7 @@ class OrcaContext(object):
 		"TPSS":   ["LDA_X", "MGGA_X_TPSS", "LDA_C_PW", "MGGA_C_TPSS"],
 		# TPSSh: The hybrid version of TPSS (10% HF exchange)
 		"TPSSh":  ["HYB_MGGA_XC_TPSSH"],
-		# TPSS0: A 25% exchange version of TPSSh that yields improved energetics 
+		# TPSS0: A 25% exchange version of TPSSh that yields improved energetics
                 # compared to TPSSh but is otherwise not well tested
 		# "TPSS0":  ["HYB_MGGA_XC_TPSSH"],
 		# M06L: The Minnesota M06-L meta-GGA functional
@@ -285,7 +284,7 @@ def build_OrcaMainFileSimpleMatcher():
     which allows nice formating of nested SimpleMatchers in python.
 
     Returns:
-       SimpleMatcher that parses main file of ORCA. 
+       SimpleMatcher that parses main file of ORCA.
     """
 #
 # a) SimpleMatcher for header and ORCA version:
@@ -333,7 +332,7 @@ def buildSinglePointSubMatchers():
           subMatchers = [
           SM(r"\s+(?P<x_orca_atom_labels>[a-zA-Z]+)\s+(?P<x_orca_atom_positions_x__angstrom>[-+0-9.]+)\s+(?P<x_orca_atom_positions_y__angstrom>[-+0-9.]+)\s+(?P<x_orca_atom_positions_z__angstrom>[-+0-9.]+)", repeats = True)
           ]
-       ),  
+       ),
        # Get basis set information:
        SM(name = 'Basis set information',
           startReStr = r"BASIS SET INFORMATION\s*",
@@ -349,7 +348,7 @@ def buildSinglePointSubMatchers():
              SM(r"\s*Group\s+[0-9]+\s+Type\s+(?P<x_orca_basis_set_atom_labels>[a-zA-Z]+)\s+:\s+(?P<x_orca_auxiliary_basis_set>[0-9a-z]+)\s+contracted\s+to\s+(?P<x_orca_auxiliary_basis_set_contracted>[0-9a-z]+)\s+pattern\s+\{[0-9/]+\}", repeats = True)
              ]
           )
-          ]   
+          ]
        ),
        # Basis set statistics and startup info:
        SM(name = 'Basis set statistics and startup info',
@@ -544,7 +543,7 @@ def buildGeoOptMatcher():
 #
 # c) SimpleMatcher for geometry optimization:
 # *******************************************
-# 
+#
        return SM(name = 'Geometry optimization',
           startReStr = r"\s*\* Geometry Optimization Run \*\s*",
           sections = ["section_sampling_method"],
@@ -570,7 +569,7 @@ def buildGeoOptMatcher():
              sections = ["x_orca_final_geometry"],
              subMatchers = [
              SM(r"\s+(?P<x_orca_atom_labels_geo_opt>[a-zA-Z]+)\s+(?P<x_orca_atom_positions_x_geo_opt__angstrom>[-+0-9.]+)\s+(?P<x_orca_atom_positions_y_geo_opt__angstrom>[-+0-9.]+)\s+(?P<x_orca_atom_positions_z_geo_opt__angstrom>[-+0-9.]+)", repeats = True)
-             ]  
+             ]
           ),
        # *** FINAL ENERGY EVALUATION AT THE STATIONARY POINT ***
        #
@@ -586,7 +585,7 @@ def buildMp2Matcher():
 #
 # d) Post-processing calculations:
 # ********************************
-# 
+#
        # MP2 Calculation (post-proc):
     return SM(name = 'mp2',
           startReStr = r"\s*ORCA MP2 CALCULATION\s*",
@@ -711,8 +710,29 @@ parserInfo = {
   "version": "1.0"
 }
 
-metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)),"../../../../nomad-meta-info/meta_info/nomad_meta_info/orca.nomadmetainfo.json"))
+import nomad_meta_info
+metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(nomad_meta_info.__file__)), "orca.nomadmetainfo.json"))
 metaInfoEnv, warnings = loadJsonFile(filePath = metaInfoPath, dependencyLoader = None, extraArgsHandling = InfoKindEl.ADD_EXTRA_ARGS, uri = None)
 
+class OrcaParser():
+   """ A proper class envolop for running this parser from within python. """
+   def __init__(self, backend, **kwargs):
+       self.backend_factory = backend
+
+   def parse(self, mainfile):
+       from unittest.mock import patch
+       logging.info('orca parser started')
+       logging.getLogger('nomadcore').setLevel(logging.WARNING)
+       backend = self.backend_factory(metaInfoEnv)
+       with patch.object(sys, 'argv', ['<exe>', '--uri', 'nmd://uri', mainfile]):
+           mainFunction(
+               mainFileDescription,
+               metaInfoEnv,
+               parserInfo,
+               superContext=OrcaContext(),
+               superBackend=backend)
+
+       return backend
+
 if __name__ == "__main__":
     mainFunction(mainFileDescription, metaInfoEnv, parserInfo, superContext=OrcaContext())
diff --git a/parser/parser-orca/setup_paths.py b/orcaparser/setup_paths.py
similarity index 100%
rename from parser/parser-orca/setup_paths.py
rename to orcaparser/setup_paths.py
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..7444433
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,33 @@
+# Copyright 2015-2018 Lorenzo Pardini
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+from setuptools import setup, find_packages
+
+
+def main():
+    setup(
+        name='orcaparser',
+        version='0.1',
+        description='NOMAD parser implementation for Orca.',
+        license='APACHE 2.0',
+        package_dir={'': './'},
+        packages=find_packages(),
+        install_requires=[
+            'nomadcore'
+        ],
+    )
+
+
+if __name__ == '__main__':
+    main()
diff --git a/src/main/scala/eu/nomad_lab/parsers/OrcaParser.scala b/src/main/scala/eu/nomad_lab/parsers/OrcaParser.scala
deleted file mode 100644
index ba0f4dc..0000000
--- a/src/main/scala/eu/nomad_lab/parsers/OrcaParser.scala
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 2016-2018 Sebastian Alarcon Villaseca, Sebastián Alarcón Villaseca, Fawzi Mohamed, Micael Oliveira, Ankit Kariryaa, Danio Brambila
- * 
- *   Licensed under the Apache License, Version 2.0 (the "License");
- *   you may not use this file except in compliance with the License.
- *   You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- *   Unless required by applicable law or agreed to in writing, software
- *   distributed under the License is distributed on an "AS IS" BASIS,
- *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *   See the License for the specific language governing permissions and
- *   limitations under the License.
- */
-
-package eu.nomad_lab.parsers
-
-import eu.{ nomad_lab => lab }
-import eu.nomad_lab.DefaultPythonInterpreter
-import org.{ json4s => jn }
-import scala.collection.breakOut
-
-object OrcaParser extends SimpleExternalParserGenerator(
-  name = "OrcaParser",
-  parserInfo = jn.JObject(
-    ("name" -> jn.JString("OrcaParser")) ::
-      ("parserId" -> jn.JString("OrcaParser" + lab.OrcaVersionInfo.version)) ::
-      ("versionInfo" -> jn.JObject(
-        ("nomadCoreVersion" -> jn.JObject(lab.NomadCoreVersionInfo.toMap.map {
-          case (k, v) => k -> jn.JString(v.toString)
-        }(breakOut): List[(String, jn.JString)])) ::
-          (lab.OrcaVersionInfo.toMap.map {
-            case (key, value) =>
-              (key -> jn.JString(value.toString))
-          }(breakOut): List[(String, jn.JString)])
-      )) :: Nil
-  ),
-  mainFileTypes = Seq("text/.*"),
-  mainFileRe = """\s+\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**\s*
-\s+\* O   R   C   A \*\s*
-\s+\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**\s*
-\s*
-\s*--- An Ab Initio, DFT and Semiempirical electronic structure package ---\s*
-""".r,
-  cmd = Seq(DefaultPythonInterpreter.pythonExe(), "${envDir}/parsers/orca/parser/parser-orca/orca_parser.py",
-    "--uri", "${mainFileUri}", "${mainFilePath}"),
-  resList = Seq(
-    "parser-orca/orca_parser.py",
-    "parser-orca/setup_paths.py",
-    "nomad_meta_info/public.nomadmetainfo.json",
-    "nomad_meta_info/common.nomadmetainfo.json",
-    "nomad_meta_info/meta_types.nomadmetainfo.json",
-    "nomad_meta_info/orca.nomadmetainfo.json"
-  ) ++ DefaultPythonInterpreter.commonFiles(),
-  dirMap = Map(
-    "parser-orca" -> "parsers/orca/parser/parser-orca",
-    "nomad_meta_info" -> "nomad-meta-info/meta_info/nomad_meta_info"
-  ) ++ DefaultPythonInterpreter.commonDirMapping(),
-  metaInfoEnv = Some(lab.meta.KnownMetaInfoEnvs.orca)
-)
diff --git a/src/test/scala/eu/nomad_lab/parsers/OrcaParserSpec.scala b/src/test/scala/eu/nomad_lab/parsers/OrcaParserSpec.scala
deleted file mode 100644
index c8f4c0a..0000000
--- a/src/test/scala/eu/nomad_lab/parsers/OrcaParserSpec.scala
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright 2016-2018 Sebastian Alarcon Villaseca, Sebastián Alarcón Villaseca, Fawzi Mohamed, Micael Oliveira, Ankit Kariryaa, Danio Brambila
- * 
- *   Licensed under the Apache License, Version 2.0 (the "License");
- *   you may not use this file except in compliance with the License.
- *   You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- *   Unless required by applicable law or agreed to in writing, software
- *   distributed under the License is distributed on an "AS IS" BASIS,
- *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *   See the License for the specific language governing permissions and
- *   limitations under the License.
- */
-
-package eu.nomad_lab.parsers
-
-import org.specs2.mutable.Specification
-
-object OrcaParserSpec extends Specification {
-  "OrcaParserTest" >> {
-    "test with json-events" >> {
-      ParserRun.parse(OrcaParser, "parsers/orca/test/examples/output_files/orca3.2706823.out", "json-events") must_== ParseResult.ParseSuccess
-    }
-    "test with json" >> {
-      ParserRun.parse(OrcaParser, "parsers/orca/test/examples/output_files/orca3.2706823.out", "json") must_== ParseResult.ParseSuccess
-    }
-  }
-}
-- 
GitLab