Skip to content

Commit

Permalink
Rescale starting magnetization down to magnetic moments
Browse files Browse the repository at this point in the history
  • Loading branch information
edan-bainglass committed Dec 30, 2024
1 parent 338368d commit a327916
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ 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.
1) Total magnetization: Total majority spin charge - minority spin charge.
2) Magnetic moments: Starting spin polarization on atomic type 'i' in a spin polarized (LSDA or noncollinear/spin-orbit) calculation.
For Starting magnetization you can set each kind names defined in the StructureData (StructureData.get_kind_names())
For Magnetic moments you can set each kind names defined in the StructureData (StructureData.get_kind_names())
Usually these are the names of the elements in the StructureData
(For example 'C' , 'N' , 'Fe' . However the StructureData can have defined kinds like 'Fe1' and 'Fe2')
The widget generate a dictionary that can be used to set initial_magnetic_moments in the builder of PwBaseWorkChain
Expand Down Expand Up @@ -48,9 +48,7 @@ def render(self):
<div style="margin-bottom: 5px;">
<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.
Default magnetic moments correspond to theoretical values.
</div>
""")

Expand Down
16 changes: 11 additions & 5 deletions src/aiidalab_qe/app/configuration/advanced/magnetization/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MagnetizationConfigurationSettingsModel(
type_options = tl.List(
trait=tl.List(tl.Unicode()),
default_value=[
["Starting magnetization", "starting_magnetization"],
["Magnetic moments", "starting_magnetization"],
["Total magnetization", "tot_magnetization"],
],
)
Expand All @@ -47,10 +47,16 @@ def update(self, specific=""): # noqa: ARG002
self._defaults["moments"] = {}
else:
try:
self._defaults["moments"] = get_starting_magnetization(
self.input_structure,
fetch_pseudo_family_by_label(self.family),
)
family = fetch_pseudo_family_by_label(self.family)
initial_guess = get_starting_magnetization(self.input_structure, family)
self._defaults["moments"] = {
kind.name: round(
initial_guess[kind.name]
* family.get_pseudo(kind.symbol).z_valence,
3,
)
for kind in self.input_structure.kinds
}
except NotExistent:
self._defaults["moments"] = {
kind_name: 0.0
Expand Down
2 changes: 1 addition & 1 deletion src/aiidalab_qe/app/configuration/basic/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def render(self):
</p>
<p>
Please go to <b>Advanced settings</b> and override the default
values, specifying appropriate starting magnetization for each
values, specifying appropriate magnetic moments for each
species (e.g. with different signs for an antiferromagnetic
configuration).
</p>
Expand Down
6 changes: 4 additions & 2 deletions src/aiidalab_qe/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from aiida_pseudo.groups.family import PseudoPotentialFamily

from aiida import orm


Expand Down Expand Up @@ -32,6 +34,6 @@ def enable_pencil_decomposition(component):
component.settings = orm.Dict({"CMDLINE": ["-pd", ".true."]})


def fetch_pseudo_family_by_label(label):
def fetch_pseudo_family_by_label(label) -> PseudoPotentialFamily:
"""Fetch the pseudo family by label."""
return orm.Group.collection.get(label=label)
return orm.Group.collection.get(label=label) # type: ignore

0 comments on commit a327916

Please sign in to comment.