This notebook contains material from PyRosetta; content is available on Github.

Visualization with the PyMOLMover

Keywords: PyMOLMover, send_hbonds()

If you are using Google Colab: Currently, we do not have a way to connect to the local machine's PyMOL, but you can always dump any pose into a pdb file and open that on your own computer.

In [ ]:
# Notebook setup
import sys
if 'google.colab' in sys.modules:
    !pip install pyrosettacolabsetup
    import pyrosettacolabsetup
    print ("Notebook is set for PyRosetta use in Colab.  Have fun!")
In [ ]:
from pyrosetta import *

From previous section: Make sure you are in the right directory for accessing the .pdb files:

cd google_drive/My\ Drive/student-notebooks/

In [ ]:
pose = pose_from_pdb("inputs/5tj3.pdb")

To check that the necessary PyRosetta commands are run by PyMOL, open up PyMOL on Polander and check for a message like PyMOL <--> PyRosetta link started! in the dialog box. PyMOL is now listening for updates from PyRosetta on port by default.

Note: this may not work if many people are trying to do this at the same time, so you may need to specify a different port number by (1) typing pmm = PyMOLMover('', some number between 10000 and 65536) in PyRosetta, (2) run in PyMOL command line, and (3) start_rosetta_server('', that number you used in step 1) in PyMOL command line.

If you are using your own computer (not Polander): either use the PyMOL command line to run the file or drag and drop the file onto the PyMOL window to start the PyMOL-PyRosetta link.

The PyMOLMover class will let us send information from PyRosetta to PyMOL for quick visualization. We are creating an instance of PyMOLMover called pmm.

In [37]:
from pyrosetta import PyMOLMover

(Skip this if you already initialized pmm.)

In [38]:
pmm = PyMOLMover() #go here for additional help:

To view the pose, you can use the apply method on your pose.

In [39]:
clone_pose = Pose()

The PyMOLMover has useful helper functions. For example, you can visualize all the hydrogen bonds in your protein with the following:

In [36]:

Just deselect the hydrogen bonds in PyMOL if you want to hide them temporarily.

What other send methods does the PyMOLMover have?

The method keep_history, if set to True, allows you to load in structures with the same name into states of the same object in PyMOL. This is the starting point for creating a PyMOL movie of your structure, and allows you to loop through structures in different geometries efficiently (try clicking the arrows that are shown below in the red box).

In [40]:
clone_pose.set_phi(5, -90)

This is what it should look like (assuming you are able to establish the PyMOL <--> PyRosetta link):

In [1]:
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
from IPython import display
In [2]:
from pathlib import Path
gifPath = Path("./Media/PyMOL-tutorial.gif")
# Display GIF in Jupyter, CoLab, IPython
with open(gifPath,'rb') as f:
    display.Image(, format='png',width='800')