Model.set_concentration needs the network's exact species name, where BNG2.pl's setConcentration finds the species by pattern

Open
#1,833 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
57/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend

Research direction

Start by reading Model.set_concentration and Model._species_call, which the issue identifies as the lookup path. Compare their behavior with BNG2.pl’s pattern matching on network species, using the supplied model and names as reproduction cases. Done means reordered components and omitted empty parentheses resolve to the matching species, while unmatched names still raise ModelError.

Written by the indexing model from the issue text.

Description

bug

Model.set_concentration says it implements BioNetGen's setConcentration("name", value) action. BNG2.pl's action finds the species by matching the name as a pattern, so A(y,x) finds the species the network writes as A(x,y), and B finds B(). bngsim accepts only the name exactly as the network file writes it, or that name without a fixed species' $. Anything else raises ModelError.

To reproduce, run BNG2.pl 2.9.3 on this model:

begin model
begin parameters
  k 0.1
end parameters
begin molecule types
  A(x,y)
  B()
end molecule types
begin seed species
  A(x,y) 100
  B() 100
end seed species
begin observables
  Molecules Atot A()
  Molecules Btot B()
end observables
begin reaction rules
  A() -> 0 k
  B() -> 0 k
end reaction rules
end model
generate_network({overwrite=>1})
setConcentration("A(y,x)", 50)
setConcentration("B", 30)
writeNET({prefix=>"after"})

The network BNG2.pl writes after the two actions, after.net, has A(x,y) at 50 and B() at 30. Then, with the names.net that generate_network wrote:

import bngsim

model = bngsim.Model.from_net("names.net")
for name, value in [("A(x,y)", 50), ("A(y,x)", 50), ("B()", 30), ("B", 30)]:
    try:
        model.set_concentration(name, value)
        print(f"{name!r}: set to {model.get_concentration(name)}")
    except Exception as exc:
        print(f"{name!r}: {type(exc).__name__}: {exc}")

prints

'A(x,y)': set to 50.0
'A(y,x)': ModelError: Species 'A(y,x)' not found in model
'B()': set to 30.0
'B': ModelError: Species 'B' not found in model

This was run on bngsim 0.17.0. Model._species_call on main does the same lookup.

This matters to any caller that replays a BNGL model's actions on bngsim. PyBNF hit it in 16 published models in its test corpora, including An_2009, the Mitra2019 JNK fits and egfr_path. Their setConcentration names a species with its components in another order, or without (). PyBNF used to log the error and skip the action, so these models ran from the wrong amounts. Since lanl/PyBNF#1053 it runs them on BNG2.pl instead.

A fix could find the species the way BNG2.pl does: match the name against the network's species, and refuse a name that matches none.

Dominant language
Python
Stars
3
Forks
6
Avg merge
1d 1h
Merged PRs (30d)
295

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lanl/bngsim

All issues in lanl/bngsim

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.