{ "cells": [ { "cell_type": "markdown", "id": "eebd8987", "metadata": {}, "source": [ "# TMol How-To Guide\n", "\n", "[](https://colab.research.google.com/github/RosettaCommons/tmol/blob/main/docs/tutorial/01_tmol_how_to_guide.ipynb)" ] }, { "cell_type": "markdown", "id": "7cb870c8", "metadata": {}, "source": [ "A single, growing reference notebook for working with TMol. Each section is self-contained and can be run independently once the Setup cell below has run." ] }, { "cell_type": "markdown", "id": "56c086b3", "metadata": {}, "source": [ "## 1. Basics" ] }, { "cell_type": "markdown", "id": "f6748a5f", "metadata": {}, "source": [ "Load a structure from the RCSB, inspect it, change it, save it, and build batches of poses." ] }, { "cell_type": "markdown", "id": "540f0927", "metadata": {}, "source": [ "### Setup\n", "\n" ] }, { "cell_type": "markdown", "id": "afcacc4e", "metadata": {}, "source": [ "In Colab, choose a GPU runtime and Run all. For local execution, follow the [installation guide](../installation.md). This section fetches structures live from the RCSB, so no local fixture files are required.\n", "\n", "The first call into any of TMol's native routines in a fresh environment JIT-compiles kernels and can take several minutes; later calls reuse the compiled cache and are fast.\n", "\n", "Wheel install, imports, seeding, and device selection are not themselves part of what this notebook teaches, so they live in [notebook_setup.py](https://github.com/RosettaCommons/tmol/blob/main/docs/tutorial/notebook_setup.py) and are pulled in with a single call." ] }, { "cell_type": "code", "execution_count": 1, "id": "761537e5", "metadata": { "execution": { "iopub.execute_input": "2026-10-20T00:48:01.326965Z", "iopub.status.busy": "2026-10-20T00:48:01.326766Z", "iopub.status.idle": "2026-10-20T00:48:08.181239Z", "shell.execute_reply": "2026-10-20T00:48:08.180364Z" }, "tags": [ "collapse-code" ] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Environment variable CCD_MIRROR_PATH not set. Will not be able to use function requiring this variable. To set it you may:\n", " (1) add the line 'export VAR_NAME=path/to/variable' to your .bashrc or .zshrc file\n", " (2) set it in your current shell with 'export VAR_NAME=path/to/variable'\n", " (3) write it to a .env file in the root of the atomworks.io repository\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Environment variable PDB_MIRROR_PATH not set. Will not be able to use function requiring this variable. To set it you may:\n", " (1) add the line 'export VAR_NAME=path/to/variable' to your .bashrc or .zshrc file\n", " (2) set it in your current shell with 'export VAR_NAME=path/to/variable'\n", " (3) write it to a .env file in the root of the atomworks.io repository\n" ] } ], "source": [ "try:\n", " import google.colab # noqa: F401\n", "except ImportError:\n", " IN_COLAB = False\n", "else:\n", " IN_COLAB = True\n", "\n", "if IN_COLAB:\n", " from urllib.request import urlretrieve\n", "\n", " urlretrieve(\n", " \"https://raw.githubusercontent.com/RosettaCommons/tmol/\"\n", " \"main/docs/tutorial/notebook_setup.py\",\n", " \"notebook_setup.py\",\n", " )\n", "\n", "from notebook_setup import * # noqa: F401,F403\n", "\n", "device, param_db = setup()\n" ] }, { "cell_type": "markdown", "id": "51164af6", "metadata": {}, "source": [ "### Loading Structures" ] }, { "cell_type": "markdown", "id": "ae944fe5", "metadata": {}, "source": [ "#### Download a CIF file from RCSB" ] }, { "cell_type": "markdown", "id": "83653afc", "metadata": {}, "source": [ "We use [1UBQ](https://www.rcsb.org/structure/1UBQ) (ubiquitin) as the example structure for this section. `fetch_cif` downloads the raw mmCIF text; it is not written to disk here, just held in memory." ] }, { "cell_type": "code", "execution_count": 2, "id": "1e267bf3", "metadata": { "execution": { "iopub.execute_input": "2026-10-20T00:48:08.183536Z", "iopub.status.busy": "2026-10-20T00:48:08.183079Z", "iopub.status.idle": "2026-10-20T00:48:08.263722Z", "shell.execute_reply": "2026-10-20T00:48:08.263044Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "downloaded 1UBQ\n" ] } ], "source": [ "PDB_ID = \"1UBQ\"\n", "ubq_cif_text = fetch_cif(PDB_ID)\n", "print(f\"downloaded {PDB_ID}\")" ] }, { "cell_type": "markdown", "id": "34994ac0", "metadata": {}, "source": [ "#### Load a PoseStack from a CIF" ] }, { "cell_type": "markdown", "id": "58a7615c", "metadata": {}, "source": [ "A PoseStack represents a batch of molecular systems (in this case, just a single structure - ubiquitin). PoseStacks are optimized for compactness for efficient processing on the GPU. `pose_stack_from_file` accepts a path or an in-memory buffer." ] }, { "cell_type": "code", "execution_count": 3, "id": "f0baf263", "metadata": { "execution": { "iopub.execute_input": "2026-10-20T00:48:08.265905Z", "iopub.status.busy": "2026-10-20T00:48:08.265750Z", "iopub.status.idle": "2026-10-20T00:48:12.629505Z", "shell.execute_reply": "2026-10-20T00:48:12.628795Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "n_poses=1, max_n_blocks=76\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/home/runner/work/tmol/tmol/.venv/lib/python3.12/site-packages/biotite/structure/io/pdb/file.py:629: DeprecationWarning: The chararray class is deprecated and will be removed in a future release. Use an ndarray with a string or bytes dtype instead.\n", " record = np.char.array(np.where(array.hetero, \"HETATM\", \"ATOM\"))\n" ] }, { "data": { "application/3dmoljs_load.v0": "
3Dmol.js failed to load for some reason. Please check your browser console for error messages.
3Dmol.js failed to load for some reason. Please check your browser console for error messages.
3Dmol.js failed to load for some reason. Please check your browser console for error messages.
3Dmol.js failed to load for some reason. Please check your browser console for error messages.
3Dmol.js failed to load for some reason. Please check your browser console for error messages.
3Dmol.js failed to load for some reason. Please check your browser console for error messages.