{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Write MMTF Subset Demo\n", "\n", "Simple example writting a subset of mmtf files\n", "\n", "## Imports" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from pyspark import SparkConf, SparkContext\n", "from mmtfPyspark.io import mmtfReader, mmtfWriter\n", "from mmtfPyspark.filters import ExperimentalMethods, Resolution, RFree\n", "from mmtfPyspark.structureViewer import view_structure" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Configure Spark" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "conf = SparkConf().setMaster(\"local[*]\") \\\n", " .setAppName(\"WriteMMTFCustomSubset\")\n", "sc = SparkContext(conf = conf)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Read in a fractions of entries from a local Hadoop Sequence File" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "number of pdb entries read : 2215\n" ] } ], "source": [ "path = \"../../resources/mmtf_full_sample/\"\n", "fraction= 0.5\n", "seed = 123\n", "\n", "pdb = mmtfReader.read_sequence_file(path, sc, fraction = fraction, seed = seed)\n", "\n", "count = pdb.count()\n", "\n", "print(f'number of pdb entries read : {count}')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Retain high resolution X-ray structures" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "number of pdb entries left : 510\n" ] } ], "source": [ "pdb = pdb.filter(ExperimentalMethods(ExperimentalMethods.X_RAY_DIFFRACTION)) \\\n", " .filter(Resolution(0,2.0)) \\\n", " .filter(RFree(0,2.0))\n", "\n", "print(f'number of pdb entries left : {pdb.count()}')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualize Structures" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "22b3bb2a0a2149be880469adfae48cd0", "version_major": 2, "version_minor": 0 }, "text/html": [ "
Failed to display Jupyter Widget of type interactive
.
\n", " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", " that the widgets JavaScript is still loading. If this message persists, it\n", " likely means that the widgets JavaScript library is either not installed or\n", " not enabled. See the Jupyter\n", " Widgets Documentation for setup instructions.\n", "
\n", "\n", " If you're reading this message in another frontend (for example, a static\n", " rendering on GitHub or NBViewer),\n", " it may mean that your frontend doesn't currently support widgets.\n", "
\n" ], "text/plain": [ "interactive(children=(IntSlider(value=0, description='i', max=509), Output()), _dom_classes=('widget-interact',))" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "