def test_element_invalid_mathml(self): invalid = wrapMathML( "<lambda definitionURL=\"http://biomodels.net/SBO/#SBO:0000065\">" + "<bvar>" + "<ci>c</ci>" + "</bvar>" + "<apply>" + " <ci>c</ci>" + "</apply>" + "</lambda>\n") self.N = libsbml.readMathMLFromString(None) self.assert_(self.N == None) self.N = libsbml.readMathMLFromString(invalid) self.assert_(self.N == None) pass
def test_element_invalid_mathml(self): invalid = wrapMathML("<lambda definitionURL=\"http://biomodels.net/SBO/#SBO:0000065\">" + "<bvar>" + "<ci>c</ci>" + "</bvar>" + "<apply>" + " <ci>c</ci>" + "</apply>" + "</lambda>\n") self.N = libsbml.readMathMLFromString(None) self.assert_( self.N == None ) self.N = libsbml.readMathMLFromString(invalid) self.assert_( self.N == None ) pass
def test_element_ceiling(self): s = wrapMathML("<apply><ceiling/><cn> 1.6 </cn></apply>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.F = libsbml.formulaToString(self.N) self.assert_(("ceil(1.6)" == self.F)) pass
def cmathml_to_astnode(cmathml: str) -> libsbml.ASTNode: """Convert Content MathML string to ASTNode. :param cmathml: SBML Content MathML string :return: libsbml.ASTNode """ return libsbml.readMathMLFromString(cmathml)
def test_element_neq(self): s = wrapMathML("<apply> <neq/> <notanumber/> <notanumber/> </apply>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.F = libsbml.formulaToString(self.N) self.assert_(("neq(NaN, NaN)" == self.F)) pass
def test_element_not(self): s = wrapMathML("<apply> <not/> <ci> TooShabby </ci> </apply>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.F = libsbml.formulaToString(self.N) self.assert_(("not(TooShabby)" == self.F)) pass
def test_element_math(self): s = wrapXML("<math xmlns='http://www.w3.org/1998/Math/MathML'/>" ) self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.assert_( self.N.getType() == libsbml.AST_UNKNOWN ) pass
def test_element_factorial(self): s = wrapMathML("<apply><factorial/><cn> 5 </cn></apply>") self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.F = libsbml.formulaToString(self.N) self.assert_(( "factorial(5)" == self.F )) pass
def test_element_not(self): s = wrapMathML("<apply> <not/> <ci> TooShabby </ci> </apply>") self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.F = libsbml.formulaToString(self.N) self.assert_(( "not(TooShabby)" == self.F )) pass
def test_element_ceiling(self): s = wrapMathML("<apply><ceiling/><cn> 1.6 </cn></apply>") self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.F = libsbml.formulaToString(self.N) self.assert_(( "ceil(1.6)" == self.F )) pass
def test_element_floor(self): s = wrapMathML("<apply><floor/><cn> 1.2 </cn></apply>") self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.F = libsbml.formulaToString(self.N) self.assert_(( "floor(1.2)" == self.F )) pass
def test_element_tanh(self): s = wrapMathML("<apply><tanh/><ci> x </ci></apply>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.F = libsbml.formulaToString(self.N) self.assert_(("tanh(x)" == self.F)) pass
def test_element_constants_true(self): s = wrapMathML("<true/>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.assert_(self.N.getType() == libsbml.AST_CONSTANT_TRUE) self.assert_(self.N.getNumChildren() == 0) pass
def test_element_power(self): s = wrapMathML("<apply><power/> <ci>x</ci> <cn>3</cn> </apply>") self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.F = libsbml.formulaToString(self.N) self.assert_(( "pow(x, 3)" == self.F )) pass
def test_element_constants_true(self): s = wrapMathML("<true/>") self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.assert_( self.N.getType() == libsbml.AST_CONSTANT_TRUE ) self.assert_( self.N.getNumChildren() == 0 ) pass
def test_element_root_2(self): s = wrapMathML("<apply> <root/> <ci> a </ci> </apply>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.F = libsbml.formulaToString(self.N) self.assert_(("sqrt(a)" == self.F)) pass
def test_element_power(self): s = wrapMathML("<apply><power/> <ci>x</ci> <cn>3</cn> </apply>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.F = libsbml.formulaToString(self.N) self.assert_(("pow(x, 3)" == self.F)) pass
def test_element_function_call_1(self): s = wrapMathML("<apply> <ci> foo </ci> <ci> x </ci> </apply>") self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.F = libsbml.formulaToString(self.N) self.assert_(( "foo(x)" == self.F )) pass
def test_element_root_2(self): s = wrapMathML("<apply> <root/> <ci> a </ci> </apply>") self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.F = libsbml.formulaToString(self.N) self.assert_(( "sqrt(a)" == self.F )) pass
def test_element_tanh(self): s = wrapMathML("<apply><tanh/><ci> x </ci></apply>") self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.F = libsbml.formulaToString(self.N) self.assert_(( "tanh(x)" == self.F )) pass
def __set_kinetic_law(self, reaction, function_definition, parameters): '''Sets kineticLaw element to reaction.''' mathml = '<?xml version="1.0" encoding="UTF-8"?>' mathml += '<math xmlns="http://www.w3.org/1998/Math/MathML">' mathml += '<apply>' mathml += '<ci>' + function_definition.getId() + '</ci>' for parameter in parameters: mathml += '<ci>' + parameter[2] + '</ci>' mathml += '</apply>' mathml += '</math>' kinetic_law = reaction.createKineticLaw() kinetic_law.setMath(libsbml.readMathMLFromString(mathml)) for parameter in parameters: sbo_term = parameter[1] if sbo_term != sbml_utils.SBO_TERMS[sbml_utils.CONC] and \ sbo_term != sbml_utils.SBO_TERMS[sbml_utils.VOLUME]: param = kinetic_law.createParameter() param.setId(parameter[2]) param.setValue(sbml_utils.SBO_TERM_DEFAULT[sbo_term]) param.setUnits(self.__units[sbo_term]) param.setSBOTerm(sbo_term) return kinetic_law
def test_element_function_call_1(self): s = wrapMathML("<apply> <ci> foo </ci> <ci> x </ci> </apply>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.F = libsbml.formulaToString(self.N) self.assert_(("foo(x)" == self.F)) pass
def test_element_floor(self): s = wrapMathML("<apply><floor/><cn> 1.2 </cn></apply>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.F = libsbml.formulaToString(self.N) self.assert_(("floor(1.2)" == self.F)) pass
def test_element_factorial(self): s = wrapMathML("<apply><factorial/><cn> 5 </cn></apply>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.F = libsbml.formulaToString(self.N) self.assert_(("factorial(5)" == self.F)) pass
def test_element_constants_infinity(self): s = wrapMathML("<infinity/>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.assert_(self.N.getType() == libsbml.AST_REAL) self.assert_(util_isInf(self.N.getReal()) == True) self.assert_(self.N.getNumChildren() == 0) pass
def test_element_operator_times(self): s = wrapMathML( "<apply> <times/> <ci> x </ci> <ci> y </ci> <ci> z </ci> </apply>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.F = libsbml.formulaToString(self.N) self.assert_(("x * y * z" == self.F)) pass
def test_element_operator_plus(self): s = wrapMathML( "<apply> <plus/> <cn> 1 </cn> <cn> 2 </cn> <cn> 3 </cn> </apply>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.F = libsbml.formulaToString(self.N) self.assert_(("1 + 2 + 3" == self.F)) pass
def test_element_constants_notanumber(self): s = wrapMathML("<notanumber/>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.assert_(self.N.getType() == libsbml.AST_REAL) self.assertEqual(True, isnan(self.N.getReal())) self.assert_(self.N.getNumChildren() == 0) pass
def test_element_leq(self): s = wrapMathML( "<apply> <leq/> <cn>0</cn> <ci>x</ci> <cn>1</cn> </apply>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.F = libsbml.formulaToString(self.N) self.assert_(("leq(0, x, 1)" == self.F)) pass
def test_element_eq(self): s = wrapMathML( "<apply> <eq/> <ci>a</ci> <ci>b</ci> <ci>c</ci> </apply>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.F = libsbml.formulaToString(self.N) self.assert_(("eq(a, b, c)" == self.F)) pass
def test_element_cn_integer(self): s = wrapMathML("<cn type='integer'> 12345 </cn>") self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.assert_( self.N.getType() == libsbml.AST_INTEGER ) self.assert_( self.N.getInteger() == 12345 ) self.assert_( self.N.getNumChildren() == 0 ) pass
def test_element_cn_real(self): s = wrapMathML("<cn type='real'> 12345.7 </cn>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.assert_(self.N.getType() == libsbml.AST_REAL) self.assert_(self.N.getReal() == 12345.7) self.assert_(self.N.getNumChildren() == 0) pass
def test_element_ci_surrounding_spaces_bug(self): s = wrapMathML(" <ci> s </ci> ") self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.assert_( self.N.getType() == libsbml.AST_NAME ) self.assert_(( "s" == self.N.getName() )) self.assert_( self.N.getNumChildren() == 0 ) pass
def test_element_constants_infinity(self): s = wrapMathML("<infinity/>") self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.assert_( self.N.getType() == libsbml.AST_REAL ) self.assert_( util_isInf(self.N.getReal()) == True ) self.assert_( self.N.getNumChildren() == 0 ) pass
def test_element_cn_real(self): s = wrapMathML("<cn type='real'> 12345.7 </cn>") self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.assert_( self.N.getType() == libsbml.AST_REAL ) self.assert_( self.N.getReal() == 12345.7 ) self.assert_( self.N.getNumChildren() == 0 ) pass
def test_element_cn_integer(self): s = wrapMathML("<cn type='integer'> 12345 </cn>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.assert_(self.N.getType() == libsbml.AST_INTEGER) self.assert_(self.N.getInteger() == 12345) self.assert_(self.N.getNumChildren() == 0) pass
def test_element_constants_notanumber(self): s = wrapMathML("<notanumber/>") self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.assert_( self.N.getType() == libsbml.AST_REAL ) self.assertEqual( True, isnan(self.N.getReal()) ) self.assert_( self.N.getNumChildren() == 0 ) pass
def test_element_csymbol_delay_1(self): s = wrapMathML("<csymbol encoding='text' " + "definitionURL='http://www.sbml.org/sbml/symbols/delay'> delay </csymbol>") self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.assert_( self.N.getType() == libsbml.AST_FUNCTION_DELAY ) self.assert_(( "delay" == self.N.getName() )) self.assert_( self.N.getNumChildren() == 0 ) pass
def test_element_csymbol_avogadro(self): s = wrapMathML("<csymbol encoding='text' " + "definitionURL='http://www.sbml.org/sbml/symbols/avogadro'> NA </csymbol>") self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.assert_( self.N.getType() == libsbml.AST_NAME_AVOGADRO ) self.assert_(( "NA" == self.N.getName() )) self.assert_( self.N.getNumChildren() == 0 ) pass
def test_element_ci_surrounding_spaces_bug(self): s = wrapMathML(" <ci> s </ci> ") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.assert_(self.N.getType() == libsbml.AST_NAME) self.assert_(("s" == self.N.getName())) self.assert_(self.N.getNumChildren() == 0) pass
def test_element_csymbol_time(self): s = wrapMathML("<csymbol encoding='text' " + "definitionURL='http://www.sbml.org/sbml/symbols/time'> t </csymbol>") self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.assert_( self.N.getType() == libsbml.AST_NAME_TIME ) self.assert_(( "t" == self.N.getName() )) self.assert_( self.N.getNumChildren() == 0 ) pass
def test_element_ci(self): s = wrapMathML("<ci> x </ci>") self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.assert_( self.N.getType() == libsbml.AST_NAME ) self.assert_(( "x" == self.N.getName() )) self.assert_( self.N.getNumChildren() == 0 ) pass
def test_element_xor(self): s = wrapMathML("<apply> <xor/> <ci>a</ci> <ci>b</ci> <ci>b</ci> <ci>a</ci> </apply>" ) self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.F = libsbml.formulaToString(self.N) self.assert_(( "xor(a, b, b, a)" == self.F )) pass
def test_element_neq(self): s = wrapMathML("<apply> <neq/> <notanumber/> <notanumber/> </apply>" ) self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.F = libsbml.formulaToString(self.N) self.assert_(( "neq(NaN, NaN)" == self.F )) pass
def test_element_ci(self): s = wrapMathML("<ci> x </ci>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.assert_(self.N.getType() == libsbml.AST_NAME) self.assert_(("x" == self.N.getName())) self.assert_(self.N.getNumChildren() == 0) pass
def test_element_operator_times(self): s = wrapMathML("<apply> <times/> <ci> x </ci> <ci> y </ci> <ci> z </ci> </apply>" ) self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.F = libsbml.formulaToString(self.N) self.assert_(( "x * y * z" == self.F )) pass
def test_element_leq(self): s = wrapMathML("<apply> <leq/> <cn>0</cn> <ci>x</ci> <cn>1</cn> </apply>" ) self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.F = libsbml.formulaToString(self.N) self.assert_(( "leq(0, x, 1)" == self.F )) pass
def test_element_operator_plus(self): s = wrapMathML("<apply> <plus/> <cn> 1 </cn> <cn> 2 </cn> <cn> 3 </cn> </apply>" ) self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.F = libsbml.formulaToString(self.N) self.assert_(( "1 + 2 + 3" == self.F )) pass
def test_element_ci_definitionURL(self): s = wrapMathML("<ci definitionURL=\"foobar\"> x </ci>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.assert_(self.N.getType() == libsbml.AST_NAME) self.assert_(("x" == self.N.getName())) self.assert_(self.N.getNumChildren() == 0) self.assert_(self.N.getDefinitionURL().getValue(0) == "foobar") pass
def test_element_cn_e_notation(self): s = wrapMathML("<cn type='e-notation'> 12.3 <sep/> 5 </cn>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.assert_(self.N.getType() == libsbml.AST_REAL_E) self.assert_(self.N.getMantissa() == 12.3) self.assert_(self.N.getExponent() == 5) self.assert_(self.N.getNumChildren() == 0) pass
def test_element_cn_rational(self): s = wrapMathML("<cn type='rational'> 12342 <sep/> 2342342 </cn>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.assert_(self.N.getType() == libsbml.AST_RATIONAL) self.assert_(self.N.getNumerator() == 12342) self.assert_(self.N.getDenominator() == 2342342) self.assert_(self.N.getNumChildren() == 0) pass
def test_element_root_1(self): s = wrapMathML("<apply> <root/> <degree> <cn type='integer'> 3 </cn> </degree>" + " <ci> a </ci>" + "</apply>") self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.F = libsbml.formulaToString(self.N) self.assert_(( "root(3, a)" == self.F )) pass
def test_element_cn_units(self): s = wrapMathMLUnits("<cn sbml:units=\"mole\"> 12345.7 </cn>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.assert_(self.N.getType() == libsbml.AST_REAL) self.assert_(self.N.getReal() == 12345.7) self.assert_(self.N.getUnits() == "mole") self.assert_(self.N.getNumChildren() == 0) pass
def test_element_log_1(self): s = wrapMathML( "<apply> <log/> <logbase> <cn type='integer'> 3 </cn> </logbase>" + " <ci> x </ci>" + "</apply>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.F = libsbml.formulaToString(self.N) self.assert_(("log(3, x)" == self.F)) pass
def test_element_root_1(self): s = wrapMathML( "<apply> <root/> <degree> <cn type='integer'> 3 </cn> </degree>" + " <ci> a </ci>" + "</apply>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.F = libsbml.formulaToString(self.N) self.assert_(("root(3, a)" == self.F)) pass
def test_element_lt(self): s = wrapMathML( "<apply> <lt/> <apply> <minus/> <infinity/> <infinity/> </apply>" + " <cn>1</cn>" + "</apply>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.F = libsbml.formulaToString(self.N) self.assert_(("lt(INF - INF, 1)" == self.F)) pass
def test_element_lt(self): s = wrapMathML("<apply> <lt/> <apply> <minus/> <infinity/> <infinity/> </apply>" + " <cn>1</cn>" + "</apply>") self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.F = libsbml.formulaToString(self.N) self.assert_(( "lt(INF - INF, 1)" == self.F )) pass
def test_element_log_1(self): s = wrapMathML("<apply> <log/> <logbase> <cn type='integer'> 3 </cn> </logbase>" + " <ci> x </ci>" + "</apply>") self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.F = libsbml.formulaToString(self.N) self.assert_(( "log(3, x)" == self.F )) pass
def test_element_bug_cn_e_notation_3(self): s = wrapMathML("<cn type='e-notation'> -6 <sep/> -1 </cn>") self.N = libsbml.readMathMLFromString(s) self.assert_(self.N != None) self.assert_(self.N.getType() == libsbml.AST_REAL_E) self.assert_(self.N.getMantissa() == -6.0) self.assert_(self.N.getExponent() == -1.0) self.assert_(self.N.getNumChildren() == 0) pass
def test_element_function_call_2(self): s = wrapMathML("<apply> <plus/> <cn> 1 </cn>" + " <apply> <ci> f </ci> <ci> x </ci> </apply>" + "</apply>") self.N = libsbml.readMathMLFromString(s) self.assert_( self.N != None ) self.F = libsbml.formulaToString(self.N) self.assert_(( "1 + f(x)" == self.F )) pass