factory¶
Factory for creating SBML objects.
This module provides definitions of helper functions for the creation of SBML objects. These are the low level helpers to create models from scratch and are used in the higher level SBML factories.
The general workflow to create new SBML models isto create a lists/iterables of SBMLObjects by using the respective classes in this module, e.g. Compartment, Parameter, Species.
The actual SBase objects are than created in the SBMLDocument/Model by calling create_objects(model, objects) These functions DO NOT take care of the order of the creation, but the order must be correct in the model definition files. To create complete models one should use the modelcreator functionality, which takes care of the order of object creation.
ReactionEquation
¶
Representation of stoichiometric equations with modifiers.
Initialize equation.
EquationException
¶
Bases: Exception
Exception in Equation.
ValidationOptions
dataclass
¶
ValidationOptions(
log_errors=True,
internal_consistency=True,
general_consistency=True,
identifier_consistency=True,
mathml_consistency=True,
units_consistency=True,
sbo_consistency=True,
overdetermined_model=True,
modeling_practice=True,
)
Options for SBML validator.
Controls the consistency checks that are performed when SBMLDocument.checkConsistency() is called.
-
general_consistency: Correctness and consistency of specific SBML language constructs. Performing this set of checks is highly recommended. With respect to the SBML specification, these concern failures in applying the validation rules numbered 2xxxx in the Level 2 Versions 2-4 and Level 3 Versions 1-2 specifications. -
ìdentifier_consistency: Correctness and consistency of identifiers used for model entities. An example of inconsistency would be using a species identifier in a reaction rate formula without first having declared the species. With respect to the SBML specification, these concern failures in applying the validation rules numbered 103xx in the Level 2 Versions 2-4 and Level 3 Versions 1-2 specifications. -
units_consistency: Consistency of measurement units associated with quantities in a model. With respect to the SBML specification, these concern failures in applying the validation rules numbered 105xx in the Level 2 Versions 2-4 and Level 3 Versions 1-2 specifications. -
mathml_consistency: Syntax of MathML constructs. With respect to the SBML specification, these concern failures in applying the validation rules numbered 102xx in the Level 2 Versions 2-4 and Level 3 Versions 1-2 specifications. -
sbo_consistency: Consistency and validity of SBO identifiers (if any) used in the model. With respect to the SBML specification, these concern failures in applying the validation rules numbered 107xx in the Level 2 Versions 2-4 and Level 3 Versions 1-2 specifications. -
overdetermined_model: Static analysis of whether the system of equations implied by a model is mathematically overdetermined. With respect to the SBML specification, this is validation rule #10601 in the Level 2 Versions 2-4 and Level 3 Versions 1-2 specifications. -
modeling_practise: Additional checks for recommended good modeling practice. (These are tests performed by libSBML and do not have equivalent SBML validation rules.) By default, all validation checks are applied to the model in an SBMLDocument object unless SBMLDocument.setConsistencyChecks() is called to indicate that only a subset should be applied. Further, this default (i.e., performing all checks) applies separately to each new SBMLDocument object created. In other words, each time a model is read using SBMLReader.readSBML(), SBMLReader.readSBMLFromString(), or the global functions readSBML() and readSBMLFromString(), a new SBMLDocument is created and for that document, a call to SBMLDocument.checkConsistency() will default to applying all possible checks. Calling programs must invoke SBMLDocument.setConsistencyChecks() for each such new model if they wish to change the consistency checks applied. -
internal_consistency: Additional checks that model is consistent XML. -
log_errorsBoolean flag to log errors.
ModelUnits
¶
Class for storing model units information.
The ModelUnits define globally the units for time, extent, substance,
length, area and volume.
The following SBML Level 3 base units can be used.
ampere farad joule lux radian volt avogadro gram katal metre second watt becquerel gray kelvin mole siemens weber candela henry kilogram newton sievert coulomb hertz litre ohm steradian dimensionless item lumen pascal tesla
Construct ModelUnits.
set_model_units
staticmethod
¶
Set the main units in model from dictionary.
Setting the model units is important for understanding the model dynamics. Allowed keys are: time extent substance length area volume
:param model: SBMLModel :param model_units: dict of units :return:
Sbase
¶
Sbase(
sid=None,
name=None,
sboTerm=None,
metaId=None,
annotations=None,
notes=None,
keyValuePairs=None,
port=None,
uncertainties=None,
replacedBy=None,
)
Base class of all SBML objects.
KeyValuePair
¶
Value
¶
Value(
sid,
value,
name=None,
sboTerm=None,
metaId=None,
annotations=None,
notes=None,
keyValuePairs=None,
port=None,
uncertainties=None,
replacedBy=None,
)
Bases: Sbase
Helper class.
The value field is a helper storage field which is used differently by different subclasses.
UnitDefinition
¶
Units
¶
ValueWithUnit
¶
ValueWithUnit(
sid,
value,
unit=dimensionless,
name=None,
sboTerm=None,
metaId=None,
annotations=None,
notes=None,
keyValuePairs=None,
port=None,
uncertainties=None,
replacedBy=None,
)
Bases: Value
Helper class.
The value field is a helper storage field which is used differently by different subclasses.
Function
¶
Parameter
¶
Parameter(
sid,
value=None,
unit=None,
constant=True,
name=None,
sboTerm=None,
metaId=None,
annotations=None,
notes=None,
keyValuePairs=None,
port=None,
uncertainties=None,
replacedBy=None,
)
Compartment
¶
Compartment(
sid,
value,
unit=None,
constant=True,
spatialDimensions=3,
name=None,
sboTerm=None,
metaId=None,
annotations=None,
notes=None,
keyValuePairs=None,
port=None,
uncertainties=None,
replacedBy=None,
)
Species
¶
Species(
sid,
compartment,
initialAmount=None,
initialConcentration=None,
substanceUnit=None,
hasOnlySubstanceUnits=False,
constant=False,
boundaryCondition=False,
charge=None,
chemicalFormula=None,
conversionFactor=None,
name=None,
sboTerm=None,
metaId=None,
annotations=None,
notes=None,
keyValuePairs=None,
port=None,
uncertainties=None,
replacedBy=None,
)
InitialAssignment
¶
InitialAssignment(
symbol,
value,
unit=dimensionless,
sid=None,
name=None,
sboTerm=None,
metaId=None,
annotations=None,
notes=None,
keyValuePairs=None,
port=None,
uncertainties=None,
replacedBy=None,
)
Bases: Value
InitialAssignments.
The unit attribute is only for the case where a parameter must be created (which has the unit). In case of an initialAssignment of a value the units have to be defined in the math.
Construct InitialAssignment.
create_sbml
¶
Create InitialAssignment.
Creates a required parameter if the symbol for the initial assignment does not exist in the model.
RuleWithVariable
¶
Rule.
check_model_for_rule
¶
Check model for rule requirements.
Creates a required parameter if the symbol for the initial assignment does not exist in the model.
AssignmentRule
¶
AssignmentRule(
variable,
value,
unit=dimensionless,
sid=None,
name=None,
sboTerm=None,
metaId=None,
annotations=None,
notes=None,
keyValuePairs=None,
port=None,
uncertainties=None,
replacedBy=None,
)
Bases: ValueWithUnit, RuleWithVariable
AssignmentRule.
The unit attribute is only for the case where a parameter must be created (which has the unit). In case of an initialAssignment of a value the units have to be defined in the math.
Construct AssignmentRule.
RateRule
¶
RateRule(
variable,
value,
unit=dimensionless,
sid=None,
name=None,
sboTerm=None,
metaId=None,
annotations=None,
notes=None,
keyValuePairs=None,
port=None,
uncertainties=None,
replacedBy=None,
)
AlgebraicRule
¶
AlgebraicRule(
sid,
value,
unit=dimensionless,
name=None,
sboTerm=None,
metaId=None,
annotations=None,
notes=None,
keyValuePairs=None,
port=None,
uncertainties=None,
replacedBy=None,
)
Reaction
¶
Reaction(
sid,
equation,
formula=None,
pars=None,
rules=None,
compartment=None,
fast=False,
reversible=None,
lowerFluxBound=None,
upperFluxBound=None,
geneProductAssociation=None,
name=None,
sboTerm=None,
metaId=None,
annotations=None,
notes=None,
keyValuePairs=None,
port=None,
uncertainties=None,
replacedBy=None,
)
Bases: Sbase
Reaction.
Class for creating libsbml.Reaction.
Equations are of the form '1.0 S1 + 2 S2 => 2.0 P1 + 2 P2 [M1, M2]'
The equation consists of - substrates concatenated via '+' on the left side (with optional stoichiometric coefficients) - separation characters separating the left and right equation sides: '<=>' or '<->' for reversible reactions, '=>' or '->' for irreversible reactions (irreversible reactions are written from left to right) - products concatenated via '+' on the right side (with optional stoichiometric coefficients) - optional list of modifiers within brackets [] separated by ','
Examples of valid equations are
'1.0 S1 + 2 S2 => 2.0 P1 + 2 P2 [M1, M2]', 'c__gal1p => c__gal + c__phos', 'e__h2oM <-> c__h2oM', '3 atp + 2.0 phos + ki <-> 16.98 tet', 'c__gal1p => c__gal + c__phos [c__udp, c__utp]', 'A_ext => A []', '=> cit', 'acoa =>',
Construct Reaction.
Event
¶
Constraint
¶
Constraint(
sid,
math,
message=None,
name=None,
sboTerm=None,
metaId=None,
annotations=None,
notes=None,
keyValuePairs=None,
port=None,
uncertainties=None,
replacedBy=None,
)
Bases: Sbase
Constraint.
The Constraint object is a mechanism for stating the assumptions under which a model is designed to operate. The constraints are statements about permissible values of different quantities in a model.
The message must be well formated XHTML, e.g., message='
ATP must be non-negative'Constraint constructor.
UncertParameter
¶
UncertParameter.
FIXME: This is an SBase!
Construct UncertParameter.
UncertSpan
¶
UncertSpan.
FIXME: This is an SBase!
Construct UncertSpan.
Uncertainty
¶
ExchangeReaction
¶
ExchangeReaction(
species_id,
compartment=None,
fast=False,
reversible=True,
lowerFluxBound=None,
upperFluxBound=None,
geneProductAssociation=None,
name=None,
metaId=None,
annotations=None,
notes=None,
keyValuePairs=None,
port=None,
uncertainties=None,
replacedBy=None,
)
Bases: Reaction
Exchange reactions define substances which can be exchanged.
This is important for FBC models.
EXCHANGE_IMPORT (-INF, 0): is defined as negative flux through the exchange reaction, i.e. the upper bound must be 0, the lower bound some negative value, e.g. -INF
EXCHANGE_EXPORT (0, INF): is defined as positive flux through the exchange reaction, i.e. the lower bound must be 0, the upper bound some positive value, e.g. INF
Construct ExchangeReaction.
GeneProduct
¶
GeneProduct(
sid,
label,
associatedSpecies=None,
name=None,
sboTerm=None,
metaId=None,
annotations=None,
notes=None,
keyValuePairs=None,
port=None,
uncertainties=None,
replacedBy=None,
)
Bases: Sbase
GeneProduct.
GeneProduct is a new FBC class derived from SBML SBase that inherits metaid and sboTerm, as well as the subcomponents for Annotation and Notes. The purpose of this class is to define a single gene product. It implements two required attributes id and label as well as two optional attributes name and associatedSpecies.
Create a GeneProduct.
UserDefinedConstraintComponent
¶
UserDefinedConstraint
¶
UserDefinedConstraint(
lowerBound,
upperBound,
components=None,
variableType=FBC_VARIABLE_TYPE_LINEAR,
sid=None,
name=None,
sboTerm=None,
metaId=None,
annotations=None,
notes=None,
keyValuePairs=None,
port=None,
uncertainties=None,
replacedBy=None,
)
Bases: Sbase
UserDefinedConstraint.
The FBC UserDefinedConstraint class is derived from SBML SBase and inherits metaid and sboTerm, as well as the subcomponents for Annotation and Notes. It’s purpose is to define non-stoichiometric constraints, that is constraints that are not necessarily defined by the stoichiometrically coupled reaction network. In order to achieve, we defined a new type of linear constraint, the UserDefinedConstraint
Create an UserDefinedConstraint.
FluxObjective
¶
Objective
¶
Objective(
sid,
objectiveType=OBJECTIVE_TYPE_MAXIMIZE,
active=True,
fluxObjectives=None,
variableType=FBC_VARIABLE_TYPE_LINEAR,
name=None,
sboTerm=None,
metaId=None,
annotations=None,
notes=None,
keyValuePairs=None,
port=None,
uncertainties=None,
replacedBy=None,
)
Bases: Sbase
Objective.
Create an Objective.
FluxObjectives can either be provided as a list of FluxObjectives or as a dictionary with the reaction ids as keys and the coefficients as values.
ModelDefinition
¶
ExternalModelDefinition
¶
Submodel
¶
SbaseRef
¶
ReplacedElement
¶
ReplacedBy
¶
Deletion
¶
PortType
¶
Bases: StrEnum
Supported port types.
Port
¶
Port(
sid,
portRef=None,
idRef=None,
unitRef=None,
metaIdRef=None,
portType=PORT,
name=None,
sboTerm=None,
metaId=None,
annotations=None,
notes=None,
keyValuePairs=None,
)
Bases: SbaseRef
Port.
Ports are stored in an optional child ListOfPorts object, which, if present, must contain one or more Port objects. All of the Ports present in the ListOfPorts collectively define the 'port interface' of the Model.
Create a Port.
Package
¶
Bases: StrEnum
Supported/tested packages.
ModelDict
¶
Bases: TypedDict
ModelDict.
The ModelDict allows to define the Model as dictionary and then use:
md: ModelDict Model(**md)
For model construction. If possible use the Model object directly.
Model
¶
Model(
sid,
name=None,
sboTerm=None,
metaId=None,
annotations=None,
notes=None,
keyValuePairs=None,
packages=None,
creators=None,
model_units=None,
units=None,
objects=None,
external_model_definitions=None,
model_definitions=None,
submodels=None,
functions=None,
compartments=None,
species=None,
parameters=None,
assignments=None,
rules=None,
rate_rules=None,
algebraic_rules=None,
reactions=None,
events=None,
constraints=None,
ports=None,
replaced_elements=None,
deletions=None,
user_defined_constraints=None,
objectives=None,
gene_products=None,
layouts=None,
)
Bases: Sbase, FrozenClass, BaseModel
Model.
Model constructor.
create_sbml
¶
Create Model.
To create the complete SBMLDocument with the model use:
doc = Document(model=model).create_sbml()
Document
¶
FactoryResult
dataclass
¶
Data structure for model creation.
create_objects
¶
Create the objects in the model.
This function calls the respective create_sbml function of all objects in the order of the objects.
:param model: SBMLModel instance :param obj_iter: iterator of given model object classes like Parameter, ... :param key: object key :return: dictionary of SBML objects
ast_node_from_formula
¶
Parse the ASTNode from given formula string with model.
:param model: SBMLModel instance :param formula: formula str :return: astnode
set_notes
¶
Set notes information on SBase.
:param sbase: SBase :param notes: notes information (xml string) :return:
set_model_history
¶
Set the model history from given creators.
:param sbase: SBML model :param creators: list of creators :param set_timestamps: boolean flag to set timestamps on history. :return:
create_model
¶
create_model(
model,
filepath,
sbml_level=SBML_LEVEL,
sbml_version=SBML_VERSION,
validate=True,
validation_options=None,
show_sbml=False,
annotations=None,
create_antimony=False,
create_markdown=False,
)
Create SBML model from models.
This is the entry point for creating models. If multiple models are provided
these are merged in the process of model creation. See merge_models for more
details.
Additional model annotations can be provided via a file.
The created SBML can be serialized to additional formats for inspection, which
are written next to the SBML file: the antimony serialization of the model
(create_antimony, *.ant) and the markdown overview of the ODE system
(create_markdown, *.md, see sbmlutils.converters.odefac).
:param model: Model or iterable of Model instances which are merged in single model
:param filepath: Path to write the SBML model to
:param sbml_level: set SBML level for model generation
:param sbml_version: set SBML version for model generation
:param validate: boolean flag to validate the SBML file
:param validation_options: options for model validation
:param show_sbml: boolean flag to show SBML
:param annotations: Path to annotations file
:param create_antimony: write the antimony serialization to *.ant
:param create_markdown: write the markdown overview of the ODE system to *.md
:return: FactoryResult