Skip to content

Commit 6e0ddae

Browse files
authored
Merge branch 'main' into maint/pydantic_3.13
2 parents 2753207 + c68e34b commit 6e0ddae

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

news/empty_mapping_validation.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* <news item>
4+
5+
**Changed:**
6+
7+
* The RelativeHybridTopologyProtocol will now raise a ValueError during validation if the atom mapping is empty preventing execution of the simulation.
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

src/openfe/protocols/openmm_rfe/hybridtop_protocols.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ def _validate_mapping(
274274
ValueError
275275
* If there are more than one mapping or mapping is None
276276
* If the mapping components are not in the alchemical components.
277+
* If the atom mapping is empty.
277278
"""
278279
# if a single mapping is provided, convert to list
279280
if isinstance(mapping, ComponentMapping):
@@ -294,6 +295,10 @@ def _validate_mapping(
294295
f"in alchemical components of state{state}"
295296
)
296297

298+
# make sure the mapping is not empty
299+
if not m.componentA_to_componentB:
300+
raise ValueError("No atoms are mapped between the two alchemical components.")
301+
297302
@staticmethod
298303
def _validate_smcs(
299304
stateA: ChemicalSystem,

src/openfe/tests/protocols/openmm_rfe/test_hybrid_top_protocol.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,3 +2541,27 @@ def fake_gather(*args, ligand_selection="resname UNK"):
25412541
)
25422542

25432543
assert captured["ligand_selection"] == "resname LIG"
2544+
2545+
2546+
def test_empty_atom_mapping(tmp_path, benzene_vacuum_system, toluene_vacuum_system, vac_settings):
2547+
"""Make sure an informative error is raised if the user supplies an empty atom mapping which is not supported."""
2548+
2549+
protocol = openmm_rfe.RelativeHybridTopologyProtocol(
2550+
settings=vac_settings,
2551+
)
2552+
2553+
blank_mapping = gufe.LigandAtomMapping(
2554+
componentA=benzene_vacuum_system["ligand"],
2555+
componentB=toluene_vacuum_system["ligand"],
2556+
componentA_to_componentB={},
2557+
)
2558+
2559+
with pytest.raises(
2560+
ValueError, match="No atoms are mapped between the two alchemical components."
2561+
):
2562+
# create the DAG and run validation
2563+
_ = protocol.create(
2564+
stateA=benzene_vacuum_system,
2565+
stateB=toluene_vacuum_system,
2566+
mapping=blank_mapping,
2567+
)

0 commit comments

Comments
 (0)