Skip to content

matlab/matlab-agentic-toolkit / skills-catalog/computational-biology/simbiology-build-model

simbiology-build-model

Unverified

Build, modify, and diagram SimBiology models — API reference, helper functions, and layout patterns. Use when constructing or editing models programmatically or visually.

references/evacuation-procedure-guidance.md

View on GitHub
# Evacuation Procedure

> **This is a last-resort recovery procedure, NOT a standard build
> strategy.** For new models, always use `addAndPositionCompartment` to
> build one compartment at a time. Only use evacuation when rearranging
> an **existing** model where compartments must swap positions or change
> sizes.

The diagram API enforces constraints in real-time: species must remain
inside their parent compartment's bounds, and compartments cannot
overlap other blocks. When rearranging an existing layout, moving a
compartment will fail if its contained species would end up outside the
new bounds, or if the new position overlaps blocks that haven't been
moved yet.

**For rearrangements involving multiple compartments, follow this
5-phase procedure:**

## Phase 1: Move all reaction nodes to a staging area

Reaction nodes can block compartment movement. Evacuate them first:

```matlab
allRxns = model.Reactions;
for i = 1:numel(allRxns)
    try
        simbio.diagram.setBlock(allRxns(i), 'Position', [3000 + i*30, 3000, 15, 15]);
    catch
    end
end
```

## Phase 2: Move all species to a staging area

Move every species to a far-away coordinate so they don't constrain
compartment movement:

```matlab
allSpecies = model.Species;
for i = 1:numel(allSpecies)
    try
        simbio.diagram.setBlock(allSpecies(i), 'Position', [5000 + i*60, 5000, 32, 16]);
    catch
    end
end
```

## Phase 3: Move all compartments to a staging area

With species and reactions out of the way, spread compartments apart:

```matlab
allComps = model.Compartments;
for i = 1:numel(allComps)
    try
        simbio.diagram.setBlock(allComps(i), 'Position', [8000 + i*300, 8000, 250, 250]);
    catch e
        fprintf('Comp %s: %s\n', allComps(i).Name, e.message);
    end
end
```

## Phase 4: Position at final locations

Now place compartments at their final positions (no overlap conflicts),
then place species inside at planned coordinates, then reactions:

```matlab
% 1. Position compartments at final locations
comp = sbioselect(model, 'Type', 'compartment', 'Name', 'Central');
simbio.diagram.setBlock(comp, 'Position', [x y width height]);

% 2. Position species inside compartment at planned coordinates
simbio.diagram.setBlock(species(1), 'Position', [x+40, y+30, 50, 16]);
simbio.diagram.setBlock(species(2), 'Position', [x+140, y+30, 80, 16]);

% 3. Position reactions
repositionAllReactions(model);
```

If you don't have specific planned coordinates for species, distribute
them in a row inside the compartment with even spacing:

```matlab
species = comp.Species;
n = numel(species);
margin = 30;
spWidth = 50;  % scale per name length: <=5→50, 6-12→100, 13+→130
spacing = (width - 2*margin - spWidth) / max(n-1, 1);
for i = 1:n
    sx = x + margin + (i-1)*spacing;
    sy = y + height/2 - 8;
    simbio.diagram.setBlock(species(i), 'Position', [round(sx) round(sy) spWidth 16]);
end
```

## Phase 5: Verify no blocks are stranded

After placing all blocks at final positions, scan every block to ensure
none were left behind at staging coordinates (>= 2500 px from layout
center):

```matlab
threshold = 2500;
allComps = model.Compartments;
compPositions = zeros(numel(allComps), 2);
for i = 1:numel(allComps)
    p = simbio.diagram.getBlock(allComps(i), 'Position');
    compPositions(i,:) = [p(1) p(2)];
end
layoutCenter = mean(compPositions, 1);

% Check reactions
for i = 1:numel(model.Reactions)
    p = simbio.diagram.getBlock(model.Reactions(i), 'Position');
    dist = sqrt((p(1)-layoutCenter(1))^2 + (p(2)-layoutCenter(2))^2);
    if dist > threshold
        fprintf('STRANDED: Reaction %d at [%d %d]\n', i, p(1), p(2));
    end
end

% Check species
for i = 1:numel(model.Species)
    p = simbio.diagram.getBlock(model.Species(i), 'Position');
    dist = sqrt((p(1)-layoutCenter(1))^2 + (p(2)-layoutCenter(2))^2);
    if dist > threshold
        fprintf('STRANDED: Species %s at [%d %d]\n', model.Species(i).Name, p(1), p(2));
    end
end
```

**Fix stranded blocks immediately** — use `computeSafeReactionPosition`
for stranded reactions, and reposition stranded species inside their
parent compartment.

## When evacuation is needed vs not needed

- **Needed:** Rearranging an existing model where multiple compartments
  must swap positions or change sizes.
- **NOT needed — initial construction:** Use `addAndPositionCompartment`
  to build one compartment at a time with correct positions from the start.
- **Not needed:** Moving a single compartment, adding new blocks to an
  existing layout, small position adjustments.


----

Copyright 2026 The MathWorks, Inc.

----
rea-changelog-updatemorluto/reaPrepare or rewrite REA release changelogs and GitHub release notes from pinned Git history, with verified contributor thanks and Release Please synchronization.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
academy-guideanthropics/skillsStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials, and use cases from Claude Academy (academy.claude.com), Anthropic's learning hub. Trigger on: "how do I", "how can I", "getting started with", "what can Claude do", "teach me", "learn to use"; questions about artifacts, projects, skills, plugins, connectors, MCP; requests about rolling Claude out to a team, class, or organization; and any ask for training materials, onboarding content, or learning resources. Use it when the user is learning how to use a feature or product — not when they are mid-task and just want the task done. This skill composes with other skills: after consulting product documentation to answer how a Claude feature works, also check here for a matching course or tutorial — a docs-grounded answer and an Academy recommendation belong together. Only recommend on a strong match; never invent Academy content.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
claude-apianthropics/skillsReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER — read BEFORE opening the target file; don't skip because it "looks like a one-liner" — whenever: the prompt names Claude/Anthropic in any form (Claude, Anthropic, Fable, Opus, Sonnet, Haiku, `anthropic`, `@anthropic-ai`, `claude-*`, `us.anthropic.*`, `[1m]`); the user asks about an LLM (pricing/model choice/limits/caching) — never answer from memory; OR the task is LLM-shaped with provider unstated (agent/MCP/tool-definition/multi-agent/RAG/LLM-judge/computer-use; generate/summarize/extract/classify/rewrite/converse over NL; debugging refusals/cutoffs/streaming/tool-calls/tokens). SKIP only when another provider is being worked on (overrides all triggers): OpenAI/GPT/Gemini/Llama/Mistral/Cohere/Ollama named in the query; OR `grep -rE 'openai|langchain_openai|google.generativeai|genai|mistralai|cohere|ollama'` over the project hits (run this grep FIRST if no provider named — don't Read the file).Stars: 198kUpdated Claude CodeCodexUnverifiedInstall
doc-coauthoringanthropics/skillsGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision docs, or similar structured content. This workflow helps users efficiently transfer context, refine content through iteration, and verify the doc works for readers. Trigger when user mentions writing docs, creating proposals, drafting specs, or similar documentation tasks.Stars: 198kUpdated Claude CodeCodexVerifiedInstall