Skip to content

Commit a64d86f

Browse files
add toy pharma model, extends docs
1 parent d303952 commit a64d86f

File tree

3 files changed

+97
-4
lines changed

3 files changed

+97
-4
lines changed

docs/assets/toy_pharma.png

56.7 KB
Loading

docs/src/index.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,27 @@
55
@ReactionNetwork
66
```
77

8-
## Update model objects
8+
## Modify a model
9+
10+
We list common transition attributes:
11+
12+
| attribute | interpretation |
13+
| :----- | :----- |
14+
| `transPriority` | priority of a transition (influences resource allocation) |
15+
| `transProbOfSuccess` | probability that a transition terminates successfully |
16+
| `transCapacity` | maximum number of concurrent instances of the transition |
17+
| `transCycleTime` | duration of a transition's instance (adjusted by resource allocation) |
18+
| `transMaxLifeTime` | maximal duration of a transition's instance |
19+
| `transPostAction` | action to be executed once a transition's instance terminates |
20+
| `transName` | name of a transition |
21+
22+
We list common species attributes:
23+
24+
| attribute | interpretation |
25+
| :----- | :----- |
26+
| `specInitUncertainty` | uncertainty about variable's initial state (modelled as Gaussian standard deviation) |
27+
| `specInitVal` | initial value of a variable |
28+
929
```@docs
1030
@add_species
1131
@aka

readme.md

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<img src="docs/assets/diagram1.png" alt="wiring diagram"> <br>
55
<a href="#about">About</a> |
66
<a href="#context-dynamics-of-value-evolution-dyve">Context</a> |
7-
<a href="#three-sketches">Three Sketches</a> |
7+
<a href="#four-sketches">Four Sketches</a> |
88
<a href="https://merck.github.io/ReactiveDynamics.jl">Documentation</a>
99
</p>
1010

@@ -28,7 +28,9 @@ In particular, a resource can be allocated to an instance either for the instanc
2828

2929
<img src="docs/assets/diagram3.png" align="left" alt="attributes diagram"></a>
3030

