{ "cells": [ { "cell_type": "code", "execution_count": 69, "id": "initial_id", "metadata": { "ExecuteTime": { "end_time": "2026-01-24T09:06:36.981469Z", "start_time": "2026-01-24T09:06:36.975634Z" } }, "outputs": [], "source": [ "import nglview as nv\n", "import os" ] }, { "cell_type": "code", "execution_count": 106, "id": "d8d7978e-980a-400c-8c6a-5365990c8855", "metadata": { "ExecuteTime": { "end_time": "2026-01-24T09:06:37.011231Z", "start_time": "2026-01-24T09:06:37.005099Z" } }, "outputs": [], "source": [ "PDBBIND_PATH = \"refined-set\"" ] }, { "cell_type": "code", "execution_count": 107, "id": "788a6b43-c515-45c7-bc52-341d446b1a65", "metadata": { "ExecuteTime": { "end_time": "2026-01-24T09:06:37.022991Z", "start_time": "2026-01-24T09:06:37.016849Z" } }, "outputs": [], "source": [ "EXAMPLE_PDB_ID = \"1a1e\"" ] }, { "cell_type": "code", "execution_count": 108, "id": "e8f4bebc-845f-43e8-bc4d-ab7b649eb49c", "metadata": { "ExecuteTime": { "end_time": "2026-01-24T09:06:37.041322Z", "start_time": "2026-01-24T09:06:37.035944Z" } }, "outputs": [], "source": [ "pdb_dir = os.path.join(PDBBIND_PATH, EXAMPLE_PDB_ID)" ] }, { "cell_type": "code", "execution_count": 109, "id": "24b5e435-4d8f-4505-b27c-dd6317376ed4", "metadata": { "ExecuteTime": { "end_time": "2026-01-24T09:06:37.064924Z", "start_time": "2026-01-24T09:06:37.059278Z" } }, "outputs": [], "source": [ "protein_file = os.path.join(pdb_dir, f\"{EXAMPLE_PDB_ID}_protein.pdb\")" ] }, { "cell_type": "code", "execution_count": 110, "id": "e7fc3539-00c0-48a2-b012-c80757fa12c4", "metadata": { "ExecuteTime": { "end_time": "2026-01-24T09:06:37.080165Z", "start_time": "2026-01-24T09:06:37.074657Z" } }, "outputs": [], "source": [ "ligand_file = os.path.join(pdb_dir, f\"{EXAMPLE_PDB_ID}_ligand.sdf\")" ] }, { "cell_type": "code", "execution_count": 121, "id": "9a053b99-7c01-4881-b3f7-e9b39090af9d", "metadata": { "ExecuteTime": { "end_time": "2026-01-24T09:06:37.126934Z", "start_time": "2026-01-24T09:06:37.107047Z" } }, "outputs": [], "source": [ "view = nv.NGLWidget()" ] }, { "cell_type": "code", "execution_count": 123, "id": "df8c8e00-3ce6-41dd-b457-d9f50e318dad", "metadata": { "ExecuteTime": { "end_time": "2026-01-24T09:06:37.209871Z", "start_time": "2026-01-24T09:06:37.140785Z" } }, "outputs": [], "source": [ "protein_comp = view.add_component(protein_file)" ] }, { "cell_type": "code", "execution_count": 157, "id": "c191fead-fef8-4077-b787-5bf9552307b1", "metadata": { "ExecuteTime": { "end_time": "2026-01-24T09:06:37.243271Z", "start_time": "2026-01-24T09:06:37.235380Z" } }, "outputs": [], "source": [ "protein_comp.clear_representations()" ] }, { "cell_type": "code", "execution_count": 152, "id": "4559033a-aeda-4659-8d91-9002b5a6ecda", "metadata": { "ExecuteTime": { "end_time": "2026-01-24T09:06:37.276519Z", "start_time": "2026-01-24T09:06:37.270030Z" } }, "outputs": [], "source": [ "protein_comp.add_representation(\"cartoon\", color=\"blue\")" ] }, { "cell_type": "code", "execution_count": 150, "id": "566239a0-1587-447a-8ce8-d4cc9ac65907", "metadata": {}, "outputs": [], "source": [ "protein_comp.add_representation(\n", " \"surface\", opacity=0.6, color=\"lightblue\", probeRadius=1.4, quality=\"high\", smooth=2\n", ")" ] }, { "cell_type": "code", "execution_count": 143, "id": "73ea1a50-8463-40b8-a942-0c92d3e97a97", "metadata": { "ExecuteTime": { "end_time": "2026-01-24T09:06:37.309460Z", "start_time": "2026-01-24T09:06:37.299153Z" } }, "outputs": [], "source": [ "ligand_comp = view.add_component(ligand_file)" ] }, { "cell_type": "code", "execution_count": 153, "id": "16cdb710-1ed6-4b1d-9e6a-69b7ad61a600", "metadata": { "ExecuteTime": { "end_time": "2026-01-24T09:06:37.340286Z", "start_time": "2026-01-24T09:06:37.333802Z" } }, "outputs": [], "source": [ "ligand_comp.clear_representations()" ] }, { "cell_type": "code", "execution_count": 155, "id": "2193c497-f33c-4de0-86a9-6e535002fcb7", "metadata": { "ExecuteTime": { "end_time": "2026-01-24T09:06:37.372239Z", "start_time": "2026-01-24T09:06:37.365156Z" } }, "outputs": [], "source": [ "ligand_comp.add_representation(\"ball+stick\", radius=0.3)" ] }, { "cell_type": "code", "execution_count": 132, "id": "4bd2a6e3-a618-41b1-b80a-24d0344c5da9", "metadata": {}, "outputs": [], "source": [ "# ligand_comp.add_representation(\"licorice\",\n", "# colorBy=\"element\",\n", "# radius=0.3,\n", "# quality=\"high\")" ] }, { "cell_type": "code", "execution_count": 100, "id": "88c2bbaf-b7a4-401c-83af-5cc8241db079", "metadata": {}, "outputs": [], "source": [ "# ligand_comp.add_representation(\"spacefill\", radiusScale=0.5)" ] }, { "cell_type": "code", "execution_count": 119, "id": "5fc618db-a84d-4b55-9a4c-3ee5ea8b8f3d", "metadata": {}, "outputs": [], "source": [ "view.background = \"white\"" ] }, { "cell_type": "code", "execution_count": 122, "id": "b1cc7f44-a374-4400-b4ba-8f75101b21ce", "metadata": { "ExecuteTime": { "end_time": "2026-01-24T09:06:37.406445Z", "start_time": "2026-01-24T09:06:37.398945Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "61e776b5347d4c9fb531d8ac7298afd0", "version_major": 2, "version_minor": 0 }, "text/plain": [ "NGLWidget()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "view" ] }, { "cell_type": "code", "execution_count": null, "id": "b9c8d87e-8146-4b45-a362-86472a2409c4", "metadata": {}, "outputs": [], "source": [ "nv.write_html(\"1a1e.html\", view)" ] }, { "cell_type": "code", "execution_count": 158, "id": "956d85dc-9520-4f64-9258-76d52553ffe5", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Exception in thread Thread-4:\n", "Traceback (most recent call last):\n", " File \"C:\\Users\\Alex\\Desktop\\binding_affinity\\.venv\\Lib\\site-packages\\nglview\\remote_thread.py\", line 42, in run\n", " callback = self.q.pop(0)\n", " ^^^^^^^^^^^^^\n", "IndexError: pop from empty list\n", "\n", "During handling of the above exception, another exception occurred:\n", "\n", "Traceback (most recent call last):\n", " File \"C:\\Users\\Alex\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\threading.py\", line 1073, in _bootstrap_inner\n", " self.run()\n", " File \"C:\\Users\\Alex\\Desktop\\binding_affinity\\.venv\\Lib\\site-packages\\nglview\\remote_thread.py\", line 47, in run\n", " time.sleep(self.timeout)\n", "OSError: [WinError 1450] Insufficient system resources exist to complete the requested service\n" ] } ], "source": [ "view.download_image(\"1a1e.jpg\", factor=8)" ] }, { "cell_type": "code", "execution_count": null, "id": "a0acd172-7c80-4322-850c-91c25dde225e", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.12.4" } }, "nbformat": 4, "nbformat_minor": 5 }