From 7b226091dbdec839d37983eca2df9cce5d116a25 Mon Sep 17 00:00:00 2001 From: Nicola Colonna <30554261+nscolonna@users.noreply.github.com> Date: Thu, 13 Jun 2024 09:55:21 +0200 Subject: [PATCH] Bug fix in setting the number of electrons in kcp in spin-polarized calculations (#223) Moved the evaluation of keywords not assigned to a specific calculator earlier, so that this information can be used for the autogeneration of variables such as `nelup` and `neldw`. The old code resulted in a bug for `kcp.x` calculations where these keywords were incorrectly assigned if `tot_magnetization` was provided outside of the `pw` and `kcp` blocks. --- src/koopmans/workflows/_workflow.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/koopmans/workflows/_workflow.py b/src/koopmans/workflows/_workflow.py index 8f27635d0..259a457e9 100644 --- a/src/koopmans/workflows/_workflow.py +++ b/src/koopmans/workflows/_workflow.py @@ -227,6 +227,19 @@ def __init__(self, atoms: Atoms, self.parameters.pseudo_directory = pseudo_dir.resolve() + # For any kwargs... + for key, value in kwargs.items(): + match = False + # if they correspond to any valid calculator parameter, set it + for calc_params in calculator_parameters.values(): + if calc_params.is_valid(key): + calc_params[key] = value + match = True + # if not a calculator, workflow, or plotting keyword, raise an error + if not match and not self.parameters.is_valid(key) and not self.plotting.is_valid(key) \ + and not self.ml.is_valid(key): + raise ValueError(f'{key} is not a valid setting') + # Before saving the calculator_parameters, automatically generate some keywords and perform some sanity checks if self.parameters.task != 'ui' and autogenerate_settings: # Automatically calculate nelec/nelup/neldw/etc using information contained in the pseudopotential files @@ -301,19 +314,6 @@ def __init__(self, atoms: Atoms, # Initialize self.parent self.parent: Optional[Workflow] = None - # For any kwargs... - for key, value in kwargs.items(): - match = False - # if they correspond to any valid calculator parameter, set it - for calc_params in self.calculator_parameters.values(): - if calc_params.is_valid(key): - calc_params[key] = value - match = True - # if not a calculator, workflow, or plotting keyword, raise an error - if not match and not self.parameters.is_valid(key) and not self.plotting.is_valid(key) \ - and not self.ml.is_valid(key): - raise ValueError(f'{key} is not a valid setting') - # Adding excluded_bands info to self.projections if self.projections: for spin in ['up', 'down', None]: