Esempio n. 1
0
 def test_README_example(self):
     """ Tests the source example in the main README.md. """
     import tellurium as te
     rr = te.loada('''
         model example0
           S1 -> S2; k1*S1
           S1 = 10
           S2 = 0
           k1 = 0.1
         end
     ''')
     result = rr.simulate(0, 40, 500)
     te.plotArray(result)
Esempio n. 2
0
 def test_README_example(self):
     """ Tests the source example in the main README.md. """
     import tellurium as te
     rr = te.loada('''
         model example0
           S1 -> S2; k1*S1
           S1 = 10
           S2 = 0
           k1 = 0.1
         end
     ''')
     result = rr.simulate(0, 40, 500)
     te.plotArray(result)
    def runSim(start=0, stop=100, steps=100, **paramMap):
        r.reset()
        for k, v in paramMap.items():
            try:
                key = k.encode('ascii', 'ignore')
                r[key] = v
            except:
                # error in setting model variable
                e = sys.exc_info()
                print e

        try:
            s = r.simulate(start, stop, steps)
            te.plotArray(s)
        except:
            # error in simulation
            e = sys.exc_info()
            print e
Esempio n. 4
0
rr = te.loada('''
   A -> B; k1*A;
   B -> A; k2*B;
   k1 = 0.2; k2 = 0.4;
''')

starting = 6000  # 10 zepto molar 10^(-21) = 6000 molecules

rr.model["init(A)"] = starting
rr.model["init(B)"] = 0

plt.subplot(221)
plt.title("A = 6000")
m1 = rr.gillespie(0, 12, ["time", "A", "B"])
te.plotArray(m1)
rr.model["init(A)"] = starting
rr.model["init(B)"] = 0

m2 = rr.simulate(0, 12, 100)
te.plotArray(m2)

starting = 600
rr.model["init(A)"] = starting
rr.model["init(B)"] = 0

plt.subplot(222)
plt.title("A = 600")
m1 = rr.gillespie(0, 12, ["time", "A", "B"])
te.plotArray(m1)
rr.model["init(A)"] = starting
# ### Consecutive UniUni reactions using first-order mass-action kinetics
# Model creation and simulation of a simple irreversible chain of reactions S1 -> S2 -> S3 -> S4.

# In[1]:

#!!! DO NOT CHANGE !!! THIS FILE WAS CREATED AUTOMATICALLY FROM NOTEBOOKS !!! CHANGES WILL BE OVERWRITTEN !!! CHANGE CORRESPONDING NOTEBOOK FILE !!!
from __future__ import print_function
import tellurium as te

r = te.loada('''
  model pathway()
    S1 -> S2; k1*S1
    S2 -> S3; k2*S2
    S3 -> S4; k3*S3

    # Initialize values
    S1 = 5; S2 = 0; S3 = 0; S4 = 0;
    k1 = 0.1;  k2 = 0.55; k3 = 0.76
  end
''')

result = r.simulate(0, 20, 51)
te.plotArray(result);


# In[2]:



Esempio n. 6
0
import numpy
import tellurium as te

rr = te.loada('''
   $Xo -> S1; k1*Xo
   S1  -> $X1; k2*S1;

   Xo = 10; k1 = 0.3; k2 = 0.15;
 ''')
# let the reaction run for 40 time unit
m1 = rr.simulate(0, 40, 50)

# perturb by increasing S1 60%
rr.S1 = rr.S1 * 1.6

# let the reaction run for additional 40 time unit
m2 = rr.simulate(40, 80, 50)

# merge the result
m = numpy.vstack((m1, m2))

te.plotArray(m)
Xo = 0.09; X1 = 0.0;
S1 = 0.5; k1 = 3.2;
''')
print(r.selections)

initValue = 0.05
m = r.simulate (0, 4, 100, selections=["time", "S1"])

for i in range (0,12):
    r.reset()
    r['[S1]'] = initValue
    res = r.simulate (0, 4, 100, selections=["S1"])
    m = np.concatenate([m, res], axis=1)
    initValue += 1

te.plotArray(m, color="black", alpha=0.7, loc=None, 
             xlabel="time", ylabel="[S1]", title="Bistable system");


# ### Add plot elements

# In[5]:

import tellurium as te
import numpy
import matplotlib.pyplot as plt
import roadrunner

# Example showing how to embelise a graph, change title, axes labels.
# Example also uses an event to pulse S1

r = te.loada ('''
Esempio n. 8
0
model1 = '''
    model proteinProduction(protRate, mRNARate)
        -> prot; protRate * mRNA;
        -> mRNA; mRNARate;
        prot ->; (mRNARate * (time - 3600) / (8 * 3600))  * dectog * protRate;
        at (time > 3600): dectog = 1;
        at (time % 1200 < 1): prot = prot/2, mRNA = mRNA / 2
        
        prot = 0;
        mRNA = 0;
        dectog = 0;
    end
    
    model productionValues()
        proteinProduction(10, 10);
        proteinProduction(10, 100);
        proteinProduction(10, 1000);
        proteinProduction(20, 10);
        proteinProduction(20, 100);
        proteinProduction(20, 1000);
        proteinProduction(30, 10);
        proteinProduction(30, 100);
        proteinProduction(30, 1000);
    end
'''

