Skip to content

Commit

Permalink
Move all test to new folder (duartegroup#108)
Browse files Browse the repository at this point in the history
* Move all test to new folder

* Test only mlptrain folder

* Add fixtures

* Remove molecules.py
  • Loading branch information
juraskov authored Nov 3, 2024
1 parent 2e9755a commit 4bd5c1f
Show file tree
Hide file tree
Showing 22 changed files with 135 additions and 139 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
run: ./install_gap.sh

- name: Test basic install
run: pytest --cov -k "not test_openmm"
run: pytest --cov=mlptrain -k "not test_openmm"

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:
run: ./install_ace.sh

- name: Test ACE
run: pytest --cov -k "not test_openmm"
run: pytest --cov=mlptrain -k "not test_openmm"

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
Expand Down Expand Up @@ -121,7 +121,7 @@ jobs:
run: ./install_mace.sh

- name: Test MACE install
run: pytest --cov
run: pytest --cov=mlptrain

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
- id: check-shebang-scripts-are-executable
- id: check-added-large-files
args: ['--maxkb=500', '--enforce-all']
exclude: mlptrain/sampling/tests/data.zip
exclude: tests/data/data.zip
- id: check-yaml
- id: check-toml

Expand Down
Empty file.
File renamed without changes.
23 changes: 21 additions & 2 deletions mlptrain/sampling/tests/molecules.py → tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import mlptrain as mlt
import pytest
from autode.atoms import Atom


def _h2():
@pytest.fixture
def h2():
"""Dihydrogen molecule"""
atoms = [
Atom('H', -0.80952, 2.49855, 0.0),
Expand All @@ -11,11 +13,28 @@ def _h2():
return mlt.Molecule(atoms=atoms, charge=0, mult=1)


def _h2o():
@pytest.fixture
def h2o():
"""Water molecule"""
atoms = [
Atom('H', 2.32670, 0.51322, 0.0),
Atom('H', 1.03337, 0.70894, -0.89333),
Atom('O', 1.35670, 0.51322, 0.0),
]
return mlt.Molecule(atoms=atoms, charge=0, mult=1)


@pytest.fixture
def h2_configuration(h2):
system = mlt.System(h2, box=[50, 50, 50])
config = system.random_configuration()

return config


@pytest.fixture
def h2o_configuration(h2o):
system = mlt.System(h2o, box=[50, 50, 50])
config = system.random_configuration()

return config
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions mlptrain/sampling/tests/test_bias.py → tests/test_bias.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import mlptrain as mlt
from mlptrain.utils import work_in_tmp_dir
from .test_potential import TestPotential
from .molecules import _h2

mlt.Config.n_cores = 1
here = os.path.abspath(os.path.dirname(__file__))
Expand All @@ -21,8 +20,8 @@ def _get_avg_dists(atoms, atom_pair_list):


@work_in_tmp_dir()
def test_bias():
system = mlt.System(_h2(), box=[50, 50, 50])
def test_bias(h2):
system = mlt.System(h2, box=[50, 50, 50])
pot = TestPotential('1D')

config = system.random_configuration()
Expand Down
File renamed without changes.
File renamed without changes.
43 changes: 14 additions & 29 deletions mlptrain/sampling/tests/test_md.py → tests/test_md.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,17 @@
from ase.io.trajectory import Trajectory as ASETrajectory
from ase.constraints import Hookean
from .test_potential import TestPotential
from .molecules import _h2, _h2o
from .utils import work_in_zipped_dir
from .data.utils import work_in_zipped_dir

here = os.path.abspath(os.path.dirname(__file__))


def _h2_configuration():
system = mlt.System(_h2(), box=[50, 50, 50])
config = system.random_configuration()

return config


def _h2o_configuration():
system = mlt.System(_h2o(), box=[50, 50, 50])
config = system.random_configuration()

return config


@work_in_zipped_dir(os.path.join(here, 'data.zip'))
def test_md_full_plumed_input():
@work_in_zipped_dir(os.path.join(here, 'data/data.zip'))
def test_md_full_plumed_input(h2o_configuration):
bias = mlt.PlumedBias(filename='plumed_bias_nopath.dat')

mlt.md.run_mlp_md(
configuration=_h2o_configuration(),
configuration=h2o_configuration,
mlp=TestPotential('1D'),
temp=300,
dt=1,
Expand All @@ -43,13 +28,13 @@ def test_md_full_plumed_input():
assert os.path.exists('HILLS.dat')


@work_in_zipped_dir(os.path.join(here, 'data.zip'))
def test_md_restart():
atoms = _h2_configuration().ase_atoms
@work_in_zipped_dir(os.path.join(here, 'data/data.zip'))
def test_md_restart(h2_configuration):
atoms = h2_configuration.ase_atoms
initial_trajectory = ASETrajectory('md_restart.traj', 'r', atoms)

mlt.md.run_mlp_md(
configuration=_h2_configuration(),
configuration=h2_configuration,
mlp=TestPotential('1D'),
temp=300,
dt=1,
Expand All @@ -70,10 +55,10 @@ def test_md_restart():
assert len(final_trajectory) == 1001 + 101 - 1


@work_in_zipped_dir(os.path.join(here, 'data.zip'))
def test_md_save():
@work_in_zipped_dir(os.path.join(here, 'data/data.zip'))
def test_md_save(h2_configuration):
mlt.md.run_mlp_md(
configuration=_h2_configuration(),
configuration=h2_configuration,
mlp=TestPotential('1D'),
temp=300,
dt=1,
Expand All @@ -96,15 +81,15 @@ def test_md_save():
assert len(traj_200fs) == 20 + 1


@work_in_zipped_dir(os.path.join(here, 'data.zip'))
def test_md_traj_attachments():
@work_in_zipped_dir(os.path.join(here, 'data/data.zip'))
def test_md_traj_attachments(h2o_configuration):
cv1 = mlt.PlumedAverageCV('cv1', (0, 1))
bias = mlt.PlumedBias(cvs=cv1)

hookean_constraint = Hookean(a1=1, a2=2, k=100, rt=0.5)

traj = mlt.md.run_mlp_md(
configuration=_h2o_configuration(),
configuration=h2o_configuration,
mlp=TestPotential('1D'),
temp=300,
dt=1,
Expand Down
Loading

0 comments on commit 4bd5c1f

Please sign in to comment.