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”
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: columnMakes: 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
Section titled “The resonance forms of nitrate in a row”
draw nitrate view: lewisresonance nitrateMakes: 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
Section titled “Ethanol in every view Molkit can draw”
draw ethanol view: bondlinederive ethanol views: allarrange [ethanol, ethanol-lewis-angled, ethanol-lewis-square, ethanol-vsepr, ethanol-condensed] as: grid columns: 3Makes: 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”
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: 3Makes: 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”
draw ethylene view: lewisorbital-picture ethylene content: p-onlyMakes: 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”
draw water view: lewisdraw ammonia view: lewis right-of: watershow 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”
draw benzene view: bondlinedraw toluene view: bondline smiles: "Cc1ccccc1" right-of: benzenechange benzene color: blue bond-width: 2 pxMakes: 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”
draw acetic-acid view: lewisdraw acetate view: lewis right-of: acetic-acidMakes: 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”
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”
write $\mathrm{CH_4} + 2~\mathrm{O_2} \longrightarrow \mathrm{CO_2} + 2~\mathrm{H_2O}$ name: eqreaction from: eq layout: under-equationMakes: 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”
draw water view: lewisdraw ammonia view: lewis right-of: water gap: 2 bondwrite "Figure 1. Two molecules with lone pairs" size: 14 pt style: bold above: all align: leftMakes: 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”
draw khp smiles: "C1=CC=C(C(=C1)C(=O)O)C(=O)[O-].[K+]" title: "potassium hydrogen phthalate" view: lewisdraw cacl2 smiles: "[Ca+2].[Cl-].[Cl-]" title: "calcium chloride" below: khpMakes: 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”
# Br on the left of the C, hydroxide on the right: O, C, and Br on one linedraw bromomethane view: lewisrotate bromomethane by: 90 degdraw 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 Carrow from: hydroxide.O.lone-pair3 to: bromomethane.C name: attackarrow from: bromomethane.bond(C, Br) to: bromomethane.Br name: leaveMakes: 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”
draw ammonia view: lewisdraw ammonium view: lewis right-of: ammonia gap: 3 bondanimate [ammonia, ammonium] name: protonation speed: 0.5Makes: 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”
draw ammonia view: lewisdraw ammonium view: lewis right-of: ammonia gap: 3 bondanimate [ammonia, ammonium] name: protonationchange protonation.pane1 title: "Base"change protonation.pane2 title: "Conjugate acid" hold: 3 schange protonation.change1 time: 1.5 s easing: ease-in-outMakes: 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”
draw hydroxide view: lewisdraw bromomethane view: lewis right-of: hydroxide gap: 2 bondanimate [[hydroxide, bromomethane]] name: sn2arrow from: hydroxide.O.lone-pair1 to: bromomethane.C name: attackarrow from: bromomethane.bond(C, Br) to: bromomethane.Br name: leave# the next pane is what the arrows make: methanol and bromide, drawn afreshnext-step sn2 layout: redrawMakes: 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”
# the diene s-cis (its two ends facing the dienophile), ethene beside themdraw 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 bondanimate [[butadiene, ethene]] name: diels_alder# three arrows in one cycle: the new sigma bonds at the ends, the remaining pi bond moves to C2-C3arrow from: butadiene.bond(C1, C2) to: ethene.C1arrow from: ethene.bond(C1, C2) to: butadiene.C4arrow from: butadiene.bond(C3, C4) to: butadiene.bond(C2, C3)next-step diels_alder name: cyclohexene layout: redrawMakes: 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”
# 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 bondanimate [[propene, hbr]] name: additionarrow from: propene.bond(C1, C2) to: hbr.Harrow 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 itarrow from: step2-2.Br.lone-pair3 to: step2-1.C2 bow: leftnext-step addition name: product layout: redrawMakes: 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”
# 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 needsdraw 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 oneshow lone-pairs of: ethoxideanimate [[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 pairarrow from: ethoxide.O.lone-pair2 to: substrate.Harrow from: substrate.bond(H, C1) to: substrate.bond(C1, C2)arrow from: substrate.bond(C2, Br) to: substrate.Brnext-step e2 name: products layout: redrawMakes: 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”
# the alpha H written into the SMILES ([H]) so an arrow can reach it; the second acetaldehyde waits in the same panedraw hydroxide smiles: "[OH-]" view: lewisdraw donor smiles: "[H]CC=O" view: bondline coords: [(0, 0), (0.866, -0.5), (0.866, -1.5)] right-of: hydroxide gap: 1 bonddraw acceptor smiles: "CC=O" view: bondline right-of: donor gap: 1.5 bondshow lone-pairs of: donorshow lone-pairs of: acceptoranimate [[hydroxide, donor, acceptor]] name: aldol# 1. the base takes the alpha H: the enolatearrow from: hydroxide.O.lone-pair2 to: donor.Harrow from: donor.bond(H, C1) to: donor.bond(C1, C2)arrow from: donor.bond(C2, O) to: donor.Onext-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: horizontalarrow from: s2-2.O.lone-pair1 to: s2-2.bond(C2, O)arrow from: s2-2.bond(C1, C2) to: s2-3.C2arrow from: s2-3.bond(C2, O) to: s2-3.Onext-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.H2arrow from: s3-1.bond(O, H2) to: s3-1.Onext-step aldol name: product layout: redraw# four panes do not fit across a page: two rows of twoarrange aldol as: grid columns: 2Makes: 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”
# 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 itpreset acs1996cleanup aspirinchange 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”
draw chloride view: lewisdraw bromomethane view: lewis right-of: chloride gap: 2 bonddraw chloromethane view: lewis below: chloride gap: 4 bonddraw bromide view: lewis right-of: chloromethane gap: 2 bond# reactants in the first pane, products in the second, no arrows: mechanism computes themanimate [[chloride, bromomethane], [chloromethane, bromide]] name: sn2mechanism sn2Makes: 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”
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: Clrename ethanol to: chloroethaneMakes: 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
Section titled “Box the answer in red, dashed”
draw acetic-acid view: lewis caption: titlebox acetic-acid color: red dash: dashed padding: 0.6 bond name: answerMakes: 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.