Skip to content

Commit

Permalink
Implement warning for tagged magnetic structures
Browse files Browse the repository at this point in the history
  • Loading branch information
edan-bainglass committed Dec 29, 2024
1 parent ce93095 commit 4087452
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
34 changes: 34 additions & 0 deletions src/aiidalab_qe/app/configuration/basic/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def render(self):
(self._model, "spin_type"),
(self.spin_type, "value"),
)
self.spin_type.observe(
self._on_spin_type_change,
"value",
)

# Spin-Orbit calculation
self.spin_orbit = ipw.ToggleButtons(style={"description_width": "initial"})
Expand All @@ -68,6 +72,29 @@ def render(self):
(self.protocol, "value"),
)

self.warning = ipw.HTML(
value="""
<div
class="alert alert-warning"
style="line-height: 140%; margin: 10px 0 0"
>
<p>
<b>Warning:</b> detected multiples atoms with different tags.
You may be interested in an antiferromagnetic system. Note that
default starting magnetic moments do not distinguish tagged
atoms and are set to the same value.
</p>
<p>
Please go to <b>Advanced settings</b> and override the default
values, specifying appropriate starting magnetization for each
species (e.g. with different signs for an antiferromagnetic
configuration).
</p>
</div>
""",
layout=ipw.Layout(display="none"),
)

self.children = [
InAppGuide(identifier="basic-settings"),
ipw.HTML("""
Expand Down Expand Up @@ -140,9 +167,16 @@ def render(self):
(at the price of longer/costlier calculations).
</div>
"""),
self.warning,
]

self.rendered = True

def _on_input_structure_change(self, _):
self.refresh(specific="structure")

def _on_spin_type_change(self, _):
if self._model.spin_type == "collinear" and self._model.has_tags:
self.warning.layout.display = "flex"
else:
self.warning.layout.display = "none"
9 changes: 5 additions & 4 deletions src/aiidalab_qe/app/configuration/basic/model.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import traitlets as tl

from aiida import orm
from aiidalab_qe.app.parameters import DEFAULT_PARAMETERS
from aiidalab_qe.common.mixins import HasInputStructure
from aiidalab_qe.common.panel import ConfigurationSettingsModel

DEFAULT: dict = DEFAULT_PARAMETERS # type: ignore


class BasicConfigurationSettingsModel(ConfigurationSettingsModel):
class BasicConfigurationSettingsModel(
ConfigurationSettingsModel,
HasInputStructure,
):
title = "Basic settings"
identifier = "workchain"

dependencies = [
"input_structure",
]

input_structure = tl.Union([tl.Instance(orm.StructureData)], allow_none=True)

protocol_options = tl.List(
trait=tl.Tuple(tl.Unicode(), tl.Unicode()),
default_value=[
Expand Down
7 changes: 7 additions & 0 deletions src/aiidalab_qe/common/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ def has_structure(self):
def has_pbc(self):
return not self.has_structure or any(self.input_structure.pbc)

@property
def has_tags(self):
return any(
not kind_name.isalpha()
for kind_name in self.input_structure.get_kind_names()
)


class HasModels(t.Generic[T]):
def __init__(self):
Expand Down

0 comments on commit 4087452

Please sign in to comment.