Skip to content

Commit a8b668e

Browse files
committed
correct callbacks and add tooltip in control panel
1 parent af66e62 commit a8b668e

1 file changed

Lines changed: 48 additions & 27 deletions

File tree

crystal_toolkit/components/phonon.py

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from dash import dcc, html
1010
from dash.dependencies import Component, Input, Output, State
1111
from dash.exceptions import PreventUpdate
12-
from dash_mp_components import CrystalToolkitScene, PhononAnimationScene
12+
from dash_mp_components import CrystalToolkitScene, PhononAnimationScene, Tooltip
1313
from emmet.core.phonon import PhononBS
1414

1515
# crystal animation algo
@@ -64,12 +64,13 @@ def __init__(
6464
) -> None:
6565
# this is a compound component, can be fed by mpid or
6666
# by the BandStructure itself
67+
6768
super().__init__(
6869
id=id,
6970
default_data={
7071
"mpid": mpid,
7172
"bandstructure_symm_line": bandstructure_symm_line,
72-
"num_sites": density_of_states.structure.num_sites,
73+
# "num_sites": bandstructure_symm_line.structure.num_sites,
7374
"density_of_states": density_of_states,
7475
},
7576
**kwargs,
@@ -104,17 +105,6 @@ def _sub_layouts(self) -> dict[str, Component]:
104105
# on-the-fly only supported for bandstructures retrieved from MP
105106
show_path_options = bool(self.initial_data["default"]["mpid"])
106107

107-
# set maximum scale for supercell to limit size
108-
max_sc_scale = max(
109-
1,
110-
int(
111-
np.floor(
112-
(MAX_SUPERCELL_SITES / self.initial_data["default"]["num_sites"])
113-
** (1 / 3)
114-
)
115-
),
116-
)
117-
118108
options = [
119109
{"label": "Latimer-Munro", "value": "lm"},
120110
{"label": "Hinuma et al.", "value": "hin"},
@@ -220,8 +210,21 @@ def _sub_layouts(self) -> dict[str, Component]:
220210
html.Div(
221211
[
222212
hr,
223-
html.H6(
224-
"Supercell modification",
213+
html.Div(
214+
[
215+
html.H6(
216+
"Supercell modification",
217+
**{"data-tip": True},
218+
className="tooltip-label",
219+
style={
220+
"textAlign": "center",
221+
"marginBottom": "0",
222+
},
223+
),
224+
Tooltip(
225+
"Scaling limited for performance optimization."
226+
),
227+
],
225228
style={
226229
"textAlign": "center",
227230
"marginBottom": "0",
@@ -236,7 +239,7 @@ def _sub_layouts(self) -> dict[str, Component]:
236239
is_int=True,
237240
label="x",
238241
min=1,
239-
max=max_sc_scale,
242+
max=10,
240243
style={"height": "15px"},
241244
label_style={"textAlign": "center"},
242245
),
@@ -247,7 +250,7 @@ def _sub_layouts(self) -> dict[str, Component]:
247250
is_int=True,
248251
label="y",
249252
min=1,
250-
max=max_sc_scale,
253+
max=10,
251254
style={"height": "15px"},
252255
label_style={"textAlign": "center"},
253256
),
@@ -258,7 +261,7 @@ def _sub_layouts(self) -> dict[str, Component]:
258261
is_int=True,
259262
label="z",
260263
min=1,
261-
max=max_sc_scale,
264+
max=10,
262265
style={"height": "15px"},
263266
label_style={"textAlign": "center"},
264267
),
@@ -959,6 +962,9 @@ def highlight_bz_on_hover_bs(hover_data, click_data, label_select):
959962
@app.callback(
960963
Output(self.id("crystal-animation"), "data"),
961964
Output(self.id("crystal-animation"), "children"),
965+
Output(self.get_kwarg_id("scale-x"), "max"),
966+
Output(self.get_kwarg_id("scale-y"), "max"),
967+
Output(self.get_kwarg_id("scale-z"), "max"),
962968
Input(self.id("ph-bsdos-graph"), "clickData"),
963969
Input(self.id("ph_bs"), "data"),
964970
Input(self.id("supercell-controls-btn"), "n_clicks"),
@@ -1001,6 +1007,9 @@ def update_crystal_animation(
10011007
struct = bs.structure
10021008
total_repeat_cell_cnt = 1
10031009

1010+
#
1011+
num_sites = struct.num_sites
1012+
10041013
# update structure if the controls got triggered
10051014
if sueprcell_update:
10061015
total_repeat_cell_cnt = scale_x * scale_y * scale_z
@@ -1054,15 +1063,27 @@ def update_crystal_animation(
10541063
MAX_MAGNITUDE - MIN_MAGNITUDE
10551064
) * magnitude_fraction + MIN_MAGNITUDE
10561065

1057-
return PhononBandstructureAndDosComponent._get_time_function_json(
1058-
ph_bs=bs,
1059-
json_data=json_data,
1060-
band=band_num,
1061-
qpoint=qpoint,
1062-
total_repeat_cell_cnt=total_repeat_cell_cnt,
1063-
magnitude=magnitude,
1064-
velocity=velocity,
1065-
), [None, legend_layout]
1066+
# set maximum scale for supercell to limit size
1067+
max_sc_scale = max(
1068+
1,
1069+
int(np.floor((MAX_SUPERCELL_SITES / num_sites) ** (1 / 3))),
1070+
)
1071+
1072+
return (
1073+
PhononBandstructureAndDosComponent._get_time_function_json(
1074+
ph_bs=bs,
1075+
json_data=json_data,
1076+
band=band_num,
1077+
qpoint=qpoint,
1078+
total_repeat_cell_cnt=total_repeat_cell_cnt,
1079+
magnitude=magnitude,
1080+
velocity=velocity,
1081+
),
1082+
[None, legend_layout],
1083+
[max_sc_scale],
1084+
[max_sc_scale],
1085+
[max_sc_scale],
1086+
)
10661087

10671088

10681089
class PhononBandstructureAndDosPanelComponent(PanelComponent):

0 commit comments

Comments
 (0)