From 75a6c44075624f59c51260167aabb6c4f7cec92f Mon Sep 17 00:00:00 2001 From: Andrew Rosen Date: Sat, 2 Sep 2023 20:18:11 -0700 Subject: [PATCH 1/3] Add a check on the dimensions of `length_densities` --- pymatgen/io/vasp/inputs.py | 3 +++ tests/io/vasp/test_inputs.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/pymatgen/io/vasp/inputs.py b/pymatgen/io/vasp/inputs.py index 3ad412d063c..8041b63814f 100644 --- a/pymatgen/io/vasp/inputs.py +++ b/pymatgen/io/vasp/inputs.py @@ -1298,6 +1298,9 @@ def automatic_density_by_lengths( Returns: Kpoints """ + if len(length_densities) != 3: + msg = f"The dimensions of length_densities must be 3, not {len(length_densities)}" + raise ValueError(msg) comment = f"k-point density of {length_densities}/[a, b, c]" lattice = structure.lattice abc = lattice.abc diff --git a/tests/io/vasp/test_inputs.py b/tests/io/vasp/test_inputs.py index 04bb063c227..4046bbb1688 100644 --- a/tests/io/vasp/test_inputs.py +++ b/tests/io/vasp/test_inputs.py @@ -879,6 +879,9 @@ def test_automatic_density_by_lengths(self): assert kpoints.style == expected_style + with pytest.raises(ValueError): + kpoints = Kpoints.automatic_density_by_lengths(structure, [50, 50]) + def test_automatic_monkhorst_vs_gamma_style_selection(self): structs = {key: Structure.from_file(f"{TEST_FILES_DIR}/POSCAR_{key}") for key in ("bcc", "fcc", "hcp")} From a3348de5093572ae97f61a586d1c9198b1f2ad84 Mon Sep 17 00:00:00 2001 From: Andrew Rosen Date: Sat, 2 Sep 2023 20:22:28 -0700 Subject: [PATCH 2/3] Remove unused variable assignment --- tests/io/vasp/test_inputs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/io/vasp/test_inputs.py b/tests/io/vasp/test_inputs.py index 4046bbb1688..c94a780a211 100644 --- a/tests/io/vasp/test_inputs.py +++ b/tests/io/vasp/test_inputs.py @@ -880,7 +880,7 @@ def test_automatic_density_by_lengths(self): assert kpoints.style == expected_style with pytest.raises(ValueError): - kpoints = Kpoints.automatic_density_by_lengths(structure, [50, 50]) + Kpoints.automatic_density_by_lengths(structure, [50, 50]) def test_automatic_monkhorst_vs_gamma_style_selection(self): structs = {key: Structure.from_file(f"{TEST_FILES_DIR}/POSCAR_{key}") for key in ("bcc", "fcc", "hcp")} From 1dfb4a76a3180cdf3bbb4fd1314b71070a0b8d35 Mon Sep 17 00:00:00 2001 From: Andrew Rosen Date: Sat, 2 Sep 2023 20:27:08 -0700 Subject: [PATCH 3/3] fix ruff error --- tests/io/vasp/test_inputs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/io/vasp/test_inputs.py b/tests/io/vasp/test_inputs.py index c94a780a211..352616dea64 100644 --- a/tests/io/vasp/test_inputs.py +++ b/tests/io/vasp/test_inputs.py @@ -879,7 +879,7 @@ def test_automatic_density_by_lengths(self): assert kpoints.style == expected_style - with pytest.raises(ValueError): + with pytest.raises(ValueError, match="The dimensions of length_densities must be 3, not 2"): Kpoints.automatic_density_by_lengths(structure, [50, 50]) def test_automatic_monkhorst_vs_gamma_style_selection(self):