From ee40860240c0109325649b3537cdf3084ead25f4 Mon Sep 17 00:00:00 2001
From: Gabriel Studer <gabriel.studer@unibas.ch>
Date: Thu, 23 May 2024 10:06:17 +0200
Subject: [PATCH] chain mapping: Avoid error for empty chem groups

Can occur in chain_mapping._ChainMappings that provides an iterator
of all possible ways to map mdl chains onto fixed ref chains.

The situation where a chem group (group of chains in the reference) is
empty but the respective group of chains in the model is not can be
correctly resolved.
---
 modules/mol/alg/pymod/chain_mapping.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/modules/mol/alg/pymod/chain_mapping.py b/modules/mol/alg/pymod/chain_mapping.py
index 0fa35ad24..15ba5b153 100644
--- a/modules/mol/alg/pymod/chain_mapping.py
+++ b/modules/mol/alg/pymod/chain_mapping.py
@@ -3390,6 +3390,9 @@ def _RefEqualGenerator(ref_chains, mdl_chains):
     for p in itertools.permutations(mdl_chains):
         yield list(p)
 
+def _RefEmptyGenerator(ref_chains, mdl_chains):
+    yield list()
+
 def _ConcatIterators(iterators):
     for item in itertools.product(*iterators):
         yield list(item)
@@ -3435,8 +3438,8 @@ def _ChainMappings(ref_chains, mdl_chains, n_max=None):
     iterators = list()
     for ref, mdl in zip(ref_chains, mdl_chains):
         if len(ref) == 0:
-            raise RuntimeError("Expect at least one chain in ref chem group")
-        if len(ref) == len(mdl):
+            iterators.append(_RefEmptyGenerator(ref, mdl))
+        elif len(ref) == len(mdl):
             iterators.append(_RefEqualGenerator(ref, mdl))
         elif len(ref) < len(mdl):
             iterators.append(_RefSmallerGenerator(ref, mdl))
-- 
GitLab