CGO Shapes: Difference between revisions

From PyMOLWiki
Jump to navigation Jump to search
(Create page)
 
(Add examples and CONE)
Line 3: Line 3:
===CGO Commands===
===CGO Commands===


From an old version of the User Manual (and updated with current information):
Based on an old version of the User Manual:


<pre>
<pre>
Line 36: Line 36:
           red2, green2, blue2,           
           red2, green2, blue2,           
           red3, green3, blue3,           
           red3, green3, blue3,           
CONE,      x1, y1, z1,
          x2, y2, z2,
          r1, r2,
          red1, green1, blue1,         
          red2, green2, blue2,         
          cap1, cap2  # should the ends be solid (1) or open (0)?         
</pre>
</pre>
=== EXAMPLES ===
<source lang="python">
from pymol import cgo
# Unit sphere at the origin
plain_sphere = [cgo.SPHERE, 0, 0, 0, 1]
cmd.load_cgo(plain_sphere, "plain_sphere")
# Red unit sphere at (3, 4, 5)
red_sphere = [cgo.COLOR, 1, 0, 0, cgo.SPHERE, 3, 4, 5, 1]
cmd.load_cgo(red_sphere, "red_sphere")
# Narrow yellow cylinder
pos0 = [-1, -1, -1]
pos1 = [-1, -1, 1]
r = 0.1
yellow = [1, 1, 0]
yellow_cyl = [cgo.CYLINDER, *pos0, *pos1, r, *yellow, *yellow]
cmd.load_cgo(yellow_cyl, "yellow_cylinder")
# Magenta and green cone, open on one endray
pos0 = [2, 2, 2]
pos1 = [3, 3, 3]
radii = [1, 0.5]
color0 = [1, 0, 1]
color1 = [0, 1, 0]
caps = [0, 1]
cone = [CONE] + pos0 + pos1 + radii + color0 + color1 + caps
cmd.load_cgo(cone, "cone")
</source>

Revision as of 21:20, 13 February 2022

In PyMOL, a Compiled Graphics Object, or CGO, is a Python list of floating point numbers, which is compiled by PyMOL into a CGO object and associated with a given state. CGOs can be created in the PyMOL scene with the Load_CGO command.

CGO Commands

Based on an old version of the User Manual:

Lowercase names below should be replaced with floating-point numbers. Generally, the TRIANGLE primitive should only be used only as a last restore since it is much less effective to render than using a series of vertices with a BEGIN/END group.

BEGIN, { POINTS | LINES | LINE_LOOP | LINE_STRIP | TRIANGLES | TRIANGLE_STRIP | TRIANGLE_FAN },

VERTEX, x,  y,  z,

COLOR,  red, green, blue, 

NORMAL, normal-x, normal-y,  normal-z, 

END,

LINEWIDTH, line-width, 

WIDTHSCALE, width-scale,   # for ray-tracing

SPHERE, x, y, z,  radius    # uses the current color

CYLINDER, x1, y1, z1, x2, y2, z2, radius,
          red1, green1, blue1, red2, green2, blue2,

TRIANGLE,  x1, y1, z1, 
           x2, y2, z2,
           x3, y3, z3,
           normal-x1, normal-y1, normal-z1,
           normal-x2, normal-y2, normal-z2,
           normal-x3, normal-y3, normal-z3,
           red1, green1, blue1,          
           red2, green2, blue2,          
           red3, green3, blue3,          

CONE,      x1, y1, z1,
           x2, y2, z2,
           r1, r2,
           red1, green1, blue1,          
           red2, green2, blue2,          
           cap1, cap2   # should the ends be solid (1) or open (0)?           


EXAMPLES

from pymol import cgo

# Unit sphere at the origin
plain_sphere = [cgo.SPHERE, 0, 0, 0, 1]
cmd.load_cgo(plain_sphere, "plain_sphere")

# Red unit sphere at (3, 4, 5)
red_sphere = [cgo.COLOR, 1, 0, 0, cgo.SPHERE, 3, 4, 5, 1]
cmd.load_cgo(red_sphere, "red_sphere")

# Narrow yellow cylinder
pos0 = [-1, -1, -1]
pos1 = [-1, -1, 1]
r = 0.1
yellow = [1, 1, 0]
yellow_cyl = [cgo.CYLINDER, *pos0, *pos1, r, *yellow, *yellow]
cmd.load_cgo(yellow_cyl, "yellow_cylinder")

# Magenta and green cone, open on one endray
pos0 = [2, 2, 2]
pos1 = [3, 3, 3]
radii = [1, 0.5]
color0 = [1, 0, 1]
color1 = [0, 1, 0]
caps = [0, 1]
cone = [CONE] + pos0 + pos1 + radii + color0 + color1 + caps
cmd.load_cgo(cone, "cone")