Vasprun.xml

The vasprun.xml is written in xml format and contains both, general output that is written for any calculation and specific output depending on the method or quantity that is being computed. Below you see details regarding the general output, while the specific output, e.g. the dielectric function (LOPTICS), partial density of states (LORBIT), the electronic self-energy (LSELFENERGY) etc., are detailed on the corresponding tag documentation. Mind that newer features tend to write to vaspout.h5. The vaspout.h5 should generally be preferred for reading large datasets.

File format#

The root element is <modeling>. The file uses four repeating XML primitives throughout:

  • value — a named scalar (real, integer, logical, or string).
  • <v name="...">x y z</v> — a named row vector.
  • <varray name="..."> — a named array of vectors, each on a <v> line.
  • <array> — a labelled multi-field table with named dimensions; rows are stored as <r> elements inside <set> blocks.

The overall layout of vasprun.xml is:

... ... ... ... ... ... ...

… <varrayname=“forces”>… <varrayname=“stress”>… … <timename=“totalsc”>… …

…

<structurename=“finalpos”>…

Sections#

Generator#

Contains the VASP version, build details, and the date and time of the run.

vasp 6.5.0 29Jan2024(buildFeb142024)complexparallel LinuxGNU 20240101 12:00:00

INCAR#

Contains only the tags explicitly set in the INCAR file, without defaults. This is a compact record of the user-specified settings for the run.

diamondSi Normal 500.00000000 0 0.05000000

Primitive cell#

Contains the structure and lattice of the primitive unit cell, along with the mapping of primitive-cell ion indices to the full simulation-cell ion indices.

<primitive_cell> <structurename=“primitive_cell”> <varrayname=“basis”> 1.921.920.00 0.001.921.92 1.920.001.92 <iname=“volume”>28.35 <varrayname=“rec_basis”> 0.260.26-0.26 -0.260.260.26 0.26-0.260.26 <varrayname=“positions”> 0.000.000.00 0.250.250.25 <varrayname=“primitive_index”> <vtype=“int”>1 <vtype=“int”>2 </primitive_cell>

k points#

Specifies the k-point sampling of the Brillouin zone, mirroring the KPOINTS file.

444 0.00.00.0 0.250.000.00 0.000.250.00 0.000.000.25 0.000.000.00 0.0000.0000.000 0.2500.0000.000 ... 0.00463 0.03704 ...

Parameters#

Contains a complete record of all effective INCAR parameters, including those not set explicitly (with their default values). The block is organized into named <separator> subsections corresponding to groups of related tags, for example:

  • general
  • electronic (with sub-separators: smearing, projectors, startup, spin, exchange-correlation, convergence, mixer, dipolcorrection)
  • grids
  • ionic and ionic md
  • symmetry
  • dos
  • writing
  • performance
  • miscellaneous
  • orbital magnetization
  • response functions (GW/BSE calculations)
  • vdW DFT

There are several other groups that we have not included here. The full documentation for each tag is found on its individual tag page.

Atom info#

Contains the atomic species and per-ion type information.

2 1 ion element atomtype Si1 Si1 type atomspertype element mass valence pseudopotential 2Si28.085000004.00000000PAW_PBESi05Jan2001

Initial structure#

The ionic positions at the start of the run, read from POSCAR. For molecular-dynamics runs, this block also contains the initial ionic velocities.

<structurename=“initialpos”> <varrayname=“basis”> 5.430.000.00 0.005.430.00 0.000.005.43 <iname=“volume”>160.10 <varrayname=“rec_basis”> 0.1840.0000.000 0.0000.1840.000 0.0000.0000.184 <varrayname=“positions”> 0.0000.0000.000 0.2500.2500.250

<varrayname=“velocities”> 0.0005-0.00040.0002 -0.00090.00040.0005

Ionic steps#

For runs with ionic motion (relaxations, MD, NEB), each ionic step is written as a sequence of flat blocks directly under <modeling>. There is no enclosing <calculation> element; each step contains:

... ... ... ... 0.12-0.030.00 ... -0.160.000.11 0.000.000.00 0.110.00-0.08 -53.93 -53.93 -53.93 0.10 0.00 -53.83 0.040.01
Mind: For IBRION=0 (MD) with a large number of steps (NSW » 1), vasprun.xml can become very large. Consider using vaspout.h5 instead, or reading with a streaming XML parser (see below).

