SimBio 1.1.0__tar.gz → 1.3.0__tar.gz
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.
- {simbio-1.1.0 → simbio-1.3.0}/PKG-INFO +2 -2
- simbio-1.3.0/pyproject.toml +194 -0
- simbio-1.1.0/pyproject.toml → simbio-1.3.0/pyproject.toml.orig +15 -8
- simbio-1.3.0/skill/share/agent-skills/dyscolab-modeling/examples/data/decay.xml +30 -0
- simbio-1.3.0/skill/share/agent-skills/dyscolab-modeling/examples/simbio_compartments.py +93 -0
- simbio-1.3.0/skill/share/agent-skills/dyscolab-modeling/examples/simbio_sbml.py +41 -0
- simbio-1.3.0/skill/share/agent-skills/dyscolab-modeling/examples/simbio_stochastic.py +28 -0
- simbio-1.3.0/skill/share/agent-skills/dyscolab-modeling/references/simbio-api.md +29 -0
- simbio-1.3.0/skill/share/agent-skills/dyscolab-modeling/references/simbio.md +218 -0
- {simbio-1.1.0 → simbio-1.3.0}/src/simbio/__init__.py +3 -1
- {simbio-1.1.0 → simbio-1.3.0}/src/simbio/io/graph/networkx.py +13 -11
- {simbio-1.1.0 → simbio-1.3.0}/src/simbio/io/mathML/exporter.py +22 -10
- {simbio-1.1.0 → simbio-1.3.0}/src/simbio/io/mathML/importer.py +41 -19
- simbio-1.3.0/src/simbio/io/mathML/symbol.py +20 -0
- simbio-1.3.0/src/simbio/io/mathML/test_mathML.py +110 -0
- {simbio-1.1.0 → simbio-1.3.0}/src/simbio/io/mathML/to_symbolite.py +1 -1
- {simbio-1.1.0 → simbio-1.3.0}/src/simbio/io/sbml/importer.py +28 -21
- {simbio-1.1.0 → simbio-1.3.0}/src/simbio/io/sbml/test_importer.py +3 -3
- {simbio-1.1.0 → simbio-1.3.0}/src/simbio/io/sbml/tests/test_sbml_test_suite.py +13 -13
- simbio-1.3.0/src/simbio/io/substitute_by_name.py +62 -0
- simbio-1.3.0/src/simbio/latex.py +93 -0
- simbio-1.3.0/src/simbio/skill.py +15 -0
- {simbio-1.1.0 → simbio-1.3.0}/src/simbio/test_core.py +2 -1
- simbio-1.3.0/src/simbio/test_latex.py +20 -0
- simbio-1.3.0/src/simbio/test_skill.py +26 -0
- simbio-1.1.0/src/simbio/io/mathML/symbol.py +0 -9
- simbio-1.1.0/src/simbio/io/mathML/test_mathML.py +0 -32
- {simbio-1.1.0 → simbio-1.3.0}/README.md +0 -0
- {simbio-1.1.0 → simbio-1.3.0}/src/simbio/core.py +0 -0
- {simbio-1.1.0 → simbio-1.3.0}/src/simbio/io/__init__.py +0 -0
- {simbio-1.1.0 → simbio-1.3.0}/src/simbio/io/biomodels.py +0 -0
- {simbio-1.1.0 → simbio-1.3.0}/src/simbio/io/mathML/__init__.py +0 -0
- {simbio-1.1.0 → simbio-1.3.0}/src/simbio/io/sbml/__init__.py +0 -0
- {simbio-1.1.0 → simbio-1.3.0}/src/simbio/io/sbml/from_libsbml.py +0 -0
- {simbio-1.1.0 → simbio-1.3.0}/src/simbio/io/sbml/tests/atol_factor.csv +0 -0
- {simbio-1.1.0 → simbio-1.3.0}/src/simbio/io/sbml/types.py +0 -0
- {simbio-1.1.0 → simbio-1.3.0}/src/simbio/reactions/__init__.py +0 -0
- {simbio-1.1.0 → simbio-1.3.0}/src/simbio/reactions/compound.py +0 -0
- {simbio-1.1.0 → simbio-1.3.0}/src/simbio/reactions/enzymatic.py +0 -0
- {simbio-1.1.0 → simbio-1.3.0}/src/simbio/reactions/single.py +0 -0
- {simbio-1.1.0 → simbio-1.3.0}/src/simbio/reactions/test_reactions.py +0 -0
- {simbio-1.1.0 → simbio-1.3.0}/src/simbio/rebop/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: simbio
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.0
|
|
4
4
|
Summary: A Python-based package for simulation of Chemical Reaction Networks (CRNs).
|
|
5
5
|
Keywords: mass action,michaelis menten,ode,compartment,reaction,SBML,poincare
|
|
6
6
|
Author: Hernán E. Grecco, Mauro Silberberg
|
|
@@ -12,7 +12,7 @@ Classifier: Topic :: Scientific/Engineering
|
|
|
12
12
|
Classifier: Topic :: Software Development :: Libraries
|
|
13
13
|
Classifier: Programming Language :: Python :: 3
|
|
14
14
|
Classifier: Operating System :: OS Independent
|
|
15
|
-
Requires-Dist: poincare>=1.
|
|
15
|
+
Requires-Dist: poincare>=1.3.0
|
|
16
16
|
Requires-Dist: biomodels ; extra == 'io'
|
|
17
17
|
Requires-Dist: python-libsbml ; extra == 'io'
|
|
18
18
|
Requires-Python: >=3.12
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "simbio"
|
|
3
|
+
description = "A Python-based package for simulation of Chemical Reaction Networks (CRNs)."
|
|
4
|
+
version = "1.3.0"
|
|
5
|
+
license = "MIT"
|
|
6
|
+
classifiers = [
|
|
7
|
+
"Intended Audience :: Developers",
|
|
8
|
+
"Intended Audience :: Science/Research",
|
|
9
|
+
"Topic :: Scientific/Engineering",
|
|
10
|
+
"Topic :: Software Development :: Libraries",
|
|
11
|
+
"Programming Language :: Python :: 3",
|
|
12
|
+
"Operating System :: OS Independent",
|
|
13
|
+
]
|
|
14
|
+
keywords = [
|
|
15
|
+
"mass action",
|
|
16
|
+
"michaelis menten",
|
|
17
|
+
"ode",
|
|
18
|
+
"compartment",
|
|
19
|
+
"reaction",
|
|
20
|
+
"SBML",
|
|
21
|
+
"poincare",
|
|
22
|
+
]
|
|
23
|
+
requires-python = ">=3.12"
|
|
24
|
+
dependencies = ["poincare >= 1.3.0"]
|
|
25
|
+
|
|
26
|
+
[[project.authors]]
|
|
27
|
+
name = "Hernán E. Grecco"
|
|
28
|
+
email = "hernan.grecco@gmail.com"
|
|
29
|
+
|
|
30
|
+
[[project.authors]]
|
|
31
|
+
name = "Mauro Silberberg"
|
|
32
|
+
email = "maurosilber@gmail.com"
|
|
33
|
+
|
|
34
|
+
[project.readme]
|
|
35
|
+
file = "README.md"
|
|
36
|
+
content-type = "text/markdown"
|
|
37
|
+
|
|
38
|
+
[project.urls]
|
|
39
|
+
homepage = "https://github.com/dyscolab/simbio"
|
|
40
|
+
issues = "https://github.com/dyscolab/simbio/issues"
|
|
41
|
+
changelog = "https://github.com/dyscolab/simbio/blob/main/CHANGELOG.md"
|
|
42
|
+
documentation = "https://dyscolab.github.io/simbio"
|
|
43
|
+
|
|
44
|
+
[project.optional-dependencies]
|
|
45
|
+
io = [
|
|
46
|
+
"biomodels",
|
|
47
|
+
"python-libsbml",
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
[build-system]
|
|
51
|
+
requires = ["uv_build>=0.9,<0.10"]
|
|
52
|
+
build-backend = "uv_build"
|
|
53
|
+
|
|
54
|
+
[tool.uv.build-backend.data]
|
|
55
|
+
data = "skill"
|
|
56
|
+
|
|
57
|
+
[tool.pytest.ini_options]
|
|
58
|
+
addopts = ["--import-mode=importlib"]
|
|
59
|
+
|
|
60
|
+
[tool.ruff.format]
|
|
61
|
+
docstring-code-format = true
|
|
62
|
+
|
|
63
|
+
[tool.ruff.lint]
|
|
64
|
+
extend-select = ["I"]
|
|
65
|
+
|
|
66
|
+
[tool.pyright]
|
|
67
|
+
typeCheckingMode = "standard"
|
|
68
|
+
venv = "test"
|
|
69
|
+
venvPath = ".pixi/envs/"
|
|
70
|
+
|
|
71
|
+
[tool.pyrefly]
|
|
72
|
+
python-interpreter-path = ".pixi/envs/default/bin/python"
|
|
73
|
+
project-excludes = [
|
|
74
|
+
".pixi",
|
|
75
|
+
"**/__pycache__",
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
[tool.ty.environment]
|
|
79
|
+
python = ".pixi/envs/default"
|
|
80
|
+
|
|
81
|
+
[tool.pixi.workspace]
|
|
82
|
+
channels = ["https://conda.anaconda.org/conda-forge/"]
|
|
83
|
+
platforms = [
|
|
84
|
+
"linux-64",
|
|
85
|
+
"osx-arm64",
|
|
86
|
+
"win-64",
|
|
87
|
+
]
|
|
88
|
+
preview = ["pixi-build"]
|
|
89
|
+
|
|
90
|
+
[tool.pixi.package.build.backend]
|
|
91
|
+
name = "pixi-build-python"
|
|
92
|
+
version = "*"
|
|
93
|
+
|
|
94
|
+
[tool.pixi.package.build.config]
|
|
95
|
+
ignore-pypi-mapping = false
|
|
96
|
+
|
|
97
|
+
[tool.pixi.package.host-dependencies]
|
|
98
|
+
uv-build = "*"
|
|
99
|
+
|
|
100
|
+
[tool.pixi.environments]
|
|
101
|
+
default = [
|
|
102
|
+
"test",
|
|
103
|
+
"py312",
|
|
104
|
+
]
|
|
105
|
+
test-py312 = [
|
|
106
|
+
"test",
|
|
107
|
+
"io",
|
|
108
|
+
"py312",
|
|
109
|
+
]
|
|
110
|
+
test-py313 = [
|
|
111
|
+
"test",
|
|
112
|
+
"io",
|
|
113
|
+
"py313",
|
|
114
|
+
]
|
|
115
|
+
test-py314 = [
|
|
116
|
+
"test",
|
|
117
|
+
"io",
|
|
118
|
+
"py314",
|
|
119
|
+
]
|
|
120
|
+
|
|
121
|
+
[tool.pixi.environments.lint]
|
|
122
|
+
features = ["lint"]
|
|
123
|
+
no-default-feature = true
|
|
124
|
+
|
|
125
|
+
[tool.pixi.environments.build]
|
|
126
|
+
features = ["build"]
|
|
127
|
+
no-default-feature = true
|
|
128
|
+
|
|
129
|
+
[tool.pixi.dependencies.simbio]
|
|
130
|
+
path = "."
|
|
131
|
+
|
|
132
|
+
[tool.pixi.pypi-dependencies]
|
|
133
|
+
biomodels = "*"
|
|
134
|
+
python-libsbml = "*"
|
|
135
|
+
|
|
136
|
+
[tool.pixi.feature.lint.dependencies]
|
|
137
|
+
pre-commit = "*"
|
|
138
|
+
pre-commit-hooks = "*"
|
|
139
|
+
taplo = "*"
|
|
140
|
+
ruff = "*"
|
|
141
|
+
mdformat = "*"
|
|
142
|
+
mdformat-ruff = "*"
|
|
143
|
+
pyright = "*"
|
|
144
|
+
|
|
145
|
+
[tool.pixi.feature.lint.tasks]
|
|
146
|
+
pre-commit-install = "pre-commit install"
|
|
147
|
+
lint = "pre-commit run"
|
|
148
|
+
|
|
149
|
+
[tool.pixi.feature.build.dependencies]
|
|
150
|
+
uv = "*"
|
|
151
|
+
python = "*"
|
|
152
|
+
|
|
153
|
+
[tool.pixi.feature.build.pypi-dependencies]
|
|
154
|
+
mdremotifier = "*"
|
|
155
|
+
|
|
156
|
+
[tool.pixi.feature.build.tasks]
|
|
157
|
+
publish = "uv publish"
|
|
158
|
+
|
|
159
|
+
[tool.pixi.feature.build.tasks.build]
|
|
160
|
+
cmd = "uv build"
|
|
161
|
+
depends-on = ["remotify"]
|
|
162
|
+
|
|
163
|
+
[tool.pixi.feature.build.tasks.remotify]
|
|
164
|
+
cmd = [
|
|
165
|
+
"mdremotifier",
|
|
166
|
+
"-i",
|
|
167
|
+
"README.md",
|
|
168
|
+
"-o",
|
|
169
|
+
"README.md",
|
|
170
|
+
"--url-prefix",
|
|
171
|
+
"https://github.com/dyscolab/simbio/blob/main",
|
|
172
|
+
"--img-url-prefix",
|
|
173
|
+
"https://raw.githubusercontent.com/dyscolab/simbio/refs/heads/main/",
|
|
174
|
+
]
|
|
175
|
+
|
|
176
|
+
[tool.pixi.feature.test.dependencies]
|
|
177
|
+
pytest = "*"
|
|
178
|
+
pooch = "*"
|
|
179
|
+
networkx = "*"
|
|
180
|
+
|
|
181
|
+
[tool.pixi.feature.test.pypi-dependencies]
|
|
182
|
+
rebop = "*"
|
|
183
|
+
|
|
184
|
+
[tool.pixi.feature.test.tasks]
|
|
185
|
+
test = "pytest --doctest-modules"
|
|
186
|
+
|
|
187
|
+
[tool.pixi.feature.py312.dependencies]
|
|
188
|
+
python = "3.12.*"
|
|
189
|
+
|
|
190
|
+
[tool.pixi.feature.py313.dependencies]
|
|
191
|
+
python = "3.13.*"
|
|
192
|
+
|
|
193
|
+
[tool.pixi.feature.py314.dependencies]
|
|
194
|
+
python = "3.14.*"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "simbio"
|
|
3
3
|
description = "A Python-based package for simulation of Chemical Reaction Networks (CRNs)."
|
|
4
|
-
version = "1.
|
|
4
|
+
version = "1.3.0"
|
|
5
5
|
authors = [
|
|
6
6
|
{ name = "Hernán E. Grecco", email = "hernan.grecco@gmail.com" },
|
|
7
7
|
{ name = "Mauro Silberberg", email = "maurosilber@gmail.com" },
|
|
@@ -26,7 +26,7 @@ keywords = [
|
|
|
26
26
|
"poincare",
|
|
27
27
|
]
|
|
28
28
|
requires-python = ">=3.12"
|
|
29
|
-
dependencies = ["poincare >= 1.
|
|
29
|
+
dependencies = ["poincare >= 1.3.0"]
|
|
30
30
|
|
|
31
31
|
[project.urls]
|
|
32
32
|
homepage = "https://github.com/dyscolab/simbio"
|
|
@@ -41,6 +41,10 @@ io = ["biomodels", "python-libsbml"]
|
|
|
41
41
|
requires = ["uv_build>=0.9,<0.10"]
|
|
42
42
|
build-backend = "uv_build"
|
|
43
43
|
|
|
44
|
+
# The dyscolab-modeling agent skill, installed to <prefix>/share/agent-skills/.
|
|
45
|
+
[tool.uv.build-backend]
|
|
46
|
+
data = { data = "skill" }
|
|
47
|
+
|
|
44
48
|
[tool.pytest.ini_options]
|
|
45
49
|
addopts = ["--import-mode=importlib"]
|
|
46
50
|
|
|
@@ -63,19 +67,17 @@ project-excludes = [".pixi", "**/__pycache__"]
|
|
|
63
67
|
python = ".pixi/envs/default"
|
|
64
68
|
|
|
65
69
|
[tool.pixi.workspace]
|
|
66
|
-
channels = ["https://
|
|
70
|
+
channels = ["https://conda.anaconda.org/conda-forge/"]
|
|
67
71
|
platforms = ["linux-64", "osx-arm64", "win-64"]
|
|
68
72
|
preview = ["pixi-build"]
|
|
69
73
|
|
|
70
74
|
[tool.pixi.package.build]
|
|
71
|
-
backend = { name = "pixi-build-python", version = "
|
|
72
|
-
|
|
75
|
+
backend = { name = "pixi-build-python", version = "*" }
|
|
76
|
+
config = { ignore-pypi-mapping = false } # Enable automatic PyPI-to-conda mapping
|
|
73
77
|
|
|
74
78
|
[tool.pixi.package.host-dependencies]
|
|
75
79
|
uv-build = "*"
|
|
76
80
|
|
|
77
|
-
[tool.pixi.package.run-dependencies]
|
|
78
|
-
# poincare = ">=1.0.0"
|
|
79
81
|
|
|
80
82
|
[tool.pixi.environments]
|
|
81
83
|
default = ["test", "py312"]
|
|
@@ -130,9 +132,14 @@ remotify = { cmd = [
|
|
|
130
132
|
[tool.pixi.feature.test.dependencies]
|
|
131
133
|
pytest = "*"
|
|
132
134
|
pooch = "*"
|
|
135
|
+
networkx = "*"
|
|
136
|
+
|
|
137
|
+
[tool.pixi.feature.test.pypi-dependencies]
|
|
138
|
+
rebop = "*"
|
|
139
|
+
|
|
133
140
|
|
|
134
141
|
[tool.pixi.feature.test.tasks]
|
|
135
|
-
test = "pytest
|
|
142
|
+
test = "pytest --doctest-modules"
|
|
136
143
|
|
|
137
144
|
[tool.pixi.feature]
|
|
138
145
|
py312.dependencies = { python = "3.12.*" }
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<sbml xmlns="http://www.sbml.org/sbml/level3/version1/core" level="3" version="1">
|
|
3
|
+
<model id="decay" name="Decay">
|
|
4
|
+
<listOfCompartments>
|
|
5
|
+
<compartment id="cell" size="1" constant="true"/>
|
|
6
|
+
</listOfCompartments>
|
|
7
|
+
<listOfSpecies>
|
|
8
|
+
<species id="X" compartment="cell" initialAmount="10" hasOnlySubstanceUnits="true" boundaryCondition="false" constant="false"/>
|
|
9
|
+
</listOfSpecies>
|
|
10
|
+
<listOfParameters>
|
|
11
|
+
<parameter id="k" value="0.5" constant="true"/>
|
|
12
|
+
</listOfParameters>
|
|
13
|
+
<listOfReactions>
|
|
14
|
+
<reaction id="deg" reversible="false" fast="false">
|
|
15
|
+
<listOfReactants>
|
|
16
|
+
<speciesReference species="X" stoichiometry="1" constant="true"/>
|
|
17
|
+
</listOfReactants>
|
|
18
|
+
<kineticLaw>
|
|
19
|
+
<math xmlns="http://www.w3.org/1998/Math/MathML">
|
|
20
|
+
<apply>
|
|
21
|
+
<times/>
|
|
22
|
+
<ci> k </ci>
|
|
23
|
+
<ci> X </ci>
|
|
24
|
+
</apply>
|
|
25
|
+
</math>
|
|
26
|
+
</kineticLaw>
|
|
27
|
+
</reaction>
|
|
28
|
+
</listOfReactions>
|
|
29
|
+
</model>
|
|
30
|
+
</sbml>
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""Reversible binding A + B <-> AB in a simbio Compartment.
|
|
2
|
+
|
|
3
|
+
Checks: mass conservation, the analytic equilibrium, and that tracking AB as an
|
|
4
|
+
amount in a 2 L compartment gives the same concentration as tracking it as a
|
|
5
|
+
concentration.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
import pint
|
|
10
|
+
|
|
11
|
+
from poincare import SteadyState, solvers # simbio does not re-export these
|
|
12
|
+
from simbio import (
|
|
13
|
+
Compartment,
|
|
14
|
+
MassAction,
|
|
15
|
+
Parameter,
|
|
16
|
+
Simulator,
|
|
17
|
+
Species,
|
|
18
|
+
Volume,
|
|
19
|
+
amount,
|
|
20
|
+
assign,
|
|
21
|
+
concentration,
|
|
22
|
+
volume,
|
|
23
|
+
)
|
|
24
|
+
from simbio.reactions import ReversibleSynthesis
|
|
25
|
+
|
|
26
|
+
u = pint.get_application_registry()
|
|
27
|
+
TIGHT = solvers.LSODA(rtol=1e-9, atol=1e-12)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class Binding(Compartment):
|
|
31
|
+
V: Volume = volume(default=2 * u.L)
|
|
32
|
+
A: Species = concentration(default=1 * u.mM)
|
|
33
|
+
B: Species = concentration(default=0.5 * u.mM)
|
|
34
|
+
AB: Species = concentration(default=0 * u.mM)
|
|
35
|
+
kon: Parameter = assign(default=1 / u.mM / u.s)
|
|
36
|
+
koff: Parameter = assign(default=0.1 / u.s)
|
|
37
|
+
|
|
38
|
+
binding = ReversibleSynthesis(A=A, B=B, AB=AB, forward_rate=kon, reverse_rate=koff)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class BindingAmountAB(Compartment):
|
|
42
|
+
"""Same system, but AB is tracked as an amount (mmol) instead of a concentration.
|
|
43
|
+
|
|
44
|
+
With amount species, write the reactions directly in the Compartment.
|
|
45
|
+
Motifs from simbio.reactions are subsystems and do not see the compartment
|
|
46
|
+
volume (simbio 1.2.0): with units they fail, without units they silently
|
|
47
|
+
skip the volume conversion.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
V: Volume = volume(default=2 * u.L)
|
|
51
|
+
A: Species = concentration(default=1 * u.mM)
|
|
52
|
+
B: Species = concentration(default=0.5 * u.mM)
|
|
53
|
+
AB: Species = amount(default=0 * u.mmol)
|
|
54
|
+
kon: Parameter = assign(default=1 / u.mM / u.s)
|
|
55
|
+
koff: Parameter = assign(default=0.1 / u.s)
|
|
56
|
+
|
|
57
|
+
binding = MassAction(reactants=[A, B], products=[AB], rate=kon)
|
|
58
|
+
unbinding = MassAction(reactants=[AB], products=[A, B], rate=koff)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
save_at = np.linspace(0, 30, 61) * u.s
|
|
62
|
+
conc = Simulator(Binding).with_solver(TIGHT).with_times(save_at=save_at).solve()
|
|
63
|
+
|
|
64
|
+
# Conservation: A + AB and B + AB are constant.
|
|
65
|
+
total_A = (conc["A"] + conc["AB"]).pint.to(u.mM).pint.dequantify().values
|
|
66
|
+
np.testing.assert_allclose(total_A, 1.0, rtol=1e-8)
|
|
67
|
+
|
|
68
|
+
# Equilibrium: AB = (A0 - AB)(B0 - AB) / Kd, with Kd = koff / kon = 0.1 mM.
|
|
69
|
+
a0, b0, kd = 1.0, 0.5, 0.1
|
|
70
|
+
ab_eq = ((a0 + b0 + kd) - np.sqrt((a0 + b0 + kd) ** 2 - 4 * a0 * b0)) / 2
|
|
71
|
+
steady = SteadyState().solve(Simulator(Binding).with_solver(TIGHT))
|
|
72
|
+
np.testing.assert_allclose(steady["AB"].pint.to(u.mM).pint.dequantify().item(), ab_eq, rtol=1e-6)
|
|
73
|
+
|
|
74
|
+
# Amount vs concentration bookkeeping: AB_amount / V == AB_concentration.
|
|
75
|
+
amt = (
|
|
76
|
+
Simulator(BindingAmountAB)
|
|
77
|
+
.with_solver(TIGHT)
|
|
78
|
+
.with_times(save_at=save_at)
|
|
79
|
+
.with_transform({"AB_conc": BindingAmountAB.AB / BindingAmountAB.V}, append=True)
|
|
80
|
+
.solve()
|
|
81
|
+
)
|
|
82
|
+
np.testing.assert_allclose(
|
|
83
|
+
amt["AB_conc"].pint.to(u.mM).pint.dequantify().values,
|
|
84
|
+
conc["AB"].pint.to(u.mM).pint.dequantify().values,
|
|
85
|
+
rtol=1e-6,
|
|
86
|
+
atol=1e-12,
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
if __name__ == "__main__":
|
|
90
|
+
import matplotlib.pyplot as plt
|
|
91
|
+
|
|
92
|
+
conc.pint.dequantify().to_dataframe()[["A", "B", "AB"]].plot()
|
|
93
|
+
plt.show()
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Import an SBML model with simbio and simulate it with poincare.
|
|
2
|
+
|
|
3
|
+
data/decay.xml is X -> 0 with k = 0.5 and X(0) = 10, checked against
|
|
4
|
+
X(t) = 10 exp(-0.5 t).
|
|
5
|
+
|
|
6
|
+
Requires the `io` extra (`pip install "simbio[io]"`). simbio 1.2.0's SBML import
|
|
7
|
+
only works on Python >= 3.14; older Pythons fail at import with
|
|
8
|
+
`NameError: name 'types' is not defined`.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
import numpy as np
|
|
14
|
+
|
|
15
|
+
from poincare import solvers
|
|
16
|
+
from simbio import Simulator
|
|
17
|
+
from simbio.io import sbml
|
|
18
|
+
|
|
19
|
+
path = Path(__file__).parent / "data" / "decay.xml"
|
|
20
|
+
Decay = sbml.load(path) # a poincare System class; pass name=... if the SBML model has none
|
|
21
|
+
|
|
22
|
+
# Components are class attributes named after their SBML ids.
|
|
23
|
+
print(Decay) # summary table of variables, parameters and equations
|
|
24
|
+
assert {"X", "k", "deg"} <= set(vars(Decay))
|
|
25
|
+
|
|
26
|
+
t = np.linspace(0, 6, 31)
|
|
27
|
+
sim = (
|
|
28
|
+
Simulator(Decay)
|
|
29
|
+
.with_solver(solvers.LSODA(rtol=1e-9, atol=1e-12))
|
|
30
|
+
.with_times(save_at=t)
|
|
31
|
+
)
|
|
32
|
+
result = sim.solve()
|
|
33
|
+
np.testing.assert_allclose(result["X"].values, 10 * np.exp(-0.5 * t), rtol=1e-6)
|
|
34
|
+
|
|
35
|
+
# Parameters and initial values are changed like in any other model.
|
|
36
|
+
faster = sim.with_values({Decay.k: 1.0, Decay.X: 5}).solve()
|
|
37
|
+
np.testing.assert_allclose(faster["X"].values, 5 * np.exp(-1.0 * t), rtol=1e-6)
|
|
38
|
+
|
|
39
|
+
# The same model from a string; `name` is required when the SBML has no name.
|
|
40
|
+
Decay2 = sbml.loads(path.read_text(), name="DecayFromString")
|
|
41
|
+
assert Decay2.__name__ == "DecayFromString"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Stochastic (Gillespie) simulation of a reaction network with rebop.
|
|
2
|
+
|
|
3
|
+
A -> 0 with rate k: the mean of many stochastic runs follows the ODE solution
|
|
4
|
+
N0 exp(-k t). Requires `pip install rebop`.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
import xarray as xr
|
|
9
|
+
|
|
10
|
+
from simbio import MassAction, Simulator, System, Variable, initial
|
|
11
|
+
from simbio.rebop import RebopSimulator
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Decay(System):
|
|
15
|
+
A: Variable = initial(default=500) # copy numbers: integers, no units
|
|
16
|
+
degradation = MassAction(reactants=[A], products=[], rate=0.5)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# n_points equally spaced samples after t = 0, so n_points + 1 time points.
|
|
20
|
+
rsim = RebopSimulator(Decay).with_times(upto_t=4, n_points=8)
|
|
21
|
+
runs = xr.concat([rsim.solve(rng=seed) for seed in range(40)], dim="run")
|
|
22
|
+
mean = runs["A"].mean("run")
|
|
23
|
+
t = mean["time"].values
|
|
24
|
+
np.testing.assert_allclose(mean.values, 500 * np.exp(-0.5 * t), rtol=0.05)
|
|
25
|
+
|
|
26
|
+
# The same model runs deterministically with the ODE simulator.
|
|
27
|
+
ode = Simulator(Decay).with_times(save_at=t).solve()
|
|
28
|
+
np.testing.assert_allclose(ode["A"].values, 500 * np.exp(-0.5 * t), rtol=1e-2)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Public API inventory: simbio (1.2.0 and newer)
|
|
2
|
+
|
|
3
|
+
Use this to check that a name exists before you write code with it. When the installed
|
|
4
|
+
version differs, check the installed source instead
|
|
5
|
+
(`python -c "import simbio.reactions as m; print(dir(m))"`). The poincare inventory is in
|
|
6
|
+
[api-inventory.md](api-inventory.md).
|
|
7
|
+
|
|
8
|
+
Names marked *(newer)* exist only after simbio 1.2.0.
|
|
9
|
+
|
|
10
|
+
## simbio
|
|
11
|
+
|
|
12
|
+
| Module | Names | Reference |
|
|
13
|
+
| --- | --- | --- |
|
|
14
|
+
| `simbio` | re-exports from poincare (`System`, `Variable`, `Parameter`, `Constant`, `Independent`, `Simulator`, `initial`, `assign`, `Reactant`, `reaction_initial`, `RateLaw`, `MassAction`, `AbsoluteRateLaw`) plus `Compartment`, `Species`, `Volume`, `amount`, `concentration`, `volume`, `reaction_amount`, `reaction_concentration`, `model_report`, `notebook_report` *(newer)* | [simbio.md](simbio.md) |
|
|
15
|
+
| `simbio.reactions` (`.single`, `.compound`, `.enzymatic`) | `Creation`, `AutoCreation`, `Destruction`, `Conversion`, `Synthesis`, `Dissociation`, `ReversibleSynthesis`, `Equilibration`, `CatalyzeConvert`, `MichaelisMenten`, `MichaelisMentenEqApprox`, `MichaelisMentenQuasiSSAprox` | [simbio.md](simbio.md#reaction-motifs) |
|
|
16
|
+
| `simbio.io.sbml` | `load`, `loads` (Python ≥ 3.14 with 1.2.0) | [simbio.md](simbio.md#sbml-biomodels-and-mathml) |
|
|
17
|
+
| `simbio.io.biomodels` | `load` | same |
|
|
18
|
+
| `simbio.io.mathML` | `to_mathML`, `mathMLImporter` | same |
|
|
19
|
+
| `simbio.io.sbml.substitute_by_name` (newer: `simbio.io.substitute_by_name`) | `substitute_by_name` | same |
|
|
20
|
+
| `simbio.latex` | `latex_reactions` (*(newer)* `format=`), `model_report`, `notebook_report` *(newer)* | [simbio.md](simbio.md#graphs-reports-stochastic-runs) |
|
|
21
|
+
| `simbio.io.graph.networkx` | `graph`, `to_Variable_graph`, `to_reaction_graph` | [simbio.md](simbio.md#graphs-reports-stochastic-runs) |
|
|
22
|
+
| `simbio.rebop` | `RebopSimulator` | [analysis.md](analysis.md#stochastic-simulation-rebop) |
|
|
23
|
+
| `simbio.skill` *(newer)* | `install`, `check`: the same as `poincare.skill` | [SKILL.md](../SKILL.md#versions-and-environment) |
|
|
24
|
+
|
|
25
|
+
## Internal helpers (don't use)
|
|
26
|
+
|
|
27
|
+
`simbio.core.first_system_parent`, `is_instance_or_subclass`,
|
|
28
|
+
`simbio.io.sbml.substitute_by_name.call_substitute_by_name` / `value_substitute_by_name`,
|
|
29
|
+
and anything whose name starts with `_`.
|