{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Adding Resources\n", "\n", "> ### In this tutorial we will cover:\n", "> - how we can set custom default resources" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you checked out the tutorial on _built-in_ data resources you know that biobuild comes with a variety of molecular structures for the user to work with directly, such as compounds containing amino acids or sugars. These can be easily loaded using functions such as `load_sugars()`. However, what if we are working on a drug discovery project and would like to engineer small variations of a promising compound? We may have a structure of the compound itself but we don't want to keep re-loading them every time we open a new notebook to use biobuild. But we would like for it to be available by default. \n", "\n", "Luckily, biobuild allows us to set our own _defaults_ that can be loaded in every future session. We can add _custom linkages_ and _custom structures_ to the default CHARMM topology and PDBE Compounds, respecitively using functions `add_linkage` and `add_compound`. Here's how:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Adding custom linkages\n", "\n", "You may know that you can refer to any registered linkage directly via its string identifier. For example, we can refer to a beta 1->4 glycosydic linkage by its id `14bb`. We do not need to get the linkage object first because biobuild will be able to interpret the id and search the linkage object automatically. To make a custom linkage available in such a way, we simply need to define it, give it an id (which is otherwise optional when creating a `Linkage` object). Then we call `add_linkage` with our new linkage and that's it!" ] }, { "cell_type": "code", "execution_count": 1, "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": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[Linkage(SCK0),\n", " Linkage(SCK1),\n", " Linkage(LLLO),\n", " Linkage(CERA),\n", " Linkage(CERB),\n", " Linkage(DAGA),\n", " Linkage(DAGB),\n", " Linkage(INS2A),\n", " Linkage(INS2B),\n", " Linkage(INS6A),\n", " Linkage(INS6B),\n", " Linkage(SGPA),\n", " Linkage(TGPA),\n", " Linkage(SGPB),\n", " Linkage(TGPB),\n", " Linkage(NGLA),\n", " Linkage(11aa),\n", " Linkage(11ab),\n", " Linkage(11bb),\n", " Linkage(12aa),\n", " Linkage(12ab),\n", " Linkage(12ba),\n", " Linkage(12bb),\n", " Linkage(13aa),\n", " Linkage(13ab),\n", " Linkage(13ba),\n", " Linkage(13bb),\n", " Linkage(14aa),\n", " Linkage(14ab),\n", " Linkage(14ba),\n", " Linkage(14bb),\n", " Linkage(16aa),\n", " Linkage(16ab),\n", " Linkage(16ba),\n", " Linkage(SUCR),\n", " Linkage(LCTL),\n", " Linkage(AB15),\n", " Linkage(SA23AB),\n", " Linkage(LINK),\n", " Linkage(my_14_glyco_link)]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import biobuild as bb\n", "\n", "# define a custom link\n", "my_link = bb.linkage(\"C1\", \"O4\", [\"O1\", \"HO1\"], [\"HO4\"], id=\"my_14_glyco_link\")\n", "\n", "# now add the link to the default CHARMM topology\n", "bb.add_linkage(my_link)\n", "\n", "# now we find it at the bottom of the list of 'out-of-the-box' available linkages\n", "bb.available_linkages()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can now make use of our custom linkage just as we would use any of the predefined ones. So, to connect a glucose and a mannose using our new linkage, we can do:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "customdata": [ [ "C1", 1, 1, "GLC", "A" ], [ "C2", 2, 1, "GLC", "A" ], [ "C3", 3, 1, "GLC", "A" ], [ "C4", 4, 1, "GLC", "A" ], [ "C5", 5, 1, "GLC", "A" ], [ "C6", 6, 1, "GLC", "A" ], [ "C1", 23, 2, "MAN", "A" ], [ "C2", 24, 2, "MAN", "A" ], [ "C3", 25, 2, "MAN", "A" ], [ "C4", 26, 2, "MAN", "A" ], [ "C5", 27, 2, "MAN", "A" ], [ "C6", 28, 2, "MAN", "A" ] ], "hovertemplate": "atom_element=C
x=%{x}
y=%{y}
z=%{z}
atom_id=%{customdata[0]}
atom_serial=%{customdata[1]}
residue_serial=%{customdata[2]}
residue_name=%{customdata[3]}
chain_id=%{customdata[4]}", "legendgroup": "C", "marker": { "color": "darkslategray", "opacity": 1, "symbol": "circle" }, "mode": "markers", "name": "C", "scene": "scene", "showlegend": true, "type": "scatter3d", "x": [ -0.567, -1.578, -1.179, 0.249, 1.189, 2.607, 1.0412284533787022, 1.6458347466942311, 1.2782669252045022, -0.2430780854798531, -0.7032729071897424, -2.2174573649219873 ], "y": [ 1.572, 0.465, -0.806, -1.195, -0.024, -0.383, 5.2036268609345715, 4.8101677425692495, 3.354573583181976, 3.200565825867666, 3.715702562793978, 3.5335931551889543 ], "z": [ -0.245, -0.554, 0.203, -0.192, 0.102, -0.345, 2.6132992149825363, 1.2637696109136085, 0.9590048823721431, 1.0623149455452712, 2.426973462662397, 2.5550226392464475 ] }, { "customdata": [ [ "O2", 7, 1, "GLC", "A" ], [ "O3", 8, 1, "GLC", "A" ], [ "O4", 9, 1, "GLC", "A" ], [ "O5", 10, 1, "GLC", "A" ], [ "O6", 11, 1, "GLC", "A" ], [ "O1", 29, 2, "MAN", "A" ], [ "O2", 30, 2, "MAN", "A" ], [ "O3", 31, 2, "MAN", "A" ], [ "O4", 32, 2, "MAN", "A" ], [ "O5", 33, 2, "MAN", "A" ], [ "O6", 34, 2, "MAN", "A" ] ], "hovertemplate": "atom_element=O
x=%{x}
y=%{y}
z=%{z}
atom_id=%{customdata[0]}
atom_serial=%{customdata[1]}
residue_serial=%{customdata[2]}
residue_name=%{customdata[3]}
chain_id=%{customdata[4]}", "legendgroup": "O", "marker": { "color": "red", "opacity": 1, "symbol": "circle" }, "mode": "markers", "name": "O", "scene": "scene", "showlegend": true, "type": "scatter3d", "x": [ -2.881, -2.075, 0.658, 0.744, 3.506, 1.5417583977808431, 1.1251242458716428, 1.708400882482027, -0.5946656044193569, -0.3794827686925375, -2.6483088357978604 ], "y": [ 0.879, -1.866, -2.338, 1.133, 0.661, 4.332403807590114, 5.6603947585998124, 3.0187633237363576, 1.8226671430723538, 5.097368566672854, 4.010511409712635 ], "z": [ -0.139, -0.137, 0.562, -0.608, 0.035, 3.6285790611717283, 0.24135453104396315, -0.3624175513892347, 0.9253389021036997, 2.5559424509399626, 3.8303037802291664 ] }, { "customdata": [ [ "H1", 12, 1, "GLC", "A" ], [ "H2", 13, 1, "GLC", "A" ], [ "H3", 14, 1, "GLC", "A" ], [ "H4", 15, 1, "GLC", "A" ], [ "H5", 16, 1, "GLC", "A" ], [ "H61", 17, 1, "GLC", "A" ], [ "H62", 18, 1, "GLC", "A" ], [ "HO2", 19, 1, "GLC", "A" ], [ "HO3", 20, 1, "GLC", "A" ], [ "HO4", 21, 1, "GLC", "A" ], [ "HO6", 22, 1, "GLC", "A" ], [ "H1", 35, 2, "MAN", "A" ], [ "H2", 36, 2, "MAN", "A" ], [ "H3", 37, 2, "MAN", "A" ], [ "H4", 38, 2, "MAN", "A" ], [ "H5", 39, 2, "MAN", "A" ], [ "H61", 40, 2, "MAN", "A" ], [ "H62", 41, 2, "MAN", "A" ], [ "HO1", 42, 2, "MAN", "A" ], [ "HO2", 43, 2, "MAN", "A" ], [ "HO3", 44, 2, "MAN", "A" ], [ "HO6", 45, 2, "MAN", "A" ] ], "hovertemplate": "atom_element=H
x=%{x}
y=%{y}
z=%{z}
atom_id=%{customdata[0]}
atom_serial=%{customdata[1]}
residue_serial=%{customdata[2]}
residue_name=%{customdata[3]}
chain_id=%{customdata[4]}", "legendgroup": "H", "marker": { "color": "lightgray", "opacity": 1, "symbol": "circle" }, "mode": "markers", "name": "H", "scene": "scene", "showlegend": true, "type": "scatter3d", "x": [ -0.822, -1.583, -1.223, 0.281, 1.187, 2.913, 2.627, -3.197, -3, 0.102, 4.425, 1.3192516342969647, 2.7295835361502903, 1.7630034825492609, -0.7220919572637852, -0.2037786290066907, -2.7182450280798114, -2.466598025937429, 1.1429996109897875, 1.3727482686737793, 2.667287282996804, -3.6052614134328644 ], "y": [ 2.466, 0.264, -0.619, -1.429, 0.184, -1.315, -0.503, 1.682, -1.684, -3.118, 0.501, 6.230936865490683, 4.911871278338715, 2.6958569666947336, 3.7794271674609354, 3.1517572395636404, 4.0981102973873345, 2.477423279597051, 4.615928687892744, 6.564759315749751, 3.1420476018530348, 3.8789336841575066 ], "z": [ -0.815, -1.626, 1.276, -1.257, 1.173, 0.129, -1.428, -0.576, 0.08, 0.427, -0.218, 2.849577155999066, 1.3048299587508536, 1.679119379613486, 0.27214771144390226, 3.2141298248097296, 1.7678796328028274, 2.457924107223708, 4.461666734953009, 0.47648872911451556, -0.38390842566330696, 3.870028662802439 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ -0.567, -1.578 ], "y": [ 1.572, 0.465 ], "z": [ -0.245, -0.554 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ -0.567, 0.744 ], "y": [ 1.572, 1.133 ], "z": [ -0.245, -0.608 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ -0.567, -0.822 ], "y": [ 1.572, 2.466 ], "z": [ -0.245, -0.815 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ -0.567, -0.5946656044193569 ], "y": [ 1.572, 1.8226671430723538 ], "z": [ -0.245, 0.9253389021036997 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ -1.578, -1.179 ], "y": [ 0.465, -0.806 ], "z": [ -0.554, 0.203 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ -1.578, -2.881 ], "y": [ 0.465, 0.879 ], "z": [ -0.554, -0.139 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ -1.578, -1.583 ], "y": [ 0.465, 0.264 ], "z": [ -0.554, -1.626 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ -1.179, 0.249 ], "y": [ -0.806, -1.195 ], "z": [ 0.203, -0.192 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ -1.179, -2.075 ], "y": [ -0.806, -1.866 ], "z": [ 0.203, -0.137 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ -1.179, -1.223 ], "y": [ -0.806, -0.619 ], "z": [ 0.203, 1.276 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 0.249, 1.189 ], "y": [ -1.195, -0.024 ], "z": [ -0.192, 0.102 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 0.249, 0.658 ], "y": [ -1.195, -2.338 ], "z": [ -0.192, 0.562 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 0.249, 0.281 ], "y": [ -1.195, -1.429 ], "z": [ -0.192, -1.257 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 1.189, 2.607 ], "y": [ -0.024, -0.383 ], "z": [ 0.102, -0.345 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 1.189, 0.744 ], "y": [ -0.024, 1.133 ], "z": [ 0.102, -0.608 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 1.189, 1.187 ], "y": [ -0.024, 0.184 ], "z": [ 0.102, 1.173 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 2.607, 3.506 ], "y": [ -0.383, 0.661 ], "z": [ -0.345, 0.035 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 2.607, 2.913 ], "y": [ -0.383, -1.315 ], "z": [ -0.345, 0.129 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 2.607, 2.627 ], "y": [ -0.383, -0.503 ], "z": [ -0.345, -1.428 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ -2.881, -3.197 ], "y": [ 0.879, 1.682 ], "z": [ -0.139, -0.576 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ -2.075, -3 ], "y": [ -1.866, -1.684 ], "z": [ -0.137, 0.08 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 0.658, 0.102 ], "y": [ -2.338, -3.118 ], "z": [ 0.562, 0.427 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 3.506, 4.425 ], "y": [ 0.661, 0.501 ], "z": [ 0.035, -0.218 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 1.0412284533787022, 1.6458347466942311 ], "y": [ 5.2036268609345715, 4.8101677425692495 ], "z": [ 2.6132992149825363, 1.2637696109136085 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 1.0412284533787022, 1.5417583977808431 ], "y": [ 5.2036268609345715, 4.332403807590114 ], "z": [ 2.6132992149825363, 3.6285790611717283 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 1.0412284533787022, -0.3794827686925375 ], "y": [ 5.2036268609345715, 5.097368566672854 ], "z": [ 2.6132992149825363, 2.5559424509399626 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 1.0412284533787022, 1.3192516342969647 ], "y": [ 5.2036268609345715, 6.230936865490683 ], "z": [ 2.6132992149825363, 2.849577155999066 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 1.6458347466942311, 1.2782669252045022 ], "y": [ 4.8101677425692495, 3.354573583181976 ], "z": [ 1.2637696109136085, 0.9590048823721431 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 1.6458347466942311, 1.1251242458716428 ], "y": [ 4.8101677425692495, 5.6603947585998124 ], "z": [ 1.2637696109136085, 0.24135453104396315 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 1.6458347466942311, 2.7295835361502903 ], "y": [ 4.8101677425692495, 4.911871278338715 ], "z": [ 1.2637696109136085, 1.3048299587508536 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 1.2782669252045022, -0.2430780854798531 ], "y": [ 3.354573583181976, 3.200565825867666 ], "z": [ 0.9590048823721431, 1.0623149455452712 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 1.2782669252045022, 1.708400882482027 ], "y": [ 3.354573583181976, 3.0187633237363576 ], "z": [ 0.9590048823721431, -0.3624175513892347 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 1.2782669252045022, 1.7630034825492609 ], "y": [ 3.354573583181976, 2.6958569666947336 ], "z": [ 0.9590048823721431, 1.679119379613486 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ -0.2430780854798531, -0.7032729071897424 ], "y": [ 3.200565825867666, 3.715702562793978 ], "z": [ 1.0623149455452712, 2.426973462662397 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ -0.2430780854798531, -0.5946656044193569 ], "y": [ 3.200565825867666, 1.8226671430723538 ], "z": [ 1.0623149455452712, 0.9253389021036997 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ -0.2430780854798531, -0.7220919572637852 ], "y": [ 3.200565825867666, 3.7794271674609354 ], "z": [ 1.0623149455452712, 0.27214771144390226 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ -0.7032729071897424, -2.2174573649219873 ], "y": [ 3.715702562793978, 3.5335931551889543 ], "z": [ 2.426973462662397, 2.5550226392464475 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ -0.7032729071897424, -0.3794827686925375 ], "y": [ 3.715702562793978, 5.097368566672854 ], "z": [ 2.426973462662397, 2.5559424509399626 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ -0.7032729071897424, -0.2037786290066907 ], "y": [ 3.715702562793978, 3.1517572395636404 ], "z": [ 2.426973462662397, 3.2141298248097296 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ -2.2174573649219873, -2.6483088357978604 ], "y": [ 3.5335931551889543, 4.010511409712635 ], "z": [ 2.5550226392464475, 3.8303037802291664 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ -2.2174573649219873, -2.7182450280798114 ], "y": [ 3.5335931551889543, 4.0981102973873345 ], "z": [ 2.5550226392464475, 1.7678796328028274 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ -2.2174573649219873, -2.466598025937429 ], "y": [ 3.5335931551889543, 2.477423279597051 ], "z": [ 2.5550226392464475, 2.457924107223708 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 1.5417583977808431, 1.1429996109897875 ], "y": [ 4.332403807590114, 4.615928687892744 ], "z": [ 3.6285790611717283, 4.461666734953009 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 1.1251242458716428, 1.3727482686737793 ], "y": [ 5.6603947585998124, 6.564759315749751 ], "z": [ 0.24135453104396315, 0.47648872911451556 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ 1.708400882482027, 2.667287282996804 ], "y": [ 3.0187633237363576, 3.1420476018530348 ], "z": [ -0.3624175513892347, -0.38390842566330696 ] }, { "hoverinfo": "skip", "line": { "color": "black", "width": 1.44 }, "mode": "lines", "showlegend": false, "type": "scatter3d", "x": [ -2.6483088357978604, -3.6052614134328644 ], "y": [ 4.010511409712635, 3.8789336841575066 ], "z": [ 3.8303037802291664, 3.870028662802439 ] } ], "layout": { "scene": { "xaxis": { "showgrid": false, "showline": false, "showticklabels": false }, "yaxis": { "showgrid": false, "showline": false, "showticklabels": false }, "zaxis": { "showgrid": false, "showline": false, "showticklabels": false } }, "template": { "data": { "bar": [ { "error_x": { "color": "rgb(36,36,36)" }, "error_y": { "color": "rgb(36,36,36)" }, "marker": { "line": { "color": "white", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "white", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "rgb(36,36,36)", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "rgb(36,36,36)" }, "baxis": { "endlinecolor": "rgb(36,36,36)", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "rgb(36,36,36)" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" }, "colorscale": [ [ 0, "#440154" ], [ 0.1111111111111111, "#482878" ], [ 0.2222222222222222, "#3e4989" ], [ 0.3333333333333333, "#31688e" ], [ 0.4444444444444444, "#26828e" ], [ 0.5555555555555556, "#1f9e89" ], [ 0.6666666666666666, "#35b779" ], [ 0.7777777777777778, "#6ece58" ], [ 0.8888888888888888, "#b5de2b" ], [ 1, "#fde725" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" }, "colorscale": [ [ 0, "#440154" ], [ 0.1111111111111111, "#482878" ], [ 0.2222222222222222, "#3e4989" ], [ 0.3333333333333333, "#31688e" ], [ 0.4444444444444444, "#26828e" ], [ 0.5555555555555556, "#1f9e89" ], [ 0.6666666666666666, "#35b779" ], [ 0.7777777777777778, "#6ece58" ], [ 0.8888888888888888, "#b5de2b" ], [ 1, "#fde725" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" }, "colorscale": [ [ 0, "#440154" ], [ 0.1111111111111111, "#482878" ], [ 0.2222222222222222, "#3e4989" ], [ 0.3333333333333333, "#31688e" ], [ 0.4444444444444444, "#26828e" ], [ 0.5555555555555556, "#1f9e89" ], [ 0.6666666666666666, "#35b779" ], [ 0.7777777777777778, "#6ece58" ], [ 0.8888888888888888, "#b5de2b" ], [ 1, "#fde725" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "line": { "color": "white", "width": 0.6 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" }, "colorscale": [ [ 0, "#440154" ], [ 0.1111111111111111, "#482878" ], [ 0.2222222222222222, "#3e4989" ], [ 0.3333333333333333, "#31688e" ], [ 0.4444444444444444, "#26828e" ], [ 0.5555555555555556, "#1f9e89" ], [ 0.6666666666666666, "#35b779" ], [ 0.7777777777777778, "#6ece58" ], [ 0.8888888888888888, "#b5de2b" ], [ 1, "#fde725" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" }, "colorscale": [ [ 0, "#440154" ], [ 0.1111111111111111, "#482878" ], [ 0.2222222222222222, "#3e4989" ], [ 0.3333333333333333, "#31688e" ], [ 0.4444444444444444, "#26828e" ], [ 0.5555555555555556, "#1f9e89" ], [ 0.6666666666666666, "#35b779" ], [ 0.7777777777777778, "#6ece58" ], [ 0.8888888888888888, "#b5de2b" ], [ 1, "#fde725" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" } }, "marker": { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" }, "colorscale": [ [ 0, "#440154" ], [ 0.1111111111111111, "#482878" ], [ 0.2222222222222222, "#3e4989" ], [ 0.3333333333333333, "#31688e" ], [ 0.4444444444444444, "#26828e" ], [ 0.5555555555555556, "#1f9e89" ], [ 0.6666666666666666, "#35b779" ], [ 0.7777777777777778, "#6ece58" ], [ 0.8888888888888888, "#b5de2b" ], [ 1, "#fde725" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "rgb(237,237,237)" }, "line": { "color": "white" } }, "header": { "fill": { "color": "rgb(217,217,217)" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" } }, "colorscale": { "diverging": [ [ 0, "rgb(103,0,31)" ], [ 0.1, "rgb(178,24,43)" ], [ 0.2, "rgb(214,96,77)" ], [ 0.3, "rgb(244,165,130)" ], [ 0.4, "rgb(253,219,199)" ], [ 0.5, "rgb(247,247,247)" ], [ 0.6, "rgb(209,229,240)" ], [ 0.7, "rgb(146,197,222)" ], [ 0.8, "rgb(67,147,195)" ], [ 0.9, "rgb(33,102,172)" ], [ 1, "rgb(5,48,97)" ] ], "sequential": [ [ 0, "#440154" ], [ 0.1111111111111111, "#482878" ], [ 0.2222222222222222, "#3e4989" ], [ 0.3333333333333333, "#31688e" ], [ 0.4444444444444444, "#26828e" ], [ 0.5555555555555556, "#1f9e89" ], [ 0.6666666666666666, "#35b779" ], [ 0.7777777777777778, "#6ece58" ], [ 0.8888888888888888, "#b5de2b" ], [ 1, "#fde725" ] ], "sequentialminus": [ [ 0, "#440154" ], [ 0.1111111111111111, "#482878" ], [ 0.2222222222222222, "#3e4989" ], [ 0.3333333333333333, "#31688e" ], [ 0.4444444444444444, "#26828e" ], [ 0.5555555555555556, "#1f9e89" ], [ 0.6666666666666666, "#35b779" ], [ 0.7777777777777778, "#6ece58" ], [ 0.8888888888888888, "#b5de2b" ], [ 1, "#fde725" ] ] }, "colorway": [ "#1F77B4", "#FF7F0E", "#2CA02C", "#D62728", "#9467BD", "#8C564B", "#E377C2", "#7F7F7F", "#BCBD22", "#17BECF" ], "font": { "color": "rgb(36,36,36)" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "white", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "white", "polar": { "angularaxis": { "gridcolor": "rgb(232,232,232)", "linecolor": "rgb(36,36,36)", "showgrid": false, "showline": true, "ticks": "outside" }, "bgcolor": "white", "radialaxis": { "gridcolor": "rgb(232,232,232)", "linecolor": "rgb(36,36,36)", "showgrid": false, "showline": true, "ticks": "outside" } }, "scene": { "xaxis": { "backgroundcolor": "white", "gridcolor": "rgb(232,232,232)", "gridwidth": 2, "linecolor": "rgb(36,36,36)", "showbackground": true, "showgrid": false, "showline": true, "ticks": "outside", "zeroline": false, "zerolinecolor": "rgb(36,36,36)" }, "yaxis": { "backgroundcolor": "white", "gridcolor": "rgb(232,232,232)", "gridwidth": 2, "linecolor": "rgb(36,36,36)", "showbackground": true, "showgrid": false, "showline": true, "ticks": "outside", "zeroline": false, "zerolinecolor": "rgb(36,36,36)" }, "zaxis": { "backgroundcolor": "white", "gridcolor": "rgb(232,232,232)", "gridwidth": 2, "linecolor": "rgb(36,36,36)", "showbackground": true, "showgrid": false, "showline": true, "ticks": "outside", "zeroline": false, "zerolinecolor": "rgb(36,36,36)" } }, "shapedefaults": { "fillcolor": "black", "line": { "width": 0 }, "opacity": 0.3 }, "ternary": { "aaxis": { "gridcolor": "rgb(232,232,232)", "linecolor": "rgb(36,36,36)", "showgrid": false, "showline": true, "ticks": "outside" }, "baxis": { "gridcolor": "rgb(232,232,232)", "linecolor": "rgb(36,36,36)", "showgrid": false, "showline": true, "ticks": "outside" }, "bgcolor": "white", "caxis": { "gridcolor": "rgb(232,232,232)", "linecolor": "rgb(36,36,36)", "showgrid": false, "showline": true, "ticks": "outside" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "rgb(232,232,232)", "linecolor": "rgb(36,36,36)", "showgrid": false, "showline": true, "ticks": "outside", "title": { "standoff": 15 }, "zeroline": false, "zerolinecolor": "rgb(36,36,36)" }, "yaxis": { "automargin": true, "gridcolor": "rgb(232,232,232)", "linecolor": "rgb(36,36,36)", "showgrid": false, "showline": true, "ticks": "outside", "title": { "standoff": 15 }, "zeroline": false, "zerolinecolor": "rgb(36,36,36)" } } } } }, "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "bb.load_sugars()\n", "\n", "glc = bb.molecule(\"GLC\")\n", "man = bb.molecule(\"MAN\")\n", "\n", "# connect using only the string identifier\n", "# instead of the actual Linkage object\n", "new = bb.connect(glc, man, \"my_14_glyco_link\")\n", "new.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If we close the notebook, we will have lost `\"my_14_glyco_link\"` however. In order to ensure it is available in all future sessions, we can call `add_linkage` with the additional argument `overwrite=True`. This will permanently save the modified CHARMM topology as the new default." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# now the linkage is available even the next time we open a new notebook or restart the kernel\n", "bb.add_linkage(my_link, overwrite=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Adding custom structures\n", "\n", "While it is true that biobuild does not load sugar-compounds and the like automatically, it does actually load a default PDBE compounds instance (it just happens to be empty be default). It can be populated with anything we want, however, using the `add_compound` function. The function expects a molecule, alongside with some additional metadata such as identifiers and name synonyms by which the molecule can be found. The logic is identical to `add_linkage` and we can make the additions permanent using the `overwrite=True` argument when calling `add_compound`. " ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# first we need to make sure the molecule has a good id\n", "# the id can be anything, but it needs to be unique\n", "new.id = \"my_sugar\"\n", "\n", "# now let's add our small sugar compound to the PDBE compounds\n", "# we provide as metadata only two names for the compound (more options are available)\n", "bb.add_compound(new, names=[\"my first sugar\", \"glucose-mannose\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we can check if `\"my_sugar\"` is available as a compound using `bb.has_compound`:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(True, True)" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# the has_compound function accepts both the \n", "# registered id as well as any of the name synonyms or identifiers\n", "bb.has_compound(\"my_sugar\"), bb.has_compound(\"my first sugar\")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "# again we can make the compound available for the next time we open a new notebook or restart the kernel\n", "# by using the overwrite=True option\n", "bb.add_compound(new, names=[\"my first sugar\", \"glucose-mannose\"], overwrite=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "> #### Warning\n", "> Using the `add_compound` function using `overwrite=True` can lead to an unwanted consequence: all other loaded compounds are automatically also added to the default compounds! That means, since we called `load_sugars` before, now the default loaded compounds will include not only our `my_sugar` molecule but also all the sugars that we loaded before! To prevent this from happening it would be better first to create a new instance of `PDBECompounds`, add the compound there. Then use the `save_as_default_compounds` function to permanently set the defaults in this way." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['my_sugar']" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# make a new empty PDBECompounds object\n", "new_compounds = bb.PDBECompounds()\n", "\n", "# now we can add our compound to the new object\n", "new_compounds.add(new, type=\"CUSTOM-MOLECULES\", names=[\"my first sugar\", \"glucose-mannose\"])\n", "\n", "# check what compounds are now available in the new object\n", "new_compounds.ids" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we can save this object as the future default using `save_as_default_compounds`, without saving the 1000-something sugar compounds that are currently also loaded." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1069" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# save as defaults\n", "bb.save_as_default_compounds(new_compounds)\n", "\n", "# print the number of currently loaded compounds\n", "len(bb.get_default_compounds())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What if we have multiple compounds already added to our defaults which we would like to keep? The easiest way to handle this kind of scenario is using `subset_compounds_by_types` in order to get a new `PDBECompounds` object that only contains compounds of interest. For instance, if we always set the type of our custom molecules to be `CUSTOM-MOLECULES`, then we can always get our custom defaults using `subset_compounds_by_types(\"CUSTOM-MOLECULES\")`, add any new compound to this database, and use `save_as_default_compounds` to make sure we have our molecules available in the future. \n", "\n", "All this will leave the currently loaded default compounds of 1000-sugars and our custom molecules completely unaffected. " ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "# get all custom compounds we may have already added in the past\n", "my_compounds = bb.subset_compounds_by_types(\"CUSTOM-MOLECULES\")\n", "\n", "# now add the new compounds to the existing ones\n", "my_compounds.add(new, type=\"CUSTOM-MOLECULES\", names=[\"my first sugar\", \"glucose-mannose\"])\n", "\n", "# (if we have not already done so) also add it to the current defaults (just don't use overwrite=True)\n", "bb.add_compound(new, type=\"CUSTOM-MOLECULES\", names=[\"my first sugar\", \"glucose-mannose\"])\n", "\n", "# now save the new compounds as defaults\n", "bb.save_as_default_compounds(my_compounds)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Handling updates\n", "\n", "Setting defaults like this will overwrite some files in your local biobuild package directory. Since biobuild comes with these same files when you install it, every update would overwrite your custom defaults again. To make sure your custom settings are not simply lost, be sure to call `export_custom_resources` before updating. This will export your CHARMM Topology and PDBECompounds database to external files in some directory of your choice. After the update you can use `import_custom_resources` to point to these files and re-set your precious settings (again `import_custom_resources` can be used transiently or permanently, depending on whether or not we use `overwrite=True` or not).\n", "\n", "> #### Note\n", "> These functions will use the currently loaded default compounds." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "# export the custom defaults we just made\n", "# to the current directory\n", "bb.export_custom_resources(\".\")\n", "\n", "# now we can load the custom resources from the current directory\n", "bb.import_custom_resources(\".\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Restoring biobuild defaults\n", "\n", "Made a mistake and now your compounds are messed up? You can always call `restore_default_compounds` or `restore_default_topology` to get the previous settings back. This will restore your settings to biobuild factory defaults, i.e. an empty component library! Make sure to first export any compounds you would like to keep using `subset_compounds_by_types` or more thoroughly using `export_compounds` and later use the `PDBECompounds.merge` method to create a custom library to your liking. " ] } ], "metadata": { "kernelspec": { "display_name": "glyco2", "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.11.2" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }