{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example of using PySpark to find ligand interaction fingerprint\n", "\n", "Demo how to calculate ligand-polymer interaction data and maps it to polymer chains." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Imports and variables" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "scrolled": true }, "outputs": [], "source": [ "from pyspark import SparkConf, SparkContext \n", "from mmtfPyspark.io import mmtfReader\n", "from mmtfPyspark.interactions import InteractionFilter, InteractionFingerprinter\n", " \n", "# Create variables \n", "APP_NAME = \"MMTF_Spark\" \n", "\n", "# Configure Spark \n", "conf = SparkConf().setAppName(APP_NAME).setMaster(\"local[*]\") \n", "sc = SparkContext(conf=conf) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Download 1OHR structure" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "pdb = mmtfReader.download_mmtf_files(['1OHR'], sc)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Find interactions of small molecules (except water)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
structureChainIdqueryLigandIdqueryLigandNumberqueryLigandChainIdtargetChainIdgroupNumberssequenceIndicessequenceinteractingChains
01OHR.A1UN201AA[25, 27, 28, 29, 30, 49, 50, 80, 81, 82, 84][24, 26, 27, 28, 29, 48, 49, 79, 80, 81, 83]PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM...2
11OHR.B1UN201AB[8, 23, 25, 27, 28, 29, 30, 32, 47, 48, 49, 50...[7, 22, 24, 26, 27, 28, 29, 31, 46, 47, 48, 49...PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM...2
\n", "
" ], "text/plain": [ " structureChainId queryLigandId queryLigandNumber queryLigandChainId \\\n", "0 1OHR.A 1UN 201 A \n", "1 1OHR.B 1UN 201 A \n", "\n", " targetChainId groupNumbers \\\n", "0 A [25, 27, 28, 29, 30, 49, 50, 80, 81, 82, 84] \n", "1 B [8, 23, 25, 27, 28, 29, 30, 32, 47, 48, 49, 50... \n", "\n", " sequenceIndices \\\n", "0 [24, 26, 27, 28, 29, 48, 49, 79, 80, 81, 83] \n", "1 [7, 22, 24, 26, 27, 28, 29, 31, 46, 47, 48, 49... \n", "\n", " sequence interactingChains \n", "0 PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM... 2 \n", "1 PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM... 2 " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "interactionFilter = InteractionFilter()\n", "interactionFilter.set_distance_cutoff(4.0)\n", "interactionFilter.set_query_groups(False, \"HOH\") # ignore water interactions\n", "\n", "interactions = InteractionFingerprinter.get_ligand_polymer_interactions(pdb, interactionFilter)\n", "interactions.toPandas().head(10) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Terminate Spark" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "sc.stop()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "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.6.0" } }, "nbformat": 4, "nbformat_minor": 2 }