File size: 1,417 Bytes
b78a213 | 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 | """
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import os
import numpy as np
import pytest
from ase.io import read
from ocpmodels.common.utils import get_pbc_distances
from ocpmodels.datasets import data_list_collater
from ocpmodels.preprocessing import AtomsToGraphs
@pytest.fixture(scope="class")
def load_data(request):
atoms = read(
os.path.join(os.path.dirname(os.path.abspath(__file__)), "atoms.json"),
index=0,
format="json",
)
a2g = AtomsToGraphs(
max_neigh=12,
radius=6,
r_energy=True,
r_forces=True,
r_distances=True,
)
data_list = a2g.convert_all([atoms])
request.cls.data = data_list[0]
@pytest.mark.usefixtures("load_data")
class TestPBC:
def test_pbc_distances(self):
data = self.data
batch = data_list_collater([data] * 5)
out = get_pbc_distances(
batch.pos,
batch.edge_index,
batch.cell,
batch.cell_offsets,
batch.neighbors,
)
edge_index, pbc_distances = out["edge_index"], out["distances"]
np.testing.assert_array_equal(
batch.edge_index,
edge_index,
)
np.testing.assert_array_almost_equal(batch.distances, pbc_distances)
|