msneddon / nfsim

A general-purpose, stochastic, biochemical reaction simulator for large reaction networks
MIT License
17 stars 18 forks source link

Local function on Molecular scope not evaluated with -nocslf flag set #17

Open msneddon opened 8 years ago

msneddon commented 8 years ago

Local functions can be evaluated over an entire connected complex or a single molecule, based on scope indicated by the tag. The -nocslf flag turns off calculation of local functions that are evaluated over a complex, which is a useful performance enhancement, but should not affect calculation or update of functions evaluated on a single molecule scope.

However, for some reactions, if -nocslf is set, then functions evaluated on a single molecule scope fail to update. Here is a simple model that reproduces the problem:

begin molecule types
  A(p~0~1,m~0~1)
  B(p~0~1)
end molecule types

begin species
  A(p~0,m~0) 100
  B(p~0) 100
end species

begin observables
  Molecules Ap A(p~1)
  Molecules Bp B(p~1)
end observables

begin functions
  func1(x) = 1*Ap(x)
end functions

begin reaction rules
  A(p~0) <-> A(p~1) 1,1
  B(p~0) + A%x() -> B(p~1) + A%x() func1(x)
  B(p~1) -> B(p~0) 1
end reaction rules

writeXML()

When running as:

nfsim -xml test.xml -sim 10 -oSteps 5 -v

We get as expected the DOR reaction firing as seen after the simulation:

DORRxnClass: _R2  ( baseRate=1,  a=96, fired=1125 times )
  -|2 mappings| B(p~0)
  -(DOR) |100 mappings| A()
         (rateFactorSum=48).

However when we turn on the -nocslf

nfsim -xml test.xml -sim 10 -oSteps 5 -v -nocslf

The rateFactorSum never updates, and the rule never fires

DORRxnClass: _R2  ( baseRate=1,  a=0, fired=0 times )
  -|100 mappings|   B(p~0)
  -(DOR) |100 mappings| A()
         (rateFactorSum=0).
msneddon commented 8 years ago

May have found a fix (https://github.com/msneddon/nfsim/tree/lf-fix), but I want to test a few other things. Looks like the recent changes/fixes in the dev branch may have also fixed this issue.