PyMOL tips and tricks

Table of contents:

back to my home page

First and basic command is "ray". It allows you to make a figure look nicer...

not ray traced

ray traced

not ray traced

ray traced

... but most importantly to it allows you to make it any size you want.
the syntax:

ray xxx

where xxx is width of image in pixels. Do not worry about the height, it is auto-magically adjusted to preserve the proportions of the image.

ray 2400

How many pixels do I need?
It depends where do you want to use the image. For web or presentation purposes screen resolution is usually sufficient. However for printing you would most likely need much bigger image. Usually journal will specify the required resolution (in dpi) and maximum dimensions of figures.
I case journal needs images of resolution = 300 dpi and the image should be 8 inches wide then you would need 2400 pixels (8x300).

But before you would use final ray command you would probably like to make your image even nicer.

  • Antialiasing
  • It will make contours of all objects smoother, set it to 1 or 2 (with value of 2 or more ray tracing will be longer).

    set antialias, 1

  • Ray trace mode
  • set ray_trace_mode, 0

    possible values: 0, 1, 2, 3

    ray trace mode 0

    ray trace mode 1

    ray trace mode 2

    ray trace mode 3

    set ray_trace_mode, 0
    set ray_trace_mode, 1
    set ray_trace_mode, 2
    set ray_trace_mode, 3


    with an outline

    just the outline

    Andy Warhol would have been pleased

    For ray trace modes 1, 2 and 3 the higher antialias value is set the thinner the outline would be. Outline has also fixed size in pixels so the bigger image you will ray trace the smaller proportionally outline would be. Moreover outline is always in colour that is complementary to the colour of the background.

    The more pixels in the ray command the thinner the outline would be.
    The bigger value of antialias command the thinner the outline would be.
    Therefore in case of rendering big image (e.g. ray 2400) you might choose to set antialias to 0 or 1 instead of 2 in order to make the outline more pronounced.

  • Background colour
  • You can change background colour to whatever colour you would like. Here you can find a list of pre-defined PyMOL colours.
    example command:

    bg_color white

    Want a transparent backgroud?
    No problem:
    set ray_opaque_background, off

    you can use on/off or 0/1 values

    N.B. even with transparent background the colour of background will still determine the colour of outline for ray trace modes 1, 2 and 3.

  • Tricks with cartoons
  • cartoon fancy helices off

    cartoon fancy helices on

    set cartoon_fancy_helices, 0

    set cartoon_fancy_helices, 1

    cartoon side chain helper off

    cartoon side chain helper on

    set cartoon_side_chain_helper, off

    set cartoon_side_chain_helper, on

    The cartoon_side_chain_helper will hide stick representation of all residue atoms except side-chain atoms.
    The helix is semi-transparent for clarity.

  • Tricks with surface
  • surface quality 0

    surface quality 2

    set surface_quality, 0

    set surface_quality, 2

    Normally you would use surface quality values 0 or 1 because it will take long time to display and ray trace the surface with quality set to 2 or more.

    surface quality 0

    surface quality 2

    set solvent_radius, 1.0

    set solvent_radius, 2.0

    This command changes the probe radius, default value is 1.4 Å.

    To display of solvent accessible surface use:

    set surface_solvent = on

  • What about RNA/DNA?
  • There is a number of commands to make your nucleic acid look better than default representation. The most important one from listed below is cartoon_ring_mode. Detailed description of these (and many other) commands can be found on PyMOL wiki. Description of cartoon_ring_transparency can be found elsewhere in PyMOL wiki.

    set cartoon_ring_mode, 3
    set cartoon_ring_finder, 1
    set cartoon_ladder_mode, 1
    set cartoon_nucleic_acid_mode, 4
    set cartoon_ring_transparency, 0.5

    surface quality 0

    surface quality 2

    default representation

    improved representation

  • How to move stuff around in PyMOL?
  • To move molecules around one have to activate 3-button editing mouse mode. Easiest way to do it is to click on "Mouse Mode - 3-Button Viewing" in the lower right corner of the main window. Then you will be able to move single molecule while holding down shift key:

    • left mouse button rotates molecule
    • middle mouse button moves molecule
    • right mouse button moves molecule closer or farther

    Note: you cannot move or rotate CGOs that way.

  • How to make black and white figure?
  • Prepare your scene, make your selections and assign white, black and grey colours to them as you wish. Then issue following commands:

    bg_color white
    set ray_trace_mode,  1
    set ambient, 1
    set reflect, 0
    set two_sided_lighting, on

    You can can find detailed descriptions of above commands in PyMOLWiki.
    Note: Things that are white will now disappear. You have to ray trace scene to see them (as the black outline will appear). You will have to adjust the antialias value to the certain resolution of picture that you would like to render.

    B&W image example
    Example of B&W image done using method described above

    To set nucleic acid backbone to be not tube but ribbon shaped, first nucleic acid was selected under specific name, then following commands where issued:

    cartoon oval, <selection_name>
    set cartoon_oval_width, 0.3
    set cartoon_oval_length, 1.1

  • I would like to see symmetry neighbours
  • To do that you have to use symexp command.

    symexp name_for_new_objects, name_of_target, selection, cutoff_in_Å


    symexp sym, abc.pdb, all, 5.0

  • I would like to cut my protein in half
  • It is sometimes useful to have cross section of your protein, especially in case of pockets, tunnels etc.
    First issue following commands:

    hide all
    show surface
    set ray_trace_mode, 0
    set two_sided_lighting, off
    set ray_interior_color, grey50

    Of course you can set up ray_interior_color to any colour you want. This colour is used to display the clipping plane.

    Then you will have to adjust the 'near' clipping plane so that it will cut you protein in desired place:

    cmd.clip("near", x)

    Where x can be positive or negative value (e.g -15 , +10, -90, +100 etc.).
    Negative values will move clipping plane towards the molecule and positive values will move it towards you. You will have to start from negative values to move the clipping plane into the molecule.
    You will have to ray trace image to see final result.

    Sliced protein
    Example of protein sliced using method described above

  • How to make a movie
  • In my opinion the easiest way is to use eMovie plug-in. If you are using Mac OS X to use the plug-in you will have to have X11 installed and use PyMOL in X11 hybrid mode. To do that you will have to make a copy of you PyMOL application and rename it to "PyMOLX11Hybrid". Now you will have to open PyMOLX11Hybrid application and put some files inside to install plug-in. If you are not terminal savvy you can use "Show Package Contents" from Finder contextual menu to get into the application. It is generally good idea to have PyMOLX11Hybrid version of PyMOL as you can benefit not only from eMovie but also other plug-ins like ABPS.
    After you set up your movie in eMovie issue following command to ray trace each frame of your movie:

    set ray_trace_frames, on

    Then you can save your movie as MPEG (menu File -> Save Movie as -> MPEG).
    Alternatively you can save each frame of your movie as image (menu File -> Save Movie as -> PNG images) and then link all the images into a movie. There are a lot of free applications available to do that so I will leave for you to decide which one to use.

    Example of a movie made by using (slightly modified) "Backbone Trace" eMovie option.

    You can also use build in PyMOL movie functions instead of using eMovie. In that case you might want to take a look at tutorial at PyMOLWiki.

  • Labels
  • Labels allows you to put text into PyMOL scene and produce final image with all necessary text included.

    label (selection), expression

    label n. CA and i. 7, "label text" 

    This command will label alpha carbon of the residue 7 with text in parenthesis.

    You can move labels as you can move protein. For this the editing mode have to active (if you have no idea what editing mode is look here). You can move labels using left mouse button:

    • in Y, X holding conrol key
    • in Z (depth) holding control and shift at the same time

    Once you have a label you can control a variety of its properties like:

    • Size
      set label_size, x

      Where x is any number. Positive values represent font size in pt, while negative values set font size in angstroms.
      After ray-tracing a big image labels have tendency to appear smaller, therefore it is good idea to set them bigger just prior the ray-tracing.
    • Typeface
      set label_font_id, x

      Where x value = 5—16.
    • Label colour
      set label_font_id, yellow
    • Label outline colour
      set label_outline_color, blue
    • Label shadow
      set label_shadow_mode, x

      Where x value = 0-3.
      0 = no shadows.
      1 = label cannot produce shadow but can be in a shadow.
      2 = label can produce shadow and it can be in a shadow.
      3 = label can produce shadow but cannot be in a shadow.

    To clear labels, simply omit the expression or set it to "".

    label n. CA and i. 7, ""

    To introduce special characters you need to use Unicode character code:

    label n. CA and i. 7, "label text" + u"x"

    Where x is Unicode character code. Here are some of them:

    • \u03b1 = α (alpha)
    • \u03b2 = β (beta)
    • \u00c5 = Å (angstroms)
    • \u00b2 = ² (square, upper-index)
    • \u00b0 = ° (degree symbol)
    • \u00b1 = ± (+/-)