rrplugins 2.11.0__cp315-cp315-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
rrplugins/README.txt ADDED
@@ -0,0 +1,10 @@
1
+ Tellurium PluginAPI Python Wrapper
2
+
3
+ The telplugins_c_api.py file is a python wrapper around the telplugins_c_api library.
4
+
5
+ On top of the raw API defined by telplugins_c_api.py, is another more user friendly API defined, in the file telplugins.py.
6
+
7
+ Necessary files in this folder should be installed to your systems python installations site-packages folder.
8
+
9
+ =================================================================================
10
+ Totte Karlsson and Herbert Sauro.
rrplugins/__init__.py ADDED
@@ -0,0 +1,4 @@
1
+ from .telplugins import *
2
+ from .telplugins_c_api import *
3
+
4
+ __version__ = '2.11.0'
@@ -0,0 +1,22 @@
1
+ import roadrunner
2
+
3
+ import rrplugins as tel
4
+
5
+ rr = roadrunner.RoadRunner()
6
+
7
+ rr.load("path to any model. Eg. some models are provided in source code, like, sbml_test_0001")
8
+
9
+ data = rr.simulate(0, 10, 511)
10
+
11
+ noisePlugin = tel.Plugin ("tel_add_noise")
12
+
13
+ d = tel.getDataSeries (data)
14
+
15
+ noisePlugin.InputData = d
16
+
17
+ noisePlugin.Sigma = 3.e-6
18
+
19
+ noisePlugin.execute()
20
+
21
+ noisePlugin.InputData.plot()
22
+
@@ -0,0 +1,32 @@
1
+ from rrplugins import *
2
+ auto = Plugin("tel_auto2000")
3
+
4
+
5
+ # path to any model. Eg. some models are provided in source code, like BIOMD0000000203.xml
6
+ sbmlModel = "BIOMD0000000203.xml"
7
+
8
+ auto.setProperty("SBML", readAllText(sbmlModel))
9
+
10
+ auto.setProperty("NMX", 5000)
11
+
12
+ auto.setProperty("ScanDirection", "Positive")
13
+
14
+ auto.setProperty("PrincipalContinuationParameter", "A")
15
+ auto.setProperty("PCPLowerBound", 10)
16
+ auto.setProperty("PCPUpperBound", 200)
17
+
18
+ #Max numberof points
19
+ auto.setProperty("NMX", 5000)
20
+
21
+ #Execute the plugin
22
+ auto.execute()
23
+
24
+ # Bifurcation summary
25
+ print("Summary: " + auto.BifurcationSummary)
26
+
27
+ #Plot Bifurcation diagram
28
+ pts = auto.BifurcationPoints
29
+ lbls = auto.BifurcationLabels
30
+ biData = auto.BifurcationData
31
+
32
+ biData.plotBifurcationDiagram(pts, lbls)
@@ -0,0 +1,36 @@
1
+ import tellurium as te
2
+ from rrplugins import *
3
+ auto = Plugin("tel_auto2000")
4
+
5
+
6
+ r = te.loada (
7
+ '''
8
+ $Xo -> x; 0.1 + k1*x^4/(k2+x^4);
9
+ x -> $w; k3*x;
10
+ // Initialization here
11
+ k1 = 0.9;
12
+ k2 = 0.3;
13
+ k3 = 0.7;
14
+ '''
15
+ )
16
+
17
+ auto.setProperty("SBML", r.getCurrentSBML())
18
+ auto.setProperty("NMX", 5000)
19
+ auto.setProperty("ScanDirection", "Positive")
20
+ auto.setProperty("PrincipalContinuationParameter", "k3")
21
+
22
+ auto.setProperty("PCPLowerBound", 0.2)
23
+ auto.setProperty("PCPUpperBound", 1.8)
24
+
25
+ #Execute the plugin
26
+ auto.execute()
27
+
28
+ # Bifurcation summary
29
+ print("Summary: " + auto.BifurcationSummary)
30
+
31
+ #Plot Bifurcation diagram
32
+ pts = auto.BifurcationPoints
33
+ lbls = auto.BifurcationLabels
34
+ biData = auto.BifurcationData
35
+
36
+ biData.plotBifurcationDiagram(pts, lbls)
@@ -0,0 +1,22 @@
1
+ from rrplugins import *
2
+
3
+ modelPlugin = Plugin("tel_test_model")
4
+ noisePlugin = Plugin("tel_add_noise")
5
+ chiSquarePlugin = Plugin("tel_chisquare")
6
+
7
+ #Generate internal test data
8
+ modelPlugin.execute()
9
+ modelData = modelPlugin.TestData
10
+ expData = modelPlugin.TestDataWithNoise
11
+
12
+ chiSquarePlugin.ExperimentalData = expData
13
+ chiSquarePlugin.ModelData = modelData
14
+ chiSquarePlugin.NrOfModelParameters = 1
15
+
16
+ chiSquarePlugin.execute()
17
+
18
+ chi = chiSquarePlugin.ChiSquare
19
+ reduced_chi = chiSquarePlugin.ReducedChiSquare
20
+
21
+ print("ChiSquare is: +", chi)
22
+ print("Reduced ChiSquare is: ",reduced_chi)
@@ -0,0 +1,3 @@
1
+ import rrplugins as tel
2
+ hello = tel.Plugin("tel_hello")
3
+ hello.execute()
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,33 @@
1
+ import rrplugins
2
+
3
+ sbmlModel ="BIOMD0000000203.xml"
4
+ auto = rrplugins.Plugin("tel_auto2000")
5
+
6
+ #print auto.listOfPropertyNames()
7
+
8
+ #Setup Auto Propertys
9
+ auto.setProperty("SBML", rrplugins.readAllText(sbmlModel))
10
+
11
+ #Auto specific properties
12
+ auto.setProperty("ScanDirection", "Positive")
13
+ auto.setProperty("PrincipalContinuationParameter", "A")
14
+ auto.setProperty("PCPLowerBound", 10)
15
+ auto.setProperty("PCPUpperBound", 200)
16
+
17
+ #Max numberof points
18
+ auto.setProperty("NMX", 5000)
19
+
20
+ #Execute the plugin
21
+ auto.execute()
22
+
23
+ # Bifurcation summary
24
+ print("Summary: ", auto.BifurcationSummary)
25
+
26
+ #Plot Bifurcation diagram
27
+ pts = auto.BifurcationPoints
28
+ lbls = auto.BifurcationLabels
29
+ biData = auto.BifurcationData
30
+
31
+ biData.plotBifurcationDiagram(pts, lbls)
32
+
33
+ print("Done")
@@ -0,0 +1,72 @@
1
+ import rrplugins
2
+ from rrplugins import tpc
3
+
4
+ # Load Plugins
5
+ chiPlugin = rrplugins.Plugin("tel_chisquare")
6
+ lm = rrplugins.Plugin("tel_levenberg_marquardt")
7
+ modelPlugin = rrplugins.Plugin("tel_test_model")
8
+ addNoisePlugin = rrplugins.Plugin("tel_add_noise")
9
+
10
+ #========== EVENT FUNCTION SETUP ===========================
11
+ def myEvent(dummy, dummy2): #We are not capturing any data from the plugin, so just pass a dummy
12
+ print('Iteration, Norm = ', lm.getProperty("NrOfIter") , ', ', lm.getProperty("Norm"))
13
+
14
+ #Setup progress event function
15
+ progressEvent = rrplugins.NotifyEventEx(myEvent)
16
+ rrplugins.assignOnProgressEvent(lm.plugin, progressEvent)
17
+ #============================================================
18
+
19
+ #Create model data, with and without noise using the test_model plugin
20
+ modelPlugin.execute()
21
+
22
+ #Setup lmfit properties.
23
+ lm.SBML = modelPlugin.Model
24
+ lm.ExperimentalData = modelPlugin.TestDataWithNoise
25
+
26
+ # Add the parameters that we're going to fit and an initial 'start' value
27
+ lm.setProperty("InputParameterList", ["k1", .3])
28
+ lm.setProperty("FittedDataSelectionList", "[S1] [S2]")
29
+ lm.setProperty("ExperimentalDataSelectionList", "[S1] [S2]")
30
+
31
+ # Start minimization
32
+ lm.execute()
33
+
34
+ print('Minimization finished. \n==== Result ====')
35
+ print('Fit engine status: ', lm.getProperty('StatusMessage'))
36
+
37
+ print('Hessian Matrix')
38
+ print(lm.getProperty("Hessian"))
39
+
40
+ print('Covariance Matrix')
41
+ print(lm.getProperty("CovarianceMatrix"))
42
+
43
+ print('ChiSquare = ' , lm.getProperty("ChiSquare"))
44
+ print('Reduced ChiSquare = ' , lm.getProperty("ReducedChiSquare"))
45
+
46
+ #This is a list of parameters
47
+ parameters = tpc.getPluginProperty (lm.plugin, "OutputParameterList")
48
+ confLimits = tpc.getPluginProperty (lm.plugin, "ConfidenceLimits")
49
+
50
+ #Iterate trough list of parameters and confidence limits
51
+ para = rrplugins.getFirstProperty(parameters)
52
+ limit = rrplugins.getFirstProperty(confLimits)
53
+ while para and limit:
54
+ print(rrplugins.getPropertyName(para), ' = ', rrplugins.getPropertyValue(para), ' +/- ', rrplugins.getPropertyValue(limit))
55
+ para = rrplugins.getNextProperty(parameters)
56
+ limit = rrplugins.getNextProperty(confLimits)
57
+
58
+
59
+ # Get the fitted and residual data
60
+ fittedData = lm.getProperty ("FittedData").toNumPy()
61
+ residuals = lm.getProperty ("Residuals").toNumPy()
62
+
63
+ # Get the experimental data as a numpy array
64
+ experimentalData = modelPlugin.TestDataWithNoise.toNumPy()
65
+
66
+ rrplugins.plot(fittedData [:,[0,1]], "blue", "-", "", "S1 Fitted")
67
+ rrplugins.plot(fittedData [:,[0,2]], "blue", "-", "", "S2 Fitted")
68
+ rrplugins.plot(residuals [:,[0,1]], "blue", "None", "x", "S1 Residual")
69
+ rrplugins.plot(residuals [:,[0,2]], "red", "None", "x", "S2 Residual")
70
+ rrplugins.plot(experimentalData [:,[0,1]], "red", "", "*", "S1 Data")
71
+ rrplugins.plot(experimentalData [:,[0,2]], "blue", "", "*", "S2 Data")
72
+ rrplugins.plt.show()
@@ -0,0 +1,88 @@
1
+ import rrplugins
2
+ import matplotlib.pyplot as plt
3
+ import numpy as np
4
+
5
+ #Load plugins
6
+ modelP = rrplugins.Plugin("tel_test_model")
7
+ nP = rrplugins.Plugin("tel_add_noise")
8
+ chiP = rrplugins.Plugin("tel_chisquare")
9
+ lmP = rrplugins.Plugin("tel_levenberg_marquardt")
10
+ nmP = rrplugins.Plugin("tel_nelder_mead")
11
+ mcP = rrplugins.Plugin("tel_monte_carlo_bs")
12
+
13
+ #========== EVENT FUNCTION SETUP ===========================
14
+ def myEventFunction(ignore, ignore2):
15
+ # Get the fitted and residual data
16
+ experimentalData = lmP.getProperty ("ExperimentalData").toNumPy()
17
+ fittedData = lmP.getProperty ("FittedData").toNumPy()
18
+ residuals = lmP.getProperty ("Residuals").toNumPy()
19
+
20
+ rrplugins.plot(fittedData [:,[0,1]], "blue", "-", "", "S1 Fitted")
21
+ rrplugins.plot(fittedData [:,[0,2]], "blue", "-", "", "S2 Fitted")
22
+ rrplugins.plot(residuals [:,[0,1]], "blue", "None", "x", "S1 Residual")
23
+ rrplugins.plot(residuals [:,[0,2]], "red", "None", "x", "S2 Residual")
24
+ rrplugins.plot(experimentalData [:,[0,1]], "red", "", "*", "S1 Data")
25
+ rrplugins.plot(experimentalData [:,[0,2]], "blue", "", "*", "S2 Data")
26
+
27
+ print('Minimization finished. \n==== Result ====')
28
+ print(rrplugins.getPluginResult(lmP.plugin))
29
+ rrplugins.plt.show()
30
+
31
+ #Communicating event
32
+ myEvent = rrplugins.NotifyEventEx(myEventFunction)
33
+
34
+ #Uncomment the event assignment below to plot each monte carlo data set
35
+ #assignOnFinishedEvent(lmP.plugin, myEvent, None)
36
+
37
+ #This will create test data with noise. We will use that as 'experimental' data
38
+ modelP.execute()
39
+
40
+ #Setup Monte Carlo properties.
41
+ mcP.SBML = modelP.Model
42
+ mcP.ExperimentalData = modelP.TestDataWithNoise
43
+
44
+ #Select what minimization plugin to use
45
+ #mcP.MinimizerPlugin = "Nelder-Mead"
46
+ mcP.MinimizerPlugin = "Levenberg-Marquardt"
47
+ mcP.NrOfMCRuns = 100
48
+ mcP.InputParameterList = ["k1", 1.5]
49
+ mcP.FittedDataSelectionList = "[S1] [S2]"
50
+ mcP.ExperimentalDataSelectionList = "[S1] [S2]"
51
+
52
+ # Start Monte Carlo
53
+ mcP.execute()
54
+
55
+ print('Monte Carlo Finished. \n==== Result ====')
56
+ print(mcP.MonteCarloParameters.getColumnHeaders())
57
+ paras = mcP.MonteCarloParameters.toNumPy()
58
+ print(paras)
59
+
60
+ #Get mean (assuming normal distribution).
61
+ print("The mean: k1= ", np.mean(paras))
62
+
63
+
64
+ PropertyOfTypeListHandle = rrplugins.getPluginProperty(mcP.plugin, "ConfidenceIntervals")
65
+ print(rrplugins.getNamesFromPropertyList(PropertyOfTypeListHandle))
66
+ aProperty = rrplugins.getFirstProperty(PropertyOfTypeListHandle)
67
+ if aProperty:
68
+ print(rrplugins.getPropertyValueAsString(aProperty))
69
+
70
+ PercentileHandle = rrplugins.getPluginProperty(mcP.plugin, "Percentiles")
71
+ print(rrplugins.getNamesFromPropertyList(PercentileHandle))
72
+ aProperty = rrplugins.getFirstProperty(PercentileHandle)
73
+ while aProperty:
74
+ print(rrplugins.getPropertyName(aProperty), ":", rrplugins.getPropertyValueAsString(aProperty))
75
+ aProperty = rrplugins.getNextProperty(PercentileHandle)
76
+
77
+ #Show MOnte Carlo parameters as a histogram
78
+ plt.hist(paras, 50)
79
+ plt.show()
80
+
81
+ #Plot Monte Carlo data sets
82
+ #dataSeries = DataSeries.readDataSeries("MCDataSets.dat")
83
+ #dataSeries.plot()
84
+
85
+ #Finally, view the manual and version
86
+ # mcP.viewManual()
87
+ print('Plugin version: ', mcP.getVersion())
88
+
@@ -0,0 +1,66 @@
1
+ import rrplugins
2
+ from rrplugins import tpc
3
+
4
+ # Load Plugins
5
+ chiPlugin = rrplugins.Plugin("tel_chisquare")
6
+ nm = rrplugins.Plugin("tel_nelder_mead")
7
+ modelPlugin = rrplugins.Plugin("tel_test_model")
8
+ addNoisePlugin = rrplugins.Plugin("tel_add_noise")
9
+
10
+ #========== EVENT FUNCTION SETUP ===========================
11
+ def myEvent(dummy, dummy2): #We are not capturing any data from the plugin, so just pass a dummy
12
+ print('Iteration, Norm = ', nm.getProperty("NrOfIter") , ', ', nm.getProperty("Norm"))
13
+
14
+ #Setup progress event function
15
+ progressEvent = rrplugins.NotifyEventEx(myEvent)
16
+ rrplugins.assignOnProgressEvent(nm.plugin, progressEvent)
17
+ #============================================================
18
+
19
+ #Create model data, with and without noise using the test_model plugin
20
+ modelPlugin.execute()
21
+
22
+ #Setup plugin properties.
23
+ nm.SBML = modelPlugin.Model
24
+ nm.ExperimentalData = modelPlugin.TestDataWithNoise
25
+
26
+ # Add the parameters that we're going to fit and an initial 'start' value
27
+ nm.setProperty("InputParameterList", ["k1", .3])
28
+ nm.setProperty("FittedDataSelectionList", "[S1] [S2]")
29
+ nm.setProperty("ExperimentalDataSelectionList", "[S1] [S2]")
30
+
31
+ # Start minimization
32
+ nm.execute()
33
+
34
+ print('Minimization finished. \n==== Result ====')
35
+
36
+ print('ChiSquare = ' , nm.getProperty("ChiSquare"))
37
+ print('Reduced ChiSquare = ' , nm.getProperty("ReducedChiSquare"))
38
+
39
+ #This is a list of parameters
40
+ parameters = tpc.getPluginProperty (nm.plugin, "OutputParameterList")
41
+
42
+ #Iterate trough list of parameters and confidence limits
43
+ para = rrplugins.getFirstProperty(parameters)
44
+ while para:
45
+ print(rrplugins.getPropertyName(para), ' = ', rrplugins.getPropertyValue(para))
46
+ para = rrplugins.getNextProperty(parameters)
47
+
48
+
49
+ # Get the fitted and residual data
50
+ fittedData = nm.getProperty ("FittedData").toNumPy()
51
+ residuals = nm.getProperty ("Residuals").toNumPy()
52
+
53
+ # Get the experimental data as a numpy array
54
+ experimentalData = modelPlugin.TestDataWithNoise.toNumPy()
55
+
56
+ rrplugins.plot(fittedData [:,[0,1]], "blue", "-", "", "S1 Fitted")
57
+ rrplugins.plot(fittedData [:,[0,2]], "blue", "-", "", "S2 Fitted")
58
+ rrplugins.plot(residuals [:,[0,1]], "blue", "None", "x", "S1 Residual")
59
+ rrplugins.plot(residuals [:,[0,2]], "red", "None", "x", "S2 Residual")
60
+ rrplugins.plot(experimentalData [:,[0,1]], "red", "", "*", "S1 Data")
61
+ rrplugins.plot(experimentalData [:,[0,2]], "blue", "", "*", "S2 Data")
62
+ rrplugins.plt.show()
63
+
64
+ #Finally, view the manual and version
65
+ # nm.viewManual()
66
+ print('Plugin version: ', nm.getVersion())