$npx -y skills add matlab/matlab-agentic-toolkit --skill matlab-simulate-simbiology-modelSimulate SimBiology models — ODE, stochastic (SSA), scenarios, and sensitivity analysis. Use when asked to run, simulate, predict, explore what-if, or identify influential parameters.
| 1 | # Simulate SimBiology Models |
| 2 | |
| 3 | Run simulations of SimBiology models: deterministic ODE, stochastic SSA, |
| 4 | scenario exploration, and sensitivity analysis. |
| 5 | |
| 6 | ## When to Use |
| 7 | |
| 8 | - "simulate", "run", "predict" model behavior |
| 9 | - "what if" / "what happens if" (implies simulation or scenarios) |
| 10 | - Time-course results from a model |
| 11 | - Dose-response studies, parameter sweeps, factorial designs |
| 12 | - Stochastic, SSA, Gillespie, noise, gene expression variability |
| 13 | - "which parameters matter most", sensitivity, Sobol, Morris |
| 14 | - Keywords: "simulate", "run", "predict", "what-if", "stochastic", "sensitivity" |
| 15 | |
| 16 | ## When NOT to Use |
| 17 | |
| 18 | - Model construction or diagram layout (use `matlab-build-simbiology-model`) |
| 19 | - Parameter estimation from data (use `matlab-fit-simbiology-model`) |
| 20 | - NCA / AUC / Cmax from data (use `matlab-fit-simbiology-model`) |
| 21 | |
| 22 | ## Must-Follow Rules |
| 23 | |
| 24 | ### 0. Add helper scripts to the MATLAB path first |
| 25 | |
| 26 | Run at the start of every session: |
| 27 | ```matlab |
| 28 | addpath(fullfile('<WORKSPACE_ROOT>', '.claude', 'skills', 'matlab-simulate-simbiology-model', 'scripts')); |
| 29 | ``` |
| 30 | |
| 31 | ### 1. Element-wise operators in observables |
| 32 | |
| 33 | Use `./` and `.*` (element-wise) in observable expressions when mixing |
| 34 | time-varying species with constant parameters. Plain `/` and `*` cause |
| 35 | size mismatches at simulation time. |
| 36 | |
| 37 | ### 2. StatesToLog for constant parameters |
| 38 | |
| 39 | When observables reference constant parameters (e.g., `Drug ./ Vd`), |
| 40 | add those parameters explicitly to `StatesToLog`: |
| 41 | ```matlab |
| 42 | cs.RuntimeOptions.StatesToLog = [m.Species; sbioselect(m,'Type','parameter','Name','Vd')]; |
| 43 | ``` |
| 44 | `StatesToLog = 'all'` does **not** log constant compartments or parameters. |
| 45 | |
| 46 | ### 3. All reactions must be MassAction for SSA |
| 47 | |
| 48 | The stochastic solver does not support custom rate expressions. Every |
| 49 | reaction must use `addkineticlaw(rx, 'MassAction')`. |
| 50 | |
| 51 | ### 4. Do NOT combine Scenarios with `+` |
| 52 | |
| 53 | The `+` operator is not supported on `SimBiology.Scenarios` objects. |
| 54 | Always use `add()` to append entries. |
| 55 | |
| 56 | ### 5. Reset local sensitivity options after use |
| 57 | |
| 58 | Local sensitivity settings persist on the configset and affect |
| 59 | subsequent simulations. Always reset: |
| 60 | ```matlab |
| 61 | cs.SolverOptions.SensitivityAnalysis = false; |
| 62 | cs.SensitivityAnalysisOptions.Inputs = []; |
| 63 | cs.SensitivityAnalysisOptions.Outputs = []; |
| 64 | ``` |
| 65 | |
| 66 | ### 6. Set `MaximumWallClock` to prevent hung simulations |
| 67 | |
| 68 | When fitting or scanning, bad parameter values can make individual |
| 69 | simulations extremely slow. Protect against this: |
| 70 | ```matlab |
| 71 | cs.MaximumWallClock = 60; % seconds; default is Inf |
| 72 | ``` |
| 73 | This is a **configset** property (not a solver or optimizer option). |
| 74 | It stops any single simulation that exceeds the wall clock limit. |
| 75 | |
| 76 | ### 7. Unit conversion requires `TimeUnits` |
| 77 | |
| 78 | When `cs.CompileOptions.UnitConversion = true`, you MUST also set |
| 79 | `cs.TimeUnits` to match your StopTime units (e.g., `'hour'`). |
| 80 | Otherwise SimBiology defaults to seconds and your 24-unit simulation |
| 81 | covers 24 seconds, not 24 hours: |
| 82 | ```matlab |
| 83 | cs.CompileOptions.UnitConversion = true; |
| 84 | cs.TimeUnits = 'hour'; |
| 85 | cs.StopTime = 24; % now correctly 24 hours |
| 86 | ``` |
| 87 | |
| 88 | ### 8. Scenario results are interleaved, not blocked |
| 89 | |
| 90 | Factorial scenario results come back interleaved by the first dimension. |
| 91 | Always use `generate(sc)` to map result indices to conditions — never |
| 92 | assume all entries of one factor appear consecutively. |
| 93 | |
| 94 | ## Decision Table |
| 95 | |
| 96 | | Scenario | Approach | |
| 97 | |----------|----------| |
| 98 | | One-off simulation | `sbiosimulate` | |
| 99 | | Parameter sweep / Monte Carlo | `createSimFunction` | |
| 100 | | Dose/variant/parameter what-if | `SimBiology.Scenarios` + `createSimFunction` | |
| 101 | | Low molecule count / noise | SSA solver (`cs.SolverType = 'ssa'`) | |
| 102 | | Which parameters matter? | `sbiosobol` (Sobol) or `sbioelementaryeffects` (Morris) | |
| 103 | | Quick sensitivity check | Local sensitivity via configset | |
| 104 | |
| 105 | ## Basic Simulation (`sbiosimulate`) |
| 106 | |
| 107 | Prefer returning **SimData** (single output) — it carries state names, |
| 108 | units, and metadata, and works directly with `sbioplot` and `selectbyname`: |
| 109 | |
| 110 | ```matlab |
| 111 | m = getModelByUUID(modelId); |
| 112 | cs = getconfigset(m, 'active'); |
| 113 | cs.StopTime = 24; |
| 114 | cs.SolverType = 'ode15s'; |
| 115 | simData = sbiosimulate(m); |
| 116 | ``` |
| 117 | |
| 118 | With a dose (configset is **required** as 2nd argument when passing doses): |
| 119 | ```matlab |
| 120 | d = sbiodose('Bolus', 'schedule'); |
| 121 | d.TargetName = 'Drug'; d.Amount = 100; d.Time = 0; |
| 122 | simData = sbiosimulate(m, cs, d); % NOT sbiosimulate(m, d) — errors |
| 123 | ``` |
| 124 | |
| 125 | ## Plotting Results |
| 126 | |
| 127 | Use `sbioplot` for quick visualization of SimData: |
| 128 | ```matlab |
| 129 | simData = sbiosimulate(m, cs, d); |
| 130 | sbioplot(simData); |
| 131 | ``` |
| 132 | |
| 133 | For custom plots, extract numeric data first: |
| 134 | ```matlab |
| 135 | [t, x, names] = getdata(simData); |
| 136 | plot(t, x); |
| 137 | legend(names, 'Interpreter', 'none'); |
| 138 | xlabel('Time'); ylabel('Amount'); |
| 139 | ``` |
| 140 | |
| 141 | ## Extracting State Data from SimData |
| 142 | |
| 143 | Use |