Commit dc09cfb3 authored by Mikkel Strange's avatar Mikkel Strange

small changes

parent ce3be585
...@@ -2,7 +2,7 @@ from copy import copy ...@@ -2,7 +2,7 @@ from copy import copy
from scipy.io.netcdf import netcdf_file from scipy.io.netcdf import netcdf_file
from parser_configurations import parse_configuration as p_conf from parser_configurations import parse_configuration as p_conf
from parser_calculator import parse_calculator as p_calc from parser_calculator import parse_calculator as p_calc
import re
class X: class X:
def __init__(self, name=None): def __init__(self, name=None):
...@@ -20,19 +20,28 @@ class Reader: ...@@ -20,19 +20,28 @@ class Reader:
self.CommonConcepts = X('CommonConcepts') self.CommonConcepts = X('CommonConcepts')
self.CommonConcepts.Configurations = X('Configurations') self.CommonConcepts.Configurations = X('Configurations')
if 1: gIDs = []
gIDs = [] for k in self.f.dimensions.keys():
for k in self.f.dimensions.keys(): if '_gID' not in k:
if '_gID' not in k: continue
continue i = k.index('_gID')
i = k.index('_gID') gID = int(k[i+4: i+7])
gID = int(k[i+4: i+7]) if gID not in gIDs:
if gID not in gIDs: gIDs.append(gID)
gIDs.append(gID)
self.gIDs = gIDs
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.atk_version = self.f.version[4:].decode('utf-8')
self.finger_prints = [x.split(':') for x in self.finger_prints = [x.split(':') for x in
self.f.fingerprint_table.\ self.f.fingerprint_table.\
...@@ -58,17 +67,7 @@ class Reader: ...@@ -58,17 +67,7 @@ class Reader:
self.wave_functions = X('wave_functions') self.wave_functions = X('wave_functions')
def extract_calculator(self): def extract_calculator(self):
#p_calc(self) self.calculator = p_calc(self.f, self.conf_name)
# 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
def extract_bandstructure(self): def extract_bandstructure(self):
self.wave_functions = X('wave_functions') self.wave_functions = X('wave_functions')
...@@ -115,15 +114,21 @@ class Reader: ...@@ -115,15 +114,21 @@ class Reader:
ham.e_tot = ham.e_kin + ham.e_xc + ham.e_hartree + ham.e_S ham.e_tot = ham.e_kin + ham.e_xc + ham.e_hartree + ham.e_S
def extract_common_concepts(self): def extract_common_concepts(self):
if 'BulkConfiguration_gID000_dimension' in self.f.dimensions.keys(): pm = re.compile('MoleculeConfiguration(?P<gid>_gID[0-9][0-9][0-9])$')
self.CommonConcepts.Configurations = X('BulkConfiguration') pb = re.compile('BulkConfiguration(?P<gid>_gID[0-9][0-9][0-9])$')
elif 'MoleculeConfiguration_gID000_dimension' in \ for key in self.f.variables.keys():
self.f.dimensions.keys(): s = re.search(pm, key)
self.CommonConcepts.Configurations = X('MoleculeConfiguration') if s is not None:
else: self.conf_gID = s.group('gid')
assert 0, 'Not a Bulk or Molecule configurations found!' self.conf_name = s.group()
break
self.atoms = p_conf(self.f, self.CommonConcepts.Configurations.name) 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__': if __name__ == '__main__':
import sys import sys
......
...@@ -47,8 +47,8 @@ class BulkConfiguration: ...@@ -47,8 +47,8 @@ class BulkConfiguration:
self.atoms = atoms self.atoms = atoms
def parse_configuration(fd, conftype='BulkConfiguration', verbose=False): def parse_configuration(fd, confname, verbose=False):
code = fd.variables[conftype + '_gID000'].data[:].copy() code = fd.variables[confname].data[:].copy()
code = code.tostring().decode("utf-8") code = code.tostring().decode("utf-8")
s = re.search('\s*(?P<name>[0-9a-zA-Z_]+)\s*=\s*BulkConfiguration\(', code) s = re.search('\s*(?P<name>[0-9a-zA-Z_]+)\s*=\s*BulkConfiguration\(', code)
name = s.group('name') name = s.group('name')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment