From 7dcd3f2ab22399bab7a05695bbc461bdac43d55f Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 28 May 2024 17:54:34 +0200 Subject: [PATCH] - Add default for basis set (when not mentioned) - Remove `None` clauses --- electronicparsers/gaussian/parser.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/electronicparsers/gaussian/parser.py b/electronicparsers/gaussian/parser.py index 799e1c07..f58b1337 100644 --- a/electronicparsers/gaussian/parser.py +++ b/electronicparsers/gaussian/parser.py @@ -1306,7 +1306,8 @@ def resolve_prefix(name): name = res[2] return prefix, name - def resolve_basis_set(parameter): + def resolve_basis_set(parameter: str) -> tuple[str, str]: + """Standardize basis set names (`parameter`) to the format used in the metainfo.""" basis_set = self._basis_set_map.get(parameter, None) if basis_set is not None: return (parameter, parameter) @@ -1320,6 +1321,9 @@ def resolve_basis_set(parameter): ) return (basis_keys[0], parameter) + # fall back onto default basis set + return ('STO-3G', 'STO-3G') + def resolve_xc_functional(parameter): xc_functional = self._xc_functional_map.get(parameter, None) if xc_functional is not None: @@ -1373,9 +1377,9 @@ def resolve_xc_functional(parameter): xc_functionals.add(xc_functional) basis_set_parameter = parameter[0] if not parameter[1:] else parameter[1] + # ! invert logic basis_set = resolve_basis_set(basis_set_parameter.strip()) - if basis_set is not None: - basis_sets.add(basis_set) + basis_sets.add(basis_set) sec_dft = DFT() sec_method.dft = sec_dft @@ -1401,7 +1405,7 @@ def resolve_xc_functional(parameter): self.logger.error( 'Found multiple or no basis set', data=dict(n_parsed=len(basis_sets)) ) - bs = None + for basis_set in basis_sets: bs = BasisSet( type='gaussians', @@ -1415,7 +1419,7 @@ def resolve_xc_functional(parameter): BasisSetContainer( type='atom-centered orbitals', scope=['wavefunction'], - basis_set=[bs] if bs is not None else [], + basis_set=[bs], ) ]