示例#1
0
文件: tester.py 项目: uwigem/test
def checkScaledConcentrationControlMatrix(rrInstance, testId):
    # Unscaled Concentration Control matrix
    Config.setValue(Config.ROADRUNNER_JACOBIAN_MODE,
                    Config.ROADRUNNER_JACOBIAN_MODE_CONCENTRATIONS)
    print(("Check " + testId).ljust(rpadding), end="")
    st = rrInstance.getScaledConcentrationControlCoefficientMatrix()
    checkMatrixVsUpcomingText(st)
示例#2
0
def checkJacobian(rrInstance, testId):
    # TODO need to update python 2.x printing
    print string.ljust("Check " + testId, rpadding),
    from roadrunner import Config
    import numpy as n

    errors = False

    # max difference between reduced and full
    maxDiff = 2e-10

    # save the old value
    saved = Config.getValue(Config.ROADRUNNER_JACOBIAN_MODE)

    # set to amounts mode
    Config.setValue(Config.ROADRUNNER_JACOBIAN_MODE,
                    Config.ROADRUNNER_JACOBIAN_MODE_AMOUNTS)

    full = rrInstance.getFullJacobian()
    reduced = rrInstance.getReducedJacobian()

    m = n.max(n.abs(reduced - full))
    if (m > maxDiff):
        errors = True
        print("Jacobians different in amounts mode, max difference: " + str(m))

    # set to conc mode
    Config.setValue(Config.ROADRUNNER_JACOBIAN_MODE,
                    Config.ROADRUNNER_JACOBIAN_MODE_CONCENTRATIONS)

    full = rrInstance.getFullJacobian()
    reduced = rrInstance.getReducedJacobian()

    m = n.max(n.abs(reduced - full))
    if (m > maxDiff):
        errors = True
        print("Jacobians different in concentrations mode, max difference: " +
              str(m))

    # restore previous value
    Config.setValue(Config.ROADRUNNER_JACOBIAN_MODE, saved)

    print passMsg(errors)
示例#3
0
def checkJacobian(rrInstance, testId):
    # TODO need to update python 2.x printing
    print string.ljust ("Check " + testId, rpadding),
    from roadrunner import Config
    import numpy as n

    errors = False

    # max difference between reduced and full
    maxDiff = 2e-10

    # save the old value
    saved = Config.getValue(Config.ROADRUNNER_JACOBIAN_MODE)

    # set to amounts mode
    Config.setValue(Config.ROADRUNNER_JACOBIAN_MODE, Config.ROADRUNNER_JACOBIAN_MODE_AMOUNTS)

    full = rrInstance.getFullJacobian()
    reduced = rrInstance.getReducedJacobian()

    m = n.max(n.abs(reduced-full))
    if (m > maxDiff):
        errors = True
        print("Jacobians different in amounts mode, max difference: " + str(m))

    # set to conc mode
    Config.setValue(Config.ROADRUNNER_JACOBIAN_MODE, Config.ROADRUNNER_JACOBIAN_MODE_CONCENTRATIONS)

    full = rrInstance.getFullJacobian()
    reduced = rrInstance.getReducedJacobian()

    m = n.max(n.abs(reduced-full))
    if (m > maxDiff):
        errors = True
        print("Jacobians different in concentrations mode, max difference: " + str(m))

    # restore previous value
    Config.setValue(Config.ROADRUNNER_JACOBIAN_MODE, saved)

    print passMsg(errors)
