diff --git a/src/aiidalab_qe_vibroscopy/app/model.py b/src/aiidalab_qe_vibroscopy/app/model.py index b1aa45e..a200736 100644 --- a/src/aiidalab_qe_vibroscopy/app/model.py +++ b/src/aiidalab_qe_vibroscopy/app/model.py @@ -26,6 +26,12 @@ class VibroConfigurationSettingsModel(ConfigurationSettingsModel, HasInputStruct supercell_y = tl.Int(2) supercell_z = tl.Int(2) + #Control for disable the supercell widget + + disable_x = tl.Bool(False) + disable_y = tl.Bool(False) + disable_z = tl.Bool(False) + supercell = tl.List( trait=tl.Int(), default_value=[2, 2, 2], @@ -33,3 +39,28 @@ class VibroConfigurationSettingsModel(ConfigurationSettingsModel, HasInputStruct def _get_default(self, trait): return self._defaults.get(trait, self.traits()[trait].default_value) + + def on_input_structure_change(self, _=None): + + if not self.input_structure: + self._get_default() + + else: + + self.disable_x, self.disable_y, self.disable_z = True, True, True + pbc = self.input_structure.pbc + + if pbc == (False,False, False): + # No periodicity; fully disable and reset supercell + self.supercell_x = self.supercell_y = self.supercell_z = 1 + elif pbc == (True, False, False): + self.supercell_y = self.supercell_z = 1 + self.disable_x = False + elif pbc == (True, True, False): + self.supercell_z = 1 + self.disable_x = self.disable_y = False + elif pbc == (True, True, True): + self.disable_x = self.disable_y = self.disable_z = False + + + self.supercell = [self.supercell_x, self.supercell_y, self.supercell_z] diff --git a/src/aiidalab_qe_vibroscopy/app/settings.py b/src/aiidalab_qe_vibroscopy/app/settings.py index ca61136..52039e5 100644 --- a/src/aiidalab_qe_vibroscopy/app/settings.py +++ b/src/aiidalab_qe_vibroscopy/app/settings.py @@ -72,11 +72,14 @@ class VibroConfigurationSettingPanel( title = "Vibrational Settings" identifier = "vibronic" - # input_structure = tl.Instance(orm.StructureData, allow_none=True) - def __init__(self, model: VibroConfigurationSettingsModel, **kwargs): super().__init__(model, **kwargs) + self._model.observe( + self._on_input_structure_change, + "input_structure", + ) + def render(self): if self.rendered: return @@ -158,14 +161,26 @@ def render(self): (self._model, "supercell_x"), (self.supercell_x, "value"), ) + ipw.link( + (self._model, "disable_x"), + (self.supercell_x, "disabled"), + ) ipw.link( (self._model, "supercell_y"), (self.supercell_y, "value"), ) + ipw.link( + (self._model, "disable_y"), + (self.supercell_y, "disabled"), + ) ipw.link( (self._model, "supercell_z"), (self.supercell_z, "value"), ) + ipw.link( + (self._model, "disable_z"), + (self.supercell_z, "disabled"), + ) # self.simulation_type.observe(self._display_supercell, names="value") # self.supercell = [2, 2, 2] @@ -318,6 +333,11 @@ def render(self): self.rendered = True + def _on_input_structure_change(self, _): + self.refresh(specific="structure") + self._model.on_input_structure_change() + + # we define a block for the estimation of the supercell if we ask for hint, # so that we call the estimator only at the end of the supercell hint generator, # and now each time after the x, y, z generation (i.e., we don't lose time).