diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index bf86e808..958dcd7a 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -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 @@ -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 @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ade846a5..5c1d0ad9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/mlptrain/training/tests/__init__.py b/mlptrain/training/tests/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/mlptrain/configurations/tests/__init__.py b/tests/__init__.py similarity index 100% rename from mlptrain/configurations/tests/__init__.py rename to tests/__init__.py diff --git a/mlptrain/sampling/tests/molecules.py b/tests/conftest.py similarity index 56% rename from mlptrain/sampling/tests/molecules.py rename to tests/conftest.py index a5142fd7..611640cb 100644 --- a/mlptrain/sampling/tests/molecules.py +++ b/tests/conftest.py @@ -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), @@ -11,7 +13,8 @@ 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), @@ -19,3 +22,19 @@ def _h2o(): 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 diff --git a/mlptrain/sampling/tests/__init__.py b/tests/data/__init__.py similarity index 100% rename from mlptrain/sampling/tests/__init__.py rename to tests/data/__init__.py diff --git a/mlptrain/sampling/tests/data.zip b/tests/data/data.zip similarity index 100% rename from mlptrain/sampling/tests/data.zip rename to tests/data/data.zip diff --git a/mlptrain/training/tests/data/methane.xyz b/tests/data/methane.xyz similarity index 100% rename from mlptrain/training/tests/data/methane.xyz rename to tests/data/methane.xyz diff --git a/mlptrain/sampling/tests/utils.py b/tests/data/utils.py similarity index 100% rename from mlptrain/sampling/tests/utils.py rename to tests/data/utils.py diff --git a/mlptrain/sampling/tests/test_bias.py b/tests/test_bias.py similarity index 94% rename from mlptrain/sampling/tests/test_bias.py rename to tests/test_bias.py index 468deb08..40945e06 100644 --- a/mlptrain/sampling/tests/test_bias.py +++ b/tests/test_bias.py @@ -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__)) @@ -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() diff --git a/mlptrain/configurations/tests/test_configuration.py b/tests/test_configuration.py similarity index 100% rename from mlptrain/configurations/tests/test_configuration.py rename to tests/test_configuration.py diff --git a/mlptrain/configurations/tests/test_configuration_set.py b/tests/test_configuration_set.py similarity index 100% rename from mlptrain/configurations/tests/test_configuration_set.py rename to tests/test_configuration_set.py diff --git a/mlptrain/sampling/tests/test_md.py b/tests/test_md.py similarity index 74% rename from mlptrain/sampling/tests/test_md.py rename to tests/test_md.py index 1fc8e3af..f165c6d7 100644 --- a/mlptrain/sampling/tests/test_md.py +++ b/tests/test_md.py @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/mlptrain/sampling/tests/test_metadynamics.py b/tests/test_metadynamics.py similarity index 75% rename from mlptrain/sampling/tests/test_metadynamics.py rename to tests/test_metadynamics.py index 54c501e9..8d196353 100644 --- a/mlptrain/sampling/tests/test_metadynamics.py +++ b/tests/test_metadynamics.py @@ -1,70 +1,59 @@ import os import numpy as np import mlptrain as mlt +import pytest from ase.io.trajectory import Trajectory as ASETrajectory 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 mlt.Config.n_cores = 2 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 - - -def _run_metadynamics( - metadynamics, - n_runs, - configuration=None, - al_iter=None, - save_sep=False, - all_to_xyz=False, - restart=False, - **kwargs, -): - if configuration is None: - configuration = _h2_configuration() - - metadynamics.run_metadynamics( - configuration=configuration, - mlp=TestPotential('1D'), - temp=300, - dt=1, - interval=10, - pace=100, - width=0.05, - height=0.1, - biasfactor=3, - al_iter=al_iter, - n_runs=n_runs, - save_sep=save_sep, - all_to_xyz=all_to_xyz, - restart=restart, +@pytest.fixture +def run_metadynamics(): + def _run_metadynamics( + metad, + n_runs, + configuration, + al_iter=None, + save_sep=False, + all_to_xyz=False, + restart=False, **kwargs, - ) + ): + metad.run_metadynamics( + configuration=configuration, + mlp=TestPotential('1D'), + temp=300, + dt=1, + interval=10, + pace=100, + width=0.05, + height=0.1, + biasfactor=3, + al_iter=al_iter, + n_runs=n_runs, + save_sep=save_sep, + all_to_xyz=all_to_xyz, + restart=restart, + **kwargs, + ) + + return _run_metadynamics -@work_in_zipped_dir(os.path.join(here, 'data.zip')) -def test_run_metadynamics(): +@work_in_zipped_dir(os.path.join(here, 'data/data.zip')) +def test_run_metadynamics(h2_configuration, run_metadynamics): cv1 = mlt.PlumedAverageCV('cv1', (0, 1)) metad = mlt.Metadynamics(cv1) n_runs = 4 assert metad.bias is not None - _run_metadynamics(metad, n_runs, all_to_xyz=True, save_fs=200, fs=500) + run_metadynamics( + metad, n_runs, h2_configuration, all_to_xyz=True, save_fs=200, fs=500 + ) assert os.path.exists('trajectories') assert os.path.exists('trajectories/combined_trajectory.xyz') @@ -112,15 +101,15 @@ def test_run_metadynamics(): assert os.path.exists('fes_convergence/fes_convergence.pdf') -@work_in_zipped_dir(os.path.join(here, 'data.zip')) -def test_run_metadynamics_restart(): +@work_in_zipped_dir(os.path.join(here, 'data/data.zip')) +def test_run_metadynamics_restart(h2_configuration, run_metadynamics): cv1 = mlt.PlumedAverageCV('cv1', (0, 1)) metad = mlt.Metadynamics(cv1) n_runs = 4 - _run_metadynamics(metad, n_runs, fs=500) + run_metadynamics(metad, n_runs, h2_configuration, fs=500) - _run_metadynamics(metad, n_runs, restart=True, fs=500) + run_metadynamics(metad, n_runs, h2_configuration, restart=True, fs=500) n_steps = len( np.loadtxt('plumed_files/metadynamics/colvar_cv1_1.dat', usecols=0) @@ -144,15 +133,19 @@ def test_run_metadynamics_restart(): assert len(trajectory) == 51 + 51 - 1 -@work_in_zipped_dir(os.path.join(here, 'data.zip')) -def test_run_metadynamics_with_inherited_bias(): +@work_in_zipped_dir(os.path.join(here, 'data/data.zip')) +def test_run_metadynamics_with_inherited_bias( + h2_configuration, run_metadynamics +): cv1 = mlt.PlumedAverageCV('cv1', (0, 1)) metad = mlt.Metadynamics(cv1) n_runs = 4 - _run_metadynamics(metad, n_runs, al_iter=3, fs=500) + run_metadynamics(metad, n_runs, h2_configuration, al_iter=3, fs=500) - _run_metadynamics(metad, n_runs, al_iter=3, restart=True, fs=500) + run_metadynamics( + metad, n_runs, h2_configuration, al_iter=3, restart=True, fs=500 + ) metad_dir = 'plumed_files/metadynamics' for idx in range(1, n_runs + 1): @@ -165,13 +158,13 @@ def test_run_metadynamics_with_inherited_bias(): assert os.path.exists('fes_raw.npy') -@work_in_zipped_dir(os.path.join(here, 'data.zip')) -def test_run_metadynamics_with_component(): +@work_in_zipped_dir(os.path.join(here, 'data/data.zip')) +def test_run_metadynamics_with_component(h2_configuration, run_metadynamics): cv1 = mlt.PlumedCustomCV('plumed_cv_dist.dat', 'x') metad = mlt.Metadynamics(cv1) n_runs = 4 - _run_metadynamics(metad, n_runs, fs=100) + run_metadynamics(metad, n_runs, h2_configuration, fs=100) metad_dir = 'plumed_files/metadynamics' for idx in range(1, n_runs + 1): @@ -180,8 +173,10 @@ def test_run_metadynamics_with_component(): ) -@work_in_zipped_dir(os.path.join(here, 'data.zip')) -def test_run_metadynamics_with_additional_cvs(): +@work_in_zipped_dir(os.path.join(here, 'data/data.zip')) +def test_run_metadynamics_with_additional_cvs( + h2o_configuration, run_metadynamics +): cv1 = mlt.PlumedAverageCV('cv1', (0, 1)) cv2 = mlt.PlumedAverageCV('cv2', (2, 1)) cv2.attach_upper_wall(location=3.0, kappa=150.0) @@ -194,9 +189,9 @@ def test_run_metadynamics_with_additional_cvs(): assert metad.n_cvs == 1 n_runs = 1 - _run_metadynamics( + run_metadynamics( metad, - configuration=_h2o_configuration(), + configuration=h2o_configuration, n_runs=n_runs, write_plumed_setup=True, fs=100, @@ -222,13 +217,13 @@ def test_run_metadynamics_with_additional_cvs(): ] -@work_in_zipped_dir(os.path.join(here, 'data.zip')) -def test_estimate_width(): +@work_in_zipped_dir(os.path.join(here, 'data/data.zip')) +def test_estimate_width(h2_configuration): cv1 = mlt.PlumedAverageCV('cv1', (0, 1)) metad = mlt.Metadynamics(cv1) width = metad.estimate_width( - configurations=_h2_configuration(), + configurations=h2_configuration, mlp=TestPotential('1D'), plot=True, fs=100, @@ -246,14 +241,14 @@ def test_estimate_width(): assert os.path.exists(os.path.join(plots_directory, 'cv1_config1.pdf')) -@work_in_zipped_dir(os.path.join(here, 'data.zip')) -def test_try_multiple_biasfactors(): +@work_in_zipped_dir(os.path.join(here, 'data/data.zip')) +def test_try_multiple_biasfactors(h2_configuration): cv1 = mlt.PlumedAverageCV('cv1', (0, 1)) metad = mlt.Metadynamics(cv1) biasfactors = range(5, 11, 5) metad.try_multiple_biasfactors( - configuration=_h2_configuration(), + configuration=h2_configuration, mlp=TestPotential('1D'), temp=300, interval=10, @@ -277,8 +272,8 @@ def test_try_multiple_biasfactors(): assert os.path.exists(os.path.join(plots_dir, f'cv1_biasf{biasf}.pdf')) -@work_in_zipped_dir(os.path.join(here, 'data.zip')) -def test_block_analysis(): +@work_in_zipped_dir(os.path.join(here, 'data/data.zip')) +def test_block_analysis(h2_configuration): cv1 = mlt.PlumedAverageCV('cv1', (0, 1)) metad = mlt.Metadynamics(cv1) dt = 1 @@ -288,7 +283,7 @@ def test_block_analysis(): start_time = 0.5 metad.run_metadynamics( - configuration=_h2_configuration(), + configuration=h2_configuration, mlp=TestPotential('1D'), temp=300, dt=dt, diff --git a/mlptrain/sampling/tests/test_openmm_md.py b/tests/test_openmm_md.py similarity index 92% rename from mlptrain/sampling/tests/test_openmm_md.py rename to tests/test_openmm_md.py index 26022f76..83caee4f 100644 --- a/mlptrain/sampling/tests/test_openmm_md.py +++ b/tests/test_openmm_md.py @@ -4,8 +4,7 @@ import pytest from ase.io.trajectory import Trajectory as ASETrajectory -from .molecules import _h2, _h2o -from .utils import work_in_zipped_dir +from .data.utils import work_in_zipped_dir import ase.units @@ -15,20 +14,20 @@ @pytest.fixture -def h2_system_config(): - system = mlt.System(_h2(), box=[50, 50, 50]) +def h2_system_config(h2): + system = mlt.System(h2, box=[50, 50, 50]) config = system.random_configuration() return system, config @pytest.fixture -def h2o_system_config(): - system = mlt.System(_h2o(), box=[50, 50, 50]) +def h2o_system_config(h2o): + system = mlt.System(h2o, box=[50, 50, 50]) config = system.random_configuration() return system, config -@work_in_zipped_dir(os.path.join(here, 'data.zip')) +@work_in_zipped_dir(os.path.join(here, 'data/data.zip')) def test_openmm_topology(h2_system_config, h2o_system_config): """Test the creation of an OpenMM Topology from an ASE Atoms object.""" # H2 molecule @@ -58,7 +57,7 @@ def test_openmm_topology(h2_system_config, h2o_system_config): ) -@work_in_zipped_dir(os.path.join(here, 'data.zip')) +@work_in_zipped_dir(os.path.join(here, 'data/data.zip')) def test_openmm_simulation(h2o_system_config): """Test the OpenMM Simulation object.""" # H2O molecule @@ -116,7 +115,7 @@ def test_openmm_simulation_name_generation(): assert name == state_file -@work_in_zipped_dir(os.path.join(here, 'data.zip')) +@work_in_zipped_dir(os.path.join(here, 'data/data.zip')) def test_openmm_md(h2o_system_config): """Test the OpenMM MD simulation.""" # H2O molecule @@ -142,7 +141,7 @@ def test_openmm_md(h2o_system_config): assert len(traj) == 11 -@work_in_zipped_dir(os.path.join(here, 'data.zip')) +@work_in_zipped_dir(os.path.join(here, 'data/data.zip')) def test_openmm_md_restart(h2o_system_config): """Test the MD restart functionality.""" system, config = h2o_system_config @@ -172,7 +171,7 @@ def test_openmm_md_restart(h2o_system_config): assert len(final_trajectory) == 1001 + 11 - 1 -@work_in_zipped_dir(os.path.join(here, 'data.zip')) +@work_in_zipped_dir(os.path.join(here, 'data/data.zip')) def test_openmm_md_save(h2o_system_config): """Test the MD save functionality.""" system, config = h2o_system_config diff --git a/mlptrain/sampling/tests/test_plumed.py b/tests/test_plumed.py similarity index 96% rename from mlptrain/sampling/tests/test_plumed.py rename to tests/test_plumed.py index ba16cebc..a315177e 100644 --- a/mlptrain/sampling/tests/test_plumed.py +++ b/tests/test_plumed.py @@ -1,7 +1,7 @@ import os import pytest import mlptrain as mlt -from .utils import work_in_zipped_dir +from .data.utils import work_in_zipped_dir here = os.path.abspath(os.path.dirname(__file__)) @@ -55,7 +55,7 @@ def test_plumed_cv_from_atom_groups(): mlt.PlumedDifferenceCV('', ((0, 1), (2, 3), (4, 5))) -@work_in_zipped_dir(os.path.join(here, 'data.zip')) +@work_in_zipped_dir(os.path.join(here, 'data/data.zip')) def test_plumed_cv_from_file(): cv1 = mlt.PlumedCustomCV( 'plumed_cv_custom.dat', component='spath', units='Å' @@ -147,7 +147,7 @@ def test_plumed_bias_from_cvs(): assert value is None -@work_in_zipped_dir(os.path.join(here, 'data.zip')) +@work_in_zipped_dir(os.path.join(here, 'data/data.zip')) def test_plumed_bias_from_file(): bias = mlt.PlumedBias(filename='plumed_bias.dat') @@ -190,7 +190,7 @@ def test_plumed_bias_from_file(): ] -@work_in_zipped_dir(os.path.join(here, 'data.zip')) +@work_in_zipped_dir(os.path.join(here, 'data/data.zip')) def test_plumed_plot(): colvar1 = 'test_plumed_plot/colvar1.dat' colvar2 = 'test_plumed_plot/colvar2.dat' diff --git a/mlptrain/sampling/tests/test_potential.py b/tests/test_potential.py similarity index 100% rename from mlptrain/sampling/tests/test_potential.py rename to tests/test_potential.py diff --git a/mlptrain/sampling/tests/test_reaction_coord.py b/tests/test_reaction_coord.py similarity index 92% rename from mlptrain/sampling/tests/test_reaction_coord.py rename to tests/test_reaction_coord.py index 1bf8fc14..5d8c5494 100644 --- a/mlptrain/sampling/tests/test_reaction_coord.py +++ b/tests/test_reaction_coord.py @@ -3,15 +3,12 @@ import mlptrain as mlt from ase.atoms import Atoms as ASEAtoms -from .molecules import _h2o -def test_differencedistance(): +def test_differencedistance(h2o_configuration): """Test the DifferenceDistance class for reaction coordinate""" - system = mlt.System(_h2o(), box=[50, 50, 50]) - - config = system.random_configuration() + config = h2o_configuration atoms = config.ase_atoms diff_dist = mlt.DifferenceDistance((0, 1), (0, 2)) diff --git a/mlptrain/training/tests/test_selection.py b/tests/test_selection.py similarity index 100% rename from mlptrain/training/tests/test_selection.py rename to tests/test_selection.py diff --git a/mlptrain/configurations/tests/test_trajectory.py b/tests/test_trajectory.py similarity index 100% rename from mlptrain/configurations/tests/test_trajectory.py rename to tests/test_trajectory.py diff --git a/mlptrain/sampling/tests/test_umbrella.py b/tests/test_umbrella.py similarity index 93% rename from mlptrain/sampling/tests/test_umbrella.py rename to tests/test_umbrella.py index 3a1c9956..95e36d60 100644 --- a/mlptrain/sampling/tests/test_umbrella.py +++ b/tests/test_umbrella.py @@ -6,7 +6,7 @@ import mlptrain as mlt from .test_potential import TestPotential -from .utils import work_in_zipped_dir +from .data.utils import work_in_zipped_dir here = os.path.abspath(os.path.dirname(__file__)) @@ -19,7 +19,9 @@ def _h2_umbrella(): def _h2_pulled_traj(): traj = mlt.ConfigurationSet() - traj.load_xyz(os.path.join(here, 'data', 'h2_traj.xyz'), charge=0, mult=1) + traj.load_xyz( + os.path.join(here, 'data/data', 'h2_traj.xyz'), charge=0, mult=1 + ) return traj @@ -33,7 +35,7 @@ def _h2_sparse_traj(): return sparse_traj -@work_in_zipped_dir(os.path.join(here, 'data.zip')) +@work_in_zipped_dir(os.path.join(here, 'data/data.zip')) def test_run_umbrella(): umbrella = _h2_umbrella() traj = _h2_pulled_traj() @@ -83,7 +85,7 @@ def test_run_umbrella(): # TODO: This tests fails on GHA with MACE install, # need to investigate more, for now skipping. -@work_in_zipped_dir(os.path.join(here, 'data.zip')) +@work_in_zipped_dir(os.path.join(here, 'data/data.zip')) @pytest.mark.skip(reason='Test fails on GHA with MACE') def test_umbrella_parallel(): execution_time = {} @@ -112,7 +114,7 @@ def test_umbrella_parallel(): assert execution_time[2] < execution_time[1] -@work_in_zipped_dir(os.path.join(here, 'data.zip')) +@work_in_zipped_dir(os.path.join(here, 'data/data.zip')) def test_umbrella_sparse_traj(): umbrella = _h2_umbrella() traj = _h2_sparse_traj() @@ -168,7 +170,7 @@ def test_umbrella_sparse_traj(): assert starting_frame == closest_frame -@work_in_zipped_dir(os.path.join(here, 'data.zip')) +@work_in_zipped_dir(os.path.join(here, 'data/data.zip')) def test_umbrella_save_load(): umbrella = _h2_umbrella() traj = _h2_pulled_traj() diff --git a/mlptrain/sampling/tests/test_wham.py b/tests/test_wham.py similarity index 93% rename from mlptrain/sampling/tests/test_wham.py rename to tests/test_wham.py index 9576d67b..635436ee 100644 --- a/mlptrain/sampling/tests/test_wham.py +++ b/tests/test_wham.py @@ -2,7 +2,7 @@ import numpy as np from mlptrain.sampling.bias import Bias from mlptrain.sampling.umbrella import _Window, UmbrellaSampling -from .utils import work_in_zipped_dir +from .data.utils import work_in_zipped_dir here = os.path.dirname(os.path.abspath(__file__)) @@ -40,7 +40,7 @@ def _initialised_us() -> UmbrellaSampling: return us -@work_in_zipped_dir(os.path.join(here, 'data.zip')) +@work_in_zipped_dir(os.path.join(here, 'data/data.zip')) def test_wham_is_close_to_ref(): us = _initialised_us() zetas, free_energies = us.wham(n_bins=499) @@ -65,7 +65,7 @@ def test_wham_is_close_to_ref(): assert np.isclose(free_energy, ref_free_energies[close_idx], atol=0.02) -@work_in_zipped_dir(os.path.join(here, 'data.zip')) +@work_in_zipped_dir(os.path.join(here, 'data/data.zip')) def test_wham_is_somewhat_independent_of_nbins(): us = _initialised_us() _, free_energies_500bins = us.wham(n_bins=500)