SimBio 0.4.0__tar.gz → 1.0.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.
Files changed (70) hide show
  1. simbio-1.0.0/PKG-INFO +125 -0
  2. simbio-1.0.0/README.md +100 -0
  3. simbio-1.0.0/pyproject.toml +139 -0
  4. simbio-1.0.0/src/simbio/__init__.py +50 -0
  5. simbio-1.0.0/src/simbio/core.py +163 -0
  6. simbio-1.0.0/src/simbio/io/graph/networkx.py +46 -0
  7. {simbio-0.4 → simbio-1.0.0}/src/simbio/io/mathML/exporter.py +44 -43
  8. {simbio-0.4 → simbio-1.0.0}/src/simbio/io/mathML/importer.py +47 -45
  9. simbio-1.0.0/src/simbio/io/mathML/symbol.py +9 -0
  10. {simbio-0.4 → simbio-1.0.0}/src/simbio/io/mathML/test_mathML.py +3 -3
  11. {simbio-0.4 → simbio-1.0.0}/src/simbio/io/mathML/to_symbolite.py +45 -50
  12. {simbio-0.4 → simbio-1.0.0}/src/simbio/io/sbml/importer.py +56 -60
  13. {simbio-0.4 → simbio-1.0.0}/src/simbio/io/sbml/test_importer.py +2 -2
  14. {simbio-0.4 → simbio-1.0.0}/src/simbio/reactions/compound.py +19 -18
  15. {simbio-0.4 → simbio-1.0.0}/src/simbio/reactions/enzymatic.py +21 -14
  16. {simbio-0.4 → simbio-1.0.0}/src/simbio/reactions/single.py +25 -18
  17. simbio-1.0.0/src/simbio/reactions/test_reactions.py +22 -0
  18. simbio-1.0.0/src/simbio/test_core.py +378 -0
  19. simbio-0.4/.gitattributes +0 -4
  20. simbio-0.4/.github/workflows/ci.yml +0 -54
  21. simbio-0.4/.gitignore +0 -24
  22. simbio-0.4/.pre-commit-config.yaml +0 -28
  23. simbio-0.4/.readthedocs.yml +0 -21
  24. simbio-0.4/PKG-INFO +0 -174
  25. simbio-0.4/README.md +0 -142
  26. simbio-0.4/conftest.py +0 -32
  27. simbio-0.4/docs/_config.yml +0 -32
  28. simbio-0.4/docs/_toc.yml +0 -21
  29. simbio-0.4/docs/compilers/index.md +0 -67
  30. simbio-0.4/docs/design/design.md +0 -186
  31. simbio-0.4/docs/design/dsl.md +0 -225
  32. simbio-0.4/docs/design/features.md +0 -77
  33. simbio-0.4/docs/design/multilevel_dsl.md +0 -31
  34. simbio-0.4/docs/design/references.md +0 -164
  35. simbio-0.4/docs/examples/basic.md +0 -70
  36. simbio-0.4/docs/examples/chained-reactions.md +0 -78
  37. simbio-0.4/docs/examples/compartments.md +0 -85
  38. simbio-0.4/docs/examples/enzymatic.md +0 -86
  39. simbio-0.4/docs/index.md +0 -24
  40. simbio-0.4/docs/jupytext.toml +0 -3
  41. simbio-0.4/docs/model/dynamic.md +0 -115
  42. simbio-0.4/docs/model/index.md +0 -13
  43. simbio-0.4/docs/model/reactions.md +0 -132
  44. simbio-0.4/docs/model/static.md +0 -314
  45. simbio-0.4/environment-dev.yml +0 -18
  46. simbio-0.4/pyproject.toml +0 -59
  47. simbio-0.4/requirements.docs.txt +0 -5
  48. simbio-0.4/requirements.io.txt +0 -2
  49. simbio-0.4/requirements.test.txt +0 -3
  50. simbio-0.4/requirements.txt +0 -1
  51. simbio-0.4/setup.cfg +0 -4
  52. simbio-0.4/src/SimBio.egg-info/PKG-INFO +0 -174
  53. simbio-0.4/src/SimBio.egg-info/SOURCES.txt +0 -59
  54. simbio-0.4/src/SimBio.egg-info/dependency_links.txt +0 -1
  55. simbio-0.4/src/SimBio.egg-info/requires.txt +0 -17
  56. simbio-0.4/src/SimBio.egg-info/top_level.txt +0 -1
  57. simbio-0.4/src/simbio/__init__.py +0 -18
  58. simbio-0.4/src/simbio/core.py +0 -311
  59. simbio-0.4/src/simbio/io/mathML/symbol.py +0 -9
  60. simbio-0.4/src/simbio/reactions/test_reactions.py +0 -29
  61. simbio-0.4/src/simbio/test_core.py +0 -203
  62. /simbio-0.4/docs/references.bib → /simbio-1.0.0/src/simbio/io/__init__.py +0 -0
  63. {simbio-0.4 → simbio-1.0.0}/src/simbio/io/biomodels.py +0 -0
  64. {simbio-0.4 → simbio-1.0.0}/src/simbio/io/mathML/__init__.py +0 -0
  65. {simbio-0.4 → simbio-1.0.0}/src/simbio/io/sbml/__init__.py +0 -0
  66. {simbio-0.4 → simbio-1.0.0}/src/simbio/io/sbml/from_libsbml.py +0 -0
  67. {simbio-0.4 → simbio-1.0.0}/src/simbio/io/sbml/tests/atol_factor.csv +0 -0
  68. {simbio-0.4 → simbio-1.0.0}/src/simbio/io/sbml/tests/test_sbml_test_suite.py +0 -0
  69. {simbio-0.4 → simbio-1.0.0}/src/simbio/io/sbml/types.py +0 -0
  70. {simbio-0.4 → simbio-1.0.0}/src/simbio/reactions/__init__.py +0 -0
