This repository contains a portable nephrotoxicity screening system for university reporting and local demonstration. It combines data preparation, model execution, consolidated evaluation, live SMILES inference, and a browser-based dashboard for reviewing saved and live predictions.
The aim of the project is to compare several molecular toxicity modelling families and present their outputs in a consistent screening interface. The system is designed to support two workflows:
- saved screening against the already evaluated external dataset
- live screening of a user-supplied SMILES string with applicability-domain routing and explanation output
The pipeline uses the curated CSV files under datasets/raw/:
model construction dataset.csvfor training and internal fingerprint contextexternal test dataset.csvfor external evaluation and saved predictions- Murcko scaffold and carbon scaffold files for scaffold-level summaries and cleaning checks
Running python main.py writes cleaned versions into datasets/processed/ and stores a cleaning audit in datasets/processed/dataset_cleaning_report.json.
The current codebase is organised around a simple end-to-end flow:
main.pyoptionally cleans the raw datasets and runs the selected model families.src/pipelines/prepare_datasets.pystandardises label and scaffold CSV files, removes invalid rows, deduplicates records, and writes the cleaning report.src/models/contains the main model families and the wrappers that recover archived outputs when those artifacts are available.src/evaluation/schema.pynormalises summary and prediction rows into the report schema used across the project.src/utils/dashboard_data.pyreads the output CSV files and builds the analytics payload used by the dashboard.serve_dashboard.pyexposes the dashboard and live prediction API.
- Screening Terminal with an explicit saved/live mode toggle.
- Saved mode searches the consolidated external prediction outputs and keeps the existing behaviour of the archived evaluation lookup.
- Live mode accepts a valid SMILES string, canonicalises it with RDKit, and returns a prediction dossier with three engine probabilities, consensus arbitration, applicability-domain routing, and a four-layer explanation stack.
- Deep Analytics page with AUROC vs F1 comparison, dataset balance, generalisation gap, and a Tanimoto similarity heatmap.
- Intelligence Core and Research Heritage pages that summarise the model families and the project lineage.
- Local feedback capture for live predictions.
The repository currently exposes five main model families through src/models/registry.py:
full_coverage_improvementsfull_coverage_descriptor_fp_meta_v4nephro_unsupervisednephro_chembertamodular_tanimoto_gpc
The associated algorithms are implemented as follows:
nephro_chembertacombines RDKit descriptors, Morgan fingerprints, structural alert flags, and ChemBERTa embeddings, then evaluates CatBoost and LightGBM components before writing the external metrics and per-sample predictions.nephro_unsupervisedcompares a PCA projection with an autoencoder-based latent representation, then evaluates both with CatBoost on the external test set.full_coverage_improvementsandfull_coverage_descriptor_fp_meta_v4are selection wrappers over broader full-coverage comparison outputs from the archived project families.modular_tanimoto_gpcloads the similarity-first Tanimoto GPC outputs from the historical modular nephrotoxicity run.
For live inference, src/utils/live_analysis.py builds the query context, computes nearest-neighbour similarity, flags structural alerts, derives scaffold context, loads serialized live engines, and routes the result through src/utils/consensus.py.
The consolidated summary schema records:
- accuracy
- precision
- recall
- F1 score
- ROC-AUC
- PR-AUC
- training time where available
- inference time where available
The standalone model runners also compute auxiliary metrics such as Cohen's kappa, but the unified project reports focus on the metrics above.
The current workspace already contains a consolidated evaluation file in outputs/final_reports/overall_evaluation.csv. Ranked by external-test ROC-AUC (the held-out generalisation measure), the recorded runs are:
full_coverage_improvements/meta_logreg_knn_plus_lgbm: accuracy 0.768, F1 0.762, ROC-AUC 0.860, PR-AUC 0.872full_coverage_descriptor_fp_meta_v4/challenger_proxy_meta: accuracy 0.755, F1 0.747, ROC-AUC 0.856, PR-AUC 0.868modular_tanimoto_gpc/TanimotoGPC: accuracy 0.768, F1 0.767, ROC-AUC 0.829, PR-AUC 0.846nephro_unsupervised/Autoencoder: accuracy 0.745, F1 0.735, ROC-AUC 0.826, PR-AUC 0.840nephro_chemberta/chemberta_hybrid_cb_lgbm: accuracy 0.722, F1 0.718, ROC-AUC 0.785, PR-AUC 0.759
These outputs indicate that the full_coverage meta-ensembles (logistic regression + kNN + LightGBM) are currently the strongest on external data, with the Tanimoto GPC and the unsupervised autoencoder close behind. The ChemBERTa hybrid is the strongest on internal cross-validation (ROC-AUC 0.921) but shows the largest internal-to-external gap (~0.14), which points to overfitting to the training chemistry and is worth discussing as a limitation rather than a headline result.
The dashboard's Deep Analytics view reflects this comparison through the AUROC/F1 chart, the generalisation-gap panel, and the Tanimoto similarity heatmap.
- Some historical model wrappers still depend on archived legacy project paths that are not present in this portable checkout, so those runners can fail if the external legacy artifacts are missing.
- Live prediction requires RDKit to parse the input SMILES string and load the local serialized live-inference bundles under
models/. - The live explanation stack currently exposes nearest neighbours, structural alerts, scaffold context, and a placeholder feature-importance layer until serialized attribution support is added.
- Restore or vendor the missing archived legacy runners so all historical wrappers are reproducible from this repository alone.
- Export real feature-attribution outputs for the live explanation stack.
- Add regression tests for the dashboard payload shape and the processed dataset cleaning report.
- Extend the feedback loop so confirmed live labels can be reused in retraining.
Install dependencies with:
pip install -r requirements.txtRecommended packages include pandas, scikit-learn, lightgbm, catboost, rdkit, torch, and transformers.
Python 3.12 is recommended for the most stable experience in this workspace.
Run the preprocessing and model pipeline:
python main.pyStart the local dashboard:
python serve_dashboard.pyIf you need another port:
python serve_dashboard.py --port 8001The dashboard is intentionally split into the main files below:
main.pyorchestrates preprocessing and model execution.serve_dashboard.pyserves the API and static dashboard.webapp/contains the screening terminal and analytics interface.src/models/contains the model-family entry points.src/utils/dashboard_data.pyshapes the data used by the UI.
Stop the dashboard:
Ctrl+C
If port 8000 is already in use:
lsof -i :8000
lsof -ti :8000
kill $(lsof -ti :8000)Or use another port:
python serve_dashboard.py --port 8001List the available models:
python main.py --list-modelsSkip dataset preparation:
python main.py --skip-data-prepForce a rerun:
python main.py --force-rerunRun the dashboard on a chosen host and port:
python serve_dashboard.py --host 127.0.0.1 --port 8000Default dashboard URL:
http://127.0.0.1:8000
This project can be deployed as a small web service.
Before deploying, make sure the dashboard data files already exist in the project:
datasets/processed/external_test_dataset.csvoutputs/final_reports/overall_evaluation.csvoutputs/detailed_predictions/all_model_predictions.csv
If they do not exist yet, generate them locally first:
python main.pyThe project now supports deployment-friendly host and port settings:
HOSTPORT
It also includes:
Dockerfile.dockerignore
The simplest free hosted options for a public demo are usually:
- Render Free Web Service
- Hugging Face Spaces with Docker
These free options are useful for demos and submissions, but they are not ideal for production. Platform limits and pricing can change, so always check the official documentation before deploying.
Official docs:
- Render free web services:
https://render.com/docs/free - Render web services:
https://render.com/docs/your-first-deploy - Render Docker deploys:
https://render.com/docs/docker - Hugging Face Spaces overview:
https://huggingface.co/docs/hub/spaces-overview - Hugging Face Docker Spaces:
https://huggingface.co/docs/hub/spaces-sdks-docker-first-demo
Good for:
- quick public demo
- easiest browser-based deployment flow
Important limitations:
- free services spin down after inactivity
- startup after sleep is slower
- free services are not recommended for production
- the filesystem is ephemeral
Recommended setup on Render:
- Push this project to GitHub
- Create a new Web Service on Render
- Set the root directory to this project folder if the repository contains multiple folders
- Choose either:
Dockerruntime, which will use the includedDockerfilePythonruntime
If you use the Python runtime:
- Build Command:
pip install -r requirements.txt- Start Command:
python serve_dashboard.py --host 0.0.0.0 --port $PORTRecommended health check path:
/api/health
Good for:
- a free hosted demo
- a project showcase page
Important limitations:
- free hardware can sleep when idle
- the environment is not meant for long-running production traffic
Suggested setup:
- Create a new Hugging Face Space
- Choose
Dockeras the Space SDK - Push this project into that Space repository
- Make sure the processed dataset and output CSV files are included
- If needed for the Space repo, add the following YAML block at the top of that deployment repo's
README.md:
---
title: FINAL_ KV6013_NEPHROTOXICITY_PREDICTOR
sdk: docker
app_port: 8000
---The included Dockerfile can then be used to build and run the dashboard service.
For a more stable deployment, use one of these:
- Render paid web service
- any VPS that can run Docker
- any Docker-compatible platform
This is the best option if you want:
- a more reliable always-on service
- better control over uptime
- a cleaner deployment path for demonstrations or assessment
Build the image:
docker build -t kv6013-dashboard .Run it:
docker run --rm -p 8000:8000 kv6013-dashboardThen open:
http://127.0.0.1:8000
To run it on a server with a custom port:
docker run --rm -e HOST=0.0.0.0 -e PORT=8000 -p 8000:8000 kv6013-dashboardIf you deploy the Docker image to a platform such as Render, the platform can provide the PORT value automatically.
The frontend reads these files from this same folder:
outputs/final_reports/overall_evaluation.csvoutputs/detailed_predictions/all_model_predictions.csvdatasets/processed/external_test_dataset.csv
The dashboard can:
- search saved evaluation molecules by SMILES
- search a small set of supported medicine names
- compare the saved predictions across the five main models
- show analytics based on the processed external dataset
- trigger a refresh run of
python main.py --skip-data-prep
The current dashboard does not yet run brand-new single-molecule inference from raw model weights.
- Place source CSV files in
datasets/raw/ - Run
python main.py - Cleaned files are written to
datasets/processed/ - Outputs are written to
outputs/ - Start
python serve_dashboard.pyto inspect them in the browser