Skip to content
Snippets Groups Projects
Commit ce58ded8 authored by Mikkel Strange's avatar Mikkel Strange
Browse files

more polishing

parent 19ca5f00
Branches
Tags
No related merge requests found
...@@ -19,6 +19,11 @@ class Reader: ...@@ -19,6 +19,11 @@ class Reader:
self.calculator_x[gid] = parse_calculator(self.f, calc_name) self.calculator_x[gid] = parse_calculator(self.f, calc_name)
def initialize(self): 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.conf_names = self._read_configuration_names()
self.calc_names = self._read_calculator_names() self.calc_names = self._read_calculator_names()
self.finger_print_table = self._read_finger_print_table() self.finger_print_table = self._read_finger_print_table()
......
...@@ -9,15 +9,18 @@ SphericalSymmetric = 'SphericalSymmetric' ...@@ -9,15 +9,18 @@ SphericalSymmetric = 'SphericalSymmetric'
LDA = type('LDA', (object,), {'PZ': 'LDA.PZ', LDA = type('LDA', (object,), {'PZ': 'LDA.PZ',
'PW': 'LDA.PW'})() 'PW': 'LDA.PW',
'RPA': 'LDA.RPA'})()
GGA = type('GGA', (object,), {'PBE': 'GGA.PBE', GGA = type('GGA', (object,), {'PBE': 'GGA.PBE',
'RPBE': 'GGA.RPBE', 'RPBE': 'GGA.RPBE',
'PW91': 'GGA.PW91'})() 'PW91': 'GGA.PW91',
'PBES': 'GGA.PBES'})()
ptable = {name: symbol for symbol, name in zip(data.chemical_symbols, ptable = {name: symbol for symbol, name in zip(data.chemical_symbols,
data.atomic_names)} data.atomic_names)}
PeriodicTable = type('PeriodicTable', (object,), ptable)() PeriodicTable = type('PeriodicTable', (object,), ptable)()
Preconditioner = type('Preconditioner', (object,), {'Off': 'Off', Preconditioner = type('Preconditioner', (object,), {'Off': 'Off',
'On': 'On'}) 'On': 'On'})
...@@ -28,11 +31,14 @@ Preconditioner = type('Preconditioner', (object,), {'Off': 'Off', ...@@ -28,11 +31,14 @@ Preconditioner = type('Preconditioner', (object,), {'Off': 'Off',
# class LCAOCalculator(object): # class LCAOCalculator(object):
# def __init__(self, basis_set=None, ...) # 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): def init(self, *args, **kwargs):
#if len(args)>0:
# print(*args)
#assert len(args) == 0
self.args = args self.args = args
for key, value in kwargs.iteritems(): for key, value in kwargs.items():
setattr(self, key, value) setattr(self, key, value)
...@@ -42,23 +48,31 @@ clss = ['LCAOCalculator', 'BasisSet', 'ConfinedOrbital', 'CheckpointHandler', ...@@ -42,23 +48,31 @@ clss = ['LCAOCalculator', 'BasisSet', 'ConfinedOrbital', 'CheckpointHandler',
'NumericalAccuracyParameters', 'MonkhorstPackGrid', 'NumericalAccuracyParameters', 'MonkhorstPackGrid',
'NormConservingPseudoPotential', 'AnalyticalSplit', 'ConfinedOrbital', 'NormConservingPseudoPotential', 'AnalyticalSplit', 'ConfinedOrbital',
'PolarizationOrbital', 'PulayMixer'] 'PolarizationOrbital', 'PulayMixer']
for cls in clss: for cls in clss:
code = cls + ' = type("' + cls + '", (object,)' + ', {"__init__": init})' code = cls + ' = type("' + cls + '", (object,)' + ', {"__init__": init})'
exec(code) exec(code)
def parse_calculator(fd, conf='BulkConfiguration_gID000', verbose=False): def parse_calculator(fd, calcname):
"""conf: the configuratio the calcualtor refers to """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") code = code.tostring().decode("utf-8")
s = re.search('\s*(?P<name>[0-9a-zA-Z_]+)\s*=\s*LCAOCalculator\(', code) if 1:
name = s.group('name') print(code)
#s = re.search('\s*(?P<name>[0-9a-zA-Z_]+)\s*=\s*LCAOCalculator\(', code)
#name = s.group('name')
exec(code) exec(code)
calc = (locals()[name]) for obj in locals().values():
return calc if isinstance(obj, LCAOCalculator):
return obj
assert 0, 'No calculator found'
if __name__ == '__main__': if __name__ == '__main__':
from scipy.io.netcdf import netcdf_file from scipy.io.netcdf import netcdf_file
fd = netcdf_file('Water.nc', 'r') fd = netcdf_file('Water.nc', 'r')
calc = parse_calculator(fd) calc = parse_calculator(fd, 'BulkConfiguration_gID000_calculator')
print(dir(calc))
...@@ -15,7 +15,6 @@ Silicon = type('Silicon', (object,), {}) ...@@ -15,7 +15,6 @@ Silicon = type('Silicon', (object,), {})
Silicon.symbol = 'Si' Silicon.symbol = 'Si'
class UnitCell: class UnitCell:
def __init__(self, a, b, c, origin=None): def __init__(self, a, b, c, origin=None):
self.cell = [a, b, c] self.cell = [a, b, c]
...@@ -64,5 +63,5 @@ if __name__ == '__main__': ...@@ -64,5 +63,5 @@ if __name__ == '__main__':
import re import re
from scipy.io.netcdf import netcdf_file from scipy.io.netcdf import netcdf_file
fd = netcdf_file('Water.nc', 'r') fd = netcdf_file('Water.nc', 'r')
atoms = parse_configuration(fd, verbose=True) atoms = parse_configuration(fd, 'BulkConfiguration_gID000', verbose=True)
print(atoms) print(atoms)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment