Skip to content

Commit d4c1cea

Browse files
authored
Merge pull request #510 from esoteric-ephemera/maxph
Fix maximum size of phonon supercell in animation
2 parents 653865b + 0ef88c9 commit d4c1cea

7 files changed

Lines changed: 63 additions & 18 deletions

File tree

crystal_toolkit/apps/examples/tests/test_fermi_surface.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22

33
from typing import TYPE_CHECKING
44

5-
from crystal_toolkit.apps.examples.fermi_surface import app
5+
import pytest
6+
7+
try:
8+
from crystal_toolkit.apps.examples.fermi_surface import app
9+
except ImportError:
10+
pytest.skip(
11+
"IFermi either not installed or newer version of setuptools used.",
12+
allow_module_level=True,
13+
)
614

715
if TYPE_CHECKING:
816
from crystal_toolkit.apps.examples.tests.typing import DashDuo

crystal_toolkit/components/phonon.py

Lines changed: 49 additions & 12 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
@@ -38,6 +38,7 @@
3838
MARKER_SHAPE = "x"
3939
MAX_MAGNITUDE = 500
4040
MIN_MAGNITUDE = 0
41+
MAX_SUPERCELL_SITES = 500
4142

4243
DEFAULTS: 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

10521089
class PhononBandstructureAndDosPanelComponent(PanelComponent):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ requires-python = ">=3.10"
1111
authors = [{ name = "Matt Horton", email = "mkhorton@lbl.gov" }]
1212

1313
dependencies = [
14-
"dash-mp-components==0.5.1rc5",
14+
"dash-mp-components>=0.5.1rc5,<0.5.2",
1515
"dash>=2.11.0",
1616
"flask-caching",
1717
"frozendict",

requirements/ubuntu-latest_py3.11.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ cython==3.2.4
4444
# via boltztrap2
4545
dash==3.4.0
4646
# via crystal_toolkit (pyproject.toml)
47-
dash-mp-components==0.5.0rc0
47+
dash-mp-components==0.5.1rc5
4848
# via crystal_toolkit (pyproject.toml)
4949
decorator==5.2.1
5050
# via ipython

requirements/ubuntu-latest_py3.11_extras.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ dash[testing]==3.4.0
135135
# dash-vtk
136136
dash-extensions==2.0.4
137137
# via crystal_toolkit (pyproject.toml)
138-
dash-mp-components==0.5.0rc0
138+
dash-mp-components==0.5.1rc5
139139
# via crystal_toolkit (pyproject.toml)
140140
dash-testing-stub==0.0.2
141141
# via dash

requirements/ubuntu-latest_py3.12.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ cython==3.2.4
4444
# via boltztrap2
4545
dash==3.4.0
4646
# via crystal_toolkit (pyproject.toml)
47-
dash-mp-components==0.5.0rc0
47+
dash-mp-components==0.5.1rc5
4848
# via crystal_toolkit (pyproject.toml)
4949
decorator==5.2.1
5050
# via ipython

requirements/ubuntu-latest_py3.12_extras.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ dash[testing]==3.4.0
135135
# dash-vtk
136136
dash-extensions==2.0.4
137137
# via crystal_toolkit (pyproject.toml)
138-
dash-mp-components==0.5.0rc0
138+
dash-mp-components==0.5.1rc5
139139
# via crystal_toolkit (pyproject.toml)
140140
dash-testing-stub==0.0.2
141141
# via dash

0 commit comments

Comments
 (0)