示例#4
0
#-------------------------------------------------------------------------------
# Purpose: Example demonstrating how to access and plot various statistics from
# a fitting session, e.g. RESIDUALS, STANDARDIZED RESIDUALS and
# NORMAL PROBABILITY OF RESIDUALS (Q-Q plot)
#
# Author: Totte Karlsson ([email protected])
#-------------------------------------------------------------------------------
import roadrunner
import numpy as np
import matplotlib.pyplot as plt
import teplugins as tel
from roadrunner import Config
try:
    Config.setValue(Config.LOADSBMLOPTIONS_CONSERVED_MOIETIES, False)
    Config.setValue(Config.SIMULATEOPTIONS_STRUCTURED_RESULT, True)
    chiPlugin = tel.Plugin("tel_chisquare")

    #Retrieve a SBML model from plugin
    modelPlugin = tel.Plugin("tel_test_model")
    test_model = modelPlugin.Model

    # Create a roadrunner instance and create some data
    rr = roadrunner.RoadRunner()
    rr.load(test_model)
    data = rr.simulate(0, 10, 15000)

    #Add noise to the data
    noisePlugin = tel.Plugin("tel_add_noise")

    # Get the dataseries from data returned by roadrunner
    d = tel.getDataSeries(data)
示例#5
0
def checkScaledConcentrationControlMatrix(rrInstance, testId):
    # Unscaled Concentration Control matrix
    Config.setValue(Config.ROADRUNNER_JACOBIAN_MODE, Config.ROADRUNNER_JACOBIAN_MODE_CONCENTRATIONS)
    print(string.ljust ("Check " + testId, rpadding), end="")
    st = rrInstance.getScaledConcentrationControlCoefficientMatrix();
    checkMatrixVsUpcomingText(st)

def chiFun(k1,k2):
    rr.reset()
    rr.setValue("k1", k1)
    rr.setValue("k2", k2)          
    data = rr.simulate(timeStart, timeEnd, nrPoints - 1)            
    chiSquare.ModelData = tel.getDataSeries(data)
    
    if not chiSquare.execute():
        raise Exception( tel.getLastError() )
           
    return chiSquare.ReducedChiSquare                   
            
try:
    Config.setValue(Config.LOADSBMLOPTIONS_CONSERVED_MOIETIES, False)    
    Config.setValue(Config.SIMULATEOPTIONS_STRUCTURED_RESULT, True)
    #Read some 'experimental' data   
    expData = tel.DataSeries()
    
    #This does not look right.. but it works..
    expData = expData.readDataSeries('TwoParametersData.dat')   
            
    test_model = 'two_parameters.xml'            

    # Create a roadrunner instance and create some MODEL data
    rr = roadrunner.RoadRunner()
    rr.load(test_model)

    #Get chi square plugin and set it up
    chiSquare =  tel.Plugin("tel_chisquare")    
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 11 15:06:33 2014

