Skip to content

Commit

Permalink
Clean up sets (#2425)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-S-Rosen authored Aug 16, 2024
1 parent 005b371 commit 5262623
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 28 deletions.
22 changes: 13 additions & 9 deletions src/quacc/calculators/espresso/espresso.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class Espresso(GenericFileIOCalculator):
def __init__(
self,
input_atoms: Atoms | None = None,
preset: str | None = None,
preset: str | Path | None = None,
template: EspressoTemplate | None = None,
**kwargs,
) -> None:
Expand All @@ -370,11 +370,12 @@ def __init__(
input_atoms
The input Atoms object to be used for the calculation.
preset
The name of a YAML file containing a list of parameters to use as
a "preset" for the calculator. quacc will automatically look in the
`ESPRESSO_PRESET_DIR` (default: quacc/calculators/espresso/presets),
The .yaml extension is not necessary. Any user-supplied calculator
**kwargs will override any corresponding preset values.
A YAML file containing a list of INCAR parameters to use as a "preset"
for the calculator. If `preset` has a .yml or .yaml file extension, the
path to this file will be used directly. If `preset` is a string without
an extension, the corresponding YAML file will be assumed to be in the
`ESPRESSO_PRESET_DIR`. Any user-supplied calculator **kwargs will
override any corresponding preset values.
template
ASE calculator templace which can be used to specify which espresso
binary will be used in the calculation. This is taken care of by recipe
Expand Down Expand Up @@ -407,7 +408,7 @@ def __init__(
self._cleanup_params()
else:
LOGGER.warning(
f"the binary you requested, `{self._binary}`, is not supported by ASE. This means that presets and usual checks will not be carried out, your `input_data` must be provided in nested format."
f"The binary you requested, `{self._binary}`, is not supported by ASE. This means that presets and usual checks will not be carried out, your `input_data` must be provided in nested format."
)

self.kwargs["input_data"] = Namelist(self.kwargs.get("input_data"))
Expand Down Expand Up @@ -451,9 +452,12 @@ def _cleanup_params(self) -> None:
self.kwargs["input_data"].to_nested(binary=self._binary, **self.kwargs)

if self.preset:
calc_preset = load_yaml_calc(
self._settings.ESPRESSO_PRESET_DIR / f"{self.preset}"
preset_path = (
self.preset
if Path(self.preset).suffix in (".yaml", ".yml")
else self._settings.ESPRESSO_PRESET_DIR / f"{self.preset}.yaml"
)
calc_preset = load_yaml_calc(preset_path)
calc_preset["input_data"] = Namelist(calc_preset.get("input_data"))
calc_preset["input_data"].to_nested(binary=self._binary, **calc_preset)
if "pseudopotentials" in calc_preset:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ input_data:
mixing_mode: local-TF
mixing_beta: 0.35

parent_pseudopotentials: sssp_1.3.0_pbe_efficiency.yaml
parent_pseudopotentials: sssp_1.3.0_pbe_efficiency
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ input_data:
mixing_mode: local-TF
mixing_beta: 0.35

parent_pseudopotentials: sssp_1.3.0_pbe_precision.yaml
parent_pseudopotentials: sssp_1.3.0_pbe_precision
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ input_data:
mixing_mode: local-TF
mixing_beta: 0.25

parent_pseudopotentials: sssp_1.3.0_pbe_efficiency.yaml
parent_pseudopotentials: sssp_1.3.0_pbe_efficiency
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ input_data:
mixing_mode: local-TF
mixing_beta: 0.25

parent_pseudopotentials: sssp_1.3.0_pbe_precision.yaml
parent_pseudopotentials: sssp_1.3.0_pbe_precision
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ input_data:

kspacing: 0.03

parent_pseudopotentials: sssp_1.3.0_pbe_efficiency.yaml
parent_pseudopotentials: sssp_1.3.0_pbe_efficiency
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ input_data:

kspacing: 0.015

parent_pseudopotentials: sssp_1.3.0_pbe_precision.yaml
parent_pseudopotentials: sssp_1.3.0_pbe_precision
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ input_data:

kpts: null

parent_pseudopotentials: sssp_1.3.0_pbe_efficiency.yaml
parent_pseudopotentials: sssp_1.3.0_pbe_efficiency
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ input_data:

kspacing: 0.045

parent_pseudopotentials: sssp_1.3.0_pbe_efficiency.yaml
parent_pseudopotentials: sssp_1.3.0_pbe_efficiency
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ input_data:

kspacing: 0.03

parent_pseudopotentials: sssp_1.3.0_pbe_precision.yaml
parent_pseudopotentials: sssp_1.3.0_pbe_precision
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ input_data:

kpts: null

parent_pseudopotentials: sssp_1.3.0_pbe_efficiency.yaml
parent_pseudopotentials: sssp_1.3.0_pbe_efficiency
4 changes: 2 additions & 2 deletions src/quacc/calculators/vasp/presets/BulkSet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ inputs:
prec: accurate
sigma: 0.05
xc: pbe
parent_magmoms: magmoms_base.yaml
parent_setups: setups_pbe64.yaml
parent_magmoms: magmoms_base
parent_setups: setups_pbe64
4 changes: 2 additions & 2 deletions src/quacc/calculators/vasp/presets/QMOFSet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ inputs:
sigma: 0.01
symprec: 1.0e-8
xc: pbe
parent_magmoms: magmoms_qmof.yaml
parent_setups: setups_qmof.yaml
parent_magmoms: magmoms_qmof
parent_setups: setups_qmof
2 changes: 1 addition & 1 deletion src/quacc/calculators/vasp/presets/SlabSet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ inputs:
encut: 450
ivdw: 0
xc: rpbe
parent: BulkSet.yaml
parent: BulkSet
6 changes: 3 additions & 3 deletions src/quacc/utils/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ def load_yaml_calc(yaml_path: str | Path) -> dict[str, Any]:
# the child file.
for config_arg in deepcopy(config):
if "parent" in config_arg.lower():
if Path(config[config_arg]).suffix not in (".yml", ".yaml"):
yaml_parent_path = yaml_path.parent / config[config_arg]
if Path(config[config_arg]).suffix in (".yml", ".yaml"):
yaml_parent_path = config[config_arg]
else:
yaml_parent_path = Path(config[config_arg])
yaml_parent_path = yaml_path.parent / f"{config[config_arg]}.yaml"
parent_config = load_yaml_calc(yaml_parent_path)

for k, v in parent_config.items():
Expand Down
2 changes: 1 addition & 1 deletion tests/core/calculators/espresso/test_espresso.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_espresso_presets():


def test_espresso_presets_gamma():
preset = "molecule_efficiency.yaml"
preset = "molecule_efficiency"

calc = Espresso(preset=preset)

Expand Down

0 comments on commit 5262623

Please sign in to comment.