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

Kumagai Correction #196

Merged
merged 11 commits into from
May 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
2 changes: 1 addition & 1 deletion pymatgen/analysis/defects/corrections/kumagai.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

def _check_import_pydefect() -> None:
"""Import pydefect if it is installed."""
if __has_pydefect__:
if not __has_pydefect__:
msg = "vise/pydefect is not installed. Please install it first."
raise ModuleNotFoundError(
msg,
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ dev = ["pre-commit>=2.12.1"]
docs = [
"jupyter-book>=0.13.1",
]
optional = ["pydefect>=0.6.2", "dscribe>=2.0.0", "numba"]
optional = ["pydefect", "dscribe>=2.0.0", "numba"]

strict = [
"pymatgen==2024.5.1",
"dscribe==2.1.0",
"mp-pyrho==0.4.4",
"pydefect==0.9.4",
]

tests = ["pytest==8.2.0", "pytest-cov==5.0.0", "nbmake==1.5.3"]
Expand Down
31 changes: 19 additions & 12 deletions tests/test_corrections.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
get_freysoldt_correction,
plot_plnr_avg,
)
from pymatgen.analysis.defects.corrections.kumagai import get_efnv_correction, get_structure_with_pot


def test_freysoldt(data_Mg_Ga):
Expand Down Expand Up @@ -71,17 +72,23 @@ def test_freysoldt_sxdefect_compare(v_N_GaN):
assert results[q] == pytest.approx(references[q], abs=1e-3)


# def test_kumagai(test_dir):
# sb = get_structure_with_pot(test_dir / "Mg_Ga" / "bulk_sc")
# sd0 = get_structure_with_pot(test_dir / "Mg_Ga" / "q=0")
# sd1 = get_structure_with_pot(test_dir / "Mg_Ga" / "q=1")
def test_kumagai(test_dir):
sb = get_structure_with_pot(test_dir / "Mg_Ga" / "bulk_sc")
sd0 = get_structure_with_pot(test_dir / "Mg_Ga" / "q=0")
sd1 = get_structure_with_pot(test_dir / "Mg_Ga" / "q=1")

# res0 = get_efnv_correction(
# 0, sd0, sb, dielectric_tensor=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]
# )
# assert res0.correction_energy == pytest.approx(0, abs=1e-4)
res0 = get_efnv_correction(
0, sd0, sb, dielectric_tensor=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]
)
assert res0.correction_energy == pytest.approx(0, abs=1e-4)

res1 = get_efnv_correction(
1, sd1, sb, dielectric_tensor=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]
)
assert res1.correction_energy > 0

# res1 = get_efnv_correction(
# 1, sd1, sb, dielectric_tensor=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]
# )
# assert res1.correction_energy > 0
def test_kumagai_missing():
from pymatgen.analysis.defects.corrections import kumagai
kumagai.__has_pydefect__ = False
with pytest.raises(ImportError):
kumagai._check_import_pydefect()
Loading