From ecd84e0dea9b6da91bda358bc1f917f891013481 Mon Sep 17 00:00:00 2001 From: t-reents Date: Thu, 9 Sep 2021 13:41:07 +0200 Subject: [PATCH 01/15] Adjust dos and projwfc inputs --- src/aiida_quantumespresso/workflows/pdos.py | 48 ++++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/src/aiida_quantumespresso/workflows/pdos.py b/src/aiida_quantumespresso/workflows/pdos.py index 888379f63..ef6b779f2 100644 --- a/src/aiida_quantumespresso/workflows/pdos.py +++ b/src/aiida_quantumespresso/workflows/pdos.py @@ -113,10 +113,13 @@ def validate_inputs(value, _): if value['dos']['parameters']['DOS'].get(par, None) != value['projwfc']['parameters']['PROJWFC'].get(par, None): return f'The `{par}`` parameter has to be equal for the `dos` and `projwfc` inputs.' - if value.get('align_to_fermi', False): + if value.get('fermi_energy_range', False): for par in ['Emin', 'Emax']: - if value['dos']['parameters']['DOS'].get(par, None) is None: - return f'The `{par}`` parameter must be set in case `align_to_fermi` is set to `True`.' + if value['dos']['parameters']['DOS'].get(par, None): + return ( + f'The `{par}`` parameter and fermi_energy_range were specified.' + 'The value in fermi_energy_range will be used.' + ) def validate_scf(value, _): @@ -217,14 +220,15 @@ def define(cls, spec): help='Terminate workchain steps before submitting calculations (test purposes only).' ) spec.input( - 'align_to_fermi', - valid_type=orm.Bool, + 'fermi_energy_range', + valid_type=orm.List, + required=False, serializer=to_aiida_type, - default=lambda: orm.Bool(False), + default=lambda: orm.List(list=[]), help=( - 'If true, Emin=>Emin-Efermi & Emax=>Emax-Efermi, where Efermi is taken from the `nscf` calculation. ' - 'Note that it only makes sense to align `Emax` and `Emin` to the fermi level in case they are actually ' - 'provided by in the `dos` and `projwfc` inputs, since otherwise the ' + 'Energy range around the Fermi level that should be covered in DOS and PROJWFC calculation.' + 'If not specified and Emin and Emax are specified in the in put parameters, these values will be used.' + 'Otherwise the default values are extracted from the NSCF calculation.' ) ) spec.expose_inputs( @@ -465,10 +469,16 @@ def _generate_dos_inputs(self): dos_inputs = AttributeDict(self.exposed_inputs(DosCalculation, 'dos')) dos_inputs.parent_folder = self.ctx.nscf_parent_folder dos_parameters = self.inputs.dos.parameters.get_dict() + fermi_energy_range = self.inputs.fermi_energy_range - if dos_parameters.pop('align_to_fermi', False): - dos_parameters['DOS']['Emin'] = dos_parameters['Emin'] + self.ctx.nscf_fermi - dos_parameters['DOS']['Emax'] = dos_parameters['Emax'] + self.ctx.nscf_fermi + if fermi_energy_range: + dos_parameters['DOS']['Emin'] = fermi_energy_range[0] + self.ctx.nscf_fermi + dos_parameters['DOS']['Emax'] = fermi_energy_range[1] + self.ctx.nscf_fermi + elif 'Emin' in dos_parameters['DOS'] and 'Emax' in dos_parameters['DOS']: + pass + else: + dos_parameters['DOS']['Emin'] = self.ctx.nscf_emin + dos_parameters['DOS']['Emax'] = self.ctx.nscf_emax dos_inputs.parameters = orm.Dict(dos_parameters) dos_inputs['metadata']['call_link_label'] = 'dos' @@ -479,10 +489,16 @@ def _generate_projwfc_inputs(self): projwfc_inputs = AttributeDict(self.exposed_inputs(ProjwfcCalculation, 'projwfc')) projwfc_inputs.parent_folder = self.ctx.nscf_parent_folder projwfc_parameters = self.inputs.projwfc.parameters.get_dict() - - if projwfc_parameters.pop('align_to_fermi', False): - projwfc_parameters['PROJWFC']['Emin'] = projwfc_parameters['Emin'] + self.ctx.nscf_fermi - projwfc_parameters['PROJWFC']['Emax'] = projwfc_parameters['Emax'] + self.ctx.nscf_fermi + fermi_energy_range = self.inputs.fermi_energy_range + + if fermi_energy_range: + projwfc_parameters['DOS']['Emin'] = fermi_energy_range[0] + self.ctx.nscf_fermi + projwfc_parameters['DOS']['Emax'] = fermi_energy_range[1] + self.ctx.nscf_fermi + elif 'Emin' in projwfc_parameters['DOS'] and 'Emax' in projwfc_parameters['DOS']: + pass + else: + projwfc_parameters['DOS']['Emin'] = self.ctx.nscf_emin + projwfc_parameters['DOS']['Emax'] = self.ctx.nscf_emax projwfc_inputs.parameters = orm.Dict(projwfc_parameters) projwfc_inputs['metadata']['call_link_label'] = 'projwfc' From 77560452eacac77620871fb49f57545a78093069 Mon Sep 17 00:00:00 2001 From: t-reents Date: Wed, 8 Dec 2021 11:41:31 +0100 Subject: [PATCH 02/15] fix projwfc inputs --- src/aiida_quantumespresso/workflows/pdos.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/aiida_quantumespresso/workflows/pdos.py b/src/aiida_quantumespresso/workflows/pdos.py index ef6b779f2..01513552c 100644 --- a/src/aiida_quantumespresso/workflows/pdos.py +++ b/src/aiida_quantumespresso/workflows/pdos.py @@ -116,7 +116,7 @@ def validate_inputs(value, _): if value.get('fermi_energy_range', False): for par in ['Emin', 'Emax']: if value['dos']['parameters']['DOS'].get(par, None): - return ( + warnings.warn( f'The `{par}`` parameter and fermi_energy_range were specified.' 'The value in fermi_energy_range will be used.' ) @@ -492,13 +492,13 @@ def _generate_projwfc_inputs(self): fermi_energy_range = self.inputs.fermi_energy_range if fermi_energy_range: - projwfc_parameters['DOS']['Emin'] = fermi_energy_range[0] + self.ctx.nscf_fermi - projwfc_parameters['DOS']['Emax'] = fermi_energy_range[1] + self.ctx.nscf_fermi - elif 'Emin' in projwfc_parameters['DOS'] and 'Emax' in projwfc_parameters['DOS']: + projwfc_parameters['PROJWFC']['Emin'] = fermi_energy_range[0] + self.ctx.nscf_fermi + projwfc_parameters['PROJWFC']['Emax'] = fermi_energy_range[1] + self.ctx.nscf_fermi + elif 'Emin' in projwfc_parameters['PROJWFC'] and 'Emax' in projwfc_parameters['PROJWFC']: pass else: - projwfc_parameters['DOS']['Emin'] = self.ctx.nscf_emin - projwfc_parameters['DOS']['Emax'] = self.ctx.nscf_emax + projwfc_parameters['PROJWFC']['Emin'] = self.ctx.nscf_emin + projwfc_parameters['PROJWFC']['Emax'] = self.ctx.nscf_emax projwfc_inputs.parameters = orm.Dict(projwfc_parameters) projwfc_inputs['metadata']['call_link_label'] = 'projwfc' From b6a422b6e4a8bdc5c90cfab6743b6cb562bba950 Mon Sep 17 00:00:00 2001 From: t-reents <77727843+t-reents@users.noreply.github.com> Date: Mon, 27 Dec 2021 13:15:21 +0100 Subject: [PATCH 03/15] fix input help --- src/aiida_quantumespresso/workflows/pdos.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/aiida_quantumespresso/workflows/pdos.py b/src/aiida_quantumespresso/workflows/pdos.py index 01513552c..dedae6d8d 100644 --- a/src/aiida_quantumespresso/workflows/pdos.py +++ b/src/aiida_quantumespresso/workflows/pdos.py @@ -227,8 +227,8 @@ def define(cls, spec): default=lambda: orm.List(list=[]), help=( 'Energy range around the Fermi level that should be covered in DOS and PROJWFC calculation.' - 'If not specified and Emin and Emax are specified in the in put parameters, these values will be used.' - 'Otherwise the default values are extracted from the NSCF calculation.' + 'If not specified but Emin and Emax are specified in the input parameters, these values will be used.' + 'Otherwise, the default values are extracted from the NSCF calculation.' ) ) spec.expose_inputs( From 58137acc05808dff93ee7faa808d861aef0d6098 Mon Sep 17 00:00:00 2001 From: t-reents <77727843+t-reents@users.noreply.github.com> Date: Thu, 30 Dec 2021 09:54:09 +0100 Subject: [PATCH 04/15] Update aiida_quantumespresso/workflows/pdos.py Co-authored-by: Sebastiaan Huber --- src/aiida_quantumespresso/workflows/pdos.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/aiida_quantumespresso/workflows/pdos.py b/src/aiida_quantumespresso/workflows/pdos.py index dedae6d8d..a55709092 100644 --- a/src/aiida_quantumespresso/workflows/pdos.py +++ b/src/aiida_quantumespresso/workflows/pdos.py @@ -474,11 +474,9 @@ def _generate_dos_inputs(self): if fermi_energy_range: dos_parameters['DOS']['Emin'] = fermi_energy_range[0] + self.ctx.nscf_fermi dos_parameters['DOS']['Emax'] = fermi_energy_range[1] + self.ctx.nscf_fermi - elif 'Emin' in dos_parameters['DOS'] and 'Emax' in dos_parameters['DOS']: - pass else: - dos_parameters['DOS']['Emin'] = self.ctx.nscf_emin - dos_parameters['DOS']['Emax'] = self.ctx.nscf_emax + dos_parameters['DOS'].setdefault('Emin', self.ctx.nscf_emin) + dos_parameters['DOS'].setdefault('Emax', self.ctx.nscf_emax) dos_inputs.parameters = orm.Dict(dos_parameters) dos_inputs['metadata']['call_link_label'] = 'dos' From 4b951527e7d4a10b2c8cd1f7618508088d971e0b Mon Sep 17 00:00:00 2001 From: Timo Reents Date: Thu, 30 Dec 2021 20:25:41 +0100 Subject: [PATCH 05/15] add validator and small changes --- src/aiida_quantumespresso/workflows/pdos.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/aiida_quantumespresso/workflows/pdos.py b/src/aiida_quantumespresso/workflows/pdos.py index a55709092..d53fa3bf8 100644 --- a/src/aiida_quantumespresso/workflows/pdos.py +++ b/src/aiida_quantumespresso/workflows/pdos.py @@ -160,6 +160,17 @@ def validate_projwfc(value, _): jsonschema.validate(value['parameters'].get_dict()['PROJWFC'], get_parameter_schema()) +def validate_fermi_energy_range(value): + """Validate specified fermi_energy_range. + + - List needs to consist of two float values. + """ + if len(value) != 2: + return 'List needs to consist of two values.' + if not all(isinstance(val, float) for val in value): + return 'Fermi energy range needs to be specified as floats.' + + def clean_calcjob_remote(node): """Clean the remote directory of a ``CalcJobNode``.""" cleaned = False @@ -224,9 +235,9 @@ def define(cls, spec): valid_type=orm.List, required=False, serializer=to_aiida_type, - default=lambda: orm.List(list=[]), + validator=validate_fermi_energy_range, help=( - 'Energy range around the Fermi level that should be covered in DOS and PROJWFC calculation.' + 'Energy range with respect to the Fermi level that should be covered in DOS and PROJWFC calculation.' 'If not specified but Emin and Emax are specified in the input parameters, these values will be used.' 'Otherwise, the default values are extracted from the NSCF calculation.' ) @@ -492,11 +503,9 @@ def _generate_projwfc_inputs(self): if fermi_energy_range: projwfc_parameters['PROJWFC']['Emin'] = fermi_energy_range[0] + self.ctx.nscf_fermi projwfc_parameters['PROJWFC']['Emax'] = fermi_energy_range[1] + self.ctx.nscf_fermi - elif 'Emin' in projwfc_parameters['PROJWFC'] and 'Emax' in projwfc_parameters['PROJWFC']: - pass else: - projwfc_parameters['PROJWFC']['Emin'] = self.ctx.nscf_emin - projwfc_parameters['PROJWFC']['Emax'] = self.ctx.nscf_emax + projwfc_parameters['PROJWFC'].setdefault('Emin', self.ctx.nscf_emin) + projwfc_parameters['PROJWFC'].setdefault('Emax', self.ctx.nscf_emax) projwfc_inputs.parameters = orm.Dict(projwfc_parameters) projwfc_inputs['metadata']['call_link_label'] = 'projwfc' From 64e350fbff6a6d86c1a27cd2860e2bb73f42caca Mon Sep 17 00:00:00 2001 From: t-reents <77727843+t-reents@users.noreply.github.com> Date: Tue, 4 Jan 2022 08:11:26 +0100 Subject: [PATCH 06/15] Update validator Co-authored-by: Sebastiaan Huber --- src/aiida_quantumespresso/workflows/pdos.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/aiida_quantumespresso/workflows/pdos.py b/src/aiida_quantumespresso/workflows/pdos.py index d53fa3bf8..599f099bf 100644 --- a/src/aiida_quantumespresso/workflows/pdos.py +++ b/src/aiida_quantumespresso/workflows/pdos.py @@ -166,9 +166,9 @@ def validate_fermi_energy_range(value): - List needs to consist of two float values. """ if len(value) != 2: - return 'List needs to consist of two values.' + return f'`fermi_energy_range` should be a `List` of length two, but got: {value}' if not all(isinstance(val, float) for val in value): - return 'Fermi energy range needs to be specified as floats.' + return f'`fermi_energy_range` should be a `List` of floats, but got: {value}' def clean_calcjob_remote(node): From 1c4d427d247525b8e75bb44a102b7377c7242719 Mon Sep 17 00:00:00 2001 From: t-reents <77727843+t-reents@users.noreply.github.com> Date: Tue, 4 Jan 2022 08:12:31 +0100 Subject: [PATCH 07/15] Update aiida_quantumespresso/workflows/pdos.py Co-authored-by: Sebastiaan Huber --- src/aiida_quantumespresso/workflows/pdos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aiida_quantumespresso/workflows/pdos.py b/src/aiida_quantumespresso/workflows/pdos.py index 599f099bf..7ce26453f 100644 --- a/src/aiida_quantumespresso/workflows/pdos.py +++ b/src/aiida_quantumespresso/workflows/pdos.py @@ -117,7 +117,7 @@ def validate_inputs(value, _): for par in ['Emin', 'Emax']: if value['dos']['parameters']['DOS'].get(par, None): warnings.warn( - f'The `{par}`` parameter and fermi_energy_range were specified.' + f'The `{par}` parameter and `fermi_energy_range` were specified.' 'The value in fermi_energy_range will be used.' ) From 0b68610124360b0058f87c81303d5d00b0130856 Mon Sep 17 00:00:00 2001 From: t-reents <77727843+t-reents@users.noreply.github.com> Date: Tue, 4 Jan 2022 08:12:46 +0100 Subject: [PATCH 08/15] Update aiida_quantumespresso/workflows/pdos.py Co-authored-by: Sebastiaan Huber --- src/aiida_quantumespresso/workflows/pdos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aiida_quantumespresso/workflows/pdos.py b/src/aiida_quantumespresso/workflows/pdos.py index 7ce26453f..88d8e9642 100644 --- a/src/aiida_quantumespresso/workflows/pdos.py +++ b/src/aiida_quantumespresso/workflows/pdos.py @@ -118,7 +118,7 @@ def validate_inputs(value, _): if value['dos']['parameters']['DOS'].get(par, None): warnings.warn( f'The `{par}` parameter and `fermi_energy_range` were specified.' - 'The value in fermi_energy_range will be used.' + 'The value in `fermi_energy_range` will be used.' ) From 4577d48d9b14cddc6ca24bee7bc5b0c8f8c28ce4 Mon Sep 17 00:00:00 2001 From: Timo Reents Date: Tue, 4 Jan 2022 08:23:10 +0100 Subject: [PATCH 09/15] minor change in fermi_energy_range validator --- src/aiida_quantumespresso/workflows/pdos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aiida_quantumespresso/workflows/pdos.py b/src/aiida_quantumespresso/workflows/pdos.py index 88d8e9642..d8aaa3463 100644 --- a/src/aiida_quantumespresso/workflows/pdos.py +++ b/src/aiida_quantumespresso/workflows/pdos.py @@ -160,7 +160,7 @@ def validate_projwfc(value, _): jsonschema.validate(value['parameters'].get_dict()['PROJWFC'], get_parameter_schema()) -def validate_fermi_energy_range(value): +def validate_fermi_energy_range(value, _): """Validate specified fermi_energy_range. - List needs to consist of two float values. From 889951c4035682e5de185cb3947d36191f4d7fa7 Mon Sep 17 00:00:00 2001 From: t-reents Date: Tue, 11 Jan 2022 13:54:22 +0100 Subject: [PATCH 10/15] change input name --- src/aiida_quantumespresso/workflows/pdos.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/aiida_quantumespresso/workflows/pdos.py b/src/aiida_quantumespresso/workflows/pdos.py index d8aaa3463..a63bea818 100644 --- a/src/aiida_quantumespresso/workflows/pdos.py +++ b/src/aiida_quantumespresso/workflows/pdos.py @@ -160,9 +160,9 @@ def validate_projwfc(value, _): jsonschema.validate(value['parameters'].get_dict()['PROJWFC'], get_parameter_schema()) -def validate_fermi_energy_range(value, _): +def validate_energy_range_vs_fermi(value, _): """Validate specified fermi_energy_range. - + - List needs to consist of two float values. """ if len(value) != 2: @@ -231,11 +231,11 @@ def define(cls, spec): help='Terminate workchain steps before submitting calculations (test purposes only).' ) spec.input( - 'fermi_energy_range', + 'energy_range_vs_fermi', valid_type=orm.List, required=False, serializer=to_aiida_type, - validator=validate_fermi_energy_range, + validator=validate_energy_range_vs_fermi, help=( 'Energy range with respect to the Fermi level that should be covered in DOS and PROJWFC calculation.' 'If not specified but Emin and Emax are specified in the input parameters, these values will be used.' From 23c3c9df3b79004a876270882ad6cc0a7ee169e8 Mon Sep 17 00:00:00 2001 From: t-reents Date: Tue, 11 Jan 2022 13:59:08 +0100 Subject: [PATCH 11/15] adapt validator --- src/aiida_quantumespresso/workflows/pdos.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/aiida_quantumespresso/workflows/pdos.py b/src/aiida_quantumespresso/workflows/pdos.py index a63bea818..4f9c3b9f2 100644 --- a/src/aiida_quantumespresso/workflows/pdos.py +++ b/src/aiida_quantumespresso/workflows/pdos.py @@ -113,12 +113,12 @@ def validate_inputs(value, _): if value['dos']['parameters']['DOS'].get(par, None) != value['projwfc']['parameters']['PROJWFC'].get(par, None): return f'The `{par}`` parameter has to be equal for the `dos` and `projwfc` inputs.' - if value.get('fermi_energy_range', False): + if value.get('energy_range_vs_fermi', False): for par in ['Emin', 'Emax']: if value['dos']['parameters']['DOS'].get(par, None): warnings.warn( - f'The `{par}` parameter and `fermi_energy_range` were specified.' - 'The value in `fermi_energy_range` will be used.' + f'The `{par}` parameter and `energy_range_vs_fermi` were specified.' + 'The value in `energy_range_vs_fermi` will be used.' ) @@ -161,14 +161,14 @@ def validate_projwfc(value, _): def validate_energy_range_vs_fermi(value, _): - """Validate specified fermi_energy_range. + """Validate specified energy_range_vs_fermi. - List needs to consist of two float values. """ if len(value) != 2: - return f'`fermi_energy_range` should be a `List` of length two, but got: {value}' + return f'`energy_range_vs_fermi` should be a `List` of length two, but got: {value}' if not all(isinstance(val, float) for val in value): - return f'`fermi_energy_range` should be a `List` of floats, but got: {value}' + return f'`energy_range_vs_fermi` should be a `List` of floats, but got: {value}' def clean_calcjob_remote(node): From 018e5a5df1be8149493403333f5eb6b20b59f917 Mon Sep 17 00:00:00 2001 From: t-reents Date: Tue, 11 Jan 2022 16:23:35 +0100 Subject: [PATCH 12/15] update parameters --- src/aiida_quantumespresso/workflows/pdos.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/aiida_quantumespresso/workflows/pdos.py b/src/aiida_quantumespresso/workflows/pdos.py index 4f9c3b9f2..beb23b6f6 100644 --- a/src/aiida_quantumespresso/workflows/pdos.py +++ b/src/aiida_quantumespresso/workflows/pdos.py @@ -480,11 +480,11 @@ def _generate_dos_inputs(self): dos_inputs = AttributeDict(self.exposed_inputs(DosCalculation, 'dos')) dos_inputs.parent_folder = self.ctx.nscf_parent_folder dos_parameters = self.inputs.dos.parameters.get_dict() - fermi_energy_range = self.inputs.fermi_energy_range + energy_range_vs_fermi = self.inputs.energy_range_vs_fermi - if fermi_energy_range: - dos_parameters['DOS']['Emin'] = fermi_energy_range[0] + self.ctx.nscf_fermi - dos_parameters['DOS']['Emax'] = fermi_energy_range[1] + self.ctx.nscf_fermi + if energy_range_vs_fermi: + dos_parameters['DOS']['Emin'] = energy_range_vs_fermi[0] + self.ctx.nscf_fermi + dos_parameters['DOS']['Emax'] = energy_range_vs_fermi[1] + self.ctx.nscf_fermi else: dos_parameters['DOS'].setdefault('Emin', self.ctx.nscf_emin) dos_parameters['DOS'].setdefault('Emax', self.ctx.nscf_emax) @@ -498,11 +498,11 @@ def _generate_projwfc_inputs(self): projwfc_inputs = AttributeDict(self.exposed_inputs(ProjwfcCalculation, 'projwfc')) projwfc_inputs.parent_folder = self.ctx.nscf_parent_folder projwfc_parameters = self.inputs.projwfc.parameters.get_dict() - fermi_energy_range = self.inputs.fermi_energy_range + energy_range_vs_fermi = self.inputs.energy_range_vs_fermi - if fermi_energy_range: - projwfc_parameters['PROJWFC']['Emin'] = fermi_energy_range[0] + self.ctx.nscf_fermi - projwfc_parameters['PROJWFC']['Emax'] = fermi_energy_range[1] + self.ctx.nscf_fermi + if energy_range_vs_fermi: + projwfc_parameters['PROJWFC']['Emin'] = energy_range_vs_fermi[0] + self.ctx.nscf_fermi + projwfc_parameters['PROJWFC']['Emax'] = energy_range_vs_fermi[1] + self.ctx.nscf_fermi else: projwfc_parameters['PROJWFC'].setdefault('Emin', self.ctx.nscf_emin) projwfc_parameters['PROJWFC'].setdefault('Emax', self.ctx.nscf_emax) From a88dfc70f2677f3231c4e4be533f1cb8c7bcf7cf Mon Sep 17 00:00:00 2001 From: Marnik Bercx Date: Wed, 10 May 2023 07:21:06 +0200 Subject: [PATCH 13/15] Fix tests --- src/aiida_quantumespresso/workflows/pdos.py | 2 +- tests/conftest.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/aiida_quantumespresso/workflows/pdos.py b/src/aiida_quantumespresso/workflows/pdos.py index beb23b6f6..435a208dc 100644 --- a/src/aiida_quantumespresso/workflows/pdos.py +++ b/src/aiida_quantumespresso/workflows/pdos.py @@ -167,7 +167,7 @@ def validate_energy_range_vs_fermi(value, _): """ if len(value) != 2: return f'`energy_range_vs_fermi` should be a `List` of length two, but got: {value}' - if not all(isinstance(val, float) for val in value): + if not all(isinstance(val, (float, int)) for val in value): return f'`energy_range_vs_fermi` should be a `List` of floats, but got: {value}' diff --git a/tests/conftest.py b/tests/conftest.py index e0b08b57e..3809e8032 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -807,7 +807,7 @@ def generate_workchain_pdos(generate_workchain, generate_inputs_pw, fixture_code """Generate an instance of a `PdosWorkChain`.""" def _generate_workchain_pdos(): - from aiida.orm import Bool, Dict + from aiida.orm import Bool, Dict, List from aiida_quantumespresso.utils.resources import get_default_options @@ -855,7 +855,7 @@ def _generate_workchain_pdos(): 'nscf': nscf, 'dos': dos, 'projwfc': projwfc, - 'align_to_fermi': Bool(True), + 'energy_range_vs_fermi': List([-10, 10]), 'dry_run': Bool(True) } From 914323fdfa234b2d8704f8ebc3e3747bc2545ef1 Mon Sep 17 00:00:00 2001 From: Timo Reents Date: Wed, 15 Nov 2023 20:07:50 +0100 Subject: [PATCH 14/15] Draft for test adjustments --- src/aiida_quantumespresso/workflows/pdos.py | 18 +++++++++--------- tests/conftest.py | 14 +++++++++----- tests/workflows/test_pdos.py | 20 +++++++++++++++++++- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/aiida_quantumespresso/workflows/pdos.py b/src/aiida_quantumespresso/workflows/pdos.py index 435a208dc..0e570ce46 100644 --- a/src/aiida_quantumespresso/workflows/pdos.py +++ b/src/aiida_quantumespresso/workflows/pdos.py @@ -97,7 +97,6 @@ def validate_inputs(value, _): - Check that either the `scf` or `nscf.pw.parent_folder` inputs is provided. - Check that the `Emin`, `Emax` and `DeltaE` inputs are the same for the `dos` and `projwfc` namespaces. - - Check that `Emin` and `Emax` are provided in case `align_to_fermi` is set to `True`. """ # Check that either the `scf` input or `nscf.pw.parent_folder` is provided. import warnings @@ -390,6 +389,9 @@ def setup(self): """Initialize context variables that are used during the logical flow of the workchain.""" self.ctx.serial_clean = 'serial_clean' in self.inputs and self.inputs.serial_clean.value self.ctx.dry_run = 'dry_run' in self.inputs and self.inputs.dry_run.value + self.ctx.energy_range_vs_fermi = ( + self.inputs.energy_range_vs_fermi if 'energy_range_vs_fermi' in self.inputs else None + ) def serial_clean(self): """Return whether dos and projwfc calculations should be run in serial. @@ -480,11 +482,10 @@ def _generate_dos_inputs(self): dos_inputs = AttributeDict(self.exposed_inputs(DosCalculation, 'dos')) dos_inputs.parent_folder = self.ctx.nscf_parent_folder dos_parameters = self.inputs.dos.parameters.get_dict() - energy_range_vs_fermi = self.inputs.energy_range_vs_fermi - if energy_range_vs_fermi: - dos_parameters['DOS']['Emin'] = energy_range_vs_fermi[0] + self.ctx.nscf_fermi - dos_parameters['DOS']['Emax'] = energy_range_vs_fermi[1] + self.ctx.nscf_fermi + if self.ctx.energy_range_vs_fermi: + dos_parameters['DOS']['Emin'] = self.ctx.energy_range_vs_fermi[0] + self.ctx.nscf_fermi + dos_parameters['DOS']['Emax'] = self.ctx.energy_range_vs_fermi[1] + self.ctx.nscf_fermi else: dos_parameters['DOS'].setdefault('Emin', self.ctx.nscf_emin) dos_parameters['DOS'].setdefault('Emax', self.ctx.nscf_emax) @@ -498,11 +499,10 @@ def _generate_projwfc_inputs(self): projwfc_inputs = AttributeDict(self.exposed_inputs(ProjwfcCalculation, 'projwfc')) projwfc_inputs.parent_folder = self.ctx.nscf_parent_folder projwfc_parameters = self.inputs.projwfc.parameters.get_dict() - energy_range_vs_fermi = self.inputs.energy_range_vs_fermi - if energy_range_vs_fermi: - projwfc_parameters['PROJWFC']['Emin'] = energy_range_vs_fermi[0] + self.ctx.nscf_fermi - projwfc_parameters['PROJWFC']['Emax'] = energy_range_vs_fermi[1] + self.ctx.nscf_fermi + if self.ctx.energy_range_vs_fermi: + projwfc_parameters['PROJWFC']['Emin'] = self.ctx.energy_range_vs_fermi[0] + self.ctx.nscf_fermi + projwfc_parameters['PROJWFC']['Emax'] = self.ctx.energy_range_vs_fermi[1] + self.ctx.nscf_fermi else: projwfc_parameters['PROJWFC'].setdefault('Emin', self.ctx.nscf_emin) projwfc_parameters['PROJWFC'].setdefault('Emax', self.ctx.nscf_emax) diff --git a/tests/conftest.py b/tests/conftest.py index 3809e8032..1de5d2c94 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -806,7 +806,7 @@ def _generate_workchain_ph(exit_code=None, inputs=None, return_inputs=False): def generate_workchain_pdos(generate_workchain, generate_inputs_pw, fixture_code): """Generate an instance of a `PdosWorkChain`.""" - def _generate_workchain_pdos(): + def _generate_workchain_pdos(emin=None, emax=None, energy_range_vs_fermi=None): from aiida.orm import Bool, Dict, List from aiida_quantumespresso.utils.resources import get_default_options @@ -829,12 +829,15 @@ def _generate_workchain_pdos(): dos_params = { 'DOS': { - 'Emin': -10, - 'Emax': 10, 'DeltaE': 0.01, } } - projwfc_params = {'PROJWFC': {'Emin': -10, 'Emax': 10, 'DeltaE': 0.01, 'ngauss': 0, 'degauss': 0.01}} + projwfc_params = {'PROJWFC': {'DeltaE': 0.01, 'ngauss': 0, 'degauss': 0.01}} + + if emin and emax: + dos_params['DOS'].update({'Emin': emin, 'Emax': emax}) + projwfc_params['PROJWFC'].update({'Emin': emin, 'Emax': emax}) + dos = { 'code': fixture_code('quantumespresso.dos'), 'parameters': Dict(dos_params), @@ -855,9 +858,10 @@ def _generate_workchain_pdos(): 'nscf': nscf, 'dos': dos, 'projwfc': projwfc, - 'energy_range_vs_fermi': List([-10, 10]), 'dry_run': Bool(True) } + if energy_range_vs_fermi: + inputs.update({'energy_range_vs_fermi': List(energy_range_vs_fermi)}) return generate_workchain(entry_point, inputs) diff --git a/tests/workflows/test_pdos.py b/tests/workflows/test_pdos.py index beb8b3ddc..2b767de8a 100644 --- a/tests/workflows/test_pdos.py +++ b/tests/workflows/test_pdos.py @@ -8,6 +8,7 @@ from aiida.engine.utils import instantiate_process from aiida.manage.manager import get_manager from plumpy import ProcessState +import pytest from aiida_quantumespresso.calculations.helpers import pw_input_helper @@ -26,6 +27,10 @@ def instantiate_process_cls(process_cls, inputs): return instantiate_process(runner, process_cls, **inputs) +@pytest.mark.parametrize( + 'energy_range_inputs,expected_p_dos_inputs', [((-10, 10, None), (-10, 10)), + ((None, None, [-10, 10]), (-3.0970404109571996, 16.9029595890428))] +) def test_default( generate_workchain_pdos, generate_workchain_pw, @@ -35,10 +40,12 @@ def test_default( generate_calc_job_node, fixture_sandbox, generate_bands_data, + energy_range_inputs, + expected_p_dos_inputs, ): """Test instantiating the WorkChain, then mock its process, by calling methods in the ``spec.outline``.""" + wkchain = generate_workchain_pdos(*energy_range_inputs) - wkchain = generate_workchain_pdos() assert wkchain.setup() is None assert wkchain.serial_clean() is False @@ -90,6 +97,17 @@ def test_default( # mock run dos and projwfc, and check that their inputs are acceptable dos_inputs, projwfc_inputs = wkchain.run_pdos_parallel() + + # check generated inputs + # @mbercx please uncomment the following lines + # dos_params = dos_inputs.parameters.get_dict() + # projwfc_params = projwfc_inputs.parameters.get_dict() + + # assert dos_params['DOS']['Emin'] == expected_p_dos_inputs[0] + # assert dos_params['DOS']['Emax'] == expected_p_dos_inputs[1] + # assert projwfc_params['PROJWFC']['Emin'] == expected_p_dos_inputs[0] + # assert projwfc_params['PROJWFC']['Emax'] == expected_p_dos_inputs[1] + generate_calc_job(fixture_sandbox, 'quantumespresso.dos', dos_inputs) generate_calc_job(fixture_sandbox, 'quantumespresso.projwfc', projwfc_inputs) From e1eeb149aa8c35dfc70b9f15660e67db1c7f73fd Mon Sep 17 00:00:00 2001 From: Timo Reents Date: Fri, 22 Nov 2024 12:04:59 +0100 Subject: [PATCH 15/15] Adding tests to check the new energy range logic --- tests/workflows/test_pdos.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/tests/workflows/test_pdos.py b/tests/workflows/test_pdos.py index 2b767de8a..0fdfd6b7a 100644 --- a/tests/workflows/test_pdos.py +++ b/tests/workflows/test_pdos.py @@ -27,10 +27,24 @@ def instantiate_process_cls(process_cls, inputs): return instantiate_process(runner, process_cls, **inputs) +def check_pdos_energy_range(dos_inputs, projwfc_inputs, expected_p_dos_inputs): + """Check the energy range of the pdos calculation.""" + # check generated inputs + dos_params = dos_inputs.parameters.get_dict() + projwfc_params = projwfc_inputs.parameters.get_dict() + + assert dos_params['DOS']['Emin'] == expected_p_dos_inputs[0] + assert dos_params['DOS']['Emax'] == expected_p_dos_inputs[1] + assert projwfc_params['PROJWFC']['Emin'] == expected_p_dos_inputs[0] + assert projwfc_params['PROJWFC']['Emax'] == expected_p_dos_inputs[1] + + @pytest.mark.parametrize( 'energy_range_inputs,expected_p_dos_inputs', [((-10, 10, None), (-10, 10)), - ((None, None, [-10, 10]), (-3.0970404109571996, 16.9029595890428))] + ((None, None, [-10, 10]), (-3.0970404109571996, 16.9029595890428)), + ((None, None, None), (-5.64024889, 8.91047649))] ) +@pytest.mark.usefixtures('aiida_profile_clean') def test_default( generate_workchain_pdos, generate_workchain_pw, @@ -83,12 +97,10 @@ def test_default( remote.store() remote.base.links.add_incoming(mock_wknode, link_type=LinkType.RETURN, link_label='remote_folder') - result = orm.Dict({'fermi_energy': 6.9029595890428}) - result.store() + result = orm.Dict({'fermi_energy': 6.9029595890428}).store() result.base.links.add_incoming(mock_wknode, link_type=LinkType.RETURN, link_label='output_parameters') - bands_data = generate_bands_data() - bands_data.store() + bands_data = generate_bands_data().store() bands_data.base.links.add_incoming(mock_wknode, link_type=LinkType.RETURN, link_label='output_band') wkchain.ctx.workchain_nscf = mock_wknode @@ -98,15 +110,7 @@ def test_default( # mock run dos and projwfc, and check that their inputs are acceptable dos_inputs, projwfc_inputs = wkchain.run_pdos_parallel() - # check generated inputs - # @mbercx please uncomment the following lines - # dos_params = dos_inputs.parameters.get_dict() - # projwfc_params = projwfc_inputs.parameters.get_dict() - - # assert dos_params['DOS']['Emin'] == expected_p_dos_inputs[0] - # assert dos_params['DOS']['Emax'] == expected_p_dos_inputs[1] - # assert projwfc_params['PROJWFC']['Emin'] == expected_p_dos_inputs[0] - # assert projwfc_params['PROJWFC']['Emax'] == expected_p_dos_inputs[1] + check_pdos_energy_range(dos_inputs, projwfc_inputs, expected_p_dos_inputs) generate_calc_job(fixture_sandbox, 'quantumespresso.dos', dos_inputs) generate_calc_job(fixture_sandbox, 'quantumespresso.projwfc', projwfc_inputs)