8
$\begingroup$

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 getting this figure: enter image description here

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?

$\endgroup$
5
  • 3
    $\begingroup$ Are you looking for ways to plot the band structure using the EIGENVAL file? Or is it okay if you get the plot using other VASP output files? If it is the latter case: see this and this question where you can find many post-processing tools. (The link to sumo is broken in the question. This is working) $\endgroup$ Apr 12, 2023 at 23:34
  • $\begingroup$ Could you please clarify in your question what you mean by “better way to plot band structure”? what is your expected output of the plot? $\endgroup$ Apr 13, 2023 at 7:21
  • $\begingroup$ Thanks so much @AbdulMuhaymin. This answers my question. $\endgroup$
    – Mohamed
    Apr 13, 2023 at 20:29
  • $\begingroup$ @Mohamed in that case, I will try to add it as an answer. $\endgroup$ Apr 13, 2023 at 21:51
  • $\begingroup$ @AbdulMuhaymin very useful links, I had also tried in the past to extract by parsing the data of the vasp.xml file for a plot using gnuplot, but this is stuff already done and more efficiently. $\endgroup$
    – M06-2x
    Apr 14, 2023 at 11:26

1 Answer 1

1
$\begingroup$

As @AbdulMuhaymin pointed out in the comments: PyPROCAR looks like a nice tool that does more than just plotting band structures, and it works for many DFT codes other than VASP.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .