Skip to content

Commit 3ee6052

Browse files
committed
Adressing review comments: Improved error handling and fixing of small bugs
1 parent 41d27ff commit 3ee6052

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

src/aiida_common_workflows/workflows/em.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from aiida.engine import WorkChain, append_
77
from aiida.plugins import WorkflowFactory
88

9-
from aiida_common_workflows.workflows.relax.generator import ElectronicType, RelaxType, SpinType
9+
from aiida_common_workflows.workflows.relax.generator import ElectronicType, OptionalRelaxFeatures, RelaxType, SpinType
1010
from aiida_common_workflows.workflows.relax.workchain import CommonRelaxWorkChain
1111

1212

@@ -17,6 +17,12 @@ def validate_inputs(value, _):
1717
process_class = WorkflowFactory(value['sub_process_class'])
1818
generator = process_class.get_input_generator()
1919

20+
if not generator.supports_feature(OptionalRelaxFeatures.FIXED_MAGNETIZATION):
21+
return (
22+
f'The `{value["sub_process_class"]}` plugin does not support the '
23+
f'`{OptionalRelaxFeatures.FIXED_MAGNETIZATION}` optional feature required for this workflow.'
24+
)
25+
2026
try:
2127
generator.get_builder(structure=value['structure'], **value['generator_inputs'])
2228
except Exception as exc:
@@ -74,18 +80,14 @@ def define(cls, spec):
7480
help='The type of spin for the calculation.')
7581
spec.input('generator_inputs.electronic_type', valid_type=(ElectronicType, str), required=False, non_db=True,
7682
help='The type of electronics (insulator/metal) for the calculation.')
77-
spec.input(
78-
'generator_inputs.fixed_total_cell_magnetization', valid_type=(list, tuple),
79-
required=False, non_db=True,
80-
help='List containing the total magnetizations per cell to be calculated.'
81-
)
8283
spec.input('generator_inputs.threshold_forces', valid_type=float, required=False, non_db=True,
8384
help='Target threshold for the forces in eV/Å.')
8485
spec.input('generator_inputs.threshold_stress', valid_type=float, required=False, non_db=True,
8586
help='Target threshold for the stress in eV/Å^3.')
8687
spec.input_namespace('sub_process', dynamic=True, populate_defaults=False)
8788
spec.input('sub_process_class', non_db=True, validator=validate_sub_process_class)
8889
spec.inputs.validator = validate_inputs
90+
8991
spec.outline(
9092
cls.run_em,
9193
cls.inspect_em,

src/aiida_common_workflows/workflows/eos.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,6 @@ def validate_inputs(value, _):
1616
if 'scale_count' not in value or 'scale_increment' not in value:
1717
return 'neither `scale_factors` nor the pair of `scale_count` and `scale_increment` were defined.'
1818

19-
# Validate mutual exclusivity of magnetization inputs.
20-
if 'generator_inputs' in value:
21-
gen_inputs = value['generator_inputs']
22-
if (
23-
gen_inputs.get('magnetization_per_site') is not None
24-
and gen_inputs.get('fixed_total_cell_magnetization') is not None
25-
):
26-
return (
27-
'the inputs `generator_inputs.magnetization_per_site` and '
28-
'`generator_inputs.fixed_total_cell_magnetization` are mutually exclusive.'
29-
)
30-
3119
# Validate that the provided ``generator_inputs`` are valid for the associated input generator.
3220
process_class = WorkflowFactory(value['sub_process_class'])
3321
generator = process_class.get_input_generator()

src/aiida_common_workflows/workflows/relax/generator.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
__all__ = ('CommonRelaxInputGenerator',)
1212

1313

14+
def validate_inputs(value, _):
15+
"""Validate the entire input namespace."""
16+
# Validate mutual exclusivity of magnetization inputs.
17+
if value.get('magnetization_per_site') is not None and value.get('fixed_total_cell_magnetization') is not None:
18+
return 'the inputs `magnetization_per_site` and ' '`fixed_total_cell_magnetization` are mutually exclusive.'
19+
20+
1421
class OptionalRelaxFeatures(OptionalFeature):
1522
FIXED_MAGNETIZATION = 'fixed_total_cell_magnetization'
1623

@@ -129,3 +136,5 @@ def define(cls, spec):
129136
non_db=True,
130137
help='Options for the geometry optimization calculation jobs.',
131138
)
139+
140+
spec.inputs.validator = validate_inputs

0 commit comments

Comments
 (0)