From 6aae73beb3702217f823ab114796b6be65af1f7a Mon Sep 17 00:00:00 2001 From: frostedoyster Date: Sat, 28 Feb 2026 14:55:35 +0100 Subject: [PATCH] Add tests for edge cases --- pyproject.toml | 3 --- tests/test_edge_cases.py | 43 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 tests/test_edge_cases.py diff --git a/pyproject.toml b/pyproject.toml index e592081..7ea4a3b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,9 +74,6 @@ ignore_missing_imports = true disable_error_code = ["union-attr"] [tool.pytest.ini_options] -markers = [ - "slow: marks tests as slow (deselect with '-m \"not slow\"')", -] filterwarnings = [ "error", "ignore:custom data:UserWarning", diff --git a/tests/test_edge_cases.py b/tests/test_edge_cases.py new file mode 100644 index 0000000..859503c --- /dev/null +++ b/tests/test_edge_cases.py @@ -0,0 +1,43 @@ +import ase.build +import ase.io +import ase.units +import torch +from ase.md import VelocityVerlet + +from flashmd import get_pretrained +from flashmd.ase import EnergyCalculator + + +def test_isolated_atom(monkeypatch, tmp_path): + """Test that a short MD run completes without errors on an isolated atom.""" + monkeypatch.chdir(tmp_path) + + atoms = ase.Atoms("O", positions=[[0, 0, 0]]) + + time_step = 64 + device = "cuda" if torch.cuda.is_available() else "cpu" + energy_model, _ = get_pretrained("pet-omatpes-v2", time_step) + calculator = EnergyCalculator(energy_model, device=device) + atoms.calc = calculator + + dyn = VelocityVerlet(atoms=atoms, timestep=time_step * ase.units.fs) + dyn.run(10) + + +def test_slab_plus_isolated_atom(monkeypatch, tmp_path): + """Test that a short MD run completes without errors on a slab plus an isolated atom.""" + monkeypatch.chdir(tmp_path) + + # Create a slab and an isolated atom + slab = ase.build.fcc111("Al", size=(2, 2, 3), vacuum=10) + isolated_atom = ase.Atoms("O", positions=[[0, 0, 24]]) + atoms = slab + isolated_atom + + time_step = 64 + device = "cuda" if torch.cuda.is_available() else "cpu" + energy_model, _ = get_pretrained("pet-omatpes-v2", time_step) + calculator = EnergyCalculator(energy_model, device=device) + atoms.calc = calculator + + dyn = VelocityVerlet(atoms=atoms, timestep=time_step * ase.units.fs) + dyn.run(10)