From 41e909d2787a95305213696f006ebac76d78ed4a Mon Sep 17 00:00:00 2001 From: Bill Hlavacek Date: Sun, 10 May 2026 15:50:19 -0600 Subject: [PATCH] Render multi-bond first partner as flat `!N!N`, not `!N![N]` `BondsXML.resolve_xml` had an off-by-one-character bug: when the SAME site is the first partner of two or more bonds (the `hub(x!1!2)` shape), the second-and-later bond IDs were appended to `self.bonds_dict` as a one-element LIST `[ibond + 1]` instead of as the int `ibond + 1`. The second partner's branch already appended the int correctly, so the bug only surfaced for sites that appeared as `bond_partner_1` in multiple bonds. `Component.__str__` then ran `f"!{bond}"` over the flat bonds list, which turned `[2]` into `![2]`. BNG2.pl reads `![N]` as a compartment specifier in pattern syntax and aborts with `Invalid syntax at ![2]` when it re-loads the regenerated BNGL. Fix: append the int (parity with the second-partner branch). --- bionetgen/modelapi/xmlparsers.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bionetgen/modelapi/xmlparsers.py b/bionetgen/modelapi/xmlparsers.py index bf529821..d5d553e0 100644 --- a/bionetgen/modelapi/xmlparsers.py +++ b/bionetgen/modelapi/xmlparsers.py @@ -114,7 +114,11 @@ def resolve_xml(self, bonds_xml): if bond_partner_1 not in self.bonds_dict: self.bonds_dict[bond_partner_1] = [ibond + 1] else: - self.bonds_dict[bond_partner_1].append([ibond + 1]) + # B13: must append the int, not a [int] list — the + # rendered Component.__str__ emits ``f"!{bond}"`` per + # entry, so a list ``[2]`` would render as ``![2]``, + # which BNG2.pl reads as a compartment specifier. + self.bonds_dict[bond_partner_1].append(ibond + 1) if bond_partner_2 not in self.bonds_dict: self.bonds_dict[bond_partner_2] = [ibond + 1] else: