#!/usr/bin/env python # coding: utf-8 # # Setting Rendering Styles # This tutorial demonstrates how to instantiate a py3Dmol viewer and set atom styles and colors. # In[1]: import py3Dmol # ## Instantiating the py3mol viewer with a PDB ID # py3Dmol downloads PDB structures using the MMTF file format from https://mmtf.rcsb.org. Prepend the 'pdb:" prefix to the 4-letter PDB ID. # In[2]: viewer = py3Dmol.view(query='pdb:1STP') viewer.show() # ## Setting an Atom Style # Styles are specified as nested dictionaries. In this example, 'stick' is the AtomStyleSpec [(list of atom styles)](http://3dmol.csb.pitt.edu/doc/types.html#AtomStyleSpec). # In[3]: viewer.setStyle({'stick': {}}) viewer.show() # ## Setting a Color Representation # Colors are specified as a dictionary, e.g., {'color': 'spectrum'} or monochrome colors {'color':'lightgreen'} [(list of colors)](https://github.com/3dmol/3Dmol.js/blob/master/3Dmol/colors.js#L45-L192). # In[4]: viewer.setStyle({'cartoon': {'color': 'spectrum'}}) viewer.show() # ## Setting a Color Scheme # Color schemes can be used to color atoms and residues by properties. A particulary useful color scheme is the Carbon color scheme, for example: 'greenCarbon' [(list of color schemes)](https://github.com/3dmol/3Dmol.js/blob/master/3Dmol/colors.js#L26-L36). # In[5]: viewer.setStyle({'stick': {'colorscheme': 'greenCarbon'}}) viewer.show() # Example of coloring by amino acid type # In[6]: viewer.setStyle({'cartoon': {'colorscheme':'amino'}}) viewer.show() # In[ ]: # In[ ]: