Skip to content

Commit 66c3ed2

Browse files
committed
Add fermi energy to outputs. This is necessary in order to calculate an effective magnetic field based on the difference between the fermi energy of the spin-up and spin-down channel
1 parent 3ee6052 commit 66c3ed2

File tree

4 files changed

+58
-13
lines changed

4 files changed

+58
-13
lines changed

docs/source/workflows/base/relax/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ Only ``structure`` and ``engines`` can be specified as a positional argument, al
171171
The default for this input is the Python value None and, in case of calculations with spin, the None value signals that the implementation should automatically decide an appropriate default initial magnetization.
172172
The implementation of such choice is code-dependent and described in the supplementary material of the `S. P. Huber et al., npj Comput. Mater. 7, 136 (2021)`_.
173173

174+
175+
* ``fixed_total_cell_magnetization``. (Type: Python None or a Python float).
176+
The total magnetization of the system for fixed spin moment calculations.
177+
Should be a float representing the total magnetization in Bohr magnetons (μB).
178+
174179
.. _relax-ref-wc:
175180

176181
* ``reference_workchain.`` (Type: a previously completed ``RelaxWorkChain``, performed with the same code as the ``RelaxWorkChain`` created by ``get_builder``).

src/aiida_common_workflows/workflows/em.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
"""Equation of state workflow that can use any code plugin implementing the common relax workflow."""
1+
"""Workflow to calculate the energy as a function of fixed total magnetization that can use any code
2+
plugin implementing the common relax workflow and supports fixed spin-moment calulations."""
23
import inspect
34

45
from aiida import orm
@@ -96,7 +97,21 @@ def define(cls, spec):
9697
spec.output_namespace('total_energies', valid_type=orm.Float,
9798
help='The computed total energy of the relaxed structures at each scaling factor.')
9899
spec.output_namespace('total_magnetizations', valid_type=orm.Float,
99-
help='The fixed total magnetizations that were evaluated.')
100+
help='The fixed total magnetizations that were evaluated in mu_B.')
101+
spec.output_namespace('fermi_energies_up', valid_type=orm.Float,
102+
help=(
103+
'The fermi energies of the spin-up channel (at each fixed total magnetization). '
104+
'Can be used to compute an effective magnetic field. Otherwise, only meaningful '
105+
'in combination with the BandsData that will be added in the future.'
106+
)
107+
)
108+
spec.output_namespace('fermi_energies_down', valid_type=orm.Float,
109+
help=(
110+
'The fermi energies of the spin-down channel (at each fixed total magnetization). '
111+
'Can be used to compute an effective magnetic field. Otherwise, only meaningful '
112+
'in combination with the BandsData that will be added in the future.'
113+
)
114+
)
100115
spec.exit_code(400, 'ERROR_SUB_PROCESS_FAILED',
101116
message='At least one of the `{cls}` sub processes did not finish successfully.')
102117

@@ -130,7 +145,12 @@ def inspect_em(self):
130145
energy = child.outputs.total_energy
131146
total_magnetization = child.outputs.total_magnetization
132147

148+
fermi_energy_up = child.outputs.fermi_energy_up
149+
fermi_energy_down = child.outputs.fermi_energy_down
150+
133151
self.report(f'Image {index}: total_magnetization={total_magnetization}, total energy={energy.value}')
134152

135153
self.out(f'total_energies.{index}', energy)
136154
self.out(f'total_magnetizations.{index}', total_magnetization)
155+
self.out(f'fermi_energies_up.{index}', fermi_energy_up)
156+
self.out(f'fermi_energies_down.{index}', fermi_energy_down)

src/aiida_common_workflows/workflows/relax/quantum_espresso/workchain.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
__all__ = ('QuantumEspressoCommonRelaxWorkChain',)
1111

12+
OPTIONAL_OUTPUT_PORTS = ['total_magnetization', 'fermi_energy', 'fermi_energy_up', 'fermi_energy_down']
13+
1214

1315
@calcfunction
1416
def extract_from_trajectory(trajectory):
@@ -30,12 +32,12 @@ def extract_from_trajectory(trajectory):
3032
def extract_from_parameters(parameters):
3133
"""Return the total energy and optionally the total magnetization from the given parameters node."""
3234
total_energy = parameters.base.attributes.get('energy')
33-
total_magnetization = parameters.base.attributes.get('total_magnetization', None)
3435

3536
results = {'total_energy': orm.Float(total_energy)}
3637

37-
if total_magnetization is not None:
38-
results['total_magnetization'] = orm.Float(total_magnetization)
38+
for output_name in OPTIONAL_OUTPUT_PORTS:
39+
if output_name in parameters.base.attributes:
40+
results[output_name] = orm.Float(parameters.base.attributes.get(output_name))
3941

4042
return results
4143

@@ -50,20 +52,18 @@ def convert_outputs(self):
5052
"""Convert the outputs of the sub workchain to the common output specification."""
5153
outputs = self.ctx.workchain.outputs
5254

53-
result = extract_from_parameters(outputs.output_parameters).values()
55+
results = extract_from_parameters(outputs.output_parameters)
5456
forces, stress = extract_from_trajectory(outputs.output_trajectory).values()
5557

56-
try:
57-
total_energy, total_magnetization = result
58-
except ValueError:
59-
total_energy, total_magnetization = next(iter(result)), None
58+
total_energy = results.get('total_energy')
6059

6160
if 'output_structure' in outputs:
6261
self.out('relaxed_structure', outputs.output_structure)
6362

64-
if total_magnetization is not None:
65-
self.out('total_magnetization', total_magnetization)
66-
6763
self.out('total_energy', total_energy)
6864
self.out('forces', forces)
6965
self.out('stress', stress)
66+
67+
for output_name in OPTIONAL_OUTPUT_PORTS:
68+
if output_name in results:
69+
self.out(output_name, results[output_name])

src/aiida_common_workflows/workflows/relax/workchain.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,26 @@ def define(cls, spec):
4848
help='All cell dimensions and atomic positions are in Ångstrom.')
4949
spec.output('total_energy', valid_type=Float, required=False,
5050
help='Total energy in eV.')
51+
spec.output('fermi_energy', valid_type=Float, required=False,
52+
help=(
53+
'Fermi energy in eV. The value is only present for non-magnetic '
54+
'or non-collinear magnetic calculations. In case of collinear '
55+
'magnetic calculations, the fermi energies for spin up and down '
56+
'are.'
57+
)
58+
)
59+
spec.output('fermi_energy_down', valid_type=Float, required=False,
60+
help=(
61+
'Fermi energy for spin down channel in eV. Only returned for '
62+
'collinear magnetic calculations.'
63+
)
64+
)
65+
spec.output('fermi_energy_up', valid_type=Float, required=False,
66+
help=(
67+
'Fermi energy for spin up channel in eV. Only returned for '
68+
'collinear magnetic calculations.'
69+
)
70+
)
5171
spec.output('total_magnetization', valid_type=Float, required=False,
5272
help='Total magnetization in Bohr magnetons.')
5373
spec.output('remote_folder', valid_type=RemoteData, required=False,

0 commit comments

Comments
 (0)