From b5532cd05624840466598587087284ff8f8dab8e Mon Sep 17 00:00:00 2001 From: AndresOrtegaGuerrero Date: Wed, 2 Oct 2024 09:42:00 +0000 Subject: [PATCH 1/8] adding nbands_factor logic into PdosWorkChain --- src/aiida_quantumespresso/workflows/pdos.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/aiida_quantumespresso/workflows/pdos.py b/src/aiida_quantumespresso/workflows/pdos.py index 311d8237f..f3c54c742 100644 --- a/src/aiida_quantumespresso/workflows/pdos.py +++ b/src/aiida_quantumespresso/workflows/pdos.py @@ -227,6 +227,9 @@ def define(cls, spec): 'provided by in the `dos` and `projwfc` inputs, since otherwise the ' ) ) + spec.input('nbands_factor', valid_type=orm.Float, required=False, + help='The number of bands for the NSCF calculation is that used for the SCF multiplied by this factor.') + spec.expose_inputs( PwBaseWorkChain, namespace='scf', @@ -431,6 +434,18 @@ def run_nscf(self): inputs.pw.structure = self.inputs.structure inputs.metadata.call_link_label = 'nscf' + + if 'nbands_factor' in self.inputs: + factor = self.inputs.nbands_factor.value + parameters = self.ctx.workchain_scf.outputs.output_parameters.get_dict() + nbands = int(parameters['number_of_bands']) + nelectron = int(parameters['number_of_electrons']) + nbnd = max(int(0.5 * nelectron * factor), int(0.5 * nelectron) + 4, nbands) + inputs.pw.parameters['SYSTEM']['nbnd'] = nbnd + + else: + inputs.pw.parameters['SYSTEM']['nbnd'] = self.ctx.workchain_scf.outputs.output_parameters['number_of_bands'] + inputs = prepare_process_inputs(PwBaseWorkChain, inputs) if self.ctx.dry_run: From 88214e6395cae27c56d2f2baebc168fa2877301e Mon Sep 17 00:00:00 2001 From: AndresOrtegaGuerrero Date: Tue, 19 Nov 2024 17:46:01 +0000 Subject: [PATCH 2/8] including logic if scf is present --- src/aiida_quantumespresso/workflows/pdos.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/aiida_quantumespresso/workflows/pdos.py b/src/aiida_quantumespresso/workflows/pdos.py index f3c54c742..c846ce61d 100644 --- a/src/aiida_quantumespresso/workflows/pdos.py +++ b/src/aiida_quantumespresso/workflows/pdos.py @@ -431,20 +431,22 @@ def run_nscf(self): inputs = AttributeDict(self.exposed_inputs(PwBaseWorkChain, 'nscf')) if 'scf' in self.inputs: inputs.pw.parent_folder = self.ctx.scf_parent_folder + + if 'nbands_factor' in self.inputs: + factor = self.inputs.nbands_factor.value + parameters = self.ctx.workchain_scf.outputs.output_parameters.get_dict() + nbands = int(parameters['number_of_bands']) + nelectron = int(parameters['number_of_electrons']) + nbnd = max(int(0.5 * nelectron * factor), int(0.5 * nelectron) + 4, nbands) + inputs.pw.parameters['SYSTEM']['nbnd'] = nbnd + + else: + inputs.pw.parameters['SYSTEM']['nbnd'] = self.ctx.workchain_scf.outputs.output_parameters['number_of_bands'] inputs.pw.structure = self.inputs.structure inputs.metadata.call_link_label = 'nscf' - if 'nbands_factor' in self.inputs: - factor = self.inputs.nbands_factor.value - parameters = self.ctx.workchain_scf.outputs.output_parameters.get_dict() - nbands = int(parameters['number_of_bands']) - nelectron = int(parameters['number_of_electrons']) - nbnd = max(int(0.5 * nelectron * factor), int(0.5 * nelectron) + 4, nbands) - inputs.pw.parameters['SYSTEM']['nbnd'] = nbnd - else: - inputs.pw.parameters['SYSTEM']['nbnd'] = self.ctx.workchain_scf.outputs.output_parameters['number_of_bands'] inputs = prepare_process_inputs(PwBaseWorkChain, inputs) From d4057cc9553b6c0d565ceec80bf75142441d8dbb Mon Sep 17 00:00:00 2001 From: AndresOrtegaGuerrero Date: Wed, 20 Nov 2024 08:23:23 +0000 Subject: [PATCH 3/8] fix pylint error --- src/aiida_quantumespresso/workflows/pdos.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/aiida_quantumespresso/workflows/pdos.py b/src/aiida_quantumespresso/workflows/pdos.py index c846ce61d..df48dd2cb 100644 --- a/src/aiida_quantumespresso/workflows/pdos.py +++ b/src/aiida_quantumespresso/workflows/pdos.py @@ -441,7 +441,9 @@ def run_nscf(self): inputs.pw.parameters['SYSTEM']['nbnd'] = nbnd else: - inputs.pw.parameters['SYSTEM']['nbnd'] = self.ctx.workchain_scf.outputs.output_parameters['number_of_bands'] + inputs.pw.parameters['SYSTEM']['nbnd'] = ( + self.ctx.workchain_scf.outputs.output_parameters['number_of_bands'] + ) inputs.pw.structure = self.inputs.structure inputs.metadata.call_link_label = 'nscf' From 2a9435805f8ff92f60b54ceae1819c9d70e92d15 Mon Sep 17 00:00:00 2001 From: AndresOrtegaGuerrero Date: Wed, 20 Nov 2024 08:43:38 +0000 Subject: [PATCH 4/8] using base attribute to get number_of_bands --- 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 df48dd2cb..f859af886 100644 --- a/src/aiida_quantumespresso/workflows/pdos.py +++ b/src/aiida_quantumespresso/workflows/pdos.py @@ -434,7 +434,7 @@ def run_nscf(self): if 'nbands_factor' in self.inputs: factor = self.inputs.nbands_factor.value - parameters = self.ctx.workchain_scf.outputs.output_parameters.get_dict() + parameters = self.ctx.workchain_scf.outputs.output_parameters.base.attributes.get('number_of_bands') nbands = int(parameters['number_of_bands']) nelectron = int(parameters['number_of_electrons']) nbnd = max(int(0.5 * nelectron * factor), int(0.5 * nelectron) + 4, nbands) From d976db40124db40aebde60bd1be0798665e6e4f6 Mon Sep 17 00:00:00 2001 From: AndresOrtegaGuerrero Date: Wed, 20 Nov 2024 08:58:49 +0000 Subject: [PATCH 5/8] fix attributes --- 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 f859af886..a60e00a86 100644 --- a/src/aiida_quantumespresso/workflows/pdos.py +++ b/src/aiida_quantumespresso/workflows/pdos.py @@ -434,7 +434,7 @@ def run_nscf(self): if 'nbands_factor' in self.inputs: factor = self.inputs.nbands_factor.value - parameters = self.ctx.workchain_scf.outputs.output_parameters.base.attributes.get('number_of_bands') + parameters = self.ctx.workchain_scf.outputs.output_parameters.get_dict() nbands = int(parameters['number_of_bands']) nelectron = int(parameters['number_of_electrons']) nbnd = max(int(0.5 * nelectron * factor), int(0.5 * nelectron) + 4, nbands) @@ -442,7 +442,7 @@ def run_nscf(self): else: inputs.pw.parameters['SYSTEM']['nbnd'] = ( - self.ctx.workchain_scf.outputs.output_parameters['number_of_bands'] + self.ctx.workchain_scf.outputs.output_parameters.base.attributes.get('number_of_bands') ) inputs.pw.structure = self.inputs.structure From 115f6a8e4460f91d3e2016c3fdbcdda9e8e456ed Mon Sep 17 00:00:00 2001 From: AndresOrtegaGuerrero Date: Wed, 20 Nov 2024 09:09:32 +0000 Subject: [PATCH 6/8] remove statement of using scf bands --- src/aiida_quantumespresso/workflows/pdos.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/aiida_quantumespresso/workflows/pdos.py b/src/aiida_quantumespresso/workflows/pdos.py index a60e00a86..c662bfe69 100644 --- a/src/aiida_quantumespresso/workflows/pdos.py +++ b/src/aiida_quantumespresso/workflows/pdos.py @@ -440,10 +440,6 @@ def run_nscf(self): nbnd = max(int(0.5 * nelectron * factor), int(0.5 * nelectron) + 4, nbands) inputs.pw.parameters['SYSTEM']['nbnd'] = nbnd - else: - inputs.pw.parameters['SYSTEM']['nbnd'] = ( - self.ctx.workchain_scf.outputs.output_parameters.base.attributes.get('number_of_bands') - ) inputs.pw.structure = self.inputs.structure inputs.metadata.call_link_label = 'nscf' From 1a3447c678ed606f083eade9b7c947db00c210bb Mon Sep 17 00:00:00 2001 From: AndresOrtegaGuerrero Date: Wed, 20 Nov 2024 12:22:54 +0000 Subject: [PATCH 7/8] adapting logic --- src/aiida_quantumespresso/workflows/pdos.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/aiida_quantumespresso/workflows/pdos.py b/src/aiida_quantumespresso/workflows/pdos.py index c662bfe69..bad906371 100644 --- a/src/aiida_quantumespresso/workflows/pdos.py +++ b/src/aiida_quantumespresso/workflows/pdos.py @@ -429,23 +429,23 @@ def run_nscf(self): """ inputs = AttributeDict(self.exposed_inputs(PwBaseWorkChain, 'nscf')) + if 'scf' in self.inputs: inputs.pw.parent_folder = self.ctx.scf_parent_folder - if 'nbands_factor' in self.inputs: - factor = self.inputs.nbands_factor.value - parameters = self.ctx.workchain_scf.outputs.output_parameters.get_dict() - nbands = int(parameters['number_of_bands']) - nelectron = int(parameters['number_of_electrons']) - nbnd = max(int(0.5 * nelectron * factor), int(0.5 * nelectron) + 4, nbands) - inputs.pw.parameters['SYSTEM']['nbnd'] = nbnd + if 'nbands_factor' in self.inputs: + inputs.pw.parameters = inputs.pw.parameters.get_dict() + factor = self.inputs.nbands_factor.value + parameters = self.ctx.workchain_scf.outputs.output_parameters.get_dict() + nbands = int(parameters['number_of_bands']) + nelectron = int(parameters['number_of_electrons']) + nbnd = max(int(0.5 * nelectron * factor), int(0.5 * nelectron) + 4, nbands) + inputs.pw.parameters['SYSTEM']['nbnd'] = nbnd inputs.pw.structure = self.inputs.structure inputs.metadata.call_link_label = 'nscf' - - inputs = prepare_process_inputs(PwBaseWorkChain, inputs) if self.ctx.dry_run: From 9de2ec4a8c2a7b99de6d49bb1611a1f1a376fca1 Mon Sep 17 00:00:00 2001 From: AndresOrtegaGuerrero Date: Wed, 20 Nov 2024 12:44:46 +0000 Subject: [PATCH 8/8] including a nbands_factor validator --- src/aiida_quantumespresso/workflows/pdos.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/aiida_quantumespresso/workflows/pdos.py b/src/aiida_quantumespresso/workflows/pdos.py index bad906371..09ec45012 100644 --- a/src/aiida_quantumespresso/workflows/pdos.py +++ b/src/aiida_quantumespresso/workflows/pdos.py @@ -118,6 +118,9 @@ def validate_inputs(value, _): 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 'nbands_factor' in value and 'nbnd' in value['nscf']['pw']['parameters'].base.attributes.get('SYSTEM', {}): + return PdosWorkChain.exit_codes.ERROR_INVALID_INPUT_NUMBER_OF_BANDS.message + def validate_scf(value, _): """Validate the scf parameters.""" @@ -304,6 +307,8 @@ def define(cls, spec): message='the PROJWFC sub process failed') spec.exit_code(404, 'ERROR_SUB_PROCESS_FAILED_BOTH', message='both the DOS and PROJWFC sub process failed') + spec.exit_code(405, 'ERROR_INVALID_INPUT_NUMBER_OF_BANDS', + message='Cannot specify both `nbands_factor` and `nscf.pw.parameters.SYSTEM.nbnd`.') spec.expose_outputs(PwBaseWorkChain, namespace='nscf') spec.expose_outputs(DosCalculation, namespace='dos')