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.
pose.dump_pdb("output_file.pdb")
# Notebook setup
import sys
if 'google.colab' in sys.modules:
!pip install pyrosettacolabsetup
import pyrosettacolabsetup
pyrosettacolabsetup.setup()
print ("Notebook is set for PyRosetta use in Colab. Have fun!")
from pyrosetta import *
init()
From previous section:
Make sure you are in the right directory for accessing the .pdb
files:
cd google_drive/My\ Drive/student-notebooks/
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 127.0.0.1 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('127.0.0.1', some number between 10000 and 65536)
in PyRosetta, (2) run PyMOL-RosettaServer.py
in PyMOL command line, and (3) start_rosetta_server('127.0.0.1', 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 PyMOL-RosettaServer.py file or drag and drop the PyMOL-RosettaServer.py 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
.
from pyrosetta import PyMOLMover
(Skip this if you already initialized pmm.)
pmm = PyMOLMover() #go here for additional help: http://www.pyrosetta.org/pymol_mover-tutorial
To view the pose, you can use the apply method on your pose.
clone_pose = Pose()
clone_pose.assign(pose)
pmm.apply(clone_pose)
The PyMOLMover has useful helper functions. For example, you can visualize all the hydrogen bonds in your protein with the following:
pmm.send_hbonds(clone_pose)
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).
pmm.keep_history(True)
pmm.apply(clone_pose)
clone_pose.set_phi(5, -90)
pmm.apply(clone_pose)
This is what it should look like (assuming you are able to establish the PyMOL <--> PyRosetta link):
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
from IPython import display
from pathlib import Path
gifPath = Path("./Media/PyMOL-tutorial.gif")
# Display GIF in Jupyter, CoLab, IPython
with open(gifPath,'rb') as f:
display.Image(data=f.read(), format='png',width='800')