Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify BadInputSetWarning logic for relaxations of a likely metal #3634

Merged
merged 6 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions pymatgen/io/vasp/sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,11 +743,23 @@ def incar(self) -> Incar:
BadInputSetWarning,
)

if all(k.is_metal for k in structure.composition) and incar.get("NSW", 0) > 0 and incar.get("ISMEAR", 1) < 1:
ismear = incar.get("ISMEAR", 1)
sigma = incar.get("SIGMA", 0.2)
if (
all(elem.is_metal for elem in structure.composition)
and incar.get("NSW", 0) > 0
and (ismear < 0 or (ismear == 0 and sigma > 0.05))
):
ismear_docs = "https://www.vasp.at/wiki/index.php/ISMEAR"
msg = ""
if ismear < 0:
msg = f"Relaxation of likely metal with ISMEAR < 0 ({ismear})."
elif ismear == 0 and sigma > 0.05:
msg = f"ISMEAR = 0 with a small SIGMA ({sigma}) detected."
warnings.warn(
"Relaxation of likely metal with ISMEAR < 1 detected. See VASP "
"recommendations on ISMEAR for metals.",
f"{msg} See VASP recommendations on ISMEAR for metals ({ismear_docs}).",
BadInputSetWarning,
stacklevel=1,
)

return incar
Expand Down
2 changes: 1 addition & 1 deletion tests/files/.pytest-split-durations
Original file line number Diff line number Diff line change
Expand Up @@ -2210,7 +2210,7 @@
"tests/io/vasp/test_sets.py::TestMITMPRelaxSet::test_hubbard_off_and_ediff_override": 0.004546375945210457,
"tests/io/vasp/test_sets.py::TestMITMPRelaxSet::test_incar_lmaxmix": 0.008337250037584454,
"tests/io/vasp/test_sets.py::TestMITMPRelaxSet::test_lda_potcar": 0.035044250020291656,
"tests/io/vasp/test_sets.py::TestMITMPRelaxSet::test_metal_check": 0.006276416010223329,
"tests/io/vasp/test_sets.py::TestMITMPRelaxSet::test_warnings": 0.006276416010223329,
"tests/io/vasp/test_sets.py::TestMITMPRelaxSet::test_nelect": 1.6427247499814257,
"tests/io/vasp/test_sets.py::TestMITMPRelaxSet::test_poscar": 0.006406874977983534,
"tests/io/vasp/test_sets.py::TestMITMPRelaxSet::test_potcar_special_defaults": 0.008440207981038839,
Expand Down
28 changes: 19 additions & 9 deletions tests/io/vasp/test_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,23 +198,33 @@ def test_no_structure_init(self):
assert vis.as_dict()["structure"] is not None
assert "structure" not in vis.as_dict(verbosity=1)

def test_metal_check(self):
def test_warnings(self):
structure = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3), ["Cu"], [[0, 0, 0]])

with pytest.warns(
BadInputSetWarning,
match="Relaxation of likely metal with ISMEAR < 1 detected. "
"See VASP recommendations on ISMEAR for metals.",
) as warns_metal:
vis = self.set(structure)
vis = self.set(structure)
with pytest.warns(BadInputSetWarning) as warns_metal:
_ = vis.incar
assert len(warns_metal) == 1
vasp_docs_link = "See VASP recommendations on ISMEAR for metals (https://www.vasp.at/wiki/index.php/ISMEAR)."
assert (
str(warns_metal[0].message)
== f"Relaxation of likely metal with ISMEAR < 0 ({vis.incar['ISMEAR']}). {vasp_docs_link}"
)

# test different warning for ismear == 0 and sigma > 0.05
vis = self.set(structure, user_incar_settings={"ISMEAR": 0, "SIGMA": 0.1})
with pytest.warns(BadInputSetWarning) as warns_metal:
_ = vis.incar
assert len(warns_metal) == 1
assert (
str(warns_metal[0].message)
== f"ISMEAR = 0 with a small SIGMA ({vis.incar['SIGMA']}) detected. {vasp_docs_link}"
)

with pytest.warns(
BadInputSetWarning,
match="Large KSPACING value detected with ISMEAR = -5. Ensure that VASP "
"generates an adequate number of KPOINTS, lower KSPACING, or "
"set ISMEAR = 0",
"generates an adequate number of KPOINTS, lower KSPACING, or set ISMEAR = 0",
) as warns_kspacing:
vis = self.set(structure, user_incar_settings={"KSPACING": 1, "ISMEAR": -5})
_ = vis.incar
Expand Down
Loading