File: test_materials.py

package info (click to toggle)
python-emmet-core 0.84.2-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 77,220 kB
  • sloc: python: 16,355; makefile: 30
file content (48 lines) | stat: -rw-r--r-- 1,290 bytes parent folder | download
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
import json

import pytest
from monty.io import zopen

from emmet.core.vasp.calc_types import TaskType
from emmet.core.vasp.material import MaterialsDoc
from emmet.core.vasp.task_valid import TaskDocument


@pytest.fixture
def test_tasks(test_dir):
    with zopen(test_dir / "test_si_tasks.json.gz") as f:
        tasks = json.load(f)

    tasks = [TaskDocument(**t) for t in tasks]
    return tasks


def test_make_mat(test_tasks):
    material = MaterialsDoc.from_tasks(test_tasks)
    assert material.formula_pretty == "Si"
    assert len(material.task_ids) == 4
    assert len(material.entries.model_dump(exclude_none=True)) == 1

    bad_task_group = [
        task for task in test_tasks if task.task_type != TaskType.Structure_Optimization
    ]

    with pytest.raises(Exception):
        MaterialsDoc.from_tasks(bad_task_group, use_statics=False)


def test_make_deprecated_mat(test_tasks):
    bad_task_group = [
        task for task in test_tasks if task.task_type != TaskType.Structure_Optimization
    ]

    material = MaterialsDoc.construct_deprecated_material(bad_task_group)

    assert material.deprecated
    assert material.formula_pretty == "Si"
    assert len(material.task_ids) == 3
    assert material.entries is None


def test_schema():
    MaterialsDoc.schema()