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.
  • From 0.5.0 the other object kinds are drawn: arrow (15 types, heads at either end, a signed bend, and anchors that tie an end to an atom, a lone pair, a bond or the space between two atoms), plus, bracket, shape, line, table, tlc, orbital, image and caption. A group lists its children back to front; members are in no page order.
  • A caption has a target (the structure it belongs to) and an offset from the target's bottom centre; its x, y are a cache kept in step whenever the target or the caption moves. Compound numbers are number: {auto: true, value: "1"}.
  • page.reactions lists reactions and their steps: the arrow, the reactant, product, agent and condition object ids, explicit (roles set by hand or by a file, kept by perception), optional coefficients, and optional stoich, the amounts you typed in the Stoichiometry panel (scale_mmol, limiting, product, isolated_mg, and per component equiv, mass_mg, volume_ml, density_g_ml, conc_m, purity_pct, mw). Moles, masses implied by equivalents, the limiting reagent and yields are worked out, never stored. A table with stoich: {reaction, step} is a stoichiometry grid. Atom map numbers are map on atoms and reacting marks reacting on bonds.
  • From 0.6.0 a fragment may carry stereo_groups (enhanced stereo: {kind: "abs"}, {kind: "and", n: 1, atoms: [...]}, {kind: "or", n: 2, atoms: [...]}) and chiral (absolute, relative or racemic). For the chemistry, relative puts every stereocentre in no group into one OR group and racemic into one AND group, each with the next free number; absolute also sets the molfile chiral flag.
  • An atom's query holds its query features: list and not, generic (A, AH, Q, QH, X, XH, M, MH), ring_bonds, subst, unsat, h_min, aromatic, and from 0.6.0 smarts, the SMARTS text of an atom query the other fields cannot express (SMARTS import writes it; it wins over the other fields). A bond's query is any, single_or_double, single_or_aromatic or double_or_aromatic, and topology is ring or chain.
  • rgroups on a scaffold fragment define its R-groups by number: members (fragment ids), occurrence, rest_h, if_then, and attach, a map of member fragment id to its attachment atom ids. A member without an attach entry attaches at its atoms with data.attach 1 or 2, else at its * stubs (no label, one bond, standing for the R atom), else at its first atom.
  • expansions hold what an abbreviation atom stands for (its atoms, bonds, attachment atoms and reversed label); source is builtin when the expansion came from the shipped library and user otherwise.
  • media maps a media id to {name, mime, bytes, w, h, sha256}; an image object names the id. The bytes go into the package as media/[id].[ext], and only ids listed in media are written.
  • From 0.7.0 style.grid may hold the drawing's page grid: {type, spacing, major, strength}, where type is lines, dots, crosses, isometric, isometric-dots, hex or hex-dots and spacing is points or "bond" (the bond length). It is read only from the document's own style, never from presets or an object's style, and it changes only the screen and snapping, never exports or the chemistry. A drawing without it shows the window's default grid and saves unchanged. Whether the grid is shown and whether snapping is on belong to the window, not the file (Grid and Page).
  • meta.imported records a file opened from another format (name, format, and from 0.7.0 report, the import report items).

What is not in the file

The engine's chemistry (canonical SMILES, InChI and InChIKey, formula, masses, elemental analysis, implicit hydrogens, valence errors, warnings, from 0.5.0 the balance check of every reaction step, and CIP labels that follow the stereo groups and the chiral flag) 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, RD, SMILES and CXSMILES, SMARTS, InChI, CML, CDXML and CDX files open as new, unsaved drawings laid out at the drawing's bond length; files with reactions open as drawn schemes with their roles set. From 0.7.0 a drawing exports to all of them (and InChIKey), each with a report of what the format could not keep, and to SVG, PNG, PDF and EPS pictures (Formats and Export). From 0.6.0 the engine also writes and reads V3000 molfiles with query features, enhanced stereo and R-group blocks, and SMARTS for query structures (Stereo and Queries); a molfile with its chiral flag at 0 opens with its centres absolute.

The drawing inside pictures and on the clipboard

A picture exported with "Keep the editable drawing inside the file" carries a copy of the drawing in the same document.json form, holding one page and only the exported objects, with meta.embedded = {scope, from} (scope is page, selection or structure, from the source document's id). It sits in SVG metadata, a PNG iTXt chunk, an attached file drawing.fchem.json in PDF, or %FormChemSource: comment lines in EPS, always under the MIME type application/x-formchem+json. Placed pictures are left out of the copy, because their bytes are not carried. Opening such a picture gives a new document with new document and page ids, the file name as its title and the object ids kept. The FormChem clipboard form is the same document shape with meta.clipboard, and pasting gives every object fresh ids. Details are in docs/FORMATS.md. Templates use the document format too (docs/TEMPLATES.md).

Clone this wiki locally