|
| 1 | +import numpy as np |
| 2 | + |
| 3 | +from ase.build import bulk |
| 4 | + |
| 5 | +from lorem.calculator import Calculator |
| 6 | +from lorem.models.bec import LoremBEC |
| 7 | +from lorem.models.mlip import Lorem |
| 8 | + |
| 9 | + |
| 10 | +def test_calculator_energy_forces(): |
| 11 | + model = Lorem(cutoff=5.0, num_features=8, num_spherical_features=2, num_radial=4) |
| 12 | + calc = Calculator.from_model(model) |
| 13 | + |
| 14 | + atoms = bulk("Ar") * [2, 2, 2] |
| 15 | + calc.calculate(atoms) |
| 16 | + |
| 17 | + assert "energy" in calc.results |
| 18 | + assert "forces" in calc.results |
| 19 | + assert calc.results["forces"].shape == (len(atoms), 3) |
| 20 | + assert "BEC" not in calc.results # Lorem (not LoremBEC) has no BEC |
| 21 | + |
| 22 | + |
| 23 | +def test_calculator_bec(): |
| 24 | + model = LoremBEC(cutoff=5.0, num_features=8, num_spherical_features=2, num_radial=4) |
| 25 | + calc = Calculator.from_model(model) |
| 26 | + |
| 27 | + atoms = bulk("Ar") * [2, 2, 2] |
| 28 | + calc.calculate(atoms) |
| 29 | + |
| 30 | + assert "energy" in calc.results |
| 31 | + assert "forces" in calc.results |
| 32 | + assert "BEC" in calc.results |
| 33 | + |
| 34 | + natoms = len(atoms) |
| 35 | + assert calc.results["BEC"].shape == (3 * natoms, 3) |
| 36 | + assert calc.results["BEC"].dtype == np.float32 |
| 37 | + |
| 38 | + |
| 39 | +def test_calculator_bec_get_property(): |
| 40 | + model = LoremBEC(cutoff=5.0, num_features=8, num_spherical_features=2, num_radial=4) |
| 41 | + calc = Calculator.from_model(model) |
| 42 | + |
| 43 | + atoms = bulk("Ar") * [2, 2, 2] |
| 44 | + calc.calculate(atoms) |
| 45 | + |
| 46 | + bec = calc.get_property("BEC", atoms) |
| 47 | + assert bec.shape == (3 * len(atoms), 3) |
| 48 | + |
| 49 | + |
| 50 | +def test_lorem_calculator_import(): |
| 51 | + from lorem import LOREMCalculator |
| 52 | + |
| 53 | + model = LoremBEC(cutoff=5.0, num_features=8, num_spherical_features=2, num_radial=4) |
| 54 | + calc = LOREMCalculator.from_model(model) |
| 55 | + |
| 56 | + atoms = bulk("Ar") * [2, 2, 2] |
| 57 | + calc.calculate(atoms) |
| 58 | + |
| 59 | + assert "BEC" in calc.results |
| 60 | + assert calc.results["BEC"].shape == (3 * len(atoms), 3) |
0 commit comments