Planned maintenance on Wednesday, 2021-01-20, 17:00-18:00. Expect some interruptions during that time

Commit ce3be585 authored by Mikkel Strange's avatar Mikkel Strange

now parsing calculatur input

parent c920ffc7
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
from parser_calculator import parse_calculator as p_calc
class X:
def __init__(self, name=None):
......@@ -19,7 +20,7 @@ class Reader:
self.CommonConcepts = X('CommonConcepts')
self.CommonConcepts.Configurations = X('Configurations')
if 0:
if 1:
gIDs = []
for k in self.f.dimensions.keys():
if '_gID' not in k:
......@@ -31,16 +32,17 @@ class Reader:
self.gIDs = gIDs
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.\
decode('utf-8').split('#')][:-1]
self.extract_common_concepts() # atoms
self.extract_total_energy()
self.extract_calculator()
self.extract_results()
self.extract_wave_functions()
self.extract_bandstructure()
self.extract_calculator() # extract the calculator
self.extract_total_energy() # look for total energy
self.extract_results() # look for results, forces, stress etc
self.extract_wave_functions() # look for eigenvalues, wave functions
self.extract_bandstructure() # look for band structures
def print_keys(self):
print('---dimensions---')
......@@ -51,20 +53,22 @@ class Reader:
print(k)
def extract_wave_functions(self):
""" extract eigenvalues, occupations and wave_functions
""" extract eigenvalues, occupations and wave_functions
"""
self.wave_functions = X('wave_functions')
def extract_calculator(self):
#p_calc(self)
# dummy until p_calc stops crashing!
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
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):
self.wave_functions = X('wave_functions')
......@@ -129,5 +133,5 @@ if __name__ == '__main__':
#print(r.atoms)
print(r.atk_version)
print(r.hamiltonian.e_tot)
print
print(r.calculator)
from __future__ import print_function
short_names = {
'LDA': 'LDA_X+LDA_C_PW',
'PW91': 'GGA_X_PW91+GGA_C_PW91',
'PBE': 'GGA_X_PBE+GGA_C_PBE',
'PBEsol': 'GGA_X_PBE_SOL+GGA_C_PBE_SOL',
'LDA.RPA': 'LDA_X+LDA_C_RPA',
'LDA.PZ': 'LDA_X+LDA_C_PZ',
'LDA.PW': 'LDA_X+LDA_C_PW',
'GGA.PW91': 'GGA_X_PW91+GGA_C_PW91',
'GGA.PBE': 'GGA_X_PBE+GGA_C_PBE',
'GGA.PBES': 'GGA_X_PBE_SOL+GGA_C_PBE_SOL',
'revPBE': 'GGA_X_PBE_R+GGA_C_PBE',
'RPBE': 'GGA_X_RPBE+GGA_C_PBE',
'GGA.RPBE': 'GGA_X_RPBE+GGA_C_PBE',
'BLYP': 'GGA_X_B88+GGA_C_LYP',
'HCTH407': 'GGA_XC_HCTH_407',
'WC': 'GGA_X_WC+GGA_C_PBE',
......
......@@ -51,7 +51,7 @@ def parse(filename):
p.addValue('program_basis_set_type', 'numeric AOs')
with o(p, 'section_basis_set_atom_centered'):
p.addValue('basis_set_atom_centered_short_name',
r.calculator.basis)
'ATK LCAO basis')
with o(p, 'section_system') as system_gid:
p.addArrayValues('simulation_cell',
c(r.atoms.cell, 'angstrom'))
......@@ -72,16 +72,17 @@ def parse(filename):
pass
with o(p, 'section_method') as method_gid:
p.addValue('relativity_method', 'pseudo_scalar_relativistic')
p.addValue('electronic_structure_method', r.calculator.method)
p.addValue('electronic_structure_method', 'DFT')
#p.addValue('scf_threshold_energy_change',
# c(r.convergence.scf_energy, 'eV')) # eV / electron
p.addValue('smearing_kind', 'fermi')
p.addRealValue('smearing_width',
c(r.calculator.temp, 'K'))
c(r.calculator.numerical_accuracy_parameters.\
electron_temperature, 'K'))
p.addRealValue('total_charge', r.calculator.charge)
with o(p, 'section_XC_functionals'):
p.addValue('XC_functional_name',
get_libxc_name(r.calculator.xc))
get_libxc_name(r.calculator.exchange_correlation))
with o(p, 'section_single_configuration_calculation'):
p.addValue('single_configuration_calculation_to_system_ref',
system_gid)
......
from ase import data
import re
from physical_quantities import eV, Angstrom, Bohr, Kelvin, Hour, Hartree
All = 'All'
Automatic = 'Automatic'
HamiltonianVariable = 'HamiltonianVariable'
SphericalSymmetric = 'SphericalSymmetric'
LDA = type('LDA', (object,), {'PZ': 'LDA.PZ',
'PW': 'LDA.PW'})()
GGA = type('GGA', (object,), {'PBE': 'GGA.PBE',
'RPBE': 'GGA.RPBE',
'PW91': 'GGA.PW91'})()
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'})
# Populate with dummy classes to hold hold variables (assumes kwargs!)
# Otherwise we have to build all of them with something like
# class LCAOCalculator(object):
# def __init__(self, basis_set=None, ...)
#
# is easily done, but a bit more work at the moment
#
def init(self, *args, **kwargs):
self.args = args
for key, value in kwargs.iteritems():
setattr(self, key, value)
clss = ['LCAOCalculator', 'BasisSet', 'ConfinedOrbital', 'CheckpointHandler',
'ParallelParameters', 'AlgorithmParameters', 'DiagonalizationSolver',
'FastFourierSolver', 'IterationControlParameters',
'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
"""
code = fd.variables[conf + '_calculator'].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')
exec(code)
calc = (locals()[name])
return calc
if __name__ == '__main__':
from scipy.io.netcdf import netcdf_file
fd = netcdf_file('Water.nc', 'r')
calc = parse_calculator(fd)
......@@ -5,6 +5,10 @@ import re
Angstrom = 1
Hydrogen = type('Hydrogen', (object,), {})
Hydrogen.symbol = 'H'
Helium= type('Helium', (object,), {})
Helium.symbol = 'H'
Lithium= type('Lithium', (object,), {})
Lithium.symbol = 'Si'
Oxygen = type('Oxygen', (object,), {})
Oxygen.symbol = 'O'
Silicon = type('Silicon', (object,), {})
......
from ase.units import Bohr, Angstrom, kB as Kelvin, eV, Hartree
class PC(list):
def __init__(self, val):
self.val = val
def __mul__(self, other):
if type(other) is not list:
if type(other) is not tuple:
return self.val * other
out = [o * self.val for o in other]
if type(other) is tuple:
out = tuple(out)
return out
def __rmul__(self, other):
return self.__mul__(other)
def __repr__(self):
return format(self.val)
eV = PC(eV)
Angstrom = PC(Angstrom)
Hartree = PC(Hartree)
Bohr = PC(Bohr)
Kelvin = PC(Kelvin)
Hour = 1
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