Registry / data / vasprun-xml

vasprun-xml

JSON →
library1.0.4pypypi✓ verified 89d ago

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.

pip install vasprun-xml
INSTALL
IMPORT
SIG · VASPRUN-XML
V
vasprun-xml
datapythonv1.0.4
Install
15.5s avg
Import
3074ms
Disk
408MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.0.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 3.158s · 405.5MB
glibc
py 3.10–3.910 runs
installs and imports cleanly · install 15.5s · import 2.989s · 389MB
408MB installed
● package 408MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

vasprun
✓ from vasprun import vasprun

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")
vasprun-xml --version
Debug
Known issues
breakingThe `vasprun-xml` library explicitly requires Python 3. Support for Python 2.x is not provided, and attempts to use it with Python 2 will result in compatibility errors.
fix
Ensure your environment uses Python 3.6.1 or newer. Upgrade your Python installation if necessary.
affects: <3.6.1
gotchaVASP's `vasprun.xml` can become corrupted or malformed if the VASP calculation terminates abruptly (e.g., due to system errors or manual termination), especially common with GPU VASP runs. This often leads to 'XML not well-formed' errors during parsing.
fix
Ensure VASP calculations terminate gracefully. If using a job scheduler or workflow manager, implement mechanisms for graceful termination (e.g., writing a `STOPCAR` file). For existing corrupted files, manual editing may be required, or the VASP calculation must be re-run.
affects: All versions of vasprun-xml (dependent on VASP output)
gotchaThe internal structure of `vasprun.xml` can vary between major VASP versions (e.g., VASP 5 vs. VASP 6), which might affect how `vasprun-xml` parses certain data fields or lead to missing information for newer VASP features. While the library strives for robustness, significant schema changes may not be immediately supported.
fix
Consult the `vasprun-xml` documentation or GitHub issues for known compatibility notes with specific VASP versions. If encountering parsing issues, verify the XML structure against an expected format for your VASP version.
affects: All versions (dependent on VASP version)
Errors
Common errors & fixes
lxml.etree.XMLSyntaxError: Premature end of data in tag ...
The `vasprun.xml` file is incomplete or malformed, typically because the VASP job was terminated before the XML file could be fully written.
fix
Verify that your VASP calculation completed successfully. If not, re-run the calculation ensuring a graceful termination. For partially written files, try opening the XML in a text editor to identify and potentially manually fix truncation points, though a re-run is generally more reliable.
ModuleNotFoundError: No module named 'vasprun'
The Python package is named `vasprun-xml` on PyPI, but the import statement should use `vasprun` as the top-level module name.
fix
Use `from vasprun import vasprun` or `import vasprun` in your Python code. The installation command `pip install vasprun-xml` installs the package under the `vasprun` module name.
AttributeError: 'Vasprun' object has no attribute 'plot_dos'
This error can occur if `matplotlib` (a required dependency for plotting) is not installed, or if the `vasprun.xml` file being parsed does not contain the necessary density of states (DOS) or band structure data for plotting.
fix
First, ensure `matplotlib` is installed (`pip install matplotlib`). Second, confirm that your `vasprun.xml` file contains the relevant sections (e.g., `EIGENVAL` for bands, `DOS` for density of states) as output by VASP.
Upgrade
Version history
1.0.4latest on PyPI · released Feb 14, 2022
Audit
Dependencies
lxmlrequiredRequired for efficient XML parsing.
matplotlibrequiredEssential for generating DOS and band structure plots.
numpyrequiredCore numerical computing library for data manipulation.
scipyrequiredUsed for scientific computing, potentially for data processing or smearing.
pandasrequiredData structures and analysis tools.
Agent activity
23 hits · last 30 days
node
18
OpenAI (training)
1
Resources
vasprun-xml — pip install vasprun-xml · libregistry