English · 中文
dsh-chem-render
Deterministic chemical-structure rendering for DeepSeek Harness: one chem_render tool turns a SMILES string into SVG, PNG, standalone HTML, Markdown and LaTeX.
The model supplies only the SMILES string. Parsing, validation, 2D layout and rendering all run in code (openchemlib-extended + resvg-js), so an invalid SMILES fails with a readable error instead of a wrong picture. Optional native chemfig source for LaTeX comes from the mol2chemfigPy3 converter (kekulized first, so the output uses only standard chemfig macros).
Preview
A molecule (caffeine, default clean monochrome rendering):

Stereochemistry with strict wedge bonds (glucose):

Install
pnpm dsh plugin --profile web add 'github:<owner>/dsh-chem-render#<commit>'Local development checkout:
pnpm dsh plugin --profile web add link:D:/path/to/dsh-chem-renderThe package declares dsh.bundle.patch, so the CLI mounts its patch layer automatically.
Optional: native chemfig source in LaTeX
latex / chemfig / all formats additionally emit native \chemfig{...} source when this machine has:
pip install mol2chemfigPy3Override the interpreter or its search path with DSH_CHEMFIG_PYTHON / DSH_CHEMFIG_PYTHONPATH. Without it, the LaTeX output still works through the raster route (\includegraphics with a sibling PNG) and the result notes what was skipped.
Usage
Ask the model for a structure; it calls the tool:
chem_render { smiles: "CN1C=NC2=C1C(=O)N(C(=O)N2C)C", format: "all", name: "caffeine" }format | writes | notes |
|---|---|---|
svg | <name>.svg | vector, policy-safe text write |
png | <name>.png | rasterized from the SVG; confined-backend installs keep binary writes inside the session workspace |
html | <name>.html | self-contained page (inline SVG + PNG data URI), no network |
markdown | <name>.md + sibling .svg/.png | relative PNG reference (works in VS Code preview and elsewhere); data-URI only when the PNG file cannot be written |
latex | <name>.tex + sibling .png | \includegraphics route always; \chemfig{} route when the converter is installed |
chemfig | <name>-chemfig.tex | converter source only |
all | everything above |
Parameters: smiles (required), format (required), name (base filename, sanitized), save_dir (default .), width (200–1200, default 500).
Style options (defaults = clean black rendering, no annotations):
| parameter | default | effect |
|---|---|---|
palette | "monochrome" | "monochrome" draws everything in pure black; "element" colors heteroatoms (N blue, O red, …) |
stereo_labels | false | true shows R/S, abs and enantiomer annotations on chiral centers |
stereo_position | "below" | where that annotation text sits when stereo_labels is on: below / above / frame-top / frame-bottom |
rotate | 0 | rotate the 2D structure by this angle in degrees (counterclockwise); applies to every format including chemfig |
These options also live in the harness settings page (the plugin's config form): values set there act as defaults, and per-call tool arguments override them.
Stereo wedges (up/down bonds) are post-processed into strict geometry: solid wedges become single straight-edged triangles and hash wedges become evenly spaced, linearly tapering dashes perpendicular to the bond axis.
Files are written through the harness filesystem service, so they obey the session's sandbox policy like every other tool write.
The compiled .tex needs graphicx (and chemfig for route 2) — both are standard in TeX Live / MiKTeX. Verified with pdflatex: caffeine and glucose compile clean through both routes.
Development
npm install
npm test # pure rendering-core tests
DSH_NODE_MODULES=~/.dsh/profiles/web/node_modules node tests/boot.test.mjs
# boots a real harness Context and executes the toolNotes & limitations
- Polymer repeat-unit notation is not supported in this release. The bracket notation (delimiters + subscript
n
around a repeat unit) was experimental and has been removed from the tool surface; rendering a polymer fragment as a plain molecule (a finite chain) works, but the textbook bracket form does not.
- The chemfig source is best-effort: quality depends on mol2chemfigPy3/Indigo. Fused bicyclic rings (caffeine) render
correctly; very complex molecules can look imperfect — the raster route is always available.
- Works with any harness surface that has a tools registry and an
fsservice (web profile, headless runs).
License
MIT — see [LICENSE](LICENSE). Rendering depends on npm packages under their own licenses; the optional chemfig route uses the user-installed mol2chemfigPy3 (MIT).