libSBML Python API
5.8.0
|
Abstract Syntax Tree (AST) representation of a mathematical expression.
This class of objects is defined by libSBML only and has no direct equivalent in terms of SBML components. This class is not prescribed by the SBML specifications, although it is used to implement features defined in SBML.
Abstract Syntax Trees (ASTs) are a simple kind of data structure used in libSBML for storing mathematical expressions. The ASTNode is the cornerstone of libSBML's AST representation. An AST 'node' represents the most basic, indivisible part of a mathematical formula and come in many types. For instance, there are node types to represent numbers (with subtypes to distinguish integer, real, and rational numbers), names (e.g., constants or variables), simple mathematical operators, logical or relational operators and functions. LibSBML ASTs provide a canonical, in-memory representation for all mathematical formulas regardless of their original format (which might be MathML or might be text strings).
An AST node in libSBML is a recursive structure containing a pointer to the node's value (which might be, for example, a number or a symbol) and a list of children nodes. Each ASTNode node may have none, one, two, or more children depending on its type. The following diagram illustrates an example of how the mathematical expression '1 + 2'
is represented as an AST with one plus node having two integer children nodes for the numbers 1
and 2
. The figure also shows the corresponding MathML representation:
Infix | AST | MathML |
---|---|---|
1 + 2
|
<math xmlns="http://www.w3.org/1998/Math/MathML"> <apply> <plus/> <cn type="integer"> 1 </cn> <cn type="integer"> 2 </cn> </apply> </math>
|
The following are other noteworthy points about the AST representation in libSBML:
A numerical value represented in MathML as a real number with an exponent is preserved as such in the AST node representation, even if the number could be stored in a float
data type. This is done so that when an SBML model is read in and then written out again, the amount of change introduced by libSBML to the SBML during the round-trip activity is minimized.
Rational numbers are represented in an AST node using separate numerator and denominator values. These can be retrieved using the methods ASTNode.getNumerator() and ASTNode.getDenominator().
Every ASTNode has an associated type code to indicate, for example, whether it holds a number or stands for an arithmetic operator. The type is recorded as a value drawn from a set of static integer constants defined in the class libsbml. Their names begin with the characters AST_.The
list of possible types is quite long, because it covers all the mathematical functions that are permitted in SBML. The values are shown in the following table:
The types have the following meanings:
If the node is basic mathematical operator (e.g., '+'
), then the node's type will be AST_PLUS
, AST_MINUS
, AST_TIMES
, AST_DIVIDE
, or AST_POWER
, as appropriate.
If the node is a predefined function or operator from SBML Level 1 (in the string-based formula syntax used in Level 1) or SBML Levels 2 and 3 (in the subset of MathML used in SBML Levels 2 and 3), then the node's type will be either AST_FUNCTION_
X, AST_LOGICAL_
X, or AST_RELATIONAL_
X, as appropriate. (Examples: AST_FUNCTION_LOG
, AST_RELATIONAL_LEQ
.)
If the node refers to a user-defined function, the node's type will be AST_FUNCTION
(because it holds the name of the function).
If the node is a lambda expression, its type will be AST_LAMBDA
.
If the node is a predefined constant ('ExponentialE'
, 'Pi'
, 'True'
or 'False'
), then the node's type will be AST_CONSTANT_E
, AST_CONSTANT_PI
, AST_CONSTANT_TRUE
, or AST_CONSTANT_FALSE
.
(Levels 2 and 3 only) If the node is the special MathML csymbol time
, the value of the node will be AST_NAME_TIME
. (Note, however, that the MathML csymbol delay
is translated into a node of type AST_FUNCTION_DELAY
. The difference is due to the fact that time
is a single variable, whereas delay
is actually a function taking arguments.)
(Level 3 only) If the node is the special MathML csymbol avogadro
, the value of the node will be AST_NAME_AVOGADRO
.
AST_INTEGER
, AST_REAL
, AST_REAL_E
, or AST_RATIONAL
, as appropriate. The text-string form of mathematical formulas produced bylibsbml.formulaToString() and read bylibsbml.parseFormula() and libsbml.parseL3Formula() are in a simple C-inspired infix notation. A formula in this text-string form can be handed to a program that understands SBML mathematical expressions, or used as part of a translation system. The libSBML distribution comes with an example program in the 'examples'
subdirectory called translateMath
that implements an interactive command-line demonstration of translating infix formulas into MathML and vice-versa.
The formula strings may contain operators, function calls, symbols, and white space characters. The allowable white space characters are tab and space. The following are illustrative examples of formulas expressed in the syntax:
0.10 * k4^2
(vm * s1)/(km + s1)
The following table shows the precedence rules in this syntax. In the Class column, operand implies the construct is an operand, prefix implies the operation is applied to the following arguments, unary implies there is one argument, and binary implies there are two arguments. The values in the Precedence column show how the order of different types of operation are determined. For example, the expression a * b + c is evaluated as (a * b) + c because the *
operator has higher precedence. The Associates column shows how the order of similar precedence operations is determined; for example, a - b + c is evaluated as (a - b) + c because the +
and -
operators are left-associative. The precedence and associativity rules are taken from the C programming language, except for the symbol ^
, which is used in C for a different purpose. (Exponentiation can be invoked using either ^
or the function power
.)
Token | Operation | Class | Precedence | Associates |
---|---|---|---|---|
name | symbol reference | operand | 6 | n/a |
( expression) | expression grouping | operand | 6 | n/a |
f( ...) | function call | prefix | 6 | left |
- | negation | unary | 5 | right |
^ | power | binary | 4 | left |
* | multiplication | binary | 3 | left |
/ | divison | binary | 3 | left |
+ | addition | binary | 2 | left |
- | subtraction | binary | 2 | left |
, | argument delimiter | binary | 1 | left |
A program parsing a formula in an SBML model should assume that names appearing in the formula are the identifiers of Species, Parameter, Compartment, FunctionDefinition, Reaction (in SBML Levels 2 and 3), or SpeciesReference (in SBML Level 3 only) objects defined in a model. When a function call is involved, the syntax consists of a function identifier, followed by optional white space, followed by an opening parenthesis, followed by a sequence of zero or more arguments separated by commas (with each comma optionally preceded and/or followed by zero or more white space characters), followed by a closing parenthesis. There is an almost one-to-one mapping between the list of predefined functions available, and those defined in MathML. All of the MathML functions are recognized; this set is larger than the functions defined in SBML Level 1. In the subset of functions that overlap between MathML and SBML Level 1, there exist a few differences. The following table summarizes the differences between the predefined functions in SBML Level 1 and the MathML equivalents in SBML Levels 2 and 3:
Text string formula functions | MathML equivalents in SBML Levels 2 and 3 |
---|---|
acos | arccos |
asin | arcsin |
atan | arctan |
ceil | ceiling |
log | ln |
log10(x) | log(10, x) |
pow(x, y) | power(x, y) |
sqr(x) | power(x, 2) |
sqrt(x) | root(2, x) |
def libsbml.ASTNode.addChild | ( | self, | |
args | |||
) |
Python method signature(s):
addChild(ASTNode self, ASTNode child)int
Adds the given node as a child of this ASTNode. Child nodes are added in-order, from left to right.
child | the ASTNode instance to add |
def libsbml.ASTNode.addSemanticsAnnotation | ( | self, | |
args | |||
) |
Python method signature(s):
addSemanticsAnnotation(ASTNode self, XMLNode sAnnotation)int
Adds the given XMLNode as a semantic annotation of this ASTNode.
The<semantics>
element is a MathML 2.0 construct
that can be used to associate additional information with a MathML
construct. The construct can be used to decorate a MathML expressions with
a sequence of one or more <annotation>
or
<annotation-xml>
elements. Each such element contains a
pair of items; the first is a symbol that acts as an attribute or key, and
the second is the value associated with the attribute or key. Please refer
to the MathML 2.0 documentation, particularly the Section
5.2, Semantic Annotations for more information about these constructs.
sAnnotation | the annotation to add. |
def libsbml.ASTNode.canonicalize | ( | self | ) |
Python method signature(s):
canonicalize(ASTNode self)bool
Converts this ASTNode to a canonical form and returns True
if successful, False
otherwise.
The rules determining the canonical form conversion are as follows:
If the node type is AST_NAME and the node name matches 'ExponentialE'
, 'Pi'
, 'True'
or 'False'
the node type is converted to the corresponding AST_CONSTANT_
X type.
If the node type is an AST_FUNCTION and the node name matches an SBML (MathML) function name, logical operator name, or relational operator name, the node is converted to the corresponding AST_FUNCTION_
X or AST_LOGICAL_
X type.
SBML Level 1 function names are searched first; thus, for example, canonicalizing log
will result in a node type of AST_FUNCTION_LN. (See the SBML Level 1 Version 2 Specification, Appendix C.)
Sometimes, canonicalization of a node results in a structural conversion of the node as a result of adding a child. For example, a node with the SBML Level 1 function name sqr
and a single child node (the argument) will be transformed to a node of type AST_FUNCTION_POWER with two children. The first child will remain unchanged, but the second child will be an ASTNode of type AST_INTEGER and a value of 2. The function names that result in structural changes are: log10
, sqr
, and sqrt
.
def libsbml.ASTNode.deepCopy | ( | self | ) |
def libsbml.ASTNode.freeName | ( | self | ) |
Abstract Syntax Tree (AST) representation of a mathematical expression.
This class of objects is defined by libSBML only and has no direct equivalent in terms of SBML components. This class is not prescribed by the SBML specifications, although it is used to implement features defined in SBML.
Abstract Syntax Trees (ASTs) are a simple kind of data structure used in libSBML for storing mathematical expressions. The ASTNode is the cornerstone of libSBML's AST representation. An AST 'node' represents the most basic, indivisible part of a mathematical formula and come in many types. For instance, there are node types to represent numbers (with subtypes to distinguish integer, real, and rational numbers), names (e.g., constants or variables), simple mathematical operators, logical or relational operators and functions. LibSBML ASTs provide a canonical, in-memory representation for all mathematical formulas regardless of their original format (which might be MathML or might be text strings).
An AST node in libSBML is a recursive structure containing a pointer to the node's value (which might be, for example, a number or a symbol) and a list of children nodes. Each ASTNode node may have none, one, two, or more children depending on its type. The following diagram illustrates an example of how the mathematical expression '1 + 2'
is represented as an AST with one plus node having two integer children nodes for the numbers 1
and 2
. The figure also shows the corresponding MathML representation:
Infix | AST | MathML |
---|---|---|
1 + 2
|
<math xmlns="http://www.w3.org/1998/Math/MathML"> <apply> <plus/> <cn type="integer"> 1 </cn> <cn type="integer"> 2 </cn> </apply> </math>
|
The following are other noteworthy points about the AST representation in libSBML:
A numerical value represented in MathML as a real number with an exponent is preserved as such in the AST node representation, even if the number could be stored in a float
data type. This is done so that when an SBML model is read in and then written out again, the amount of change introduced by libSBML to the SBML during the round-trip activity is minimized.
Rational numbers are represented in an AST node using separate numerator and denominator values. These can be retrieved using the methods ASTNode.getNumerator() and ASTNode.getDenominator().
Every ASTNode has an associated type code to indicate, for example, whether it holds a number or stands for an arithmetic operator. The type is recorded as a value drawn from a set of static integer constants defined in the class libsbml. Their names begin with the characters AST_.The
list of possible types is quite long, because it covers all the mathematical functions that are permitted in SBML. The values are shown in the following table:
The types have the following meanings:
If the node is basic mathematical operator (e.g., '+'
), then the node's type will be AST_PLUS
, AST_MINUS
, AST_TIMES
, AST_DIVIDE
, or AST_POWER
, as appropriate.
If the node is a predefined function or operator from SBML Level 1 (in the string-based formula syntax used in Level 1) or SBML Levels 2 and 3 (in the subset of MathML used in SBML Levels 2 and 3), then the node's type will be either AST_FUNCTION_
X, AST_LOGICAL_
X, or AST_RELATIONAL_
X, as appropriate. (Examples: AST_FUNCTION_LOG
, AST_RELATIONAL_LEQ
.)
If the node refers to a user-defined function, the node's type will be AST_FUNCTION
(because it holds the name of the function).
If the node is a lambda expression, its type will be AST_LAMBDA
.
If the node is a predefined constant ('ExponentialE'
, 'Pi'
, 'True'
or 'False'
), then the node's type will be AST_CONSTANT_E
, AST_CONSTANT_PI
, AST_CONSTANT_TRUE
, or AST_CONSTANT_FALSE
.
(Levels 2 and 3 only) If the node is the special MathML csymbol time
, the value of the node will be AST_NAME_TIME
. (Note, however, that the MathML csymbol delay
is translated into a node of type AST_FUNCTION_DELAY
. The difference is due to the fact that time
is a single variable, whereas delay
is actually a function taking arguments.)
(Level 3 only) If the node is the special MathML csymbol avogadro
, the value of the node will be AST_NAME_AVOGADRO
.
AST_INTEGER
, AST_REAL
, AST_REAL_E
, or AST_RATIONAL
, as appropriate. The text-string form of mathematical formulas produced bylibsbml.formulaToString() and read bylibsbml.parseFormula() and libsbml.parseL3Formula() are in a simple C-inspired infix notation. A formula in this text-string form can be handed to a program that understands SBML mathematical expressions, or used as part of a translation system. The libSBML distribution comes with an example program in the 'examples'
subdirectory called translateMath
that implements an interactive command-line demonstration of translating infix formulas into MathML and vice-versa.
The formula strings may contain operators, function calls, symbols, and white space characters. The allowable white space characters are tab and space. The following are illustrative examples of formulas expressed in the syntax:
0.10 * k4^2
(vm * s1)/(km + s1)
The following table shows the precedence rules in this syntax. In the Class column, operand implies the construct is an operand, prefix implies the operation is applied to the following arguments, unary implies there is one argument, and binary implies there are two arguments. The values in the Precedence column show how the order of different types of operation are determined. For example, the expression a * b + c is evaluated as (a * b) + c because the *
operator has higher precedence. The Associates column shows how the order of similar precedence operations is determined; for example, a - b + c is evaluated as (a - b) + c because the +
and -
operators are left-associative. The precedence and associativity rules are taken from the C programming language, except for the symbol ^
, which is used in C for a different purpose. (Exponentiation can be invoked using either ^
or the function power
.)
Token | Operation | Class | Precedence | Associates |
---|---|---|---|---|
name | symbol reference | operand | 6 | n/a |
( expression) | expression grouping | operand | 6 | n/a |
f( ...) | function call | prefix | 6 | left |
- | negation | unary | 5 | right |
^ | power | binary | 4 | left |
* | multiplication | binary | 3 | left |
/ | divison | binary | 3 | left |
+ | addition | binary | 2 | left |
- | subtraction | binary | 2 | left |
, | argument delimiter | binary | 1 | left |
A program parsing a formula in an SBML model should assume that names appearing in the formula are the identifiers of Species, Parameter, Compartment, FunctionDefinition, Reaction (in SBML Levels 2 and 3), or SpeciesReference (in SBML Level 3 only) objects defined in a model. When a function call is involved, the syntax consists of a function identifier, followed by optional white space, followed by an opening parenthesis, followed by a sequence of zero or more arguments separated by commas (with each comma optionally preceded and/or followed by zero or more white space characters), followed by a closing parenthesis. There is an almost one-to-one mapping between the list of predefined functions available, and those defined in MathML. All of the MathML functions are recognized; this set is larger than the functions defined in SBML Level 1. In the subset of functions that overlap between MathML and SBML Level 1, there exist a few differences. The following table summarizes the differences between the predefined functions in SBML Level 1 and the MathML equivalents in SBML Levels 2 and 3:
Text string formula functions | MathML equivalents in SBML Levels 2 and 3 |
---|---|
acos | arccos |
asin | arcsin |
atan | arctan |
ceil | ceiling |
log | ln |
log10(x) | log(10, x) |
pow(x, y) | power(x, y) |
sqr(x) | power(x, 2) |
sqrt(x) | root(2, x) |
freeName(ASTNode self)int
Frees the name of this ASTNode and sets it to None
.
This operation is only applicable to ASTNode objects corresponding to operators, numbers, or AST_UNKNOWN. This method has no effect on other types of nodes.
def libsbml.ASTNode.getCharacter | ( | self | ) |
Python method signature(s):
getCharacter(ASTNode self)string
Get the value of this node as a single character. This function should be called only when ASTNode.getType() returns AST_PLUS, AST_MINUS, AST_TIMES, AST_DIVIDE or AST_POWER.
def libsbml.ASTNode.getChild | ( | self, | |
args | |||
) |
Python method signature(s):
getChild(ASTNode self, long n)ASTNode
Get a child of this node according to its index number.
n | the index of the child to get |
None
if this node has no nth child (n >
ASTNode.getNumChildren() - 1
). def libsbml.ASTNode.getClass | ( | self | ) |
def libsbml.ASTNode.getDefinitionURL | ( | self | ) |
Python method signature(s):
getDefinitionURL(ASTNode self)XMLAttributes
Gets the MathML definitionURL
attribute value.
definitionURL
attribute, in the form of a libSBML XMLAttributes object. def libsbml.ASTNode.getDenominator | ( | self | ) |
Python method signature(s):
getDenominator(ASTNode self)long
Get the value of the denominator of this node. This function should be called only when ASTNode.getType() == AST_RATIONAL
.
def libsbml.ASTNode.getExponent | ( | self | ) |
Python method signature(s):
getExponent(ASTNode self)long
Get the exponent value of this ASTNode. This function should be called only when ASTNode.getType() returns AST_REAL_E or AST_REAL.
def libsbml.ASTNode.getId | ( | self | ) |
def libsbml.ASTNode.getInteger | ( | self | ) |
Python method signature(s):
getInteger(ASTNode self)long
Get the value of this node as an integer. This function should be called only when ASTNode.getType() == AST_INTEGER
.
long
) integer. def libsbml.ASTNode.getLeftChild | ( | self | ) |
Python method signature(s):
getLeftChild(ASTNode self)ASTNode
Get the left child of this node.
0
. def libsbml.ASTNode.getListOfNodes | ( | self | ) |
Python method signature(s):
getListOfNodes(ASTNode self)ASTNodeList
Performs a depth-first search of the tree rooted at this ASTNode object, and returns a List of nodes where the given function predicate(node)
returns True
(non-zero).
For portability between different programming languages, the predicate is passed in as a pointer to a function.
predicate | the predicate to use |
True
(non-zero). The List returned is owned by the caller and should be deleted after the caller is done using it. The ASTNode objects in the list; however, are not owned by the caller (as they still belong to the tree itself), and therefore should not be deleted. def libsbml.ASTNode.getMantissa | ( | self | ) |
Python method signature(s):
getMantissa(ASTNode self)float
Get the mantissa value of this node. This function should be called only when ASTNode.getType() returns AST_REAL_E or AST_REAL. If ASTNode.getType() returns AST_REAL, this method is identical to ASTNode.getReal().
def libsbml.ASTNode.getName | ( | self | ) |
getName(ASTNode self) string *
Get the value of this node as a string. This function may be called on nodes that (1) are not operators, i.e., nodes for which ASTNode.isOperator() returns False
, and (2) are not numbers, i.e., ASTNode.isNumber() returns False
.
def libsbml.ASTNode.getNumChildren | ( | self | ) |
def libsbml.ASTNode.getNumerator | ( | self | ) |
Python method signature(s):
getNumerator(ASTNode self)long
Get the value of the numerator of this node. This function should be called only when ASTNode.getType() == AST_RATIONAL
.
def libsbml.ASTNode.getNumSemanticsAnnotations | ( | self | ) |
Python method signature(s):
getNumSemanticsAnnotations(ASTNode self)long
Get the number of semantic annotation elements inside this node.
The<semantics>
element is a MathML 2.0 construct
that can be used to associate additional information with a MathML
construct. The construct can be used to decorate a MathML expressions with
a sequence of one or more <annotation>
or
<annotation-xml>
elements. Each such element contains a
pair of items; the first is a symbol that acts as an attribute or key, and
the second is the value associated with the attribute or key. Please refer
to the MathML 2.0 documentation, particularly the Section
5.2, Semantic Annotations for more information about these constructs.
def libsbml.ASTNode.getOperatorName | ( | self | ) |
getOperatorName(ASTNode self) string *
Get the value of this operator node as a string. This function may be called on nodes that are operators, i.e., nodes for which ASTNode.isOperator() returns True
.
def libsbml.ASTNode.getParentSBMLObject | ( | self | ) |
def libsbml.ASTNode.getPrecedence | ( | self | ) |
Python method signature(s):
getPrecedence(ASTNode self)int
Get the precedence of this node in the infix math syntax of SBML Level 1. For more information about the infix syntax, see the discussion about text string formulas at the top of the documentation for ASTNode.
def libsbml.ASTNode.getReal | ( | self | ) |
Python method signature(s):
getReal(ASTNode self)float
Get the real-numbered value of this node. This function should be called only when ASTNode.isReal() == true
.
This function performs the necessary arithmetic if the node type is AST_REAL_E (mantissa * 10 exponent) or AST_RATIONAL (numerator / denominator).
def libsbml.ASTNode.getRightChild | ( | self | ) |
Python method signature(s):
getRightChild(ASTNode self)ASTNode
Get the right child of this node.
None
if this node has no right child. If ASTNode.getNumChildren() > 1
, then this is equivalent to: def libsbml.ASTNode.getSemanticsAnnotation | ( | self, | |
args | |||
) |
Python method signature(s):
getSemanticsAnnotation(ASTNode self, long n)XMLNode
Get the nth semantic annotation of this node.
The<semantics>
element is a MathML 2.0 construct
that can be used to associate additional information with a MathML
construct. The construct can be used to decorate a MathML expressions with
a sequence of one or more <annotation>
or
<annotation-xml>
elements. Each such element contains a
pair of items; the first is a symbol that acts as an attribute or key, and
the second is the value associated with the attribute or key. Please refer
to the MathML 2.0 documentation, particularly the Section
5.2, Semantic Annotations for more information about these constructs.
None
if this node has no nth annotation (n >
ASTNode.getNumChildren() - 1
).def libsbml.ASTNode.getStyle | ( | self | ) |
def libsbml.ASTNode.getType | ( | self | ) |
Python method signature(s):
getType(ASTNode self)long
Get the type of this ASTNode. The value returned is one of the enumeration values such as AST_LAMBDA, AST_PLUS, etc.
def libsbml.ASTNode.getUnits | ( | self | ) |
Python method signature(s):
getUnits(ASTNode self)string
Get the units of this ASTNode.
SBML Level 3 Version 1 introduced the ability to include an attributesbml:units
on MathML cn
elements
appearing in SBML mathematical formulas. The value of this attribute can
be used to indicate the unit of measurement to be associated with the
number in the content of the cn
element. The value of this
attribute must be the identifier of a unit of measurement defined by SBML
or the enclosing Model. Here, the sbml
portion is an XML
namespace prefix that must be associated with the SBML namespace for SBML
Level 3. The following example illustrates how this attribute can be
used to define a number with value 10
and unit of measurement
second
:
<math xmlns="http://www.w3.org/1998/Math/MathML" xmlns:sbml="http://www.sbml.org/sbml/level3/version1/core"> <cn type="integer" sbml:units="second"> 10 </cn> </math>
sbml:units
attribute is only available in SBML Level 3. It may not be used in Levels 1–2 of SBML.def libsbml.ASTNode.hasCorrectNumberArguments | ( | self | ) |
Python method signature(s):
hasCorrectNumberArguments(ASTNode self)bool
Predicate returning True
or False
depending on whether this ASTNode has the correct number of children for it's type.
For example, an ASTNode with type AST_PLUS expects 2 child nodes.
True
if this ASTNode is has appropriate number of children for it's type, False
otherwise.def libsbml.ASTNode.hasUnits | ( | self | ) |
Python method signature(s):
hasUnits(ASTNode self)bool
Predicate returning True
(non-zero) if this node or any of its children nodes have the attribute sbml:units
.
sbml:units
on MathML cn
elements
appearing in SBML mathematical formulas. The value of this attribute can
be used to indicate the unit of measurement to be associated with the
number in the content of the cn
element. The value of this
attribute must be the identifier of a unit of measurement defined by SBML
or the enclosing Model. Here, the sbml
portion is an XML
namespace prefix that must be associated with the SBML namespace for SBML
Level 3. The following example illustrates how this attribute can be
used to define a number with value 10
and unit of measurement
second
:
<math xmlns="http://www.w3.org/1998/Math/MathML" xmlns:sbml="http://www.sbml.org/sbml/level3/version1/core"> <cn type="integer" sbml:units="second"> 10 </cn> </math>
True
if this ASTNode or its children has units associated with it, False
otherwise.sbml:units
attribute is only available in SBML Level 3. It may not be used in Levels 1–2 of SBML. def libsbml.ASTNode.insertChild | ( | self, | |
args | |||
) |
Python method signature(s):
insertChild(ASTNode self, long n, ASTNode newChild)int
Insert the given ASTNode at point n in the list of children of this ASTNode.
def libsbml.ASTNode.isAvogadro | ( | self | ) |
Python method signature(s):
isAvogadro(ASTNode self)bool
Predicate returning True
(non-zero) if this node is the special symbol avogadro
. The predicate returns False
(zero) otherwise.
True
if this ASTNode is the special symbol avogadro.def libsbml.ASTNode.isBoolean | ( | self | ) |
def libsbml.ASTNode.isConstant | ( | self | ) |
Python method signature(s):
isConstant(ASTNode self)bool
Predicate returning True
(non-zero) if this node represents a MathML constant (e.g., True
, Pi
).
True
if this ASTNode is a MathML constant, False
otherwise.True
for AST_NAME_AVOGADRO in SBML Level 3. def libsbml.ASTNode.isFunction | ( | self | ) |
def libsbml.ASTNode.isInfinity | ( | self | ) |
def libsbml.ASTNode.isInteger | ( | self | ) |
Python method signature(s):
isInteger(ASTNode self)bool
Predicate returning True
(non-zero) if this node contains an integer value, False
(zero) otherwise.
True
if this ASTNode is of type AST_INTEGER, False
otherwise. def libsbml.ASTNode.isLambda | ( | self | ) |
Python method signature(s):
isLambda(ASTNode self)bool
Predicate returning True
(non-zero) if this node is a MathML <lambda>
, False
(zero) otherwise.
True
if this ASTNode is of type AST_LAMBDA, False
otherwise. def libsbml.ASTNode.isLog10 | ( | self | ) |
Python method signature(s):
isLog10(ASTNode self)bool
Predicate returning True
(non-zero) if this node represents a log10
function, False
(zero) otherwise. More precisely, this predicate returns True
if the node type is AST_FUNCTION_LOG with two children, the first of which is an AST_INTEGER equal to 10.
True
if the given ASTNode represents a log10() function, false
otherwise.def libsbml.ASTNode.isLogical | ( | self | ) |
def libsbml.ASTNode.isName | ( | self | ) |
Python method signature(s):
isName(ASTNode self)bool
Predicate returning True
(non-zero) if this node is a user-defined variable name in SBML L1, L2 (MathML), or the special symbols delay
or time
. The predicate returns False
(zero) otherwise.
True
if this ASTNode is a user-defined variable name in SBML L1, L2 (MathML) or the special symbols delay or time. def libsbml.ASTNode.isNaN | ( | self | ) |
def libsbml.ASTNode.isNegInfinity | ( | self | ) |
def libsbml.ASTNode.isNumber | ( | self | ) |
def libsbml.ASTNode.isOperator | ( | self | ) |
def libsbml.ASTNode.isPiecewise | ( | self | ) |
def libsbml.ASTNode.isRational | ( | self | ) |
Python method signature(s):
isRational(ASTNode self)bool
Predicate returning True
(non-zero) if this node represents a rational number, False
(zero) otherwise.
True
if this ASTNode is of type AST_RATIONAL. def libsbml.ASTNode.isReal | ( | self | ) |
Python method signature(s):
isReal(ASTNode self)bool
Predicate returning True
(non-zero) if this node can represent a real number, False
(zero) otherwise. More precisely, this node must be of one of the following types: AST_REAL, AST_REAL_E or AST_RATIONAL.
True
if the value of this ASTNode can represented as a real number, False
otherwise. def libsbml.ASTNode.isRelational | ( | self | ) |
def libsbml.ASTNode.isSetClass | ( | self | ) |
def libsbml.ASTNode.isSetId | ( | self | ) |
def libsbml.ASTNode.isSetStyle | ( | self | ) |
def libsbml.ASTNode.isSetUnits | ( | self | ) |
Python method signature(s):
isSetUnits(ASTNode self)bool
Predicate returning True
(non-zero) if this node has the attribute sbml:units
.
sbml:units
on MathML cn
elements
appearing in SBML mathematical formulas. The value of this attribute can
be used to indicate the unit of measurement to be associated with the
number in the content of the cn
element. The value of this
attribute must be the identifier of a unit of measurement defined by SBML
or the enclosing Model. Here, the sbml
portion is an XML
namespace prefix that must be associated with the SBML namespace for SBML
Level 3. The following example illustrates how this attribute can be
used to define a number with value 10
and unit of measurement
second
:
<math xmlns="http://www.w3.org/1998/Math/MathML" xmlns:sbml="http://www.sbml.org/sbml/level3/version1/core"> <cn type="integer" sbml:units="second"> 10 </cn> </math>
True
if this ASTNode has units associated with it, False
otherwise.sbml:units
attribute is only available in SBML Level 3. It may not be used in Levels 1–2 of SBML. def libsbml.ASTNode.isSqrt | ( | self | ) |
Python method signature(s):
isSqrt(ASTNode self)bool
Predicate returning True
(non-zero) if this node represents a square root function, False
(zero) otherwise. More precisely, the node type must be AST_FUNCTION_ROOT with two children, the first of which is an AST_INTEGER node having value equal to 2.
True
if the given ASTNode represents a sqrt() function, False
otherwise. def libsbml.ASTNode.isUMinus | ( | self | ) |
Python method signature(s):
isUMinus(ASTNode self)bool
Predicate returning True
(non-zero) if this node is a unary minus operator, False
(zero) otherwise. A node is defined as a unary minus node if it is of type AST_MINUS and has exactly one child.
For numbers, unary minus nodes can be 'collapsed' by negating the number. In fact, libsbml.parseFormula() does this during its parsing process, and libsbml.parseL3Formula() has a configuration option that allows this behavior to be turned on or off. However, unary minus nodes for symbols (AST_NAME) cannot be 'collapsed', so this predicate function is necessary.
True
if this ASTNode is a unary minus, False
otherwise.def libsbml.ASTNode.isUnknown | ( | self | ) |
Python method signature(s):
isUnknown(ASTNode self)bool
Predicate returning True
(non-zero) if this node has an unknown type.
'Unknown' nodes have the type AST_UNKNOWN. Nodes with unknown types will not appear in an ASTNode tree returned by libSBML based upon valid SBML input; the only situation in which a node with type AST_UNKNOWN may appear is immediately after having create a new, untyped node using the ASTNode constructor. Callers creating nodes should endeavor to set the type to a valid node type as soon as possible after creating new nodes.
True
if this ASTNode is of type AST_UNKNOWN, False
otherwise. def libsbml.ASTNode.isUPlus | ( | self | ) |
Python method signature(s):
isUPlus(ASTNode self)bool
Predicate returning True
(non-zero) if this node is a unary plus operator, False
(zero) otherwise. A node is defined as a unary minus node if it is of type AST_MINUS and has exactly one child.
True
if this ASTNode is a unary plus, False
otherwise. def libsbml.ASTNode.isWellFormedASTNode | ( | self | ) |
Python method signature(s):
isWellFormedASTNode(ASTNode self)bool
Predicate returning True
or False
depending on whether this ASTNode is well-formed.
True
if this ASTNode is well-formed, False
otherwise.def libsbml.ASTNode.prependChild | ( | self, | |
args | |||
) |
Python method signature(s):
prependChild(ASTNode self, ASTNode child)int
Adds the given node as a child of this ASTNode. This method adds child nodes from right to left.
child | the ASTNode instance to add |
def libsbml.ASTNode.reduceToBinary | ( | self | ) |
def libsbml.ASTNode.removeChild | ( | self, | |
args | |||
) |
Python method signature(s):
removeChild(ASTNode self, long n)int
Removes the nth child of this ASTNode object.
n | long the index of the child to remove |
def libsbml.ASTNode.renameSIdRefs | ( | self, | |
args | |||
) |
Python method signature(s):
renameSIdRefs(ASTNode self, string oldid, string newid)
Renames all the SIdRef attributes on this node and any child node
def libsbml.ASTNode.renameUnitSIdRefs | ( | self, | |
args | |||
) |
Python method signature(s):
renameUnitSIdRefs(ASTNode self, string oldid, string newid)
Renames all the UnitSIdRef attributes on this node and any child node. (The only place UnitSIDRefs appear in MathML <cn>
elements.)
def libsbml.ASTNode.replaceArgument | ( | self, | |
args | |||
) |
Python method signature(s):
replaceArgument(ASTNode self, string bvar, ASTNode arg)
Replaces occurences of a given name within this ASTNode with the name/value/formula represented by arg
.
For example, if the formula in this ASTNode is x + y
, then the <bvar>
is x
and arg
is an ASTNode representing the real value 3
. This method substitutes 3
for x
within this ASTNode object.
bvar | a string representing the variable name to be substituted |
arg | an ASTNode representing the name/value/formula to substitute |
def libsbml.ASTNode.replaceChild | ( | self, | |
args | |||
) |
Python method signature(s):
replaceChild(ASTNode self, long n, ASTNode newChild)int
Replaces the nth child of this ASTNode with the given ASTNode.
n | long the index of the child to replace |
newChild | ASTNode to replace the nth child |
def libsbml.ASTNode.returnsBoolean | ( | self, | |
model = None |
|||
) |
Python method signature(s):
returnsBoolean(ASTNode self, Model model=None)bool returnsBoolean(ASTNode self)
bool
Predicate returning True
(non-zero) if this node returns a boolean type or False
(zero) otherwise.
This function looks at the whole ASTNode rather than just the top level of the ASTNode. Thus it will consider return values from piecewise statements. In addition, if this ASTNode uses a function call, the return value of the functionDefinition will be determined. Note that this is only possible where the ASTNode can trace its parent Model, that is, the ASTNode must represent the math element of some SBML object that has already been added to an instance of an SBMLDocument.
def libsbml.ASTNode.setCharacter | ( | self, | |
args | |||
) |
Python method signature(s):
setCharacter(ASTNode self, char value)int
Sets the value of this ASTNode to the given character. If character is one of +
, -
, *
, /
or ^
, the node type will be set accordingly. For all other characters, the node type will be set to AST_UNKNOWN.
value | the character value to which the node's value should be set. |
def libsbml.ASTNode.setClass | ( | self, | |
args | |||
) |
Python method signature(s):
setClass(ASTNode self, string className)int
Sets the mathml class of this ASTNode to className.
className | string representing the mathml class for this node. |
def libsbml.ASTNode.setId | ( | self, | |
args | |||
) |
def libsbml.ASTNode.setName | ( | self, | |
args | |||
) |
setName(ASTNode self, char * name) int
Sets the value of this ASTNode to the given name.
As a side-effect, this ASTNode object's type will be reset to AST_NAME if (and only if) the ASTNode was previously an operator ( ASTNode.isOperator() == true
), number ( ASTNode.isNumber() == true
), or unknown. This allows names to be set for AST_FUNCTION nodes and the like.
name | the string containing the name to which this node's value should be set |
def libsbml.ASTNode.setStyle | ( | self, | |
args | |||
) |
def libsbml.ASTNode.setType | ( | self, | |
args | |||
) |
Python method signature(s):
setType(ASTNode self, long type)int
Sets the type of this ASTNode to the given type code. A side-effect of doing this is that any numerical values previously stored in this node are reset to zero.
type | the type to which this node should be set |
def libsbml.ASTNode.setUnits | ( | self, | |
args | |||
) |
Python method signature(s):
setUnits(ASTNode self, string units)int
Sets the units of this ASTNode to units.
The units will be set only if this ASTNode object represents a MathML <cn>
element, i.e., represents a number. Callers may use ASTNode.isNumber() to inquire whether the node is of that type.
sbml:units
on MathML cn
elements
appearing in SBML mathematical formulas. The value of this attribute can
be used to indicate the unit of measurement to be associated with the
number in the content of the cn
element. The value of this
attribute must be the identifier of a unit of measurement defined by SBML
or the enclosing Model. Here, the sbml
portion is an XML
namespace prefix that must be associated with the SBML namespace for SBML
Level 3. The following example illustrates how this attribute can be
used to define a number with value 10
and unit of measurement
second
:
<math xmlns="http://www.w3.org/1998/Math/MathML" xmlns:sbml="http://www.sbml.org/sbml/level3/version1/core"> <cn type="integer" sbml:units="second"> 10 </cn> </math>
units | string representing the unit identifier. |
sbml:units
attribute is only available in SBML Level 3. It may not be used in Levels 1–2 of SBML. def libsbml.ASTNode.setValue | ( | self, | |
args | |||
) |
Python method signature(s):
setValue(ASTNode self, long value)int setValue(ASTNode self, long numerator, long denominator)
int setValue(ASTNode self, float value)
int setValue(ASTNode self, float mantissa, long exponent)
int
This method has multiple variants that differ in the arguments they accept. Each is described separately below.
Method variant with the following signature:
setValue(long numerator, long denominator)
Sets the value of this ASTNode to the given rational in two parts: the numerator and denominator. The node type is set to AST_RATIONAL.
numerator | the numerator value of the rational |
denominator | the denominator value of the rational |
setValue (float mantissa, long exponent)
Sets the value of this ASTNode to the given real (float
) in two parts: the mantissa and the exponent. The node type is set to AST_REAL_E.
mantissa | the mantissa of this node's real-numbered value |
exponent | the exponent of this node's real-numbered value |
setValue(int value)
Sets the value of this ASTNode to the given integer and sets the node type to AST_INTEGER.
value | the integer to which this node's value should be set |
setValue (float value)
Sets the value of this ASTNode to the given real (float
) and sets the node type to AST_REAL.
This is functionally equivalent to:
value | the float format number to which this node's value should be set |
setValue(long value)
Sets the value of this ASTNode to the given (long
) integer and sets the node type to AST_INTEGER.
value | the integer to which this node's value should be set |
def libsbml.ASTNode.swapChildren | ( | self, | |
args | |||
) |
Python method signature(s):
swapChildren(ASTNode self, ASTNode that)int
Swap the children of this ASTNode object with the children of the given ASTNode object.
that | the other node whose children should be used to replace this node's children |
def libsbml.ASTNode.unsetClass | ( | self | ) |
def libsbml.ASTNode.unsetId | ( | self | ) |
def libsbml.ASTNode.unsetStyle | ( | self | ) |