{ "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": [ "
\n", " | system | \n", "L_rms | \n", "I_rms | \n", "F_nat | \n", "DOCKQ | \n", "CAPRI_class | \n", "
---|---|---|---|---|---|---|
0 | \n", "3g9w__A1_Q71LX4--3g9w__D1_P05556 | \n", "34.781349 | \n", "15.405367 | \n", "0.0 | \n", "0.021916 | \n", "Incorrect | \n", "