Jmol/JSmol interactive scripting documentation



Search View Full Database Index

draw 

   ID [object id]
   [modifying parameters]
   [positions]
   [display options]


   See examples-11/draw.htm 

The draw command allows for the insertion of points, lines, and planes to a model. Objects with IDs that start with "_!_" indicates that the object should be displayed when only one frame is visible. The general syntax of the draw command is as follows:

draw [objectID] [modifying parameters] [positions]



ID [object id]    back

The optional identifier such as "line1" or "plane2" that can be referred to in later scripts as $line1 or $plane2. These words are arbitrary and if preceded by the optional keyword ID may be any string. Specifically for the options ON, OFF, and DELETE, the id may include a wildcard character (asterisk). Thus, draw v* off turns off all drawn objects having an ID starting with the letter "v".

[modifying parameters]    back

Several options allow for modifications of some or all of the object types described below. These include:
COLOR (color)Sets the color of the drawn object at the time it is created. (The color command can be used retroactively as well.)
CROSSEDTwo lines (already drawn objects) specified next are crossed; switch the order of vertices for defining a plane.
DELETEDeletes the object if an identifier is given or all drawn objects if none is given; not used with any other parameters. "*" can be used as a wild card either at the beginning or end of the identifier. For example, DRAW pt* DELETE.
DIAMETER nSets the number of pixels for the diameter of points, lines, arrows, and curves. Note that this means that zooming of the model does not change the width of these objects. n may be a decimal value x.x, same as WIDTH x.x.
DIAMETER n [x y %]Draws a sphere in the 2D window (in front of atoms) of size n x% from the left and y% from the bottom of the screen. For example, to create a key of elements and their colors:

  background white
  load $caffeine
  function createElementKey() {
    var y = 90
    var fontSize = _height*20/400
    for (var e in {*}.element.pivot){
      var c = {element=@e}.color
      draw ID @{"d_"+ e} diameter 2 [90 @y %] color @c
      set echo ID @{"e_" + e} [91 @{y-2} %]
      echo @e;
      font echo @fontSize bold sansserif
      color echo black
      y -= 5
    }
  }
  createElementKey()
DIAMETER n [x y]Draws a sphere in the 2D window (in front of atoms) of size n x pixels from the left and y pixels from the bottom of the screen.
FIXED/MODELBASEDSets whether the surface generated is to be associated with the fixed window -- and thus appear with all frames/models -- or is to be associated with the currently displayed model (the default).
LISTLists all DRAW objects. Not used with any other parameters.
ON/OFFTurns on or off the identified object or all drawn objects if no identifier is given; not used with any other parameters.
PERP
PERPENDICULAR
Draw this object perpendicular to the next indicated object.
REVERSEReverse the order of vertices used if the next object listed is a line.
ROTATE45Rotate a perpendicular plane to a line by 45 degrees.
LENGTH (decimal)The length for a line/axis in Angstroms. The keyword LENGTH is optional.
OFFSET {x y z} offsets the object by the given x, y, and z distances.
SCALE (decimal)
SCALE (integer)
SCALE with a decimal value indicates a scaling factor for the drawn object. For example, draw SCALE 1.5 (atomno=1) (atomno=2) draws a line with length 1.5 times the distance from atom 1 to atom 2. The line is centered on the two atoms. The keyword SCALE is required in this case. Note that a draw command can consist of just an identifier and a scale. Thus, if $line1 is already defined, draw line1 SCALE 1.3 will rescale that line to 130% of the distance between its defining points. SCALE with an integer number indicates a percent scale. The keyword SCALE is optional in this case.
VERTICES Generally the geometric center of an atom expression or drawn object is used for positioning. Added just before the atom set or object name reference, VERTICES indicates to use all vertices, not just the center point of the atoms in the expression or the points in the object.
WIDTH x.xSets the diameter of points, lines, arrows, and curves to a given width in Angstroms. Objects drawn will be scaled based on perspective and zoom setting.
TITLE "text" A simple text label can accompany drawn objects. The text appears near the first point. Text starting with ">" will be associated with the last point instead of the first. The ">" character will be stripped before the text is displayed. If set drawHover TRUE has been issued, this text will appear only when the object is hovered over. (Not applicable to composite drawn objects such as SYMOPS and SPACEGROUP.)
TITLE COLOR color sets the color of the title font.
TITLE FONT size face stylesets the font for the title. See the font command for details.


