MolGFX
Commands

Writing queries and commands

How to pick atoms with a MolFrame query, and how the command language uses them.

Two small languages work together in MolGFX:

  • A query picks atoms: resname HEM, protein and chain A, byres (within 5 of resname HEM) and protein. It is MolFrame's selection language, used unchanged.
  • A command does something with a query: show cartoon, protein, color orange, $pocket. Commands are text you pass to Session.execute().

In a command, the query always comes after the comma:

show cartoon, protein
│    │        └─ query: which atoms
│    └─ form: how to draw them
└─ verb: what to do

Try it

Open a session over a structure and run a program on it:

import molframe
import molgfx

structure = molframe.read("4hhb.cif").infer_bonds()
session = molgfx.Session(structure)
show cartoon
show spacefill, resname HEM
select pocket, byres (within 5 of resname HEM) and protein
show licorice, $pocket
color orange, $pocket

Pass the program to session.execute("..."); session.completions(text, cursor) lists what could come next. To test a query without drawing anything, ask MolFrame how many atoms it selects:

len(structure.select("byres (within 5 of resname HEM) and protein"))   # 758

Queries at a glance

You wantWrite
Everythingall (or leave the target out: show cartoon)
A kind of moleculeprotein, nucleic, water, ligand, polymer, hetero
Residues by nameresname HEM, resname HIS HEM
A chainchain A, chain A B
Residue numbersresid 87, resid 1:10
Atoms by namename CA, name N CA C O, name C*
Elementselement Fe, element C N
A numeric conditionbfactor > 50
Both / either / notprotein and chain A, water or ligand, not water
Near somethingwithin 5 of resname HEM, around 5 resname HEM
Whole residuesbyres (within 5 of resname HEM)
A selection you named$pocket

Keywords are case-insensitive; values such as residue names are not (resname HEM, not hem). not binds tightest, then and, then or; add parentheses whenever you mix and and or. Every keyword, column and operator is in the MolFrame query reference.

Names: $selection and @layer

  • select pocket, QUERY names a selection. Refer to it as $pocket in any later query. It is a definition, not a frozen list of atoms: redefining it moves everything that uses it.
  • show FORM as pocket, QUERY names a layer (one drawn representation). Refer to it as @pocket in hide, remove, opacity and color.
select heme, resname HEM
select pocket, byres (within 5 of $heme) and protein
show ball_and_stick as pocket, $pocket
opacity 0.5, @pocket
select pocket, byres (within 8 of $heme) and protein   # @pocket follows

Without as, a layer is named after its form: show cartoon makes @cartoon.

Recipes

GoalProgram
Protein as cartoon, ligands as sticksshow cartoon, protein; show licorice, ligand
A binding pocketselect pocket, byres (within 5 of resname HEM) and protein then show licorice, $pocket
One chain onlyshow cartoon, chain A
Backbone traceshow licorice, protein and name N CA C O
Side chains of a residue rangeshow licorice, protein and resid 50:60 and not name N CA C O
Hide the watersshow spacefill, water then hide @spacefill
Colour by chain, highlight one residuecolor chain, @cartoon; color yellow, resid 87
Frame the ligandfocus resname HEM

Commands

CommandDoes
select NAME, QUERYdefine or redefine $NAME; everything using it follows
unselect NAMEremove a named selection nothing uses
show FORM [control=value]... [duplicate] [as LAYER] [in STRUCTURE] [, QUERY]draw a query with a form (all atoms when the query is left out)
show @LAYERreveal a hidden layer
hide @LAYER, remove @LAYERhide a layer, or remove it
color COLOR [in STRUCTURE] [, TARGET]colour a layer (@name) or the atoms of a query in every layer
uncolor [in STRUCTURE] [, QUERY]remove colour rules
opacity VALUE, @LAYERset a layer's opacity, 0 to 1
focus TARGET, unfocushighlight and frame a target, or clear it
undo, redostep through history
plane JSONadd a finite rectangular guide owned by a structure; undo removes it

Separate statements with ; or new lines. A program runs as one edit: if any statement fails, nothing changes.

Forms and their controls: cartoon (width, style), ball_and_stick (radius, bond_radius), spacefill (radius), licorice (radius, bond_radius), lines (width), points (size), surface (kind, style, probe_radius, isolevel), nucleic_acid (width), bases (radius), base_pairs (radius, bond_radius), glycan (width). Every form also takes color= and opacity=: show licorice bond_radius=0.2 color=orange, ligand.

Colours: a scheme (element, chain, residue, secondary_structure), a name (red, orange, slate, …), or #rrggbb.

Planar guides

plane takes a complete scene-space rectangle. Coordinates and full dimensions are in ångström; the outline width is in pixels. The normal and tangent must be non-zero and independent. The rectangle follows its owning structure placement and remains visible when molecular layers are hidden. It draws an outline, not a filled surface.

plane {"structure":1,"center":[0,0,0],"normal":[0,0,1],"tangent":[1,0,0],"size":[4,2],"color":[226,232,240,255],"width_pixels":1.6,"opacity":1}
undo
redo

The same command runs through Python Session.execute. Rust callers can add a PlaneSpec with Scene::add; patches use add_plane and remove_plane.

When something goes wrong

Errors point at the problem and suggest a fix:

error: 'shwo' is not a command; did you mean 'show'?
  --> line 1, column 1
   | shwo cartoon, protein
   | ^^^^
SymptomLikely cause
'protein' is not a formthe query went where the form belongs: show cartoon, protein
unknown selection keyworda typo in the query, such as resnam HEM
selection requires data this structure does not carrybackbone, sidechain, ion, … need chemistry annotations; write protein and name N CA C O instead of backbone
A query matches nothingcheck the case of values (HEM, not hem), and try it alone with len(structure.select(...))
Sticks without bondsmmCIF lists only the bonds between residues; call structure.infer_bonds()

On this page