1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
import pytest
from monty.serialization import loadfn
from emmet.core.qchem.task import TaskDocument
from emmet.core.qchem.molecule import MoleculeDoc
from emmet.core.molecules.thermo import MoleculeThermoDoc
from emmet.core.molecules.redox import RedoxDoc
@pytest.fixture(scope="session")
def base_mol(test_dir):
mol = loadfn((test_dir / "redox_doc" / "base_mol.json").as_posix())
mol_doc = MoleculeDoc(**mol)
return mol_doc
@pytest.fixture(scope="session")
def base_thermo(test_dir):
thermo = loadfn((test_dir / "redox_doc" / "thermo.json").as_posix())
thermo_doc = MoleculeThermoDoc(**thermo)
return thermo_doc
@pytest.fixture(scope="session")
def red_thermo(test_dir):
thermo = loadfn((test_dir / "redox_doc" / "red_thermo.json").as_posix())
thermo_doc = MoleculeThermoDoc(**thermo)
return thermo_doc
@pytest.fixture(scope="session")
def ox_thermo(test_dir):
thermo = loadfn((test_dir / "redox_doc" / "ox_thermo.json").as_posix())
thermo_doc = MoleculeThermoDoc(**thermo)
return thermo_doc
@pytest.fixture(scope="session")
def ie_task(test_dir):
pytest.importorskip("custodian")
try:
task = loadfn((test_dir / "redox_doc" / "ie_task.json").as_posix())
except RuntimeError:
pytest.skip("openbabel is only available for the default Python version")
task_doc = TaskDocument(**task)
return task_doc
@pytest.fixture(scope="session")
def ea_task(test_dir):
task = loadfn((test_dir / "redox_doc" / "ea_task.json").as_posix())
task_doc = TaskDocument(**task)
return task_doc
def test_redox(base_mol, base_thermo, red_thermo, ox_thermo, ie_task, ea_task):
redox_doc = RedoxDoc.from_docs(
base_molecule_doc=base_mol,
base_thermo_doc=base_thermo,
red_doc=red_thermo,
ox_doc=ox_thermo,
ea_doc=ea_task,
ie_doc=ie_task,
)
assert redox_doc.electron_affinity == pytest.approx(-3.3024638499209686)
assert redox_doc.ionization_energy == pytest.approx(4.903294672107222)
assert redox_doc.oxidation_free_energy == pytest.approx(3.9880055108133092)
assert redox_doc.reduction_free_energy == pytest.approx(-4.237271030198826)
|