[positions]    back

Positions define position of the point, the endpoints of the line/axis, or the corners of a plane. Positions can be indicated in any combination of any of the following four ways. Mixed types are processed in the order given on the command line.

{x, y, z}a model-frame cartesian coordinate, in braces,
{x, y, z/}for crystal structures, a unit-cell fractional coordinate, in braces,
$objecta previously defined drawing object such as $line1 or $plane2, preceded by "$".
(atom expression)an atom expression, in parentheses.
@{ {atomExpression}.split()} atom expressions split based on model index .
In addition, if two parameters are given, where the first evaluates to a point and the second is a four-vector {a b c d}, a line is drawn from the point to the nearest point on the plane defined by ax + by + cz + d = 0. (Note that because quaternions and axisAngle are stored in quaternion format, which is internally the same as that used for planes, if a quaternion or axisAngle is used in this context, the line will be along the axis of rotation represented by the quaternion or axisAngle q to a point on a plane defined by d = q.w = cos(theta/2), where theta is the rotation angle).

[display options]    back

Display options for DRAW are indicated in the following table. These may be given at the end of the definition or in a later command having just these keywords and the identifier (or "ALL") of the desired draw object.

FILL/NOFILL Display the drawn opject as a smoothly filled surface.
FRONTONLY/NOTFRONTONLY Display only the front half of the surface. This can be useful when the options mesh nofill are used.
FRONTLIT /BACKLIT /FULLYLIT In some cases the object may appear flat. Using BACKLIT will fix this; FULLYLIT makes exterior and interior surfaces bright; FRONTLIT is the default setting.
MESH/NOMESH Display a mesh of lines intersecting at the vertexes used to construct the object. For cylinders, the combination MESH NOFILL creates a cylinder with no end caps.
ON/OFF Turn the object ON or OFF, but do not delete it.
OPAQUE/TRANSLUCENT n Display the object as an opaque or translucent object. Several translucent options are available; see the color command.


 draw ARC {pt1} {pt2} {ptRef} {nDegreesOffset theta fractionalOffset}

Draws a theta-degree arc in a plane perpendicular to the line pt1--pt2 starting at nDegreesOffset degrees rotation from reference point {ptRef} at a point fractionalOffset from pt1 to pt2. The SCALE parameter is used to set the diameter of the overall circle containing the arc; the DIAMETER parameter sets the diameter of the curved arc line itself. ARROW ARC adds an arrow head.

 draw ARC {pt1} {plane} {ptRef} {nDegreesOffset theta fractionalOffset}

As above, but uses the plane as a reference to define a perpendicular axis.

 draw ARROW {pt1} {pt2} {pt3} ...

Draws a straight (two-point) or curve (more than two-point) arrow. The keyword BARB indicates "fish-hook" half-arrows as for organic chemistry mechanisms involving radicals.

 draw ARROW [array of points]

Draws an ARROW based on an array of points.

 draw ARROW ATOM/BOND

The DRAW command can be used to draw organic "mechanistic arrows." You need to specify two atoms, two bonds, an atom and a bond, or a bond and an atom. Atoms are identified using the keyword ATOM followed by an atom expression; bonds are identified using the keyword BOND followed by two atom expressions. For example: draw ID "arrow1" ARROW ATOM @1 BOND @1 @2, which draws a curved arrow from atom 1 (atomno=1) to the middle of the bond connecting that atom to atom 2. These drawn objects are then "connected" to the atoms, so if the atoms are not displayed, the arrow is not displayed either. Of course, individual arrows can be hidden independently of their associated atoms as well.

 draw BEST BOUNDBOX atoms

