--- title: Xml Parser keywords: fastai sidebar: home_sidebar summary: "This parser contains functions to extract data from vasprun.xml. All functions in xml parser can work without arguments if working directory contains `vasprun.xml`." description: "This parser contains functions to extract data from vasprun.xml. All functions in xml parser can work without arguments if working directory contains `vasprun.xml`." nb_path: "XmlElementTree.ipynb" ---
Dict2Data object with attributes accessible via dot notation. This object can by transformed to a dictionary by to_dict() method on the object.x = Dict2Data({'A':1,'B':2})
print('Dict: ',x.to_dict())
print('JSON: ',x.to_json())
print('Pickle: ',x.to_pickle())
print('Tuple: ',x.to_tuple())
x['A']
import pivotpy.vr_parser as vp
xml_data=vp.read_asxml(path= '../vasprun.xml')
get_summary(xml_data=xml_data).to_tuple()
get_kpts(xml_data=xml_data,skipk=10)
get_tdos(xml_data=xml_data,spin_set=1,elim=[])
get_evals(xml_data=xml_data,skipk=10,elim=[-5,5])
get_bands_pro_set(xml_data,skipk=0,spin_set=1,bands_range=range(0, 1))
get_structure(xml_data=xml_data)
export_vasprun(path='E:/Research/graphene_example/ISPIN_1/bands/vasprun.xml',elim=[-1,0],try_pwsh=True)
shift_kpath in export_vasprun and plot each export on same axis, this will align bandstructures side by side on same axis.This back and forth data transport is required in pivotpy-dash app where data is stored in browser in json format, but needs to by python objects for figures.
Use dump_vasprun to write output of export_vasprun or load_export to pickle/json file. Pickle is useful for quick load in python while json is useful to transfer data into any language.
import pivotpy as pp
evr = pp.Vasprun('../vasprun.xml').data
s = dump_dict(evr.poscar,dump_to='pickle')
#print(s)
load_from_dump(s)
islice2array is used to read text files which have patterns of text and numbers inline, such as EIGENVAL and PROCAR. With all the options of this function, reading and parsing of such files should take a few lines of code only. It can be used to read txt,csv tsv as well with efficent speed.slice_data([list(range(1,7)),-1,-1,range(2)],old_shape=[52,768,64,9])
vasprun.xml Files You can split a large vasprun.xml file in a small _vasprun.xml file which does not contain projected data, and _set[1,2,3,4].txt file(s) which contain projected data of each spin set. These spin set text files can be processed by islice2array function efficiently.