From ce58ded8619ed8466bf506b7decee14003d22cb1 Mon Sep 17 00:00:00 2001
From: Mikkel Strange <mikst@fysik.dtu.dk>
Date: Wed, 28 Sep 2016 16:57:05 +0200
Subject: [PATCH] more polishing

---
 parser/parser-atk/atkio.py                 |  5 +++
 parser/parser-atk/parser_calculator.py     | 38 +++++++++++++++-------
 parser/parser-atk/parser_configurations.py |  3 +-
 3 files changed, 32 insertions(+), 14 deletions(-)

diff --git a/parser/parser-atk/atkio.py b/parser/parser-atk/atkio.py
index db4f935..b85f85f 100644
--- a/parser/parser-atk/atkio.py
+++ b/parser/parser-atk/atkio.py
@@ -19,6 +19,11 @@ class Reader:
             self.calculator_x[gid] = parse_calculator(self.f, calc_name)
 
     def initialize(self):
+        """Read the names of the variables in the netcdf file for
+           configurations and calculators and setup
+           the finger print table which maps between calculated
+           quantities and configurations.
+        """
         self.conf_names = self._read_configuration_names()
         self.calc_names = self._read_calculator_names()
         self.finger_print_table = self._read_finger_print_table()
diff --git a/parser/parser-atk/parser_calculator.py b/parser/parser-atk/parser_calculator.py
index 804ddeb..bf1ae00 100644
--- a/parser/parser-atk/parser_calculator.py
+++ b/parser/parser-atk/parser_calculator.py
@@ -9,15 +9,18 @@ SphericalSymmetric = 'SphericalSymmetric'
 
 
 LDA = type('LDA', (object,), {'PZ': 'LDA.PZ',
-                              'PW': 'LDA.PW'})()
+                              'PW': 'LDA.PW',
+                              'RPA': 'LDA.RPA'})()
 
 GGA = type('GGA', (object,), {'PBE': 'GGA.PBE',
                               'RPBE': 'GGA.RPBE',
-                              'PW91': 'GGA.PW91'})()
+                              'PW91': 'GGA.PW91',
+                              'PBES': 'GGA.PBES'})()
 
 ptable = {name: symbol for symbol, name in zip(data.chemical_symbols,
                                                data.atomic_names)}
 PeriodicTable = type('PeriodicTable', (object,), ptable)()
+
 Preconditioner = type('Preconditioner', (object,), {'Off': 'Off',
 
                                                     'On': 'On'})
@@ -28,11 +31,14 @@ Preconditioner = type('Preconditioner', (object,), {'Off': 'Off',
 # class LCAOCalculator(object):
 #     def __init__(self, basis_set=None, ...)
 #
-# is easily done, but a bit more work at the moment
+# is easily done, but a bit more work at the moment...
 #
 def init(self, *args, **kwargs):
+    #if len(args)>0:
+    #    print(*args)
+    #assert len(args) == 0
     self.args = args
-    for key, value in kwargs.iteritems():
+    for key, value in kwargs.items():
         setattr(self, key, value)
 
 
@@ -42,23 +48,31 @@ clss = ['LCAOCalculator', 'BasisSet', 'ConfinedOrbital', 'CheckpointHandler',
         'NumericalAccuracyParameters', 'MonkhorstPackGrid',
         'NormConservingPseudoPotential', 'AnalyticalSplit', 'ConfinedOrbital',
         'PolarizationOrbital', 'PulayMixer']
+
 for cls in clss:
     code = cls + ' = type("' + cls + '", (object,)' + ', {"__init__": init})'
     exec(code)
 
 
-def parse_calculator(fd, conf='BulkConfiguration_gID000', verbose=False):
-    """conf: the configuratio the calcualtor refers to
+def parse_calculator(fd, calcname):
+    """calc: the configuratio the calcualtor refers to
+       The name of the calculator in the nc-file is
+       conf_calculator, fx BulkConfiguration_gID000_calculator
     """
-    code = fd.variables[conf + '_calculator'].data[:].copy()
+    code = fd.variables[calcname].data[:].copy()
     code = code.tostring().decode("utf-8")
-    s = re.search('\s*(?P<name>[0-9a-zA-Z_]+)\s*=\s*LCAOCalculator\(', code)
-    name = s.group('name')
+    if 1:
+        print(code)
+    #s = re.search('\s*(?P<name>[0-9a-zA-Z_]+)\s*=\s*LCAOCalculator\(', code)
+    #name = s.group('name')
     exec(code)
-    calc = (locals()[name])
-    return calc
+    for obj in locals().values():
+        if isinstance(obj, LCAOCalculator):
+            return obj
+    assert 0, 'No calculator found'
 
 if __name__ == '__main__':
     from scipy.io.netcdf import netcdf_file
     fd = netcdf_file('Water.nc', 'r')
-    calc = parse_calculator(fd)
+    calc = parse_calculator(fd, 'BulkConfiguration_gID000_calculator')
+    print(dir(calc))
diff --git a/parser/parser-atk/parser_configurations.py b/parser/parser-atk/parser_configurations.py
index b0d4b4d..4181a1f 100644
--- a/parser/parser-atk/parser_configurations.py
+++ b/parser/parser-atk/parser_configurations.py
@@ -15,7 +15,6 @@ Silicon = type('Silicon', (object,), {})
 Silicon.symbol = 'Si'
 
 
-
 class UnitCell:
     def __init__(self, a, b, c, origin=None):
         self.cell = [a, b, c]
@@ -64,5 +63,5 @@ if __name__ == '__main__':
     import re
     from scipy.io.netcdf import netcdf_file
     fd = netcdf_file('Water.nc', 'r')
-    atoms = parse_configuration(fd, verbose=True)
+    atoms = parse_configuration(fd, 'BulkConfiguration_gID000', verbose=True)
     print(atoms)
-- 
GitLab