6
$\begingroup$

Assume I have an infix expression such as k1*s1, how do I use libsbml to translate this expression to mathml using the python interface?

$\endgroup$
2
  • $\begingroup$ Welcome to the site. Can you include examples if what you have already tried? $\endgroup$
    – Bioathlete
    Jul 18, 2019 at 15:52
  • $\begingroup$ See answer below. It works, I tried it. $\endgroup$
    – rhody
    Jul 18, 2019 at 17:14

1 Answer 1

4
$\begingroup$

It’s quite straightforward to convert infix to mathml using libsbml. Make sure you have libsbml installed in python by typing

pip install python-libsbml

at the windows/Mac/Linux command line or

!pip install python-libsbml

if you are running a Jupyter notebook. Some tools such as Tellurium already have libsbml preinstalled.

At the python command line type

import libsbml

to import the package. To enter the infix expression type the following:

p = libsbml.parseFormula ('k1*s1')

To generate the mathml type

print (libsbml.writeMathMLToString (p))
$\endgroup$
1
  • $\begingroup$ One should use the newer libsbml.parseL3Formula which provides the full set of SBML Level 3 formula parsing. I recommend using the extended libsbml.parseL3FormulaWithModel(formula, model) which uses a model instance to resolve the actual symbols in the formula. Thereby it is clear if all the symbols exist in the model. If the functions return None make sure to check the getLastParseL3Error to find out what went wrong. $\endgroup$ Jul 29, 2019 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.