Skip to content

Commit

Permalink
Use qe plugin utility to define default starting magnetization
Browse files Browse the repository at this point in the history
  • Loading branch information
edan-bainglass committed Dec 28, 2024
1 parent ea89e2f commit 7e73aea
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/aiidalab_qe/app/configuration/advanced/advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def __init__(self, model: AdvancedConfigurationSettingsModel, **kwargs):
"kpoints_distance",
)

# NOTE connect pseudos first, as some settings depend on it
pseudos_model = PseudosConfigurationSettingsModel()
self.pseudos = PseudosConfigurationSettingsPanel(model=pseudos_model)
model.add_model("pseudos", pseudos_model)

smearing_model = SmearingConfigurationSettingsModel()
self.smearing = SmearingConfigurationSettingsPanel(model=smearing_model)
model.add_model("smearing", smearing_model)
Expand All @@ -64,10 +69,6 @@ def __init__(self, model: AdvancedConfigurationSettingsModel, **kwargs):
self.hubbard = HubbardConfigurationSettingsPanel(model=hubbard_model)
model.add_model("hubbard", hubbard_model)

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

def render(self):
if self.rendered:
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ def render(self):
if self.rendered:
return

self.description = ipw.HTML("<b>Magnetization:</b>")
self.description = ipw.HTML("""
<div>
<b>Magnetization:</b>
<br>
The default starting magnetization is computed as the theoretical
magnetic moment scaled by the valence charge defined in the selected
pseudopotential family.
</div>
""")

self.magnetization_type = ipw.ToggleButtons(
style={
Expand Down
18 changes: 15 additions & 3 deletions src/aiidalab_qe/app/configuration/advanced/magnetization/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import traitlets as tl

from aiida.common.exceptions import NotExistent
from aiida_quantumespresso.workflows.protocols.utils import get_starting_magnetization
from aiidalab_qe.common.mixins import HasInputStructure
from aiidalab_qe.utils import fetch_pseudo_family_by_label

from ..subsettings import AdvancedCalculationSubSettingsModel

Expand All @@ -17,10 +20,12 @@ class MagnetizationConfigurationSettingsModel(
"input_structure",
"electronic_type",
"spin_type",
"pseudos.family",
]

electronic_type = tl.Unicode()
spin_type = tl.Unicode()
family = tl.Unicode()

type_options = tl.List(
trait=tl.List(tl.Unicode()),
Expand All @@ -41,9 +46,16 @@ def update(self, specific=""): # noqa: ARG002
if self.spin_type == "none" or not self.has_structure:
self._defaults["moments"] = {}
else:
self._defaults["moments"] = {
kind_name: 0.0 for kind_name in self.input_structure.get_kind_names()
}
try:
self._defaults["moments"] = get_starting_magnetization(
self.input_structure,
fetch_pseudo_family_by_label(self.family),
)
except NotExistent:
self._defaults["moments"] = {
kind_name: 0.0
for kind_name in self.input_structure.get_kind_names()
}
with self.hold_trait_notifications():
self.moments = self._get_default_moments()

Expand Down

0 comments on commit 7e73aea

Please sign in to comment.