The following lists the main differences in the formula syntax supported by the "Level 3" or L3 versions of the formula parsers and formatters, compared to what is supported by the Level 1-oriented SBML_parseFormula() and SBML_formulaToString():
- Units may be asociated with bare numbers, using the following syntax:
number unitThe number may be in any form (an integer, real, or rational number), and the unit must conform to the syntax of an SBML identifier (technically, the type defined asSIdin the SBML specifications). The whitespace between number and unit is optional.
import libsbml
doc = libsbml.SBMLDocument(3, 2)
model = doc.createModel()
model.id = "test_inline_unit"
ud = model.createUnitDefinition()
ud.setId("m")
u = model.createUnit()
u.setKind(libsbml.UNIT_KIND_METRE)
u.setExponent(1.0)
u.setScale(1)
u.setMultiplier(1.0)
ud.addUnit(u)
p = model.createParameter()
p.id = "p"
p.constant = False
p.units = "m"
rule = model.createAssignmentRule()
rule.variable = "p"
ast = libsbml.parseL3FormulaWithModel("5.0 m", model)
rule.setMath(ast)
formula = libsbml.formulaToL3String(ast)
print(formula)
libsbml.writeSBMLToFile(doc, "inline_units_py.xml")
package org.cy3sbml.oven;
import org.sbml.jsbml.*;
import org.sbml.jsbml.text.parser.ParseException;
import javax.xml.stream.XMLStreamException;
import java.io.IOException;
public class InlineUnitsDropped {
public static void main(String[] args) throws IOException, XMLStreamException, ParseException {
// [1] To formula with inline units not working
SBMLDocument doc1 = JSBML.readSBML("/home/mkoenig/Desktop/inline_units_py.xml");
Model m1 = doc1.getModel();
AssignmentRule r1 = m1.getAssignmentRuleByVariable("p");
ASTNode a1 = r1.getMath();
String formula = JSBML.formulaToString(a1);
System.out.println(formula);
// [2] Parsing formulas with inline units not working
SBMLDocument doc = new SBMLDocument(3, 2);
Model model = doc.createModel();
model.setId("test_inline_unit");
UnitDefinition ud = model.createUnitDefinition();
ud.setId("m");
Unit u = new Unit();
u.setKind(Unit.Kind.METRE);
u.setExponent(1.0);
u.setScale(1);
u.setMultiplier(1.0);
ud.addUnit(u);
Parameter p = model.createParameter("p");
p.setConstant(false);
p.setUnits("m");
AssignmentRule rule = model.createAssignmentRule();
rule.setVariable("p");
ASTNode ast = JSBML.parseFormula("5.0 m");
rule.setMath(ast);
System.out.println(ast);
JSBML.writeSBML(doc, "/home/mkoenig/Desktop/inline_units.xml");
}
}
Hi Matthias,
Thanks for the request, I have added a pivotal story for it (https://www.pivotaltracker.com/story/show/155658888) but it won't have high priority. May be we can find a student to work on it at some point.
cheers,
Nico
--
You received this message because you are subscribed to the Google Groups "jsbml-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsbml-developm...@googlegroups.com.
To post to this group, send email to jsbml-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsbml-development/46473917-6557-49e0-aca4-02f8c5938487%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to jsbml-development+unsubscribe@googlegroups.com.
To post to this group, send email to jsbml-development@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsbml-development/46473917-6557-49e0-aca4-02f8c5938487%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "jsbml-development" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jsbml-development/NKvOu6Mukg0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jsbml-development+unsubscribe@googlegroups.com.
To post to this group, send email to jsbml-development@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsbml-development/ad24c62f-0ada-d7cf-a2b3-f0f6d4750e9b%40ebi.ac.uk.