Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@ jobs:
python=${{ matrix.python-version }}
init-shell: bash

- name: "Download Zenodo data"
run: |
python - <<'EOF'
import pooch
from pathlib import Path

cache = Path(pooch.os_cache("openfe_analysis"))
cache.mkdir(parents=True, exist_ok=True)

zenodo = pooch.create(
path=cache,
base_url="doi:10.5281/zenodo.17916322",
registry={
"openfe_analysis_simulation_output.tar.gz": "md5:09752f2c4e5b7744d8afdee66dbd1414",
"openfe_analysis_skipped.tar.gz": "md5:3840d044299caacc4ccd50e6b22c0880",
},
)

zenodo.fetch("openfe_analysis_simulation_output.tar.gz", processor=pooch.Untar())
zenodo.fetch("openfe_analysis_skipped.tar.gz", processor=pooch.Untar())
EOF

- name: "Install"
run: |
python -m pip install --no-deps .
Expand All @@ -68,4 +90,4 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
file: coverage.xml
fail_ci_if_error: false
verbose: true
verbose: true
21 changes: 15 additions & 6 deletions src/openfe_analysis/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import pytest

POOCH_CACHE = pooch.os_cache("openfe_analysis")
POOCH_CACHE.mkdir(parents=True, exist_ok=True)

ZENODO_RBFE_DATA = pooch.create(
path=POOCH_CACHE,
base_url="doi:10.5281/zenodo.17916322",
Expand All @@ -14,17 +16,24 @@
},
)

def _fetch_and_untar_once(filename: str) -> pathlib.Path:
untar_dir = POOCH_CACHE / f"{filename}.untar"

if not untar_dir.exists():
ZENODO_RBFE_DATA.fetch(filename, processor=pooch.Untar())

return untar_dir

@pytest.fixture(scope="session")
def rbfe_output_data_dir() -> pathlib.Path:
ZENODO_RBFE_DATA.fetch("openfe_analysis_simulation_output.tar.gz", processor=pooch.Untar())
result_dir = pathlib.Path(POOCH_CACHE) / "openfe_analysis_simulation_output.tar.gz.untar/openfe_analysis_simulation_output/"
return result_dir
untar_dir = _fetch_and_untar_once("openfe_analysis_simulation_output.tar.gz")
return untar_dir / "openfe_analysis_simulation_output"


@pytest.fixture(scope="session")
def rbfe_skipped_data_dir() -> pathlib.Path:
ZENODO_RBFE_DATA.fetch("openfe_analysis_skipped.tar.gz", processor=pooch.Untar())
result_dir = pathlib.Path(POOCH_CACHE) / "openfe_analysis_skipped.tar.gz.untar/openfe_analysis_skipped/"
return result_dir
untar_dir = _fetch_and_untar_once("openfe_analysis_skipped.tar.gz")
return untar_dir / "openfe_analysis_skipped"

@pytest.fixture(scope="session")
def simulation_nc(rbfe_output_data_dir) -> pathlib.Path:
Expand Down
45 changes: 21 additions & 24 deletions src/openfe_analysis/tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,58 +106,55 @@ def test_universe_creation(simulation_nc, hybrid_system_pdb):
assert_allclose(u.dimensions, [82.191055, 82.191055, 82.191055, 90.0, 90.0, 90.0])


def test_universe_from_nc_file(simulation_nc, hybrid_system_pdb):
ds = nc.Dataset(simulation_nc)
def test_universe_from_nc_file(simulation_skipped_nc, hybrid_system_skipped_pdb):
ds = nc.Dataset(simulation_skipped_nc)

with pytest.warns(UserWarning, match="This is an older NetCDF file that"):
u = mda.Universe(hybrid_system_pdb, ds, format="MultiStateReporter", state_id=0)
u = mda.Universe(hybrid_system_skipped_pdb, ds, format="MultiStateReporter", state_id=0)

assert u
assert len(u.atoms) == 4782
assert len(u.trajectory) == 501
assert u.trajectory.dt == pytest.approx(1.0)

assert len(u.atoms) == 4762
assert len(u.trajectory) == 6
assert u.trajectory.dt == pytest.approx(100.0)

