-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdraw_bandstructure1.normal.py
57 lines (47 loc) · 1.97 KB
/
draw_bandstructure1.normal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import pymatgen as mg
from pymatgen.io.vasp.outputs import BSVasprun, Vasprun
#from pymatgen import Spin
from pymatgen.electronic_structure.plotter import BSPlotter, BSDOSPlotter, DosPlotter
import matplotlib.pyplot as plt
print('Need to run inside a bs_non-self subfolder')
## (1) use vasprun to process data
v = BSVasprun('vasprun.xml')
bs = v.get_band_structure(kpoints_filename="KPOINTS",line_mode=True)
print('Fermi level in OUTCAR is ',bs.efermi) # print the fermi level
## (2) use plotter to get the plot
bsplot = BSPlotter(bs)
ticks=bsplot.get_ticks()
print(ticks)
# if want to show legends, change in this bs_labels. Use ax_legend() to omit showing this label
zero_to_efermi=True
bsplot.get_plot(ylim=(-6, 10), zero_to_efermi=zero_to_efermi) #, bs_labels=['wBeO']
## (3) add some plot features
ax = plt.gca()
#### labels of x and y axis
ax.set_xlabel('Wave Vector',rotation=0)
ax.set_ylabel('', rotation=0) # energies (eV) '$\mathrm{E}-\mathrm{E}_\mathrm{VBM} (eV)$' ,rotation=270
#### put y labels on the right
#ax.yaxis.set_label_position('right') # position of labels
#ax.yaxis.tick_right() # put the ticks on the right hand side
### tick size
plt.yticks(fontsize=22)
### set title
ax.set_title("Band Structure", fontsize=25)
### Draw a horizontal line to represent fermi level when zero_to_efermi=True
if zero_to_efermi:
xlim = ax.get_xlim()
ax.hlines(0, xlim[0], xlim[1], linestyles="dashed", color="black")
# remove legend with this command
#ax.legend(fontsize=16)#, loc="upper left") # remove legend like 'band 0 up' # will get 'No handles with labels found to put in legend.'
####################################
#### HERE!!! set ylimit
#plt.ylim([-1.0,0.5]) # HERE!!! ylim
#plt.ylim([-0.5,1.0]) # HERE!!! ylim
plt.ylim([-2.0,1.0]) # HERE!!! ylim
#plt.ylim([-5.0,9.0]) # HERE!!! ylim
####################################
## (4) save the plot
plt.tight_layout()
plt.savefig('bandstructure.pdf',dpi=600)
print('figure generated: bandstructure.pdf')
#bsplot.save_plot('bandstructure.png')