RuleWorld / bionetgen

Rule-based modeling framework
https://bionetgen.org/
MIT License
56 stars 25 forks source link

Time dependent file #227

Closed ASinanSaglam closed 3 years ago

ASinanSaglam commented 3 years ago

This pull request allows BioNetGen to process a new function type called TFUN. This function type only makes sense for NFsim, once this pull request is merged. TFUN has the following syntax

begin functions
  f = observable/1e2
  k = TFUN(f, "myfile.dat") * 1e3
end functions

where TFUN points to either an observable or another function and returns values from the file. File is structured as a simple 2 column, white space separated data file. The first column is the value of the observable TFUN will match to and the second column is the value TFUN will return.

The changes to BNG-side only affects the XML writing. A TFUN will return the following function type in the XML

<Function id="my_func" type="TFUN" file='my_file.dat' ctrName="counter_name">

BNG will error out if generate_network or anything related to run_network is called since only NFsim understands what TFUN is at the moment. When combined with the NFsim compiled with the pull request mentioned earlier, this pull request passes all validation checks and it shouldn't impact any model without a TFUN call.

ASinanSaglam commented 3 years ago

One major change since the pull request was created. BNG will now add an extra reference to the NFsim XML for each function definition that contains a TFUN function:

<Reference name="__TFUN__VAL__" type="Constant"/>

This reference is used by NFsim upon function creation for replacement down stream, this value is replaced by the values pulled from the file. The expression of the function also changes upon writing to XML, e.g. from:

TFUN(ctr, "rates.txt") / (6.022e8*(0.25^3))

to:

__TFUN__VAL__/(6.022e8*(0.25^3))

allowing NFsim to replace the built-in variable __TFUN__VAL__ which was previously just the name of the counter observable/function. This allows for the re-use of the same counter observable/function in the same expression, which is the expected behavior. E.g.

k = TFUN(ctr, "rates.txt") * ctr

function definition will work now.