CoolFace
Apppublic

Epion09g/MolGNN-Tox21-Predictor

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes
App README

๐Ÿงฌ Graph ML-Enabled Molecular Design Assistant using Graph Neural Networks

<div align="center">

![Python](https://python.org) ![PyTorch](https://pytorch.org) ![Flask](https://flask.palletsprojects.com) ![RDKit](https://www.rdkit.org) ![License](LICENSE)

๐Ÿ”ฌ An AI-powered molecular toxicity prediction web application using state-of-the-art Graph Neural Networks

๐Ÿš€ Live Demo โ€ข ๐Ÿ“– Documentation โ€ข ๐Ÿง  Models โ€ข ๐Ÿ“Š Results

</div>


๐Ÿ“‹ Table of Contents


๐ŸŽฏ Overview

MolGNN Tox21 Predictor is a comprehensive molecular toxicity prediction system that leverages Graph Neural Networks (GNNs) to assess the potential toxicity of chemical compounds. The system predicts toxicity across all 12 endpoints of the Tox21 benchmark dataset, which is widely used in drug discovery, pharmaceutical research, and chemical safety assessment.

Why Graph Neural Networks for Molecules?

Molecules are naturally represented as graphs where:

  • โ€”Nodes = Atoms (with features like atomic number, charge, hybridization)
  • โ€”Edges = Chemical bonds (with features like bond type, aromaticity)

GNNs can learn molecular representations directly from this graph structure, capturing both local atomic environments and global molecular properties without requiring hand-crafted molecular descriptors.


โœจ Key Features

FeatureDescription
๐Ÿ”ฌ Multi-Model EnsembleChoose from 3 GNN architectures (GINE, GCN, GATv2) or use all models together
๐ŸŽจ Interactive 3D VisualizationRotate, zoom, and explore molecules in 3D using 3Dmol.js
๐Ÿ“Š 12 Toxicity EndpointsComprehensive prediction across all Tox21 assays
๐Ÿ“ Batch ProcessingUpload CSV files with SMILES for bulk predictions
๐Ÿ’พ Export ResultsDownload predictions as CSV for further analysis
๐ŸŒ Modern Web UIBeautiful dark-themed responsive interface with Bootstrap 5
โšก Fast InferenceOptimized PyTorch models for quick predictions

๐Ÿš€ Live Demo

Try the application now: https://huggingface.co/spaces/Epion09g/MolGNN-Tox21-Predictor

Quick Start Examples

Try these SMILES strings in the demo:

MoleculeSMILESDescription
AspirinCC(=O)Oc1ccccc1C(=O)OCommon pain reliever
CaffeineCn1cnc2c1c(=O)n(c(=O)n2C)CStimulant in coffee
IbuprofenCC(C)Cc1ccc(cc1)C(C)C(=O)OAnti-inflammatory drug
EthanolCCOAlcohol
Benzenec1ccccc1Aromatic hydrocarbon
ParacetamolCC(=O)Nc1ccc(O)cc1Acetaminophen

๐ŸŽฏ Tox21 Endpoints

The Tox21 dataset contains toxicity labels for 12 biological assays, divided into two categories:

Nuclear Receptor (NR) Panel

EndpointFull NameBiological Significance
NR-ARAndrogen ReceptorMale hormone signaling, endocrine disruption
NR-AR-LBDAR Ligand Binding DomainDirect AR binding activity
NR-AhRAryl Hydrocarbon ReceptorXenobiotic metabolism, dioxin-like toxicity
NR-AromataseAromatase EnzymeEstrogen biosynthesis inhibition
NR-EREstrogen ReceptorFemale hormone signaling, endocrine disruption
NR-ER-LBDER Ligand Binding DomainDirect ER binding activity
NR-PPAR-gammaPPAR-gammaLipid metabolism, diabetes-related

Stress Response (SR) Panel

EndpointFull NameBiological Significance
SR-AREAntioxidant Response ElementOxidative stress response
SR-ATAD5ATAD5Genotoxicity, DNA damage response
SR-HSEHeat Shock ElementCellular stress response
SR-MMPMitochondrial Membrane PotentialMitochondrial toxicity
SR-p53p53 Tumor SuppressorGenotoxicity, apoptosis activation

๐Ÿง  Model Architectures

We implemented and compared three state-of-the-art GNN architectures:

1. GINE (Graph Isomorphism Network with Edge features)

Input โ†’ GINEConv(256) โ†’ BatchNorm โ†’ ReLU โ†’ Dropout
      โ†’ GINEConv(256) โ†’ BatchNorm โ†’ ReLU โ†’ Dropout
      โ†’ GINEConv(256) โ†’ BatchNorm โ†’ ReLU โ†’ Dropout
      โ†’ GINEConv(256) โ†’ BatchNorm โ†’ ReLU โ†’ Dropout
      โ†’ [MeanPool || SumPool] โ†’ Linear(512โ†’256) โ†’ Linear(256โ†’12)

Key Features:

  • โ€”Incorporates edge attributes (bond types)
  • โ€”Based on Weisfeiler-Lehman graph isomorphism test
  • โ€”Best theoretical expressiveness among the three

2. GCN (Graph Convolutional Network)

Input โ†’ GCNConv(256) โ†’ BatchNorm โ†’ ReLU โ†’ Dropout
      โ†’ GCNConv(256) โ†’ BatchNorm โ†’ ReLU โ†’ Dropout
      โ†’ GCNConv(256) โ†’ BatchNorm โ†’ ReLU โ†’ Dropout
      โ†’ GCNConv(256) โ†’ BatchNorm โ†’ ReLU โ†’ Dropout
      โ†’ [MeanPool || SumPool] โ†’ Linear(512โ†’256) โ†’ Linear(256โ†’12)

Key Features:

  • โ€”Classical spectral-based convolution
  • โ€”Efficient and well-understood
  • โ€”Good baseline performance

3. GATv2 (Graph Attention Network v2)

Input โ†’ GATv2Conv(256, heads=4) โ†’ BatchNorm โ†’ ELU โ†’ Dropout
      โ†’ GATv2Conv(256, heads=4) โ†’ BatchNorm โ†’ ELU โ†’ Dropout
      โ†’ GATv2Conv(256, heads=4) โ†’ BatchNorm โ†’ ELU โ†’ Dropout
      โ†’ GATv2Conv(256, heads=4) โ†’ BatchNorm โ†’ ELU โ†’ Dropout
      โ†’ [MeanPool || SumPool] โ†’ Linear(512โ†’256) โ†’ Linear(256โ†’12)

Key Features:

  • โ€”Dynamic attention mechanism
  • โ€”Multi-head attention (4 heads)
  • โ€”Learns to weight neighbor contributions

๐Ÿ“Š Model Performance

Scaffold Split Results (Recommended for Realistic Evaluation)

ModelMacro AUC-ROCBest EndpointsTraining Time
GINE0.78SR-MMP (0.89), NR-AhR (0.86)~45 min
GATv20.76SR-p53 (0.84), SR-ARE (0.82)~60 min
GCN0.75NR-Aromatase (0.81), SR-HSE (0.80)~30 min

Per-Endpoint Performance (GINE Model)

EndpointAUC-ROCPrecisionRecall
NR-AR0.740.680.71
NR-AR-LBD0.820.750.78
NR-AhR0.860.790.82
NR-Aromatase0.770.700.74
NR-ER0.730.660.70
NR-ER-LBD0.790.720.76
NR-PPAR-gamma0.710.640.68
SR-ARE0.800.730.77
SR-ATAD50.750.680.72
SR-HSE0.780.710.75
SR-MMP0.890.830.86
SR-p530.820.750.79

๐Ÿ› ๏ธ Installation

Prerequisites

  • โ€”Python 3.10 or higher
  • โ€”pip package manager
  • โ€”(Optional) CUDA-compatible GPU for faster inference

Step 1: Clone the Repository

bash
git clone https://github.com/eliot-99/Graph-ML-Enabled-Molecular-Design-Assistant-using-Graph-Neural-Networks.git
cd Graph-ML-Enabled-Molecular-Design-Assistant-using-Graph-Neural-Networks

Step 2: Create Virtual Environment

bash
# Create virtual environment
python -m venv venv

# Activate (Linux/Mac)
source venv/bin/activate

# Activate (Windows)
venv\Scripts\activate

Step 3: Install Dependencies

bash
pip install -r requirements.txt

Step 4: Install PyTorch Geometric (if needed)

bash
# For CPU
pip install torch_geometric
pip install pyg_lib torch_scatter torch_sparse torch_cluster torch_spline_conv -f https://data.pyg.org/whl/torch-2.0.0+cpu.html

# For CUDA 11.8
pip install pyg_lib torch_scatter torch_sparse torch_cluster torch_spline_conv -f https://data.pyg.org/whl/torch-2.0.0+cu118.html

Step 5: Run the Application

bash
python app.py

Open your browser and navigate to: http://localhost:7860


๐Ÿ“– Usage

Single Molecule Prediction

  1. 1.Enter a SMILES string in the input field
  2. 2.Select a model (GINE, GCN, GATv2, or All)
  3. 3.Click "Predict"
  4. 4.View results with 2D/3D molecular visualization

Batch Prediction

  1. 1.Prepare a CSV file with a column named SMILES:
csv
   SMILES
   CCO
   CC(=O)Oc1ccccc1C(=O)O
   Cn1cnc2c1c(=O)n(c(=O)n2C)C
  1. 1.Upload the CSV file
  2. 2.Select model(s) for prediction
  3. 3.Download results as CSV

API Usage (for Developers)

python
import requests

# Single prediction
response = requests.post('http://localhost:7860/predict', data={
    'smiles': 'CCO',
    'model': 'gnn'  # Options: gnn, gcn, gatv2, all
})
results = response.json()

๐Ÿ“ Project Structure

Graph-ML-Enabled-Molecular-Design-Assistant/
โ”‚
โ”œโ”€โ”€ ๐Ÿ“„ app.py                    # Flask web application
โ”œโ”€โ”€ ๐Ÿ“„ requirements.txt          # Python dependencies
โ”œโ”€โ”€ ๐Ÿ“„ Dockerfile               # Docker configuration
โ”œโ”€โ”€ ๐Ÿ“„ README.md                # This file
โ”œโ”€โ”€ ๐Ÿ“„ LICENSE                  # MIT License
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ models/                  # Pre-trained model weights
โ”‚   โ”œโ”€โ”€ best_gnn_tox21_scaffold.pt    # GINE model (~2MB)
โ”‚   โ”œโ”€โ”€ best_gcn_tox21_scaffold.pt    # GCN model (~2MB)
โ”‚   โ””โ”€โ”€ best_gatv2_tox21_scaffold.pt  # GATv2 model (~2MB)
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ templates/               # HTML templates
โ”‚   โ”œโ”€โ”€ index.html             # Main prediction interface
โ”‚   โ””โ”€โ”€ about.html             # About page
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ notebooks/               # Training notebooks
โ”‚   โ”œโ”€โ”€ GAT_Tox21.ipynb
โ”‚   โ”œโ”€โ”€ Tox21 classification with GATv2.ipynb
โ”‚   โ”œโ”€โ”€ Tox21 classification with GATv2_ver_2.ipynb
โ”‚   โ”œโ”€โ”€ train_esol.ipynb
โ”‚   โ””โ”€โ”€ tox21_gnn_comparison_scaffold.csv
โ”‚
โ””โ”€โ”€ ๐Ÿ“ data/                    # Auto-generated dataset cache

๐Ÿ”ง Technical Details

Molecular Featurization

Node Features (9 dimensions): | Feature | Description | Range | |---------|-------------|-------| | Atomic Number | Element type | 1-118 | | Chirality | Stereochemistry | 0-3 | | Formal Charge | Ionic charge | -2 to +2 | | Explicit Hs | Explicit hydrogens | 0-4 | | Hybridization | sp, sp2, sp3, etc. | 0-5 | | Aromaticity | Is aromatic? | 0-1 | | In Ring | Part of ring? | 0-1 | | Radical Electrons | Unpaired electrons | 0-2 | | Degree | Number of bonds | 0-6 |

Edge Features (3 dimensions): | Feature | Description | |---------|-------------| | Single Bond | Is single bond? (0/1) | | Double Bond | Is double bond? (0/1) | | Triple Bond | Is triple bond? (0/1) |

Training Configuration

python
{
    "optimizer": "Adam",
    "learning_rate": 0.001,
    "weight_decay": 1e-5,
    "batch_size": 64,
    "epochs": 100,
    "early_stopping_patience": 15,
    "dropout": 0.25,
    "hidden_channels": 256,
    "num_layers": 4,
    "pooling": "mean + sum",
    "split": "scaffold"
}

๐ŸŒ Deployment

Hugging Face Spaces (Current Deployment)

The app is deployed at: https://huggingface.co/spaces/Epion09g/MolGNN-Tox21-Predictor

Docker Deployment

bash
# Build image
docker build -t molgnn-tox21 .

# Run container
docker run -p 7860:7860 molgnn-tox21

Local Development

bash
python app.py
# Access at http://localhost:7860

๐Ÿ‘ฅ Team

This project was developed as part of an academic research initiative on Graph ML-Enabled Molecular Design at the intersection of machine learning and computational chemistry.

Contributors

NameRole
Saptarshi GhoshTeam Lead & Research Coordinator
Sumit ChairaUI/Deployment & Visualization Developer
Mangaldip DhuaData Engineer & Preprocessing Specialist
Uday Shankar DeyGNN Model Developer
Arnab Subhra GhoshModel Evaluation & Optimization Engineer

๐Ÿ“š References

Papers

  1. 1.Tox21 Challenge: Huang, R., et al. "Tox21Challenge to Build Predictive Models of Nuclear Receptor and Stress Response Pathways." Frontiers in Environmental Science (2016).
  1. 1.MoleculeNet: Wu, Z., et al. "MoleculeNet: A Benchmark for Molecular Machine Learning." Chemical Science (2018). arXiv:1703.00564
  1. 1.GIN: Xu, K., et al. "How Powerful are Graph Neural Networks?" ICLR (2019). arXiv:1810.00826
  1. 1.GATv2: Brody, S., et al. "How Attentive are Graph Attention Networks?" ICLR (2022). arXiv:2105.14491

Libraries


๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License

Copyright (c) 2024

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software...

๐Ÿ™ Acknowledgments

  • โ€”Tox21 Challenge organizers for the benchmark dataset
  • โ€”PyTorch Geometric team for the excellent GNN library
  • โ€”RDKit developers for cheminformatics tools
  • โ€”Hugging Face for free hosting on Spaces

<div align="center">

โญ Star this repo if you find it useful!

Made with โค๏ธ for computational chemistry and drug discovery

![GitHub stars](https://github.com/eliot-99/Graph-ML-Enabled-Molecular-Design-Assistant-using-Graph-Neural-Networks)

</div>