Skip to content

Commit 353c172

Browse files
committed
Match BNG2.pl: drop the molecules/rules block aliases (keep species)
The grammar doc lists `molecules` (for `molecule types`) and `rules` (for `reaction rules`) as block aliases, but BNG2.pl 2.9.3 -- the reference this reader targets -- REJECTS both ("Could not process block type 'molecules' / 'rules'"). Honoring them let the reader enumerate entities from a block BNG2.pl refuses, i.e. accept models the reference rejects. Restrict _BLOCK_ALIASES to `species` (for `seed species`), which BNG2.pl accepts and in fact emits as its own canonical seed-species spelling. Verified empirically against BNG2.pl 2.9.3. The corpus gate is unchanged (no fixture uses the dropped aliases; golden regenerates identically). ruff clean; 24 passed. Refs: PEtab-dev/PEtab#436.
1 parent ccf0e2b commit 353c172

2 files changed

Lines changed: 23 additions & 18 deletions

File tree

petab/v1/models/bngl_model.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
compartments, and seed species.
2626
2727
The block scanner is hardened against the BNGL grammar (BioNetGen ``Perl2/``;
28-
see the reference in ``BNG_vscode_extension`` ``docs/bngl-grammar.md``): line
29-
continuations (a trailing ``\\``), block aliases (``molecules``/``species``/
30-
``rules``), line labels (a numeric index ``1 L0 1`` or a named ``CD14: ...``),
31-
and the seed-species ``$`` clamp marker are all honored. It is kept in sync
32-
with PyBNF's sibling reader (``pybnf/petab/_bngl.py``, ADR-0026) -- the
33-
grammar-hardening tests are the anchor that keeps the two from drifting.
28+
cross-checked against ``BNG_vscode_extension`` ``docs/bngl-grammar.md``): line
29+
continuations (a trailing ``\\``), the ``species`` block alias (``begin
30+
species`` = ``begin seed species``), line labels (a numeric index ``1 L0 1`` or
31+
a named ``CD14: ...``), and the seed-species ``$`` clamp marker are honored. It
32+
is kept in sync with PyBNF's sibling reader (``pybnf/petab/_bngl.py``,
33+
ADR-0026) -- the grammar-hardening tests are the anchor against drift.
3434
"""
3535

3636
from __future__ import annotations
@@ -53,13 +53,15 @@
5353
#: The three keywords that open an observable declaration line.
5454
_OBS_KEYWORDS = frozenset({"Molecules", "Species", "Counter"})
5555

56-
#: Short spellings BioNetGen accepts for a block's canonical (long) name --
57-
#: either spelling opens and closes the same block. Only the blocks this reader
58-
#: enumerates need an entry.
56+
#: Short spellings BNG2.pl accepts for a block's canonical (long) name; either
57+
#: spelling opens and closes the same block. The grammar doc
58+
#: (``BNG_vscode_extension/docs/bngl-grammar.md``) also lists ``molecules`` and
59+
#: ``rules``, but BNG2.pl 2.9.3 -- the reference this reader targets -- rejects
60+
#: both ("Could not process block type"), so honoring them would accept models
61+
#: BNG2.pl refuses. Only ``species`` (for ``seed species``, also BNG2.pl's own
62+
#: canonical output spelling) is real.
5963
_BLOCK_ALIASES = {
60-
"molecule types": ("molecules",),
6164
"seed species": ("species",),
62-
"reaction rules": ("rules",),
6365
}
6466

6567

@@ -157,10 +159,10 @@ def _logical_lines(text: str) -> list[str]:
157159
def _block_lines(text: str, block_name: str) -> list[str]:
158160
"""The comment-stripped, non-blank lines inside ``begin``/``end``.
159161
160-
``block_name`` is the canonical (long) spelling; any BioNetGen alias for it
161-
(``molecules`` for ``molecule types``, ``species`` for ``seed species``,
162-
``rules`` for ``reaction rules``) opens and closes the same block. Lines
163-
are logical lines -- continuations joined (see :func:`_logical_lines`).
162+
``block_name`` is the canonical (long) spelling; a BNG2.pl-accepted alias
163+
for it (only ``species`` for ``seed species``; see :data:`_BLOCK_ALIASES`)
164+
opens and closes the same block. Lines are logical lines -- continuations
165+
joined (see :func:`_logical_lines`).
164166
"""
165167
names = "|".join(
166168
re.escape(name)

tests/v1/test_model_bngl.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,13 @@ def test_seed_species_dollar_clamp_is_stripped():
8080
assert "$A()" not in entities.seed_species # the marker never leaks
8181

8282

83-
def test_molecule_types_block_alias():
84-
# `begin molecules` is BNG's short alias for `begin molecule types`.
83+
def test_rejected_block_aliases_are_not_honored():
84+
# The grammar doc lists `molecules`/`rules` as aliases, but BNG2.pl 2.9.3
85+
# REJECTS both ("Could not process block type"); only `species` is real. To
86+
# match the reference implementation the reader must NOT treat
87+
# `begin molecules`/`begin rules` as their canonical blocks.
8588
entities = parse_bngl("begin molecules\n A()\n B(x)\nend molecules\n")
86-
assert entities.molecule_type_names == frozenset({"A", "B"})
89+
assert entities.molecule_type_names == frozenset()
8790

8891

8992
def test_seed_species_block_alias():

0 commit comments

Comments
 (0)