# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Importing Structures
# This tutorial demonstrates how to visualize 3D structures using the [py3Dmol](http://3dmol.csb.pitt.edu/index.html) Jupyter Notebook widget. Here we show how to download structures from the PDB as well as read local structure files.
#
# 3Dmol.js: molecular visualization with WebGL, <NAME>, <NAME>, [Bioinformatics (2015) 31, 1322–1324](https://doi.org/10.1093/bioinformatics/btu829)
#
# Also, check out the [py3Dmol tutorial](http://nbviewer.jupyter.org/github/3dmol/3Dmol.js/blob/9050b97144e81f065df7eecc87ba9a16723ab14b/py3Dmol/examples.ipynb) for additional features.

import py3Dmol

# ## Download a structure from the RCSB Protein Data Bank
# py3Dmol downloads PDB structures using the [compressed](http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0174846) binary [MMTF file format](https://doi.org/10.1371/journal.pcbi.1005575) from https://mmtf.rcsb.org. Prepend the 'pdb:" prefix to the 4-letter PDB ID.
#
# Downloading PDB structures in MMTF format has the following advantages:
# * Very large structures are downloaded efficiently
# * Molecules contain bond order information
# * DSSP secondary structure has been recalculated for consistency

# +
viewer = py3Dmol.view(query='pdb:5MXB')

# setting styles will be covered in the next tutorial
viewer.setStyle({'cartoon': {'color': 'spectrum'}})
viewer.setStyle({'hetflag': True}, {'stick':{'radius': 0.3, 'singleBond': False}})
viewer.zoomTo()
viewer.show()
# -

# # Import a structure from a local file
# [List of supported file formats](http://3dmol.csb.pitt.edu/doc/types.html#FileFormats)
#
# A disadvantage of reading local PDB files is the absence of bond order information. Compare the small molecules below with the downloaded version above.

# +
structure = open('5mxb.pdb','r').read()
viewer = py3Dmol.view()
viewer.addModel(structure,'pdb')

viewer.setStyle({'cartoon': {'color': 'spectrum'}})
viewer.setStyle({'hetflag': True}, {'stick':{'radius': 0.3, 'singleBond': False}})
viewer.zoomTo()
viewer.show()
# -



StarcoderdataJupyterScriptsDedupFiltered