Skip to content

Commit

Permalink
Flesh out es tests more
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Munro committed Jul 15, 2021
1 parent 23bb60a commit afca174
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 7 deletions.
1 change: 1 addition & 0 deletions emmet-core/emmet/core/electronic_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ def from_bsdos( # type: ignore[override]
summary_vbm = dos_vbm
summary_efermi = dos_efermi
summary_magnetic_ordering = dos_mag_ordering
is_metal = True if np.isclose(dos_gap, 0.0, atol=0.01, rtol=0) else False

return cls.from_structure(
material_id=MPID(material_id),
Expand Down
12 changes: 9 additions & 3 deletions tests/emmet-builders/test_electronic_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

@pytest.fixture(scope="session")
def tasks_store(test_dir):
return JSONStore(test_dir / "es_task_docs.json.gz", key="task_id")
return JSONStore(
test_dir / "electronic_structure/es_task_docs.json.gz", key="task_id"
)


@pytest.fixture(scope="session")
Expand All @@ -28,12 +30,16 @@ def electronic_structure_store():

@pytest.fixture
def bandstructure_fs(test_dir):
return JSONStore(test_dir / "es_bs_objs.json.gz", key="task_id")
return JSONStore(
test_dir / "electronic_structure/es_bs_objs.json.gz", key="task_id"
)


@pytest.fixture
def dos_fs(test_dir):
return JSONStore(test_dir / "es_dos_objs.json.gz", key="task_id")
return JSONStore(
test_dir / "electronic_structure/es_dos_objs.json.gz", key="task_id"
)


def test_electronic_structure_builder(
Expand Down
58 changes: 54 additions & 4 deletions tests/emmet-core/test_electronic_structure.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import pytest
from monty.serialization import loadfn
from maggma.stores import JSONStore
from pymatgen.electronic_structure.bandstructure import BandStructureSymmLine
from pymatgen.electronic_structure.dos import CompleteDos

from emmet.core.electronic_structure import ElectronicStructureDoc

Expand All @@ -9,7 +12,7 @@ def structure(test_dir):
"""
Fe (mp-13) structure with correct magmoms
"""
structure = loadfn(test_dir / "Fe_structure.json")
structure = loadfn(test_dir / "electronic_structure/Fe_structure.json")
return structure


Expand All @@ -18,7 +21,7 @@ def bandstructure(test_dir):
"""
Fe (mp-13) line-mode band structure
"""
bs = loadfn(test_dir / "Fe_bs.json")
bs = loadfn(test_dir / "electronic_structure/Fe_bs.json")
return bs


Expand All @@ -27,11 +30,11 @@ def dos(test_dir):
"""
Fe (mp-13) dos
"""
dos = loadfn(test_dir / "Fe_dos.json")
dos = loadfn(test_dir / "electronic_structure/Fe_dos.json")
return dos


def test_from_bsdos(bandstructure, dos, structure):
def test_from_bsdos_1(bandstructure, dos, structure):

es_doc = ElectronicStructureDoc.from_bsdos(
material_id="mp-13",
Expand All @@ -55,3 +58,50 @@ def test_from_bsdos(bandstructure, dos, structure):
assert es_doc.bandstructure.setyawan_curtarolo.band_gap == 0.0
assert es_doc.bandstructure.setyawan_curtarolo.efermi == 5.18804178
assert es_doc.bandstructure.setyawan_curtarolo.nbands == 96.0


@pytest.fixture
def bandstructure_fs(test_dir):
return JSONStore(
test_dir / "electronic_structure/es_bs_objs.json.gz", key="task_id"
)


@pytest.fixture
def dos_fs(test_dir):
return JSONStore(
test_dir / "electronic_structure/es_dos_objs.json.gz", key="task_id"
)


def test_from_bsdos_2(bandstructure_fs, dos_fs):

dos_fs.connect()
bandstructure_fs.connect()

dos = CompleteDos.from_dict(dos_fs.query_one({"task_id": "mp-823888"})["data"])
bs = BandStructureSymmLine.from_dict(
bandstructure_fs.query_one({"task_id": "mp-1612487"})["data"]
)

es_doc = ElectronicStructureDoc.from_bsdos(
material_id="mp-25375",
dos={"mp-823888": dos},
is_gap_direct=False,
is_metal=True,
setyawan_curtarolo={"mp-1612487": bs},
)

assert str(es_doc.material_id) == "mp-25375"
assert es_doc.band_gap == 0.0
assert es_doc.cbm == 2.7102
assert es_doc.vbm == 2.9396
assert es_doc.efermi == 2.75448867
assert es_doc.is_gap_direct is False
assert es_doc.is_metal is True
assert str(es_doc.magnetic_ordering) == "Ordering.NM"

assert str(es_doc.bandstructure.setyawan_curtarolo.task_id) == "mp-1612487"
assert es_doc.bandstructure.setyawan_curtarolo.band_gap == 1.9916
assert es_doc.bandstructure.setyawan_curtarolo.efermi == 2.49084067
assert es_doc.bandstructure.setyawan_curtarolo.nbands == 64.0
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
File renamed without changes.
File renamed without changes.
Binary file removed tests/test_files/es_bs_objs.json.gz
Binary file not shown.

0 comments on commit afca174

Please sign in to comment.