Commit f1c6c3aa authored by Mikkel Strange's avatar Mikkel Strange

atk bands parsing started

parent 8d8d699f
......@@ -2,13 +2,15 @@
from scipy.io.netcdf import netcdf_file
class X:
def __init__(self, name=None):
self.name = name
class Atoms:
def __init__(self):
def __init__(self, fd):
self.positions = None
self.numbers = None
self.cell = None
......
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
class X:
def __init__(self, name=None):
self.name = name
def has_data_with(what, f):
for key in f.variables.keys():
if what in key:
return True
return False
class Reader:
def __init__(self, fname):
self.f = netcdf_file(fname, 'r', mmap=True)
self.CommonConcepts = X('CommonConcepts')
self.CommonConcepts.Configurations = X('Configurations')
if 0:
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
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()
def print_keys(self):
print('---dimensions---')
for k in self.f.dimensions.keys():
print(k)
print('---variables---')
for k in self.f.variables.keys():
print(k)
def extract_wave_functions(self):
""" 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
def extract_bandstructure(self):
self.wave_functions = X('wave_functions')
what = 'Bandstructure'
if has_data_with(what, self.f) is False:
return
for key in self.f.variables.keys():
if what in key:
if 'route' in key:
self.wave_functions.route =\
self.f.variables[key][:].copy().tostring().decode('utf-8')
print(self.wave_functions.route)
def extract_results(self):
"""
try to read forces, stress and other stuff
"""
self.results = X('results')
def extract_total_energy(self):
what = 'TotalEnergy'
self.hamiltonian = X('hamiltonian')
if has_data_with(what, self.f) is False:
return
for key in self.f.variables.keys():
if what in key:
if 'finger_print' in key:
self.hamiltonian.e_finger_print =\
self.f.variables[key][:].copy().tostring().decode('utf-8')
elif 'Kinetic' in key:
self.hamiltonian.e_kin = self.f.variables[key][:].copy()[0]
elif 'Exchange-Correlation' in key:
self.hamiltonian.e_xc = self.f.variables[key][:].copy()[0]
elif 'External-Field' in key:
self.hamiltonian.e_external =\
self.f.variables[key][:].copy()[0]
elif 'Electrostatic' in key:
self.hamiltonian.e_hartree = \
self.f.variables[key][:].copy()[0]
elif 'Entropy-Term' in key:
self.hamiltonian.e_S = self.f.variables[key][:].copy()[0]
ham = self.hamiltonian
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)
if __name__ == '__main__':
import sys
fname = sys.argv[1]
r = Reader(fname)
#r.print_keys()
#print(r.atoms)
print(r.atk_version)
print(r.hamiltonian.e_tot)
print
......@@ -4,7 +4,7 @@ from contextlib import contextmanager
import numpy as np
from ase import units
from ase.data import chemical_symbols
from atkio import Reader
from atkio2 import Reader
from scipy.io.netcdf import netcdf_file
from ase.data import atomic_masses
from ase.units import Rydberg
......@@ -47,12 +47,11 @@ def parse(filename):
p.startedParsingSession(filename, parser_info)
with o(p, 'section_run'):
p.addValue('program_name', 'ATK')
p.addValue('program_version', r.version)
mode = parms['mode']
p.addValue('program_version', r.atk_version)
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.basis)
r.calculator.basis)
with o(p, 'section_system') as system_gid:
p.addArrayValues('simulation_cell',
c(r.atoms.cell, 'angstrom'))
......@@ -73,36 +72,34 @@ def parse(filename):
pass
with o(p, 'section_method') as method_gid:
p.addValue('relativity_method', 'pseudo_scalar_relativistic')
p.addValue('electronic_structure_method', 'DFT')
p.addValue('scf_threshold_energy_change',
c(r.convergence.scf_energy, 'eV')) # eV / electron
p.addValue('smearing_kind', r.occupations.name)
p.addValue('electronic_structure_method', r.calculator.method)
#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.occupations.width, 'eV'))
p.addRealValue('total_charge', r.system.charge)
c(r.calculator.temp, 'K'))
p.addRealValue('total_charge', r.calculator.charge)
with o(p, 'section_XC_functionals'):
p.addValue('XC_functional_name',
get_libxc_name(r.xc))
get_libxc_name(r.calculator.xc))
with o(p, 'section_single_configuration_calculation'):
p.addValue('single_configuration_calculation_to_system_ref',
system_gid)
p.addValue('single_configuration_to_calculation_method_ref',
method_gid)
p.addValue('single_configuration_calculation_converged',
r.scf.converged)
p.addRealValue('energy_total',
c(r.hamiltonian.e_total_extrapolated, 'eV'))
# p.addValue('single_configuration_calculation_converged',
# r.scf.converged)
# p.addRealValue('energy_total',
# c(r.hamiltonian.e_tot_extrapolated, 'eV'))
p.addRealValue('energy_free',
c(r.hamiltonian.e_total_free, 'eV'))
c(r.hamiltonian.e_tot, 'eV'))
p.addRealValue('energy_XC', c(r.hamiltonian.e_xc, 'eV'))
p.addRealValue('electronic_kinetic_energy',
c(r.hamiltonian.e_kinetic, 'eV'))
c(r.hamiltonian.e_kin, 'eV'))
p.addRealValue('energy_correction_entropy',
c(r.hamiltonian.e_entropy, 'eV'))
p.addRealValue('energy_reference_fermi',
c(r.occupations.fermilevel, 'eV'))
p.addRealValue('energy_reference_fermi',
c(r.occupations.fermilevel, 'eV'))
c(r.hamiltonian.e_S, 'eV'))
# p.addRealValue('energy_reference_fermi',
# c(r.occupations.fermilevel, 'eV'))
if hasattr(r.results, 'forces'):
p.addArrayValues('atom_forces_free_raw',
c(r.results.forces, 'eV/angstrom'))
......@@ -110,14 +107,15 @@ def parse(filename):
# p.addArrayValues('x_gpaw_magnetic_moments',
# r.results.magmoms)
# p.addRealValue('x_atk_spin_Sz', r.results.magmoms.sum() / 2.0)
with o(p, 'section_eigenvalues'):
p.addValue('eigenvalues_kind', 'normal')
p.addArrayValues('eigenvalues_values',
c(r.wave_functions.eigenvalues, 'eV'))
p.addArrayValues('eigenvalues_occupation',
r.wave_functions.occupations)
p.addArrayValues('eigenvalues_kpoints',
r.wave_functions.ibz_kpts)
if hasattr(r.wave_functions, 'eigenvalues'):
with o(p, 'section_eigenvalues'):
p.addValue('eigenvalues_kind', 'normal')
p.addArrayValues('eigenvalues_values',
c(r.wave_functions.eigenvalues, 'eV'))
p.addArrayValues('eigenvalues_occupation',
r.wave_functions.occupations)
p.addArrayValues('eigenvalues_kpoints',
r.wave_functions.ibz_kpts)
if hasattr(r.wave_functions, 'band_paths'):
with o(p, 'section_k_band'):
for band_path in r.wave_functions.band_paths:
......
from ase import Atoms
from ase.build import bulk
import re
Angstrom = 1
Hydrogen = type('Hydrogen', (object,), {})
Hydrogen.symbol = 'H'
Oxygen = type('Oxygen', (object,), {})
Oxygen.symbol = 'O'
Silicon = type('Silicon', (object,), {})
Silicon.symbol = 'Si'
class UnitCell:
def __init__(self, a, b, c, origin=None):
self.cell = [a, b, c]
class FaceCenteredCubic:
def __init__(self, a):
self.cell = bulk('X', crystalstructure='fcc', a=a).get_cell()
class BulkConfiguration:
def __init__(self, bravais_lattice, elements, cartesian_coordinates=None,
fractional_coordinates=None, ghost_atoms=None,
velocities=None, tag_data=None, fast_init=False):
self.bulkconfiguration = True
symbols = [e.symbol for e in elements]
if cartesian_coordinates is not None:
positions = cartesian_coordinates
scale_atoms = False
elif fractional_coordinates is not None:
positions = fractional_coordinates
scale_atoms = True
else:
positions = None
scale_atoms = False
pbc = True
atoms = Atoms(symbols, positions, pbc=pbc)
atoms.set_cell(bravais_lattice.cell, scale_atoms=scale_atoms)
self.ghost_atoms_indices = ghost_atoms
self.atoms = atoms
def parse_configuration(fd, conftype='BulkConfiguration', verbose=False):
code = fd.variables[conftype + '_gID000'].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')
if verbose:
print('name:', name)
print(code)
exec(code)
atoms = (locals()[name]).atoms
return atoms
if __name__ == '__main__':
import re
from scipy.io.netcdf import netcdf_file
fd = netcdf_file('Water.nc', 'r')
atoms = parse_configuration(fd, verbose=True)
print(atoms)
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