Commit ce58ded8 authored by Mikkel Strange's avatar Mikkel Strange

more polishing

parent 19ca5f00
......@@ -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()
......@@ -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',
'PW91': 'GGA.PW91'})()
'PW91': 'GGA.PW91',
'PBES': 'GGA.PBES'})()
ptable = {name: symbol for symbol, name in zip(data.chemical_symbols,
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})'
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 ='\s*(?P<name>[0-9a-zA-Z_]+)\s*=\s*LCAOCalculator\(', code)
name ='name')
if 1:
#s ='\s*(?P<name>[0-9a-zA-Z_]+)\s*=\s*LCAOCalculator\(', code)
#name ='name')
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 import netcdf_file
fd = netcdf_file('', 'r')
calc = parse_calculator(fd)
calc = parse_calculator(fd, 'BulkConfiguration_gID000_calculator')
......@@ -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 import netcdf_file
fd = netcdf_file('', 'r')
atoms = parse_configuration(fd, verbose=True)
atoms = parse_configuration(fd, 'BulkConfiguration_gID000', verbose=True)
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