Your first script
In this tutorial you build a figure from an empty canvas: three molecules, each with its 3D shape, captioned and laid out, with a title. Then you build a second, short figure: hydrogen chloride giving its proton to water, with curved arrows between parts of the molecules.
Before you start
Section titled “Before you start”Each run adds to what is already on the canvas, and a name can be used only once in a document. If you run draw water a second time, the run stops with E-TAKEN (“water already exists”). So when a step runs the same molecules again, it tells you to clear the canvas first: click the canvas, press Ctrl+A, then press Delete. You can also press Ctrl+Z on the canvas to take back the whole last run.
Build the figures
Section titled “Build the figures”-
Open the console. Press Ctrl+` (Cmd+` on a Mac), or click Molkit Script in the tool palette. Clear the example in the box: select all of it and delete it.
-
Draw one molecule. Type this line and press Ctrl+Enter:
draw water view: lewisWater appears as a Lewis structure, named
water, and the log says what the line did.view: lewisasks for the Lewis view;bondlineis the other view thatdrawmakes. -
Make its shape.
derivemakes other views of a molecule. Replace the script with these two lines and run them:draw ammonia view: lewisderive ammonia views: [vsepr]Ammonia appears next to the water from step 2, and its VSEPR copy, named
ammonia-vsepr, appears to its right. -
Do the same for several molecules with a loop. Replace the script with this one, clear the canvas, and run it:
foreach m in [water, ammonia, methane] {draw m view: lewis caption: titlederive m views: [vsepr]}mtakes each name in turn, andcaption: titlewrites each molecule’s name under it. Water is planar, so its Lewis drawing already shows its VSEPR shape: Molkit makes no copy, and the log says so. -
Keep each pair together in a set. A set holds a molecule and its views, and moves as one block. Replace the script with this one, clear the canvas, and run it:
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"{m.title}"builds each set’s name from the molecule’s title, andarrangestacks the three sets in a column. -
Add a title. Placement options put a new object relative to others, and
allmeans the box around everything. Add this line at the end of the script, clear the canvas, and run the whole script again:write "Lone pairs and shape" size: 14 pt style: bold above: all align: left -
Point at a part of a molecule. A dot path names a piece of a molecule:
water.Ois its oxygen,water.bond(O, H1)is a bond, andwater.O.lone-pair1is a lone pair. Replace the script with this one, clear the canvas, and run it:draw hydrogen-chloride view: lewisdraw water view: lewis right-of: hydrogen-chloride gap: 1.5 bondrotate water by: 45 degdescribe waterWater goes to the right of HCl, one and a half bond lengths away, and is turned so that one of its lone pairs faces the HCl.
The
describeline lists the parts of water and where each lone pair sits now:O (lone-pair1 top, lone-pair2 left), H1, H2. Solone-pair2is the pair that faces the H of HCl. Before the turn, the pairs sat top-right and top-left: a lone pair keeps its number when the molecule turns. -
Push the electrons with curved arrows. An
arrowfrom a part to a part is a curved mechanism arrow, attached at both ends. Replace thedescribe waterline with two arrows, clear the canvas, and run the script:draw hydrogen-chloride view: lewisdraw water view: lewis right-of: hydrogen-chloride gap: 1.5 bondrotate water by: 45 degarrow from: water.O.lone-pair2 to: hydrogen-chloride.Harrow from: hydrogen-chloride.bond(H, Cl) to: hydrogen-chloride.ClThe first arrow starts at the lone pair of water and ends at the H that the pair bonds to. The second starts at the H–Cl bond and ends at the Cl, which keeps that pair. An arrow starts where the electrons are (a lone pair or a bond) and ends where they go (an atom or a bond).

What the script draws: water’s lone pair goes to the H of HCl, and the H–Cl bond’s pair goes to the Cl. The arrows move with the molecules when you drag them. If an arrow bulges the wrong way, add
bow: leftorbow: right;bow: biggerorbow: smallerchanges its size. The rules are on the language page under Curved arrows. -
Check before you run. Make a typo on purpose: type
draw water veiw: lewisand click Check. Nothing runs. The problem is underlined at the word, with a fix: “Did you mean: view:?”. Correct the typo and click Check again; the log says “no problems”. -
See what is there. Run this line:
describeThe log lists every object by name, with what it is and where it is, then the document’s settings and what you have selected.
-
Save the script. Save… writes a
.mkscriptfile, and Open… (or dropping the file on the console) brings it back. The same script makes the same figure in any document.