def test_universe_creation_noconversion(simulation_nc, hybrid_system_pdb):
with pytest.warns(UserWarning, match="This is an older NetCDF file that"):
u = mda.Universe(
hybrid_system_pdb, simulation_nc, format=FEReader, state_id=0, convert_units=False
)

def test_universe_creation_noconversion(simulation_skipped_nc, hybrid_system_skipped_pdb):
u = mda.Universe(
hybrid_system_skipped_pdb, simulation_skipped_nc, format=FEReader, state_id=0, convert_units=False
)
assert u.trajectory.ts.frame == 0
assert_allclose(
u.atoms[:3].positions,
np.array(
[
[6.51474, -1.7640617, 8.406607],
[6.641961, -1.8410535, 8.433087],
[6.71369, -1.8112476, 8.533738],
[2.778386, 2.733918, 6.116591],
[2.836767, 2.600875, 6.174912],
[2.917513, 2.604454, 6.273793],
]
),
atol=1e-6,
)


def test_fereader_negative_state(simulation_nc, hybrid_system_pdb):
with pytest.warns(UserWarning, match="This is an older NetCDF file that"):
u = mda.Universe(hybrid_system_pdb, simulation_nc, format=FEReader, state_id=-1)
def test_fereader_negative_state(simulation_skipped_nc, hybrid_system_skipped_pdb):
u = mda.Universe(hybrid_system_skipped_pdb, simulation_skipped_nc, format=FEReader, state_id=-1)

assert u.trajectory._state_id == 10
assert u.trajectory._replica_id is None


def test_fereader_negative_replica(simulation_nc, hybrid_system_pdb):
with pytest.warns(UserWarning, match="This is an older NetCDF file that"):
u = mda.Universe(hybrid_system_pdb, simulation_nc, format=FEReader, replica_id=-2)
def test_fereader_negative_replica(simulation_skipped_nc, hybrid_system_skipped_pdb):
u = mda.Universe(hybrid_system_skipped_pdb, simulation_skipped_nc, format=FEReader, replica_id=-2)

assert u.trajectory._state_id is None
assert u.trajectory._replica_id == 9


@pytest.mark.parametrize("rep_id, state_id", [[None, None], [1, 1]])
@pytest.mark.flaky(reruns=3)
def test_fereader_replica_state_id_error(simulation_nc, hybrid_system_pdb, rep_id, state_id):
def test_fereader_replica_state_id_error(simulation_skipped_nc, hybrid_system_skipped_pdb, rep_id, state_id):
with pytest.raises(ValueError, match="Specify one and only one"):
_ = mda.Universe(
hybrid_system_pdb, simulation_nc, format=FEReader, state_id=state_id, replica_id=rep_id
hybrid_system_skipped_pdb, simulation_skipped_nc, format=FEReader, state_id=state_id, replica_id=rep_id
)


Expand Down
16 changes: 11 additions & 5 deletions src/openfe_analysis/tests/test_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@


@pytest.fixture
def universe(hybrid_system_pdb, simulation_nc):
def universe(hybrid_system_skipped_pdb, simulation_skipped_nc):
return mda.Universe(
hybrid_system_pdb,
simulation_nc,
hybrid_system_skipped_pdb,
simulation_skipped_nc,
format="MultiStateReporter",
state_id=0,
)
Expand All @@ -31,11 +31,17 @@ def test_minimiser(universe):
d = mda.lib.distances.calc_bonds(prot.center_of_mass(), lig.center_of_mass())
# in the raw trajectory this is ~71 A as they're in diff images
# accounting for pbc should result in ~11.10
assert d == pytest.approx(11.10, abs=0.01)
assert d == pytest.approx(11.78, abs=0.01)


@pytest.mark.flaky(reruns=3)
def test_nojump(universe):
def test_nojump(hybrid_system_pdb, simulation_nc):
universe = mda.Universe(
hybrid_system_pdb,
simulation_nc,
format="MultiStateReporter",
state_id=0,
)
# find frame where protein would teleport across boundary and check it
prot = universe.select_atoms("protein and name CA")

Expand Down