Package: torchdrug
withDocs|Tutorials|Benchmarks|Papers ImplementedTorchDrug is aPyTorch-based machine learning toolbox designed for several purposes.Easy implementation of graph operations in a PyTorchic style with GPU supportBeing friendly to practitioners with minimal knowledge about drug discoveryRapid prototyping of machine learning researchInstallationTorchDrug can be installed on either Linux, Windows or macOS. It is compatible with
3.7 <= Python <= 3.10 and PyTorch >= 1.8.0.From Condacondainstalltorchdrug-cmilagraph-cconda-forge-cpytorch-cpygFrom Pippipinstalltorch==1.9.0
pipinstalltorch-scattertorch-cluster-fhttps://pytorch-geometric.com/whl/torch-1.9.0+cu102.html
pipinstalltorchdrugTo installtorch-scatterfor other PyTorch or CUDA versions, please see the
instructions inhttps://github.com/rusty1s/pytorch_scatterFrom Sourcegitclonehttps://github.com/DeepGraphLearning/torchdrugcdtorchdrug
pipinstall-rrequirements.txt
pythonsetup.pyinstallWindows (PowerShell)We need to first install the build tools for Visual Studio. We then install the
following modules in PowerShell.Install-ModulePscx-AllowClobberInstall-ModuleVSSetupInitialize 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-Architecturex64$env:LIB+=";C:\Program Files\Python37\libs"Apple Silicon (M1/M2 Chips)We need PyTorch >= 1.13 to run TorchDrug on Apple silicon. Fortorch-scatterandtorch-cluster, they can be compiled from their sources. Note TorchDrug doesn't
supportmpsdevices.pipinstalltorch==1.13.0
pipinstallgit+https://github.com/rusty1s/pytorch_scatter.git
pipinstallgit+https://github.com/rusty1s/pytorch_cluster.git
pipinstalltorchdrugQuick StartTorchDrug 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 byPyTorchframework, and support GPU
acceleration and auto differentiation.fromtorchdrugimportdataedge_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 & 4subgraph=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.withmol.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.importtorchfromtorchdrugimportdatasetsdataset=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)fromtorchdrugimportmodels,tasksmodel=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.fromtorchdrugimportcore# Single CPU / Multiple CPUs / Distributed CPUssolver=core.Engine(task,train_set,valid_set,test_set,optimizer)# Single GPUsolver=core.Engine(task,train_set,valid_set,test_set,optimizer,gpus=[0])# Multiple GPUssolver=core.Engine(task,train_set,valid_set,test_set,optimizer,gpus=[0,1,2,3])# Distributed GPUssolver=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 throughWeights & Biases platform.solver=core.Engine(task,train_set,valid_set,test_set,optimizer,logger="wandb")ContributingEveryone is welcome to contribute to the development of TorchDrug.
Please refer tocontributing guidelinesfor more details.LicenseTorchDrug is released underApache-2.0 License.