def run_auto(pars, r, direction='Positive'): if pars: for k in pars: r[k] = pars[k] auto = Plugin("tel_auto2000") # Setup properties auto.setProperty("SBML", r.getCurrentSBML()) auto.setProperty("ScanDirection", direction) auto.setProperty("PrincipalContinuationParameter", "mu") auto.setProperty("PreSimulation", "True") auto.setProperty("PreSimulationDuration", 30) auto.setProperty("RL0", 0) auto.setProperty("RL1", 2.5) auto.setProperty("NMX", 10000) #auto.setProperty("NDIM", 15) auto.setProperty("NPR", 2) auto.setProperty("KeepTempFiles", True) auto.setProperty("DS", 0.001) auto.setProperty("DSMIN", 0.0001) auto.setProperty("DSMAX", 0.1) auto.execute() pts1 = auto.BifurcationPoints if 1: lbl1 = auto.BifurcationLabels biData1 = auto.BifurcationData biData1.plotBifurcationDiagram(pts1, lbl1)
def bifurcation(model, parameter, lowerBound, upperBound, maxPoints=5000, scanPositive=True): '''Plot a bifurcation diagram. :param model: A path to an SBML or Antimony file, or raw SBML or Antimony string. :param parameter: The principal continuation parameter. :param lowerBound: The lower bound of the continuation. :param upperBound: The upper bound of the continuation. :param maxPoints: The maximum number of points. :param scanPositive: Scan from lower to upper bound (direction is reversed if false). ''' if isinstance(model, RoadRunner): sbml = model.getSBML() elif os.path.exists(model) and os.path.isfile(model): # it's a file path if os.path.splitext(model)[1] == '.sb': # it's an Antimony file with open(model) as f: sbml = antimonyConverter.antimonyToSBML(f.read()) elif os.path.splitext(model)[1] == '.txt': raise RuntimeError( 'File ending in ".txt" is ambiguous - pass an SBML file (.xml) or an Antimony file (.sb).' ) else: with open(model) as f: sbml = f.read() else: # check if it's Antimony source try: sbml = antimonyConverter.antimonyToSBML(model) except: # it better be SBML import tesbml as libsbml # this will throw if it's not SBML libsbml.readSBML(model) auto = Plugin('tel_auto2000') # Set SBML source auto.setProperty('SBML', sbml) # Set parameters auto.setProperty('ScanDirection', 'Positive' if scanPositive else 'Negative') auto.setProperty('PrincipalContinuationParameter', parameter) auto.setProperty('PCPLowerBound', lowerBound) auto.setProperty('PCPUpperBound', upperBound) # Set maximum numberof points auto.setProperty('NMX', maxPoints) # execute the plugin auto.execute() # plot Bifurcation diagram pts = auto.BifurcationPoints lbls = auto.BifurcationLabels biData = auto.BifurcationData return pts, lbls, biData
#------------------------------------------------------------------------------- # Purpose: Example demonstrating how to setup and use the TestModel plugin # This example also shows how to plot data and how to view a plugins # embedded manual # # Authors: Totte Karlsson ([email protected]), J Kyle Medley #------------------------------------------------------------------------------- from rrplugins import Plugin modelPlugin = Plugin("tel_test_model") #Test model plugin depends on the add_noise plugin noisePlugin = Plugin("tel_add_noise") #Generate internal test data modelPlugin.execute() test_data = modelPlugin.TestData test_data_with_noise = modelPlugin.TestDataWithNoise test_data.plot() test_data_with_noise.plot() #modelPlugin.viewManual() print('Plugin version: {}'.format(modelPlugin.getVersion()))