Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having some issues with xdist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the nc files don't play well, had a crashed worker

- name: "Save pooch test data cache"
id: cache-testdata-save
uses: actions/cache/save@v3
Expand Down
66 changes: 66 additions & 0 deletions src/tests/test_transformations.py
Original file line number Diff line number Diff line change
@@ -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)