r = te.loadAntimonyModel(model1)
output = r.simulate (0,64800,64800)
te.plotArray(output)

# -*- coding: utf-8 -*-
"""
Created on Tue Mar 11 14:27:13 2014

@author: mgaldzic
"""

import tellurium as te
# Consecutive UniUni reactions using first-order mass-action kinetics
model = '''
  model pathway()
    S1 -> S2; k1*S1
    S2 -> S3; k2*S2
    S3 -> S4; k3*S3

    # Initialize values
    S1 = 5; S2 = 0; S3 = 0; S4 = 0;
    k1 = 0.1;  k2 = 0.55; k3 = 0.76
  end
'''

r = te.loadAntimonyModel (model)
result = r.simulate (0, 20, 50)
te.plotArray(result)
Esempio n. 10
0
J0: A + B -> AB ; K_AB * A * B - 1/K_AB * AB
J1: B + C -> BC ; K_BC * B * C - 1/K_BC * BC
J4: AB + C -> ABC ; K_AB_C * AB * C - 1/K_AB_C * ABC
J5: BC + A -> ABC ; K_BC_A * BC * A - 1/K_BC_A * ABC
# *******************************
# Parameters
A = 1;
B = 1;
C = 1;
K_AB = 1;
K_BC = 0.1;
K_AB_C = 1;
K_BC_A = 0.1;
""")

simulation = r.simulate(start=0, end=100, steps=100)
r.plot(simulation)
print(simulation[100, 6])
print(simulation)

concentrations = [0, 0.01, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10]

for i in concentrations:
    r.resetToOrigin()
    r.B = i
    m = r.simulate(0, 5, 100, ['time', 'ABC'])
    print(m)
    te.plotArray(m,
                 show=False,
                 labels=['Concentration=' + str(i)],
                 resetColorCycle=False)
Esempio n. 11
0
# coding: utf-8

# Back to the main [Index](../index.ipynb)

# ### Consecutive UniUni reactions using first-order mass-action kinetics
# Model creation and simulation of a simple irreversible chain of reactions S1 -> S2 -> S3 -> S4.

# In[1]:

#!!! DO NOT CHANGE !!! THIS FILE WAS CREATED AUTOMATICALLY FROM NOTEBOOKS !!! CHANGES WILL BE OVERWRITTEN !!! CHANGE CORRESPONDING NOTEBOOK FILE !!!
from __future__ import print_function
import tellurium as te

r = te.loada('''
  model pathway()
    S1 -> S2; k1*S1
    S2 -> S3; k2*S2
    S3 -> S4; k3*S3

    # Initialize values
    S1 = 5; S2 = 0; S3 = 0; S4 = 0;
    k1 = 0.1;  k2 = 0.55; k3 = 0.76
  end
''')

result = r.simulate(0, 20, 51)
te.plotArray(result)

# In[2]:
        threshold = 0.018; light_intensity = 1; duration = 5;
            /* Values can be changed to modify the feedback response */
           
    //Plotting
        c_add := c_TEV + c_X
        p_tot := p_end + TEV_in + TEV + X_tot;
        TEV_tot := TEV + TX_c + TEV_in
        TEV_act := TEV + TX_c
        TEV_ratio := (TEV + TX_c) / TEV_tot
        Output := N * X_sol * d_N * tur
        
//Running simulations
    //Cells & nutrients
        s = 1e20; N = 1e7;
    
    //Initializing species
        /* Initial values obtained by running the simulation to steady state 
        without X induction */
        
        m_r = 109; m_t = 16; m_m = 16; m_q = 766;
        c_r = 1105; c_t = 44; c_m = 44; c_q = 2089
        p_r = 1232; p_t = 4423; p_m = 4423; p_q = 2.122e5;
        a = 24;
        
end""")