Draws the best boundbox through a set of atoms. The atoms can be given as one or more atomsets.

 draw BEST LINE atoms

Draws the best line through a set of atoms. The atoms can be given as one or more atomsets.

 draw BEST PLANE atoms

Draws the best plane through a set of atoms. The atoms can be given as one or more atomsets.

 draw BOUNDBOX

Draws the currently defined boundbox. Note that by default this is a solid. To show just edges, use options MESH NOFILL.

 draw BOUNDBOX BEST

Draws the (approximately) best box around the selected set of atoms, not necessarily oriented by the x,y,z axes. Note that by default this is a solid. To show just edges, use options MESH NOFILL.

 draw BOUNDBOX atoms

Draws a boundbox with edges in the x, y, and z directions through a set of atoms, which may be given as one or more atomsets.

 draw BOUNDBOX $isosurfaceID

Draws a boundbox around the specified isosurface

 draw BOUNDBOX BEST $isosurfaceID

Draws the best boundbox around he specified isosurface

 draw CIRCLE {pt1} {pt2}

Draws a circle with center at pt1 (which may be an atom expression) in the plane perpendicular to the line between pt1 and pt2. If pt2 is not specified, the circle appears in 2D and remains in the plane of the screen when the model is manipulated. Together, the SCALE and DIAMETER parameters set the overall size of the circle. If no DIAMETER is given and an atom expression is given for pt1, the default diameter is one that includes those atoms; otherwise the default diameter is 1.0 Angstrom. The circle will be filled to form a solid disk unless the MESH NOFILL option is given.

 draw CIRCLE {pt1} {plane}

Draws a circle around pt1 in the indicated plane.

 draw CURVE {pt1} {pt2} {pt3} ...

Draws a smooth curve through the given positions.

 draw CURVE [array of points]

Draws a curve based on the array of points.

 draw CYLINDER {pt1} {pt2}

Draw CYLINDER creates a cylinder of the designated diameter. End caps can be set to closed/flat (FILL, the default) or open (MESH NOFILL).

 draw DIAMETER -1 ..

For lines or mesh option. Draws a simple line with 1-pixel width.

 draw DIAMETER -n ..

For lines or mesh option. Draws a dotted 1-pixel line with alternating n on, n off pixels.

 draw FRAME [atom-expression] {quaternion}

Draws a frame (an x,y,z axis set) at the given center with the given quaternion orientation. Quaternions are expressed using the quaternion() function within a math @{...} wrapper. For example, draw ID "q1" frame {0 0 0} @{quaternion(1,0,1,0)} draws a frame at the origin that has been rotated 90 degrees relative to the Y axis. (Jmol automatically normalizes the quaternion to q0=0.70710677, q1=0, q2=0.70710677, q4=0, which represents a 90-degree rotation about the Y axis.)

 draw HELIX AXIS

Draws a vector representing the local helical axis for the selected amino acid or nucleic acid residue, connecting it to the previous residue in its chain. The length of the arrow is the vertical height per residue.

 draw HKL {1 1 1 x.x}

Offsets an HKL plane from the origin by x.x Angstroms.

 draw HKL {1 1 1} OFFSET x.x

Alternative to HKL {1 1 1 x.x}

 draw HOVERLABEL " xxx "

Allows for a hover label that appears whether or not drawHover is on.

 draw "hover>xxx.... "

Used for saving the hover label in a state.

 draw INTERSECTION BOUNDBOX (plane expression)

Draws the portion of a plane that intersects the current boundbox based on a plane expression.

 draw INTERSECTION [unitcell or boundbox description] [line or plane description]

Intersects all types of boundboxes and unitcells with any type of plane or line.

 draw INTERSECTION [unitcell or boundbox description] ON [line or plane description]

Projects a unitcell or boundbox on any plane.

 draw INTERSECTION [unitcell or boundbox description] LINE @1 @2

