99from dash import dcc , html
1010from dash .dependencies import Component , Input , Output , State
1111from dash .exceptions import PreventUpdate
12- from dash_mp_components import CrystalToolkitScene , PhononAnimationScene
12+ from dash_mp_components import CrystalToolkitScene , PhononAnimationScene , Tooltip
1313from emmet .core .phonon import PhononBS
1414
1515# crystal animation algo
3838MARKER_SHAPE = "x"
3939MAX_MAGNITUDE = 500
4040MIN_MAGNITUDE = 0
41+ MAX_SUPERCELL_SITES = 500
4142
4243DEFAULTS : dict [str , str | bool ] = {
4344 "color_scheme" : "VESTA" ,
@@ -63,11 +64,13 @@ def __init__(
6364 ) -> None :
6465 # this is a compound component, can be fed by mpid or
6566 # by the BandStructure itself
67+
6668 super ().__init__ (
6769 id = id ,
6870 default_data = {
6971 "mpid" : mpid ,
7072 "bandstructure_symm_line" : bandstructure_symm_line ,
73+ # "num_sites": bandstructure_symm_line.structure.num_sites,
7174 "density_of_states" : density_of_states ,
7275 },
7376 ** kwargs ,
@@ -207,8 +210,21 @@ def _sub_layouts(self) -> dict[str, Component]:
207210 html .Div (
208211 [
209212 hr ,
210- html .H6 (
211- "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+ ],
212228 style = {
213229 "textAlign" : "center" ,
214230 "marginBottom" : "0" ,
@@ -223,6 +239,7 @@ def _sub_layouts(self) -> dict[str, Component]:
223239 is_int = True ,
224240 label = "x" ,
225241 min = 1 ,
242+ max = 10 ,
226243 style = {"height" : "15px" },
227244 label_style = {"textAlign" : "center" },
228245 ),
@@ -233,6 +250,7 @@ def _sub_layouts(self) -> dict[str, Component]:
233250 is_int = True ,
234251 label = "y" ,
235252 min = 1 ,
253+ max = 10 ,
236254 style = {"height" : "15px" },
237255 label_style = {"textAlign" : "center" },
238256 ),
@@ -243,6 +261,7 @@ def _sub_layouts(self) -> dict[str, Component]:
243261 is_int = True ,
244262 label = "z" ,
245263 min = 1 ,
264+ max = 10 ,
246265 style = {"height" : "15px" },
247266 label_style = {"textAlign" : "center" },
248267 ),
@@ -943,6 +962,9 @@ def highlight_bz_on_hover_bs(hover_data, click_data, label_select):
943962 @app .callback (
944963 Output (self .id ("crystal-animation" ), "data" ),
945964 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" ),
946968 Input (self .id ("ph-bsdos-graph" ), "clickData" ),
947969 Input (self .id ("ph_bs" ), "data" ),
948970 Input (self .id ("supercell-controls-btn" ), "n_clicks" ),
@@ -985,6 +1007,9 @@ def update_crystal_animation(
9851007 struct = bs .structure
9861008 total_repeat_cell_cnt = 1
9871009
1010+ #
1011+ num_sites = struct .num_sites
1012+
9881013 # update structure if the controls got triggered
9891014 if sueprcell_update :
9901015 total_repeat_cell_cnt = scale_x * scale_y * scale_z
@@ -1038,15 +1063,27 @@ def update_crystal_animation(
10381063 MAX_MAGNITUDE - MIN_MAGNITUDE
10391064 ) * magnitude_fraction + MIN_MAGNITUDE
10401065
1041- return PhononBandstructureAndDosComponent ._get_time_function_json (
1042- ph_bs = bs ,
1043- json_data = json_data ,
1044- band = band_num ,
1045- qpoint = qpoint ,
1046- total_repeat_cell_cnt = total_repeat_cell_cnt ,
1047- magnitude = magnitude ,
1048- velocity = velocity ,
1049- ), [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+ )
10501087
10511088
10521089class PhononBandstructureAndDosPanelComponent (PanelComponent ):
0 commit comments