Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add layer of abstraction in Panel classes #945

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions src/aiidalab_qe/app/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@

from aiidalab_qe.app.parameters import DEFAULT_PARAMETERS
from aiidalab_qe.app.utils import get_entry_items
from aiidalab_qe.common.panel import SettingsModel, SettingsPanel
from aiidalab_qe.common.panel import (
ConfigurationSettingsModel,
ConfigurationSettingsPanel,
)
from aiidalab_widgets_base import WizardAppWidgetStep

from .advanced import AdvancedModel, AdvancedSettings
from .basic import WorkChainModel, WorkChainSettings
from .advanced import (
AdvancedConfigurationSettingsModel,
AdvancedConfigurationSettingsPanel,
)
from .basic import BasicConfigurationSettingsModel, BasicConfigurationSettingsPanel
from .model import ConfigurationStepModel

DEFAULT: dict = DEFAULT_PARAMETERS # type: ignore
Expand Down Expand Up @@ -56,12 +62,14 @@ def __init__(self, model: ConfigurationStepModel, **kwargs):
""",
)

workchain_model = WorkChainModel()
self.workchain_settings = WorkChainSettings(model=workchain_model)
workchain_model = BasicConfigurationSettingsModel()
self.workchain_settings = BasicConfigurationSettingsPanel(model=workchain_model)
self._model.add_model("workchain", workchain_model)

advanced_model = AdvancedModel()
self.advanced_settings = AdvancedSettings(model=advanced_model)
advanced_model = AdvancedConfigurationSettingsModel()
self.advanced_settings = AdvancedConfigurationSettingsPanel(
model=advanced_model
)
self._model.add_model("advanced", advanced_model)

self.settings = {
Expand All @@ -71,7 +79,7 @@ def __init__(self, model: ConfigurationStepModel, **kwargs):

self.property_children = []

self._fetch_plugin_settings()
self._fetch_plugin_calculation_settings()

def render(self):
if self.rendered:
Expand Down Expand Up @@ -178,7 +186,7 @@ def _on_previous_step_state_change(self, _):
def _on_tab_change(self, change):
if (tab_index := change["new"]) is None:
return
tab: SettingsPanel = self.tabs.children[tab_index] # type: ignore
tab: ConfigurationSettingsPanel = self.tabs.children[tab_index] # type: ignore
tab.render()
tab.update()

Expand Down Expand Up @@ -214,15 +222,16 @@ def _update_state(self, _=None):
else:
self.state = self.State.INIT

def _fetch_plugin_settings(self):
def _fetch_plugin_calculation_settings(self):
outlines = get_entry_items("aiidalab_qe.properties", "outline")
entries = get_entry_items("aiidalab_qe.properties", "setting")
for identifier, entry in entries.items():
entries = get_entry_items("aiidalab_qe.properties", "configuration")
for identifier, configuration in entries.items():
for key in ("panel", "model"):
if key not in entry:
if key not in configuration:
raise ValueError(f"Entry {identifier} is missing the '{key}' key")
panel = entry["panel"]
model: SettingsModel = entry["model"]()

panel = configuration["panel"]
model: ConfigurationSettingsModel = configuration["model"]()
self._model.add_model(identifier, model)

outline = outlines[identifier]()
Expand Down
8 changes: 4 additions & 4 deletions src/aiidalab_qe/app/configuration/advanced/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .advanced import AdvancedSettings
from .model import AdvancedModel
from .advanced import AdvancedConfigurationSettingsPanel
from .model import AdvancedConfigurationSettingsModel

__all__ = [
"AdvancedModel",
"AdvancedSettings",
"AdvancedConfigurationSettingsModel",
"AdvancedConfigurationSettingsPanel",
]
48 changes: 32 additions & 16 deletions src/aiidalab_qe/app/configuration/advanced/advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,34 @@

import ipywidgets as ipw

from aiidalab_qe.common.panel import SettingsPanel
from aiidalab_qe.common.panel import ConfigurationSettingsPanel

from .hubbard import HubbardModel, HubbardSettings
from .magnetization import MagnetizationModel, MagnetizationSettings
from .model import AdvancedModel
from .pseudos import PseudoSettings, PseudosModel
from .smearing import SmearingModel, SmearingSettings
from .hubbard import (
HubbardConfigurationSettingsModel,
HubbardConfigurationSettingsPanel,
)
from .magnetization import (
MagnetizationConfigurationSettingsModel,
MagnetizationConfigurationSettingsPanel,
)
from .model import AdvancedConfigurationSettingsModel
from .pseudos import (
PseudosConfigurationSettingsModel,
PseudosConfigurationSettingsPanel,
)
from .smearing import (
SmearingConfigurationSettingsModel,
SmearingConfigurationSettingsPanel,
)


class AdvancedSettings(SettingsPanel[AdvancedModel]):
class AdvancedConfigurationSettingsPanel(
ConfigurationSettingsPanel[AdvancedConfigurationSettingsModel],
):
title = "Advanced Settings"
identifier = "advanced"

def __init__(self, model: AdvancedModel, **kwargs):
def __init__(self, model: AdvancedConfigurationSettingsModel, **kwargs):
super().__init__(
model=model,
layout={"justify_content": "space-between", **kwargs.get("layout", {})},
Expand All @@ -42,20 +56,22 @@ def __init__(self, model: AdvancedModel, **kwargs):
"kpoints_distance",
)

smearing_model = SmearingModel()
self.smearing = SmearingSettings(model=smearing_model)
smearing_model = SmearingConfigurationSettingsModel()
self.smearing = SmearingConfigurationSettingsPanel(model=smearing_model)
model.add_model("smearing", smearing_model)

magnetization_model = MagnetizationModel()
self.magnetization = MagnetizationSettings(model=magnetization_model)
magnetization_model = MagnetizationConfigurationSettingsModel()
self.magnetization = MagnetizationConfigurationSettingsPanel(
model=magnetization_model,
)
model.add_model("magnetization", magnetization_model)

hubbard_model = HubbardModel()
self.hubbard = HubbardSettings(model=hubbard_model)
hubbard_model = HubbardConfigurationSettingsModel()
self.hubbard = HubbardConfigurationSettingsPanel(model=hubbard_model)
model.add_model("hubbard", hubbard_model)

pseudos_model = PseudosModel()
self.pseudos = PseudoSettings(model=pseudos_model)
pseudos_model = PseudosConfigurationSettingsModel()
self.pseudos = PseudosConfigurationSettingsPanel(model=pseudos_model)
model.add_model("pseudos", pseudos_model)

def render(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .hubbard import HubbardSettings
from .model import HubbardModel
from .hubbard import HubbardConfigurationSettingsPanel
from .model import HubbardConfigurationSettingsModel

__all__ = [
"HubbardSettings",
"HubbardModel",
"HubbardConfigurationSettingsModel",
"HubbardConfigurationSettingsPanel",
]
12 changes: 7 additions & 5 deletions src/aiidalab_qe/app/configuration/advanced/hubbard/hubbard.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import ipywidgets as ipw

from ..subsettings import AdvancedSubSettings
from .model import HubbardModel
from ..subsettings import AdvancedConfigurationSubSettingsPanel
from .model import HubbardConfigurationSettingsModel


class HubbardSettings(AdvancedSubSettings[HubbardModel]):
class HubbardConfigurationSettingsPanel(
AdvancedConfigurationSubSettingsPanel[HubbardConfigurationSettingsModel],
):
identifier = "hubbard"

def __init__(self, model: HubbardModel, **kwargs):
def __init__(self, model: HubbardConfigurationSettingsModel, **kwargs):
super().__init__(model, **kwargs)

self._model.observe(
Expand Down Expand Up @@ -100,7 +102,7 @@ def _update(self, specific=""):
if self.updated:
return
self._show_loading()
if not self._model.loaded_from_process or specific and specific != "widgets":
if not self._model.loaded_from_process or (specific and specific != "widgets"):
self._model.update(specific)
self._build_hubbard_widget()
self._toggle_hubbard_widget()
Expand Down
7 changes: 5 additions & 2 deletions src/aiidalab_qe/app/configuration/advanced/hubbard/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
from aiida_quantumespresso.data.hubbard_structure import HubbardStructureData
from aiidalab_qe.common.mixins import HasInputStructure

from ..subsettings import AdvancedSubModel
from ..subsettings import AdvancedCalculationSubSettingsModel


class HubbardModel(AdvancedSubModel, HasInputStructure):
class HubbardConfigurationSettingsModel(
AdvancedCalculationSubSettingsModel,
HasInputStructure,
):
dependencies = [
"input_structure",
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .magnetization import MagnetizationSettings
from .model import MagnetizationModel
from .magnetization import MagnetizationConfigurationSettingsPanel
from .model import MagnetizationConfigurationSettingsModel

__all__ = [
"MagnetizationModel",
"MagnetizationSettings",
"MagnetizationConfigurationSettingsModel",
"MagnetizationConfigurationSettingsPanel",
]
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import ipywidgets as ipw

from ..subsettings import AdvancedSubSettings
from .model import MagnetizationModel
from ..subsettings import AdvancedConfigurationSubSettingsPanel
from .model import MagnetizationConfigurationSettingsModel


class MagnetizationSettings(AdvancedSubSettings[MagnetizationModel]):
class MagnetizationConfigurationSettingsPanel(
AdvancedConfigurationSubSettingsPanel[MagnetizationConfigurationSettingsModel],
):
"""Widget to set the type of magnetization used in the calculation:
1) Tot_magnetization: Total majority spin charge - minority spin charge.
2) Starting magnetization: Starting spin polarization on atomic type 'i' in a spin polarized (LSDA or noncollinear/spin-orbit) calculation.
Expand All @@ -20,7 +22,7 @@ class MagnetizationSettings(AdvancedSubSettings[MagnetizationModel]):

identifier = "magnetization"

def __init__(self, model: MagnetizationModel, **kwargs):
def __init__(self, model: MagnetizationConfigurationSettingsModel, **kwargs):
super().__init__(model, **kwargs)

self._model.observe(
Expand Down Expand Up @@ -111,7 +113,7 @@ def _update(self, specific=""):
if self.updated:
return
self._show_loading()
if not self._model.loaded_from_process or specific and specific != "widgets":
if not self._model.loaded_from_process or (specific and specific != "widgets"):
self._model.update(specific)
self._build_kinds_widget()
self._switch_widgets()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

from aiidalab_qe.common.mixins import HasInputStructure

from ..subsettings import AdvancedSubModel
from ..subsettings import AdvancedCalculationSubSettingsModel


class MagnetizationModel(AdvancedSubModel, HasInputStructure):
class MagnetizationConfigurationSettingsModel(
AdvancedCalculationSubSettingsModel,
HasInputStructure,
):
dependencies = [
"input_structure",
"electronic_type",
Expand Down
Loading
Loading