31-
The transitions are <b>parametric</b>. That is, it is possible to set the period over which an instance of a transition acts in the system (as well as the maximal period of this action), the total number of transition's instances allowed to exist in the system, etc. An annotated transition takes the form `rate, a*A + b*B + ... --> c*C + ..., prm => val, ...`, where the numerical values can be given by a function which depends on the system's state. Internally, the reaction network is represented as an <a href=https://algebraicjulia.github.io/Catlab.jl/dev/generated/wiring_diagrams/wd_cset/><b>attributed C-set</b></a>.
31+
The transitions are <b>parametric</b>. That is, it is possible to set the period over which an instance of a transition acts in the system (as well as the maximal period of this action), the total number of transition's instances allowed to exist in the system, etc. An annotated transition takes the form `rate, a*A + b*B + ... --> c*C + ..., prm => val, ...`, where the numerical values can be given by a function which depends on the system's state. Internally, the reaction network is represented as an <a href=https://algebraicjulia.github.io/Catlab.jl/dev/generated/wiring_diagrams/wd_cset/><b>attributed C-set</b></a>.
32+
33+
For an overview of accepted attributes for both transitions and species classes, read the [docs](https://merck.github.io/ReactiveDynamics.jl/#Update-model-objects)
3234

3335
A network's dynamics is specified using a compact **modeling metalanguage**. Moreover, we have integrated another expression comprehension metalanguage which makes it easy to generate arbitrarily complex dynamics from a single template transition!
3436

@@ -48,7 +50,7 @@ This includes **[GeneratedExpressions.jl](https://github.com/Merck/GeneratedExpr
4850

4951
Another package is **[AlgebraicAgents.jl](https://github.com/Merck/AlgebraicAgents.jl)**, a lightweight package to enable hierarchical, heterogeneous dynamical systems co-integration. It implements a highly scalable, fully customizable interface featuring sums and compositions of dynamical systems. In present context, we note it can be used to co-integrate a reaction network problem with, e.g., a stochastic ordinary differential problem!
5052

51-
## Three Sketches
53+
## Four Sketches
5254

5355
For other examples, see the **[tutorials](tutorial)**.
5456

@@ -105,6 +107,77 @@ sol = @solve prob trajectories=20
105107

106108
![sir plots](docs/assets/sir_plot.png)
107109

110+
### A Primer on Attributed Transitions
111+
112+
Before we move on to more intricate examples demonstrating generative capabilities of the package, let's sketch a toy pharma model with as little as three transitions.
113+
114+
```julia
115+
toy_pharma_model = @ReactionNetwork
116+
```
117+
118+
First, a **"discovery" transition** will take a team of scientist and a portion of a company's budget at the input (say, for experimental resources), and it will **output candidate compounds**.
119+
120+
```julia
121+
@push toy_pharma_model α(candidate_compound, marketed_drug, κ) 3*@conserved(scientist) + @rate(budget) --> candidate_compound name=>discovery probability=>.3 cycletime=>6 priority=>.5
122+
```
123+
124+
Note that per a time unit, `α(candidate_compound, marketed_drug, κ)` "discovery" projects will be started. We provide a name of the class of transitions (`name=>discovery`), set up a probability of the transition terminating successfully (`probability=>.3`), a cycle time (`cycletime=>6`), and we provide a weight of the transitions' class for use in resource allocation (`priority=>.5`).
125+
126+
Moreover, we annotate "scientists" as a conserved resource (no matter how the project terminates, the workforce isn't consumed), i.e., `@conserved(scientist)`, and we state that a unit "budget" is consumed per a time unit, i.e., `@rate(budget)`.
127+
128+
Next, **candidate compounds will undergo clinical trials**. If successful, a compound transforms into a marketed drug, and the company receives a premium.
129+
130+
```julia
131+
@push toy_pharma_model β(candidate_compound, marketed_drug) candidate_compound + 5*@conserved(scientist) + 2*@rate(budget) --> marketed_drug + 5*budget name=>dx2market probability=>.5+.001*@t() cycletime=>4
132+
```
133+
134+
Note that as time evolves, the probability of technical success increases, i.e., `probability=>.5+.001*@t()`.
135+
136+
In addition, **marketed drugs bring profit to the company** - which will fuel invention of new drugs.
137+
138+
We model the situation as a periodic callback.
139+
140+
```julia
141+
@periodic toy_pharma_model 1. budget += 11*marketed_drug
142+
```
143+
144+
A **marketed drug may eventually be withdrawn** from the market. To account for such scenario, we add the following transition:
145+
146+
```julia
147+
@push toy_pharma_model γ*marketed_drug marketed_drug --> ∅ name=>drug_withdrawn
148+
```
149+
150+
Next we provide the functions `α` and `β`.
151+
152+
```julia
153+
@register α(number_candidate_compounds, number_marketed_drugs, κ) = κ + exp(-number_candidate_compounds) + exp(-number_marketed_drugs)
154+
@register β(number_candidate_compounds, number_marketed_drugs) = numbercandidate_compounds + exp(-number_marketed_drugs)
155+
```
156+
157+
Likewise, we set the remaining parameters, initial values, and model metadata:
158+
159+
```julia
160+
161+
# simulation parameters
162+
## initial values
163+
@prob_init toy_pharma_model candidate_compound=5 marketed_drug=6 scientist=20 budget=100
164+
## parameters
165+
@prob_params toy_pharma_model κ=4 γ=.1
166+
## other arguments passed to the solver
167+
@prob_meta toy_pharma_model tspan=250 dt=.1
168+
```
169+
170+
And we problematize the model, solve the problem, and plot the solution:
171+
172+
```julia
173+
prob = @problematize toy_pharma_model
174+
sol = @solve prob trajectories=20
175+
@plot sol plot_type=summary show=[:candidate_compound, :marketed_drug]
176+
```
177+
178+
![plot](docs/assets/toy_pharma.png)
179+
180+
108181
### Sparse Interactions
109182

110183
We introduce a complex reaction network as a union of $n_{\text{models}}$ reaction networks, where the off-diagonal interactions are sparse.

0 commit comments

Comments
 (0)