Skip to content
In development: Molkit Script and the AI chat are not available to accounts yet. These pages describe work in progress and may change.

Cookbook

Each example answers one request: the script, the picture it makes on an empty canvas, the names of the objects it makes, and how to change it for a similar request.

To use an example, open the console (Ctrl+`), click Examples, and insert it, or copy it from this page into the script box. The AI chat also looks up these examples when a request is close to one.

Water, ammonia, and methane, each as a Lewis structure with its VSEPR view, each pair in its own set

Section titled “Water, ammonia, and methane, each as a Lewis structure with its VSEPR view, each pair in its own set”

Water, ammonia, and methane, each as a Lewis structure with its VSEPR view, each pair in its own set

foreach m in [water, ammonia, methane] {
draw m view: lewis into: set "{m.title}"
derive m views: [vsepr] into: set "{m.title}"
}
arrange [set "water", set "ammonia", set "methane"] as: column

Makes: water, ammonia, ammonia-vsepr, methane, methane-vsepr.

Variations: Every view, not only VSEPR: views: all. No sets: leave out into:. A planar molecule (water) is already its own VSEPR view: Molkit marks it as that view and makes no copy.

The resonance forms of nitrate in a row

draw nitrate view: lewis
resonance nitrate

Makes: nitrate, nitrate-form2, nitrate-form3, nitrate-arrow1, nitrate-arrow2.

Variations: Expanded-octet forms (SF6, PF5): resonance <name> kind: octet.

Ethanol in every view Molkit can draw

draw ethanol view: bondline
derive ethanol views: all
arrange [ethanol, ethanol-lewis-angled, ethanol-lewis-square, ethanol-vsepr, ethanol-condensed] as: grid columns: 3

Makes: ethanol, ethanol-lewis-angled, ethanol-lewis-square, ethanol-vsepr, ethanol-condensed.

Variations: One Lewis layout only: layout: angled or layout: square.

Six molecules with their names under them, in a grid of three columns

Section titled “Six molecules with their names under them, in a grid of three columns”

Six molecules with their names under them, in a grid of three columns

foreach m in [water, ammonia, methane, ethanol, benzene, acetic-acid] {
draw m caption: title
}
arrange [water, ammonia, methane, ethanol, benzene, acetic-acid] as: grid columns: 3

Makes: water, ammonia, methane, ethanol, benzene, acetic-acid.

Variations: Formulas instead of names: caption: formula. One row: as: row.

The p orbitals of ethylene beside its Lewis structure

Section titled “The p orbitals of ethylene beside its Lewis structure”

The p orbitals of ethylene beside its Lewis structure

draw ethylene view: lewis
orbital-picture ethylene content: p-only

Makes: ethylene, ethylene-orbitals-p-only.

Variations: Every orbital: content: full. On the molecule itself instead of a copy: copy: off.

Water and ammonia with their dipole arrows

Section titled “Water and ammonia with their dipole arrows”

Water and ammonia with their dipole arrows

draw water view: lewis
draw ammonia view: lewis right-of: water
show dipole of: [water, ammonia]

Makes: water, ammonia.

Variations: Every molecule: show dipole of: all.

Benzene in blue with thicker bonds, next to toluene in the usual colors

Section titled “Benzene in blue with thicker bonds, next to toluene in the usual colors”

Benzene in blue with thicker bonds, next to toluene in the usual colors

draw benzene view: bondline
draw toluene view: bondline smiles: "Cc1ccccc1" right-of: benzene
change benzene color: blue bond-width: 2 px

Makes: benzene, toluene.

Variations: You have already selected what to color: change selection color: blue.

Acetic acid and acetate, the ion in brackets with its charge

Section titled “Acetic acid and acetate, the ion in brackets with its charge”

Acetic acid and acetate, the ion in brackets with its charge

draw acetic-acid view: lewis
draw acetate view: lewis right-of: acetic-acid

Makes: acetic-acid, acetate.

Variations: The charge on the atom instead of in brackets: charge: atom.

The combustion of methane drawn with structures: coefficients, plus signs, and a reaction arrow

Section titled “The combustion of methane drawn with structures: coefficients, plus signs, and a reaction arrow”

The combustion of methane drawn with structures: coefficients, plus signs, and a reaction arrow

reaction $\mathrm{CH_4} + 2~\mathrm{O_2} \longrightarrow \mathrm{CO_2} + 2~\mathrm{H_2O}$

Makes: methane, oxygen, carbon-dioxide, water, reaction-1.

Variations: The written equation with each structure under its formula: write the equation, then reaction from: eq layout: under-equation (next example).

The combustion of methane as an equation with the structures under it

Section titled “The combustion of methane as an equation with the structures under it”

The combustion of methane as an equation with the structures under it

write $\mathrm{CH_4} + 2~\mathrm{O_2} \longrightarrow \mathrm{CO_2} + 2~\mathrm{H_2O}$ name: eq
reaction from: eq layout: under-equation

Makes: methane, oxygen, carbon-dioxide, water.

Variations: A generic acid (HA): give the species with with: [[HA, acetic-acid], [A-, acetate]].

A titled figure: two molecules side by side with a bold title above everything

Section titled “A titled figure: two molecules side by side with a bold title above everything”

A titled figure: two molecules side by side with a bold title above everything

draw water view: lewis
draw ammonia view: lewis right-of: water gap: 2 bond
write "Figure 1. Two molecules with lone pairs" size: 14 pt style: bold above: all align: left

Makes: water, ammonia, text-1.

Variations: A note under one molecule: write "..." below: water.

Potassium hydrogen phthalate and calcium chloride as Lewis structures, each ion drawn on its own

Section titled “Potassium hydrogen phthalate and calcium chloride as Lewis structures, each ion drawn on its own”

Potassium hydrogen phthalate and calcium chloride as Lewis structures, each ion drawn on its own

draw khp smiles: "C1=CC=C(C(=C1)C(=O)O)C(=O)[O-].[K+]" title: "potassium hydrogen phthalate" view: lewis
draw cacl2 smiles: "[Ca+2].[Cl-].[Cl-]" title: "calcium chloride" below: khp

Makes: khp, potassium-ion, khp-anion, cacl2, calcium-ion, chloride.

Variations: IUPAC order: the larger hydrogen phthalate is on the left of K+; Ca2+ and Cl− are similar in size, so Ca2+ is on the left. The repeated chloride is drawn once with a 2; repeats: each draws both (chloride, chloride-2). By name (PubChem gives the pieces): draw "potassium hydrogen phthalate". One ion only: draw chloride. An ionic formula as one word (NH4Cl) is not built yet: use the name or smiles:.

The SN2 reaction of hydroxide with bromomethane, with the curved arrows

Section titled “The SN2 reaction of hydroxide with bromomethane, with the curved arrows”

The SN2 reaction of hydroxide with bromomethane, with the curved arrows

# Br on the left of the C, hydroxide on the right: O, C, and Br on one line
draw bromomethane view: lewis
rotate bromomethane by: 90 deg
draw hydroxide view: lewis charge: atom right-of: bromomethane gap: 1.5 bond
# describe hydroxide lists its lone pairs: lone-pair3 is the one on the left, facing the C
arrow from: hydroxide.O.lone-pair3 to: bromomethane.C name: attack
arrow from: bromomethane.bond(C, Br) to: bromomethane.Br name: leave

Makes: bromomethane, hydroxide, attack, leave.

Variations: Another lone pair or side: run describe <molecule> first and name the pair that faces the target. To bulge the other way: bow: left or bow: right. A straight reaction arrow between two whole molecules: arrow from: a to: b.

An animation of ammonia taking a proton to become ammonium, played slowly

Section titled “An animation of ammonia taking a proton to become ammonium, played slowly”

An animation of ammonia taking a proton to become ammonium, played slowly

draw ammonia view: lewis
draw ammonium view: lewis right-of: ammonia gap: 3 bond
animate [ammonia, ammonium] name: protonation speed: 0.5

Makes: ammonia, ammonium.

Variations: More steps: list more objects, one pane each (animate [a, b, c]). A second version to change: duplicate protonation. The file: export protonation (an animated SVG; loop: on repeats it). Its panes and timing: describe protonation.

Slow the protonation animation down: hold the ammonium pane, make the change smooth, and title both panes

Section titled “Slow the protonation animation down: hold the ammonium pane, make the change smooth, and title both panes”

Slow the protonation animation down: hold the ammonium pane, make the change smooth, and title both panes

draw ammonia view: lewis
draw ammonium view: lewis right-of: ammonia gap: 3 bond
animate [ammonia, ammonium] name: protonation
change protonation.pane1 title: "Base"
change protonation.pane2 title: "Conjugate acid" hold: 3 s
change protonation.change1 time: 1.5 s easing: ease-in-out

Makes: ammonia, ammonium.

Variations: The whole animation to a length: change protonation duration: 8 s (it sets the speed). Back to the automatic times: change protonation timing: auto. A pane left out of playback: change protonation.pane1 excluded: on. Changes are numbered among the panes that play.

Animate the SN2 reaction of hydroxide with bromomethane from the curved arrows

Section titled “Animate the SN2 reaction of hydroxide with bromomethane from the curved arrows”

Animate the SN2 reaction of hydroxide with bromomethane from the curved arrows

draw hydroxide view: lewis
draw bromomethane view: lewis right-of: hydroxide gap: 2 bond
animate [[hydroxide, bromomethane]] name: sn2
arrow from: hydroxide.O.lone-pair1 to: bromomethane.C name: attack
arrow from: bromomethane.bond(C, Br) to: bromomethane.Br name: leave
# the next pane is what the arrows make: methanol and bromide, drawn afresh
next-step sn2 layout: redraw

Makes: hydroxide, bromomethane, sn2-p2-1, sn2-p2-2.

Variations: Keep every atom where it was, as the toolbar does: leave out layout: redraw (the new O-C bond then runs long). Read a middle pane: next-step sn2 from: bromomethane. Name the products: next-step sn2 name: product makes product-1, product-2.

Animate the Diels-Alder reaction of butadiene and ethene with its curved arrows

Section titled “Animate the Diels-Alder reaction of butadiene and ethene with its curved arrows”

Animate the Diels-Alder reaction of butadiene and ethene with its curved arrows

# the diene s-cis (its two ends facing the dienophile), ethene beside them
draw butadiene smiles: "C=CC=C" coords: [(0, 0), (-0.866, 0.5), (-0.866, 1.5), (0, 2)]
# ethene as a bare double line, like the diene (carbon-labels: off; the rule writes a two-carbon molecule H2C=CH2)
draw ethene smiles: "C=C" view: bondline carbon-labels: off coords: [(0, 0), (0, 1)] right-of: butadiene gap: 1.2 bond
animate [[butadiene, ethene]] name: diels_alder
# three arrows in one cycle: the new sigma bonds at the ends, the remaining pi bond moves to C2-C3
arrow from: butadiene.bond(C1, C2) to: ethene.C1
arrow from: ethene.bond(C1, C2) to: butadiene.C4
arrow from: butadiene.bond(C3, C4) to: butadiene.bond(C2, C3)
next-step diels_alder name: cyclohexene layout: redraw

Makes: butadiene, ethene, cyclohexene.

Variations: A substituted diene or dienophile: draw it by SMILES with the same coords for the four diene carbons, and name the arrows’ atoms by their numbers in that SMILES. Only the drawing with the arrows, no animation: leave out next-step. The s-trans diene cannot react: never draw the diene as a zig-zag for this reaction.

Animate the addition of HBr to propene, step by step, with the curved arrows

Section titled “Animate the addition of HBr to propene, step by step, with the curved arrows”

Animate the addition of HBr to propene, step by step, with the curved arrows

# propene with its CH2 end (C1) facing the H of H-Br: the pi bond forms its new bond from the end NEARER the H, so
# this puts the H on C1 and the cation on C2 (Markovnikov)
draw propene smiles: "C=CC" view: bondline coords: [(0, 0), (-0.866, 0.5), (-1.732, 0)]
draw hbr smiles: "[H]Br" view: lewis right-of: propene gap: 1.2 bond
animate [[propene, hbr]] name: addition
arrow from: propene.bond(C1, C2) to: hbr.H
arrow from: hbr.bond(H, Br) to: hbr.Br
# pane 2: the cation (step2-1) and bromide (step2-2)
next-step addition name: step2 layout: redraw
# the bromide's lower pair to the cation, bowed under the CH3 rather than through it
arrow from: step2-2.Br.lone-pair3 to: step2-1.C2 bow: left
next-step addition name: product layout: redraw

Makes: propene, hbr, step2-1, step2-2, product.

Variations: HCl or HI: the same script with [H]Cl or [H]I. Another alkene: draw it with the less substituted carbon facing the H (it takes the H). Name the new panes’ parts by describe step2-1 before drawing their arrows. One pane, only the arrows: leave out the next-step lines.

Animate the E2 elimination of 2-bromopropane with ethoxide, with the curved arrows

Section titled “Animate the E2 elimination of 2-bromopropane with ethoxide, with the curved arrows”

Animate the E2 elimination of 2-bromopropane with ethoxide, with the curved arrows

# the beta H written into the SMILES ([H]) so an arrow can reach it; coords: put it straight down (it is placed
# 120 degrees from its C) and the Br straight up: anti, as E2 needs
draw substrate smiles: "[H]CC(Br)C" view: bondline coords: [(0, 0), (0.866, -0.5), (0.866, -1.5), (1.732, 0)]
draw ethoxide smiles: "CC[O-]" view: bondline left-of: substrate gap: 1 bond
# the base's pairs drawn, so the first arrow starts on one
show lone-pairs of: ethoxide
animate [[ethoxide, substrate]] name: e2
# three arrows, one step: base takes the H, the C-H pair becomes the pi bond, Br leaves with the C-Br pair
arrow from: ethoxide.O.lone-pair2 to: substrate.H
arrow from: substrate.bond(H, C1) to: substrate.bond(C1, C2)
arrow from: substrate.bond(C2, Br) to: substrate.Br
next-step e2 name: products layout: redraw

Makes: substrate, ethoxide, products-1, products-2, products-3.

Variations: Another base (hydroxide, tert-butoxide): draw it the same way and start the first arrow on the pair facing the H (describe <base> names them). Another substrate: put [H] on the beta carbon in the SMILES and give coords: with the leaving group opposite it. E1: two steps, the leaving group first (next-step), then the base on the H of the cation.

Animate the base-catalyzed aldol addition of acetaldehyde, step by step, with the curved arrows

Section titled “Animate the base-catalyzed aldol addition of acetaldehyde, step by step, with the curved arrows”

Animate the base-catalyzed aldol addition of acetaldehyde, step by step, with the curved arrows

# the alpha H written into the SMILES ([H]) so an arrow can reach it; the second acetaldehyde waits in the same pane
draw hydroxide smiles: "[OH-]" view: lewis
draw donor smiles: "[H]CC=O" view: bondline coords: [(0, 0), (0.866, -0.5), (0.866, -1.5)] right-of: hydroxide gap: 1 bond
draw acceptor smiles: "CC=O" view: bondline right-of: donor gap: 1.5 bond
show lone-pairs of: donor
show lone-pairs of: acceptor
animate [[hydroxide, donor, acceptor]] name: aldol
# 1. the base takes the alpha H: the enolate
arrow from: hydroxide.O.lone-pair2 to: donor.H
arrow from: donor.bond(H, C1) to: donor.bond(C1, C2)
arrow from: donor.bond(C2, O) to: donor.O
next-step aldol name: s2 layout: redraw
# 2. the enolate's CH2 end attacks the other carbonyl C (a pi bond bonds from its end NEARER the target: the flip puts
# the CH2 end on the acceptor's side)
flip s2-2 direction: horizontal
arrow from: s2-2.O.lone-pair1 to: s2-2.bond(C2, O)
arrow from: s2-2.bond(C1, C2) to: s2-3.C2
arrow from: s2-3.bond(C2, O) to: s2-3.O
next-step aldol name: s3 layout: redraw
# 3. the alkoxide takes a proton from water (describe s3-2 names the pair facing it)
arrow from: s3-2.O2.lone-pair4 to: s3-1.H2
arrow from: s3-1.bond(O, H2) to: s3-1.O
next-step aldol name: product layout: redraw
# four panes do not fit across a page: two rows of two
arrange aldol as: grid columns: 2

Makes: hydroxide, donor, acceptor, s2-1, s2-2, s2-3, s3-1, s3-2, product-1, product-2.

Variations: Another carbonyl: the same three steps, the [H] on its alpha carbon. Aldol condensation: a fourth step, the E1cB loss of water (base on the new alpha H, the OH leaving). Acid-catalyzed: the enol, not the enolate. Before each step’s arrows, describe the new pane’s molecules: their parts and lone pairs are renamed.

Clean up this drawing, put it in ACS 1996 style, and add its name under it

Section titled “Clean up this drawing, put it in ACS 1996 style, and add its name under it”

Clean up this drawing, put it in ACS 1996 style, and add its name under it

# a hand drawing to tidy (in a real request it is already on the canvas: use its name, molecule-1 for an unnamed one)
draw aspirin smiles: "CC(=O)Oc1ccccc1C(=O)O"
# the journal's sizes first, then the geometry tidied at them, then the name under it
preset acs1996
cleanup aspirin
change aspirin caption: "Aspirin"

Makes: aspirin.

Variations: Another journal: preset rsc, nature, cell, thieme, beilstein or frontiers. The formula under it: caption: formula. Only the geometry: cleanup <name> alone; every drawing: cleanup all.

Work out the curved arrows for chloride and bromomethane from the reactants and the products

Section titled “Work out the curved arrows for chloride and bromomethane from the reactants and the products”

Work out the curved arrows for chloride and bromomethane from the reactants and the products

draw chloride view: lewis
draw bromomethane view: lewis right-of: chloride gap: 2 bond
draw chloromethane view: lewis below: chloride gap: 4 bond
draw bromide view: lewis right-of: chloromethane gap: 2 bond
# reactants in the first pane, products in the second, no arrows: mechanism computes them
animate [[chloride, bromomethane], [chloromethane, bromide]] name: sn2
mechanism sn2

Makes: chloride, bromomethane, chloromethane, bromide.

Variations: Ions in water: mechanism sn2 where: machine computes with xTB in water (this needs the calculation helper). More careful: precision: tight; one threshold alone: path-force: 0.02. The log says concerted or stepwise, the barrier and the method.

Turn ethanol into chloroethane by editing its parts

Section titled “Turn ethanol into chloroethane by editing its parts”

Turn ethanol into chloroethane by editing its parts

draw ethanol view: lewis
# the O and its H go; a Cl takes their place on C2 (with its three lone pairs)
delete [ethanol.O, ethanol.H6]
add ethanol.C2 atom: Cl
rename ethanol to: chloroethane

Makes: chloroethane.

Variations: Which H is which: describe ethanol lists every part with its name. A double bond: add ethanol.bond(C1, C2) is a bond between two atoms that are there; change ethanol.bond(C1, C2) order: 2 raises one. One lone pair less: delete water.O.lone-pair1.

Box the answer in red, dashed

draw acetic-acid view: lewis caption: title
box acetic-acid color: red dash: dashed padding: 0.6 bond name: answer

Makes: acetic-acid, answer.

Variations: Color the molecule itself instead: change acetic-acid color: red. A box around several: box [a, b]. The box does not follow the molecule when it moves: box last.