Skip to content
homerquanPublic

About

Demo the idea of graph based drug discovery

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DrugCLIP — Multimodal Graph–Text Drug Design

DrugCLIP is a multimodal command-line interface (CLI) tool designed for small-molecule drug discovery. It uses a CLIP-style contrastive learning architecture to align molecular graph embeddings (using SchNet) with textual descriptors (using DistilBERT).

This tool allows you to train an alignment model and infer/design molecules using goal-directed text prompts, mimicking image-text generation/retrieval for medicinal chemistry.

Setup and Installation

1. Requirements

Ensure you are using Python 3.9+ and install the dependencies. The system is designed to run on a machine with a CUDA-enabled GPU for best performance.

pip install -r requirements.txt

Note: The model uses PyTorch Geometric (torch_geometric). To bypass compilation issues with C++ extensions (torch-cluster, torch-scatter), the graph encoder dynamically patches radius_graph to run in pure PyTorch natively.

Helper Scripts

A set of convenient wrapper scripts are provided in the scripts/ folder. All scripts are meant to be executed from the root of the project.

  • scripts/download_data.sh: Downloads necessary datasets.
  • scripts/train.sh: Executes the model training routine.
  • scripts/infer.sh: Runs inference via text prompting.

Usage Guide

1. Downloading Datasets

DrugCLIP leverages datasets like MolTextNet (PubChemSTM alternative), TDC Tox21, TDC ClinTox, and ChEMBL.

Use the download_data.sh script to fetch the data.

Download all datasets:

./scripts/download_data.sh all

Download specific datasets:

./scripts/download_data.sh moltextnet
./scripts/download_data.sh tdc-tox
./scripts/download_data.sh chembl

Note: Datasets are downloaded directly to the data/ directory inside your project.

2. Training the Model

The training script automatically initializes the Graph Encoder (SchNet) and the Text Encoder (DistilBERT), aligning them in a shared embedding space using contrastive loss (InfoNCE).

To run a rapid 2-epoch validation loop using generated synthetic data (great for evaluating if your hardware and libraries are correctly configured before a multi-hour run):

./scripts/train.sh --quick-validate

To begin the full pretraining loop utilizing the actual MolTextNet data you downloaded:

./scripts/train.sh

What to expect during training: When the training initializes, it prints a diagnostic block confirming the active compute device and the specific GPU model loaded, enabling you to verify hardware acceleration before epochs begin.

Starting alignment training using config: configs/align_pubchemstm.yaml
==================================================
TRAINING DEVICE: cuda
GPU MODEL: NVIDIA GH200 480GB
==================================================
Generating synthetic drug-text pairs for pretraining (using 250 samples)...
Generating 3D conformations...
Successfully processed 250 molecules.
Starting Training...
Epoch 1/2 - Loss: 2.7144
Epoch 2/2 - Loss: 1.9601
Training complete! Model saved to runs/align/best.ckpt

Note: If --quick-validate is passed, the script generates synthetic 3D conformers from a small array of hardcoded SMILES strings on the fly. For full production pretraining (the default), the dataloader connects to the data/moltextnet/train.csv artifacts.

3. Inference and Retrieval

Once trained, you can use the model to retrieve and rank drug candidates based on a natural language design prompt and an optional reference SMILES scaffold.

./scripts/infer.sh \
  --goal-text "Design a low-toxicity oral kinase inhibitor similar to osimertinib" \
  --reference-smiles "COc1cc..." \
  --top-n 20 \
  --checkpoint runs/align/best.ckpt

Direct CLI Usage

You can bypass the scripts and use the python CLI directly if you prefer:

# Data
PYTHONPATH=. python3 drugclip/cli.py data download all

# Train
USE_TF=0 PYTHONPATH=. python3 drugclip/cli.py train align

# Infer
USE_TF=0 PYTHONPATH=. python3 drugclip/cli.py infer --goal-text "find safe inhibitors"

(The USE_TF=0 flag is recommended to avoid transformers attempting to import a broken TensorFlow installation on some GPU clusters).

About

Demo the idea of graph based drug discovery

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages