Skip to content

Commit

Permalink
Bands align (#21)
Browse files Browse the repository at this point in the history
The workaround for the issue in osscar-org/widget-bandsplot#55 from the frontend, but it should be fixed from bandsplot widget side.
  • Loading branch information
unkcpz authored Mar 30, 2023
1 parent 6377fd8 commit 51119b4
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions aiidalab_sssp/inspect/subwidgets/bands.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
_RY_TO_EV = 13.6056980659
_FERMI_SHIFT = 10.0 # eV in protocol FIXME also change title of plot Tab widget

_SMEARING_WIDTH = _DEGAUSS * _RY_TO_EV


def _bandview(json_path):
"""
Expand Down Expand Up @@ -85,27 +87,41 @@ def _on_pseudo_select(self, _):
path = pseudo1["accuracy"]["bands"]["band_structure"]
json_path = Path.joinpath(SSSP_DB, path)

band = _bandview(json_path)
if band:
bands.append(band)
bandsdata_a = self.bands_align_to_fermi(_bandview(json_path))
bands.append(bandsdata_a)

if pseudo2:
path = pseudo2["accuracy"]["bands"]["band_structure"]
json_path = Path.joinpath(SSSP_DB, path)

band = _bandview(json_path)
if band:
bands.append(band)
bandsdata_b = self.bands_align_to_fermi(_bandview(json_path))
bands.append(bandsdata_b)

_band_structure_preview = BandsPlotWidget(
bands=bands,
energy_range={"ymin": -30.0, "ymax": 11.0},
energy_range={"ymin": -10.0, "ymax": 15.0},
fermi_energy=0.0, # since we have aligned to fermi level
)

with self.band_structure:
clear_output(wait=True)
display(_band_structure_preview)

def bands_align_to_fermi(self, bandsdata):
"""
align the band structure to fermi level
"""
fermi_energy = bandsdata["fermi_level"]

for path in bandsdata["paths"]:
values = [[y - fermi_energy for y in ys] for ys in path["values"]]
path["values"] = values

# After align to fermi level, we need to update the fermi level to 0.0
bandsdata["fermi_level"] = 0.0

return bandsdata


class BandChessboard(ipw.VBox):
"""Band distance compare in chess board"""
Expand Down Expand Up @@ -166,7 +182,7 @@ def _render_plot(ax_v, ax_c, arr_v, arr_c, labels):
for idx, (ax, arr, title) in enumerate(
[(ax_v, arr_v, r"$\eta_v$"), (ax_c, arr_c, r"$\eta_{10}$")]
):
ax.imshow(arr)
ax.imshow(arr, vmin=0, vmax=50, cmap="viridis")

# Show all ticks and label them with the respective list entries
# We want to show all ticks...
Expand Down Expand Up @@ -234,7 +250,7 @@ def _bands_distance(self, pseudos):
distance = get_bands_distance(
bandsdata_a=bandsdata1,
bandsdata_b=bandsdata2,
smearing=_DEGAUSS * _RY_TO_EV,
smearing=_SMEARING_WIDTH,
fermi_shift=fermi_shift,
do_smearing=do_smearing,
spin=spin,
Expand Down

0 comments on commit 51119b4

Please sign in to comment.