22import pathlib
33
44import anywidget
5- import traitlets
5+ import traitlets as tl
66
77from . import utils
88
@@ -16,17 +16,26 @@ class BZVisualizer(anywidget.AnyWidget):
1616 _esm = pathlib .Path (__file__ ).parent / "static" / "widget.js"
1717 _css = pathlib .Path (__file__ ).parent / "static" / "widget.css"
1818
19- seekpath_data = traitlets .Dict ({}).tag (sync = True )
19+ # primary input parameters, not directly used in the JS app
20+ cell = tl .List ().tag (sync = True )
21+ rel_coords = tl .List ().tag (sync = True )
22+ atom_numbers = tl .List ().tag (sync = True )
2023
21- # parameters passed to the js BZVisualizer
22- show_axes = traitlets .Bool (True ).tag (sync = True )
23- show_bvectors = traitlets .Bool (True ).tag (sync = True )
24- show_pathpoints = traitlets .Bool (False ).tag (sync = True )
25- disable_interact_overlay = traitlets .Bool (False ).tag (sync = True )
24+ # auxiliary traitlet to easily manage the previous ones
25+ system = tl .Dict ({}).tag (sync = True )
2626
27- # Parameters to control the size of the div-container
28- width = traitlets .Unicode ("100%" ).tag (sync = True )
29- height = traitlets .Unicode ("400px" ).tag (sync = True )
27+ # Data used in the JS app
28+ seekpath_data = tl .Dict ({}).tag (sync = True )
29+
30+ # optional parameters passed to the JS BZVisualizer
31+ show_axes = tl .Bool (True ).tag (sync = True )
32+ show_bvectors = tl .Bool (True ).tag (sync = True )
33+ show_pathpoints = tl .Bool (False ).tag (sync = True )
34+ disable_interact_overlay = tl .Bool (False ).tag (sync = True )
35+
36+ # parameters to control the size of the div-container
37+ width = tl .Unicode ("100%" ).tag (sync = True )
38+ height = tl .Unicode ("400px" ).tag (sync = True )
3039
3140 def __init__ (
3241 self ,
@@ -40,6 +49,14 @@ def __init__(
4049 The traitlets defined above can be set as a kwargs.
4150 """
4251 super ().__init__ (** kwargs )
43- self .seekpath_data = utils .get_seekpath_data_for_visualizer (
44- cell , rel_coords , atom_numbers
45- )
52+ self .system = {
53+ "cell" : cell ,
54+ "rel_coords" : rel_coords ,
55+ "atom_numbers" : atom_numbers ,
56+ }
57+ self .seekpath_data = utils .get_seekpath_data_for_visualizer (self .system )
58+
59+ @tl .observe ("cell" )
60+ def _cell_changed (self , change ):
61+ self .system [change ["name" ]] = change ["new" ]
62+ self .seekpath_data = utils .get_seekpath_data_for_visualizer (self .system )
0 commit comments