From dc09cfb3ed7667ef65b5727c710ab11a339b5c79 Mon Sep 17 00:00:00 2001
From: Mikkel Strange <mikst@fysik.dtu.dk>
Date: Sun, 18 Sep 2016 13:40:16 +0200
Subject: [PATCH] small changes

---
 parser/parser-atk/atkio2.py                | 71 ++++++++++++----------
 parser/parser-atk/parser_configurations.py |  4 +-
 2 files changed, 40 insertions(+), 35 deletions(-)

diff --git a/parser/parser-atk/atkio2.py b/parser/parser-atk/atkio2.py
index 34d62a1..8b34c55 100644
--- a/parser/parser-atk/atkio2.py
+++ b/parser/parser-atk/atkio2.py
@@ -2,7 +2,7 @@ from copy import copy
 from scipy.io.netcdf import netcdf_file
 from parser_configurations import parse_configuration as p_conf
 from parser_calculator import parse_calculator as p_calc 
-
+import re
 
 class X:
     def __init__(self, name=None):
@@ -20,19 +20,28 @@ class Reader:
         self.CommonConcepts = X('CommonConcepts')
         self.CommonConcepts.Configurations = X('Configurations')
 
-        if 1:
-            gIDs = []
-            for k in self.f.dimensions.keys():
-                if '_gID' not in k:
-                    continue
-                i = k.index('_gID')
-                gID = int(k[i+4: i+7])
-                if gID not in gIDs:
-                    gIDs.append(gID)
-
-            self.gIDs = gIDs
+        gIDs = []
+        for k in self.f.dimensions.keys():
+            if '_gID' not in k:
+                continue
+            i = k.index('_gID')
+            gID = int(k[i+4: i+7])
+            if gID not in gIDs:
+                gIDs.append(gID)
+
+        self.gIDs = gIDs
+        pm = re.compile('MoleculeConfiguration(?P<gid>_gID[0-9][0-9][0-9])$')
+        pb = re.compile('BulkConfiguration(?P<gid>_gID[0-9][0-9][0-9])$')
+        for key in self.f.variables.keys():
+            s = re.search(pm, key)
+            if s is not None:
+                self.conf_gID = s.group('gid')
+                break
+            s = re.search(pb, key)
+            if s is not None:
+                self.conf_gID = s.group('gid')
+                break
 
-        self.conf_gID = '_gID000'
         self.atk_version = self.f.version[4:].decode('utf-8')
         self.finger_prints = [x.split(':') for x in
                               self.f.fingerprint_table.\
@@ -58,17 +67,7 @@ class Reader:
         self.wave_functions = X('wave_functions')
 
     def extract_calculator(self):
-        #p_calc(self)
-        # dummy until p_calc stops crashing!
-        name = self.CommonConcepts.Configurations.name + self.conf_gID
-        self.calculator = p_calc(self.f, name)
-#        self.calculator = X('calculator')
-#        self.calculator.basis = 'dzp'
-#        self.calculator.method = 'DFT'
-#        self.calculator.xc = 'LDA'
-#        self.calculator.charge = 0
-#        self.calculator.temp = 300.0  # icp
-#        self.calculator.dens_tolerance = 0.0001 # icp
+        self.calculator = p_calc(self.f, self.conf_name)
 
     def extract_bandstructure(self):
         self.wave_functions = X('wave_functions')
@@ -115,15 +114,21 @@ class Reader:
         ham.e_tot = ham.e_kin + ham.e_xc + ham.e_hartree + ham.e_S
 
     def extract_common_concepts(self):
-        if 'BulkConfiguration_gID000_dimension' in self.f.dimensions.keys():
-            self.CommonConcepts.Configurations = X('BulkConfiguration')
-        elif 'MoleculeConfiguration_gID000_dimension' in \
-                self.f.dimensions.keys():
-            self.CommonConcepts.Configurations = X('MoleculeConfiguration')
-        else:
-            assert 0, 'Not a Bulk or Molecule configurations found!'
-
-        self.atoms = p_conf(self.f, self.CommonConcepts.Configurations.name)
+        pm = re.compile('MoleculeConfiguration(?P<gid>_gID[0-9][0-9][0-9])$')
+        pb = re.compile('BulkConfiguration(?P<gid>_gID[0-9][0-9][0-9])$')
+        for key in self.f.variables.keys():
+            s = re.search(pm, key)
+            if s is not None:
+                self.conf_gID = s.group('gid')
+                self.conf_name = s.group()
+                break
+            s = re.search(pb, key)
+            if s is not None:
+                self.conf_gID = s.group('gid')
+                self.conf_name = s.group()
+                break
+        print(self.conf_name)
+        self.atoms = p_conf(self.f, self.conf_name)
 
 if __name__ == '__main__':
     import sys
diff --git a/parser/parser-atk/parser_configurations.py b/parser/parser-atk/parser_configurations.py
index 839720a..b0d4b4d 100644
--- a/parser/parser-atk/parser_configurations.py
+++ b/parser/parser-atk/parser_configurations.py
@@ -47,8 +47,8 @@ class BulkConfiguration:
         self.atoms = atoms
 
 
-def parse_configuration(fd, conftype='BulkConfiguration', verbose=False):
-    code = fd.variables[conftype + '_gID000'].data[:].copy()
+def parse_configuration(fd, confname, verbose=False):
+    code = fd.variables[confname].data[:].copy()
     code = code.tostring().decode("utf-8")
     s = re.search('\s*(?P<name>[0-9a-zA-Z_]+)\s*=\s*BulkConfiguration\(', code)
     name = s.group('name')
-- 
GitLab