Chemistry metadata
Every SVG exported from the Export SVG dialog carries a machine-readable description of the structure. The description has three parts: scalar attributes on the root element, data-mk-* attributes on every atom group and bond group, and a structured mk:chemistry block inside the file’s metadata element. Your page script can read the formula, walk the bond graph, or pass the embedded MOL block to a cheminformatics library without a server request.
Reading conventions
Section titled “Reading conventions”- Attribute values are strings. Numbers are plain decimals. Boolean flags are the literal
"true"and are omitted when false; there is no"false"value except where noted. - Attributes marked “JSON” hold JSON text and need
JSON.parse. getAttributereturnsnullfor an absent attribute. An absent attribute means “not applicable” or “not computed”, never zero.- Coordinates in
data-mk-x,data-mk-y, the bond endpoint attributes, anddata-mk-view-boxesare in the SVG’s own coordinate space: the rootviewBoxspace, with Y increasing downward.
Root attributes
Section titled “Root attributes”Scalar attributes on the svg root identify the structure without walking the tree. They repeat values from the metadata block so that they survive HTML sanitizers that remove metadata elements.
| Attribute | When present | Value and meaning |
|---|---|---|
data-mk-version |
always | Schema version: 1.0 |
data-mk-species-type |
the structure is a real species (no generic atoms) | molecular, element, monatomic-ion, polyatomic-ion, or ionic (a salt drawn as separate charged ions). See species type |
data-mk-slug |
the author named the molecule in Molkit | Kebab-case identity, for example carbon-monoxide |
data-mk-formula |
identity is emitted (see below) | Molecular formula. Ions carry a Unicode superscript charge, for example NO3⁻, CO3²⁻. Carbon compounds use Hill order; carbon-free compounds use the IUPAC element sequence (NH3, SO2, PF5). Isotope labels appear in the formula, for example D2O |
data-mk-mw |
identity is emitted | Molecular weight in g/mol, rounded to three decimals |
data-mk-smiles |
identity is emitted and SMILES generation succeeded | SMILES string, built from computed formal charges |
data-mk-canonical-smiles |
Molkit could compute a canonical SMILES at export | Canonical SMILES |
data-mk-inchi |
PubChem lookup succeeded with a full property match | InChI |
data-mk-inchi-key |
same as above | 27-character InChIKey |
data-mk-cid |
PubChem lookup returned a compound | PubChem compound ID |
data-mk-has-abbreviations |
a condensed label such as CH3 or OEt was decomposed |
"true". See condensed labels |
data-mk-has-generic-definitions |
R-group definitions were exported | "true". See mk:generic-definitions |
data-mk-has-resonance |
a resonance set was exported | "true" |
data-mk-has-visual-sets |
a visual set (one species drawn in several views) was exported | "true" |
data-mk-views |
with data-mk-has-visual-sets |
Comma-separated views in canonical order: lewis, vsepr, condensed, bondline, fischer, orbitals |
data-mk-default-view |
with data-mk-has-visual-sets |
The view the author chose to open on |
data-mk-default-layout |
the Lewis view has two layouts | orthogonal or zigzag: the Lewis layout to open on |
data-mk-view-boxes |
with data-mk-has-visual-sets |
JSON object mapping a view (or view.layout when a view has two Lewis layouts) to an "x y w h" box in root viewBox space. Set the root viewBox to one box to show only that depiction |
When identity is emitted. The formula, molecular weight, and SMILES attributes are written when the export holds one of the following:
- exactly one covalently connected species
- an ionic salt whose charges balance to zero
- a resonance set or visual set (one species drawn several times, reported from one depiction)
They are never written when any atom is a generic placeholder. Non-covalent bonds (hydrogen bonds, order-0 coordination, dotted bonds) do not join two species into one.
The InChI, InChIKey, and CID attributes come from an online lookup at export time (see PubChem integration). They are absent when the export ran offline or PubChem did not recognize the structure. When a PubChem result disagrees with the drawn formula (for example, a radical that PubChem completes with hydrogen), Molkit falls back to a formula search. That search returns only a CID and a name, so data-mk-cid can be present without data-mk-inchi.
Species type
Section titled “Species type”data-mk-species-type (mirrored as mk:species-type) is derived from covalent components and their net formal charges:
| Value | Meaning | Example |
|---|---|---|
molecular |
one neutral species of mixed elements, including zwitterions; also neutral mixtures | water, glycine |
element |
neutral species of one element | O2, S8 |
monatomic-ion |
one charged atom | Cl− |
polyatomic-ion |
one charged multi-atom species | NO3− |
ionic |
two or more components with at least one positive and one negative | NaCl, NH4NO3 |
Per-atom attributes
Section titled “Per-atom attributes”Every atom group (the element with class atom-group that carries the atom’s data-id) gets its own attributes. Query atoms with [data-mk-element].
| Attribute | When present | Value and meaning |
|---|---|---|
data-mk-element |
always | Element symbol, for example N. * for a generic placeholder |
data-mk-x, data-mk-y |
non-generic atoms | Atom position |
data-mk-index |
non-generic atoms | Zero-based atom index. For a single molecule it matches the MOL block atom order |
data-mk-formal-charge |
non-generic atoms | Formal charge computed from bonds and lone pairs; can be 0 or negative |
data-mk-lone-pairs |
non-generic atoms | Lone pair count |
data-mk-domains-bonding |
non-generic atoms | Bonding electron domains (VSEPR). Includes coordinate bonds to lone ions drawn around a core, so SF6 drawn as four S-F bonds plus two F− reads 6 |
data-mk-domains-nonbonding |
non-generic atoms | Nonbonding electron domains (VSEPR) |
data-mk-implicit-h |
non-generic atoms | Implicit hydrogen count. Reads 0 when Omit per-atom implicit H counts (metadata) was checked at export |
data-mk-implicit-h-meta |
implicit H count above 0 | JSON object describing each implicit H: element, bondedTo, bonds, lonePairs, hybridization (null), formalCharge, valenceElectrons, octet, oxidationState (1, or -1 when bonded to a less electronegative atom such as B or Si) |
data-mk-octet |
the octet is defined for this atom | satisfied, deficient, or expanded. Absent for generic placeholders, atoms in a three-center two-electron bridge (bridging H and its bridgeheads), and bare transition-metal ions |
data-mk-valence-electrons |
non-generic atoms | Valence electrons contributed by this atom |
data-mk-radical |
the atom has unpaired electrons | Number of unpaired electrons, for example 1 on the N of NO2 |
data-mk-warnings |
non-generic atoms | JSON array of validator warning types: valence, charge, coincident. [] when clean. See the note below |
data-mk-hybridization |
the domain count maps to a hybridization | sp, sp2, sp3, sp3d, or sp3d2. Absent on a bridging hydrogen (diborane), whose two drawn bonds are one three-center bond |
data-mk-lp-delocalized |
with data-mk-hybridization, when a lone pair is delocalized into an adjacent pi bond |
"true". The atom reports sp2 although it has four domains. See delocalized lone pairs |
data-mk-geometry |
the VSEPR geometry is known | Geometry name, for example trigonal planar, trigonal pyramidal, seesaw, square planar. Absent on a bridging hydrogen, where VSEPR does not apply. The bridgeheads keep theirs (tetrahedral for the borons of diborane) |
data-mk-vsepr-angles |
with data-mk-geometry |
JSON array of reference angles in degrees for that geometry, for example [120], [107] for ammonia, [134] for a center with one unpaired electron and no lone pair (NO2) |
data-mk-chiral |
four distinct substituents detected | "true". A heuristic (element and bond order of each neighbor), not a full CIP analysis |
data-mk-isotope |
an isotope label is set | Mass number |
data-mk-aromatic |
atom in an aromatic ring | "true" |
data-mk-ring-sizes |
atom in at least one ring | JSON array of ring sizes, for example [6] |
data-mk-oxidation-state |
computable | Oxidation state. The bonds of a three-center bridge share one electron pair, so a bridging hydrogen in diborane is -1 and each boron +3. In a resonance set every form carries the same value for the same atom position. The value comes from the forms that put the most electrons on the most electronegative atoms, so the nitrogen in NO2 is +4 in every form. When electrons move along a bond between like atoms from form to form, those atoms carry the average: ozone is 0 on every oxygen, and each nitrogen in N2O is +1. The value can be a fraction, for example -0.33 for each nitrogen in azide |
data-mk-abbreviation |
the atom is drawn with a custom label | The displayed label, for example OEt or R |
data-mk-abbreviation-head |
the label was decomposed into mk:abbreviations |
"true". See condensed labels |
data-mk-oxidation-state-ambiguous |
abbreviation heads, when bonds to like atoms split electrons evenly; resonance-set atoms whose value is an average over like atoms | "true" |
Warnings on bracketed ions. An ion drawn with neutral atoms and its charge on the bracket gets no charge warning when the bracket charge agrees with the electron count. The export applies the same bracket check as the app, so the warnings in the file match the canvas.
Delocalized lone pairs
Section titled “Delocalized lone pairs”An N or O with only single bonds, at least one lone pair, and a neighbor that carries a pi bond has its lone pair delocalized into that pi bond.
- An amide nitrogen (neighbor is C=O or C=S) or a nitrogen with two pi-bearing neighbors (pyrrole) reports
sp2,trigonal planar, and[120]. - An oxygen next to a pi bond (acid, ester, phenol) reports
sp2but keeps its measuredbentgeometry and angle.
In both cases data-mk-domains-bonding plus data-mk-domains-nonbonding still totals four, and data-mk-lp-delocalized="true" tells you why the hybridization does not follow the domain count. The atom is not flagged when it is part of a coordinate-bond core.
Generic placeholder atoms
Section titled “Generic placeholder atoms”Generic atoms (R, R’, X, Y, Z, A, E, Nu, LG, and the other labels in the generics palette) carry the element *. The export writes only three attributes on them:
| Attribute | Value |
|---|---|
data-mk-generic |
"true" |
data-mk-element |
* |
data-mk-abbreviation |
the displayed label, for example R or X |
No per-atom chemistry is written for a generic atom, because a placeholder has none. Because A, X, and E are generic labels, a VSEPR template such as AX2E2 exports as placeholders. Any generic atom in the export also suppresses the molecule-level identity. The file then has no formula, SMILES, species type, or MOL block, and mk:chemistry gains mk:indeterminate (text true) and mk:generic-labels (a JSON array of the labels).
Condensed labels
Section titled “Condensed labels”When an atom is drawn with a condensed label that Molkit can parse (CH3, CH2, OCH3, CO2H, and similar), the atom group gets data-mk-abbreviation-head="true". Its per-atom attributes describe the group’s attachment atom and that atom’s bonds, so a CH3 carbon reads sp3 with zero lone pairs. data-mk-geometry and data-mk-vsepr-angles are removed from the head, because the group members carry the real shape. The decomposition itself is in mk:abbreviations.
Per-bond attributes
Section titled “Per-bond attributes”Bond groups carry the bond graph and the rendered geometry. Query bonds with [data-mk-order].
| Attribute | When present | Value and meaning |
|---|---|---|
data-mk-order |
always | Bond order: 1, 2, 3, or 1.5 |
data-mk-atom1, data-mk-atom2 |
always | data-id of each endpoint atom |
data-mk-x1, data-mk-y1, data-mk-x2, data-mk-y2 |
geometry could be read | Rendered start and end points of the bond line |
data-mk-stereo |
non-plain bonds | Drawn bond style, for example wedge, dash, wavy, aromatic, dative |
data-mk-polarity |
electronegativity difference at or above 0.05 | Pauling electronegativity difference, two decimals |
data-mk-polar-toward |
with data-mk-polarity |
Element symbol of the more electronegative end |
data-mk-conjugated |
bond in a conjugated system | "true" |
data-mk-resonance-order |
aromatic bonds | 1.5 |
data-mk-avg-bond-order |
bonds in a resonance set whose forms share one skeleton | Average bond order over the non-minor forms, for example 1.33 |
data-mk-avg-bond-order-range |
the order varies across forms | min-max, for example 1-2 |
Resonance and visual-set tags
Section titled “Resonance and visual-set tags”Resonance sets and visual sets draw one species several times in the same file. Each drawing’s atom groups, bond groups, and decorations (ion brackets, charge labels) are tagged, so your code can show one drawing at a time.
| Attribute | Appears on | Value and meaning |
|---|---|---|
data-mk-resonance-set |
atoms, bonds, decorations of a resonance form | Set id. In a visual set it is setId:view, extended with :layout and :octet when the set has more than one Lewis layout or mixes octet models |
data-mk-resonance-index |
same | Form index within the set, as a string |
data-mk-resonance-arrow |
resonance arrows | "true" |
data-mk-visual-set |
atoms, bonds, decorations, arrows in a visual set | Visual set id |
data-mk-view |
same, and mk:conformer-3d |
Space-separated list of views this drawing serves, for example lewis vsepr for a planar drawing that is both |
data-mk-lewis-layout |
Lewis drawings in a set with two layouts, and matching conformers | orthogonal or zigzag |
data-mk-octet-model |
drawings in a set that mixes octet models | expanded or strict. Distinct from the per-atom data-mk-octet |
data-mk-resonance-parent |
a convenience drawing that stands for several forms | "true" |
data-mk-resonance-parent-kind |
with data-mk-resonance-parent |
for example expanded-octet, aromatic |
data-mk-resonance-note |
with data-mk-resonance-parent, when the author wrote one |
Free text |
A drawing that is the only form in its view gets data-mk-visual-set and data-mk-view but no resonance tags. Resonance arrows in a visual set get only data-mk-visual-set, data-mk-view, and data-mk-lewis-layout, because they connect forms rather than belong to one.
The metadata element
Section titled “The metadata element”The rest of the data is in the mk:chemistry element inside the SVG’s metadata element, in the namespace https://molkit.app/ns/chemistry/1.0. Children appear roughly in the order below, with PubChem results last. Match them by localName, not by position.
| Element | When present | Content |
|---|---|---|
mk:molkit-version |
every export | Molkit version that wrote the file |
mk:created |
every export | ISO 8601 timestamp |
mk:url |
every export | https://molkit.com |
mk:schema-org |
every export | JSON-LD. A Schema.org MolecularEntity when identity is emitted, otherwise a SoftwareApplication block describing Molkit |
mk:author |
the document has an author | Text |
mk:common-names |
names the author entered, or PubChem synonyms | Comma-separated text as entered; replaced by a JSON array when PubChem synonyms are merged in |
mk:indeterminate, mk:generic-labels |
a generic atom is present | true; JSON array of labels |
mk:species-type |
as data-mk-species-type |
Same value |
mk:common-name |
the name the author gave the molecule, or the first PubChem synonym | Text |
mk:pubchem-cid, mk:iupac-name, mk:inchi, mk:inchi-key |
from a stored identity or the PubChem lookup | Text |
mk:generic-definitions |
R-group definitions exist | One mk:def label atom per generic atom, each holding mk:member display smiles [source] children |
mk:abbreviations |
condensed labels were decomposed | One mk:group atom label resolved per labeled atom. A resolved group adds source, attach, mk:member i element x y lone-pairs implicit-h [formal-charge] children, and mk:bond from to order children |
mk:formula, mk:molecular-weight, mk:smiles, mk:canonical-smiles |
identity is emitted | As the root attributes |
mk:formula-html |
a single molecule | Formula with sub and sup markup |
mk:exact-mass |
a single molecule | Monoisotopic mass, four decimals |
mk:atom-count, mk:bond-count, mk:total-valence-electrons, mk:degree-of-unsaturation |
a single molecule | Numbers; counts include implicit hydrogens |
mk:element-composition |
a single molecule | JSON object of element counts |
mk:point-group, mk:point-group-confidence |
a single molecule, when determinable | Schoenflies symbol and a confidence rating |
mk:functional-groups |
a single molecule with detected groups | JSON array of group names |
mk:mol-block |
a single molecule | V2000 molfile |
mk:conformer-3d, mk:dipole |
3D conformer generation succeeded at export | See 3D conformers and dipoles |
mk:esp |
a molecule in the export has an electrostatic potential map that matches its current structure, unless the Electrostatic maps export option leaves maps out | See electrostatic potential maps |
mk:dipole-measured |
the species has a reference dipole on file | See measured dipole |
mk:resonance |
a resonance set was exported | See resonance and visual-set blocks |
mk:visual-set |
a visual set was exported | Same |
mk:view3d |
a 3D view on the canvas was exported on its own (the only 3D view in the export, in no set) | See saved 3D views |
“A single molecule” here means one species drawn once. For a resonance set or visual set, only the formula, molecular weight, SMILES, and JSON-LD are written, because the other counts would add up every drawing.
When the author checks Include editable source, the export also puts an mk:source element next to mk:chemistry inside the metadata element. It holds the editable Molkit document, so the SVG can be reopened in Molkit. The option is off by default, and mk:source is not chemistry data: do not depend on it. Everything your code needs is in the attributes and elements above.
JSON-LD
Section titled “JSON-LD”The MolecularEntity payload, taken from a real export of ammonia:
{ "@context": "https://schema.org", "@type": "MolecularEntity", "name": "NH3", "molecularFormula": "NH3", "molecularWeight": "17.031", "smiles": "[H]N([H])[H]", "hasRepresentation": { "@type": "ImageObject", "encodingFormat": "image/svg+xml", "creator": { "@type": "SoftwareApplication", "name": "Molkit", "url": "https://molkit.com" } }}When the PubChem lookup succeeds, name becomes the IUPAC name and iupacName, inChI, inChIKey, and identifier (CID:<number>) are added.
3D conformers and dipoles
Section titled “3D conformers and dipoles”SVG exports also embed 3D data. Conformer generation runs at export time and can fail; the file then has no conformer block and nothing else changes. When it succeeds, each non-generic species gets one mk:conformer-3d element with generated 3D coordinates, followed by its mk:dipole elements. Your code can render the 3D model from these without a chemistry library.
<mk:conformer-3d component="0" source="openchemlib" added-h="false" units="angstrom" frame="drawing-aligned" scope="molecule" data-mk-view="lewis" data-mk-conformer-primary="true"> <mk:atoms>C:-0.6980,-0.0000,-0.0000; O:0.6980,-0.0000,-0.0000</mk:atoms> <mk:bonds>0-1:3</mk:bonds></mk:conformer-3d><mk:dipole component="0" method="bond-sum" units="relative" magnitude="0.89" dir="-1,0,0"/>mk:conformer-3d attributes:
| Attribute | Value and meaning |
|---|---|
component |
Index that pairs this conformer with the mk:dipole elements carrying the same component. Numbers can skip |
source |
Coordinate generator: openchemlib, or adopted when the author made the geometry of an electrostatic potential map the molecule’s 3D structure (exported as it is, with no idealized shape applied). A single central atom with bonds and lone pairs gets the ideal VSEPR shape (linear, trigonal planar, T-shaped, seesaw, square planar, square pyramidal, octahedral) |
added-h |
true when hydrogens not drawn in 2D were added for the 3D model |
units |
angstrom |
frame |
drawing-aligned: rotated so the model matches the 2D drawing, x right and y up |
scope |
molecule |
data-mk-view, data-mk-lewis-layout |
In a visual set, the depiction this conformer was aligned to |
data-mk-conformer-primary |
"true" on the conformer whose drawing gives the clearest 3D view (VSEPR first, then angled Lewis, bond-line, square Lewis, condensed, Fischer). Use this one when you show a single 3D model |
mk:atoms is a ; -separated list of Element:x,y,z entries. Drawn atoms come first, in drawing order, then any added hydrogens. mk:bonds is a ; -separated list of i-j:order entries, where i and j are zero-based indexes into mk:atoms. An entry can end with a flag: :c marks a coordinate bond (draw it dashed), and :d marks a bond whose order varies across resonance forms (draw it as a partial bond). Parse the order with parseInt and read any flag from the rest of the entry.
A resonance form has no separate 3D shape, so a resonance set carries one conformer for the species rather than one per form. In a visual set, conformers aligned to resonance forms are dropped when a non-resonant depiction has one; otherwise the first form of each view keeps its conformer.
mk:dipole attributes:
| Attribute | Value and meaning |
|---|---|
component |
Matches a mk:conformer-3d |
method |
bond-sum (vector sum of bond dipoles from electronegativity differences) or gasteiger (from Gasteiger partial charges) |
units |
relative for bond-sum (electronegativity units, not debye); debye for gasteiger |
magnitude |
Three decimals. 0 when below 0.05 |
dir |
Unit vector x,y,z in the drawing frame (x right, y down, z out of the page) pointing toward the negative end. 0,0,0 when the magnitude is 0 |
If no bond is polar, no bond-sum element is written for that component, which means a prediction of exactly zero. For carbon monoxide and nitric oxide the direction follows the measured moment (negative end on C and on N), not the electronegativity rule; the matching mk:dipole-measured says so.
Measured dipole
Section titled “Measured dipole”mk:dipole-measured holds the measured gas-phase dipole moment for species in Molkit’s reference table of dipole moments. It appears at most once per file. Its absence means no reference value is on file, not that the moment is zero.
| Attribute | When present | Value and meaning |
|---|---|---|
mu |
always | Moment in debye |
units |
always | debye |
kind |
always | experimental, or symmetry for an exact zero by symmetry with no primary measurement (SF6, Br2, I2, anti-butane). Do not present symmetry values as measurements |
year |
known | Measurement year. For entries from the 1967 NSRDS-NBS10 compilation this is an upper bound |
species |
always | Species name |
key |
always | InChIKey of the reference entry |
matched-by |
always | inchi-key (canonical) or name (name match checked against the drawn formula) |
source, doi |
known | Citation and DOI |
note |
the entry has one | Free text caveat |
negative-end |
the measured direction contradicts the electronegativity rule | Element symbol at the negative end: C for carbon monoxide, N for nitric oxide |
departure |
with negative-end |
Sentence explaining the departure from the rule of thumb |
Only mu === 0 means zero by symmetry. Small nonzero values (propane, 0.084 D) are real.
Electrostatic potential maps
Section titled “Electrostatic potential maps”A molecule with an electrostatic potential map gets one mk:esp element next to its mk:conformer-3d, with the same component. The Electrostatic maps option in the Export SVG dialog puts the map data inside the SVG or in a separate .esp file; the mk:esp description is in the SVG either way. A map that is out of date with its molecule is never exported.
mk:esp attributes (absent when unknown):
| Attribute | Value and meaning |
|---|---|
component |
Matches a mk:conformer-3d |
format |
1 |
program, program-version |
The program that computed the potential, for example OCC |
method, basis |
Level of theory split at the first /: B3LYP and def2-SVP. GFN2-xTB has no basis |
charge, unpaired |
Net charge and number of unpaired electrons of the calculation |
phase |
gas |
geometry |
built (Molkit’s idealized geometry), relaxed, or imported (from cube files) |
geometry-method, geometry-medium |
For relaxed: the relax method and program, and gas or water |
date |
Date of the calculation, YYYY-MM-DD |
surface |
electron density 0.002 e/bohr^3 |
density-source |
calculated or free-atom densities |
units |
atomic units (hartree per elementary charge) |
grid-step |
Grid spacing in angstrom |
fingerprint |
8 hex digits identifying the geometry the map belongs to |
surface-min, surface-max |
Lowest and highest potential on the surface, atomic units |
Children:
| Element | Content |
|---|---|
mk:esp-caption |
One sentence describing the map, for a caption or a screen reader |
mk:esp-note |
Notes from the calculation, when there were any |
mk:esp-citation |
One per reference for the program and method |
mk:esp-charges |
Per-atom charges in mk:conformer-3d atom order, space-separated, with a kind attribute (CHELPG from OCC). The viewer does not show them |
mk:esp-display |
The author’s display settings as attributes (scheme, range-mode, fixed, opacity, cut-opacity, iso, view, plane, plane-offset, contours), and view-q, the camera rotation as a quaternion x y z w when the map was on in the 3D viewer at export. Starting values only; treat them as untrusted and clamp them |
mk:esp-data |
The map file as base64, with encoding="base64", bytes, and checksum |
mk:esp-file |
Instead of mk:esp-data: href (a relative path, by default esp/<name>-<fingerprint>.esp), bytes, and checksum |
The .esp file (embedded or separate) starts with the line MKESP 1. One line of JSON follows (the mk:esp attributes above, the atoms, and the grid shapes), then a newline and the grid data as 16-bit values. checksum is an FNV-1a hash of the whole file in 8 hex digits; if it does not match, show no map. Files are named by content, so a changed geometry gets a new file name.
Resonance and visual-set blocks
Section titled “Resonance and visual-set blocks”mk:resonance has attributes set, optional equivalent="true", and optional arrow-ids (comma-separated). It contains one mk:form per form, with index, weight (equivalent, major, or minor), optional dominant="true" (a display flag; it does not change the average), and optional caption.
mk:visual-set has attributes id, default (the default view), views (comma-separated), optional planar="true", and optional primary (view:index or view:parent). It contains one mk:depiction per drawing, with view, optional views (when one drawing serves several views), lewis-layout, octet, index, is-parent, parent-kind, weight, dominant, caption, and provenance attributes generated-by, edited, source-view, source-index, source-layout.
A depiction in the orbitals view is an orbital picture. A group can hold several, and each always has a caption: the author’s own, or All orbitals or Pi system written from the picture’s settings. It also has a box attribute, "x y w h" in root viewBox space, because the lobes reach past the atoms and data-mk-view-boxes holds only the union of all pictures.
Both blocks can contain mk:bond-order summaries, one per bond type, when the forms share one skeleton: elements (space-separated pair, for example N O), order (average), optional range (min-max), basis (non-minor or all), and in a visual set group (the view key the average belongs to).
Overlay layers
Section titled “Overlay layers”An export can carry hidden layers that a web page turns on: the molecular geometry at each center, the bond dipoles, and the net dipole. Each layer is a group inside the molecule, <g class="mk-ov mk-ov-NAME" data-mk-overlay="NAME" style="display:none">, where NAME is geometry, polarity, or dipole. Because the layers are hidden, the file looks the same as an export without them in a viewer, an image tag, or the viewer.
| Layer | What it holds |
|---|---|
geometry |
One text per shape: the centers (an atom other than H with two or more neighbors, implicit hydrogens included, so the O of an OH in a bond-line drawing is a center; a bond that joins an ionic pair does not count, so the Mg of a drawn F-Mg-F is not a center), are grouped by their VSEPR molecular geometry, and each group gets one text with the name, such as bent, at the center nearest the group’s middle, with data-mk-geometry-of set to that atom’s id. A text that stands for several centers carries data-mk-geometry-all with their number (phenol: one trigonal planar for the ring and one bent for the O). The Lewis and bond-line views of one molecule give the same names. A two-word name is two tspan lines |
polarity |
An arrow beside each bond whose Pauling electronegativity difference is 0.4 or more, pointing to the more electronegative atom, with a crossbar near the tail. A bond that joins an ionic pair gets no arrow, even when it is drawn as a line: an alkali or alkaline-earth metal other than Be bonded to F, Cl, Br, I, O, N or S (a drawn Na-Cl). A polar covalent bond with a large difference, such as H-F or B-F, keeps its arrow |
dipole |
The net dipole arrow, as described in Net dipole. Only a neutral molecule has one |
The root keeps the viewBox of an export without the layers. The box that also holds the layers is in data-mk-overlay-viewbox, with data-mk-overlay-width and data-mk-overlay-height when the root has a fixed size, and data-mk-overlay-view-boxes for a visual set’s per-view boxes. To show a layer, set its group to display: inline and use these larger boxes, so that the layer is not cut off.
Formal charges have no layer of their own. A charge mark that shows only a formal charge carries data-mk-formal, so your page can show or hide those marks by that attribute.
Saved 3D views
Section titled “Saved 3D views”A 3D view drawn on the canvas is exported with its camera angle and display settings, so a page can show the molecule at the angle and in the look the author chose. They are written as an mk:view3d format="json" element. A visual set’s 3D view puts that element inside an mk:depiction view="3d" index="0", which also has a box attribute ("x y w h" in root viewBox space), and the view’s group in the drawing gets data-mk-visual-set and data-mk-view="3d". A 3D view in no set is written as mk:view3d format="json" scope="object" directly in mk:chemistry, but only when it is the export’s only 3D view and no set has one.
The JSON object has these fields. Treat all of them as untrusted: check each number, and cap the counts.
| Field | Meaning |
|---|---|
v |
Format version, 1. Fields may be added without a new version; refuse an object with a version you do not know |
atoms |
El:x,y,z per atom in angstroms, separated by ; . Drawn atoms come first, then added hydrogens |
bonds |
a-b:order per bond, with optional :c (coordinate) and :d (delocalized); a and b are indices into atoms |
ids |
The drawn atom id for each atom by index, null for an added hydrogen |
q |
The camera rotation as a quaternion [x, y, z, w], meaningful only against these coordinates |
fill |
How much of the shorter side of the box the molecule fills |
look |
ball-and-stick, space-filling, stick, wireframe, or cartoon |
layers |
What the author showed: noH, lp, dipole, vib (band in cm-1 and name), esp, and surface (vdw, sas, or ms) |
draw |
The layers ready to draw in the record’s frame: lobes ([cx, cy, cz, dx, dy, dz] each), arrows ([x1, y1, z1, x2, y2, z2] each), and dipole (tail then head) |
play |
What the page plays: kind (spin, vib, or flip), autoplay, loop, words (a sentence for the text alternative), and for a spin speed (turns a minute), for a vibration d (the displacements), or for a flip frames (the coordinates of each frame), method (MMFF94 or GFN2-xTB), and mark (the index of the marked axial hydrogen) |
Extracting the MOL block
Section titled “Extracting the MOL block”The mk:mol-block element holds a complete V2000 molfile as text, ready for RDKit.js, Open Babel, or any tool that reads MOL files. Its Y coordinates are flipped relative to the SVG: the chemistry convention is Y up, and SVG is Y down. Match metadata children by localName, which ignores the namespace prefix and works in every browser:
function getMolBlock(svg) { const meta = svg.querySelector('metadata'); if (!meta) return null; const chem = [...meta.children].find(el => el.localName === 'chemistry'); const mol = chem && [...chem.children].find(el => el.localName === 'mol-block'); return mol ? mol.textContent : null;}Reading the molecule graph
Section titled “Reading the molecule graph”The atom and bond attributes together form a complete graph. This parser builds an adjacency structure for highlighting, tooltips, or analysis. It works on an inlined export (see Embed SVG exports):
function parseGraph(svg) { const atoms = new Map(); const int = (g, name) => { const v = g.getAttribute(name); return v == null ? null : parseInt(v, 10); };
for (const g of svg.querySelectorAll('[data-mk-element]')) { const id = g.getAttribute('data-id'); const generic = g.getAttribute('data-mk-generic') === 'true'; atoms.set(id, { id, generic, element: g.getAttribute('data-mk-element'), // "*" for a generic label: g.getAttribute('data-mk-abbreviation'), // "R", "OEt", or null charge: int(g, 'data-mk-formal-charge'), // null on generics lonePairs: int(g, 'data-mk-lone-pairs'), implicitH: int(g, 'data-mk-implicit-h'), hybridization: g.getAttribute('data-mk-hybridization'), ringSizes: JSON.parse(g.getAttribute('data-mk-ring-sizes') ?? '[]'), neighbors: [], node: g, // keep the live element for styling }); }
const bonds = []; for (const g of svg.querySelectorAll('[data-mk-order]')) { const bond = { order: parseFloat(g.getAttribute('data-mk-order')), atom1: g.getAttribute('data-mk-atom1'), atom2: g.getAttribute('data-mk-atom2'), stereo: g.getAttribute('data-mk-stereo'), // null for plain bonds node: g, }; bonds.push(bond); atoms.get(bond.atom1)?.neighbors.push(bond.atom2); atoms.get(bond.atom2)?.neighbors.push(bond.atom1); }
return { atoms, bonds };}In a resonance set or visual set the same species appears once per drawing, so the graph has several disconnected copies. Filter by data-mk-resonance-index or data-mk-view to work with one.
Pitfalls
Section titled “Pitfalls”- Conditional attributes need null checks. Decide on a default before parsing. In particular,
data-mk-octetis absent where the octet is undefined; do not read absence assatisfied. - Never use logical-or fallbacks on numeric reads. Zero is a valid value for
data-mk-formal-charge,data-mk-lone-pairs,data-mk-implicit-h, anddata-mk-oxidation-state. Use??after parsing, not||. - Generic atoms carry almost nothing. Check
data-mk-genericbefore reading coordinates, charge, or index; they are absent on generics. - JSON attributes need
JSON.parse:data-mk-vsepr-angles,data-mk-ring-sizes,data-mk-warnings,data-mk-implicit-h-meta, anddata-mk-view-boxes. - Hybridization does not always follow the domain count. Check
data-mk-lp-delocalizedbefore explainingsp2from four domains. - Identity fields can be missing on a valid export. Multi-species drawings, unbalanced ion mixtures, and anything with a generic atom have no formula, SMILES, or MOL block. Per-atom and per-bond attributes are still present.
- Atom IDs are opaque strings. Do not parse them. Match bonds to atoms by comparing
data-mk-atom1anddata-mk-atom2against each atom group’sdata-id. - The bond-sum dipole is not in debye. Use
mk:dipole-measuredfor a number in debye; thegasteigerrecord is in debye but is a model value. - PubChem fields can be missing.
data-mk-inchi,data-mk-inchi-key,data-mk-cid, and the IUPAC name exist only when the lookup succeeded online. - Omit per-atom implicit H counts (metadata) changes only the per-atom attributes. With it checked, every
data-mk-implicit-hreads 0 anddata-mk-implicit-h-metais dropped. Formula, molecular weight, atom count, and total valence electrons always include implicit hydrogens. - Re-export files made before Molkit 0.24.0. Those files can have
data-mk-octet="expanded"on generics and bridging hydrogens,chargewarnings on correctly bracketed ions, and dipole directions that depend on how a freely rotating O-H was drawn. Files made before 0.11.1 can also have wrong implicit-hydrogen counts.