Simbiology Simulate Model
MathWorksOfficialCreated by MathWorks
- Skill
- Tool integration
- Science and research
- BSD-2-Clause
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a comprehensive framework for running simulations on SimBiology models. It supports deterministic ODE solvers, stochastic SSA solvers for low-molecule systems, and various sensitivity analysis methods like Sobol and Morris screening. It includes guidance on handling scenarios for parameter sweeps, dose-response studies, and virtual population generation, ensuring users can effectively predict model behavior and identify influential parameters.
What it does
- Executes deterministic ODE and stochastic SSA simulations.
- Performs sensitivity analysis using Sobol, Morris, and local methods.
- Manages complex scenario exploration including dose-response and factorial designs.
- Provides tools for accelerating repeated simulations.
- Facilitates visualization of simulation results and state data extraction.
- Supports virtual population generation via probability distributions.
When to use it
- When you need to predict model behavior or time-course results.
- When exploring 'what-if' scenarios involving doses or parameter variations.
- When analyzing systems with low molecule counts requiring stochastic solvers.
- When identifying which parameters most influence model outputs.
- When performing parameter sweeps or Monte Carlo simulations.
Advantages
- Provides a unified interface for diverse simulation types.
- Includes performance optimization via model acceleration.
- Supports robust sensitivity analysis for model validation.
- Enables systematic exploration of parameter spaces through scenarios.
- Offers clear guidance on solver selection and configuration.
Usage examples
- “Run a 24-hour simulation on my model and plot the results.”
- The agent configures the active configset, sets the stop time, executes sbiosimulate, and generates a plot using sbioplot.
- “Perform a Sobol sensitivity analysis on parameters ke and ka.”
- The agent executes sbiosobol with specified bounds and samples, then reports the first-order and total-order indices.
- “Run a stochastic simulation for 100 seconds.”
- The agent sets the solver to 'ssa', configures the stop time, runs the simulation, and extracts the resulting data.
- “Create a parameter sweep for ke values 0.05, 0.1, and 0.2.”
- The agent initializes a SimBiology.Scenarios object, adds the parameter sweep, creates a simulation function, and executes the scenarios.
Install
1 of its files are not mirrored here, so install it from its source:
https://github.com/matlab/matlab-agentic-toolkit/tree/2a7f215e965597acf6ed495beb9e7b8aff45a3be/skills-catalog/computational-biology/simbiology-simulate-model
Documentation by MathWorks
Simulate SimBiology Models
Run simulations of SimBiology models: deterministic ODE, stochastic SSA, scenario exploration, and sensitivity analysis.
When to Use
"simulate", "run", "predict" model behavior
"what if" / "what happens if" (implies simulation or scenarios)
Time-course results from a model
Dose-response studies, parameter sweeps, factorial designs
Stochastic, SSA, Gillespie, noise, gene expression variability
"which parameters matter most", sensitivity, Sobol, Morris
Keywords: "simulate", "run", "predict", "what-if", "stochastic", "sensitivity"
When NOT to Use
Model construction or diagram layout (use
simbiology-build-model)Parameter estimation from data (use
simbiology-fit-model)NCA / AUC / Cmax from data (use
simbiology-fit-model)
Must-Follow Rules
0. Add helper scripts to the MATLAB path first
Run at the start of every session:
addpath(fullfile('<WORKSPACE_ROOT>', '.claude', 'skills', 'simbiology-simulate-model', 'scripts'));1. Element-wise operators in observables
Use ./ and .* (element-wise) in observable expressions when mixing
time-varying species with constant parameters. Plain / and * cause
size mismatches at simulation time.
2. StatesToLog for constant parameters
When observables reference constant parameters (e.g., Drug ./ Vd),
add those parameters explicitly to StatesToLog:
cs.RuntimeOptions.StatesToLog = [m.Species; sbioselect(m,'Type','parameter','Name','Vd')];StatesToLog = 'all' does not log constant compartments or parameters.
3. All reactions must be MassAction for SSA
The stochastic solver does not support custom rate expressions. Every
reaction must use addkineticlaw(rx, 'MassAction').
4. Do NOT combine Scenarios with +
The + operator is not supported on SimBiology.Scenarios objects.
Always use add() to append entries.
5. Reset local sensitivity options after use
Local sensitivity settings persist on the configset and affect subsequent simulations. Always reset:
cs.SolverOptions.SensitivityAnalysis = false;
cs.SensitivityAnalysisOptions.Inputs = [];
cs.SensitivityAnalysisOptions.Outputs = [];6. Set MaximumWallClock to prevent hung simulations
When fitting or scanning, bad parameter values can make individual simulations extremely slow. Protect against this:
cs.MaximumWallClock = 60; % seconds; default is InfThis is a configset property (not a solver or optimizer option). It stops any single simulation that exceeds the wall clock limit.
7. Unit conversion requires TimeUnits
When cs.CompileOptions.UnitConversion = true, you MUST also set
cs.TimeUnits to match your StopTime units (e.g., 'hour').
Otherwise SimBiology defaults to seconds and your 24-unit simulation
covers 24 seconds, not 24 hours:
cs.CompileOptions.UnitConversion = true;
cs.TimeUnits = 'hour';
cs.StopTime = 24; % now correctly 24 hours8. Scenario results are interleaved, not blocked
Factorial scenario results come back interleaved by the first dimension.
Always use generate(sc) to map result indices to conditions — never
assume all entries of one factor appear consecutively.
Decision Table
| Scenario | Approach |
|---|---|
| One-off simulation | sbiosimulate |
| Parameter sweep / Monte Carlo | createSimFunction |
| Dose/variant/parameter what-if | SimBiology.Scenarios + createSimFunction |
| Low molecule count / noise | SSA solver (cs.SolverType = 'ssa') |
| Which parameters matter? | sbiosobol (Sobol) or sbioelementaryeffects (Morris) |
| Quick sensitivity check | Local sensitivity via configset |
Basic Simulation (sbiosimulate)
Prefer returning SimData (single output) — it carries state names,
units, and metadata, and works directly with sbioplot and selectbyname:
m = getModelByUUID(modelId);
cs = getconfigset(m, 'active');
cs.StopTime = 24;
cs.SolverType = 'ode15s';
simData = sbiosimulate(m);With a dose (configset is required as 2nd argument when passing doses):
d = sbiodose('Bolus', 'schedule');
d.TargetName = 'Drug'; d.Amount = 100; d.Time = 0;
simData = sbiosimulate(m, cs, d); % NOT sbiosimulate(m, d) — errorsPlotting Results
Use sbioplot for quick visualization of SimData:
simData = sbiosimulate(m, cs, d);
sbioplot(simData);For custom plots, extract numeric data first:
[t, x, names] = getdata(simData);
plot(t, x);
legend(names, 'Interpreter', 'none');
xlabel('Time'); ylabel('Amount');Extracting State Data from SimData
Use selectbyname to extract specific states. It returns a SimData
object, not a numeric array — extract numeric data before doing math:
simData = sbiosimulate(m, cs, d);
result = selectbyname(simData, 'Central.Drug'); % returns SimData, NOT double
drugData = result.Data; % numeric column vector
drugTime = result.Time; % time column vectorOr use getdata() to get arrays:
[t, x, names] = getdata(selectbyname(simData, 'Central.Drug'));For quick numeric access to all states without SimData, use the three-output form:
[t, x, names] = sbiosimulate(m, cs, d); % t, x are double arrays directlyAcceleration (sbioaccelerate)
For repeated sbiosimulate calls on the same model, accelerate once first:
sbioaccelerate(m);
simData = sbiosimulate(m); % fasterRules:
Call only right before
sbiosimulate— not before fitting or analysis functionsValid after changing parameter/species values (e.g.,
p.Value = 0.2)Invalidated by structural changes (adding reactions, species, compartments) — must re-accelerate
Do NOT use with
createSimFunction, Scenarios, sensitivity, or fitting — these handle acceleration internally viaAutoAccelerate
Repeated Simulation (createSimFunction)
% Signature: createSimFunction(model, params, observables, dosedSpecies)
simfun = createSimFunction(model, {'ke','ka'}, {'Drug'}, []);
r1 = simfun([0.1, 0.5], 24); % single run
r2 = simfun([0.1, 0.5; 0.3, 1.0], 24); % multiple parameter sets (rows)
[t, x] = r1.getdata();Compiles once, runs many — much faster than
sbiosimulatein a loopException: SSA (stochastic) requires
sbiosimulatein a loop because each run needs fresh random state;createSimFunctiondoes not support stochastic solversCompatible with
parfor(Parallel Computing Toolbox)Returns
SimDataobjects; use.getdata()to extract arrays
SimFunction with doses
The 4th argument to createSimFunction declares which species receive
doses. When executing, pass doses as a table (NOT a dose object):
% Create: specify dosed species names in 4th argument
simfun = createSimFunction(model, {'ke'}, {'Drug'}, {'Drug'});
% Execute: pass dose as a table with Time and Amount columns
doseTable = table(0, 100, 'VariableNames', {'Time', 'Amount'});
result = simfun(0.1, 24, doseTable);
% Multiple dose events
multiDose = table([0; 12], [100; 50], 'VariableNames', {'Time', 'Amount'});
result = simfun(0.1, 24, multiDose);
% Multiple dosed species: cell array of tables (one per species, same order)
simfun2 = createSimFunction(model, {'ke'}, {'Drug','Drug2'}, {'Drug','Drug2'});
doses = {doseTable1, doseTable2};
result = simfun2(0.1, 24, doses);Common mistake: passing a sbiodose object to a SimFunction — this
errors. Always convert to a table with Time and Amount columns.
Scenarios (SimBiology.Scenarios)
Systematically explore combinations of doses, variants, and parameters.
add() signature (argument order is critical)
add(sc, combination, name, values, ...)
% ^^^^^^^^^^^^^
% MUST be 2nd argument: 'cartesian' or 'elementwise'The combination type ('cartesian' or 'elementwise') is always the
second argument to add(). Putting it elsewhere errors.
Dose sweep
d1 = sbiodose('Low','schedule'); d1.TargetName = 'Drug'; d1.Amount = 50; d1.Time = 0;
d2 = sbiodose('High','schedule'); d2.TargetName = 'Drug'; d2.Amount = 200; d2.Time = 0;
sc = SimBiology.Scenarios('DoseLevel', [d1, d2]);Full factorial (dose x parameter)
sc = SimBiology.Scenarios('DoseLevel', [d1, d2]);
add(sc, 'cartesian', 'ke', [0.05 0.1 0.2]); % 2 x 3 = 6 combinations
simfun = createSimFunction(model, sc, {'Drug'}, []);
results = simfun(sc, 24);Parameter sweep with dosed SimFunction
sc = SimBiology.Scenarios('ke', [0.05 0.1 0.2]);
simfun = createSimFunction(model, sc, {'Drug'}, {'Drug'});
doseTable = table(0, 100, 'VariableNames', {'Time', 'Amount'});
results = simfun(sc, 24, doseTable); % dose table as 3rd argumentResult ordering (critical)
Scenario results are interleaved by the first dimension, not blocked. For a 2-dose × 3-ke factorial, results come back as:
results(1): Dose1, ke1
results(2): Dose2, ke1
results(3): Dose1, ke2
results(4): Dose2, ke2
results(5): Dose1, ke3
results(6): Dose2, ke3Use generate(sc) to get a table mapping each result index to its conditions:
genTable = generate(sc); % table with one row per scenario
for i = 1:numel(results)
[t, x] = results(i).getdata();
fprintf('Dose=%s, ke=%.2f: Drug at t=end = %.2f\n', ...
genTable.DoseLevel(i).Name, genTable.ke(i), x(end,1));
endNever assume blocked ordering (all of Dose1 first, then all of Dose2).
Always use generate(sc) to map results to conditions.
Entry types
| Content Type | Example |
|---|---|
| Dose vector | SimBiology.Scenarios('DoseLevel', [d1, d2]) |
| Variant vector | SimBiology.Scenarios('Pop', [v1, v2]) |
| Parameter values | SimBiology.Scenarios('ke', [0.05 0.1 0.2]) |
| Species values | SimBiology.Scenarios('Drug', [50 100 200]) |
| Probability distribution | add(sc, 'elementwise', 'ke', makedist('Lognormal',...), 'Number', 50) |
Virtual population via distribution sampling
Scenarios can sample from probability distributions — use this for virtual patient simulations instead of manually generating parameter matrices:
pd = makedist('Lognormal', 'mu', log(0.1), 'sigma', 0.3);
sc = SimBiology.Scenarios;
add(sc, 'elementwise', 'ke', pd, 'Number', 50);
simfun = createSimFunction(model, sc, {'Drug'}, []);
results = simfun(sc, 24);Steady-state with repeat dosing
d = sbiodose('RepeatDose', 'repeat');
d.TargetName = 'Drug'; d.Amount = 100;
d.StartTime = 0; d.Interval = 12; d.RepeatCount = 50;
cs.StopTime = d.Interval * (d.RepeatCount + 1);
[t, x, names] = sbiosimulate(model, cs, d);Stochastic Simulation (SSA)
For low molecule count systems where continuous ODE breaks down.
Single trajectory
cs = getconfigset(model, 'active');
cs.SolverType = 'ssa';
cs.StopTime = 100;
simData = sbiosimulate(model);
[t, x, names] = getdata(simData);Ensemble (multiple trajectories)
nRuns = 200;
allResults = cell(nRuns, 1);
for i = 1:nRuns
allResults{i} = sbiosimulate(model);
endGene expression template (all MassAction)
model = sbiomodel('GeneExpr');
comp = addcompartment(model, 'cell');
addspecies(comp, 'Gene', 1);
addspecies(comp, 'mRNA', 0);
addspecies(comp, 'Protein', 0);
addparameter(model, 'k_txn', 0.1);
addparameter(model, 'k_tln', 0.5);
addparameter(model, 'k_mdeg', 0.05);
addparameter(model, 'k_pdeg', 0.01);
% Transcription: Gene -> Gene + mRNA (Gene is catalyst)
rx1 = addreaction(model, 'Gene -> Gene + mRNA');
kl1 = addkineticlaw(rx1, 'MassAction'); kl1.ParameterVariableNames = {'k_txn'};
% Translation: mRNA -> mRNA + Protein
rx2 = addreaction(model, 'mRNA -> mRNA + Protein');
kl2 = addkineticlaw(rx2, 'MassAction'); kl2.ParameterVariableNames = {'k_tln'};
% Degradation
rx3 = addreaction(model, 'mRNA -> null');
kl3 = addkineticlaw(rx3, 'MassAction'); kl3.ParameterVariableNames = {'k_mdeg'};
rx4 = addreaction(model, 'Protein -> null');
kl4 = addkineticlaw(rx4, 'MassAction'); kl4.ParameterVariableNames = {'k_pdeg'};After SSA, reset solver: cs.SolverType = 'ode15s';
Sensitivity Analysis
Sobol (global, quantitative)
bounds = [0.01 1; 0.1 5]; % [low high] per parameter
sobolResults = sbiosobol(m, {'ke','ka'}, {'Drug'}, ...
'OutputTimes', 0:1:24, 'NumberSamples', 500, 'Bounds', bounds);
plot(sobolResults);
% Extract indices from struct array
for i = 1:numel(sobolResults.SobolIndices)
Si = mean(sobolResults.SobolIndices(i).FirstOrder, 'omitnan');
STi = mean(sobolResults.SobolIndices(i).TotalOrder, 'omitnan');
fprintf('%s: Si=%.3f, STi=%.3f\n', sobolResults.SobolIndices(i).Parameter, Si, STi);
endFirst-order (Si): variance due to parameter alone
Total-order (STi): variance due to parameter + all interactions
Large gap STi - Si → strong interaction effects
Access via
sobolResults.SobolIndices(i).FirstOrder/.TotalOrder(struct array, one per parameter)
Morris screening (global, ranking)
bounds = [0.01 1; 0.1 5];
eeResults = sbioelementaryeffects(m, {'ke','ka'}, {'Drug'}, ...
'OutputTimes', 0:1:24, 'NumberSamples', 50, 'Bounds', bounds);High mean effect → influential parameter
High standard deviation → nonlinear or interaction effects
Local sensitivity
cs.SolverOptions.SensitivityAnalysis = true;
cs.SensitivityAnalysisOptions.Normalization = 'Full';
cs.SensitivityAnalysisOptions.Inputs = sbioselect(m,'Type','parameter','Name',{'ke','ka'});
cs.SensitivityAnalysisOptions.Outputs = sbioselect(m,'Type','species','Name','Drug');
simData = sbiosimulate(m);
[t, R] = getsensmatrix(simData);
% IMPORTANT: Reset after use
cs.SolverOptions.SensitivityAnalysis = false;
cs.SensitivityAnalysisOptions.Inputs = [];
cs.SensitivityAnalysisOptions.Outputs = [];| Normalization | Meaning |
|---|---|
'None' | Raw dY/dp |
'Half' | (p/y) dY/dp |
'Full' | Dimensionless; both sides normalized |
Conventions
Loading
.sbprojfiles:sbioloadprojectreturns a struct with the model name as field — extract dynamically:proj = sbioloadproject('file.sbproj'); fn = fieldnames(proj); model = proj.(fn{1});Pass model objects (not UUID strings) to simulation functions
Use
getModelByUUID(uuid)to recover handles (provided by this skill'sscripts/directory — add to path at session start)createSimFunctionreturnsSimData; extract with.getdata()Pass model directly to
sbiosobol/sbioelementaryeffects(not a SimFunction)Bounds matrix: one row per parameter, columns
[low high]
References
Load on demand for detailed guidance:
references/stochastic-simulation-guidance.md— ensemble plotting, distribution analysisreferences/sensitivity-analysis-guidance.md— full Sobol/Morris/Local patterns and interpretation
Copyright 2026 The MathWorks, Inc.
Files
- ATTRIBUTION.mdAdded by AutoGineer1.0 KiB
- LICENSELicence file added by AutoGineer1.4 KiB
- SKILL.md15.0 KiB
- manifest.yaml507 B
- references/sensitivity-analysis-guidance.md4.6 KiB
- references/stochastic-simulation-guidance.md3.2 KiB
- scripts/getModelByUUID.p(opens on GitHub)Not mirrored: opens on GitHub268 B
references/sensitivity-analysis-guidance.md
Sensitivity Analysis Guidance
Full patterns for Sobol, Morris, and local sensitivity analysis including interpretation, dispatch heuristics, and troubleshooting.
Method Selection
| Method | Function | Samples Needed | Best For |
|---|---|---|---|
| Sobol | sbiosobol | 500-1000 | Quantifying first-order and interaction effects |
| Morris | sbioelementaryeffects | 50-100 | Quick screening/ranking as a first pass |
| Local | configset SensitivityAnalysis | 1 sim | Quick check near current parameter values |
Dispatch heuristic:
< 5 parameters → Sobol directly
5-20 parameters → Morris first to screen, then Sobol on top parameters
20 parameters → Morris to narrow down, then Sobol on top 5-10
Sobol Analysis (Detailed)
m = getModelByUUID(modelId);
paramNames = {'ke', 'ka', 'Vd', 'k12', 'k21'};
bounds = [0.01 1; 0.1 5; 5 50; 0.01 1; 0.01 1]; % [low high] per param
sobolResults = sbiosobol(m, paramNames, {'Drug'}, ...
'OutputTimes', 0:1:24, ...
'NumberSamples', 500, ...
'Bounds', bounds);
% Plot built-in visualization
plot(sobolResults);Interpreting Sobol indices
First-order index (Si): fraction of output variance due to parameter i alone (main effect)
Total-order index (STi): fraction due to parameter i + all its interactions with other parameters
Interaction contribution: STi - Si (large means parameter has strong synergistic effects with others)
| Pattern | Interpretation |
|---|---|
| Si high, STi ≈ Si | Parameter is influential, mostly independently |
| Si low, STi high | Parameter is influential only via interactions |
| Si ≈ 0, STi ≈ 0 | Parameter can likely be fixed |
| Sum(Si) ≈ 1 | Additive model (no interactions) |
| Sum(Si) << 1 | Strong interaction effects present |
Accessing results programmatically
for i = 1:numel(sobolResults.SobolIndices)
si = sobolResults.SobolIndices(i);
fprintf('Parameter: %s\n', si.Parameter);
fprintf(' First-order (mean over time): %.3f\n', mean(si.FirstOrder, 'omitnan'));
fprintf(' Total-order (mean over time): %.3f\n', mean(si.TotalOrder, 'omitnan'));
endNote: Indices at t=0 may be NaN (zero output variance).
Morris Screening (Detailed)
bounds = [0.01 1; 0.1 5; 5 50];
eeResults = sbioelementaryeffects(m, {'ke','ka','Vd'}, {'Drug'}, ...
'OutputTimes', 0:1:24, ...
'NumberSamples', 50, ...
'Bounds', bounds);Interpreting Morris results
for i = 1:numel(eeResults.Results)
r = eeResults.Results(i);
fprintf('Parameter: %s\n', r.Parameter);
fprintf(' Mean effect: %.3f\n', mean(r.Mean, 'omitnan'));
fprintf(' Std deviation: %.3f\n', mean(r.StandardDeviation, 'omitnan'));
end| Mean Effect | Std Dev | Interpretation |
|---|---|---|
| High | Low | Linear, influential |
| High | High | Nonlinear or interacting, influential |
| Low | Low | Not influential (can fix) |
| Low | High | Nonlinear but weak overall effect |
Local Sensitivity (Detailed)
cs = getconfigset(m, 'active');
cs.SolverOptions.SensitivityAnalysis = true;
cs.SensitivityAnalysisOptions.Normalization = 'Full';
cs.SensitivityAnalysisOptions.Inputs = ...
sbioselect(m, 'Type', 'parameter', 'Name', {'ke','ka'});
cs.SensitivityAnalysisOptions.Outputs = ...
sbioselect(m, 'Type', 'species', 'Name', 'Drug');
simData = sbiosimulate(m);
[t, R] = getsensmatrix(simData);
% R is nTimepoints x nOutputs x nInputs
% Plot sensitivity of Drug to ke over time
figure;
plot(t, R(:,1,1));
xlabel('Time'); ylabel('Sensitivity (dDrug/dke, normalized)');
% IMPORTANT: Reset after use
cs.SolverOptions.SensitivityAnalysis = false;
cs.SensitivityAnalysisOptions.Inputs = [];
cs.SensitivityAnalysisOptions.Outputs = [];Normalization options
| Option | Formula | When to Use |
|---|---|---|
'None' | dY/dp | When absolute magnitudes matter |
'Half' | (p/Y) dY/dp | Fractional change in output per unit change in param |
'Full' | (p/Y)(dY/dp) | Dimensionless elasticity — comparable across parameters |
Troubleshooting
| Issue | Cause | Fix |
|---|---|---|
| NaN in Sobol indices at t=0 | Zero output variance at initial time | Normal — variance grows over time |
| All indices ≈ 0 | Bounds too narrow | Widen parameter bounds |
| Sum(STi) > 1 | Normal for total-order indices | This is expected; sum of Si <= 1 |
| Morris all same rank | Too few samples | Increase NumberSamples |
| Local sensitivity persists | Didn't reset configset | Reset after every local run |
Copyright 2026 The MathWorks, Inc.
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- MathWorks
- Publisher
- MathWorks (Official)
- Source
- matlab/matlab-agentic-toolkit · skills-catalog/computational-biology/simbiology-simulate-model · commit 2a7f215
- Licence
- BSD 2-Clause License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE.md)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by MathWorks or MathWorks.
Get it from the source
1 of this skill’s files are not mirrored here, so there is no ZIP. Get the complete skill from its source: matlab/matlab-agentic-toolkit