Accessing the SBML Model Variables

All of the SBML model variables are accessed via the RoadRunner.model object. This is an instance of the ExecutableModel class described here. One always access the model object that belongs to the top RoadRunner object, i.e. rr.model, where rr is an instance of the RoadRunner class.

The ExecutableModel class also implements the Python dictionary protocol, so that it can be used as a dictionary. The dictionary keys are all of the symbols specified in the original model as well as a number of selection strings described in the Selections section.

ExecutableModel.keys()

Get a list of all the keys that this model has. This is a very good way of looking at all the available symbols and selection strings:

>>> rr.model.keys()
[ 'S1', 'S2', '[S1]', '[S2]', 'compartment', 'k1', 'cm0',
  'reaction1',  'init([S1])',  'init([S2])', 'init(S1)',
  'init(S2)',  "S1'"]
ExecutableModel.items()

Get a list of key / value pairs of all the selections / values in the model.

>>> rr.model.items()
[('S1', 0.5), ('S2', 9.99954570660308), ('[S1]', 0.5), ('[S2]', 9.99954570660308),
('default_compartment', 1.0), ('k1', 1.0), ('init(k1)', 1.0), ('_J0', 0.5), ('init([S1])', 10.0),
('init([S2])', 0.0), ('init(S1)', 10.0), ('init(S2)', 0.0), ("S1'", -0.5), ("S2'", 0.5)]
ExecutableModel.__getitem__()

Implements the python [] indexing operator, so the model values can be accessed like:

>>> rr.model["S1"]
0.0

Following notation is also accepted:

>>> rr.S1
0.0
ExecutableModel.__setitem__()

Implements the python [] indexing operator for setting values:

>>> rr.model["S1]
0.0
>>> rr.model["S1"] = 1.3
>>> rr.model["S1"]
1.3

Following notation is also accepted:

>>> rr.S1 = 1.0

Note, some keys are read only such as values defined by rules, or calculated values such as reaction rates. If one attempts to set the value of a read-only symbol, an exception is raised indicating the error, and no harm done.

Floating Species

ExecutableModel.getFloatingSpeciesIds()

Return a list of all floating species SBML ids.

>>> rr.getFloatingSpeciesIds()
['S1', 'S2', 'S3', 'S4']
ExecutableModel.getDependentFloatingSpeciesIds()

Return a list of dependent floating species SBML ids.

>>> rr.getDependentFloatingSpeciesIds()
['S4']
ExecutableModel.getIndependentFloatingSpeciesIds()

Return a list of independent floating species SBML ids.

>>> rr.getIndependentFloatingSpeciesIds()
['S1', 'S2', 'S3']
ExecutableModel.getFloatingSpeciesConcentrationIds()

Return a list of all floating species concentration ids.

>>> rr.getFloatingSpeciesConcentrationIds()
['[S1]', '[S2]', '[S3]', '[S4]']
ExecutableModel.getNumFloatingSpecies()

Return the number of floating species in the model.

>>> rr.getNumFloatingSpecies()
2
ExecutableModel.getFloatingSpeciesAmounts([index])

Get the list of floating species amounts. If no arguments are given, this returns all floating species amounts.

Parameters:

index (numpy.ndarray) – (optional) an optional array of desired floating species indices.

Retuns:

an array of floating species amounts.

Return type:

numpy.ndarray

To get all the amounts:

>>> rr.model.getFloatingSpeciesAmounts()
array([ 0.97390578,  1.56331018,  1.15301155,  1.22717548])

To get amounts from index 0 and 1:

>>> rr.model.getFloatingSpeciesAmounts([0,1])
array([ 0.97390578,  1.56331018])
ExecutableModel.setFloatingSpeciesAmounts(values)

Use this to set the entire set of floating species amounts in one call. The order of species is given by the order of Ids returned by getFloatingSpeciesIds()

Parameters:

values (numpy.ndarray) – the values to set.

>>> rr.model.getFloatingSpeciesAmounts([0,1])
array([ 0.97390578,  1.56331018])
>>> rr.model.setFloatingSpeciesAmounts([1.0, 1.5])
>>> rr.model.getFloatingSpeciesAmounts([0,1])
array([ 1. ,  1.5])
ExecutableModel.getFloatingSpeciesConcentrations([index])

Return a vector of floating species concentrations. The order of species is given by the order of Ids returned by getFloatingSpeciesIds()

Parameters:

index (numpy.ndarray) – (optional) an index array indicating which items to return.

Returns:

an array of floating species concentrations.

Return type:

numpy.ndarray

>>> rr.model.getFloatingSpeciesConcentrations()
array([  4.54293397e-04,   9.99954571e+00])
ExecutableModel.setFloatingSpeciesConcentrations([index, ]values)

Use this to set the entire set of floating species concentrations in one call. The order of species is given by the order of Ids returned by getFloatingSpeciesIds()

Parameters:
  • index (numpy.ndarray) – (optional) an index array indicating which items to set, or if no index array is given, the first param should be an array of all the values to set.

  • values (numpy.ndarray) – the values to set.

>>> rr.model.getFloatingSpeciesConcentrations()
array([  4.54293397e-04,   9.99954571e+00])
>>> rr.model.setFloatingSpeciesConcentrations([0],[0.5])
>>> rr.model.getFloatingSpeciesConcentrations()
array([ 0.5       ,  9.99954571])

Floating Species Initial Conditions

RoadRunner stores all initial conditions separately from the model state variables. This means that you can update the initial conditions at any time, and it does not affect the current state of the model. To reset the model, that is, reset it to its original state, or a new original state where what has changed the initial conditions use the reset() method.

The following methods allow access to the floating species initial condition values:

ExecutableModel.getFloatingSpeciesInitAmountIds()

Return a list of the floating species amount initial amount selection symbols.

>>> rr.model.getFloatingSpeciesInitAmountIds()
['init(S1)', 'init(S2)']
ExecutableModel.getFloatingSpeciesInitConcentrationIds()

Return a list of the floating species amount initial concentration selection symbols.

>>> rr.model.getFloatingSpeciesInitConcentrationIds()
['init([S1])', 'init([S2])']
ExecutableModel.getFloatingSpeciesInitConcentrations([index])

Return a vector of floating species initial concentrations. The order of species is given by the order of Ids returned by getFloatingSpeciesInitialConcentrationIds()

Parameters:

index (numpy.ndarray) – (optional) an index array indicating which items to return.

Returns:

an array of floating species initial concentrations.

Return type:

numpy.ndarray

>>> rr.model.getFloatingSpeciesInitConcentrations()
array([ 10.,   0.])
ExecutableModel.setFloatingSpeciesInitConcentrations([index, ]values)

Set a vector of floating species initial concentrations. The order of species is given by the order of Ids returned by getFloatingSpeciesInitialAmountIds()

Parameters:

index (numpy.ndarray) – (optional) an index array indicating which items to return.

>>> rr.model.setFloatingSpeciesInitConcentrations([0], [1])
>>> rr.model.getFloatingSpeciesInitConcentrations()
array([ 1.,  0.])
ExecutableModel.getFloatingSpeciesInitAmounts([index])

Return a vector of floating species initial amounts. The order of species is given by the order of Ids returned by getFloatingSpeciesInitialConcentrationIds()

Parameters:

index (numpy.ndarray) – (optional) an index array indicating which items to return.

Returns:

an array of floating species initial amounts.

Return type:

numpy.ndarray

>>> rr.model.getFloatingSpeciesInitAmounts()
array([ 10.,   0.])
ExecutableModel.setFloatingSpeciesInitAmounts([index, ]values)

Set a vector of floating species initial amounts. The order of species is given by the order of Ids returned by getFloatingSpeciesInitialAmountIds()

Parameters:

index (numpy.ndarray) – (optional) an index array indicating which items to return.

>>> rr.model.setFloatingSpeciesInitAmounts([0], [0.1])
>>> rr.model.getFloatingSpeciesInitAmounts()
array([ 0.1,  0. ])

Boundary Species

ExecutableModel.getBoundarySpeciesAmounts([index])

Return a vector of boundary species amounts. The order of species is given by the order of Ids returned by getBoundarySpeciesIds()

Parameters:

index (numpy.ndarray) – (optional) an index array indicating which items to return.

Returns:

an array of the boundary species amounts.

Return type:

numpy.ndarray

>>> rr.model.getBoundarySpeciesAmounts()
array([ 15.,   0.])
ExecutableModel.getBoundarySpeciesConcentrations([index])

Return a vector of boundary species concentrations. The order of species is given by the order of Ids returned by getBoundarySpeciesIds()

Parameters:

index (numpy.ndarray) – (optional) an index array indicating which items to return.

Returns:

an array of the boundary species concentrations.

Return type:

numpy.ndarray

>>> rr.getBoundarySpeciesConcentrations()
array([ 0.5,   0.])
ExecutableModel.getBoundarySpeciesIds()

Return a vector of boundary species Ids.

Parameters:

index (numpy.ndarray) – (optional) an index array indicating which items to return.

Returns:

a list of boundary species ids.

>>> rr.getBoundarySpeciesIds()
['X0', 'X1']
ExecutableModel.getBoundarySpeciesConcentrationIds()

Return a vector of boundary species concentration Ids.

Parameters:

index (numpy.ndarray) – (optional) an index array indicating which items to return.

Returns:

a list of boundary species concentration ids.

>>> rr.getBoundarySpeciesConcentrationIds()
['[X0]', '[X1]']
ExecutableModel.getNumBoundarySpecies()

Return the number of boundary species in the model.

>>> rr.getNumBoundarySpecies()
2
ExecutableModel.setBoundarySpeciesConcentrations([index, ]values)

Use this to set the entire set of boundary species concentrations in one call. The order of species is given by the order of boundary species returned by getBoundarySpeciesIds()

Parameters:
  • index (numpy.ndarray) – (optional) an index array indicating which items to set, or if no index array is given, the first param should be an array of all the values to set.

  • values (numpy.ndarray) – the values to set.

>>> rr.model.setBoundarySpeciesConcentrations([0], [1])
>>> rr.getBoundarySpeciesConcentrations()
array([ 1.,  0.])

Compartments

ExecutableModel.getCompartmentIds([index])

Return a vector of compartment identifier symbols.

Parameters:

index (None or numpy.ndarray) – A array of compartment indices indicating which compartment ids to return.

Returns:

a list of compartment ids.

>>> rr.getCompartmentIds()
['compartment1']
ExecutableModel.getCompartmentVolumes([index])

Return a vector of compartment volumes. The order of volumes is given by the order of Ids returned by getCompartmentIds()

Parameters:

index (numpy.ndarray) – (optional) an index array indicating which items to return.

Returns:

an array of compartment volumes.

Return type:

numpy.ndarray.

>>> rr.getCompartmentVolumes()
array([ 1.])
ExecutableModel.getNumCompartments()

Return the number of compartments in the model.

Return type:

int

>>> rr.getNumCompartments()
1
ExecutableModel.setCompartmentVolumes([index, ]values)

Set a vector of compartment volumes.

If the index vector is not give, then the values vector treated as a vector of all compartment volumes to set. If index is given, then values should have the same length as index.

Parameters:
  • index (numpy.ndarray) – (optional) an index array indicating which items to set, or if no index array is given, the first param should be an array of all the values to set.

  • values (numpy.ndarray) – the values to set.

>>> rr.model.setCompartmentVolumes([0], [2.5])
>>> rr.getCompartmentVolumes()
array([ 2.5])

Global Parameters

ExecutableModel.getGlobalParameterIds()

Return a list of global parameter ids.

Returns:

a list of global parameter ids.

ExecutableModel.getGlobalParameterValues([index])

Returns a vector of global parameter values. The order of species is given by the order of Ids returned by getGlobalParameterIds()

Parameters:

index (numpy.ndarray) – (optional) an index array indicating which items to return.

Returns:

an array of global parameter values.

Return type:

numpy.ndarray.

>>> rr.getGlobalParameterValues()
array([ 10. ,  10. ,  10. ,   2.5,   0.5])
ExecutableModel.getNumGlobalParameters()

Returns the number of global parameters in the model.

>>> rr.getNumGlobalParameters()
5
ExecutableModel.setGlobalParameterValues([index, ]values)

Sets the entire set of global parameters. The order of parameters is given by the order of Ids returned by getGlobalParameterIds()

Parameters:
  • index (numpy.ndarray) – (optional) an index array indicating which items to set, or if no index array is given, the first param should be an array of all the values to set.

  • values (numpy.ndarray) – the values to set.

>>> rr.model.setGlobalParameterValues([0], [1.5])
>>> rr.getGlobalParameterValues()
array([  1.5,  10. ,  10. ,   2.5,   0.5])

Reactions

ExecutableModel.getNumReactions()

Return the number of reactions in the model.

>>> rr.getNumReactions()
5
ExecutableModel.getReactionIds()

Return a vector of reaction Ids.

Parameters:

index (numpy.ndarray) – (optional) an index array indicating which items to return.

Returns:

a list of reaction ids.

>>> rr.getReactionIds()
['J0', 'J1', 'J2', 'J3', 'J4']
ExecutableModel.getReactionRates([index])

Return a vector of reaction rates (reaction velocity) for the current state of the model. The order of reaction rates is given by the order of Ids returned by getReactionIds()

Parameters:

index (numpy.ndarray) – (optional) an index array indicating which items to return.

Returns:

an array of reaction rates.

Return type:

numpy.ndarray

>>> rr.getReactionRates()
array([ 0.14979613,  2.37711263,  2.68498886,  2.41265507,  1.89417737])

Events

ExecutableModel.getNumEvents()

Returns the number of events.

>>> rr.getNumEvents()
1

Rate Rules

ExecutableModel.getNumRateRules()

Returns the number of rate rules.

>>> rr.getNumRateRules()
1
ExecutableModel.getEventIds()

Returns a list of event ids.

Returns:

a list of event ids.

>>> rr.model.getEventIds()
['E1']

Stoichiometry

ExecutableModel.getStoichiometry(speciesIndex, reactionIndex)

Return the stochiometric coefficient for the given species index and reaction index.

Frequently one does not need the full stochiometrix matrix, particularly if the system is large and only a single coefficient is needed.

Parameters:
>>> rr.model.getStoichiometry(1, 3)
1.0

Conserved Moieties

Refer to RoadRunner.conservedMoietyAnalysis and Config.LOADSBMLOPTIONS_CONSERVED_MOIETIES for more information.

ExecutableModel.getNumConservedMoieties()

Return the number of conserved moieties in the model.

Return type:

int

>>> rr.getNumConservedMoieties()
1
ExecutableModel.getConservedMoietyIds([index])

Return a vector of conserved moiety identifier symbols.

Parameters:

index (None or numpy.ndarray) – A array of compartment indices indicating which compartment ids to return.

Returns:

a list of compartment ids.

>>> rr.getConservedMoietyIds()
['_CSUM0']
ExecutableModel.getConservedMoietyValues([index])

Return a vector of conserved moiety volumes. The order of values is given by the order of Ids returned by getConservedMoietyIds()

Parameters:

index (numpy.ndarray) – (optional) an index array indicating which items to return.

Returns:

an array of conserved moiety values.

Return type:

numpy.ndarray.

>>> rr.getConservedMoietyValues()
array([ 2.])
ExecutableModel.setConservedMoietyValues([index, ]values)

Set a vector of conserved moiety values.

Note This method currently only updates the conserved moiety values, it does not update the initial species condition from which the values were calculated.

If the index vector is not given, then the values vector treated as a vector of all values to set. If index is given, then values should have the same length as index.

Parameters:
  • index (numpy.ndarray) – (optional) an index array indicating which items to set, or if no index array is given, the first param should be an array of all the values to set.

  • values (numpy.ndarray) – the values to set.

>>> rr.model.setConservedMoietyValues([0], [5])
>>> rr.getConservedMoietyValues()
array([ 5.])

Misc

ExecutableModel.getAllTimeCourseComponentIds()

Return a list of all component ids. The list includes ids of amount/concentration of floating species, boundary species, global parameters, compartments, and reactions, as well as time.

Returns:

a list of all component ids widely used in time course selections.

>>> rr.model.getAllTimeCourseComponentIds()
['time', 'S1', 'S2', 'S3', 'k1', 'k2', 'default_compartment', '_J0', '_J1']

ExecutableModel.getInfo()

Get various info about the model.

>>> print(rr.getInfo())
<roadrunner.RoadRunner() {
'this' : 13DEF5F8
'modelLoaded' : true
'modelName' : feedback
'libSBMLVersion' : LibSBML Version: 5.12.0
'jacobianStepSize' : 1e-005
'conservedMoietyAnalysis' : false
'simulateOptions' :
< roadrunner.SimulateOptions()
{
'this' : 0068A7F0,
'reset' : 0,
'structuredResult' : 0,
'copyResult' : 1,
'steps' : 50,
'start' : 0,
'duration' : 40
}>,
'integrator' :
< roadrunner.Integrator() >
  name: cvode
  settings:
      relative_tolerance: 0.00001
      absolute_tolerance: 0.0000000001
                   stiff: true
       maximum_bdf_order: 5
     maximum_adams_order: 12
       maximum_num_steps: 20000
       maximum_time_step: 0
          minimum_time_step: 0
       initial_time_step: 0
          multiple_steps: false
      variable_step_size: false
}>
ExecutableModel.getModelName()

Get the model name specified in the SBML.

>>> rr.model.getModelName()
'feedback'
ExecutableModel.getTime()

Get the model time. The model originally start at time t=0 and is advaced forward in time by the integrator. So, if one ran a simulation from time = 0 to time = 10, the model will then have it’s time = 10.

>>> rr.model.getTime()
40.0
ExecutableModel.setTime(time)

Set the model time variable.

Parameters:

time – time the time value to set.

>>> rr.model.setTime(20.)
>>> rr.model.getTime()
20.0
ExecutableModel.reset()

Resets all the floating species concentrations to their initial values.

ExecutableModel.resetAll()

Resets all variables, species, etc. to the CURRENT initial values. It also resets all parameter back to the values they had when the model was first loaded

ExecutableModel.resetToOrigin()

Resets the model back to the state is was when it was FIRST loaded. The scope of reset includes all initial values and parameters, etc.