Extends the specified line to intersect a unitcell or boundbox

 draw INTERSECTION UNITCELL (plane expression)

Draws the portion of a plane that intersects the current unit cell based on a plane expression.

 draw LINE [array of points]

Draws a set of line segments through the points. See also DRAW VERTICES.

 draw *xxx* ONLY

Shortcut for DRAW * OFF; DRAW *xxx* ON. Hides all but the designated DRAW objects.

 draw INTERSECTION UNITCELL uc LATTICE {na nb nc}

Draws a set of lattice points that are on a given plane; mostly for debugging. xxx can be an array [o a b c] or absent; plane can be PLANE or HKL and appropriate parameters.

 draw PLANE {pt1} {pt2} {pt3}

Creates a four-vertex quadrilateral even if only three points are given.

 draw POINTGROUP [parameters]

Calculates and draws point group symmetry planes and axes for a symmetrical or nearly symmetrical molecule. As for calculate pointgroup, the calculation is carried out only on the currently selected atoms and is limited to at most 100 selected atoms. Parameters include specification of a subset to draw (Cn, C2, C3, C4, C5, C6, C8, Sn, S3, S4, S5, S6, S8, S10, S12, Cs, Ci) optionally followed by an index (for example, draw POINTGROUP C3 2 draws the second C3 axis only). A second option, SCALE x, allows adjusting the scale of the drawn planes and axes. The default scale of 1 puts the edge of planes directly through the outermost atoms. This command automatically sets perspectiveMode OFF so as to properly represent the planes and axes.

 draw POINTGROUP {atoms} CENTER [atom-expression-or-coordinate]

Calculates and draws point group symmetry, optionally allowing only a subset of atoms to be used, for example ignoring hydrogens with {!_H}. Also optionally allows the center to be set to a specific coordinate or atom.

 draw POINTGROUP POLYHEDRON

Calculates and draws point group symmetry planes and axes for a polyhedron. One atom (one polyhedron) should be selected prior to this command.

 draw POINTGROUP SPACEGROUP

Draws the crystal class symmetry operations for a space group

 draw POINTS [array of points]

The POINTS option creates a set of points. For example, load $caffeine; draw POINTS [@5 @7 @12 @13 @1 @3].

 draw POLYGON [array of points]

This simple POLYGON option creates a polygon from a list of points. For example, load $caffeine; draw polygon [@5 @7 @12 @13 @1 @3].

 draw POLYGON [array of indices] [array of points]

This POLYGON option draws one polygon based on an array of integers (the "face") and an array of points that the indices of the face point to. The array of points is optional and defaults to {*}.xyz.all. For example,

  load $p4
  x = {*}.find("*1**1","map")
  draw ID p4r polygon @{x[1]} color red
  draw ID p4b polygon @{x[2]} color blue
  draw ID p4y polygon @{x[3]} color yellow
  draw ID p4g polygon @{x[4]} color green

 draw POLYGON [polygon definition]

This POLYGON option draws one or more polygons based on a set of vertices and a set of faces. This capability allows drawing any number of flat triangular (not quadrilateral, but read on...) faces with or without edges around each face. The description is somewhat like that for PMESH files and involves (a) giving the number of vertices, (b) listing those vertices, (c) giving the number of faces, and (d) listing the faces with a special array syntax. Each face is described as an array indicating the three (0-based) vertex indices followed by a number from 0 to 7 indicating which edges to show a border on when the mesh option is given:

0 no edge
1 edge between first and second vertex
2 edge between second and third vertex
4 edge between third and first vertex
3, 5, 6, 7 combinations of the above.
For example: draw POLYGON 4 {0 0 0} {1 1 1} {1 2 1} {0 5 0} 2 [0 1 2 6] [0 3 2 6] mesh nofill. The points and faces can be provided as arrays: draw POLYGON @points @faces mesh nofill, where in this example, points is an array of the four points, and faces is [[0 1 2 6] [0 3 2 6]].

 draw POLYHEDRON [array of arrays of atom indices] [array of points]

