PyMOL scripts
Queen's University Protein Function Discovery
and Department of Biochemistry
Molecular Modelling and Crystallographic Computing Facility
Crystallography and Modelling:
Other:
PyMOL Scripts

My PyMOL Script repository

Some PyMOL tutorials:

Included below are some PyMOL tools to create the drawing commands to show the symmetry axes for a crystal, to draw a fancier unit cell and an attempt at drawing reciprocal space in 3D.

All of these scripts require loading into PyMOL before use. You do this with the run command:
run scriptname.py
Then you can use the command according to the instructions provided.

Some of these require cctbx the Computational Crystallography Toolbox (marked with cctbx) and Numerical Python (Numeric) and some require PyMOL version 0.8 (or higher) due to the use of the pymol.vfont module (PyMOL +v0.80). The following have only really been tested on the CVS versions of cctbx and PyMOL.

Other scripts are available in my scripts page.

Name Description Dependencies Click on thumbnail to see larger image
General
pymolrc pymolrc file for use with PyMOL on MS Windows. Copy to directory pymol is installed in (normally c:\Program Files\DeLano Scientific\PyMOL\ Edit it to your preferences (particularly the run scriptname lines at the end. PyMOL +v0.97  
axes_cyl.py Draw X, Y, and Z reference axes as CGO cylinders, colored red, green and blue, respectively PyMOL +v0.80  
showaxes.py plugin version of axes_cyl.py. Install with the install plugins option. PyMOL +v0.80  
color_b.py Color a selection by b-factor or occupancy (q). Options include a choice of colour gradients, 'bgr','rgb','bwr','rwb','bmr','rmb', 'gw','wg','gy','yg','gray', 'reversegray', 'user' modes ramp, (equal numbers of atoms in each color) or histogram (equal spaced color boundaries), saturation, value and nbins (the number of colors to use) and selection. User-defined gradients can also be specified by three triplets of rgb values -- see the top of the python script for more details. Or, after doing run color_b.py from within PyMOL type help(color_b) or help(color_q).  
color_by_attype.py Color by atomtype.
color_by_attype <selection>, <optional colors>
e.g. color_by_attype model & c. a, polar_n=cyan, sulfur=green

Atom types:      Default colours:
hydrophobic      white
polar_n          marine
polar_o          salmon
positive         blue
negative         red
sulfur           yellow
 
color_by_restype.py Color by residue type.
color_by_restype <selection>, <optional colors>
e.g. color_by_restype model, hydrophobic=wheat, polar=marine
                              
Residue groups:          Default colours
hydrophobic: AGILMPV     white
semipolar: C             yellow
polar: HNQST             cyan
positive: KR             blue
negative: DE             red
aromatic: FWY            magenta
 
data2bfactor.py Extract data produced by other programs and alter the B-factor or occupancy of a molecule within PyMOL. Usually, this would be for the purposes of colouring the object with the color_b or color_q functions (see color_b.py above). This can be done per atom or per residue for B-factor or occupancy with the four functions data2b_atom, data2b_res, data2q_atom and data2b_res, respectively. The data files are expected to have data in the format:
  CHAIN   <RESI> <RESN> [name] <data>
where 'name' is required for the data2b_atom function and must be absent for the data2b_res function. RESI is the residue number and RESN is the residue name (as in PyMOL selection commands. CHAIN is optional.
Simply "run" the script and then issue the command data2b_atom 'mol','datafile' where 'mol' is the molecule in question and 'datafile' contains the data to be applied. Similarly for data2b_res 'mol','datafile' , data2q_atom 'mol','datafile' and data2q_res 'mol','datafile'
   
draw_cell.py Draw unitcell border with labels (and with fancy coloring!) within PyMOL. Now you can have a unitcell frame without reading in a PDB file. draw_cell.py also includes labels for the Origin and the ends of the A, B and C axes. PyMOL +v0.80
cctbx
Numeric
 
fitting.py Calculate the RMSD and fit one selection onto another within PyMOL without regard to matching residue names, etc. This script temporarily changes the selection2 to match selection1 so that the fit will work.
  fitting object1, selection1, object2, selection2
  e.g. fitting 1xuu, c. a & (i. 296-309 or i. 335-340), 1ame, i. 8-21 or i. 47-52
After making the changes, it calculates the RMSD and then resets the residues as they were. The script also creates a new object showing the residues/atoms that were fit.
fitting_v1.py
Older version
Calculate the RMSD and fit one selection onto another within PyMOL without regard to matching residue names, etc. This script temporarily changes the selections to be fit into glycines and sets the residue names and chain identifiers to match so that the fit command can be used on non-identical sequences.
  fitting object1, selection1, object2, selection2
  e.g. fitting 1xuu, c. a & i. 296-309, 1ame, i. 8-21 
After making the changes, it calculates the RMSD and then resets the residues as they were. The script also creates a new object showing the residues/atoms that were fit.
make_pov.py Create an input file for povray, based on the current view. See top of script for usage hints. povray  
msms_cgo.py Display surfaces calculated with Michel Sanner's MSMS program. "Run" the script and then issue the command: msms_cgo <file_name>, where the file_name is the root of the name of the face and vert files. Options include specifying the name of the new object, and the colour of the surface. MSMS (MSMS home page)
msms_pymol.py Calculate surface areas with Michel Sanner's MSMS program. "Run" the script and then issue the command: calc_msms_area <object_name>. Options include specifying the selection within the object, the probe size, the surface point density, as well as options to keep the surface area file (keep=1) and to print the full MSMS output (debug=1). You can also draw the surface that you have calculated by specifying draw=1 (show the surface for calculated for the selection) or draw=2 (show the complete surface for the object). You can specify colours using the inside_colour and outside_colour options. MSMS (MSMS home page) msms_selection_draw.py
msms_selection_draw.py Display a surface calculated with Michel Sanner's MSMS program. This surface may be precalculated outside PyMOL with MSMSor as output by my msms_similarity.py and msms_complementarity.py scripts or using the msms_pymol.py script above. MSMS (MSMS home page)
msms_sim_draw.py Draw msms surface (as written by my msms_similarity.py or msms_complementarity.py scripts as a CGO object
msms_sim_draw(vert_name,face_name,obj_name='',gradient='white-red',outside_color='grey')
msms
list_contacts.py Print a list of contacts between two selections within PyMOL.
        list_contacts <selection1>, <selection2>, cutoff=4 (default)
      
Normally you will want to exclude waters, e.g.:
        list_contacts 1abc & c. a &! r. hoh, 1abc & c. b &! r. hoh, cutoff=3.2, contact_name=1abc_contacts
      
list_hbonds.py Print a list of mainchain hydrogen bonds within a selection within PyMOL.
        list_hb <selection>, cutoff=3.2 (default)
      
Normally you will want to exclude waters, e.g.:
        list_hb 1xnb &! r. hoh, cutoff=3.2
      
rms_current.py Calculate the RMSD (without fitting) of one selection onto another within PyMOL without regard to matching residue names, etc. This script temporarily changes the selection2 to match selection1 so that the rms_cur command can be used.
  rms_current object1, selection1, object2, selection2
  e.g. rms_current 1xuu, c. a & (i. 296-309 or i. 335-340), 1ame, i. 8-21 or i. 47-52
After making the changes, it calculates the RMSD and then resets the residues as they were. The script also creates a new object showing the residues/atoms that were fit.
stride_ss.py Extract the secondary structure output from the program stride that is distributed with VMD and apply it to a molecule within PyMOL.
Simply "run" the script and then issue the command stride2pymol('mol') where 'mol' is the molecule in question or to select only part of the molecule do: stride2pymol('mol','sel'), where 'sel' defines the selection using the normal pymol selection commands (be sure to include the molecule in the selection!).
This script can also be run on its own to list the secondary structure as output by stride
./stride_ss.py <file.pdb>
stride (from VMD)  
seq_select.py Create a named selection of a particular sequence in an object.    
Modelling
build_seq.py
Build a sequence of specified secondary structure, e.g.
build_seq QGAADLESLGQYF, ss=helix 
or
build_seq QGAADLESLGQYF, phi=-75, psi=-35 
will create an object gln, unless a (pk1) selection exists, in which case it will build onto that atom. It needs seq_convert.py to convert from one-letter code to three letter code
seq_convert.py (link to info)
seq_convert.py (download script)
build_seq_phi_psi.py
Build a sequence of specified secondary structure, e.g.
build_seq_phi_psi seq_phi_psi.txt
where the file looks like:
      Q 30. 50.
      G -57. 60.
      A 120. 30.
      A -50. 60.
      D -57. 60.
      L -119. 113.
      E -119. 113.
      ...
      
will create an object named by the first residue in the specified sequence. , unless a (pk1) selection exists, in which case it will build onto that atom. It needs seq_convert.py to convert from one-letter code to three letter code
seq_convert.py (link to info)
seq_convert.py (download script)
distance_states.py Measure distance between two atoms in multi-state objects
 e.g. distance_states ,,[same=0]
or
 e.g. distance_states pk1,pk2
Where you have picked an atom in each of two objects, at least one of which has multiple states. The script will loop over the states in both objects and print out the distance between the two atoms. The two atoms could be within the same object, if you wish to measure a distance within that object as a function of states, then add the "same=1" option to the command line:
 e.g. distance_states pk1,pk2,same=1
load_models.py Load multiple PDB files into a single PyMOL object as multiple frames
  e.g. load_models prot_*.pdb, prot 
will create an object prot with a frame for each structure loaded. You can set the discrete flag to 1 to load the models into discrete states -- i.e. B-factors and secondary structure information is stored separately for each state. The default is discrete=0
  load_models prot_*.pdb, prot, discrete=1
      
load_sep.py Load multiple PDB files into a multiple PyMOL objects
  e.g. load_sep prot_*.pdb, prot 
will create objects with names, prot1, prot2, prot3, etc.
load_best.py Load multiple modeller output files into a single PyMOL objects ordered by best to worst "OBJECTIVE FUNCTION" You can select how many objects to load, or a cutoff in the "OBJECTIVE FUNCTION"
  e.g. load_best prot_*.pdb, prot, level=50000 
or
  e.g. load_best prot_*.pdb, prot, number=100 
You can add discrete=1 to load the models into discrete states. It requires my stats.py script.
stats.py (link to info)
stats.py (download script)
Symmetry axis representations
list_symm.py Simply lists the symmetry operators in both "x,y,z" and numerical matrix forms for a given space group cctbx
 
draw_symops.py Draw symmetry axes within PyMOL using the symop_axes.dat file of operator axes (not all space groups are entered yet). PyMOL +v0.80
cctbx
Numeric
symop_axes.dat
 
draw_symops_cctbx.py Draw symmetry axes within PyMOL using the cctbx tools called from all_axes_new.py (see below) to generate the unique set of symmetry axes. PyMOL +v0.80
cctbx
Numeric
all_axes_new.py
Image of symmetry display
The following two scripts can be called by the draw_symops(_cctbx).py scripts to obtain the symmetry axis information or they can be run alone to list the information interatively.
all_axes.py Generate symmetry axes using the cctbx (from Ralf W. Grosse-Kunstleve of the Computational Crystallography Initiative (CCI)) cctbx
Numeric
 
all_axes_new.py Generate symmetry axes using the cctbx, but modified by me a little to shorten some of the axis representations. cctbx
Numeric
 
symop_axes.dat Table of symmetry axis positions  
For either of the above draw_symops(_cctbx).py scripts, from within PyMOL do, for example: run draw_symops_cctbx.py and then do: draw_symops((30.,40.,50.,90.,99.,90),'p21',0.5) to draw the symmetry operators for the space group p21 (with a radius of 0.5 -- 0.2 is the default radius).
Reciprocal space viewers
ewald.py Draw the Ewald sphere at the beginning and end of a data collection pass, as well as the limiting sphere and the reflections divided into categories (within the limiting sphere, outside the limiting sphere, collected, not collected and lastly part of one asymmetric unit). PyMOL +v0.80
cctbx
Numeric
 
ewald_laue.py Draw the reflections that would be collected in a Laue experiment. PyMOL +v0.80
cctbx
Numeric