Skip to content

Project Format

nodemode-ai edited this page Dec 3, 2026 · 5 revisions

Project Format

A FormChem drawing is a .fchem file: a zip package with MIME type application/x-formchem. The full contract (every field, the style sheet, the ops and transactions, validation and coalescing) is docs/FORMAT.md. This page is the short tour.

The package

Entry What it is
mimetype application/x-formchem, the first entry, stored uncompressed
document.json The document: pages, structures, text and their styles, UTF-8
media/[id].[ext] Pictures placed in the document
thumbs/page-[n].png Optional page previews, 512 px on the longer side

The engine writes the package to a temporary file in the same folder and renames it into place, so a failed save never leaves half a file. Readers ignore entries they do not know. When the code disagrees with FORMAT.md, the code is the bug, and a format change updates FORMAT.md, the window model (frontend/src/engine/model.ts) and the engine model (backend/app/services/model.py) together.

document.json in brief

  • Units are points (1/72 inch); x runs right, y runs down; angles are degrees counter-clockwise as the person sees the page.
  • style names a preset (journal-1996 by default: bond length 14.4 pt, line width 0.6 pt, bold width 2.0 pt, Arimo labels at 10 pt) and any fields set on top of it. New drawings take the preset and the numbers from Preferences > Drawing.
  • pages is a list; each page has a size, margins and an order of object ids.
  • objects is a map by id. A fragment (kind: "fragment") holds atoms and bonds maps; text objects carry runs of styled text.
  • Ids are short random strings, stable for life and never reused in a document. Agents, extensions and the renderer address everything by id.

What is not in the file

The engine's chemistry (canonical SMILES, InChI and InChIKey, formula, masses, elemental analysis, implicit hydrogens, valence errors, warnings) is a derived cache. It is rebuilt when a drawing opens and broadcast after every change, keyed by fragment id and document revision, and never saved. Undo history is kept per open drawing by the engine and is not saved either.

Changes are transactions

Every change is a transaction: a list of set, ins, del and move ops on JSON paths into document.json, applied all or nothing, with the inverse ops kept for undo. One gesture, one command or one agent call is one transaction and one undo step. See Architecture for how a transaction travels from the window to the engine and back.

Other formats

Molfile, SDF, RXN, SMILES and CXSMILES, InChI, CML and CDXML files open as new, unsaved drawings laid out at the drawing's bond length. Exporting to them arrives in 0.7.0.

Clone this wiki locally