An inductive graph neural network engine for female-stratified polypharmacy side-effect prediction, making an opaque, sex-blind risk surface auditable at the point of prescribing.
π Built at We Hack 5.0 (organized by IEEE WIE), where it won the Best Track award.
Most drug-safety tooling is sex-blind. Many adverse drug reactions (ADRs) affect women disproportionately, yet the risk scores clinicians see rarely account for it. The gap is widest for polypharmacy (patients taking several drugs at once), where the dangerous signal lives in drug combinations, not single drugs.
- π¬ Pairwise and regimen risk prediction. A heterogeneous Graph Neural Network scores 50 adverse side-effect types for any drug pair, and for every pair across a full regimen.
- βοΈ Female-stratified scoring. Side effects known to disproportionately affect women are flagged and weighted when the patient's biological sex is female.
- π Safer substitution engine. When a pair crosses the high-risk threshold, it searches for up to 3 alternative drugs that actually reduce risk.
- π§Ύ Graph-grounded LLM explanations. Each flagged risk gets a structured explanation for clinicians (mechanism, severity, actionable guidance) and a plain-language summary for patients, constrained not to invent mechanisms, proteins, or citations.
- π Interaction reports. A full analysis renders to a PDF with a mandatory disclaimer banner, accessible via QR code.
- π Interactive dashboard. A 3D drug-interaction graph, a 3D molecule viewer (structures from PubChem), a demographic lens, a pathway inspector, and a regimen simulator.
Patient data is protected health information, so the backend treats it that way:
| Concern | How it's handled |
|---|---|
| Authentication | JWT access tokens, bcrypt password hashing |
| Authorization | Role-based access (CLINICIAN / PATIENT) with per-patient assignment checks |
| Data at rest | Identifying fields (name, DOB, MRN, emergency contact) encrypted with AES-256-GCM |
| Accountability | Every read/write of patient data writes an audit-log row |
| Onboarding | Single-use, expiring email invites; passwords are never sent |
| Care handoffs | OTP-verified patient transfers between clinicians |
| Abuse protection | Rate limiting on auth and OTP endpoints |
ββββββββββββββββββββββββββββ REST / JSON βββββββββββββββββββββββββββββββββββββββ
β Frontend β βββββββββββββββββββββΆ β FastAPI backend β
β HTML Β· CSS Β· JavaScript β β β
β Three.js force graph β β ββ GNN inference engine (PyTorch) β
β 3Dmol.js viewer β βββββββββββββββββββββ β ββ Substitution search β
ββββββββββββββββββββββββββββ β ββ LLM explainer (OpenRouter) β
β ββ PDF + QR report generation β
β ββ Auth, RBAC, encryption, audit β
ββββββββββββββββ¬βββββββββββββββββββββββ
β async SQLAlchemy
ββββββββββΌβββββββββ
β PostgreSQL β
β (Neon) β
βββββββββββββββββββ
| Architecture | Heterogeneous Graph Transformer (HGT) encoder with residual connections, plus a neural bilinear decoder (one learned embedding per side-effect relation) |
| Graph | 645 drugs and 19,089 proteins; proteinβprotein interactions, drugβprotein targets, and 50 drugβdrug side-effect relation types (Decagon-derived) |
| Hyperparameters | 128 hidden dims, 3 layers, 4 attention heads, 0.3 dropout |
| Female weighting | Female-weighted relations scaled by FEMALE_ADR_RISK_MULTIPLIER (default 1.15), clamped at 99.9 |
| High-risk threshold | Risk score > 75.0 triggers substitution search and LLM explanation in reports |
Drug embeddings are precomputed and cached (z_drug_cache.pt, fingerprinted by content hash), so inference is a fast decoder pass instead of a full message-passing run on every request.
β οΈ Scores are statistical signals, not clinical fact. PharmacoGNN is a decision-support research prototype and is not a substitute for professional medical judgment.
Backend: Python 3.11 Β· FastAPI Β· Pydantic v2 Β· SQLAlchemy 2 (async) Β· asyncpg Β· Alembic Β· PyTorch Β· PyTorch Geometric Β· httpx Β· ReportLab Β· qrcode Β· slowapi Β· PyJWT Β· passlib/bcrypt Β· cryptography
Frontend: vanilla HTML/CSS/JavaScript Β· Three.js (3D force graph) Β· 3Dmol.js Β· Node's built-in test runner
Infrastructure: PostgreSQL (Neon) Β· Docker / Docker Compose Β· MailHog (dev email) Β· Hugging Face Spaces Β· GitHub Actions CI Β· Git LFS for model weights
PharmacoGNN/
βββ backend/
β βββ app/
β β βββ api/v1/ # auth, patients, predict, explain, reports, transfers, vocab, pubchem
β β βββ core/ # config, security (JWT, AES-GCM), rate limiting
β β βββ db/ # async engine & session
β β βββ models/ # SQLAlchemy models
β β βββ schemas/ # Pydantic request/response schemas
β β βββ services/ # gnn_engine, substitution, llm_explainer, report_generation, ...
β βββ alembic/ # database migrations
β βββ weights/ # model checkpoint, graph, vocab & embedding caches (Git LFS)
β βββ tests/ # pytest suite
β βββ Dockerfile
βββ frontend/
β βββ pages/ # workspace, patients, reports, transfers, substitution engine, ...
β βββ js/ # api client, 3D graph, molecule viewer, page logic
β βββ css/
β βββ tests/
βββ docs/
βββ docker-compose.yml
βββ API_REFERENCE.md
βββ FRONTEND_GUIDE.md
βββ HUGGINGFACE_DEPLOYMENT.md
- Git LFS. The model weights are stored with LFS; without it you get tiny pointer files and the engine fails to load.
- Docker and Docker Compose, or Python 3.11+
- A PostgreSQL database: Neon or a local instance
- Node.js (only to run the frontend dev server and tests)
git lfs install
git clone https://github.com/RK-NerdyBirdy/PharmacoGNN.git
cd PharmacoGNNDocker Compose runs the backend and MailHog; the database is your Neon instance.
cp .env.example .envFill in DATABASE_URL, JWT_SECRET_KEY, and FIELD_ENCRYPTION_KEY (see Configuration), then:
docker compose up --build- API: http://localhost:8000 (interactive docs at http://localhost:8000/docs)
- MailHog inbox (invite links, OTP codes): http://localhost:8025
Migrations run automatically on startup. backend/weights is bind-mounted read-only, so you can swap in a new checkpoint without rebuilding.
cd backend
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install --index-url https://download.pytorch.org/whl/cpu torch
pip install -r requirements.txt
cp .env.example .env # set DATABASE_URL etc.
alembic upgrade head
uvicorn app.main:app --reloadFor Neon, set DATABASE_SSL_REQUIRE=true; leave it false for a local Postgres.
cd frontend
npm install
npm run devThe frontend is served at http://localhost:8420 and talks to the API at http://localhost:8000 by default (override with window.PHARMAGNN_API_BASE). Add the frontend origin to the backend's CORS list:
CORS_ORIGINS=http://localhost:8420
APP_BASE_URL=http://localhost:8420| Variable | Required | Description |
|---|---|---|
DATABASE_URL |
β | Postgres DSN using the asyncpg scheme, e.g. postgresql+asyncpg://user:pass@host/db (drop any ?sslmode= suffix) |
DATABASE_SSL_REQUIRE |
true for Neon / managed Postgres |
|
JWT_SECRET_KEY |
β | Long random secret for signing tokens |
FIELD_ENCRYPTION_KEY |
β | Base64 32-byte AES key: python -c "import base64,os; print(base64.urlsafe_b64encode(os.urandom(32)).decode())" |
OPENROUTER_API_KEY |
Enables LLM explanations. Without it, /explain returns 502 and reports skip explanations; everything else still works |
|
OPENROUTER_MODEL |
Defaults to anthropic/claude-3.5-sonnet |
|
CORS_ORIGINS |
Comma-separated allowed browser origins | |
APP_BASE_URL |
Frontend origin used in invite and QR links | |
RATE_LIMIT_ENABLED |
true by default |
|
EMAIL_BACKEND |
smtp, memory, or console |
|
SMTP_HOST / SMTP_PORT / ... |
Mail settings (defaults target MailHog) |
See .env.example (Docker) and backend/.env.example (bare metal) for the full list.
| Area | Endpoints |
|---|---|
| Auth | POST /api/v1/auth/register, /login, /refresh, /activate |
| Patients | CRUD, conditions, regimens, prescriptions, invites: /api/v1/patients/... |
| Prediction | POST /api/v1/predict/pairwise, /predict/regimen, /predict/substitute |
| Explanation | POST /api/v1/explain/interaction |
| Reports | POST /api/v1/patients/{id}/reports, GET /api/v1/reports/{id}, GET /api/v1/reports/{id}/pdf |
| Transfers | OTP-verified patient transfers: /api/v1/transfers/... |
| Vocabulary | GET /api/v1/vocab/drugs, /vocab/adverse-effects |
| Health | GET /health |
Quick example:
curl -X POST http://localhost:8000/api/v1/predict/pairwise \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"drug_a_cid": "...", "drug_b_cid": "...", "patient_sex": "FEMALE"}'π Full request/response shapes, error codes and RBAC rules: API_REFERENCE.md π§ Frontend integration notes: FRONTEND_GUIDE.md
# Backend (needs a reachable Postgres via DATABASE_URL)
cd backend
pytest -v
# Frontend
cd frontend
npm testGitHub Actions runs the backend suite against Postgres 16 on every push and pull request (backend-ci.yml).
The backend deploys as a Docker Space on Hugging Face with a Neon database. Step-by-step guide: HUGGINGFACE_DEPLOYMENT.md.
| Name | GitHub | |
|---|---|---|
![]() |
Maneet Gupta | @RK-NerdyBirdy |
![]() |
Vani Singh | @Vani-06 |
![]() |
Shriya Sawant | @shriyapsawant21-wq |
![]() |
Prakhar Sethi | @Prakhar-Sethi012 |
Released under the MIT License.



