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.

Molkit Script

Molkit Script describes a figure in a few plain lines: which molecules, in which views, where they go, and what is written under them. When you run a script, Molkit makes the figure on the canvas as one undo step. The same script makes the same figure every time, so you can rebuild, change, and share a figure as text.

draw water view: lewis
derive water views: [vsepr]
draw ammonia view: lewis right-of: water
write "Two molecules with a lone pair" below: water

To open the console, click Molkit Script (the code button near the bottom of the tool palette, above AI chat), or press Ctrl+` (Cmd+` on a Mac). Press the same keys inside the console to close it.

The console opens in a panel under the canvas. The canvas becomes shorter, so nothing on it is covered. The console has a title bar, a row of buttons, the script box at the left, and the log at the right. When the panel is narrow, the log is under the script box.

The AI chat has its own window. To open it, use any of these:

  • The AI chat button at the bottom of the tool palette.
  • The AI chat button at the right of the console’s button row.
  • More > Open AI chat in the console’s title bar.

The chat opens in a panel at the right of the canvas, so you can see the canvas, your script, and the conversation at the same time. The AI works on the script in the console’s script box, so you see its changes there. The AI chat needs your own API key from an AI provider such as Anthropic or OpenAI; see Set up your key.

Control What it does
Run (Ctrl+Enter) Runs the whole script as one undo step. If any line fails, nothing the script did stays.
Step (Ctrl+Shift+Enter) Runs one line at a time; each line is its own undo step. Run rest finishes the script; Stop ends it.
Check Finds every problem without running anything.
Record Writes what you do on the canvas as script lines.
Examples Searchable example scripts with their pictures (the same ones as the Cookbook). Insert puts one in the script box without running it. If the box already holds a script, you choose Replace or Add at the end.
Reference Every command with its options, the error codes, and the list of species names that Molkit recognizes. You can search it; a command’s Insert puts a template line at the cursor.
Copy, Copy with notes, Open in editor (under each run in the log) Copy the run’s commands, or the commands and the notes, as a script; or put the commands in the script box. See The log.
Clear log (above the log) Empties the log.

The More button (…) in the title bar holds the rest:

Item What it does
Open… / Save… Opens or saves a .mkscript file. You can also drop a file on the console.
Text size Sets the size of the text. See Text size.
Theme Match Molkit, Light, or Dark. The AI chat uses the same choice.
Move to Puts the console in the panel at the Bottom, in the panel at the Right, in a window that Floats over the canvas, or in a browser window of its own (Pop out). See Where the windows sit.

As you type, the script box colors the language, suggests commands, names, and options, and underlines each problem at the word it is about. To see help for a word, hover over it. To go to the next problem, press F8.

The help card for a command lists its options as links. Click an option, or Open in docs at the bottom of the card, to open its entry from the Command reference in the Docs pane. To open the entry for the command or option at the cursor without the mouse, press F1 in the script box.

The Docs pane docks at the right of the canvas. Like the console, it can move to the Bottom, Right, or Float under More (…) > Move to, and your browser remembers its place. Links inside the pane open their entries in the pane; Back and Forward move through the entries you opened, as in a web browser. Alt+Left, Alt+Right, and the back and forward buttons of a mouse do the same while the pointer or focus is on the pane. Open on docs site opens the same entry on docs.molkit.com in a new browser tab. To close the pane, click its close button, or press Escape twice.

The pane shows the same entries as the Command reference. For a language word such as foreach, let, recipe, defaults, or last, Open in docs and F1 open its section of The language on docs.molkit.com in a new tab.

The log is a script. Each line that made or changed something is shown as the full command that ran: loops are unrolled, names are filled in for last and selection, and the options a command chose or took from defaults are written out. Everything else is a comment line that starts with #:

  • A note from Molkit, for example # note: nitrate: bracket (charge: auto): a small ion, bracketed as a whole (GR-5.7), is gray.
  • A skipped line or a layout warning is amber.
  • An error, for example # error line 2: E-NAME There is no object named ethanl., is red. When Molkit can suggest a word, buttons under the error put that word in the script box; they are not part of the script.

Because every line is a command or a comment, whatever you copy from the log runs as it is. Under each run, Copy copies the commands only, and Copy with notes copies the commands with the comment lines in between. Open in editor replaces the script in the box with the commands (Ctrl+Z in the box takes it back). You can also select lines in the log with the mouse and copy them: the run’s heading and time, its end line, the tables from describe and help, and the buttons are left out of what you copy. The number at the left of a line selects that line in the script box.

To make the text in the console larger or smaller, click More (…) in the console’s title bar, and then choose a size under Text size: 85%, 100%, 115%, 130%, or 150%. You can also press these keys while you are in the console:

  • Ctrl+= makes the text one step larger.
  • Ctrl+- makes the text one step smaller.
  • Ctrl+0 sets the text back to 100%.

On a Mac, use Cmd instead of Ctrl. The size changes the script box, the log, the Examples and Reference sheets, and the help and suggestions in the script box. The title bar and the buttons stay the same size. The console and the AI chat window share one text size, and your browser remembers it. These keys change only the text size; they do not zoom the page or the canvas.

