I have been using PyMOL, a molecular visualisation program, throughout my PhD and wanted to share some of the things I’ve learned.
1. Installation
Open source PyMOL can be installed using conda: conda install -c conda-forge pymol-open-source
. It does not watermark figures and has full functionality, as far as I have been able to tell.
2. Documentation
You can find documentation for PyMOL online (https://pymol.org/dokuwiki/), which can be very helpful, although is not entirely complete.
3. Some of my favourite PyMOL commands/selections
- Standard commands: fetch, load, show, hide, select, create
- within: Select/show/color/etc. objects within a distance from another object. This is great, for example, to visualise binding sites.
- ray: Ray trace your images for higher resolution. You can specify the resolution – I usually go for
ray 2000, 2000
. - color / set_color: These commands allow you to use personalised colors
- distance: Find the distance between two selections. You can format the dashed line with e.g., dash_color and dash_radius.
- align and super: Align two selections; the former command takes sequence into account, while the latter does not.
4. Playing around with visualisations
- ray_trace_mode: There are three ray trace modes, which can be used for fun visualisations. Mode 1 is standard, 2 is black outline, 3 is quantised colour + black outline.
- cartoon: you can change the style of the protein backbone, for example to a ‘tube’ format.
- Check out some more ideas: https://pymolwiki.org/index.php/Gallery and https://www.blopig.com/blog/2021/01/making-pretty-pictures-with-pymol/
5. Pymol scripts
You can create .pml scripts with PyMOL commands and run these in PyMOL. For example, pml_script.pml:
load 3w2d.pdb
select Ab, chain H + chain L
select Ag, chain A
hide
show cartoon, Ab + Ag
color blue, Ab
color red, Ag
In the command line, you can run: pymol pml_script.pml
.
To run this script without opening the PyMOL GUI: pymol -c
pml_script.pml
6. Python + PyMOL scripts
PyMOL is compatible with Python! This is incredibly helpful when using PyMOL iteratively, such as for distance or rmsd calculations. There are a few ways Python + PyMOL scripts can be written/executed, but I typically use the following:
py_script.py:
import pandas as pd
abs = pd.read_csv("antibody_pdbs.csv")
for ind, row in abs.iterrows():
cmd.load(row["pdb_path"])
cmd.create("ab", f"chain {row['Hchain']} + chain {row['Lchain']}")
print("cdrh3_anchor_dist:", cmd.distance("ab & resi 105 & name CA", "ab & resi 117 & name CA"))
cmd.reinitialize()
In the command line, you can run: pymol py_script.py
.
Again, to run this script without opening the PyMOL GUI: pymol -c
py_script.py
You can see more, e.g., at https://www.blopig.com/blog/2020/11/using-python-in-pymol/.
8. .pymolrc
You can specify default settings in a .pymolrc file in your home directory (~/.pymolrc). Some of the key settings in my .pymolrc file (which I adapted from Prof Phill Stansfeld – thanks!) include:
viewport 800, 800
bg white # background to white
set orthoscopic, 1 # perspective
set two_sided_lighting, 1 # illuminate inside and outside of surfaces
set antialias = 1 # smooths jagged edges in ray tracing
set ray_shadow,0 # no shadow
set ray_trace_mode = 1 # default ray trace mode
space cmyk # cmyk color space