py4vasp

0.11.2 · active · verified Fri Apr 17

py4vasp is a Python interface for analyzing and setting up VASP calculations, primarily by extracting data from the new HDF5 file format (`VASP_H5_data.h5`). It's designed for quick data inspection, plotting, and export to other tools, serving as a powerful assistant for materials science researchers working with VASP output. The library is actively developed, with regular releases providing new features and improvements.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `Calculation` object from a VASP output directory, access common data types like the Density of States (DOS), plot them, and export them to a Python dictionary. It includes error handling for cases where VASP output files are missing or incomplete.

import py4vasp as pv
import matplotlib.pyplot as plt
import os

# This example assumes a VASP calculation's output files
# (especially VASP_H5_data.h5) are present in the 'example_calc_path' directory.
# Replace 'example_calc_path' with the actual directory containing your VASP output.
# For demonstration, we use a placeholder and handle potential errors.

# If you have VASP output in a specific directory, set it here:
example_calc_path = os.environ.get("VASP_CALC_PATH", ".") # Defaults to current directory

try:
    # Initialize a Calculation object from the path
    calc = pv.Calculation(example_calc_path)

    # Access and plot the Density of States (DOS)
    if hasattr(calc, 'dos') and calc.dos.is_readable():
        print(f"Loading DOS from: {example_calc_path}")
        dos_plot = calc.dos.plot()
        # dos_plot.show() # Uncomment to display the plot (requires matplotlib backend)

        # Export DOS data to a dictionary
        dos_data = calc.dos.to_dict()
        print("DOS data keys:", dos_data.keys())
    else:
        print(f"DOS data not found or not readable in '{example_calc_path}'.")
        print("Ensure VASP_H5_data.h5 exists and contains DOS information.")

except Exception as e:
    print(f"Error accessing VASP calculation at '{example_calc_path}': {e}")
    print("Please ensure the path is correct and contains valid VASP HDF5 output files.")

# Example of accessing the band structure data object directly
bands_object = pv.data.band()
print(f"\nExample of accessing band structure data object: {bands_object}")
# bands_object.plot().show() # Would require a VASP_H5_data.h5 with band data

view raw JSON →