# Generated Code

The following is python code generated by the CellML API from this CellML file. (Back to language selection)

The raw code is available.

```# Size of variable arrays:
sizeAlgebraic = 0
sizeStates = 3
sizeConstants = 13
from math import *
from numpy import *

def createLegends():
legend_states = [""] * sizeStates
legend_rates = [""] * sizeStates
legend_algebraic = [""] * sizeAlgebraic
legend_voi = ""
legend_constants = [""] * sizeConstants
legend_voi = "time in component environment (s)"
legend_states = "P in component P (dimensionless)"
legend_states = "Q in component Q (dimensionless)"
legend_constants = "a in component P (per_s)"
legend_constants = "b in component P (per_s)"
legend_constants = "K in component P (dimensionless)"
legend_constants = "P_star in component P_star (dimensionless)"
legend_constants = "V_3 in component R (per_s)"
legend_constants = "V_4 in component R (per_s)"
legend_constants = "K_3 in component R (dimensionless)"
legend_constants = "K_4 in component R (dimensionless)"
legend_states = "R in component R (dimensionless)"
legend_constants = "V_1 in component Q (per_s)"
legend_constants = "V_2 in component Q (per_s)"
legend_constants = "K_1 in component Q (dimensionless)"
legend_constants = "K_2 in component Q (dimensionless)"
legend_constants = "R_star in component R_star (dimensionless)"
legend_rates = "d/dt P in component P (dimensionless)"
legend_rates = "d/dt Q in component Q (dimensionless)"
legend_rates = "d/dt R in component R (dimensionless)"
return (legend_states, legend_algebraic, legend_voi, legend_constants)

def initConsts():
constants = [0.0] * sizeConstants; states = [0.0] * sizeStates;
states = 0.0
states = 0.0
constants = 0.1
constants = 0.1
constants = 0.2
constants = 6
constants = 2.5
constants = 0.01
constants = 0.01
states = 0.0
constants = 1
constants = 1.5
constants = 0.01
constants = 0.01
constants = (constants/constants)*((1.00000+2.00000*constants)/(1.00000+2.00000*constants))
constants = (constants/constants)*((1.00000+2.00000*constants)/(1.00000+2.00000*constants))
return (states, constants)

def computeRates(voi, states, constants):
rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic
rates = constants*states-constants*(states/(constants+states))
rates = constants*((1.00000-states)/(constants+(1.00000-states)))-constants*states*(states/(constants+states))
rates = states*constants*((1.00000-states)/(constants+(1.00000-states)))-constants*(states/(constants+states))
return(rates)

def computeAlgebraic(constants, states, voi):
algebraic = array([[0.0] * len(voi)] * sizeAlgebraic)
states = array(states)
voi = array(voi)
return algebraic

def solve_model():
"""Solve model with ODE solver"""
from scipy.integrate import ode
# Initialise constants and state variables
(init_states, constants) = initConsts()

# Set timespan to solve over
voi = linspace(0, 10, 500)

# Construct ODE object to solve
r = ode(computeRates)
r.set_integrator('vode', method='bdf', atol=1e-06, rtol=1e-06, max_step=1)
r.set_initial_value(init_states, voi)
r.set_f_params(constants)

# Solve model
states = array([[0.0] * len(voi)] * sizeStates)
states[:,0] = init_states
for (i,t) in enumerate(voi[1:]):
if r.successful():
r.integrate(t)
states[:,i+1] = r.y
else:
break

# Compute algebraic variables
algebraic = computeAlgebraic(constants, states, voi)
return (voi, states, algebraic)

def plot_model(voi, states, algebraic):
"""Plot variables against variable of integration"""
import pylab
(legend_states, legend_algebraic, legend_voi, legend_constants) = createLegends()
pylab.figure(1)
pylab.plot(voi,vstack((states,algebraic)).T)
pylab.xlabel(legend_voi)
pylab.legend(legend_states + legend_algebraic, loc='best')
pylab.show()

if __name__ == "__main__":
(voi, states, algebraic) = solve_model()
plot_model(voi, states, algebraic)
```
Source
Derived from workspace Goldbeter 2006 at changeset e51f2a391286.
Collaboration
To begin collaborating on this work, please use your git client and issue this command:
{"ft_lang_label":"__label__en","ft_lang_prob":0.6729843,"math_prob":0.99809843,"size":4037,"snap":"2021-43-2021-49","text_gpt3_token_len":1244,"char_repetition_ratio":0.2690305,"word_repetition_ratio":0.004474273,"special_character_ratio":0.34381968,"punctuation_ratio":0.148773,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9994297,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-11-28T06:22:34Z\",\"WARC-Record-ID\":\"<urn:uuid:5c9832bb-3626-42a0-b273-017ce16801d9>\",\"Content-Length\":\"22125\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:f4ff2937-1ae5-49ba-aec0-dda6142e28a3>\",\"WARC-Concurrent-To\":\"<urn:uuid:fad38c6e-9951-4397-b72c-eb007dcd6ba1>\",\"WARC-IP-Address\":\"54.186.195.229\",\"WARC-Target-URI\":\"https://models.cellml.org/e/4e/goldbeter_2006.cellml/@@cellml_codegen/Python\",\"WARC-Payload-Digest\":\"sha1:DQ2D7JEJSEMSNJ475R3KB4QU4NI3LDEP\",\"WARC-Block-Digest\":\"sha1:7CF77HHVROW7FA7D7SORK3UMRQSBKML3\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-49/CC-MAIN-2021-49_segments_1637964358469.34_warc_CC-MAIN-20211128043743-20211128073743-00625.warc.gz\"}"}