{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Custom Modifiers"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"> ### In this tutorial we will cover:\n",
"> - how we can define our own modifier functions like `carboxylate`\n",
"> - how we can define other modifier functions"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Building molecules is a straightforward task in BuildAMol. A \"modifier\" function is essentially any function that will take a molecule as argument and return a modified version thereof. There is technically nothing special about this process, so you can write any function that performs some action on the molecule and you have a working modifier. Why this tutorial then? You may have been using the available modifiers such as `hydroxylate` or `carboxylate` that can add functional groups to one or more positions in a molecule. This tutorial explains how they work so that you can more efficiently make your own modifiers. \n",
"\n",
"Let's dive in!"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
" \n",
" "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import plotly\n",
"plotly.offline.init_notebook_mode()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"import buildamol as bam"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Functional Group Modifiers\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"All the default modifiers share the same architecture actually. They take one molecule as argument alongside with information on where to modify, then they obtain a reference molecule for the respective functional group they want to add, then they call the `_modify` function which provides a generic implementation for attaching one molecule (the functional group) to multiple locations of a target molecule.\n",
"\n",
"To illustrate this, let's remake our own `carboxylate` function!"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[Molecule(CBX), Molecule(FMT)]"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# first we need to get a suitable reference molecule for the carboxyl group. \n",
"# Formic Acid should be the best choice. Let's see if we have that in the database\n",
"bam.load_small_molecules()\n",
"bam.get_compound(\"formic acid\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"So we have even two! `CBX` is officially called `carboxy group` in the database while `FMT` is `formic acid`, but structurally they are identical. Let's use `CBX` for our function. Now that we know which reference molecule to use for our carboxyl group we can do additional preprocessing steps. For instance, it is common to call the carbonyl-carbon `C` and the hydroxyl-Oxygen `OXT`. If we want our carboxyl group to adhere to these conventions we will have to rename the atoms accordingly. "
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/noahhk/anaconda3/envs/glyco2/lib/python3.11/site-packages/plotly/express/_core.py:1985: FutureWarning:\n",
"\n",
"When grouping with a length-1 list-like, you will need to pass a length-1 tuple to get_group in a future version of pandas. Pass `(name,)` instead of `name` to silence this warning.\n",
"\n"
]
},
{
"data": {
"application/vnd.plotly.v1+json": {
"config": {
"plotlyServerURL": "https://plot.ly"
},
"data": [
{
"customdata": [
[
"C",
1,
1,
"CBX",
"A"
]
],
"hovertemplate": "atom_element=C
x=%{x}
y=%{y}
z=%{z}
__marker_size=%{marker.size}
atom_id=%{customdata[0]}
atom_serial=%{customdata[1]}
residue_serial=%{customdata[2]}
residue_name=%{customdata[3]}
chain_id=%{customdata[4]}
x=%{x}
y=%{y}
z=%{z}
__marker_size=%{marker.size}
atom_id=%{customdata[0]}
atom_serial=%{customdata[1]}
residue_serial=%{customdata[2]}
residue_name=%{customdata[3]}
chain_id=%{customdata[4]}
x=%{x}
y=%{y}
z=%{z}
__marker_size=%{marker.size}
atom_id=%{customdata[0]}
atom_serial=%{customdata[1]}
residue_serial=%{customdata[2]}
residue_name=%{customdata[3]}
chain_id=%{customdata[4]}
You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n jupyter labextension install jupyterlab_3dmol
You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n",
" jupyter labextension install jupyterlab_3dmol
You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n jupyter labextension install jupyterlab_3dmol
You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n",
" jupyter labextension install jupyterlab_3dmol
You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n jupyter labextension install jupyterlab_3dmol
You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n",
" jupyter labextension install jupyterlab_3dmol
You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n jupyter labextension install jupyterlab_3dmol
You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n",
" jupyter labextension install jupyterlab_3dmol