Skip to content

Commit f94e49c

Browse files
committed
tests: add tests for water-bridge from iterable
1 parent c0d2190 commit f94e49c

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

tests/conftest.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,27 @@ def water_u():
178178

179179

180180
@pytest.fixture(scope="session")
181-
def water_params(water_u):
181+
def water_atomgroups(water_u):
182182
ligand = water_u.select_atoms("resname QNB")
183183
protein = water_u.select_atoms(
184184
"protein and byres around 4 group ligand", ligand=ligand
185185
)
186186
water = water_u.select_atoms(
187-
"resname TIP3 and byres around 6 (group ligand or group pocket)",
187+
"resname TIP3 and byres around 4 (group ligand or group pocket)",
188188
ligand=ligand,
189189
pocket=protein,
190190
)
191191
return ligand, protein, water
192192

193193

194+
@pytest.fixture(scope="session")
195+
def water_mols(water_atomgroups):
196+
lig_mol = Molecule.from_mda(water_atomgroups[0])
197+
prot_mol = Molecule.from_mda(water_atomgroups[1])
198+
water_mol = Molecule.from_mda(water_atomgroups[2])
199+
return lig_mol, prot_mol, water_mol
200+
201+
194202
class BaseTestMixinRDKitMol:
195203
def test_init(self, mol):
196204
assert isinstance(mol, Chem.Mol)

tests/test_fingerprint.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ def test_water_bridge_instance_without_params_raises_error(self):
345345
):
346346
Fingerprint(["WaterBridge"])
347347

348-
def test_mix_water_bridge_and_other_interactions(self, water_u, water_params):
349-
ligand, protein, water = water_params
348+
def test_mix_water_bridge_and_other_interactions(self, water_u, water_atomgroups):
349+
ligand, protein, water = water_atomgroups
350350
fp = Fingerprint(
351351
["HBDonor", "WaterBridge"], parameters={"WaterBridge": {"water": water}}
352352
)
@@ -355,8 +355,20 @@ def test_mix_water_bridge_and_other_interactions(self, water_u, water_params):
355355
assert "WaterBridge" in fp.ifp[0]["QNB1.X", "TRP400.X"]
356356
assert "HBDonor" in fp.ifp[0]["QNB1.X", "ASN404.X"]
357357

358-
def test_water_bridge_updates_cache_size(self, water_u, water_params, monkeypatch):
359-
ligand, protein, water = water_params
358+
def test_water_bridge_run_iter(self, water_mols):
359+
ligand, protein, water = water_mols
360+
fp = Fingerprint(
361+
["HBDonor", "WaterBridge"], parameters={"WaterBridge": {"water": water}}
362+
)
363+
fp.run_from_iterable([ligand], protein)
364+
365+
assert "WaterBridge" in fp.ifp[0]["QNB1.X", "TRP400.X"]
366+
assert "HBDonor" in fp.ifp[0]["QNB1.X", "ASN404.X"]
367+
368+
def test_water_bridge_updates_cache_size(
369+
self, water_u, water_atomgroups, monkeypatch
370+
):
371+
ligand, protein, water = water_atomgroups
360372
set_converter_cache_size(2)
361373
mocked = Mock(wraps=set_converter_cache_size)
362374
monkeypatch.setattr(

tests/test_interactions.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,16 +357,16 @@ class TestBridgedInteractions:
357357
({"order": 1, "min_order": 2}, "min_order cannot be greater than order"),
358358
],
359359
)
360-
def test_water_bridge_validation(self, water_params, kwargs, match):
361-
*_, water = water_params
360+
def test_water_bridge_validation(self, water_atomgroups, kwargs, match):
361+
*_, water = water_atomgroups
362362
with pytest.raises(ValueError, match=match):
363363
Fingerprint(
364364
["WaterBridge"],
365365
parameters={"WaterBridge": {"water": water, **kwargs}},
366366
)
367367

368-
def test_direct_water_bridge(self, water_u, water_params):
369-
ligand, protein, water = water_params
368+
def test_direct_water_bridge(self, water_u, water_atomgroups):
369+
ligand, protein, water = water_atomgroups
370370
fp = Fingerprint(["WaterBridge"], parameters={"WaterBridge": {"water": water}})
371371
fp.run(water_u.trajectory[:1], ligand, protein)
372372
int_data = next(fp.ifp[0].interactions())
@@ -395,3 +395,13 @@ def test_higher_order_water_bridge(self, water_u, kwargs, num_expected):
395395
assert len(all_int_data) == num_expected
396396
int_data = all_int_data[-1]
397397
assert "distance_TIP383.X_TIP317.X" in int_data.metadata
398+
399+
def test_run_iter_water_bridge(self, water_mols):
400+
ligand, protein, water = water_mols
401+
fp = Fingerprint(["WaterBridge"], parameters={"WaterBridge": {"water": water}})
402+
# mimick multiple poses
403+
fp.run_from_iterable([ligand, ligand], protein)
404+
int_data = next(fp.ifp[1].interactions())
405+
406+
assert int_data.interaction == "WaterBridge"
407+
assert str(int_data.protein) == "TRP400.X"

0 commit comments

Comments
 (0)