@@ -54,19 +54,12 @@ def options_layouts(self, state=None, structure=None):
54
54
shape = (3 ,),
55
55
)
56
56
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
-
65
57
# sigma isn't a direct input into the transformation, but has
66
58
# to be calculated from the rotation_axis and structure
67
59
_ , sigma_options , _ = self ._get_sigmas_options_and_ratio (
68
60
structure , state .get ("rotation_axis" )
69
61
)
62
+
70
63
sigma = dcc .Dropdown (
71
64
id = self .id ("sigma" ),
72
65
style = {"width" : "5rem" },
@@ -80,6 +73,19 @@ def options_layouts(self, state=None, structure=None):
80
73
"input unit cell is denoted by sigma." ,
81
74
)
82
75
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
+
83
89
expand_times = self .get_numerical_input (
84
90
label = "Expand times" ,
85
91
kwarg_label = "expand_times" ,
@@ -198,7 +204,7 @@ def _get_sigmas_options_and_ratio(structure, rotation_axis):
198
204
cutoff = cutoff , r_axis = rotation_axis , ratio_alpha = ratio
199
205
)
200
206
else :
201
- return [], None
207
+ return [], None , ratio
202
208
203
209
options = []
204
210
subscript_unicode_map = {
@@ -248,7 +254,7 @@ def update_sigma_options(rotation_axis, structure):
248
254
return sigma_options
249
255
250
256
@app .callback (
251
- Output (self .id ("rotation_angle" , is_kwarg = True ), "options" ),
257
+ Output (self .id ("rotation_angle" , is_kwarg = True , hint = "literal" ), "options" ),
252
258
[
253
259
Input (self .id ("sigma" ), "value" ),
254
260
Input (self .get_kwarg_id ("rotation_axis" ), "value" ),
@@ -290,16 +296,20 @@ def update_rotation_angle_options(sigma, rotation_axis, structure):
290
296
],
291
297
)
292
298
def update_default_value (options , enabled ):
293
- if options is None :
299
+ if not options :
294
300
raise PreventUpdate
295
301
return options [0 ]["value" ], enabled
296
302
297
303
# TODO: make client-side callback, or just combine all callbacks here
298
304
@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
+ ],
301
311
)
302
312
def update_default_value (options ):
303
- if options is None :
313
+ if not options :
304
314
raise PreventUpdate
305
315
return options [0 ]["value" ]
0 commit comments