{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true, "slideshow": { "slide_type": "slide" } }, "outputs": [], "source": [ "from IPython.display import HTML\n", "HTML('')" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### Structures like these are encoded in \"PDB\" files" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "![pdb_atoms](https://raw.githubusercontent.com/harmsm/pythonic-science/master/chapters/03_dealing-with-files/data/pdb_header.png)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "![pdb_atoms](https://raw.githubusercontent.com/harmsm/pythonic-science/master/chapters/03_dealing-with-files/data/pdb_atoms.png)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Entries are determined by columns in the file, not by spaces between the columns" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "#record atom_name chain x y z occupancy atom_type\n", "# | | | | | | | |\n", "#ATOM 1086 CG LYS A 141 -4.812 9.683 2.584 1.00 26.78 N0\n", "# | | | |\n", "# atom_num amino_acid resid_num bfactor" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### Predict what the following will do" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "line_frompdb = \"ATOM 1086 N SER A 141 -4.812 9.683 2.584 1.00 26.78 N0\"\n", "print(line_frompdb[2:4])" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Write a program that: \n", "+ Reads a pdb file (download 1stn.pdb)\n", "+ Grabs all \"ATOM\" lines whose atom type is \"CA\" \n", "+ Shifts the position of the molecule in x by +10 angstroms\n", "+ Writes out a new pdb file containing these shifted atoms\n", "+ If you want to check your work, download PyMOL and open up the files" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "#record atom_name chain x y z occupancy atom_type\n", "# | | | | | | | |\n", "#ATOM 1086 CG LYS A 141 -4.812 9.683 2.584 1.00 26.78 N0\n", "# | | | |\n", "# atom_num amino_acid resid_num bfactor" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "f = open(\"data/1stn.pdb\")\n", "g = open(\"1stn_shifted.pdb\",\"w\")\n", "\n", "for line in f.readlines():\n", " if line[0:4] == \"ATOM\" and line[13:16] == \"CA \":\n", "\n", " first_chunk = line[:30]\n", " x = line[30:38]\n", " last_chunk = line[38:]\n", " \n", " new_x = float(x) + 10\n", " \n", " g.write(\"{:}{:8.3f}{:}\".format(first_chunk,new_x,last_chunk))\n", "\n", "f.close()\n", "g.close()" ] } ], "metadata": { "celltoolbar": "Slideshow", "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 1 }