viewer¶
Display PackedPose or Pose objects, or .pdb files, in py3Dmol within a Jupyter notebook.
Usage: import pyrosetta.distributed.viewer as viewer
Example Jupyter notebook commands:¶
view = viewer.init(“path/to/pdbfile.pdb”) view.show()
import logging logging.basicConfig(level=logging.WARNING) import pyrosetta pyrosetta.init(“-mute all”)
pose = pyrosetta.toolbox.rcsb.pose_from_rcsb(“5BVL”)
view = viewer.init(pose, window_size=(800, 600)) view() # Equivalent to view.show()
poses = [pyrosetta.toolbox.rcsb.pose_from_rcsb(id) for id in [“5BVL”, “6MSR”, “1QCQ”]]
view = viewer.init(poses) + viewer.setStyle(colorscheme=”lightgreyCarbon”) + viewer.setHydrogenBonds() view()
import pyrosetta.distributed.io as io packed_pose = io.to_packed(pyrosetta.toolbox.pose_from_rcsb(“2FD7”)) polar_residue_selector = pyrosetta.rosetta.core.select.residue_selector.ResiduePropertySelector(
pyrosetta.rosetta.core.chemical.ResidueProperty(52)
)
view = viewer.init(packed_pose) view.add(viewer.setStyle(radius=0.1)) view.add(viewer.setStyle(residue_selector=polar_residue_selector, colorscheme=”whiteCarbon”, radius=0.25, label=False)) view.add(viewer.setHydrogens(color=”white”, polar_only=True, radius=0.1)) view.add(viewer.setHydrogenBonds(color=”black”)) view.add(viewer.setDisulfides(radius=0.1)) view()
- view = sum(
- [
viewer.init(packed_pose), viewer.setStyle(cartoon=False, style=”sphere”, radius=1.5, colorscheme=”darkgreyCarbon”), viewer.setZoom(factor=1.5)
]
) view.show()
pose = pyrosetta.toolbox.rcsb.pose_from_rcsb(“6MSR”) chA = pyrosetta.rosetta.core.select.residue_selector.ChainSelector(“A”) chB = pyrosetta.rosetta.core.select.residue_selector.ChainSelector(“B”)
- view = sum(
- [
viewer.init(pose), viewer.setStyle(cartoon_color=”lightgrey”, radius=0.25), viewer.setSurface(residue_selector=chA, colorscheme=”greenCarbon”, opacity=0.65, surface_type=”VDW”), viewer.setSurface(residue_selector=chB, color=”blue”, opacity=1.0, surface_type=”SAS”), viewer.setDisulfides(radius=0.25), viewer.setZoom(factor=1.5)
]
) view()
helix_selector = pyrosetta.rosetta.core.select.residue_selector.SecondaryStructureSelector(“H”) sheet_selector = pyrosetta.rosetta.core.select.residue_selector.SecondaryStructureSelector(“E”) loop_selector = pyrosetta.rosetta.core.select.residue_selector.SecondaryStructureSelector(“L”)
- modules = [
viewer.setBackgroundColor(color=”grey”), viewer.setStyle(residue_selector=helix_selector, cartoon_color=”blue”, label=False, radius=0), viewer.setStyle(residue_selector=sheet_selector, cartoon_color=”red”, label=False, radius=0), viewer.setStyle(residue_selector=loop_selector, cartoon_color=”white”, label=False, radius=0)
]
view = viewer.init(poses, window_size=(1200, 600), modules=modules) view()
view.reinit() # Subtract all visualization modules previously added to the Viewer view()
# View live trajectory:
pose = pyrosetta.toolbox.pose_from_rcsb(“2FD7”) view = viewer.init(pose, delay=0.15) + viewer.setStyle(radius=0.1) + viewer.setDisulfides(radius=0.1) backrub = pyrosetta.rosetta.protocols.backrub.BackrubMover() minimize = pyrosetta.rosetta.protocols.minimization_packing.MinMover()
- for _ in range(100):
backrub.apply(pose) minimize.apply(pose) view.show()
# Display preset custom viewers for routine visualizations:
viewer.presets.coreBoundarySurface(poses, window_size=(800, 600), continuous_update=True)
The Viewer quickly renders .pdb files, dynamically instantiating Pose objects if required for certain visualization modules (matching the name viewer.set*). So when adding visualization modules to the Viewer or using presets, passing Pose or PackedPose objects to the Viewer is suggested for quicker rendering. If a Pose object or list, tuple, or set of Pose objects are provided to the Viewer, the Pose`(s) pointer location(s) in memory remain fixed, and so the Viewer can dynamically update upon `Pose conformational changes by calling the show() method. The Viewer applies visualization modules in the same order they are added (from left to right), so layering different styles (and ResidueSelector`s) on top of one another becomes possible. The user must have already initialized PyRosetta providing `.params files for any ligands and non-canonical residues in the input molecule(s), otherwise pyrosetta.distributed automatically initializes PyRosetta with default command line options.
- pyrosetta.distributed.viewer.expand_notebook()¶
Expand Jupyter notebook cell to maximum width.
- pyrosetta.distributed.viewer.init(packed_and_poses_and_pdbs=None, window_size=None, modules=None, delay=None, continuous_update=None, *args, **kwargs)¶
Initialize the Viewer object.
- firstrequired
packed_and_poses_and_pdbs
PackedPose, Pose, or str of a valid path to a .pdb file, or a list, set, or tuple of these objects.
- secondoptional
window_size
list or tuple of int or float values for the (width, height) dimensions of the displayed window screen size. Default: (1200, 800)
- thirdoptional
modules
list of instantiated visualization modules to run upon changing amongst packed_and_poses_and_pdbs objects with the slider, matching the namespace pyrosetta.distributed.viewer.set* Default: []
- fourthoptional
delay
float or int time delay in seconds before rendering the Viewer in a Jupyter notebook, which is useful to prevent overburdening the Jupyter notebook client if for looping over quick modifications to a Pose, and should be >= 0. Default: 0.25
- fifthoptional
continuous_update
True or False. When using the interactive slider widget, False restricts rendering to mouse release events. Default: False
A Viewer instance.
- class pyrosetta.distributed.viewer.setBackgroundColor(color=4294967295)¶
Bases:
object
Set Viewer background color with either Hexcode or standard colors.
- firstoptional
color
Hexcode literal (e.g. 0xffffffff) or str indicating a standard color (e.g. “black”). Default: 0xffffffff
A Viewer instance.
- __init__(color=4294967295)¶
- apply(viewer, pose, pdbstring)¶
- class pyrosetta.distributed.viewer.setDisulfides(color='gold', radius=0.5)¶
Bases:
object
Display disulfide bonds according to pyrosetta.rosetta.core.conformation.is_disulfide_bond() for all combinations of cysteine residues in each initialized .pdb file, Pose or PackedPose object.
- firstoptional
color
str indicating a standard color (e.g. “black”). Default: “gold”
- secondoptional
radius
float or int indicating the radius of the stick connecting the atoms participating in each disulfide bond. Default: 0.5
A Viewer instance.
- __init__(color='gold', radius=0.5)¶
- apply(viewer, pose, pdbstring)¶
- class pyrosetta.distributed.viewer.setHydrogenBonds(color='black', dashed=True, radius=None)¶
Bases:
object
Display hydrogen bonds according to pyrosetta.rosetta.core.pose.Pose.get_hbonds() in each initialized .pdb file, Pose or PackedPose object.
- firstoptional
color
str indicating a standard color (e.g. “yellow”). Default: “black”
- secondoptional
dashed
True or False to show hydrogen bonds as dashed lines. If True, then option radius must be None. If False, then option radius must be specified. Default: True
- thirdoptional
radius
float or int indicating the radius of the solid (non-dashed) stick connecting the atoms participating in each hydrogen bond. If set, this automatically sets the option dashed to False. Default: None
A Viewer instance.
- __init__(color='black', dashed=True, radius=None)¶
- apply(viewer, pose, pdbstring)¶
- class pyrosetta.distributed.viewer.setHydrogens(color='white', radius=0.05, polar_only=False)¶
Bases:
object
Show all or only polar hydrogen atoms in each initialized .pdb file, Pose or PackedPose object.
- firstoptional
color
str indicating a standard color (e.g. “grey”). Default: “white”
- secondoptional
radius
float or int indicating the radius of the hydrogen atom stick represnetations. Default: 0.05
- thirdoptional
polar_only
True or False. True to show only polar hydrogen atoms, and False to show all hydrogen atoms. Default: False
A Viewer instance.
- __init__(color='white', radius=0.05, polar_only=False)¶
- apply(viewer, pose, pdbstring)¶
- class pyrosetta.distributed.viewer.setStyle(residue_selector=None, cartoon=True, cartoon_color='spectrum', style='stick', colorscheme='blackCarbon', radius='0.1', label=True, label_fontsize=12, label_background=False, label_fontcolor='black', command=None)¶
Bases:
object
Show and color cartoon, and/or show heavy atoms with provided style, color and radius for each initialized .pdb file, Pose or PackedPose object. If the residue_selector argument is provided, apply styles only to the selected residues. If the command argument is provided, override all other arguments and pass py3Dmol.view.setStyle() commands to the Viewer.
- firstoptional
residue_selector
An instance of pyrosetta.rosetta.core.select.residue_selector.ResidueSelector on which to apply the style(s). Default: None
- secondoptional
cartoon
True or False to show cartoon representation. Default: True
- thirdoptional
cartoon_color
Hexcode literal (e.g. 0xAF10AB) or str indicating a standard color (e.g. “grey”) for the cartoon representation. If “spectrum”, apply reversed color gradient based on residue numbers. The option cartoon must also be set to True. Default: “spectrum” Reference: https://3dmol.csb.pitt.edu/doc/types.html#ColorSpec
- fourthoptional
style
str indicating a representation style of heavy atoms, choosing from either “line”, “cross”, “stick”, or “sphere”. Default: “stick”
- fifthoptional
colorscheme
- str indicating the color scheme for heavy atoms represented by the style option. Options include:
A lower-case standard color followed by “Carbon” (e.g. “orangeCarbon”) “ssPyMOL”: PyMol secondary colorscheme “ssJmol”: Jmol secondary colorscheme “Jmol”: Jmol primary colorscheme “default”: default colorscheme “amino”: amino acid colorscheme “shapely”: shapely protien colorscheme “nucleic”: nucleic acid colorscheme “chain”: standard chain colorscheme “chainHetatm”: chain Hetatm colorscheme
Default: “blackCarbon” Reference: https://3dmol.csb.pitt.edu/doc/types.html#ColorschemeSpec
- sixthoptional
radius
float or int indicating the radius of the heavy atoms represented by the style option. Default: 0.1
- seventhoptional
label
True or False to show labels next to residues selected by the residue_selector option. Default: True
- eighthoptional
label_fontsize
int or float indicating the font size of labels next to residues selected by the residue_selector option, only if label is True. Default: 12
- ninthoptional
label_background
True or False to show the background of labels next to residues selected by the residue_selector option, only if label is True. Default: False
- tenthoptional
label_fontcolor
str indicating a standard font color (e.g. “grey”) for label text next to residues selected by the residue_selector option, only if label is True. Default: “black”
- eleventhoptional
command
dict or tuple of dict`s of `py3Dmol.view.setStyle() commands. If specified, this option overrides all other options. Default: None Example:
command = {“hetflag”: True}, {“stick”: {“singleBond”: False, “colorscheme”: “greyCarbon”, “radius”: 0.15}} view = viewer.init(poses) + viewer.setStyle(command=command) view.show()
A Viewer instance.
- __init__(residue_selector=None, cartoon=True, cartoon_color='spectrum', style='stick', colorscheme='blackCarbon', radius='0.1', label=True, label_fontsize=12, label_background=False, label_fontcolor='black', command=None)¶
- apply(viewer, pose, pdbstring)¶
- class pyrosetta.distributed.viewer.setSurface(residue_selector=None, surface_type='VDW', opacity=0.5, color=None, colorscheme=None)¶
Bases:
object
Show the specified surface for each initialized .pdb file, Pose or PackedPose object.
- firstoptional
residue_selector
An instance of pyrosetta.rosetta.core.select.residue_selector.ResidueSelector to select residues on which to apply the surface. Default: None
- secondoptional
surface_type
- str indicating surface type to be displayed. py3Dmol supports the following options:
“VDW”: Van der Waals surface “MS”: Molecular surface “SES”: Solvent excluded surface “SAS”: Solvent accessible surface
Default: “VDW”
- thirdoptional
opacity
float or int between 0 and 1 for opacity of the displayed surface. Default: 0.5
- fourthoptional
color
str indicating a standard color (e.g. “grey”) of the surface to be displayed. Either color or colorscheme may be specified, where colorscheme overrides color. Default: None
- fifthoptional
colorscheme
str indicating the color scheme of the surface to be displayed. Either color or colorscheme may be specified, where colorscheme overrides color. Options include:
A lower-case standard color followed by “Carbon” (e.g. “yellowCarbon”) “ssPyMOL”: PyMol secondary colorscheme “ssJmol”: Jmol secondary colorscheme “Jmol”: Jmol primary colorscheme “default”: default colorscheme “amino”: amino acid colorscheme “shapely”: shapely protien colorscheme “nucleic”: nucleic acid colorscheme “chain”: standard chain colorscheme “chainHetatm”: chain Hetatm colorscheme
Default: None Reference: https://3dmol.csb.pitt.edu/doc/types.html#ColorschemeSpec
A Viewer instance.
- __init__(residue_selector=None, surface_type='VDW', opacity=0.5, color=None, colorscheme=None)¶
- apply(viewer, pose, pdbstring)¶
- class pyrosetta.distributed.viewer.setZoom(factor=2)¶
Bases:
object
Set the zoom magnification factor of each initialized .pdb file, Pose or PackedPose object. Values >1 zoom in, and values <1 zoom out.
- firstoptional
factor
float or int indicating the zoom magnification factor. Default: 2
A Viewer instance.
- __init__(factor=2)¶
- apply(viewer, pose, pdbstring)¶
- class pyrosetta.distributed.viewer.setZoomTo(residue_selector=None)¶
Bases:
object
Zoom to a ResidueSelector in each initialized .pdb file, Pose or PackedPose object.
- firstoptional
residue_selector
An instance of pyrosetta.rosetta.core.select.residue_selector.ResidueSelector into which to zoom. Default: None
A Viewer instance.
- __init__(residue_selector=None)¶
- apply(viewer, pose, pdbstring)¶