sys-bio / antimony

BSD 3-Clause "New" or "Revised" License
15 stars 4 forks source link

Bugs with initial value of species when exporting to SBML #99

Closed leodarrigade closed 1 month ago

leodarrigade commented 3 months ago

Hello, First, thank you for developping Antimony, it is very useful for writing simple SBML model ! I have the following code that define an Antimony model, does a plot of the dynamic and export it to SBML.

import tellurium as te
antimony_str = '''
    model truc
    # Reactions
    ## Complex formation
    const Lm;
    J1 : Rm + Lm -> LRm; k_in * k_off / K_D * Lm * Rm;
    J2 : LRm -> Rm; k_in * k_off * LRm;
    J3 : Rm -> LRe; k_in * Rm;

    ## AMPc production
    -> AMPc; k_in * k_plus * LRm;
    AMPc ->; k_in * k_minus * AMPc;

    E_lavage : at (time > t_wash): Lm = 0.0;

    # Parameters
    k_off = 1.; K_D = 1.0; k_plus = 1.0; k_minus = 1.0; k_in = 1.0; t_wash = 60; L_0 = 2.; R_tot = 10;

    # Species initializations
    Rm = 1.0; LRm = 0.0; LRe = 0.0 ; AMPc = 0.0; Lm = L_0;
    end
'''

r = te.loada(antimony_str) # returns a RoadRunner instance with the model loaded

r.simulate(0, 200, 500)
r.plot()

r.exportToSBML('truc.xml')

The plot is fine and I don't get any error message. However, in the species definition of the SBML, this is what I get

    <listOfSpecies>
      <species id="Lm" compartment="default_compartment" initialConcentration="0" hasOnlySubstanceUnits="false" boundaryCondition="true" constant="false"/>
      <species id="Rm" compartment="default_compartment" initialAmount="-1.65922220518393e-22" hasOnlySubstanceUnits="false" boundaryCondition="false" constant="false"/>
      <species id="LRm" compartment="default_compartment" initialAmount="-4.45745325904997e-24" hasOnlySubstanceUnits="false" boundaryCondition="false" constant="false"/>
      <species id="LRe" compartment="default_compartment" initialAmount="1.00000000000001" hasOnlySubstanceUnits="false" boundaryCondition="false" constant="false"/>
      <species id="AMPc" compartment="default_compartment" initialAmount="-1.70380164310411e-22" hasOnlySubstanceUnits="false" boundaryCondition="false" constant="false"/>
    </listOfSpecies>

The initialAmount of LRe is 1 but it should be 0.

This is done with Tellurium == 2.2.10.

luciansmith commented 3 months ago

The problem is that 'exportToSBML' exports the current state of the model, not the initial state. If you notice the other values, everything has basically reached steady state: LRe is at 1, and everything else is at zero. If you want the initial state, add the argument 'current=False' to 'exportToSBML':

r.exportToSBML('truc.xml', current=False)

Alternatively, you can always call the function before simulation:

r = te.loada(antimony_str) # returns a RoadRunner instance with the model loaded
r.exportToSBML('truc_orig1.xml')

r.simulate(0, 200, 500)
r.plot()

r.exportToSBML('truc_current.xml')
r.exportToSBML('truc_orig2.xml', current=False)
leodarrigade commented 3 months ago

Ok, thank you very much !