Skip to main content
ClaudeWave
EN, English
Skill1.2k repo starsupdated 6d ago

matlab-simulate-simbiology-model

This Claude Code skill simulates SimBiology models including deterministic ODE, stochastic SSA, scenario exploration, and sensitivity analysis. Use it when asked to run simulations, predict model behavior, perform what-if analyses, conduct parameter sweeps, or identify influential parameters through sensitivity methods like Sobol or Morris.

Install in Claude Code
Copy
git clone --depth 1 https://github.com/matlab/matlab-agentic-toolkit /tmp/matlab-simulate-simbiology-model && cp -r /tmp/matlab-simulate-simbiology-model/skills-catalog/computational-biology/matlab-simulate-simbiology-model ~/.claude/skills/matlab-simulate-simbiology-model
Then start a new Claude Code session; the skill loads automatically.

SKILL.md

# 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 `matlab-build-simbiology-model`)
- Parameter estimation from data (use `matlab-fit-simbiology-model`)
- NCA / AUC / Cmax from data (use `matlab-fit-simbiology-model`)

## Must-Follow Rules

### 0. Add helper scripts to the MATLAB path first

Run at the start of every session:
```matlab
addpath(fullfile('<WORKSPACE_ROOT>', '.claude', 'skills', 'matlab-simulate-simbiology-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`:
```matlab
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:
```matlab
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:
```matlab
cs.MaximumWallClock = 60;  % seconds; default is Inf
```
This 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:
```matlab
cs.CompileOptions.UnitConversion = true;
cs.TimeUnits = 'hour';
cs.StopTime = 24;  % now correctly 24 hours
```

### 8. 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`:

```matlab
m = getModelByUUID(modelId);
cs = getconfigset(m, 'active');
cs.StopTime = 24;
cs.SolverType = 'ode15s';
simData = sbiosimulate(m);
```

With a dose:
```matlab
d = sbiodose('Bolus', 'schedule');
d.TargetName = 'Drug'; d.Amount = 100; d.Time = 0;
simData = sbiosimulate(m, cs, d);
```

## Plotting Results

Use `sbioplot` for quick visualization of SimData:
```matlab
simData = sbiosimulate(m, cs, d);
sbioplot(simData);
```

For custom plots, extract numeric data first:
```matlab
[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:
```matlab
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 vector
```

Or use `getdata()` to get arrays:
```matlab
[t, x, names] = getdata(selectbyname(simData, 'Central.Drug'));
```

For quick numeric access to all states without SimData, use the
three-output form:
```matlab
[t, x, names] = sbiosimulate(m, cs, d);  % t, x are double arrays directly
```

## Repeated Simulation (`createSimFunction`)

```matlab
% 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 `sbiosimulate` in a loop
- **Exception:** SSA (stochastic) requires `sbiosimulate` in a loop because each run needs fresh random state; `createSimFunction` does not support stochastic solvers
- Compatible with `parfor` (Parallel Computing Toolbox)
- Returns `SimData` objects; use `.getdata()` to extract arrays

### SimFunction with doses

The 4th argument to `createSimFunction` dec
matlab-access-datafeedSkill

>

matlab-analyze-ams-waveformSkill

Analyze AMS waveform data using Mixed-Signal Blockset utilities: phase noise measurement, clock jitter, anti-aliased resampling, timing measurements, lock time, INL/DNL, ADC/DAC calibration, HSpice import. Use when analyzing time-domain voltage from PLL/VCO/clock simulations, measuring phase noise from variable-step solver output, computing jitter, or resampling non-uniform data.

matlab-analyze-dataSkill

Analyze data using MATLAB. Use when the task involves tables, timetables, time-series data, numeric arrays, sensor matrices, or gridded data — including but not limited to exploring, filtering, sorting, cleaning, transforming, aggregating, smoothing, padding, trimming, and answering questions about data. MATLAB provides extensive, easy-to-use built-in functions for these workflows with no additional products required.

matlab-analyze-dependenciesSkill

Analyze the effective toolbox file set to produce a Dependency Manifest — classify all transitive dependencies as included, product, add-on, or external-unresolved, then present resolution options with tradeoffs. Use after matlab-define-toolbox-api when the spec is approved.

matlab-analyze-emSkill

S-parameters, insertion loss, fields, currents, mesh control, and solver selection for RF PCB performance validation. TRIGGER: user asks to compute S-parameters, analyze insertion/return loss, extract fields or currents, compare MoM vs FEM, or control mesh for any RF PCB component. Invoke BEFORE writing sparameters() or solver code — API is non-obvious. SKIP: designing or creating components (use the specific matlab-design-pcb-* skill), material/stackup setup only (use matlab-manage-pcb-material), optimization sweeps (use matlab-optimize-pcb-design), PDN/IR-drop analysis (use matlab-analyze-pcb-pdn).

matlab-analyze-installed-antennaSkill

Analyze antennas installed on electrically large conducting platforms using MATLAB Antenna Toolbox. Loads platform geometry from STL/STEP/IGES, installs antenna elements, selects electromagnetic solvers (MoM-PO, FMM, MoM), and computes patterns, impedance, coupling, and efficiency. Use when the user wants to model an antenna on a vehicle, aircraft, ship, satellite, or other large structure.

matlab-analyze-pcb-pdnSkill

PDN DC voltage/current analysis, IR drop, design rule checking, and multi-net batch analysis on imported PCB layouts. TRIGGER: user asks about power integrity, PDN analysis, IR drop, voltage distribution, current density, power nets, or design rule checking on a PCB. Invoke BEFORE writing code — the PDN API chain is specialized and non-obvious. SKIP: importing a PCB file (use matlab-read-pcb-layout), EM field/S-parameter extraction (use matlab-analyze-em), material/stackup setup only (use matlab-manage-pcb-material), transmission line design (use matlab-design-pcb-txline).

matlab-analyze-rcsSkill

Calculate and visualize monostatic and bistatic radar cross section (RCS) using MATLAB Antenna Toolbox. Computes RCS of platforms, antennas, and arrays with PO, MoM, and FMM solvers, supporting HH/VV/HV/VH polarization, GPU acceleration, and near-field observation. Use when the user wants to compute, plot, or analyze radar cross section.