diff --git a/pyproject.toml b/pyproject.toml index d2300b16..288e8411 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ name = "wfl" requires-python = ">=3.9" -dependencies = [ "click>=7.0", "numpy<2", "ase>=3.22.1", "pyyaml", "spglib", +dependencies = [ "click>=7.0", "numpy>=2", "ase>=3.22.1", "pyyaml", "spglib", "docstring_parser", "expyre-wfl", "universalSOAP", "pandas" ] readme = "README.md" license = { file = "LICENSE" } diff --git a/tests/calculators/test_aims.py b/tests/calculators/test_aims.py index 1a2dab89..a95f5e66 100644 --- a/tests/calculators/test_aims.py +++ b/tests/calculators/test_aims.py @@ -103,6 +103,45 @@ def test_setup_calc_params(parameters_nonperiodic): assert key_i in calc.parameters +@pytest.mark.skipif(Version(ase.__version__) < Version("3.23"), reason="Aims tests are only supported for ASE v3.23") +def test_setup_calc_params_kspacing(parameters_nonperiodic): + from wfl.calculators.kpts import universal_kspacing_n_k + + parameters = parameters_nonperiodic + parameters["kspacing"] = 0.3 + parameters["profile"] = AimsProfile("_DUMMY_") + + # PBC is TTT + atoms = bulk("Si", cubic=True) + calc = wfl.calculators.aims.Aims(**parameters) + calc.atoms = atoms.copy() + calc._setup_calc_params() + assert "kspacing" not in calc.parameters + assert calc.parameters["k_grid"] == tuple(universal_kspacing_n_k(atoms.cell, atoms.pbc, 0.3)) + assert calc.parameters["k_grid"] == (4, 4, 4) + + # PBC is TTF (slab) + atoms = Atoms("H", cell=[4, 6, 20], pbc=[True, True, False]) + calc = wfl.calculators.aims.Aims(**parameters) + calc.atoms = atoms.copy() + calc._setup_calc_params() + assert calc.parameters["k_grid"] == (6, 4, 1) + + # PBC is FFF + atoms = Atoms("H") + calc = wfl.calculators.aims.Aims(**parameters) + calc.atoms = atoms.copy() + calc._setup_calc_params() + assert "kspacing" not in calc.parameters + assert "k_grid" not in calc.parameters + + # conflicting k-point specification + calc = wfl.calculators.aims.Aims(**parameters, k_grid=(2, 2, 2)) + calc.atoms = bulk("Si") + with pytest.raises(ValueError): + calc._setup_calc_params() + + @aims_prerequisites def test_aims_calculation(tmp_path, parameters_nonperiodic): diff --git a/wfl/calculators/aims.py b/wfl/calculators/aims.py index 6b0047f6..95d3a610 100644 --- a/wfl/calculators/aims.py +++ b/wfl/calculators/aims.py @@ -13,6 +13,7 @@ AimsProfile = None from .wfl_fileio_calculator import WFLFileIOCalculator +from .kpts import universal_kspacing_n_k # NOMAD compatible, see https://nomad-lab.eu/prod/rae/gui/uploads _default_keep_files = ["control.in", "geometry.in", "aims.out"] @@ -31,6 +32,11 @@ class Aims(WFLFileIOCalculator, ASE_Aims): Parameters ---------- + kspacing: float, default None + If given, the ```k_grid``` is set for each structure from this spacing in reciprocal space + (in 1/Angstrom, including the factor of 2 pi, as for VASP's KSPACING), with a single k-point + along non-periodic directions. Cannot be combined with ```k_grid```, ```k_grid_density``` + or ```kpts```. keep_files: bool / None / "default" / list(str), default "default" What kind of files to keep from the run: - True : Everything kept. @@ -112,8 +118,15 @@ def _setup_calc_params(self): """ Setup parameters for the calculation based on the atomistic systems periodicity. - Remove entries in ```self.parameters``` that don't fit to the atomistic systems periodicity. + Remove entries in ```self.parameters``` that don't fit to the atomistic systems periodicity, + and convert ```kspacing``` (if present) into a ```k_grid```. """ + kspacing = self.parameters.pop("kspacing", None) + if kspacing is not None: + conflicting = [param_i for param_i in ["k_grid", "k_grid_density", "kpts"] if param_i in self.parameters] + if conflicting: + raise ValueError(f"'kspacing' cannot be combined with {conflicting}") + if np.all(~self.atoms.pbc): # PBC is FFF # e.g. k_grid or k_grid_density, k_offset, sc_accuracy_stress rm_parameters = [param_i for param_i in self.parameters if 'k_grid' in param_i @@ -121,6 +134,6 @@ def _setup_calc_params(self): or param_i in ['relax_unit_cell', 'external_pressure']] for param_i in rm_parameters: self.parameters.pop(param_i) - - - + elif kspacing is not None: + n_k = universal_kspacing_n_k(cell=self.atoms.cell, pbc=self.atoms.pbc, kspacing=kspacing) + self.parameters["k_grid"] = tuple(int(n) for n in n_k)