PySCeS / pysces

The official PySCeS project source code repository.
https://pysces.github.io
Other
34 stars 10 forks source link

Simulation sometimes results differ from other tools #44

Closed jonrkarr closed 3 years ago

jonrkarr commented 3 years ago

This was noticed by @freiburgermsu.

Example model (Elowitz repressilator model)

Example results

PySCeS

PySCeS' results are internally consistent between CVODE and LSODA, but different from that of other tools that also use LSODA and CVODE

PySCeS

COPASI (LSODA)

COPASI

OpenCOR (CVODE)

OpenCOR (CellML)

Interactive versions of the same results

bgoli commented 3 years ago

@jonrkarr thanks for the report, I will look into it.

jmrohwer commented 3 years ago

BIOMD0000000012_url.xml.psc.txt

The bug is in the SBML parser. The <ln/> MathML operator is translated to math.log10 in the PSC file. Corrected PSC file attached above. This gives the correct results. @bgoli you wrote the SBML conversion code, would you be able to pinpoint this quickly?

jmrohwer commented 3 years ago

The problem lies within the internal MathML translations of libsbml.

>>> import libsbml as SBML
>>> r = SBML.SBMLReader()
>>> d = r.readSBMLFromFile('BIOMD0000000012_url.xml')
>>> m = d.getModel()
>>> a = m.getListOfRules()[0]
>>> a.getFormula()
    'tau_mRNA / log(2)'

Upon reading a document, MathML <ln/> is translated to log in the formula (see above). Upon writing the document with d.toSBML(), any log in the formula is back-translated to <ln/> in the MathML, and any ln in the formula is also back-translated to <ln/>. If the formula contains log10, this is translated to

<log/>
              <logbase>
                <cn type="integer"> 10 </cn>
              </logbase>

How do other tools deal with this? Clearly it means that we cannot use symmetrical translation tables in pysces.core2.PyscesCore2Interfaces.CoreToSBML.NumpyToMathML and pysces.core2.InfixParser.MyInfixLexer.MathmlToNumpy_funcs.

jonrkarr commented 3 years ago

Maybe Frank Bergmann could shed light on how COPASI does it.

Thanks for the explanation. GillesPy2 has similar issue with this model. I only realized this from your explanation about ln. In their case, they raise an exception which indicates they don't know how to interpret ln.

bgoli commented 3 years ago

@jmrohwer thanks for finding the problem this, I will look into this in more detail. We probably notice the problem as we use the L2 infix translator while COPASI would use the ASTnodes directly.

jmrohwer commented 3 years ago

This #45 fixes it, but I am not sure if you would want to make more significant changes in terms of using the AST nodes vs infix translator. Also, SBML export from the PSC file does not work 100% (assignment rules are not properly translated), this most probably has to do with PySCeS still using SBML L2 internally.

jmrohwer commented 3 years ago

Fixed in #53