Skip to content

Commit

Permalink
Kumagai Correction (#196)
Browse files Browse the repository at this point in the history
* plot fed

* plot fef

* plot fed

* plot fed

* plot fed

* plot fed

* remove uid

* remove uid

* add pydefect back

* test lint
  • Loading branch information
jmmshn authored May 21, 2024
1 parent a50a35b commit 553db2b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
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) -> None:
Expand Down Expand Up @@ -71,17 +72,23 @@ def test_freysoldt_sxdefect_compare(v_N_GaN) -> None:
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()

0 comments on commit 553db2b

Please sign in to comment.