diff --git a/examples/konnektor_bench.ipynb b/examples/konnektor_bench.ipynb index b4ff50b..ac38623 100644 --- a/examples/konnektor_bench.ipynb +++ b/examples/konnektor_bench.ipynb @@ -11,46 +11,25 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 4, "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-02-27T10:47:42.556235500Z", - "start_time": "2024-02-27T10:47:40.807827200Z" + "end_time": "2024-03-31T17:41:53.972958Z", + "start_time": "2024-03-31T17:41:53.909892Z" } }, "outputs": [], "source": [ - "from rdkit import Chem\n", - "from gufe import SmallMoleculeComponent\n", - "\n", - "from gufe import LigandAtomMapping\n", - "import numpy as np\n", - "\n", - "\n", - "def build_random_dataset(n=20):\n", - "\n", - " class genMapper:\n", - " def suggest_mappings(molA, molB):\n", - " yield LigandAtomMapping(molA, molB, {})\n", - "\n", - " \n", - " class genScorer:\n", - " vals = np.random.random(int(n**2))\n", - " i=0\n", - " \n", - " def __call__(self, x):\n", - " v=self.vals[self.i]\n", - " self.i= (self.i+1)%n\n", - " return v\n", - "\n", - " mols = [Chem.AddHs(Chem.MolFromSmiles(\"C\"*i)) for i in range(1, int(n))]\n", - " [Chem.rdDistGeom.EmbedMolecule(m) for m in mols]\n", - " compounds = [ SmallMoleculeComponent(name=str(i), rdkit=m) for i,m in enumerate(mols)]\n", - "\n", - " return compounds, genMapper, genScorer\n", - "\n", - "compounds, genMapper, genScorer= build_random_dataset()" + "# NBVAL_SKIP\n", + "# Only run this cell if on google colab\n", + "import os\n", + "if \"COLAB_RELEASE_TAG\" in os.environ:\n", + " !pip install -U https://github.com/conda-incubator/condacolab/archive/cuda-version-12.tar.gz\n", + " import condacolab\n", + " condacolab.install_mambaforge()\n", + " !wget -q https://raw.githubusercontent.com/OpenFreeEnergy/konnektor/main/examples/environment.yaml\n", + " !mamba env update -q --name=base --file=environment.yaml\n" ] }, { @@ -62,21 +41,18 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": { "ExecuteTime": { - "end_time": "2024-02-27T10:48:00.339633100Z", - "start_time": "2024-02-27T10:48:00.306561400Z" + "end_time": "2024-03-31T17:41:57.220978Z", + "start_time": "2024-03-31T17:41:57.207310Z" } }, "outputs": [], "source": [ "import random\n", - "import numpy as np\n", - "from konnektor import network_analysis as ana\n", "from konnektor import network_tools as tools\n", "\n", - "\n", "def get_edge_failure_robustness(network, failure_rate=0.05, nrepeats=20):\n", " edges = list(network.edges)\n", " connected=[]\n", @@ -99,7 +75,7 @@ "metadata": { "is_executing": true, "ExecuteTime": { - "start_time": "2024-02-27T10:48:09.542681400Z" + "start_time": "2024-03-31T17:43:36.135439Z" } }, "outputs": [ @@ -109,36 +85,138 @@ "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, - "model_id": "f9a29c456a7e454e9c85948f2dd294b2" + "model_id": "73374f4fdb76474992c2bbfefbdd804f" } }, "metadata": {}, "output_type": "display_data" }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n", + "Build Cluster Networks: 100%|██████████| 3/3 [00:00<00:00, 197.31it/s]\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ERR a cycle can not be larger, than the number of nodes.\n", + "ERR a cycle can not be larger, than the number of nodes.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n", + "Build Cluster Networks: 100%|██████████| 3/3 [00:00<00:00, 143.94it/s]\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ERR a cycle can not be larger, than the number of nodes.\n", + "ERR a cycle can not be larger, than the number of nodes.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n", + "Build Cluster Networks: 100%|██████████| 3/3 [00:00<00:00, 142.83it/s]\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ERR a cycle can not be larger, than the number of nodes.\n", + "ERR a cycle can not be larger, than the number of nodes.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n", + "Build Cluster Networks: 100%|██████████| 3/3 [00:00<00:00, 110.24it/s]\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ERR a cycle can not be larger, than the number of nodes.\n", + "ERR a cycle can not be larger, than the number of nodes.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n", + "Build Cluster Networks: 100%|██████████| 3/3 [00:00<00:00, 51.02it/s]\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ERR a cycle can not be larger, than the number of nodes.\n", + "ERR a cycle can not be larger, than the number of nodes.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n", + "Build Cluster Networks: 100%|██████████| 3/3 [00:00<00:00, 132.57it/s]\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ERR a cycle can not be larger, than the number of nodes.\n", + "ERR a cycle can not be larger, than the number of nodes.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n", + "Build Cluster Networks: 100%|██████████| 3/3 [00:00<00:00, 68.04it/s]\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ERR a cycle can not be larger, than the number of nodes.\n", + "ERR a cycle can not be larger, than the number of nodes.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n", + "Build Cluster Networks: 100%|██████████| 3/3 [00:00<00:00, 94.46it/s]\n" + ] + }, { "name": "stdout", "output_type": "stream", "text": [ - " 1 5\n", - "('list index out of range',)\n", - " 0 12\n", - "('list index out of range',)\n", - " 2 12\n", - "('list index out of range',)\n", - " 1 16\n", - "('list index out of range',)\n", - " 2 16\n", - "('list index out of range',)\n", - " 0 20\n", - "('list index out of range',)\n", - " 1 20\n", - "('list index out of range',)\n", - " 0 24\n", - "('list index out of range',)\n", - " 2 24\n", - "('list index out of range',)\n", - " 0 28\n", - "('list index out of range',)\n" + "ERR a cycle can not be larger, than the number of nodes.\n", + "ERR a cycle can not be larger, than the number of nodes.\n" ] } ], @@ -148,6 +226,7 @@ "import numpy as np\n", "import pandas as pd\n", "from konnektor import network_analysis as ana\n", + "from konnektor.utils.toy_data import build_random_dataset\n", "from konnektor.network_planners import (MaximalNetworkPlanner, \n", " RadialLigandNetworkPlanner, \n", " StarrySkyLigandNetworkPlanner,\n", @@ -171,8 +250,8 @@ " for net in networker:\n", " try:\n", " start = datetime.now()\n", - " planner = net(mapper=genMapper, scorer=genScorer())\n", - " \n", + " planner = net(mapper=genMapper(), scorer=genScorer())\n", + " \n", " #Build\n", " network = planner(compounds)\n", " network.name= planner.__class__.__name__.replace(\"Planner\", \"\").replace(\"MinimalSpanningTree\", \"MST\").replace(\"Ligand\", \"\")\n", @@ -200,17 +279,6 @@ "df = pd.DataFrame(ncomp)" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "ExecuteTime": { - "start_time": "2024-02-27T10:47:44.655567500Z" - } - }, - "outputs": [], - "source": [] - }, { "cell_type": "code", "execution_count": 27, @@ -408,22 +476,13 @@ "source": [ "fig.savefig(\"../.img/Network_Overview.png\")" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "t.microseconds" - ] } ], "metadata": { "kernelspec": { - "display_name": "konnnektor", + "name": "python3", "language": "python", - "name": "konnektor" + "display_name": "Python 3 (ipykernel)" }, "language_info": { "codemirror_mode": {