Skip to content
Snippets Groups Projects
Commit cde754b3 authored by Daria Tomecka's avatar Daria Tomecka
Browse files

wien2k: update of units and atom positions

parent 669d0889
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ import setup_paths ...@@ -3,7 +3,7 @@ import setup_paths
from nomadcore.simple_parser import mainFunction, AncillaryParser, CachingLevel from nomadcore.simple_parser import mainFunction, AncillaryParser, CachingLevel
from nomadcore.simple_parser import SimpleMatcher as SM from nomadcore.simple_parser import SimpleMatcher as SM
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
import os, sys, json import os, sys, json, logging
import wien2k_parser_struct, wien2k_parser_in0, wien2k_parser_in1c, wien2k_parser_in2c, wien2k_parser_in1, wien2k_parser_in2 import wien2k_parser_struct, wien2k_parser_in0, wien2k_parser_in1c, wien2k_parser_in2c, wien2k_parser_in1, wien2k_parser_in2
...@@ -39,18 +39,6 @@ class Wien2kContext(object): ...@@ -39,18 +39,6 @@ class Wien2kContext(object):
def onOpen_section_system(self, backend, gIndex, section): def onOpen_section_system(self, backend, gIndex, section):
self.secSystemIndex = gIndex self.secSystemIndex = gIndex
mainFile = self.parser.fIn.fIn.name
fName = mainFile[:-4] + ".struct"
if os.path.exists(fName):
structSuperContext = wien2k_parser_struct.Wien2kStructContext()
structParser = AncillaryParser(
fileDescription = wien2k_parser_struct.buildStructureMatchers(),
parser = self.parser,
cachingLevelForMetaName = wien2k_parser_struct.get_cachingLevelForMetaName(self.metaInfoEnv, CachingLevel.PreOpenedIgnore),
superContext = structSuperContext)
with open(fName) as fIn:
structParser.parseFile(fIn)
def onOpen_section_method(self, backend, gIndex, section): def onOpen_section_method(self, backend, gIndex, section):
...@@ -141,10 +129,10 @@ class Wien2kContext(object): ...@@ -141,10 +129,10 @@ class Wien2kContext(object):
backend.addValue('x_wien2k_smearing_kind', value) backend.addValue('x_wien2k_smearing_kind', value)
smearing_width = section['x_wien2k_smearing_width__rydberg'] smearing_width = section['x_wien2k_smearing_width']
if smearing_width is not None: if smearing_width is not None:
# value = '' # value = ''
backend.addValue('x_wien2k_smearing_width__rydberg', value) backend.addValue('x_wien2k_smearing_width', value)
# atom labels # atom labels
atom_labels = section['x_wien2k_atom_name'] atom_labels = section['x_wien2k_atom_name']
...@@ -162,15 +150,18 @@ class Wien2kContext(object): ...@@ -162,15 +150,18 @@ class Wien2kContext(object):
# need to transpose array since its shape is [number_of_atoms,3] in\the metadata # need to transpose array since its shape is [number_of_atoms,3] in\the metadata
backend.addArrayValues('atom_forces', np.transpose(np.asarray(atom_force))) backend.addArrayValues('atom_forces', np.transpose(np.asarray(atom_force)))
# unit_cell mainFile = self.parser.fIn.fIn.name
unit_cell = [] fName = mainFile[:-4] + ".struct"
for i in ['a', 'b', 'c']: if os.path.exists(fName):
uci = section['x_wien2k_unit_cell_param_' + i] structSuperContext = wien2k_parser_struct.Wien2kStructContext()
if uci is not None: structParser = AncillaryParser(
unit_cell.append(uci) fileDescription = wien2k_parser_struct.buildStructureMatchers(),
if unit_cell: parser = self.parser,
backend.addArrayValues('simulation_cell', np.asarray(unit_cell)) cachingLevelForMetaName = wien2k_parser_struct.get_cachingLevelForMetaName(self.metaInfoEnv, CachingLevel.PreOpenedIgnore),
backend.addArrayValues("configuration_periodic_dimensions", np.ones(3, dtype=bool)) superContext = structSuperContext)
with open(fName) as fIn:
structParser.parseFile(fIn)
......
...@@ -5,6 +5,7 @@ from nomadcore.simple_parser import SimpleMatcher as SM ...@@ -5,6 +5,7 @@ from nomadcore.simple_parser import SimpleMatcher as SM
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
import os, sys, json, logging import os, sys, json, logging
import numpy as np import numpy as np
import ase.geometry
################################################################ ################################################################
...@@ -29,15 +30,32 @@ class Wien2kStructContext(object): ...@@ -29,15 +30,32 @@ class Wien2kStructContext(object):
self.initialize_values() self.initialize_values()
def onClose_section_system(self, backend, gIndex, section): def onClose_section_system(self, backend, gIndex, section):
# unit_cell
unit_cell_params = []
for i in ['a', 'b', 'c']:
uci = section['x_wien2k_unit_cell_param_' + i]
#if uci is not None:
unit_cell_params.append(uci[0])
for i in ['alfa', 'beta', 'gamma']:
uci = section['x_wien2k_angle_between_unit_axis_' + i]
# if uci is not None:
unit_cell_params.append(uci[0])
unit_cell = ase.geometry.cellpar_to_cell(unit_cell_params)
backend.addArrayValues('simulation_cell', unit_cell)
backend.addArrayValues("configuration_periodic_dimensions", np.ones(3, dtype=bool))
equiv_atoms = section["x_wien2k_section_equiv_atoms"] equiv_atoms = section["x_wien2k_section_equiv_atoms"]
#logging.error("section: %s", section) #logging.error("section: %s", section)
labels = [] labels = []
pos = [] pos = []
for eqAtoms in equiv_atoms: for eqAtoms in equiv_atoms:
label = eqAtoms["x_wien2k_atom_name"][0] label = eqAtoms["x_wien2k_atom_name"][0]
x = eqAtoms["x_wien2k_atom_pos_x"] x = eqAtoms["x_wien2k_atom_pos_x"]
y = eqAtoms["x_wien2k_atom_pos_y"] y = eqAtoms["x_wien2k_atom_pos_y"]
z = eqAtoms["x_wien2k_atom_pos_z"] z = eqAtoms["x_wien2k_atom_pos_z"]
#OB logging.error("equiv_atoms: %s x %s y %s z %s",eqAtoms, x, y, z)
if len(x) != len(y) or len(x) != len(z): if len(x) != len(y) or len(x) != len(z):
raise Exception("incorrect parsing, different number of x,y,z components") raise Exception("incorrect parsing, different number of x,y,z components")
groupPos = [[x[i],y[i],z[i]] for i in range(len(x))] groupPos = [[x[i],y[i],z[i]] for i in range(len(x))]
...@@ -45,24 +63,12 @@ class Wien2kStructContext(object): ...@@ -45,24 +63,12 @@ class Wien2kStructContext(object):
labels += [label for i in range(nAt)] labels += [label for i in range(nAt)]
pos += groupPos pos += groupPos
backend.addValue("atom_labels", labels) backend.addValue("atom_labels", labels)
backend.addValue("atom_positions", pos) #backend.addValue("atom_positions", np.dot(pos,unit_cell))
##OR #ok#backend.addArrayValues('atom_positions', np.transpose(np.asarray(pos)))
""" backend.addArrayValues('atom_positions', np.asarray(pos))
# atom_positions
atom_pos = []
for i in ['x', 'y', 'z']:
api = section['x_wien2k_atom_pos_' + i]
if api is not None:
atom_pos.append(api)
if atom_pos:
# need to transpose array since its shape is [number_of_atoms,3] in the metadata
backend.addArrayValues('atom_positions', np.transpose(np.asarray(atom_pos)))
# atom labels
atom_labels = section['x_wien2k_atom_name']
if atom_labels is not None:
backend.addArrayValues('atom_labels', np.asarray(atom_labels))
"""
# description of the input # description of the input
def buildStructureMatchers(): def buildStructureMatchers():
return SM( return SM(
...@@ -76,12 +82,12 @@ def buildStructureMatchers(): ...@@ -76,12 +82,12 @@ def buildStructureMatchers():
SM(r"\w+\s*LATTICE,NONEQUIV\.ATOMS.\s*(?P<x_wien2k_nonequiv_atoms>[0-9]+)"), SM(r"\w+\s*LATTICE,NONEQUIV\.ATOMS.\s*(?P<x_wien2k_nonequiv_atoms>[0-9]+)"),
SM(r"(?P<x_wien2k_calc_mode>.*)"), SM(r"(?P<x_wien2k_calc_mode>.*)"),
# SM(r"\s*(?P<x_wien2k_unit_cell_param_a>[-+0-9.eEdD]+)\s*(?P<x_wien2k_unit_cell_param_b>[-+0-9.eEdD]+)\s*(?P<x_wien2k_unit_cell_param_c>[-+0-9.eEdD]+)\s*(?P<x_wien2k_angle_between_unit_axis_alfa>[-+0-9.eEdD]{9})\s*(?P<x_wien2k_angle_between_unit_axis_beta>[-+0-9.eEdD]{9})\s*(?P<x_wien2k_angle_between_unit_axis_gamma>[-+0-9.eEdD]+)"), # SM(r"\s*(?P<x_wien2k_unit_cell_param_a>[-+0-9.eEdD]+)\s*(?P<x_wien2k_unit_cell_param_b>[-+0-9.eEdD]+)\s*(?P<x_wien2k_unit_cell_param_c>[-+0-9.eEdD]+)\s*(?P<x_wien2k_angle_between_unit_axis_alfa>[-+0-9.eEdD]{9})\s*(?P<x_wien2k_angle_between_unit_axis_beta>[-+0-9.eEdD]{9})\s*(?P<x_wien2k_angle_between_unit_axis_gamma>[-+0-9.eEdD]+)"),
SM(r"\s*(?P<x_wien2k_unit_cell_param_a>[-+0-9]*\.\d{0,6}){0,10}\s*(?P<x_wien2k_unit_cell_param_b>[-+0-9]*\.\d{0,6}){0,10}\s*(?P<x_wien2k_unit_cell_param_c>[-+0-9]*\.\d{0,6}){0,10}\s*(?P<x_wien2k_angle_between_unit_axis_alfa>[-+]?[0-9]*\.\d{0,6}){0,10}\s*(?P<x_wien2k_angle_between_unit_axis_beta>[-+]?[0-9]*\.\d{0,6}){0,10}\s*(?P<x_wien2k_angle_between_unit_axis_gamma>[-+]?[0-9]*\.\d*)"), SM(r"\s*(?P<x_wien2k_unit_cell_param_a__angstrom>[-+0-9]*\.\d{0,6}){0,10}\s*(?P<x_wien2k_unit_cell_param_b__angstrom>[-+0-9]*\.\d{0,6}){0,10}\s*(?P<x_wien2k_unit_cell_param_c__angstrom>[-+0-9]*\.\d{0,6}){0,10}\s*(?P<x_wien2k_angle_between_unit_axis_alfa>[-+]?[0-9]*\.\d{0,6}){0,10}\s*(?P<x_wien2k_angle_between_unit_axis_beta>[-+]?[0-9]*\.\d{0,6}){0,10}\s*(?P<x_wien2k_angle_between_unit_axis_gamma>[-+]?[0-9]*\.\d*)"),
SM(r"\s*ATOM\s*[-0-9]+:\s*X=(?P<x_wien2k_atom_pos_x>[-+0-9.eEdD]+)\s*Y=(?P<x_wien2k_atom_pos_y>[-+0-9.eEdD]+)\s*Z=(?P<x_wien2k_atom_pos_z>[-+0-9.eEdD]+)", SM(r"\s*ATOM\s*[-0-9]+:\s*X=(?P<x_wien2k_atom_pos_x__angstrom>[-+0-9.eEdD]+)\s*Y=(?P<x_wien2k_atom_pos_y__angstrom>[-+0-9.eEdD]+)\s*Z=(?P<x_wien2k_atom_pos_z__angstrom>[-+0-9.eEdD]+)",
repeats=True, repeats=True,
sections=["x_wien2k_section_equiv_atoms"], sections=["x_wien2k_section_equiv_atoms"],
subMatchers=[ subMatchers=[
SM(r"\s*[-0-9]+:\s*X=(?P<x_wien2k_atom_pos_x>[-+0-9.eEdD]+)\s*Y=(?P<x_wien2k_atom_pos_y>[-+0-9.eEdD]+)\s*Z=(?P<x_wien2k_atom_pos_z>[-+0-9.eEdD]+)", SM(r"\s*[-0-9]+:\s*X=(?P<x_wien2k_atom_pos_x__angstrom>[-+0-9.eEdD]+)\s*Y=(?P<x_wien2k_atom_pos_y__angstrom>[-+0-9.eEdD]+)\s*Z=(?P<x_wien2k_atom_pos_z__angstrom>[-+0-9.eEdD]+)",
repeats=True repeats=True
), ),
# SM(r"\s*(?P<atom>.{10})\s*NPT=\s*(?P<NPT>[0-9]+)\s*R0=(?P<r0>[0-9.]+)\s*RMT=\s*(?P<rmt>[0-9.]+)\s*Z:\s*(?P<z>[0-9.]+)",) # SM(r"\s*(?P<atom>.{10})\s*NPT=\s*(?P<NPT>[0-9]+)\s*R0=(?P<r0>[0-9.]+)\s*RMT=\s*(?P<rmt>[0-9.]+)\s*Z:\s*(?P<z>[0-9.]+)",)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment