Vasprun Parser¶
-
pivotpy.vr_parser.
Dict2Data
(d)[source]¶ Returns a Data object with dictionary keys as attributes of Data accessible by dot notation.
- Parmeters
dict : Python dictionary (nested as well) containing any python data types.
- Methods
to_dict() : Converts a Data object to dictionary if it could be made a dictionary, otherwise throws relevant error.
to_json() : Converts to json str or save to file if outfil given. Accepts indent as parameter.
to_pickle(): Converts to bytes str or save to file if outfile given.
- Example
> x = Dict2Data({‘A’:1,’B’:{‘C’:2}}) > x > Data( > A = 1 > B = Data( > C = 2 > ) > ) > x.B.to_dict() > {‘C’: 2}
-
pivotpy.vr_parser.
read_asxml
(path=None)[source]¶ Reads a big vasprun.xml file into memory once and then apply commands. If current folder contains vasprun.xml file, it automatically picks it.
- Parameters
path : Path/To/vasprun.xml
- Returns
xml_data : Xml object to use in other functions
-
pivotpy.vr_parser.
get_summary
(xml_data=None)[source]¶ Returns overview of system parameters.
- Parameters
xml_data : From read_asxml function
- Returns
Data : pivotpy.Dict2Data with attibutes accessible via dot notation.
-
pivotpy.vr_parser.
get_kpts
(xml_data=None, skipk=0, joinPathAt=[])[source]¶ Returns kpoints and calculated kpath.
- Parameters
xml_data – From read_asxml function.
skipk (int) – Number of initil kpoints to skip.
joinPathAt (list) – List of indices of kpoints where path is broken.
- Returns
Data – with attibutes kpath and kpoints.
- Return type
pivotpy.Dict2Data
See also
get_kpath()
Notes
Notes about the implementation algorithm (if needed). This can have multiple paragraphs. You may include some math:
\[X(e^{j\omega } ) = x(n)e^{ - j\omega n}\]And even use a greek symbol like \(omega\) inline.
-
pivotpy.vr_parser.
get_tdos
(xml_data=None, spin_set=1, elim=[])[source]¶ Returns total dos for a spin_set (default 1) and energy limit. If spin-polarized calculations, gives SpinUp and SpinDown keys as well.
- Parameters
xml_data : From read_asxml function
spin_set : int, default is 1.and
elim : List [min,max] of energy, default empty.
- Returns
Data : pivotpy.Dict2Data with attibutes E_Fermi, ISPIN,tdos.
-
pivotpy.vr_parser.
get_evals
(xml_data=None, skipk=None, elim=[])[source]¶ Returns eigenvalues as numpy array. If spin-polarized calculations, gives SpinUp and SpinDown keys as well.
- Parameters
xml_data : From read_asxml function
skipk : Number of initil kpoints to skip.
elim : List [min,max] of energy, default empty.
- Returns
Data : pivotpy.Dict2Data with attibutes evals and related parameters.
-
pivotpy.vr_parser.
get_bands_pro_set
(xml_data=None, spin_set=1, skipk=0, bands_range=None, set_path=None)[source]¶ Returns bands projection of a spin_set(default 1). If spin-polarized calculations, gives SpinUp and SpinDown keys as well.
- Parameters
xml_data : From read_asxml function
skipk : Number of initil kpoints to skip (Default 0).
spin_set : Spin set to get, default is 1.
bands_range : If elim used in get_evals,that will return bands_range to use here. Note that range(0,2) will give 2 bands 0,1 but tuple (0,2) will give 3 bands 0,1,2.
set_path : path/to/_set[1,2,3,4].txt, works if split_vasprun is used before.
- Returns
Data : pivotpy.Dict2Data with attibutes of bands projections and related parameters.
-
pivotpy.vr_parser.
get_dos_pro_set
(xml_data=None, spin_set=1, dos_range=None)[source]¶ Returns dos projection of a spin_set(default 1) as numpy array. If spin-polarized calculations, gives SpinUp and SpinDown keys as well.
- Parameters
xml_data : From read_asxml function
spin_set : Spin set to get, default 1.
dos_range : If elim used in get_tdos,that will return dos_range to use here..
- Returns
Data : pivotpy.Dict2Data with attibutes of dos projections and related parameters.
-
pivotpy.vr_parser.
get_structure
(xml_data=None)[source]¶ Returns structure’s volume,basis,positions and rec-basis.
- Parameters
xml_data : From read_asxml function.
- Returns
Data : pivotpy.Dict2Data with attibutes volume,basis,positions and rec_basis.
-
pivotpy.vr_parser.
export_vasprun
(path=None, skipk=None, elim=[], joinPathAt=[], shift_kpath=0)[source]¶ Returns a full dictionary of all objects from vasprun.xml file. It first try to load the data exported by powershell’s Export-VR(Vasprun), which is very fast for large files. It is recommended to export large files in powershell first.
- Parameters
path : Path to vasprun.xml file. Default is ‘./vasprun.xml’.
skipk : Default is None. Automatically detects kpoints to skip.
elim : List [min,max] of energy interval. Default is [], covers all bands.
joinPathAt : List of indices of kpoints where path is broken.
shift_kpath: Default 0. Can be used to merge multiple calculations on single axes side by side.
- Returns
- DataData accessible via dot notation containing nested Data objects:
sys_info : System Information
dim_info : Contains information about dimensions of returned objects.
kpoints : numpy array of kpoints with excluded IBZKPT points
kpath : 1D numpy array directly accessible for plot.
bands : Data containing bands.
tdos : Data containing total dos.
pro_bands : Data containing bands projections.
pro_dos : Data containing dos projections.
poscar : Data containing basis,positions, rec_basis and volume.
-
pivotpy.vr_parser.
load_export
(path='./vasprun.xml', joinPathAt=[], shift_kpath=0, path_to_ps='pwsh', skipk=None, max_filled=10, max_empty=10, keep_files=True)[source]¶ Returns a full dictionary of all objects from vasprun.xml file exported using powershell.
- Parameters
path : Path to vasprun.xml file. Default is ‘./vasprun.xml’.
skipk : Default is None. Automatically detects kpoints to skip.
path_to_ps : Path to powershell.exe. Automatically picks on Windows and Linux if added to PATH.
joinPathAt : List of indices of kpoints where path is broken.
shift_kpath: Default 0. Can be used to merge multiple calculations side by side.
keep_files : Could be use to clean exported text files. Default is True.
max_filled : Number of filled bands below and including VBM. Default is 10.
max_empty : Number of empty bands above VBM. Default is 10.
- Returns
- DataData accessible via dot notation containing nested Data objects:
sys_info : System Information
dim_info : Contains information about dimensions of returned objects.
kpoints : numpy array of kpoints with excluded IBZKPT points
kpath : 1D numpy array directly accessible for plot.
bands : Data containing bands.
tdos : Data containing total dos.
pro_bands : Data containing bands projections.
pro_dos : Data containing dos projections.
poscar : Data containing basis,positions, rec_basis and volume.
-
pivotpy.vr_parser.
dump_dict
(dict_data=None, dump_to='pickle', outfile=None, indent=1)[source]¶ Dump an export_vasprun or load_export’s Data object or any dictionary to json or pickle string/file. It convert Dict2Data to dictionary before serializing to json/pickle, so json/pickle.loads() of converted Data would be a simple dictionary, pass that to Dict2Data to again make accessible via dot notation.
- Parameters
dict_data : Any dictionary/Dict2Data object containg numpy arrays, including export_vasprun or load_export output.
dump_to : Defualt is pickle or json.
outfile : Defualt is None and return string. File name does not require extension.
indent : Defualt is 1. Only works for json.
-
pivotpy.vr_parser.
load_from_dump
(file_or_str, keep_as_dict=False)[source]¶ Loads a json/pickle dumped file or string by auto detecting it.
- Parameters
file_or_str : Filename of pickl/json or their string.
keep_as_dict: Defualt is False and return Data object. If True, returns dictionary.
-
pivotpy.vr_parser.
islice2array
(path_or_islice, dtype=<class 'float'>, delimiter='\\s+', include=None, exclude='#', raw=False, fix_format=True, start=0, nlines=None, count=-1, cols=None, new_shape=None)[source]¶ Reads a sliced array from txt,csv type files and return to array. Also manages if columns lengths are not equal and return 1D array. It is faster than loading whole file into memory. This single function could be used to parse EIGENVAL, PROCAR, DOCAR and similar files with just a combination of exclude, include,start,stop,step arguments.
- Parameters
path_or_islice: Path/to/file or itertools.islice(file_object). islice is interesting when you want to read different slices of an opened file and do not want to open it again and again. For reference on how to use it just execute pivotpy.export_potential?? in a notebook cell or ipython terminal to see how islice is used extensively.
dtype: float by default. Data type of output array, it is must have argument.
start,nlines: The indices of lines to start reading from and number of lines after start respectively. Only work if path_or_islice is a file path. both could be None or int, while start could be a list to read slices from file provided that nlines is int. The spacing between adjacent indices in start should be equal to or greater than nlines as pointer in file do not go back on its own. These parameters are in output of slice_data
> Note: start should count comments if exclude is None. You can use slice_data function to get a dictionary of start,nlines, count, cols, new_shape and unpack in argument instead of thinking too much. - count: np.size(output_array) = nrows x ncols, if it is known before execution, performance is increased. This parameter is in output of slice_data. - delimiter: Default is s+. Could be any kind of delimiter valid in numpy and in the file. - cols: List of indices of columns to pick. Useful when reading a file like PROCAR which e.g. has text and numbers inline. This parameter is in output of slice_data. - include: Default is None and includes everything. String of patterns separated by | to keep, could be a regular expression. - exclude: Default is ‘#’ to remove comments. String of patterns separated by | to drop,could be a regular expression. - raw : Default is False, if True, returns list of raw strings. Useful to select cols. - fix_format: Default is True, it sepearates numbers with poor formatting like 1.000-2.000 to 1.000 2.000 which is useful in PROCAR. Keep it False if want to read string literally. - new_shape : Tuple of shape Default is None. Will try to reshape in this shape, if fails fallbacks to 2D or 1D. This parameter is in output of slice_data.
- Examples
> islice2array(‘path/to/PROCAR’,start=3,include=’k-point’,cols=[3,4,5])[:2] > array([[ 0.125, 0.125, 0.125], > [ 0.375, 0.125, 0.125]]) > islice2array(‘path/to/EIGENVAL’,start=7,exclude=’E’,cols=[1,2])[:2] > array([[-11.476913, 1. ], > [ 0.283532, 1. ]])
> Note: Slicing a dimension to 100% of its data is faster than let say 80% for inner dimensions, so if you have to slice more than 50% of an inner dimension, then just load full data and slice after it.
-
pivotpy.vr_parser.
slice_data
(dim_inds, old_shape)[source]¶ Returns a dictionary that can be unpacked in arguments of isclice2array function. This function works only for regular txt/csv/tsv data files which have rectangular data written.
- Parameters
dim_inds : List of indices array or range to pick from each dimension. Inner dimensions are more towards right. Last itmes in dim_inds is considered to be columns. If you want to include all values in a dimension, you can put -1 in that dimension. Note that negative indexing does not work in file readig, -1 is s special case to fetch all items.
old_shape: Shape of data set including the columns length in right most place.
- Example
You have data as 3D arry where third dimension is along column.
> 0 0 > 0 2 > 1 0 > 1 2 - To pick [[0,2], [1,2]], you need to give > slice_data(dim_inds = [[0,1],[1],-1], old_shape=(2,2,2)) > {‘start’: array([1, 3]), ‘nlines’: 1, ‘count’: 2} - Unpack above dictionary in islice2array and you will get output array.
Note that dimensions are packed from right to left, like 0,2 is repeating in 2nd column.
-
pivotpy.vr_parser.
split_vasprun
(path=None)[source]¶ Splits a given vasprun.xml file into a smaller _vasprun.xml file plus _set[1,2,3,4].txt files which contain projected data for each spin set.
- Parameters
path: path/to/vasprun.xml file.
- Output
_vasprun.xml file with projected data.
_set1.txt for projected data of colinear calculation.
_set1.txt for spin up data and _set2.txt for spin-polarized case.
_set[1,2,3,4].txt for each spin set of non-colinear calculations.