Skip to content

Commit dbbd238

Browse files
committed
Fixes #236
1 parent 5b6b6b3 commit dbbd238

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

crystal_toolkit/components/transformations/grainboundary.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,12 @@ def options_layouts(self, state=None, structure=None):
5454
shape=(3,),
5555
)
5656

57-
rotation_angle = self.get_choice_input(
58-
label="Rotation angle",
59-
kwarg_label="rotation_angle",
60-
state=state,
61-
help_str="""Rotation angle to generate grain boundary. Options determined by
62-
your choice of Σ.""",
63-
)
64-
6557
# sigma isn't a direct input into the transformation, but has
6658
# to be calculated from the rotation_axis and structure
6759
_, sigma_options, _ = self._get_sigmas_options_and_ratio(
6860
structure, state.get("rotation_axis")
6961
)
62+
7063
sigma = dcc.Dropdown(
7164
id=self.id("sigma"),
7265
style={"width": "5rem"},
@@ -80,6 +73,19 @@ def options_layouts(self, state=None, structure=None):
8073
"input unit cell is denoted by sigma.",
8174
)
8275

76+
# likewise, rotation_angle is then a function of sigma, so
77+
# best determined using sigma to provide a default value:
78+
# this is initialized via a callback
79+
80+
rotation_angle = self.get_choice_input(
81+
label="Rotation angle",
82+
kwarg_label="rotation_angle",
83+
state=state, # starts as None
84+
help_str="""Rotation angle to generate grain boundary. Options determined by
85+
your choice of Σ.""",
86+
style={"width": "15rem"},
87+
)
88+
8389
expand_times = self.get_numerical_input(
8490
label="Expand times",
8591
kwarg_label="expand_times",
@@ -198,7 +204,7 @@ def _get_sigmas_options_and_ratio(structure, rotation_axis):
198204
cutoff=cutoff, r_axis=rotation_axis, ratio_alpha=ratio
199205
)
200206
else:
201-
return [], None
207+
return [], None, ratio
202208

203209
options = []
204210
subscript_unicode_map = {
@@ -248,7 +254,7 @@ def update_sigma_options(rotation_axis, structure):
248254
return sigma_options
249255

250256
@app.callback(
251-
Output(self.id("rotation_angle", is_kwarg=True), "options"),
257+
Output(self.id("rotation_angle", is_kwarg=True, hint="literal"), "options"),
252258
[
253259
Input(self.id("sigma"), "value"),
254260
Input(self.get_kwarg_id("rotation_axis"), "value"),
@@ -290,16 +296,20 @@ def update_rotation_angle_options(sigma, rotation_axis, structure):
290296
],
291297
)
292298
def update_default_value(options, enabled):
293-
if options is None:
299+
if not options:
294300
raise PreventUpdate
295301
return options[0]["value"], enabled
296302

297303
# TODO: make client-side callback, or just combine all callbacks here
298304
@app.callback(
299-
Output(self.id("rotation_angle", is_kwarg=True), "value"),
300-
[Input(self.id("rotation_angle", is_kwarg=True), "options")],
305+
Output(self.id("rotation_angle", is_kwarg=True, hint="literal"), "value"),
306+
[
307+
Input(
308+
self.id("rotation_angle", is_kwarg=True, hint="literal"), "options"
309+
)
310+
],
301311
)
302312
def update_default_value(options):
303-
if options is None:
313+
if not options:
304314
raise PreventUpdate
305315
return options[0]["value"]

0 commit comments

Comments
 (0)