{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "# SMARTFlexDB — quickstart\n\nPull the full pair table from the REST API into a pandas DataFrame and take a first look at the\ninduced-fit / geometry descriptors.\n\nOnly `requests`, `pandas`, and `matplotlib` are needed:\n\n```bash\npip install requests pandas matplotlib\n```\n\nPoint `BASE` at wherever the site is served (the public origin, or `http://localhost:8013`\nif you are running it locally)."
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import pandas as pd\n",
    "\n",
    "BASE = \"http://localhost:8013\"  # <- change to the site origin\n",
    "\n",
    "# GET /api/pairs returns {\"pairs\": [ {...}, ... ]} (already serve-filtered to the public set)\n",
    "resp = requests.get(f\"{BASE}/api/pairs\", timeout=60)\n",
    "resp.raise_for_status()\n",
    "df = pd.DataFrame(resp.json()[\"pairs\"])\n",
    "print(df.shape)\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ML-relevant columns\n",
    "\n",
    "Each row is one apo/holo pair. Useful descriptors for modelling / filtering:\n",
    "\n",
    "| column | meaning |\n",
    "|---|---|\n",
    "| `tm_score` | apo↔holo whole-fold TM-score (US-align) |\n",
    "| `rg_delta` | radius-of-gyration change holo − apo (Å) |\n",
    "| `ligand_burial` | fraction of the ligand surface buried by the RNA |\n",
    "| `rmsd` / `pocket_rmsd` | global / pocket-only C1' RMSD (Å) |"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "cols = [\n",
    "    \"id\", \"holo_pdb\", \"apo_pdb\", \"ligand\",\n",
    "    \"tm_score\", \"rg_delta\", \"ligand_burial\",\n",
    "    \"rmsd\", \"pocket_rmsd\",\n",
    "]\n",
    "ml = df[cols].copy()\n",
    "ml.describe(include=\"all\").T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Fetch the full record for a single pair (2D, interactions, DSSR, ligand props, ...)\n",
    "pair_id = df[\"id\"].iloc[0]\n",
    "detail = requests.get(f\"{BASE}/api/pair/{pair_id}\", timeout=60).json()\n",
    "sorted(detail.keys())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}