From 5905ed9e7808c22f0ba26eb11200fa7dd6e121f9 Mon Sep 17 00:00:00 2001 From: richard gowers Date: Fri, 8 Sep 2023 16:18:51 +0100 Subject: [PATCH 1/2] add tests for trajectory transforms --- src/tests/test_transformations.py | 66 +++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/tests/test_transformations.py diff --git a/src/tests/test_transformations.py b/src/tests/test_transformations.py new file mode 100644 index 0000000..9f63a9b --- /dev/null +++ b/src/tests/test_transformations.py @@ -0,0 +1,66 @@ +import MDAnalysis as mda +from MDAnalysis.analysis import rms +import numpy as np +import pytest + +from openfe_analysis import FEReader +from openfe_analysis.transformations import ( + Minimiser, + NoJump, + Aligner, +) + + +@pytest.fixture +def universe(hybrid_system_pdb, simulation_nc): + return mda.Universe( + hybrid_system_pdb, simulation_nc, + format='openfe rfe', + state_id=0, + ) + + +def test_minimiser(universe): + prot = universe.select_atoms('protein and name CA') + lig = universe.select_atoms('resname UNK') + m = Minimiser(prot, lig) + universe.trajectory.add_transformations(m) + + 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) + + +def test_nojump(universe): + # find frame where protein would teleport across boundary and check it + prot = universe.select_atoms('protein and name CA') + + nj = NoJump(prot) + universe.trajectory.add_transformations(nj) + + universe.trajectory[169] + universe.trajectory[170] + + # without the transformation, the y coordinate would jump up to ~81.86 + ref = np.array([72.37, -0.27, 66.49]) + assert prot.center_of_mass() == pytest.approx(ref, abs=0.01) + + +def test_aligner(universe): + # checks that rmsd is identical with/without center&super + prot = universe.select_atoms('protein and name CA') + a = Aligner(prot) + universe.trajectory.add_transformations(a) + + p1 = prot.positions + universe.trajectory[1] + + raw_rmsd = rms.rmsd(prot.positions, p1, center=False, superposition=False) + opt_rmsd = rms.rmsd(prot.positions, p1, center=True, superposition=True) + + # the rmsd should be identical even if the function didn't align + # as the transformation should have done this + assert raw_rmsd == pytest.approx(opt_rmsd) From 73f3e9a12367d6cb4fe19077f813a67fc0d878e5 Mon Sep 17 00:00:00 2001 From: richard gowers Date: Fri, 8 Sep 2023 16:21:43 +0100 Subject: [PATCH 2/2] run tests in serial, maybe nc will crash less --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a8123e9..32f066d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -53,7 +53,7 @@ jobs: python -Ic "import openfe_analysis; print(openfe_analysis.__version__)" - name: "Run tests" run: | - pytest -n auto -v --cov=openfe_analysis --cov-report=xml --durations=10 + pytest -n 1 -v --cov=openfe_analysis --cov-report=xml --durations=10 - name: "Save pooch test data cache" id: cache-testdata-save uses: actions/cache/save@v3