From e4fe2f37f0fb83b4038a992a2536c998a215c290 Mon Sep 17 00:00:00 2001 From: Peter Kroon Date: Tue, 10 Dec 2024 14:48:47 +0100 Subject: [PATCH] Apply modifications mappings from large to small --- vermouth/processors/do_mapping.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vermouth/processors/do_mapping.py b/vermouth/processors/do_mapping.py index 0543e7d5b..c3f8fe117 100644 --- a/vermouth/processors/do_mapping.py +++ b/vermouth/processors/do_mapping.py @@ -282,7 +282,9 @@ def modification_matches(molecule, mappings): matches = [] # Sort on the tuple[str] type names of the mappings so that mappings that # define most modifications at the same time get processed first - for mod_name in sorted(needed_mod_mappings, key=len, reverse=True): + for mod_name in sorted(needed_mod_mappings, + key=lambda ms: (len(ms), len(known_mod_mappings[ms].block_from.nodes)), + reverse=True): mod_mapping = known_mod_mappings[mod_name] for mol_to_mod, modification, references in mod_mapping.map(molecule, node_match=ptm_resname_match): matches.append((mol_to_mod, modification, references))