Skip to content

Render multi-bond first partner as flat !N!N, not !N![N]#80

Merged
jrfaeder merged 1 commit into
RuleWorld:mainfrom
wshlavacek:modelapi-b13-multibond-rendering
May 11, 2026
Merged

Render multi-bond first partner as flat !N!N, not !N![N]#80
jrfaeder merged 1 commit into
RuleWorld:mainfrom
wshlavacek:modelapi-b13-multibond-rendering

Conversation

@wshlavacek
Copy link
Copy Markdown
Contributor

Summary

`BondsXML.resolve_xml` has 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 are 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 appends the int correctly, so the bug only surfaces for sites that appear as `bond_partner_1` in multiple bonds.

`Component.str` then runs `f"!{bond}"` over the flat bonds list, which turns `[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).

Test plan

  • Existing CI passes
  • A model with a site participating in 2+ bonds (`hub(x!1!2)`) round-trips through XML and regenerates a BNG2.pl-loadable `.bngl`

`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).
@jrfaeder jrfaeder merged commit 69565ea into RuleWorld:main May 11, 2026
17 checks passed
@wshlavacek wshlavacek deleted the modelapi-b13-multibond-rendering branch May 11, 2026 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants