TorchDrug: A Powerful and Flexible Machine Learning Platform for Drug Discovery

Zhaocheng Zhu, Chence Shi, Zuobai Zhang, Shengchao Liu, Minghao Xu, Xinyu Yuan, Yangtian Zhang, Junkun Chen, Huiyu Cai, Jiarui Lu, Chang Ma, Runcheng Liu, Louis-Pascal A. C. Xhonneux, Meng Qu, Jian TangarXiv 2022

Introduction

Drug discovery is a notoriously arduous process, often spanning over a decade and incurring costs exceeding $2.5 billion to bring a single therapeutic to market. While Machine Learning (ML), particularly Graph Neural Networks (GNNs), offers a promising path to accelerate this timeline, researchers face significant barriers. These include a steep domain knowledge gap, fragmented implementations of models, and the "data tax"—the heavy engineering burden of preprocessing complex chemical structures.

TorchDrug is an open-source, PyTorch-based platform designed to bridge these gaps. By providing a hierarchical, GPU-accelerated framework, it streamlines the drug discovery pipeline from data handling to model evaluation.

A Hierarchical Architecture for Drug Discovery

To accommodate both ML experts and domain scientists, TorchDrug employs a four-layer hierarchical interface. This design allows users to interact with the library at their preferred level of abstraction.

The hierarchical architecture of TorchDrug, spanning from low-level data structures to high-level training engines.
  1. Low-level (torchdrug.data): Molecules and knowledge graphs are treated as "first-class citizens." Similar to PyTorch tensors, these objects support GPU-accelerated operations like node masking and connected component extraction with seamless auto-differentiation.
  2. Mid-level (torchdrug.layers & torchdrug.models): This layer provides essential building blocks, including standard GNN layers (Convolution, Pooling) and full architectures such as Message Passing Neural Networks (MPNN) and Graph Attention Networks (GAT).
  3. High-level (torchdrug.tasks): These are model-agnostic routines for specific challenges. A user can wrap a model in a "Task" (e.g., Property Prediction), which automatically manages training logic and evaluation metrics.
  4. The Engine (torchdrug.core): A high-level training and evaluation engine that handles configurations and hardware scaling, minimizing boilerplate code.

Molecules as Tensors: Efficiency and Flexibility

A core innovation of TorchDrug is the treatment of molecular structures as tensors. This allows for efficient batching and GPU acceleration, which are frequently the primary bottlenecks in chemical informatics.

Example of TorchDrug's API for molecular batching and visualization, demonstrating the 'Molecules as Tensors' philosophy.

The "Task" abstraction further enhances flexibility by decoupling the representation model from the specific prediction goal. This modularity enables researchers to swap underlying architectures—for instance, replacing a GCN with a GAT—with minimal code changes. Additionally, TorchDrug integrates Knowledge Graph (KG) reasoning as a core pillar, facilitating "drug repurposing" by analyzing relationships within vast biological networks.

Standardized Benchmarking and Datasets

TorchDrug integrates 30 common datasets across five major categories:

  • Molecular Property Prediction: Classification and regression tasks.
  • De Novo Design: Generating novel molecular graphs.
  • Retrosynthesis: Predicting chemical precursors.
  • Biomedical Knowledge Graphs: Large-scale relational data between drugs, diseases, and proteins.

By standardizing the interface for these datasets, TorchDrug enables fair and reproducible comparisons between state-of-the-art (SOTA) models, such as GraphAF for generative design and RotatE for knowledge graph reasoning. Since its release, the platform has seen significant community adoption, surpassing 5,000 downloads.

Future Directions

While TorchDrug currently excels in 2D graph representations, the spatial arrangement (3D conformation) of atoms is vital for understanding how drugs bind to proteins. Future development aims to expand the library's capabilities in protein representation learning, 3D molecular geometry, and protein-ligand docking to further empower the drug discovery community.

Summary updated

BibTeX
@misc{zhu2022torchdrug,
  author = {Zhaocheng Zhu and Chence Shi and Zuobai Zhang and Shengchao Liu and Minghao Xu and Xinyu Yuan and Yangtian Zhang and Junkun Chen and Huiyu Cai and Jiarui Lu and Chang Ma and Runcheng Liu and Louis-Pascal A. C. Xhonneux and Meng Qu and Jian Tang},
  title = {{TorchDrug: A Powerful and Flexible Machine Learning Platform for Drug Discovery}},
  year = {2022},
  eprint = {2202.08320},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2202.08320},
}
Figure