File size: 1,509 Bytes
1c7cd6c
 
b9692e2
 
1c7cd6c
52c1bfb
1c7cd6c
f1eddde
 
1c7cd6c
 
5b87ae4
e59afe6
 
 
 
8396dce
 
 
f1eddde
 
 
 
 
 
1c7cd6c
 
 
 
 
 
 
 
 
 
b9692e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pytest
from ase import Atoms
from ase.calculators.calculator import PropertyNotImplementedError
import numpy as np

from mlip_arena.models import MLIPEnum

from requests import HTTPError
from huggingface_hub.errors import LocalTokenNotFoundError

@pytest.mark.parametrize("model", MLIPEnum)
def test_calculate(model: MLIPEnum):

    if model.name == "ALIGNN":
        pytest.xfail("ALIGNN has poor file download mechanism")

    if model.name == "ORB":
        pytest.xfail("Orbital Materials deprecated the model a month after its premature release in favor of ORBv2")

    try:
        calc = MLIPEnum[model.name].value()

    except (LocalTokenNotFoundError, HTTPError):
        # Gracefully skip the test if HF_TOKEN is not available
        pytest.skip("Skipping test because HF_TOKEN is not available for downloading the model.")

    atoms = Atoms(
        "OO",
        positions=[[0, 0, 0], [1.5, 0, 0]],
        cell=[10, 10 + 0.001, 10 + 0.002],
        pbc=True,
    )

    atoms.calc = calc

    energy = atoms.get_potential_energy()

    assert isinstance(energy, (float, np.float64, np.float32))

    forces = atoms.get_forces()
    assert isinstance(forces, (np.ndarray, list))
    assert len(forces) == len(atoms)

    try:
        stress = atoms.get_stress()
    except PropertyNotImplementedError:
        stress = None

    if stress is None:
        pytest.xfail("Stress calculation is not supported by the model")
    else:
        assert isinstance(stress, (np.ndarray, list))