55
66import numpy as np
77import pytest
8+ from emmet .core .mpid import MPID , AlphaID
89from emmet .core .tasks import TaskDoc
910from emmet .core .vasp .calc_types import CalcType
11+ from emmet .core .phonon import PhononDOS , PhononBS
12+ from emmet .core .types .enums import ThermoType
13+
1014from pymatgen .analysis .phase_diagram import PhaseDiagram
1115from pymatgen .analysis .pourbaix_diagram import IonEntry , PourbaixDiagram , PourbaixEntry
1216from pymatgen .analysis .wulff import WulffShape
1317from pymatgen .core import SETTINGS
18+ from pymatgen .core .composition import Composition
1419from pymatgen .core .ion import Ion
1520from pymatgen .core .periodic_table import Element
1621from pymatgen .electronic_structure .bandstructure import (
2631from pymatgen .entries .computed_entries import ComputedEntry , GibbsComputedStructureEntry
2732from pymatgen .io .cif import CifParser
2833from pymatgen .io .vasp import Chgcar
29- from emmet .core .phonon import PhononDOS , PhononBS
3034
3135from mp_api .client import MPRester
3236from mp_api .client .core .client import MPRestError
3337from mp_api .client .core .settings import MAPIClientSettings
34- from mp_api .client .core .utils import _compare_emmet_ver
35-
36- if _compare_emmet_ver ("0.85.0" , ">=" ):
37- from emmet .core .types .enums import ThermoType
38- else :
39- from emmet .core .thermo import ThermoType
4038
4139
4240@pytest .fixture ()
@@ -361,6 +359,9 @@ def test_get_api_key_endpoint_from_env_var(self, monkeypatch: pytest.MonkeyPatch
361359 assert MPRester ().api_key == self .fake_mp_api_key
362360 assert MPRester ().endpoint == self .default_endpoint
363361
362+ monkeypatch .setenv ("MP_API_ENDPOINT" , self .default_endpoint [:- 1 ])
363+ assert MPRester ().endpoint .endswith ("/" )
364+
364365 def test_get_api_key_endpoint_from_settings (self , monkeypatch : pytest .MonkeyPatch ):
365366 """Test environment variable "MP_API_KEY" is not set and
366367 get "PMG_MAPI_KEY" from "SETTINGS".
@@ -522,3 +523,34 @@ def test_get_stability(self, chemsys, thermo_type):
522523 data = dct
523524 break
524525 assert pd .get_e_above_hull (entry ) == pytest .approx (data ["e_above_hull" ])
526+
527+ @pytest .mark .parametrize (
528+ "mpid, working_ion, thermo_type" ,
529+ [
530+ ("mp-1248282" ,"Al" , ThermoType .GGA_GGA_U ),
531+ (MPID ("mp-1248282" ),Element .Al , "R2SCAN" ),
532+ (AlphaID ("mp-1248282" ),"Al" ,ThermoType .GGA_GGA_U_R2SCAN ),
533+ ]
534+ )
535+ def test_oxygen_evolution (self , mpid , working_ion , thermo_type , mpr ):
536+ # Ensure oxygen evolution data has the anticipated schema
537+ # and is robust to different permutations of input
538+
539+ oxy_evo = mpr .get_oxygen_evolution (
540+ mpid , working_ion , thermo_type = thermo_type
541+ )
542+ assert all (
543+ isinstance (entry .get (k ),np .ndarray )
544+ for entry in oxy_evo .values ()
545+ for k in ("mu" ,"evolution" ,"temperature" ,"reaction" )
546+ )
547+ assert all (Composition (k ).formula == k for k in oxy_evo )
548+
549+ def test_oxygen_evolution_bad_input (self ,mpr ):
550+ # Ensure oxygen evolution fails gracefully if no O present
551+ # or no insertion electrode data
552+ with pytest .raises (ValueError ,match = "No oxygen in the host" ):
553+ _ = mpr .get_oxygen_evolution ("mp-2207" ,Element .K )
554+
555+ with pytest .raises (ValueError , match = "No available insertion electrode data" ):
556+ _ = mpr .get_oxygen_evolution ("mp-2207" ,"Al" )
0 commit comments