Skip to content

Commit

Permalink
Bug fix in setting the number of electrons in kcp in spin-polarized c…
Browse files Browse the repository at this point in the history
…alculations (#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.
  • Loading branch information
nscolonna authored Jun 13, 2024
1 parent 559da8b commit 7b22609
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/koopmans/workflows/_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]:
Expand Down

0 comments on commit 7b22609

Please sign in to comment.