Commit 78cebe38 authored by Mikkel Strange's avatar Mikkel Strange
Browse files

updated parser to handle different basis sets

parent de4fced5
import os
from contextlib import contextmanager
import numpy as np
#from nomadcore.unit_conversion.unit_conversion import convert_unit as cu
from ase.data import chemical_symbols
from nomadcore.unit_conversion.unit_conversion import convert_unit as cu
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
from nomadcore.parser_backend import JsonParseEventsWriterBackend
from tar import Reader
......@@ -14,13 +15,16 @@ def open_section(p, name):
p.closeSection(name, gid)
def cu(value, unit=None):
def c(value, unit=None):
""" Dummy function for unit conversion"""
return value
return cu(value, unit)
parser_info = {"name": "parser_gpaw", "version": "1.0"}
metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../../../nomad-meta-info/meta_info/nomad_meta_info/gpaw.nomadmetainfo.json"))
path = '../../../../nomad-meta-info/meta_info/nomad_meta_info/' +\
'gpaw.nomadmetainfo.json'
metaInfoPath = os.path.normpath(
os.path.join(os.path.dirname(os.path.abspath(__file__)), path))
metaInfoEnv, warns = loadJsonFile(filePath=metaInfoPath,
dependencyLoader=None,
......@@ -28,33 +32,53 @@ metaInfoEnv, warns = loadJsonFile(filePath=metaInfoPath,
uri=None)
# TODO: convert to SI units
def parse(filename):
p = JsonParseEventsWriterBackend(metaInfoEnv)
o = open_section
r = Reader(filename)
p.startedParsingSession(filename, parser_info)
with o(p, 'section_run'):
p.addValue('program_name', 'GPAW')
if r.Mode == 'pw':
with o(p, 'section_basis_set_cell_associated'):
p.addValue('basis_set_cell_associated_name',
'PW_%.1f_Ry' % (r.PlaneWaveCutoff * 2.0)) # in Ry
p.addRealValue('basis_set_plane_wave_cutoff',
c(r.PlaneWaveCutoff, 'hartree'))
elif r.Mode == 'fd':
with o(p, 'section_basis_set_cell_associated'):
h1 = np.linalg.norm(r.UnitCell[0]) / r.dims['ngptsx']
h2 = np.linalg.norm(r.UnitCell[1]) / r.dims['ngptsy']
h3 = np.linalg.norm(r.UnitCell[2]) / r.dims['ngptsz']
h = (h1 + h2 + h3) / 3.0
p.addValue('basis_set_cell_associated_name',
'GR_%.1f' % (c(h, 'bohr') * 1.0E15)) # in fm
elif r.Mode == 'lcao':
pass
with o(p, 'section_system_describtion'):
p.addArrayValues('simulation_cell', r.UnitCell)
p.addArrayValues('atom_label', r.CartesianPositions)
p.addArrayValues('simulation_cell', c(r.UnitCell, 'bohr'))
symbols = np.array([chemical_symbols[z] for z in r.AtomicNumbers])
p.addArrayValues('atom_label', symbols)
p.addArrayValues('atom_position', c(r.CartesianPositions, 'bohr'))
p.addArrayValues('configuration_periodic_dimensions',
np.array(r.BoundaryConditions, bool))
with o(p, 'section_single_configuration_calculation'):
p.addRealValue('energy_total', r.Epot)
p.addRealValue('energy_XC', r.Exc)
p.addRealValue('electronic_kinetic_energy', r.Ekin)
p.addRealValue('energy_total', c(r.Epot, 'hartree'))
p.addRealValue('energy_XC', c(r.Exc, 'hartree'))
p.addRealValue('electronic_kinetic_energy', c(r.Ekin, 'hartree'))
if 'CartesianForces' in r:
p.addArrayValues('atom_forces_free', r.CartesianForces)
p.addArrayValues('atom_forces_free',
c(r.CartesianForces, 'bohr/hartree'))
with o(p, 'section_method'):
p.addValue('XC_functional', r.XCFunctional)
with o(p, 'section_eigenvalues_group'):
for eps_kn, occ_kn in zip(r.Eigenvalues, r.OccupationNumbers):
with o(p, 'section_eigenvalues'):
p.addArrayValues('eigenvalues_eigenvalues', eps_kn)
p.addArrayValues('eigenvalues_eigenvalues',
c(eps_kn, 'hartree'))
p.addArrayValues('eigenvalues_occupation', occ_kn)
p.addArrayValues('eigenvalues_kpoints', r.IBZKPoints)
p.finishedParsingSession("ParseSuccess", None)
if __name__ == '__main__':
......
......@@ -34,7 +34,7 @@ class Reader:
def __contains__(self, name):
return name in self.parameters or name in self.shapes
def __getattr__(self, name):
if name in self.parameters:
return self.parameters[name]
......@@ -54,11 +54,11 @@ class Reader:
array = np.asarray(array, int)
array.shape = shape
return array
def close(self):
self.tar.close()
if __name__ == '__main__':
r = Reader('H2.gpw')
print(r.Eigenvalues, r.FermiLevel, r.UnitCell)
......
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