schemdraw — Editable Scientific Schematics with Source Traceability
Script path: This skill is installed at
/skills/weekly-skill/, the absolute script path is/skills/weekly-skill/scripts/(working directory is/app/work, do not use relative paths).
Produce a figure that is correct, editable, and export-compliant: every entity/relation traces to the material, the legend matches the data, the text stays selectable, and the exports meet the target resolution. The failure mode this skill exists to prevent: a pretty picture with wrong entity relations, invented gene names or concentrations, a legend that disagrees with the data, and a bitmap-only output that cannot be edited.
Method in one line: extract entities/relations from the material → lay them out as a layered SVG (grouped, selectable text, arrow direction by relation type) → build the chart from the same source data with an explicit legend/colour map → export PDF+PNG → validate traceability and export contract.
When to use
- Input: a case file (default
/input/case.json) with the scientific material, optional entity/relation lists, chart data and export specs. - Output: under
/app/output—figure.svg,chart.svg,figure.pdf,figure.png,entities.json,export_report.json,validation.json,result.json. - SVG is the editable source; PDF/PNG are exports.
Pipeline (run in order)
Phase 1 — Extract and draw
python3 /skills/weekly-skill/scripts/schem.py --case /input/case.json --work /app/work
- Reads each material (text/Markdown), merges provided
entities/relationswith relations extracted from patterns:X activates|promotes|enhances Y,X inhibits|suppresses|blocks Y,X -> Y,X --| Y,X binds|interacts with Y,X contains|includes Y. - Every relation carries
provenance(text-pattern+ the source quote) or comes from the provided list. - Writes
entities.jsonand a layeredfigure.svg:<g id="arrows">withdata-source/data-target/data-type,<g id="nodes">with one group per entity and<text>labels. Arrow colour/dash encodes relation type (green = activation, red = inhibition, dashed = containment). - If the case has chart data, writes
chart.svgwhose bars carrydata-label/data-valueand whose legend uses the same palette index as the bars.
Phase 2 — Export
python3 /skills/weekly-skill/scripts/export.py --work /app/work --dpi 300
LibreOffice headless converts SVG → PDF (vector, selectable text); PyMuPDF rasterizes PDF → PNG at the requested DPI. Writes export_report.json. If LibreOffice is missing, the report says so and the status becomes partial — never a silent failure.
Phase 3 — Validate
python3 /skills/weekly-skill/scripts/validate.py --case /input/case.json --work /app/work
Checks:
- every relation endpoint is a declared entity (no dangling arrows);
- every relation has provenance or a source quote;
- chart legend labels and values match the source data exactly;
- the SVG has
<text>(selectable) and ≥2 layers; - PDF and PNG exports exist and the PNG is not suspiciously small.
Phase 4 — Copy deliverables
mkdir -p /app/output
cp /app/work/figure.svg /app/work/chart.svg /app/work/figure.pdf /app/work/figure.png \
/app/work/entities.json /app/work/export_report.json /app/work/result.json /app/output/
# validation.json is written by validate.py; copy it too if present
Rules that must hold
- Entities come from the material. No invented gene names, concentrations or time points; anything the model adds must be sourced and marked.
- Relation direction is data.
A activates Bis drawn A → B, never reversed; the arrow type follows the relation type. - Legend ⇄ data consistency. Legend labels and colours come from the same array as the bars; changing the data changes the legend.
- Editable source + compliant export. Always deliver the SVG (editable) and the PDF/PNG (export) together.
- Export is checked, not assumed. DPI, font embedding and file existence are recorded; a failed export is reported.
Exception handling
| Situation | Behaviour |
|---|---|
| No material / empty | empty entity list; SVG still written with a title |
| Relation endpoint unknown | kept in entities (added from the pattern) and drawn |
| Chart data missing | chart.svg skipped; entities.json.chart_svg = null |
| LibreOffice missing | PDF/PNG missing, export_report.status = partial, limitation recorded |
| No relations | SVG with nodes only; validation notes 0 relations |
Self-check
python3 /skills/weekly-skill/scripts/validate.py --case /input/case.json --work /app/work
python3 -c "import json;e=json.load(open('/app/work/entities.json'));print(len(e['entities']), len(e['relations']), e['relation_counts'])"
valid: true is required; the model must fill in any entity/relation the deterministic extractor missed, always with a source.