{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Representations and Visualization" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`Molecule` objects can be visualized either in VMD or in NGL, a WebGL javascript molecule viewer that's integrated in the Notebook.\n", "\n", "By default, VMD is used as a viewer. If one wants to use NGL, run the following:" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from htmd.config import config\n", "config(viewer='webgl')" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### On-the-fly molecule visualization and interaction" ] }, { "cell_type": "code", "execution_count": 49, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2016-11-09 22:39:17,264 - htmd.molecule.molecule - INFO - Using local copy for 3PTB: /home/joao/maindisk/software/repos/Acellera/htmd/htmd/data/pdb/3ptb.pdb\n" ] } ], "source": [ "mol = Molecule('3PTB') # reloading the molecule\n", "mol.view(gui=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It is also possible to apply multiple representations to a `Molecule` as in VMD.\n", "\n", "Representations use the same names as in VMD, even when using the NGL viewer. Important parameters are: **style**, **color**, and **sel**. " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### The \"quick\" or \"transient\" view" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use the `Molecule.view` method, specifying the representation as arguments. Use the `hold` parameter so that following `Molecule.view` calls can overlay. Otherwise, representations will be cleared on every call." ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "collapsed": true }, "outputs": [], "source": [ "mol.view(sel='protein', style='NewCartoon', color='Index', hold=True)\n", "mol.view(sel='resname BEN', style='Licorice', color=1)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### The \"explicit\" way: using `Molecule.reps`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "One directly manipulates elements in the `reps` property of `Molecule` objects, with the views being stored in that property." ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "rep 0: sel='protein', style='NewCartoon', color='Index'\n", "rep 1: sel='resname BEN', style='Licorice', color='1'\n", "\n" ] } ], "source": [ "mol.reps.remove() # Clear representations\n", "mol.reps.add(sel='protein', style='NewCartoon', color='Index')\n", "mol.reps.add(sel='resname BEN', style='Licorice', color=1)\n", "print(mol.reps) # Show list of representations (equivalent to mol.reps.list())\n", "mol.view()" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### Atom selection expressions work as in VMD" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The following shows the molecule without a 6 Å thick slab in the middle (−3 Å ≤ `x` ≤ +3 Å):" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "collapsed": true }, "outputs": [], "source": [ "mol.reps.remove() # in order to remove the previouly stored representations\n", "mol.view(sel='x*x>9')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Visualizing a trajectory" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`Molecule` provides wrapping and aligning functionality for working with MD trajectories and improving the visualization." ] }, { "cell_type": "code", "execution_count": 53, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from htmd.home import home\n", "molTraj = Molecule(home(dataDir='dhfr') + '/dhfr.psf')\n", "molTraj.read(home(dataDir='dhfr') + '/dhfr.xtc')\n", "molTraj.view()" ] } ], "metadata": { "anaconda-cloud": {}, "celltoolbar": "Slideshow", "kernelspec": { "display_name": "Python [default]", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3.0 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.3" }, "nav_menu": {}, "toc": { "navigate_menu": true, "number_sections": true, "sideBar": true, "threshold": 6.0, "toc_cell": false, "toc_section_display": "block", "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 0 }