vasprun-xml: VASP XML Analyzer

1.0.4 · active · verified Thu Apr 16

vasprun-xml is a Python package designed for rapid analysis of VASP calculation results directly from the `vasprun.xml` file. It supports features like band gap calculation, plotting of Density of States (DOS) and band structures, generation of INCAR/POTCAR/POSCAR files, force analysis, and Kohn-Sham orbital eigenvalue analysis. The current PyPI version is 1.0.4, with active development and regular updates.

Common errors

Warnings

Install

Imports

Quickstart

Initializes the `vasprun` parser with a `vasprun.xml` file, then demonstrates how to check for calculation errors and extract basic properties like chemical formula and band gap. Note that plotting functions require a complete `vasprun.xml` containing the relevant data sections.

import os
from vasprun import vasprun

# Create a dummy vasprun.xml for demonstration or ensure one exists
# In a real scenario, this file would be generated by a VASP calculation.
# For quickstart, we'll assume 'vasprun.xml' exists in the current directory.
# Example: Create a minimal mock file if not present (not a full VASP XML)
if not os.path.exists('vasprun.xml'):
    with open('vasprun.xml', 'w') as f:
        f.write('<modeling><calculator><parameters></parameters></calculator></modeling>')

# Load the vasprun.xml file
vasp_data = vasprun('vasprun.xml')

# Check if the calculation converged or for errors
if vasp_data.error:
    print(f"VASP calculation reported an error: {vasp_data.errormsg}")
else:
    print("VASP calculation completed successfully.")

# Extract basic information
print(f"Formula: {vasp_data.values.get('formula', 'N/A')}")
print(f"Band Gap (eV): {vasp_data.values.get('gap', 'N/A')}")

# Example: Plot DOS (requires a full vasprun.xml with DOS data)
# vasp_data.plot_dos(filename='dos_plot.png', styles='t')
# print("DOS plot generated as dos_plot.png")

view raw JSON →