$npx -y skills add matlab/matlab-agentic-toolkit --skill matlab-build-simbiology-modelBuild, modify, and diagram SimBiology models — API reference, helper functions, and layout patterns. Use when constructing or editing models programmatically or visually.
| 1 | # Build SimBiology Models |
| 2 | |
| 3 | API reference, helper functions, and patterns for building, modifying, and |
| 4 | diagramming SimBiology models. Works in all MATLAB environments (desktop, |
| 5 | headless, batch, remote). Diagram/layout features require the Model Builder |
| 6 | app and are activated only when the user requests visual output. |
| 7 | |
| 8 | ## When to Use |
| 9 | |
| 10 | - Building or modifying SimBiology models (compartments, species, reactions, parameters, rules, events, doses, observables, variants) |
| 11 | - Opening, saving, or loading models in the Model Builder / Analyzer apps |
| 12 | - Designing or adjusting diagram layouts |
| 13 | - Keywords: "build", "create", "modify", "add compartment/species/reaction", "diagram", "layout" |
| 14 | |
| 15 | ## When NOT to Use |
| 16 | |
| 17 | - Simulation and analysis (use `matlab-simulate-simbiology-model`) |
| 18 | - Parameter fitting, population modeling, NCA (use `matlab-fit-simbiology-model`) |
| 19 | |
| 20 | ## Must-Follow Rules |
| 21 | |
| 22 | ### 1. Add helper scripts to the MATLAB path first |
| 23 | |
| 24 | Run at the start of every session: |
| 25 | ```matlab |
| 26 | addpath(fullfile('<WORKSPACE_ROOT>', '.claude', 'skills', 'matlab-build-simbiology-model', 'scripts')); |
| 27 | disp('Helper scripts added to path.') |
| 28 | ``` |
| 29 | |
| 30 | ### 2. Only open the Builder when needed |
| 31 | |
| 32 | Do NOT open the Model Builder by default. Open it when: |
| 33 | - The user explicitly requests a diagram, layout, or visual |
| 34 | - The input is an `.sbproj` file — use `loadViaBuilder` to preserve |
| 35 | diagram layout/styling (`sbioloadproject` loses this data) |
| 36 | |
| 37 | A model is fully functional without a diagram — it can be simulated, |
| 38 | fitted, and analyzed using only the model object on `sbioroot`. |
| 39 | |
| 40 | ### 3. Model construction uses standard SimBiology API |
| 41 | |
| 42 | Build models using `addcompartment`, `addspecies`, `addreaction`, etc. |
| 43 | directly. This works in all environments: desktop, headless, batch, remote. |
| 44 | |
| 45 | ```matlab |
| 46 | model = sbiomodel('MyModel'); disp(model.uuid) |
| 47 | comp = addcompartment(model, 'Central', 1); |
| 48 | addspecies(comp, 'Drug', 100); |
| 49 | addparameter(model, 'ke', 0.1); |
| 50 | rx = addreaction(model, 'Central.Drug -> null'); |
| 51 | kl = addkineticlaw(rx, 'MassAction'); |
| 52 | kl.ParameterVariableNames = {'ke'}; |
| 53 | ``` |
| 54 | |
| 55 | For **standard PK models** (1- or 2-compartment with standard dosing and |
| 56 | elimination), use `references/pk-library-guidance.md` as the reference for |
| 57 | correct parameterization, naming, and rules. When no diagram is needed, |
| 58 | call `PKModelDesign` directly. When the user requests a diagram, construct |
| 59 | the model manually following the same PK library conventions but use |
| 60 | `addAndPositionCompartment` for layout control (see Rule 8b). |
| 61 | |
| 62 | ### 4. Write reactions in the biological forward direction |
| 63 | |
| 64 | The diagram renders **arrows on products** and **plain lines on reactants** |
| 65 | (based on the forward direction of the reaction string). Writing a reaction |
| 66 | backwards produces incorrect arrows even if the kinetics are equivalent. |
| 67 | |
| 68 | ```matlab |
| 69 | % CORRECT — L and R get plain lines, C gets an arrow |
| 70 | addreaction(model, 'cell.L + cell.R <-> cell.C'); |
| 71 | |
| 72 | % WRONG — same kinetics but L and R get arrows (they're "products" now) |
| 73 | addreaction(model, 'cell.C <-> cell.L + cell.R'); |
| 74 | ``` |
| 75 | |
| 76 | Guidelines: |
| 77 | - **Binding:** write `A + B -> C` (substrates on left, complex on right) |
| 78 | - **Degradation/elimination:** write `Drug -> null` (not `null -> Drug`) |
| 79 | - **Synthesis:** write `null -> mRNA` (not `mRNA -> null`) |
| 80 | - **Transport:** write `Source.Drug -> Dest.Drug` (source on left) |
| 81 | |
| 82 | ### 5. Always use qualified names for species and reaction-scoped parameters |
| 83 | |
| 84 | Always reference species and reaction-scoped parameters by their **qualified name**. If any of the names are not valid MATLAB variable names, surround them with square brackets before building the qualified name. |
| 85 | |
| 86 | - **Species:** `CompartmentName.SpeciesName` (e.g., `Central.Drug`, `Peripheral.[Drug-bound]`) |
| 87 | - **Reaction-scoped parameters:** `ReactionName.ParameterName` (e.g., `Elimination.ke`) |
| 88 | |
| 89 | **Qualification is always exactly one level deep** — the immediate parent |
| 90 | compartment only. Multi-level paths like `Body.Central.Drug` are **invalid** |
| 91 | in reaction strings. This is never ambiguous because compartment names must |
| 92 | be globally unique across the entire model (SimBiology enforces this |
| 93 | regardless of nesting depth). So `Central.Drug` is always sufficient. |
| 94 | |
| 95 | **Compartment naming rules:** |
| 96 | - Names must be unique across the entire model — no two compartments can |
| 97 | share a name even at different nesting levels |
| 98 | - If you need hierarchical naming, use underscores: `Body_Central` (not |
| 99 | nested compartments both named `Central`) |
| 100 | - Species names must be unique within a compartment but can repeat across |
| 101 | different compartments (disambiguated by `Compartment.Species`) |
| 102 | |
| 103 | ### 6. Use modern property names (`Value`, `Units`, `Constant`) |
| 104 | |
| 105 | SimBiology objects (species, compartments, parameters) share a unified |
| 106 | property interface. Always us |