• Stars
    star
    1,382
  • Rank 34,014 (Top 0.7 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 3 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A powerful and flexible machine learning platform for drug discovery

TorchDrug

with TorchProtein

Open in Colab Contributions License Apache-2.0 PyPI downloads TorchDrug Twitter

Docs | Tutorials | Benchmarks | Papers Implemented

TorchDrug is a PyTorch-based machine learning toolbox designed for several purposes.

  • Easy implementation of graph operations in a PyTorchic style with GPU support
  • Being friendly to practitioners with minimal knowledge about drug discovery
  • Rapid prototyping of machine learning research

Installation

TorchDrug can be installed on either Linux, Windows or macOS. It is compatible with 3.7 <= Python <= 3.10 and PyTorch >= 1.8.0.

From Conda

conda install torchdrug -c milagraph -c conda-forge -c pytorch -c pyg

From Pip

pip install torch==1.9.0
pip install torch-scatter torch-cluster -f https://pytorch-geometric.com/whl/torch-1.9.0+cu102.html
pip install torchdrug

To install torch-scatter for other PyTorch or CUDA versions, please see the instructions in https://github.com/rusty1s/pytorch_scatter

From Source

git clone https://github.com/DeepGraphLearning/torchdrug
cd torchdrug
pip install -r requirements.txt
python setup.py install

Windows (PowerShell)

We need to first install the build tools for Visual Studio. We then install the following modules in PowerShell.

Install-Module Pscx -AllowClobber
Install-Module VSSetup

Initialize Visual Studio in PowerShell with the following commands. We may setup this for all PowerShell sessions by writing it to the PowerShell profile. Change the library path according to your own case.

Import-VisualStudioVars -Architecture x64
$env:LIB += ";C:\Program Files\Python37\libs"

Apple Silicon (M1/M2 Chips)

We need PyTorch >= 1.13 to run TorchDrug on Apple silicon. For torch-scatter and torch-cluster, they can be compiled from their sources. Note TorchDrug doesn't support mps devices.

pip install torch==1.13.0
pip install git+https://github.com/rusty1s/pytorch_scatter.git
pip install git+https://github.com/rusty1s/pytorch_cluster.git
pip install torchdrug

Quick Start

TorchDrug is designed for humans and focused on graph structured data. It enables easy implementation of graph operations in machine learning models. All the operations in TorchDrug are backed by PyTorch framework, and support GPU acceleration and auto differentiation.

from torchdrug import data

edge_list = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 0]]
graph = data.Graph(edge_list, num_node=6)
graph = graph.cuda()
# the subgraph induced by nodes 2, 3 & 4
subgraph = graph.subgraph([2, 3, 4])

Molecules are also supported in TorchDrug. You can get the desired molecule properties without any domain knowledge.

mol = data.Molecule.from_smiles("CCOC(=O)N", atom_feature="default", bond_feature="default")
print(mol.node_feature)
print(mol.atom_type)
print(mol.to_scaffold())

You may also register custom node, edge or graph attributes. They will be automatically processed during indexing operations.

with mol.edge():
	mol.is_CC_bond = (mol.edge_list[:, :2] == td.CARBON).all(dim=-1)
sub_mol = mol.subgraph(mol.atom_type != td.NITROGEN)
print(sub_mol.is_CC_bond)

TorchDrug provides a wide range of common datasets and building blocks for drug discovery. With minimal code, you can apply standard models to solve your own problem.

import torch
from torchdrug import datasets

dataset = datasets.Tox21()
dataset[0].visualize()
lengths = [int(0.8 * len(dataset)), int(0.1 * len(dataset))]
lengths += [len(dataset) - sum(lengths)]
train_set, valid_set, test_set = torch.utils.data.random_split(dataset, lengths)
from torchdrug import models, tasks

model = models.GIN(dataset.node_feature_dim, hidden_dims=[256, 256, 256, 256])
task = tasks.PropertyPrediction(model, task=dataset.tasks)

Training and inference are accelerated by multiple CPUs or GPUs. This can be seamlessly switched in TorchDrug by just a line of code.

from torchdrug import core

# Single CPU / Multiple CPUs / Distributed CPUs
solver = core.Engine(task, train_set, valid_set, test_set, optimizer)
# Single GPU
solver = core.Engine(task, train_set, valid_set, test_set, optimizer, gpus=[0])
# Multiple GPUs
solver = core.Engine(task, train_set, valid_set, test_set, optimizer, gpus=[0, 1, 2, 3])
# Distributed GPUs
solver = core.Engine(task, train_set, valid_set, test_set, optimizer, gpus=[0, 1, 2, 3, 0, 1, 2, 3])

Experiments can be easily tracked and managed through Weights & Biases platform.

solver = core.Engine(task, train_set, valid_set, test_set, optimizer, logger="wandb")

Contributing

Everyone is welcome to contribute to the development of TorchDrug. Please refer to contributing guidelines for more details.

License

TorchDrug is released under Apache-2.0 License.

More Repositories

1

LiteratureDL4Graph

A comprehensive collection of recent papers on graph deep learning
3,068
star
2

graphvite

GraphVite: A General and High-performance Graph Embedding System
C++
1,207
star
3

KnowledgeGraphEmbedding

Python
1,184
star
4

RecommenderSystems

Python
1,058
star
5

ULTRA

A foundation model for knowledge graph reasoning
Python
420
star
6

GMNN

Graph Markov Neural Networks
Python
400
star
7

GearNet

GearNet and Geometric Pretraining Methods for Protein Structure Representation Learning, ICLR'2023 (https://arxiv.org/abs/2203.06125)
Python
265
star
8

NBFNet

Official implementation of Neural Bellman-Ford Networks (NeurIPS 2021)
Python
196
star
9

ConfGF

Implementation of Learning Gradient Fields for Molecular Conformation Generation (ICML 2021).
Python
159
star
10

pLogicNet

Python
143
star
11

RNNLogic

C++
123
star
12

AStarNet

Official implementation of A* Networks
Python
121
star
13

GraphAny

GraphAny: A foundation model for node classification on any graph.
Python
101
star
14

GNN-QE

Official implementation of Graph Neural Network Query Executor (ICML 2022)
Python
89
star
15

PEER_Benchmark

PEER Benchmark, appear at NeurIPS 2022 Dataset and Benchmark Track (https://arxiv.org/abs/2206.02096)
Python
79
star
16

ESM-GearNet

ESM-GearNet for Protein Structure Representation Learning (https://arxiv.org/abs/2303.06275)
Python
75
star
17

DiffPack

Implementation of DiffPack: A Torsional Diffusion Model for Autoregressive Protein Side-Chain Packing
Python
71
star
18

GraphLoG

Implementation of Self-supervised Graph-level Representation Learning with Local and Global Structure (ICML 2021).
Python
68
star
19

ProtST

[ICML-23 ORAL] ProtST: Multi-Modality Learning of Protein Sequences and Biomedical Texts
Python
62
star
20

GraphAF

50
star
21

InductiveQE

Official implementation of Inductive Logical Query Answering in Knowledge Graphs (NeurIPS 2022)
Python
47
star
22

ContinuousGNN

Python
44
star
23

FewShotRE

Python
38
star
24

SiamDiff

Code for Pre-training Protein Encoder via Siamese Sequence-Structure Diffusion Trajectory Prediction (https://arxiv.org/abs/2301.12068)
Python
38
star
25

SPN

Python
29
star
26

GearBind

Pretrainable geometric graph neural network for antibody affinity maturation
Python
28
star
27

esm-s

Structure-Informed Protein Language Model
Python
26
star
28

DrugTutorial_AAAI2021

Tutorial for Drug Discovery on AAAI 2021.
CSS
8
star
29

DeepGraphLearning

Homepage
7
star
30

torchdrug-site

Website for TorchDrug
SCSS
6
star
31

GraphRepresentationLiterature

The literature on graph representation learning
4
star
32

ultra_torchdrug

A TorchDrug version of ULTRA for reproducibility
Python
4
star
33

AAAI19Tutorial

Tutorial "graph representation learning" given at AAAI'19
3
star
34

torchprotein-site

Website for TorchProtein
SCSS
3
star
35

coursewebsite

Course website for Deep Learning and Applications
CSS
2
star
36

Math80600A_2021W

Python
1
star