RuleWorld / nfsim

A general-purpose, stochastic, biochemical reaction simulator for large reaction networks
http://michaelsneddon.net/nfsim/
MIT License
14 stars 9 forks source link

NFSim cannot handle one molecule agent being mapped to the same reaction more than once #2

Closed jjtapia closed 8 years ago

jjtapia commented 9 years ago

NFSim molecule agents can currently be mapped to a single reaction only once. This is reflected by the fact that the data structure used to handle this information is an int array of (n-of reactions) dimensions where each entry maps to a single mappingSet id.

This also affects the way RXNmemberships are updated, since NFSim will only update the relationship once per agent per reaction, choosing only the last mapping found.

This has the effect of not correctly processing an entry of the form

R(s,s!1).L(s!2,s!1).R(s!2,s!3).L(s!3,s!4).R(s!4,s) 1

And a reaction of the form

ProblemRule:%x:R(s!1).L(s!1,s!2).R(s!2,s)->R(s!1).L(s!1,s)+R(s,s) GE2(x)

Where agent R(s!2,s!3) can map to ProblemRule twice using the same reaction even when accounting for symmetries.

jjtapia commented 9 years ago

These are the symmetries detected by NFSim along with the incorrect number of mappings as shown when enabling the use of the verbose mode

All System Reactions: DORRxnClass: ProblemRule_sym1 ( baseRate=1, a=0, fired=0 times ) -(DOR) |0 mappings| R(s!2).L(s1!1,s!2).R(s1!1,s) (rateFactorSum=0). DORRxnClass: ProblemRule_sym2 ( baseRate=1, a=0, fired=0 times ) -(DOR) |0 mappings| R(s!2).L(s1!1,s!2).R(s2!1,s) (rateFactorSum=0). DORRxnClass: ProblemRule_sym3 ( baseRate=1, a=1, fired=0 times ) -(DOR) |1 mappings| R(s!2).L(s2!1,s!2).R(s1!1,s) (rateFactorSum=1). DORRxnClass: ProblemRule_sym4 ( baseRate=1, a=0, fired=0 times ) -(DOR) |0 mappings| R(s!2).L(s2!1,s!2).R(s2!1,s) (rateFactorSum=0).

(sym3 should have two mappings)

jjtapia commented 9 years ago

When evaluating mappings, NFSim does it over the reactants. (R)

Here's an example BNGL that reproduces the issue: https://dl.dropboxusercontent.com/u/7096948/test.bngl

jjtapia commented 9 years ago

This has the result when updating a molecule agent membership to a reaction of one of its mappings still being valid but the other is not, resulting in NFSim potentially choosing the invalid mapping when firing a reaction, resulting itself in the error seen in the example file.

The solution is then to add to a molecule agent the ability to track more than one mapping per reaction, and specially adding the update membership function the ability to exhaustively track all possible agent-reaction mappings instead of just checking one of them.

jjtapia commented 9 years ago

b6cb7fc13e4513577491a867ae3637eef6a740a0 in issue #2 addresses all problems raised here and passes all validation tests currently contained in the suite.

Remaining TODO for closing the issue:

jjtapia commented 9 years ago

The current implementation of the bugfix creates a fatal error on rule

L2(r!1,r!2,r!3).R2(l!1).R2(l!2).R2(l!3)->L2(r!1,r!2,r).R2(l!1).R2(l!2)+R2(l) p*koff

in example file

https://dl.dropboxusercontent.com/u/7096948/overlapping_rules.bngl

The reported error is:

Error log: Error in Molecule::breadthFirstSearch, m is null. Likely an internal error where a MappingSet is on a list and is not actually mapped to any molecule!

The error is probably due to a mappingSet that is being created but not properly cleaned up during the mapping process

jjtapia commented 8 years ago

This is addressed in commit 0c2ffd224ee456f6990e706568b895ee7bee0389