The console and the AI chat can each sit in one of three places in Molkit, or in a browser window of their own (see Pop out). To move a window, click More (…) in its title bar, and then choose Move to > Bottom, Right, or Float. Your browser remembers each window’s place and the size of each panel.

  • Bottom: a panel under the canvas. To change its height, drag its top edge. The canvas always keeps at least 240 pixels of height.
  • Right: a panel at the right, from the toolbar to the status bar. To change its width, drag its left edge (320 to 560 pixels).
  • Float: a window over the canvas that you can move by its title bar and size by its edges.

When both windows are in the same panel, they become tabs. Click a tab, or use the left and right arrow keys on it, to change windows. Moving a window keeps everything in it: your script and its undo history, the log, the conversation, and a message you have not sent.

To fold a panel out of the way, click the collapse button (the arrow) in the window’s title bar. The bottom panel folds to its title bar, and the right panel folds to a narrow strip with the window’s name on it. Click the title bar or the name to open the panel again.

Keys What they do
Ctrl+J Folds or opens the bottom panel. If it is closed, opens the windows that sit there.
Ctrl+Alt+B Folds or opens the right panel.
F6 / Shift+F6 Moves the keyboard focus between the canvas, the console, and the AI chat.
Escape In the script box or the chat’s message box, closes a list or menu that is open. With nothing open, moves the focus to the window itself; press Escape again to close the window.

On a narrow screen (under about 1,100 pixels wide), opening one panel folds the other. On a very narrow screen (600 pixels or less), both windows sit in the bottom panel as tabs. In the LaTeX animation workspace, the bottom panel folds when the workspace opens, because the workspace has its own panes at the bottom; the right panel stays. In presentation mode, both panels fold.

To put the console or the AI chat in a browser window of its own, click More (…) in its title bar and choose Move to > Pop out, or click the pop-out button (the box with an arrow) in the title bar. The new window opens at the size the window had in Molkit. You can drag it anywhere, size it by its edges, or move it to another monitor. Everything in the window goes with it: your script, its selection and its undo history, the log, the conversation, a request the AI is working on, the mode, and a message you have not sent.

What the new window looks like depends on your browser:

  • Chrome and Edge 116 or later, and Firefox 151 or later (desktop) open a small window with no address bar. It stays on top of your other windows. A browser allows only one such window for each tab, so when you pop out both the console and the AI chat, they share it as tabs.
  • Other browsers open a pop-up window. Firefox shows a read-only address bar at the top of a pop-up window, and Chrome shows a thin bar with the address; a web page cannot remove them. Each window gets a pop-up window of its own. If your browser blocks pop-ups, Molkit tells you; allow pop-ups for Molkit, and then choose Pop out again.

Keys work in the new window as they do in Molkit: Ctrl+Enter runs the script, Enter sends a message, Escape closes a list or panel, and the text size keys change the text in both windows. Changes to the theme and the text size in Molkit show in the new window at once. A script you run there draws on the canvas in Molkit.

To bring a window back, do one of these:

  • Close the browser window with its own close button. The window goes back to its place in Molkit (the bottom panel, the right panel, or floating), with everything in it.
  • Click More (…) and choose Move to > Back into Molkit, or click the bring-back button (the arrow into a box) in the title bar. To put it in another place instead, choose Bottom, Right, or Float.

The window’s own close button (X) in its title bar closes the window as it does in Molkit: the browser window closes, and the next time you open the window, it is in its place in Molkit with everything in it. While a window is popped out, the Molkit Script and AI chat buttons in the tool palette have a dashed outline; click one to bring that window to the front.

If you reload Molkit or close its tab, the popped-out windows close. After a reload, each window is in its place in Molkit, and the console has your script, its file name, and its selection again. Your browser keeps the script for this tab until you close the tab. Popping out a window does not store your AI key.

The undo history of the script box comes along with the window, one step for each word you typed. Redo (Ctrl+Shift+Z) does not carry over: after a pop out or a bring back, you can undo but not redo the steps you undid before.

  • A run is one undo step. Ctrl+Z takes back the whole run.
  • A failed run changes nothing. The error names the line and column and says what to do. See Error codes.
  • Read-only commands leave no undo step. This applies to describe, explain, and help, and to Check.

A script refers to objects by name. An object a script makes gets the name the script gives it (draw water makes water). Every other object on the canvas gets a name the first time a script runs: molecules you drew by hand become molecule-1, molecule-2, and so on, and texts, arrows, shapes, brackets, and images become text-1, arrow-1, shape-1, and so on. Names are saved with the document.

describe lists every object by name, with what it is and where it is, followed by the document’s settings and what you have selected:

describe

selection means whatever you had selected when the run started. To try it, select something on the canvas, then run:

change selection color: blue

The log writes the names that selection stood for, so the line still means the same objects when you run the script again.

