Skip to content


A biophysicist teaches himself how to code

One of my favorite things to do is to try new ways to visually represent (in 2D) a complex three-dimensional protein structure. It’s an interesting challenge because it’s all too easy to end up with a protein backbone that looks like a pile of spaghetti from which limited useful information can be drawn.

For some time my go-to package of choice was VMD. Specifically I really appreciated the ambient occlusion lighting effects that have been incorporated into its Tachyon ray tracer, which can generate really stunning figures.

Ribosome rendered with VMD

Another “rendering mode” that I’m a big fan of are the illustrations of David Goodsell, most familiar from the PDB Molecule of the Month feature.

RNA polymerase by David Goodsell

Although these illustrations are often low in information content, they have a simplistic beauty that really appeals to me.

So recently I have been searching for a way to combine these two methods in a way that I can further modify to fit my needs. VMD itself has updated recently to include “outline rendering” in a manner similar to the Goodsell illustration style, but unfortunately this requires graphics hardware that I don’t have on my main machine. I’m also not a fan of VMD from the manipulation standpoint. Atom selections, accurate rotations (e.g. exactly 180 degrees) etc. are complex operations in this software package.

I’ve gone back to using another wonderful visualization package, PyMol. I find that it hits the sweet spot between easy setup of the scene I’d like and generating nice figures.

The specific feature that I’ve come to rely on quite heavily is the built-in ray tracer. There are three available ray tracing modes in addition to the default, each of which has its uses. Mode 1 will place a black outline around your structure, which can help make the secondary structure elements visually distinct. Mode 2 is really interesting, in that it only renders the outline. I find this especially helpful if I want to show something in an overlay without obscuring what is behind it. Mode 3 produces “quantized” color in addition to the outline, giving your figure a very cartoonish appearance. I find that this one has to be used with care 🙂

Anyhow, let’s make a few figures just for kicks. As usual I’ll be using my favorite protein structure, alpha hemolysin (PDB code 7AHL). You can load files directly from the PDB using the built-in PDB Loader plugin of pymol. For this demo I’m rendering all but one chain as a gray cartoon, and rendering the last as a blue molecular surface. I also turn of specular reflections (Display -> Specular Reflections) because I don’t like them

Here are the commands I enter on the command line to generate the image:

bg_color white
set antialias, 2
ray 600, 600

This took about 5 minutes to render on my underpowered laptop. You write out the image with (e.g.):

png mode_0.png

And gives this result:

Default ray tracing mode

Now let’s look at the other fun modes 🙂 Just enter set ray_trace_mode, 1 into the command line and repeat the ray tracing and png saving steps above. Iterate through the three modes and you end up with the following figures (click for larger versions):

Ray tracing mode 1

Ray tracing mode 2

Ray tracing mode 3

You can see that each of these has a different look, which may or may not be useful depending on the figure you are trying to produce. I’m finding that it’s especially useful to do a couple of renders (e.g. one in mode 2 and another in mode 1) and combine them via a little bit of post-processing in the GIMP.


%d bloggers like this: