@@ -157,7 +157,7 @@ def change_supercell(_=None):
157
157
)
158
158
for elem in [self ._sc_x , self ._sc_y , self ._sc_z ]:
159
159
elem .observe (change_supercell , names = "value" )
160
- elem .observe (self ._estimate_supercells , names = "value" )
160
+ elem .observe (self ._activate_estimate_supercells , names = "value" )
161
161
162
162
self .supercell_selector = ipw .HBox (
163
163
children = [
@@ -179,7 +179,7 @@ def change_supercell(_=None):
179
179
self .supercell_hint_button = ipw .Button (
180
180
description = "Size hint" ,
181
181
disabled = False ,
182
- width = "100px" ,
182
+ layout = ipw . Layout ( width = "100px" ) ,
183
183
button_style = "info" ,
184
184
)
185
185
# supercell hint (15A lattice params)
@@ -195,11 +195,23 @@ def change_supercell(_=None):
195
195
# supercell reset reaction
196
196
self .supercell_reset_button .on_click (self ._reset_supercell )
197
197
198
+ # Estimate supercell button
199
+ self .supercell_estimate_button = ipw .Button (
200
+ description = "Estimate number of supercells ➡" ,
201
+ disabled = False ,
202
+ layout = ipw .Layout (width = "240px" , display = "none" ),
203
+ button_style = "info" ,
204
+ tooltip = "Number of supercells for phonons calculations;\n warning: for large systems, this may take some time." ,
205
+ )
206
+ # supercell reset reaction
207
+ self .supercell_estimate_button .on_click (self ._estimate_supercells )
208
+
198
209
# Estimate the number of supercells for frozen phonons.
199
210
self .supercell_number_estimator = ipw .HTML (
200
- description = "Number of supercells to be computed :" ,
201
- value = "0 " ,
211
+ # description="Number of supercells:",
212
+ value = "? " ,
202
213
style = {"description_width" : "initial" },
214
+ layout = ipw .Layout (display = "none" ),
203
215
)
204
216
205
217
## end supercell hint.
@@ -212,6 +224,7 @@ def change_supercell(_=None):
212
224
self .supercell_selector ,
213
225
self .supercell_hint_button ,
214
226
self .supercell_reset_button ,
227
+ self .supercell_estimate_button , # I do it on request, as it can take long time.
215
228
self .supercell_number_estimator ,
216
229
],
217
230
),
@@ -229,19 +242,17 @@ def change_supercell(_=None):
229
242
style = {"description_width" : "initial" },
230
243
layout = {"width" : "300px" },
231
244
)
232
- self .symmetry_symprec .observe (self ._estimate_supercells , "value" )
245
+ self .symmetry_symprec .observe (self ._activate_estimate_supercells , "value" )
233
246
234
247
# reset supercell
235
248
self .symmetry_symprec_reset_button = ipw .Button (
236
249
description = "Reset symprec" ,
237
250
disabled = False ,
238
- layout = ipw .Layout (width = "150px " ),
251
+ layout = ipw .Layout (width = "125px " ),
239
252
button_style = "warning" ,
240
253
)
241
254
# supercell reset reaction
242
- self .symmetry_symprec_reset_button .on_click (
243
- lambda _ : setattr (self .symmetry_symprec , "value" , 1e-5 )
244
- )
255
+ self .symmetry_symprec_reset_button .on_click (self ._reset_symprec )
245
256
246
257
self .children = [
247
258
ipw .VBox (
@@ -285,13 +296,23 @@ def change_supercell(_=None):
285
296
286
297
@tl .observe ("input_structure" )
287
298
def _update_input_structure (self , change ):
288
- if self .input_structure is not None :
299
+ if self .input_structure :
289
300
for direction , periodic in zip (
290
301
[self ._sc_x , self ._sc_y , self ._sc_z ], self .input_structure .pbc
291
302
):
292
303
direction .value = 2 if periodic else 1
293
304
direction .disabled = False if periodic else True
294
305
306
+ self .supercell_number_estimator .layout .display = (
307
+ "block" if len (self .input_structure .sites ) <= 30 else "none"
308
+ )
309
+ self .supercell_estimate_button .layout .display = (
310
+ "block" if len (self .input_structure .sites ) <= 30 else "none"
311
+ )
312
+ else :
313
+ self .supercell_number_estimator .layout .display = "none"
314
+ self .supercell_estimate_button .layout .display = "none"
315
+
295
316
def _display_supercell (self , change ):
296
317
selected = change ["new" ]
297
318
if selected in [1 , 3 ]:
@@ -308,19 +329,23 @@ def _suggest_supercell(self, _=None):
308
329
suggested_3D = 15 // np .array (s .cell .cellpar ()[:3 ]) + 1
309
330
310
331
# if disabled, it means that it is a non-periodic direction.
311
- # here we manually unobserve the `_estimate_supercells `, so it is faster
332
+ # here we manually unobserve the `_activate_estimate_supercells `, so it is faster
312
333
# and only compute when all the three directions are updated
313
334
self .block = True
314
335
for direction , suggested , original in zip (
315
336
[self ._sc_x , self ._sc_y , self ._sc_z ], suggested_3D , s .cell .cellpar ()[:3 ]
316
337
):
317
338
direction .value = suggested if not direction .disabled else 1
318
339
self .block = False
319
- self ._estimate_supercells ()
340
+ self ._activate_estimate_supercells ()
320
341
else :
321
342
return
322
343
323
- @tl .observe ("input_structure" )
344
+ def _activate_estimate_supercells (self , _ = None ):
345
+ self .supercell_estimate_button .disabled = False
346
+ self .supercell_number_estimator .value = "?"
347
+
348
+ # @tl.observe("input_structure")
324
349
@disable_print
325
350
def _estimate_supercells (self , _ = None ):
326
351
"""_summary_
@@ -372,6 +397,7 @@ def _estimate_supercells(self, _=None):
372
397
supercells = preprocess_data.get_supercells_with_displacements()
373
398
"""
374
399
self .supercell_number_estimator .value = f"{ len (supercells )} "
400
+ self .supercell_estimate_button .disabled = True
375
401
376
402
return
377
403
@@ -385,7 +411,12 @@ def _reset_supercell(self, _=None):
385
411
reset_supercell .append (2 if periodic else 1 )
386
412
(self ._sc_x .value , self ._sc_y .value , self ._sc_z .value ) = reset_supercell
387
413
self .block = False
388
- self ._estimate_supercells ()
414
+ self ._activate_estimate_supercells ()
415
+ return
416
+
417
+ def _reset_symprec (self , _ = None ):
418
+ self .symmetry_symprec .value = 1e-5
419
+ self ._activate_estimate_supercells ()
389
420
return
390
421
391
422
def get_panel_value (self ):
0 commit comments