File size: 2,279 Bytes
1c703f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from pymatgen.io.vasp.outputs import Vasprun
from pymatgen.electronic_structure.plotter import BSPlotter
from pymatgen.electronic_structure.core import Spin
import matplotlib.pyplot as plt


def get_band_structure(vasp_xml_path):


    vasprun = Vasprun(vasp_xml_path)
    try:
        # Get the band structure
        band_structure = vasprun.get_band_structure(line_mode=True)
        k_points = [k.frac_coords for k in band_structure.kpoints]
        energies = band_structure.bands
        ek = list(energies.keys())
        for key in ek:
            if key == Spin.up:
                energies[1] = energies.pop(key)
            if key == Spin.down:
                energies[-1] = energies.pop(key)

        return band_structure, {"k_points": k_points, "energies": energies}
    except:
        return None


def get_band_gap(vasprun_xml_path):
    vasprun = Vasprun(vasprun_xml_path)
    band_structure = vasprun.get_band_structure()

    # Check if the material is a metal (no band gap)
    if band_structure.is_metal():
        return "Metallic character, no band gap"

    # Get band gap information
    gap_info = band_structure.get_band_gap()
    return gap_info


def plot_bands_structure(band_structure):
    plotter = BSPlotter(band_structure)
    plot = plotter.get_plot()
    plt.show()
    return plot

# vaspxml_path="/Users/voicutomut/Documents/GitHub/BespokeMaterials/DB/Databases/JARVIS/JARVIS2D/OPT-Bandst/JVASP-13600/vasprun.xml"
# band_structure, numerics =get_band_structure(vaspxml_path)
# print(band_structure)
# print(numerics )
# plot_bands_structure(band_structure)
# print(get_band_gap(vaspxml_path))
# # plot
# # import numpy as np
# # k_points=numerics["k_points"]
# # energies= numerics["energies"]
# # # Creating the plot
# # distances = [0]
# # for i in range(1, len(k_points)):
# #     # Calculate the distance between successive k-points
# #     distance = np.linalg.norm(k_points[i] - k_points[i-1])
# #     distances.append(distances[-1] + distance)
# #
# # print("energies:", energies)
# # ene=[b for b in  energies]
# # for b in  ene:
# #     bands=energies[b]
# #     for  b_ in bands:
# #         plt.plot(distances, b_)
# #
# # plt.xlabel("K-point Path")
# # plt.ylabel("Energy (eV)")
# # plt.title("Band Structure")
# # plt.show()