r.selections = ['time', 'lmda']       #Selects the data to be plotted. 'time' always needs to be present
result = r.simulate(0, 600, 601)        #Simulates model, uses input(start, end, number of points)
te.plotArray(result, xlabel = 'Minutes')
te.show()
Esempio n. 13
0
def simpleTimeCourseScan(r,
                         parameter,
                         variable,
                         lowRange,
                         highRange,
                         numberOfScans,
                         timeEnd=10,
                         numberOfPoints=100,
                         formatStr='{:10.6f}',
                         legendLoc='upper right'):
    """ Run a time course simulation at different parameter values, observe a single variable
    
    Args:   
      r (reference): Roadrunner instance
      parameter (string): The name of the parameter to change
      variable (string): The name of the variable to record during the scan
      lowRange (float): The starting value for the parameter
      highRange (float): The final value for the parameter
      numberOfScans (integer): The number of values of the parameter to try
      timeEnd (float): Optional: Simulate a time course up to this time
      numberOfPoints: (integer): Optional: Generate this number of points for each time course
      formatStr (string): Optional: The format string for values listed in the plot legend
         
    Return:
      numpy array:
         first column being time
         remaining columns correspond to each parameter scan.
    
    Example:
   
     .. code-block:: python

        import tellurium as te
        import teUtils as tu

        r = te.loada('''
        J1: $Xo -> S1; k10*Xo - k11*S1; 
        J2: S1 -> S2;  k20*S1 - k21*S2; 
        J3: S2 -> $X1; k30*S2 - k31*X1; 

        k10 = 1.21;  k11 = 0.69
        k20 = 1.03;  k21 = 0.13
        k30 = 1.89;  k31 = 0.10
        Xo = 6.00
        X1 = 0
        S1 = 0; S2 = 0;
        ''')

        tu.parameterScanning.simpleTimeCourseScan(r, 'k20', 'S1', 
                3, 12, 7, timeEnd=6, numberOfPoints=200, formatStr='{:4.1f}')
    """
    r[parameter] = lowRange
    stepSize = (highRange - lowRange) / (numberOfScans - 1)
    for h in range(numberOfScans):
        r.reset()
        m = r.simulate(0, timeEnd, numberOfPoints, ["Time", variable])
        _te.plotArray(m,
                      resetColorCycle=False,
                      label=parameter + ' = ' + formatStr.format(r[parameter]),
                      show=False)
        r[parameter] = r[parameter] + stepSize

    _plt.ylabel('Concentration (' + variable + ')')
    _plt.xlabel('Time')
    _plt.legend(loc=legendLoc)
    # A bit of a hack to extract the data out of the plot and construct a
    # numpy array of time in first column and scans in remaining columns
    data = _np.empty([numberOfPoints, 0])  # Create an empty array
    g = _plt.gca()
    # Collect the time column first
    xdata = g.lines[0].get_xdata()
    xdata = xdata.reshape(
        len(xdata), 1)  # Reshape to make arrays compatible when we use hstack
    data = _np.hstack((data, xdata))
    # Now collect the y columns
    for i in range(len(g.lines)):
        ydata = g.lines[i].get_ydata()
        ydata = ydata.reshape(len(ydata), 1)
        data = _np.hstack(((data, ydata)))
    return data
Esempio n. 14
0
rr = te.loada('''
    $Xo -> S1;  k1*Xo;
    S1 -> S2;   k2*S1;
    S2 -> $X1;  k3*S2;
    k1 = 0.6; Xo = 1;
    k2 = 0.4; k3 = 0.8;
''')

plt.figure(figsize=(9, 4))
S1Start = 0
S2Start = 0
for i in range(1, 11):
    rr.S1 = S1Start
    rr.S2 = S2Start
    m = rr.simulate(0, 10, 120, ["S1", "S2"])
    p = te.plotArray(m, show=False)
    plt.setp(p, color='r')
    S1Start = S1Start + 0.2
S1Start = 2
S2Start = 0
for i in range(1, 11):
    rr.S1 = S1Start
    rr.S2 = S2Start
    m = rr.simulate(0, 10, 120, ["S1", "S2"])
    p = te.plotArray(m, show=False)
    plt.setp(p, color='r')
    S2Start = S2Start + 0.2
S2Start = 0
S1Start = 0
for i in range(1, 11):
    rr.S1 = S1Start