@author: mgaldzic
"""
import tellurium as te
from roadrunner import Config

Config.setValue(Config.LOADSBMLOPTIONS_CONSERVED_MOIETIES, True) 
model = '''
  model pathway()
     $Xo -> S1; k1*Xo - k2*S1
      S1 -> S2; k3*S2
      S2 -> $X1; k4*S2

     Xo = 1;   X1 = 0
     S1 = 0;   S2 = 0
     k1 = 0.1; k2 = 0.56
     k3 = 1.2; k4 = 0.9
  end
'''

r = te.loadAntimonyModel(model)

# Compute the steady state
r.getSteadyStateValues()
Config.setValue(Config.LOADSBMLOPTIONS_CONSERVED_MOIETIES, False) 
print "S1 =", r.S1, ", S2 =", r.S2

示例#8
0
"""
Steady state scan.
"""
from __future__ import print_function, division
import tellurium as te
from roadrunner import Config

Config.setValue(Config.LOADSBMLOPTIONS_CONSERVED_MOIETIES, True)

model = '''
    $Xo -> S1; vo;
    S1 -> S2; k1*S1 - k2*S2;
    S2 -> $X1; k3*S2;
    
    vo = 1
    k1 = 2; k2 = 0; k3 = 3;
'''

rr = te.loada(model)

p = te.SteadyStateScan(rr,
                       value='k3',
                       startValue=2,
                       endValue=3,
                       numberOfPoints=20,
                       selection=['S1', 'S2'])
p.plotArray()

Config.setValue(Config.LOADSBMLOPTIONS_CONSERVED_MOIETIES, False)
示例#9
0
verbose = 2  #Verbose level: 0 = garnicht, 1 = Statistik 1x je outerLoop, 2 = Statistik nach jedem N, 3 = +Schleifenzaehler (Haengt sich die Simulation auf?)
Nscale = 100
#Produkt der naechsten 3 Variablen ist die Anzahl der insg. simulierten Pfade
outerLoop = 1  #Anzahl Wiederholungen festlegen (multipliziert sich mit AnzahlPfade zur Anzahl der simulierten Pfade je N)
Nrange = range(
    3
)  #Bereich von N festlegen. range(5) ==  0,1,2,3,4. Daher Multiplikator N = (N+1)*Nscale
AnzahlPfade = 40  #Anzahl Wiederholungen festlegen (multipliziert sich mit outerLoop). Fuer schoene Plots hier Wert 40-100. Fuer grosse N: doplot=False, hier 1, dafuer bei outerLoop gewuenschte Werte eintragen.
r = te.loadAntimonyModel(
    antStr)  #Modell laden, kann auch URL sein z.B. von www.biomodels.net
r.setIntegrator(
    'gillespie')  #Integrator auswaehlen. Andere unterstuetzen z.B. ODEs
r.getIntegrator().setValue(
    'variable_step_size', True
)  #Parameter fuer Integrator setzen, anderer Integrator unterstuetzt andere Parameter
Config.setValue(Config.MAX_OUTPUT_ROWS, pow(
    10, 7))  #bei 64-bit pow(10,11) oder weniger bei wenig Arbeitsspeicher
#----------------------------
Reactions = 0
start_time = time.time()
selectToSave = ['N'] + selectToPlot
form = (1, len(selectToSave))
r.selections = selectToSave
simuliertePfade = 0
PfadeGesamt = outerLoop * AnzahlPfade * len(Nrange)
if os.path.isfile(
        path + name
):  #Header in CSV-Datei automatisch erzeugen, falls Datei noch nicht existiert
    f = open(path + name, 'ab')
else:
    f = open(path + name, 'ab')
    head = ",".join(selectToSave)
示例#10
0
Nrange= range(3) #Bereich von N festlegen. range(5) ==  0,1,2,3,4. Daher Multiplikator N = (N+1)*Nscale
AnzahlPfade = 40 #Anzahl Wiederholungen festlegen (multipliziert sich mit outerLoop). Fuer schoene Plots hier Wert 40-100. Fuer grosse N: doplot=False, hier 1, dafuer bei outerLoop gewuenschte Werte eintragen.
#--------------stay-above-this-line----- #Modell laden, kann auch URL sein z.B. von www.biomodels.net---------
if os.path.isfile(antStr):   #----------- start copy&paste from tellurium.py
	code = antimony.loadAntimonyFile(antStr)
else:
	code = antimony.loadAntimonyString(antStr)
if code < 0:
	raise Exception('Antimony: {}'.format(antimony.getLastError()))
mid = antimony.getMainModuleName()
sbml = antimony.getSBMLString(mid)
r = roadrunner.RoadRunner(sbml) #----------- end copy&paste from tellurium.py
#----------------the-next-three-lines-should-be-user-adapted--------
r.setIntegrator('gillespie')  #Integrator auswaehlen. Andere unterstuetzen z.B. ODEs
r.getIntegrator().setValue('variable_step_size', True) #Parameter fuer Integrator setzen, anderer Integrator unterstuetzt andere Parameter
Config.setValue(Config.MAX_OUTPUT_ROWS,pow(10,7))  #bei 64-bit pow(10,11) oder weniger bei wenig Arbeitsspeicher
#-----------end-user-parameters-----------
Reactions = 0
start_time = time.time()
selectToSave = ['N'] + selectToPlot
form=(1,len(selectToSave))
r.selections = selectToSave
simuliertePfade = 0
PfadeGesamt=outerLoop*AnzahlPfade*len(Nrange)
if os.path.isfile(path+name):  #Header in CSV-Datei automatisch erzeugen, falls Datei noch nicht existiert
	f=open(path+name,'ab')
else:
	f=open(path+name,'ab')
	head=",".join(selectToSave)
	f.write(head)
	f.write("\n")