This POLYHEDRON option creates a set of polygons, collectively forming (possibly) a polyhedron from an array of arrays of indices (that is, an array of faces) and an optional array of points, which defaults to {*}.xyz.all. For example, load $caffeine; draw POLYHEDRON @{{*}.find("*1****1||*1*****1","map")} fills in the 5- and 6-membered aromatic rings with a colored surface. load $p4; draw POLYHEDRON @{{*}.find("*1**1","map")} fills in the faces of tetrahedral tetraphosphorus. The faces need not be wound correctly.

 draw QUATERNION [parameters]

Draws vectors for the previously selected residues representing the quaternion frame and rotational axis for each residue. The parameters for this command are the same as for plot quaternion or the quaternion command. Vectors are named based on the axis (x, y, z, q), residue number, and chain.

 draw RAMACHANDRAN

Draws curved arrows marked with PHI and PSI angles in planes perpendicular to the N-CA and CA-C bonds of the selected amino acids, respectively.

 draw SLAB $id PLANE (plane expression)

Creates a DRAW object based on DRAW object $id, which must be of POLYGON type, that is slabbed based on a plane definition. For example: draw p4 polygon 4 {0 0 0} {0 3 0} {3 3 0} {0 3 3} 2 [0 1 2 0] [2 3 0 0]; draw p4 slab $p4 PLANE @{plane({0 0 0}, {5 0 0})}

 draw SPACEGROUP

Draws the symmetry elements of the representative set of symmetry operations (the operations generally given in a CIF file) for the current space group.

 draw SPACEGROUP ALL

Draws symmetry elements of the representative operations of the current space group, including all translations of those operations that intersect with the unit cell. Essentially a 3D interactive "space group diagram."

 draw SPACEGROUP @n

Draws symmetry elements of all representative operations for which the specified atom (in the current model only) is invariant except for lattice translation. If the atom is in a general position, nothing is drawn. For example:

load =ams/marcasite 1 packed
draw spacegroup @3

-x,y,z mirror plane
x,-y,-z C2 axis
-x,-y,-z Ci: 0 0 0

 draw SPACEGROUP @n i

Draws the i-th operation for which the specified atom (in the current model only) is invariant except for lattice translation. If the atom is in a general position, nothing is drawn. For example:

load =ams/marcasite 1 packed
draw spacegroup @3

x,-y,-z C2 axis

 draw SYMOP [n or "x,y,z"] {atom expression}

