So I am trying to plot the band structure from the EIGENVAL
file produced by VASP. I wrote this Python code:
import numpy as np
import matplotlib.pyplot as mpl
mpl.rcParams["mathtext.fontset"] = "stix" # Change the math font
mpl.rcParams["font.family"] = "STIXGeneral" # Change the global font
with open('EIGENVAL', 'r') as f:
data = f.readlines()
nkpts = int(data[5].split()[1])
nbands = int(data[5].split()[2])
print(nkpts, nbands)
kpoints = []
energies = []
for i in range(nkpts):
line_index = 7+(nbands+2)*i
kpoint_coords = [float(x) for x in data[line_index].split()[:3]]
eigenvalues = []
for j in range(nbands):
eigenvalue = float(data[line_index+j+1].split()[1])
eigenvalues.append(eigenvalue)
kpoints.append(kpoint_coords)
energies.append(eigenvalues)
kpoints = np.array(kpoints)
energies = np.array(energies)
EF = 1.92675163
energies = (energies.T - EF).T
xaxis = [j for j in range(len(kpoints))]
mpl.xticks([xaxis[0], xaxis[int(len(xaxis)/2-1)], xaxis[-1]], ["L", "Γ", "X"])
for i in range(nbands):
mpl.plot(xaxis, energies[:, i])
mpl.axhline(y=0, linestyle='--')
# mpl.axhline(y=2, linestyle='--')
mpl.axvline(x=xaxis[0], linestyle='-')
mpl.axvline(x=xaxis[int(len(xaxis)/2-1)], linestyle='-')
mpl.axvline(x=xaxis[-1], linestyle='-')
mpl.xlabel('$k$-points')
mpl.ylabel('$E$$-$VBM [eV]')
mpl.savefig('BS.png', dpi=800, bbox_inches="tight")
mpl.show()
I am defining the xaxis
array which is rather arbitrary.
My question is: Is there a more efficient way to plot the band structure after extracting the data?