Skip to content

Commit

Permalink
control of supercell with pbc
Browse files Browse the repository at this point in the history
  • Loading branch information
AndresOrtegaGuerrero committed Nov 29, 2024
1 parent 8d171b0 commit 6ec5f94
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
31 changes: 31 additions & 0 deletions src/aiidalab_qe_vibroscopy/app/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,41 @@ 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],
)

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]
24 changes: 22 additions & 2 deletions src/aiidalab_qe_vibroscopy/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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).
Expand Down

0 comments on commit 6ec5f94

Please sign in to comment.