diff --git a/tests/vasp/test_jobs.py b/tests/vasp/test_jobs.py index 81894bca..7e80caa8 100644 --- a/tests/vasp/test_jobs.py +++ b/tests/vasp/test_jobs.py @@ -7,7 +7,9 @@ import pytest from monty.os import cd from monty.tempfile import ScratchDir +from pymatgen.core import Structure from pymatgen.io.vasp import Incar, Kpoints, Poscar +from pymatgen.io.vasp.sets import MPRelaxSet from custodian.vasp.jobs import GenerateVaspInputJob, VaspJob, VaspNEBJob, _gamma_point_only_check from tests.conftest import TEST_FILES @@ -183,32 +185,32 @@ def test_run(self) -> None: kpoints = Kpoints.from_file("KPOINTS") assert str(kpoints.style) == "Reciprocal" + class TestAutoGamma: """ Test that a VASP job can automatically detect when only 1 k-point at GAMMA is used. """ - from pymatgen.core import Structure - from pymatgen.io.vasp.sets import MPRelaxSet - - # Isolated atom in PBC - structure = Structure( - lattice = [[15 + 0.1*i if i == j else 0. for j in range(3)] for i in range(3)], - species = ["Na"], - coords = [[0.5 for _ in range(3)]] - ) - - vis = MPRelaxSet(structure=structure) - assert vis.kpoints.kpts == [(1, 1, 1)] - assert vis.kpoints.style.name == "Gamma" - assert _gamma_point_only_check(vis.get_input_set()) - - # no longer Gamma-centered - vis = MPRelaxSet(structure=structure,user_kpoints_settings=Kpoints(kpts_shift=(0.1,0.,0.))) - assert not _gamma_point_only_check(vis.get_input_set()) - - # have to increase KSPACING or this will result in a non 1 x 1 x 1 grid - vis = MPRelaxSet(structure=structure,user_incar_settings={"KSPACING": 0.5}) - assert _gamma_point_only_check(vis.get_input_set()) - - vis = MPRelaxSet(structure=structure,user_incar_settings={"KSPACING": 0.5, "KGAMMA": False}) - assert not _gamma_point_only_check(vis.get_input_set()) \ No newline at end of file + + def test_gamma_checks(self) -> None: + # Isolated atom in PBC + structure = Structure( + lattice=[[15 + 0.1 * i if i == j else 0.0 for j in range(3)] for i in range(3)], + species=["Na"], + coords=[[0.5 for _ in range(3)]], + ) + + vis = MPRelaxSet(structure=structure) + assert vis.kpoints.kpts == [(1, 1, 1)] + assert vis.kpoints.style.name == "Gamma" + assert _gamma_point_only_check(vis.get_input_set()) + + # no longer Gamma-centered + vis = MPRelaxSet(structure=structure, user_kpoints_settings=Kpoints(kpts_shift=(0.1, 0.0, 0.0))) + assert not _gamma_point_only_check(vis.get_input_set()) + + # have to increase KSPACING or this will result in a non 1 x 1 x 1 grid + vis = MPRelaxSet(structure=structure, user_incar_settings={"KSPACING": 0.5}) + assert _gamma_point_only_check(vis.get_input_set()) + + vis = MPRelaxSet(structure=structure, user_incar_settings={"KSPACING": 0.5, "KGAMMA": False}) + assert not _gamma_point_only_check(vis.get_input_set())