How to Create Publication-Quality Images in PyMOL: ray tracing, DPI, and export

 

This article covers everything you need to produce a journal-ready figure in PyMOL: orienting the view, choosing a ray trace mode, setting the background, and exporting a high-resolution PNG. The key command is ray — but knowing the right settings before you run it saves a lot of iteration.

 

 

The first thing you want to accomplish to generate an image is to adjust the view of the molecule or protein structure. You can use your mouse to get the view that best fits your needs but you can also use the command line to make sure that the system is properly oriented and centered in the interface. To this aim, we can use the orient and center commands in PyMOL.

To orient your system with the XYZ axis you can type:

1
orient

 

If you want to center it you can use:

1
center

 

Both of these commands can be used with a selection meaning that you can choose a set of atoms and use them to orient or center your system based on them. If you are not familiar with the PyMOL selection tool you can find more info here

Example

To center your view on residue 110:

1
center resi 110

To orient the view on a ligand named LIG you can use:

1
orient resn LIG

 

 

Here comes the best part. If you are here you are probably wondering how to render high-quality images with PyMOL. The good news is that this process is quite intuitive in PyMOL.

This is due to the built-in ray tracing technology that allows you to generate high-quality images of molecular structures with realistic shadows, reflections, and transparency effects. The kind of fancy images you generally find in papers and presentations.

As already mentioned, the procedure is quite easy.

You just need to set up the view according to your needs, and then you can simply type ray in the PyMOL command line and hit enter:

1
ray

 

Easy as that. PyMOL will then start the ray tracing process and generate an image of the current scene, which you can export and use as you want.

Example
Beware that the ray-tracing procedure may take some time depending on your computer and the complexity of the system you want to represent. Be patient.

You can also specify different parameters to control the ray-tracing process. Among others, you can choose to scale the width and height of the figure:

1
ray <width>, <height>

 

For instance:

1
ray 1280,720

will ray trace the current scene, but scaled to 1280x720 pixels.

 

 

It’s not over yet. PyMOL also offers different ray trace modalities.

You can choose them with the set ray_trace_mode command. Four modes are available and you can select them with 0, 1, 2, and 3. After the selection, you simply need to run the ray command to start the rendering.

Here is what they look like:

  • set ray_trace_mode, 0: The default rendering mode for PyMOL displaying natural colors.
Default ray trace mode of a protein in PyMOL.
  • set ray_trace_mode, 1: This mode gives natural colors with black outlines.
 Ray trace mode with the black outline of a protein in PyMOL
  • set ray_trace_mode, 2: Black outline with no colors.
 Black and white ray trace mode of a protein in PyMOL.
  • set ray_trace_mode, 3: quantized color with black outline.
 Ray trace mode of a protein in PyMOL with quantized colors plus black outline

Notice that you can change the color of the outline with the set ray_trace_color command.

1
2
3
set ray_trace_color, green
set ray_trace_mode, 3
ray
 Ray trace mode of a protein in PyMOL with quantized colors plus green outline

 

 

A black background color is rarely useful for publication types of images. Therefore, while we already discuss how to change the color and the appearance of your system here, we still need to discuss how to change the background color in PyMOL.

To change the background color in PyMOL use the bg_color command followed by the color you want.

1
bg_color <color>

 

Some examples:

1
2
3
4
5
6
7
8
# Change the background color to white
bg_color white

# Change the background color to black
bg_color black

# Change the background color to green
bg_color green

 

In some cases, you may also want to create a representation of your system with an opaque background. This is especially useful when you want to overlay your molecular structure on top of another image or integrate it into a larger design (e.g., a poster or a presentation).

To achieve this you need to use the set ray_opaque_background command. You can set the opaque background on or off:

  • set ray_opaque_background, on $\Rightarrow$ Non-transparent background
  • set ray_opaque_background, off$\Rightarrow$ Transparent background

 

This will make the background transparent and export the image with a transparent background:

1
2
set ray_opaque_background, off
ray

 

The image from PyMOL will be shown over a checkerboard and will only appear transparent once you export it.

 

After running ray, the rendered image is visible in the PyMOL viewer but not yet saved to disk. Use the png command to export it:

1
png filename.png

Most journals require a minimum of 300 DPI. Set it explicitly with the dpi argument:

1
png filename.png, dpi=300

For figures with fine structural details (bonds, labels), 600 DPI is safer. A complete publication workflow in four commands:

1
2
3
4
bg_color white
set ray_trace_mode, 1
ray 1920, 1080
png figure1.png, dpi=300

This gives you a white-background, black-outlined, 1080p image at 300 DPI — ready for submission.