Electronic-structure calculation block#

For a single-point electronic minimization calculations (NSW = 0) and post-DFT methods (GW, BSE), a single <calculation> block instead of per-step ionic-step blocks is written. It contains eigenvalues, the density of states (DOS), the partial DOS (LORBIT) and, for optical calculations, the dielectric function (LOPTICS).

For GW calculations (e.g., ALGO=EVGW0 or GW0), <eigenvalues> contains the quasiparticle energies updated by the GW self-energy. Multiple <dielectricfunction> blocks appear in the same <calculation>, each labelled by its comment attribute.

Final structure#

The ionic positions at the end of the run. For MD runs, this block also contains the final ionic velocities (also see VELOCITY for vaspout.h5 output), suitable for restarting the trajectory.

<structurename=“finalpos”> <varrayname=“basis”>… <iname=“volume”>… <varrayname=“rec_basis”>… <varrayname=“positions”>…

<varrayname=“velocities”>…

Reading vasprun.xml#

pymatgen#

The pymatgen library provides the Vasprun class:

frompymatgen.io.vaspimport Vasprun

vr = Vasprun(“vasprun.xml”)

print(vr.final_energy) # total energy of the final ionic step (eV)

Iterate over ionic steps#

for step in vr.ionic_steps: e = step[“electronic_steps”][-1][“e_fr_energy”] print(e)

print(vr.final_structure) # pymatgen Structure object dos = vr.complete_dos # total and projected DOS

ASE#

The Atomic Simulation Environment (ASE) reads vasprun.xml as a sequence of Atoms objects:

fromase.ioimport read

images = read(“vasprun.xml”, index=":") # all ionic steps atoms = images[-1] # final structure

print(atoms.get_potential_energy()) # total energy (eV) print(atoms.get_forces()) # forces (eV/Å)

Direct XML parsing#

ElementTree#

For custom workflows, parse vasprun.xml with Python’s standard library:

importxml.etree.ElementTreeasET

tree = ET.parse(“vasprun.xml”) root = tree.getroot()

Read INCAR tags#

for tag in root.find(“incar”): print(tag.attrib.get(“name”), “=”, tag.text.strip())

Read forces from each ionic step#

for forces in root.iter(“varray”): if forces.attrib.get(“name”) == “forces”: data = [[float(x) for x in v.text.split()] for v in forces] print(data)

Mind: For large MD trajectories, use xml.etree.ElementTree.iterparse to stream the file element by element and avoid loading it entirely into memory.

lxml#

There are also plenty of other Python packages that can be used to read vasprun.xml, e.g., lxml:

fromlxmlimport etree

Parse XML#

tree = etree.parse(“vasprun.xml”) root = tree.getroot()

Read INCAR tags#

incar = root.find(“incar”)

for tag in incar: name = tag.attrib.get(“name”) value = tag.text.strip() if tag.text else None print(name, “=”, value)

Read the final energy#

energies = root.xpath(".//i[@name=‘e_0_energy’]/text()") final_energy = float(energies[-1])

print(final_energy)

Read forces from each ionic step#

forces_blocks = root.xpath(".//varray[@name=‘forces’]")

for forces in forces_blocks: data = [ [float(x) for x in v.text.split()] for v in forces ] print(data)

There are plenty of other Python packages that can be used, or other languages if you prefer, which we will not describe here.

Terminal commands#

xmllint#

The xmllint tool can be used to view the contents of the vasprun.xml file based from command line. E.g.,

xmllint–xpath’//dos/partial’vasprun.xml

will print the partial density of states to terminal.

xmlstarlet#

Alternatively, the xmlstarlet tool can be used vasprun.xml, e.g.,

xmlstarletsel-t-c’//dos/partial’vasprun.xml

will print the partial density of states to terminal.

There are several other command line tools that can be used for analysis, e.g., mpg that we will not go into detail in here.

  • OUTCAR — the human-readable logfile.
  • vaspout.h5 — the HDF5 alternative to vasprun.xml, preferred for large runs and newer features.