The language page has the rules. In brief:

  • Parts. A dot path names a piece of a molecule: water.O (an atom), water.bond(O, H1) (a bond), water.O.lone-pair1 (a lone pair). describe water lists them. See Parts.
  • Curved arrows. An arrow from a lone pair or a bond to an atom or a bond is a curved mechanism arrow, attached at both ends: arrow from: water.O.lone-pair2 to: hydrogen-chloride.H. See Curved arrows.
  • Ions and salts. charge: auto (the default) follows IUPAC: a charge spread over an ion goes after a square bracket, and a charge on one atom stays on that atom. charge: bracket and charge: atom override it. A salt drawn by name (draw "potassium hydrogen phthalate") is drawn as its ions side by side. A repeated ion is drawn once with its count; repeats: each draws every copy. See Ions and Salts.
  • Equations. Reactions are written in plain LaTeX: upright formulas, ~ after a coefficient, and \longrightarrow for a reaction. If you use the mhchem package, \ce{...} works too. See Equations and formulas.
  • Structure edits. change sets a bond’s order or style and an atom’s element, charge, lone pairs, or radicals; add and delete add or delete atoms, bonds, and lone pairs: add water.O atom: H, delete water.H1. See Adding and deleting atoms and bonds.
  • Animations. animate [reactants, products] name: sn2 makes a structure animation with one pane for each object, framed where it is. A list inside the list is one pane that holds several objects: animate [[nucleophile, substrate], ts, products] name: sn2. Open animation mode to preview it, match the changes, and export it. animate start name: sn2 makes an animation of one pane, and next-step sn2 adds the pane its curved arrows make, as the toolbar’s Next Step does (the new molecules are named sn2-p2, or sn2-p2-1 and sn2-p2-2). add product into: sn2 adds a pane (add [x, y] into: sn2 adds one that holds both), remove ts from: sn2 removes one, arrange sn2 as: grid lays the panes out, change sn2.pane2 hold: 2 s and change sn2.change1 time: 1.5 s easing: ease-in-out set its timing (change sn2 duration: 8 s fits the whole), duplicate sn2 makes a copy with its own molecules beside it, describe sn2 lists its panes and changes, and export sn2 writes its animated SVG. A pane grows when a script adds to what it holds. See the Command reference.
  • Boxes. box [water, ammonia] color: red draws a rectangle around objects, as the Shape tool does, for a boxed answer or a group to point out. See the Command reference.

Record turns what you do by hand into script lines. To see the script, click Stop recording; then copy it or open it in the editor.

Record writes these actions as script lines:

  • Drawing, importing, or pasting a molecule. Molkit writes it as a draw line when a later line needs it or when you click Stop recording. The script draws it with the Molkit layout, so its orientation can differ from your drawing.
  • Typing a new text or inserting a LaTeX equation.
  • Deleting a molecule or text that the recording wrote, or deleting everything.
  • Moving a molecule, a text, or a whole set, by dragging, with the arrow keys, or with the align and distribute buttons.
  • Turning a molecule the recording wrote with Rotate, or mirroring it with Flip Horizontal or Flip Vertical: a rotate or flip line, then a place line that puts it where you left it, such as rotate ethanol by: 30 deg or flip ethanol direction: vertical.
  • Derive View, the Resonance submenu’s Generate Forms and Generate Octet Forms, and Build Orbital Picture.
  • Show Lone Pairs, Show Implicit Hydrogens, Show Atom Numbers, Show Stereo Labels, and Show net dipole.
  • Choosing the Traditional, Compact, or Textbook preset, or a color scheme.
  • An SVG or PNG file from Batch Export of one molecule or a set. A PNG line keeps its scale and a transparent background. A padding other than 20, or a background color other than white, is noted in a comment.
  • Changing a bond’s order, style (a wedge, a hash, a wavy bond, and so on), or color, or an atom’s lone pairs, radicals, or color, on a molecule the recording wrote. A color given to the whole molecule is one line, change water color: red. Each is written as a change line, such as change ethanol.bond(C2, O) order: 2 or change water.O radicals: 1. On a molecule you drew by hand, a copy made from one, or a molecule you edited by hand earlier, a change is written as a change line only when each atom it names is not hydrogen and is the only atom of its element in the molecule, such as the O of ethanol. Other changes to that molecule are written as a comment.
  • Changing the words, color, size, font, or style of a text the recording wrote, when the whole text has one style: change text-1 text: "Ice".
  • In an animation: its title, a pane’s title, leaving a pane out of playback, its speed, and a change’s motion (Easing). Each is a change line, such as change sn2.pane2 title: "Transition state" or change sn2.change1 easing: ease-in-out. Other animation edits, such as a hand-set time or a moved frame, are written as one comment.
  • Every script that runs while you record.

Any other change is written as a comment that starts with # not scriptable yet:. This includes editing a molecule after the recording wrote it (adding or deleting atoms or bonds, changing an element or a charge, taking a color off, or moving one atom or lone pair), drawing arrows, shapes, brackets, or images, styling part of a text (one bold word), other changes in Structure Settings, other animation edits, Page Setup, grouping or ungrouping, and changing the order of layers.

Files from Export SVG, Export PNG, and Export PDF are not recorded and leave no comment.