simbio-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,125 @@
1
+ Metadata-Version: 2.4
2
+ Name: simbio
3
+ Version: 1.0.0
4
+ Summary: A Python-based package for simulation of Chemical Reaction Networks (CRNs).
5
+ Keywords: mass action,michaelis menten,ode,compartment,reaction,SBML,poincare
6
+ Author: Hernán E. Grecco, Mauro Silberberg
7
+ Author-email: Hernán E. Grecco <hernan.grecco@gmail.com>, Mauro Silberberg <maurosilber@gmail.com>
8
+ License-Expression: MIT
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: Topic :: Scientific/Engineering
12
+ Classifier: Topic :: Software Development :: Libraries
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Operating System :: OS Independent
15
+ Requires-Dist: poincare>=1.0.0
16
+ Requires-Dist: biomodels ; extra == 'io'
17
+ Requires-Dist: python-libsbml ; extra == 'io'
18
+ Requires-Python: >=3.12
19
+ Project-URL: homepage, https://github.com/dyscolab/simbio
20
+ Project-URL: issues, https://github.com/dyscolab/simbio/issues
21
+ Project-URL: changelog, https://github.com/dyscolab/simbio/blob/main/CHANGELOG.md
22
+ Project-URL: documentation, https://dyscolab.github.io/simbio
23
+ Provides-Extra: io
24
+ Description-Content-Type: text/markdown
25
+
26
+ # simbio
27
+
28
+ [![Copier Badge][copier-badge]][copier-url]
29
+ [![Pixi Badge][pixi-badge]][pixi-url]
30
+ ![License][license-badge]
31
+ [![CI Badge][ci-badge]][ci-url]
32
+ [![conda-forge Badge][conda-forge-badge]][conda-forge-url]
33
+ [![PyPI Badge][pypi-badge]][pypi-url]
34
+ [![Python version Badge][pypi-version-badge]][pypi-version-url]
35
+
36
+ A Python-based package for simulation of Chemical Reaction Networks (CRNs).
37
+ It extends [`poincare`](https://github.com/dyscolab/poincare),
38
+ a package for modelling dynamical systems,
39
+ to add functionality for CRNs.
40
+
41
+ ## Usage
42
+
43
+ See [simbio's documentation](https://dyscolab.github.io/simbio/) on the dyscolab page, or go directly to the [intro tutorial](https://marimo.app/github.com/dyscolab/dyscolab-tutorials/blob/main/simbio/getting_started_with_simbio.py).
44
+
45
+ ## Install
46
+
47
+ Using [pixi][pixi-url],
48
+ install from PyPI with:
49
+
50
+ ```sh
51
+ pixi add --pypi simbio
52
+ ```
53
+
54
+ or install the latest development version from GitHub with:
55
+
56
+ ```sh
57
+ pixi add --pypi simbio@https://github.com/dyscolab/simbio.git
58
+ ```
59
+
60
+ Otherwise,
61
+ use `pip` or your `pip`-compatible package manager:
62
+
63
+ ```sh
64
+ pip install simbio # from PyPI
65
+ pip install git+https://github.com/dyscolab/simbio.git # from GitHub
66
+ ```
67
+
68
+ ## Development
69
+
70
+ This project is managed by [pixi][pixi-url].
71
+ You can install it for development using:
72
+
73
+ ```sh
74
+ git clone https://github.com/dyscolab/simbio
75
+ cd simbio
76
+ pixi run pre-commit-install
77
+ ```
78
+
79
+ Pre-commit hooks are used to lint and format the project.
80
+
81
+ ### Testing
82
+
83
+ Run tests using:
84
+
85
+ ```sh
86
+ pixi run test
87
+ ```
88
+
89
+ ### Publishing to PyPI
90
+
91
+ When a tagged commit is pushed to GitHub,
92
+ the GitHub Action defined in `.github/workflows/ci.yml`
93
+ builds and publishes the package to PyPI.
94
+
95
+ Tag a commit and push the tags with:
96
+
97
+ ```sh
98
+ git tag <my-tag>
99
+ git push --tags
100
+ ```
101
+
102
+ Trusted publishing must be enabled once in [PyPI Publishing](https://pypi.org/manage/account/publishing/).
103
+ Fill the following values in the form:
104
+
105
+ ```
106
+ PyPI Project Name: simbio
107
+ Owner: maurosilber
108
+ Repository name: simbio
109
+ Workflow name: ci.yml
110
+ Environment name: pypi
111
+ ```
112
+
113
+ [ci-badge]: https://img.shields.io/github/actions/workflow/status/dyscolab/simbio/ci.yml
114
+ [ci-url]: https://github.com/dyscolab/simbio/actions/workflows/ci.yml
115
+ [conda-forge-badge]: https://img.shields.io/conda/vn/conda-forge/simbio?logoColor=white&logo=conda-forge
116
+ [conda-forge-url]: https://prefix.dev/channels/conda-forge/packages/simbio
117
+ [copier-badge]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/copier-org/copier/master/img/badge/badge-black.json
118
+ [copier-url]: https://github.com/copier-org/copier
119
+ [license-badge]: https://img.shields.io/badge/license-MIT-blue
120
+ [pixi-badge]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/prefix-dev/pixi/main/assets/badge/v0.json
121
+ [pixi-url]: https://pixi.sh
122
+ [pypi-badge]: https://img.shields.io/pypi/v/simbio.svg?logo=pypi&logoColor=white
123
+ [pypi-url]: https://pypi.org/project/simbio
124
+ [pypi-version-badge]: https://img.shields.io/pypi/pyversions/simbio?logoColor=white&logo=python
125
+ [pypi-version-url]: https://pypi.org/project/simbio
simbio-1.0.0/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # simbio
2
+
3
+ [![Copier Badge][copier-badge]][copier-url]
4
+ [![Pixi Badge][pixi-badge]][pixi-url]
5
+ ![License][license-badge]
6
+ [![CI Badge][ci-badge]][ci-url]
7
+ [![conda-forge Badge][conda-forge-badge]][conda-forge-url]
8
+ [![PyPI Badge][pypi-badge]][pypi-url]
9
+ [![Python version Badge][pypi-version-badge]][pypi-version-url]
10
+
11
+ A Python-based package for simulation of Chemical Reaction Networks (CRNs).
12
+ It extends [`poincare`](https://github.com/dyscolab/poincare),
13
+ a package for modelling dynamical systems,
14
+ to add functionality for CRNs.
15
+
16
+ ## Usage
17
+
18
+ See [simbio's documentation](https://dyscolab.github.io/simbio/) on the dyscolab page, or go directly to the [intro tutorial](https://marimo.app/github.com/dyscolab/dyscolab-tutorials/blob/main/simbio/getting_started_with_simbio.py).
19
+
20
+ ## Install
21
+
22
+ Using [pixi][pixi-url],
23
+ install from PyPI with:
24
+
25
+ ```sh
26
+ pixi add --pypi simbio
27
+ ```
28
+
29
+ or install the latest development version from GitHub with:
30
+
31
+ ```sh
32
+ pixi add --pypi simbio@https://github.com/dyscolab/simbio.git
33
+ ```
34
+
35
+ Otherwise,
36
+ use `pip` or your `pip`-compatible package manager:
37
+
38
+ ```sh
39
+ pip install simbio # from PyPI
40
+ pip install git+https://github.com/dyscolab/simbio.git # from GitHub
41
+ ```
42
+
43
+ ## Development
44
+
45
+ This project is managed by [pixi][pixi-url].
46
+ You can install it for development using:
47
+
48
+ ```sh
49
+ git clone https://github.com/dyscolab/simbio
50
+ cd simbio
51
+ pixi run pre-commit-install
52
+ ```
53
+
54
+ Pre-commit hooks are used to lint and format the project.
55
+
56
+ ### Testing
57
+
58
+ Run tests using:
59
+
60
+ ```sh
61
+ pixi run test
62
+ ```
63
+
64
+ ### Publishing to PyPI
65
+
66
+ When a tagged commit is pushed to GitHub,
67
+ the GitHub Action defined in `.github/workflows/ci.yml`
68
+ builds and publishes the package to PyPI.
69
+
70
+ Tag a commit and push the tags with:
71
+
72
+ ```sh
73
+ git tag <my-tag>
74
+ git push --tags
75
+ ```
76
+
77
+ Trusted publishing must be enabled once in [PyPI Publishing](https://pypi.org/manage/account/publishing/).
78
+ Fill the following values in the form:
79
+
80
+ ```
81
+ PyPI Project Name: simbio
82
+ Owner: maurosilber
83
+ Repository name: simbio
84
+ Workflow name: ci.yml
85
+ Environment name: pypi
86
+ ```
87
+
88
+ [ci-badge]: https://img.shields.io/github/actions/workflow/status/dyscolab/simbio/ci.yml
89
+ [ci-url]: https://github.com/dyscolab/simbio/actions/workflows/ci.yml
90
+ [conda-forge-badge]: https://img.shields.io/conda/vn/conda-forge/simbio?logoColor=white&logo=conda-forge
91
+ [conda-forge-url]: https://prefix.dev/channels/conda-forge/packages/simbio
92
+ [copier-badge]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/copier-org/copier/master/img/badge/badge-black.json
93
+ [copier-url]: https://github.com/copier-org/copier
94
+ [license-badge]: https://img.shields.io/badge/license-MIT-blue
95
+ [pixi-badge]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/prefix-dev/pixi/main/assets/badge/v0.json
96
+ [pixi-url]: https://pixi.sh
97
+ [pypi-badge]: https://img.shields.io/pypi/v/simbio.svg?logo=pypi&logoColor=white
98
+ [pypi-url]: https://pypi.org/project/simbio
99
+ [pypi-version-badge]: https://img.shields.io/pypi/pyversions/simbio?logoColor=white&logo=python
100
+ [pypi-version-url]: https://pypi.org/project/simbio
@@ -0,0 +1,139 @@
1
+ [project]
2
+ name = "simbio"
3
+ description = "A Python-based package for simulation of Chemical Reaction Networks (CRNs)."
4
+ version = "1.0.0"
5
+ authors = [
6
+ { name = "Hernán E. Grecco", email = "hernan.grecco@gmail.com" },
7
+ { name = "Mauro Silberberg", email = "maurosilber@gmail.com" },
8
+ ]
9
+ readme = { file = "README.md", content-type = "text/markdown" }
10
+ license = "MIT"
11
+ classifiers = [
12
+ "Intended Audience :: Developers",
13
+ "Intended Audience :: Science/Research",
14
+ "Topic :: Scientific/Engineering",
15
+ "Topic :: Software Development :: Libraries",
16
+ "Programming Language :: Python :: 3",
17
+ "Operating System :: OS Independent",
18
+ ]
19
+ keywords = [
20
+ "mass action",
21
+ "michaelis menten",
22
+ "ode",
23
+ "compartment",
24
+ "reaction",
25
+ "SBML",
26
+ "poincare",
27
+ ]
28
+ requires-python = ">=3.12"
29
+ dependencies = ["poincare >= 1.0.0"]
30
+
31
+ [project.urls]
32
+ homepage = "https://github.com/dyscolab/simbio"
33
+ issues = "https://github.com/dyscolab/simbio/issues"
34
+ changelog = "https://github.com/dyscolab/simbio/blob/main/CHANGELOG.md"
35
+ documentation = "https://dyscolab.github.io/simbio"
36
+
37
+ [project.optional-dependencies]
38
+ io = ["biomodels", "python-libsbml"]
39
+
40
+ [build-system]
41
+ requires = ["uv_build>=0.9,<0.10"]
42
+ build-backend = "uv_build"
43
+
44
+ [tool.pytest.ini_options]
45
+ addopts = ["--import-mode=importlib"]
46
+
47
+ [tool.ruff.format]
48
+ docstring-code-format = true
49
+
50
+ [tool.ruff.lint]
51
+ extend-select = ["I"]
52
+
53
+ [tool.pyright]
54
+ typeCheckingMode = "standard"
55
+ venv = "test"
56
+ venvPath = ".pixi/envs/"
57
+
58
+ [tool.pyrefly]
59
+ python-interpreter-path = ".pixi/envs/default/bin/python"
60
+ project-excludes = [".pixi", "**/__pycache__"]
61
+
62
+ [tool.ty.environment]
63
+ python = ".pixi/envs/default"
64
+
65
+ [tool.pixi.workspace]
66
+ channels = ["https://prefix.dev/conda-forge"]
67
+ platforms = ["linux-64", "osx-arm64", "win-64"]
68
+ preview = ["pixi-build"]
69
+
70
+ [tool.pixi.package.build]
71
+ backend = { name = "pixi-build-python", version = "0.4.*" }
72
+
73
+ [tool.pixi.package.host-dependencies]
74
+ uv-build = "*"
75
+
76
+ [tool.pixi.package.run-dependencies]
77
+ # poincare = ">=1.0.0"
78
+
79
+ [tool.pixi.environments]
80
+ default = ["test", "py312"]
81
+ lint = { features = ["lint"], no-default-feature = true }
82
+ build = { features = ["build"], no-default-feature = true }
83
+ test-py312 = ["test", "io", "py312"]
84
+ test-py313 = ["test", "io", "py313"]
85
+ test-py314 = ["test", "io", "py314"]
86
+
87
+ [tool.pixi.dependencies]
88
+ simbio = { path = "." }
89
+
90
+ [tool.pixi.pypi-dependencies]
91
+ biomodels = "*"
92
+ python-libsbml = "*"
93
+
94
+ [tool.pixi.feature.lint.dependencies]
95
+ pre-commit = "*"
96
+ pre-commit-hooks = "*"
97
+ taplo = "*"
98
+ ruff = "*"
99
+ mdformat = "*"
100
+ mdformat-ruff = "*"
101
+ pyright = "*"
102
+
103
+ [tool.pixi.feature.lint.tasks]
104
+ pre-commit-install = "pre-commit install"
105
+ lint = "pre-commit run"
106
+
107
+ [tool.pixi.feature.build.dependencies]
108
+ uv = "*"
109
+ python = "*"
110
+
111
+ [tool.pixi.feature.build.pypi-dependencies]
112
+ mdremotifier = "*"
113
+
114
+ [tool.pixi.feature.build.tasks]
115
+ build = { cmd = "uv build", depends-on = ["remotify"] }
116
+ publish = "uv publish"
117
+ remotify = { cmd = [
118
+ "mdremotifier",
119
+ "-i",
120
+ "README.md",
121
+ "-o",
122
+ "README.md",
123
+ "--url-prefix",
124
+ "https://github.com/dyscolab/simbio/blob/main",
125
+ "--img-url-prefix",
126
+ "https://raw.githubusercontent.com/dyscolab/simbio/refs/heads/main/",
127
+ ] }
128
+
129
+ [tool.pixi.feature.test.dependencies]
130
+ pytest = "*"
131
+ pooch = "*"
132
+
133
+ [tool.pixi.feature.test.tasks]
134
+ test = "pytest src/simbio/test_core.py src/simbio/reactions/test_reactions.py --doctest-modules"
135
+
136
+ [tool.pixi.feature]
137
+ py312.dependencies = { python = "3.12.*" }
138
+ py313.dependencies = { python = "3.13.*" }
139
+ py314.dependencies = { python = "3.14.*" }
@@ -0,0 +1,50 @@
1
+ from poincare import (
2
+ Constant,
3
+ Independent,
4
+ Parameter,
5
+ Simulator,
6
+ Variable,
7
+ assign,
8
+ initial,
9
+ )
10
+ from poincare.reactions import (
11
+ AbsoluteRateLaw,
12
+ MassAction,
13
+ RateLaw,
14
+ Reactant,
15
+ reaction_initial,
16
+ )
17
+
18
+ from .core import (
19
+ Compartment,
20
+ Species,
21
+ System,
22
+ amount,
23
+ concentration,
24
+ reaction_amount,
25
+ reaction_concentration,
26
+ )
27
+
28
+ __all__ = [
29
+ "Constant",
30
+ "Independent",
31
+ "assign",
32
+ ]
33
+ __all__ += [
34
+ "Compartment",
35
+ "System",
36
+ "Variable",
37
+ "Reactant",
38
+ "Species",
39
+ "Parameter",
40
+ "MassAction",
41
+ "RateLaw",
42
+ "AbsoluteRateLaw",
43
+ "initial",
44
+ "amount",
45
+ "concentration",
46
+ "reaction_initial",
47
+ "reaction_concentration",
48
+ "reaction_amount",
49
+ "Simulator",
50
+ ]
@@ -0,0 +1,163 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import (
4
+ TYPE_CHECKING,
5
+ Any,
6
+ )
7
+
8
+ from poincare import (
9
+ Derivative,
10
+ Variable,
11
+ )
12
+ from poincare._node import Node, NodeMapper
13
+ from poincare.reactions import (
14
+ Reactant,
15
+ )
16
+ from poincare.reactions.reactions import (
17
+ compensate_volume,
18
+ make_concentration,
19
+ )
20
+ from poincare.types import (
21
+ Initial,
22
+ System,
23
+ )
24
+ from symbolite import Real, substitute
25
+
26
+ if TYPE_CHECKING:
27
+ pass
28
+
29
+
30
+ def is_instance_or_subclass(obj: Any, cls: type):
31
+ try:
32
+ return issubclass(obj, cls) or isinstance(obj, cls)
33
+ except TypeError:
34
+ return isinstance(obj, cls)
35
+
36
+
37
+ def first_system_parent(obj: Node | None) -> System | type[System] | None:
38
+ if isinstance(obj, Node):
39
+ parent = getattr(obj, "parent", None)
40
+ if is_instance_or_subclass(parent, System):
41
+ return parent
42
+ else:
43
+ return first_system_parent(parent)
44
+ else:
45
+ return None
46
+
47
+
48
+ def concentration(*, default: Initial | None = None):
49
+ return Species(initial=default, concentration=True)
50
+
51
+
52
+ def amount(*, default: Initial | None = None):
53
+ return Species(initial=default, concentration=False)
54
+
55
+
56
+ def reaction_concentration(*, default: Initial | None = None):
57
+ return Reactant(
58
+ variable=Species(initial=default, concentration=True), stoichiometry=1
59
+ )
60
+
61
+
62
+ def reaction_amount(*, default: Initial | None = None):
63
+ return Reactant(
64
+ variable=Species(initial=default, concentration=False), stoichiometry=1
65
+ )
66
+
67
+
68
+ def volume(*, default: Initial | None = None):
69
+ return Volume(initial=default)
70
+
71
+
72
+ class Species(Variable):
73
+ def __init__(self, *, initial: Initial, concentration: bool):
74
+ self.concentration = concentration
75
+ super().__init__(initial=initial)
76
+
77
+ def _copy_from(self, parent: Node):
78
+ mapper = NodeMapper(parent)
79
+ copy = self.__class__(
80
+ initial=substitute(self.initial, mapper), concentration=self.concentration
81
+ )
82
+ for order, der in self.derivatives.items():
83
+ copy.derivatives[order] = Derivative(
84
+ copy, initial=substitute(der.initial, mapper), order=order
85
+ )
86
+ copy.equation_order = self.equation_order
87
+ return copy
88
+
89
+
90
+ @compensate_volume.register
91
+ def compensate_volume_Species(
92
+ species: Species, rhs: Real | Initial, reaction_is_concentration: bool
93
+ ) -> Real | Initial:
94
+ system_parent = first_system_parent(species)
95
+ if is_instance_or_subclass(system_parent, Compartment):
96
+ if species.concentration and not reaction_is_concentration:
97
+ return rhs / system_parent._simbio_volume
98
+ elif not species.concentration and reaction_is_concentration:
99
+ return rhs * system_parent._simbio_volume
100
+ else:
101
+ return rhs
102
+ else:
103
+ return rhs
104
+
105
+
106
+ @make_concentration.register
107
+ def make_concentration_Species(species: Species) -> Real | Initial:
108
+ system_parent = first_system_parent(species)
109
+ if not species.concentration and (
110
+ is_instance_or_subclass(system_parent, Compartment)
111
+ ):
112
+ try:
113
+ return species / system_parent._simbio_volume
114
+ except AttributeError as err:
115
+ if not hasattr(system_parent, "_simbio_volume"):
116
+ raise AttributeError("Compartments must have a Volume")
117
+ else:
118
+ raise err
119
+ else:
120
+ return species
121
+
122
+
123
+ # def verify_species_units(initial):
124
+ # if isinstance(initial, pint.Quantity):
125
+ # if (
126
+ # initial.dimensionality == concetration_dim
127
+ # or initial.dimensionality == substance_dim
128
+ # ):
129
+ # return
130
+ # else:
131
+ # raise TypeError(
132
+ # f"Species must have concentration or substance dimensionality"
133
+ # )
134
+ # else:
135
+ # raise TypeError(
136
+ # f"Species does not have units, must have units of substance or concentration"
137
+ # )
138
+
139
+
140
+ class Volume(Variable):
141
+ def __set_name__(self, cls: Node, name: str):
142
+ super().__set_name__(cls, name)
143
+ if cls is not None:
144
+ setattr(cls, "_simbio_volume", self)
145
+
146
+
147
+ class Compartment(System, abstract=True):
148
+ def __init_subclass__(cls, **kwargs) -> None:
149
+ volumes = set(cls._yield(Volume, recursive=False))
150
+ if len(volumes) == 0:
151
+ raise AttributeError("Compartments must have a Volume")
152
+ elif len(volumes) > 1:
153
+ raise AttributeError("Compartments can only have one Volume")
154
+ super().__init_subclass__(**kwargs)
155
+
156
+ def __init__(self, *args, **kwargs):
157
+ for key, value in kwargs.items():
158
+ if isinstance(getattr(self.__class__, key, None), Species | Volume):
159
+ if isinstance(value, Node):
160
+ raise TypeError(
161
+ "Compartment Species and Volume cannot be linked to external variables, only initials can be passed on instantiation"
162
+ )
163
+ super().__init__(*args, **kwargs)
@@ -0,0 +1,46 @@
1
+ from typing import assert_never
2
+
3
+ from networkx import DiGraph, Graph, bipartite
4
+
5
+ from ...core import Compartment, RateLaw, Species
6
+
7
+
8
+ def graph(model: type[Compartment], /) -> DiGraph:
9
+ """Construct a directed bipartite graph of Species and Reactions."""
10
+ g = DiGraph()
11
+ for x in model._yield(Species | RateLaw): # type: ignore
12
+ match x:
13
+ case Species():
14
+ g.add_node(x)
15
+ case RateLaw():
16
+ name = str(x)
17
+ g.add_node(name, reaction=x)
18
+ for r in x.reactants:
19
+ g.add_edge(r.variable, name, stoichiometry=r.stoichiometry)
20
+ for p in x.products:
21
+ g.add_edge(name, p.variable, stoichiometry=p.stoichiometry)
22
+ case _:
23
+ assert_never(x)
24
+ return g
25
+
26
+
27
+ def to_species_graph(graph: DiGraph, /) -> Graph:
28
+ """Project a bipartite graph into the Species graph.
29
+
30
+ Two Species are connected if they take part in the same Reaction.
31
+ """
32
+ return bipartite.projected_graph(
33
+ graph,
34
+ nodes=[n for n in graph if isinstance(n, Species)],
35
+ )
36
+
37
+
38
+ def to_reaction_graph(graph: DiGraph, /) -> Graph:
39
+ """Project a bipartite graph into the Reaction graph.
40
+
41
+ Two Reactions are connected if they share a common Species.
42
+ """
43
+ return bipartite.projected_graph(
44
+ graph,
45
+ nodes=[n for n in graph if not isinstance(n, Species)],
46
+ )