Introduction to Molecular Visualization with PyMOL




PyMOL is a powerful molecular visualization package from DeLano Scientific, LLC. that runs under Windows 2000 or Windows XP, Linux, and Mac OS X.  In Chemistry 181H/185H, PyMOL will be used in a variety of problems and laboratory exercises. In the following, we will show you how to use PyMOL to view molecular structures and to make distance measurements. 




Download PyMOL v. 0.98 from one of the following links:


For Windows 2000 or XP:


For Mac OS X:

G4 or G5 equipped machines running Mac OS 10.3.x or 10.4.x:

(A two-button or three-button wheel mouse will be required to run PyMOL under Mac OS X.)


For Linux:


Under Windows, we suggest that you download the file to the My Documents folder. When the downloading is complete, double click on the file to run the installer.  In most cases, you can accept the suggestions that the installer makes during the installation process.

For Mac OS X, download the file to the Desktop. After the download completes, double click on the downloaded file to expand it. Drag MacPyMOL to your Applications folder.

Complete installation instructions can be found at


Starting Pymol


Under Windows, from the Start menu, click on Programs, and then click on the Delano Scientific entry.  You will get a submenu; from the four choices, click on PyMOL + Tcl-Tk GUI.  This will start the program and draw two windows, a big one (that holds graphics, we will call it the Graphics window) and a smaller one along the top that is used for data, for menus and typed commands (let's call it the Command window).


For Mac OS X, simply double click on MacPyMOL to launch the program.


Display a Molecule


PyMOL reads .pdb files, which originally came from the Brookhaven protein database. Chemists now use these files to describe the 3D structure of any molecule, not just proteins but also nucleic acids (like RNA and DNA) and even little molecules like the ones we will initially study in this course.


In this exercise, we will work with the file indole.pdb, which you can download to your hard disk by right-clicking this link and choosing the option Save Target As…


To display the indole molecule, click on the File Menu and then choose the option labeled Open….  Using the standard Windows file dialog box, navigate through your file system to find the file indole.pdb, which you just downloaded.  When PyMOL has finished working, you will see the display below:



In the graphics window, you now see a representation of the indole molecule that the PyMOL programs refers to as the lines representation.  The atoms are drawn as the vertices or endpoints of line segments, which represent the bonds.


Moving the molecule around in the graphics window


PyMOL allows the user to easily manipulate the molecule's orientation with respect to the viewer.  The easiest way is to use the mouse to do this.  As a first step, you should configure for the type of mouse that your system has.  The default configuration is 3-button editing mode. Most users have a two-button mouse, and even the fancy three-button mouses (?) with the scrolling wheels function best in PyMOL in the two-button mode.


Click on the Mouse menu, and choose the option 2-button viewing mode.  This menu option is near the top of the menu, as shown below:



When you choose 2 button viewing mode, notice that the lower right-hand part of the graphics window changes to show some new stuff, as shown in the image below:



The Mouse region of the graphics window now shows what will happen when you do stuff in the molecular-display part of the graphics window with the mouse. We will introduce you to only to two of these options in this tutorial.


  • If you click and hold the left mouse button down (left-drag) and then move around in the graphics window where the molecule is displayed, you will reorient the molecule as if you are rotating a ball.  If you left-drag in the molecule area but outside the area where the molecule is displayed (but inside the window), the molecule will rotate around the z-axis, which is defined as the one that points out of the screen (the x and y axes are defined to be in the plane of the display).
  • If you click and hold the right mouse button down (right-drag) and then move up and down in the graphics window, you will see that PyMOL resizes the molecule bigger or smaller.  Let go of the mouse button when you have achieved the size that you want.  (For now, in the tutorial, do not resize the indole molecule.)


So, as an exercise, give a left-drag a try and reorient the molecule so that you are looking in the plane of the atoms.  That's right, indole is said to be a planar molecule, all of the atoms lie in a common plane, so you should be seeing something that looks like this:



Now, try rotating the molecule back to see all of the atoms, and then rotate the molecule so that the nitrogen atom (shown in blue) is on top and the positions of the five- and six-membered rings are reversed compared to the first view:




Distance Measurements


Let's find out how big the indole molecule is.  To do this, we'll use the measurement wizard.  Access the wizard by clicking on the Wizard menu and then choose the Measurement option.  You will be prompted in the upper left corner of the molecule-display region to select the first atom of interest.  To select an atom, as shown in the Mouse region of the display, left click on the atom in the molecular display part of the window.  When you have successfully selected an atom, a little pink square will appear on that atom and you will be prompted to select the second atom.  Left-click on another atom in the molecule to complete the measurement.  You will see a yellow dashed vector drawn between the two atoms you selected and a measurement in Angstroms drawn above it.


In the image below, the vector between one of the carbon atoms in the five-membered ring and one of the carbons in the six-membered ring is indicated by the dashed yellow line:



The distance is labeled as being 4.59 Angstroms (0.459 nm).  You might want to try this distance measurement at this point.


As an aside, you can left-drag to reorient the molecule after a distance measurement has been made.  The molecule and the yellow vector rotates in 3D space.  Sometimes, in a complicated molecule, it is useful to do this so that you can see how the two selected atoms are connected by the vector in 3D space.


After you complete a distance measurement, the prompt changes to indicate that you can now select the first atom in another distance-measurement pair.


At any point, you can click on the Delete Last button that appears on the graphics window just above the Mouse region.  This deletes the yellow vector and the indicated distance for the last measurement you made.  To make the distance measurement buttons and any remaining vectors go away, click on the Done button.


As an exercise, measure the length of the nitrogen-hydrogen bond and then one each of the carbon-hydrogen bonds in the five-membered and six-membered rings, and compare their lengths.  How do the lengths of the C-N bond and C-C bonds in the five- and six-membered rings compare to the typical lengths of single and double bonds between carbon atoms? Make some distance measurements to find out.


Space-Filling Views


The line view that we have been using provides an accurate view of the three-dimensional relationships between the parts of the molecule.  But it distorts our view of the size of the molecule and gives us the mistaken idea that a molecule is wire-like and empty.  The line view really only tells us the location of the center of each atomic nucleus.  In fact, the size of a molecule really is determined by the three-dimensional extent of the electrons, which surround the atom. In analogy with this idea, the spheres view draws a representation of a molecule that is said to be space-filling; it shows how the atoms occupy space. The radius of the each atomic ball drawn in this view is approximately that of the atomic radius.


The first step used in changing the view from the lines view to the spheres view is to use the view menus that are always in view in the upper right-hand corner of the graphics menu:



The view menu lists the various objects that are displayed at a given time.  In our display at present there is only one molecule, so there is just one named object, the indole molecule. The (all) entry at the top refers to all of the objects, so you can change the view mode of all of the objects in a single step.


The view menu shows five popup menus to the right of each listed object:


In order, let's call these the A, S, H, L, and C(rainbow) menus.  If you left-click on these and drag down, you will be able to choose various options from the pop-up menu that comes up.  (At this point, we will only use a few of these options.)


  • The A (Action) menu allows the user to control the view of the molecule.  The main option you might use is zoom, which resets the size of the molecule to fit in the display.
  • The S (Show) menu shows different modes of viewing a molecule.  The lines and spheres options are the ones that we will use at first.
  • The H (Hide) menu hides the different modes.  So if you have both the lines and spheres modes turned on (using the S menu), clicking H and then selecting one of the modes turns one of them off.
  • The L (Labels) menu controls different ways of labeling the molecule.  We will not need this menu for our work at first.
  • The C (Color/rainbow) menu chooses different styles of coloring the different elements  in the molecule.  The default mode, supplied when you start PyMOL, is fine for our work, but you can try the other options to see what they do if you like.


Now, let's display indole in the space-filling (sphere) mode.  To do this, follow the steps below:

  • Use the H menu and select the everything choice.  This hides everything.  The molecule disappears.  PyMOL can still manipulate it because, although it is currently invisible, it is still loaded into memory.
  • Now use the S menu and select the spheres choice.  Now you will see the space-filling representation, as shown in the following image:



Even though we had the indole lines view sized to fit easily on the screen, the space-filling view almost goes off screen.  As mentioned above in reference to the Mouse region of the graphics window, to resize the view (in any mode, not just the spheres view) right-click and drag the mouse in the graphics window up and down.  You will see the molecule redrawn rapidly to follow the mouse movement as if we are moving in and out along the Z axis (closer or farther away from the molecule).  This is the MovZ option in the mouse area, mentioned above.


Here is the spheres view of indole, resized to fit the screen better:



Notice that the display is kind of wrinkled looking.  That's because PyMOL starts up in the maximum performance mode, which uses a less perfect rendering of the molecular display in order to achieve speed and responsiveness to the mouse especially when reorienting the view. If your computer has a fast graphics board or chip, you may be able to work in a better rendering mode. To improve the image, you can use the Display menu and the Quality choice, which offers four different modes in increasing quality with the cost of requiring more time to draw the image.  (This is an optional step.)


For use in a report or a presentation, PyMOL offers a ray-tracing feature to draw an image with a light source and shadows and other optical effects that provide an illusion that a physical, 3D model is held in the display.  This takes time (ranging from a few seconds for a small molecule to a minute or two for a large protein, depending on the speed of your system, of course).


To make a ray-traced image, click on the Command window and then click on the white bar at the bottom.  This places the insertion point in the command line, where you can type a large number of commands that are not available from PyMOL's menus.  The blue arrow in the following image of the command window shows where the command line is located:



With the insertion point (a blinking line, like that of a word processor like Microsoft Word) in the command line, type the following command and then press the Enter or return key:




You should see a progress bar at the upper left-hand corner of the graphics window during the computation.  Then the lumpy sphere view disappears and is replaced by the following publication quality image:



The ray command can also be executed by clicking on the Ray button located on the right side of the Command window.


As you know, nitrogen atoms aren't really blue and carbon atoms aren't really green, but the shape and bulk of the molecule is probably pretty much like the view another indole molecule has when an indole molecule flies by it in solution. 


But how can one save this picture for use in, say, a lab report?  Type the following command in the command line and then press the Enter key:


png indole.png


Upon receiving this command, PyMOL writes a Portable Network Graphics file called indole.png on your disk.  The file will be saved (under Windows) in the C:\Program Files\Delano Scientific  folder by default; you can drag it into whatever folder you want for safe keeping. In Mac OS X, the file will be saved in the Applications folder by default; it is advisable to move this file to your Documents folder. (Of course, in the png command line you can specify the filename and path of your choice, but it is more trouble to type in a long path than to accept the default storage location, in our opinion.)  This file can be inserted into a word processor document or it can be edited in an image editing program.  By the way, the image that the png command writes is of whatever is in view on your screen (lines, distance vectors, lumpy spheres, or ray traced molecules, as above) at the time.


To get back to the normal PyMOL graphics view, just click your mouse in the middle of the graphics window. Once you do that, the ray-traced image is gone forever.  You can always restore it by executing the ray command again.  If you need a bigger picture, you can type ray x,y, where x and y specify how many pixels to use in the image.  Watch out, though, if you type something like ray 4000,4000 you will make a gigantic file that will eat a lot of your hard disk.




PyMOL is an powerful program that is increasingly being used for very advanced molecular graphics applications in research laboratories and in the pharmaceutical industry.  Its capabilities far exceed what we have demonstrated here.  For instance, there are about a bazillioncommands you can type in the command line to do fancy stuff with big molecules, and the programming language called python can be used in scripts to make the program do stuff that even the program's designers haven't thought of. (By the way, the underlying use of python is the origin of the program’s name.).


Don't worry about learning all about PyMOL at this point; what we have shown here is enough to do all of the things we need you to be able to do.  Feel free to explore the program and try things out.  But as we go on in the course, we will show you more of what PyMOL can do.  Our intention in using PyMOL in this course is to expose you to a tool that will help you explore with ease the architecture of molecules ranging from small molecules to proteins and DNA. We hope that some of you will become interested in the general area of molecular visualization and in molecules in general, and we hope that exposure to PyMOL will help you as you work further in chemistry, biochemistry, and molecular biology courses in the future.