{ "cells": [ { "cell_type": "markdown", "id": "1afec672", "metadata": {}, "source": [ "# TMol How-To Guide — Constraints\n", "\n", "[](https://colab.research.google.com/github/RosettaCommons/tmol/blob/main/docs/tutorial/06_constraints.ipynb)" ] }, { "cell_type": "markdown", "id": "b2162287", "metadata": {}, "source": [ "## 6. Constraints" ] }, { "cell_type": "markdown", "id": "7dd743d4", "metadata": {}, "source": [ "Constraints are extra harmonic (or similar) restraint terms attached to a `PoseStack` and scored like any other energy term, at weight 0 by default. Section 2 already used one ready-made constraint generator; this notebook covers the general mechanism and a few more targeted examples." ] }, { "cell_type": "markdown", "id": "2de0598e", "metadata": {}, "source": [ "### Setup" ] }, { "cell_type": "markdown", "id": "efb17d3b", "metadata": {}, "source": [ "Wheel install, imports, seeding, and device selection live in [notebook_setup.py](https://github.com/RosettaCommons/tmol/blob/main/docs/tutorial/notebook_setup.py)." ] }, { "cell_type": "code", "execution_count": 1, "id": "c941c1bd", "metadata": { "execution": { "iopub.execute_input": "2026-10-19T23:48:29.616523Z", "iopub.status.busy": "2026-10-19T23:48:29.616277Z", "iopub.status.idle": "2026-10-19T23:48:41.211921Z", "shell.execute_reply": "2026-10-19T23:48:41.210973Z" }, "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": "012dfc0d", "metadata": {}, "source": [ "### Generating constraints programmatically" ] }, { "cell_type": "markdown", "id": "c17e5542", "metadata": {}, "source": [ "`ConstraintSet.create_empty(device, n_poses)` starts empty; `.add_constraints(constraint_function, atoms, params)` returns a new `ConstraintSet` with one more kind of restraint added. `ConstraintEnergyTerm.harmonic` is the simplest constraint function -- a single harmonic distance restraint between two atoms, `params[:, 0]` the target distance and `params[:, 1]` its standard deviation -- and `atoms` is `[constraint, atom_slot, (pose, block, atom)]` for each side." ] }, { "cell_type": "code", "execution_count": 2, "id": "dae7e9b1", "metadata": { "execution": { "iopub.execute_input": "2026-10-19T23:48:41.215646Z", "iopub.status.busy": "2026-10-19T23:48:41.215205Z", "iopub.status.idle": "2026-10-19T23:48:47.393705Z", "shell.execute_reply": "2026-10-19T23:48:47.392638Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "constraints defined: 1\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.
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.