Draws a graphic representation of a crystallographic space group symmetry operation. Operations include simple rotations, screw rotations, rotation-inversions, mirror planes, and glide planes, Either a number (for one of the model's symmetry operations) or a string indicating a Jones-Faithful operation may be used. The position may be an atom expression may be a point. If a point, it can be expressed either as a cartesian coordinate or a fractional coordinate (using a "/" in at least one position -- for example, { 1/2 0 0}. The ID of the draw command is prepended to the drawn object IDs. For example, draw ID "s1" SYMOP "x,1/2-y,z" {1/2 1/2 1/2}. See also the Jmol Crystal Symmetry Explorer.

 draw SYMOP {atom expression} {atom expression}

Draws the symmetry relations between any two atoms or groups or any two positions in space. For example, draw SYMOP {molecule=1} {molecule=2}.

 draw SYMOP (integer) {atom expression} {atom expression}

Draws the symmetry relation associated with the specified symmetry operator between any two atoms or groups or any two positions in space. For example, load =ams/quartz 1 packed;draw symop 2 @1 @3.

 draw SYMOP {atom expression} {atom expression} (integer)

Draws the nth symmetry operator for special positions, where multiple symmetry operations relate two positions in space. For example, load =ams/quartz 1 packed;draw symop @1 @3 1.

 draw SYMOP [3,4,5] @1

Draws the given array of symmetry operations (1-based) for atom 1.

 draw SYMOP @2 OFFSET {lattice offset}

Draws the symmetry operation targeting a given normalized lattice offset, where {0 0 0} is always into the unitcell [0, 1).

 draw SYMOP [matrix]

Draws the symmetry operation associated with the given 4x4 matrix, which most likely comes from a variable, for example here the symmetry operation that is the product of two other symmetry operations: draw SYMOP @{symop(11)*symop(14)}.

 draw UNITCELL

Draws the currently defined unitcell. Note that by default this is a solid. Default rendering for UNITCELL is MESH NOFILL.

 draw UNITCELL xxx LATTICE {default: na nb nc}

Draws a set of lattice points, including lattice centering; mostly for debugging; possibly useful

 draw UNITCELL AXES

Draws the currently defined unitcell along with colored axes.

 draw VECTOR {pt1} {pt2}

This option is similar to ARROW, and accepts two points. The first point is the origin; the second is of the form {dx,dy,dz}, indicating a vector to the next point rather than the point itself.



Examples:

   See examples-11/draw.htm 


See also:

undefined



top search index

Index (full)


draw 
draw ARC {pt1} {pt2} {ptRef} {nDegreesOffset theta fractionalOffset}
draw ARC {pt1} {plane} {ptRef} {nDegreesOffset theta fractionalOffset}
draw ARROW {pt1} {pt2} {pt3} ...
draw ARROW [array of points]
draw ARROW ATOM/BOND
draw BEST BOUNDBOX atoms
draw BEST LINE atoms
draw BEST PLANE atoms
draw BOUNDBOX
draw BOUNDBOX BEST
draw BOUNDBOX atoms
draw BOUNDBOX $isosurfaceID
draw BOUNDBOX BEST $isosurfaceID
draw CIRCLE {pt1} {pt2}
draw CIRCLE {pt1} {plane}
draw CURVE {pt1} {pt2} {pt3} ...
draw CURVE [array of points]
draw CYLINDER {pt1} {pt2}
draw DIAMETER -1 ..
draw DIAMETER -n ..
draw FRAME [atom-expression] {quaternion}
draw HELIX AXIS
draw HKL {1 1 1 x.x}
draw HKL {1 1 1} OFFSET x.x
draw HOVERLABEL " xxx "
draw "hover>xxx.... "
draw INTERSECTION BOUNDBOX (plane expression)
draw INTERSECTION [unitcell or boundbox description] [line or plane description]
draw INTERSECTION [unitcell or boundbox description] ON [line or plane description]
draw INTERSECTION [unitcell or boundbox description] LINE @1 @2
draw INTERSECTION UNITCELL (plane expression)
draw LINE [array of points]
draw *xxx* ONLY
draw INTERSECTION UNITCELL uc LATTICE {na nb nc}
draw PLANE {pt1} {pt2} {pt3}
draw POINTGROUP [parameters]
draw POINTGROUP {atoms} CENTER [atom-expression-or-coordinate]
draw POINTGROUP POLYHEDRON
draw POINTGROUP SPACEGROUP
draw POINTS [array of points]
draw POLYGON [array of points]
draw POLYGON [array of indices] [array of points]
draw POLYGON [polygon definition]
draw POLYHEDRON [array of arrays of atom indices] [array of points]
draw QUATERNION [parameters]
draw RAMACHANDRAN
draw SLAB $id PLANE (plane expression)
draw SPACEGROUP
draw SPACEGROUP ALL
draw SPACEGROUP @n
draw SPACEGROUP @n i
draw SYMOP [n or "x,y,z"] {atom expression}
draw SYMOP {atom expression} {atom expression}
draw SYMOP (integer) {atom expression} {atom expression}
draw SYMOP {atom expression} {atom expression} (integer)
draw SYMOP [3,4,5] @1
draw SYMOP @2 OFFSET {lattice offset}
draw SYMOP [matrix]
draw UNITCELL
draw UNITCELL xxx LATTICE {default: na nb nc}
draw UNITCELL AXES
draw VECTOR {pt1} {pt2}


last updated: May 04, 2025 11:01:10

html

xml docbook