File size: 10,413 Bytes
1e15feb c48847e 1e15feb c48847e 1e15feb c48847e 1e15feb c48847e 1e15feb c48847e 1e15feb c48847e 1e15feb c48847e 1e15feb c48847e 1e15feb c48847e 1e15feb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "6a7a5d41-e6d7-4efa-a481-3182963ca888",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting gradio_client\n",
" Downloading gradio_client-1.3.0-py3-none-any.whl.metadata (7.1 kB)\n",
"Requirement already satisfied: fsspec in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from gradio_client) (2024.6.1)\n",
"Requirement already satisfied: httpx>=0.24.1 in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from gradio_client) (0.27.0)\n",
"Collecting huggingface-hub>=0.19.3 (from gradio_client)\n",
" Downloading huggingface_hub-0.24.7-py3-none-any.whl.metadata (13 kB)\n",
"Requirement already satisfied: packaging in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from gradio_client) (24.1)\n",
"Requirement already satisfied: typing-extensions~=4.0 in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from gradio_client) (4.12.2)\n",
"Requirement already satisfied: websockets<13.0,>=10.0 in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from gradio_client) (12.0)\n",
"Requirement already satisfied: anyio in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from httpx>=0.24.1->gradio_client) (4.4.0)\n",
"Requirement already satisfied: certifi in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from httpx>=0.24.1->gradio_client) (2024.7.4)\n",
"Requirement already satisfied: httpcore==1.* in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from httpx>=0.24.1->gradio_client) (1.0.5)\n",
"Requirement already satisfied: idna in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from httpx>=0.24.1->gradio_client) (3.7)\n",
"Requirement already satisfied: sniffio in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from httpx>=0.24.1->gradio_client) (1.3.1)\n",
"Requirement already satisfied: h11<0.15,>=0.13 in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from httpcore==1.*->httpx>=0.24.1->gradio_client) (0.14.0)\n",
"Requirement already satisfied: filelock in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from huggingface-hub>=0.19.3->gradio_client) (3.15.4)\n",
"Requirement already satisfied: pyyaml>=5.1 in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from huggingface-hub>=0.19.3->gradio_client) (6.0.1)\n",
"Requirement already satisfied: requests in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from huggingface-hub>=0.19.3->gradio_client) (2.32.3)\n",
"Requirement already satisfied: tqdm>=4.42.1 in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from huggingface-hub>=0.19.3->gradio_client) (4.66.5)\n",
"Requirement already satisfied: exceptiongroup>=1.0.2 in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from anyio->httpx>=0.24.1->gradio_client) (1.2.2)\n",
"Requirement already satisfied: charset-normalizer<4,>=2 in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from requests->huggingface-hub>=0.19.3->gradio_client) (3.3.2)\n",
"Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from requests->huggingface-hub>=0.19.3->gradio_client) (2.2.2)\n",
"Downloading gradio_client-1.3.0-py3-none-any.whl (318 kB)\n",
"\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m318.7/318.7 kB\u001b[0m \u001b[31m3.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
"\u001b[?25hDownloading huggingface_hub-0.24.7-py3-none-any.whl (417 kB)\n",
"\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m417.5/417.5 kB\u001b[0m \u001b[31m11.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hInstalling collected packages: huggingface-hub, gradio_client\n",
"Successfully installed gradio_client-1.3.0 huggingface-hub-0.24.7\n"
]
}
],
"source": [
"!pip install gradio_client"
]
},
{
"cell_type": "markdown",
"id": "549b9b2c-3074-446b-962e-90c8efd2bd59",
"metadata": {},
"source": [
"# PINDER inference and evaluation template API examples"
]
},
{
"cell_type": "markdown",
"id": "b979671e-97d6-4c52-bc6e-279a09d722c8",
"metadata": {},
"source": [
"## Run inference via predict endpoint"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "2c0171fa-ee2a-40b7-8578-aa8516b4ece9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Loaded as API: https://danielkovtun-pinder-inference-template.hf.space/ β\n",
"/private/var/folders/tt/x223wxwj6dzg3vjjgc_6y5bm0000gn/T/gradio/0cda59c2805986a9e5956ed00cb552b3c86f05915da91e6e14a0a31b962e664b/3g9w_R--3g9w_L.pdb 1.2273471355438232\n"
]
}
],
"source": [
"from gradio_client import Client, handle_file\n",
"from pathlib import Path\n",
"\n",
"uri = \"https://danielkovtun-pinder-inference-template.hf.space/\"\n",
"# If running docker container locally\n",
"dev_uri = \"http://localhost:7860/\"\n",
"client = Client(uri)\n",
"result = client.predict(\n",
" receptor_pdb=handle_file(\"./3g9w_R.pdb\"),\n",
" ligand_pdb=handle_file(\"./3g9w_L.pdb\"),\n",
" receptor_fasta=None, # optional in this implementation\n",
" ligand_fasta=None,\n",
" api_name=\"/predict\"\n",
")\n",
"output_pdb, runtime = Path(result[0]), result[1]\n",
"print(output_pdb, runtime)\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "c530fde1-7f57-4991-a53e-b3855657f9fc",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(PosixPath('pinder-inference-outputs/3g9w_R--3g9w_L.pdb'), True)"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import shutil\n",
"\n",
"local_dir = Path(\"./pinder-inference-outputs\")\n",
"local_dir.mkdir(exist_ok=True, parents=True)\n",
"\n",
"output_pdb = Path(shutil.copy(output_pdb, local_dir))\n",
"output_pdb, output_pdb.is_file() \n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "b3c1c03e-74c1-4010-b385-e4366d43cd6f",
"metadata": {},
"source": [
"## Fetch evaluation metrics via evaluate endpoint"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "e5e26250-f20d-484d-84e2-320cdfef830a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Loaded as API: http://localhost:7860/ β\n"
]
},
{
"data": {
"text/plain": [
"{'headers': ['system', 'L_rms', 'I_rms', 'F_nat', 'DOCKQ', 'CAPRI_class'],\n",
" 'data': [['3g9w__A1_Q71LX4--3g9w__D1_P05556',\n",
" 34.781349182128906,\n",
" 15.405366897583008,\n",
" 0.0,\n",
" 0.021916405918697517,\n",
" 'Incorrect']],\n",
" 'metadata': None}"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"client = Client(uri)\n",
"result = client.predict(\n",
" system_id=\"3g9w__A1_Q71LX4--3g9w__D1_P05556\",\n",
" prediction_pdb=handle_file(\"3g9w_R--3g9w_L.pdb\"),\n",
" api_name=\"/evaluate\"\n",
")\n",
"metrics, pred_native, runtime = result\n",
"metrics"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "eef0d108-5d76-4bef-bd0c-4952d433ccaf",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>system</th>\n",
" <th>L_rms</th>\n",
" <th>I_rms</th>\n",
" <th>F_nat</th>\n",
" <th>DOCKQ</th>\n",
" <th>CAPRI_class</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>3g9w__A1_Q71LX4--3g9w__D1_P05556</td>\n",
" <td>34.781349</td>\n",
" <td>15.405367</td>\n",
" <td>0.0</td>\n",
" <td>0.021916</td>\n",
" <td>Incorrect</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" system L_rms I_rms F_nat DOCKQ \\\n",
"0 3g9w__A1_Q71LX4--3g9w__D1_P05556 34.781349 15.405367 0.0 0.021916 \n",
"\n",
" CAPRI_class \n",
"0 Incorrect "
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"\n",
"metric_df = pd.DataFrame(metrics[\"data\"], columns=metrics[\"headers\"])\n",
"metric_df"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "pinder",
"language": "python",
"name": "pinder"
},
"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.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|