How to get High Symmetry Kpoints used in a Band structure plot

Hi!

I used the following to get and plot the band structure of the material mp-92.

from pymatgen.electronic_structure.plotter import BSPlotter

def plot_bandstructure(bs):
    BSPlotter(bs).get_plot().show() 

with MPRester(api_key) as mpr:
    bs = mpr.get_bandstructure_by_material_id("mp-92")

plot_bandstructure(bs) 

I need help to do the following:

  1. Print High Symmetry Kpoints with their labels.
  2. Export band structures as a text file.

Thanks in advance.

Edit:

I tried as following:

api_key = "#########" 
output_file = "band_structure.txt"

with MPRester(api_key) as mpr:
    bs = mpr.get_bandstructure_by_material_id("mp-92")

bands = bs.bands
kpoints = bs.kpoints
labels_dict = bs.labels_dict

spin_component = Spin.up 

with open(output_file, 'w') as file:
    file.write("# kx  ky  kz  label  E1  E2  E3 ... (energies for each band)\n")
    for i, (kpoint, label) in enumerate(zip(kpoints, labels_dict)):
        file.write(f"{kpoint.frac_coords[0]:.6f} {kpoint.frac_coords[1]:.6f} {kpoint.frac_coords[2]:.6f} {label} ")
        file.write(" ".join(f"{energy:.6f}" for energy in bands[spin_component][i]))  # Specify the spin component
        file.write("\n")

But the results are not logic for me. Here is a part of the produced file:

# kx  ky  kz  label  E1  E2  E3 ... (energies for each band)
0.000000 0.000000 0.000000 \Gamma -4.608600 -4.608300 -4.607200 -4.605400 -4.602900  .......
0.000000 0.000000 0.005376 X 6.591500 6.571000 6.518100 6.446800 6.365600 6.278700 ........
0.000000 0.000000 0.010753 M 6.591500 6.591900 6.592800 6.594500 6.596800 6.599700 ........ 
0.000000 0.000000 0.016129 Z 6.984000 7.003100 7.051600 7.115500 7.186500 7.260200 ........ 
0.000000 0.000000 0.021505 P 10.681400 10.683800 10.691000 10.702900 10.719600 10.7 ........
0.000000 0.000000 0.026882 N 16.626300 16.618900 16.597400 16.562800 16.517000 16.4 ........
0.000000 0.000000 0.032258 Z_1 17.894500 17.891500 17.882700 17.868200 17.848200 17 ........

K points don’t make sense in addition to there are different numbers of bands at each k point.

The different number of bands might be due to the fact that the bandstructure data is a concatenation of the high-symmetry data (BandStructureSymmLine object in pymatgen) and the default BandStructure object for uniform (Monkhorst-pack) data.

The get_bandstructure_by_material_id takes two additional arguments, namely: line_mode and path_type which you can use to specify only the BandStructureSymmLine dataset e.g.

    from emmet.core.electronic_structure import BSPathType
    mpr.get_bandstructure_by_material_id("mp-92", path_type=BSPathType.'setyawan_curtarolo', line_mode=True)

Note that not all the k-points will be labelled, just the ones at those key label points, so if you want the full dataset, retrive all the kpoint objects, noting that each object has a label attribute.

Thread closed due to inactivity, please open a new thread to address related issues.