MCP HubMCP Hub
스킬 목록으로 돌아가기

torchdrug

K-Dense-AI
업데이트됨 Today
26,534
2,743
26,534
GitHub에서 보기
메타aidesigndata

정보

TorchDrug은 분자, 단백질, 지식 그래프를 중심으로 약물 발견 분야에서 맞춤형 그래프 신경망 아키텍처를 구축하기 위한 PyTorch 네이티브 툴박스입니다. 이는 주로 맞춤 모델 개발, 단백질 특성 예측, 역합성 계획과 같은 작업에 최적화되어 있습니다. 사전 학습된 모델이나 벤치마크 데이터셋을 사용하려면 DeepChem이나 PyTDC와 같은 보완 라이브러리를 통합해야 합니다.

빠른 설치

Claude Code

추천
기본
npx skills add K-Dense-AI/claude-scientific-skills -a claude-code
플러그인 명령대체
/plugin add https://github.com/K-Dense-AI/claude-scientific-skills
Git 클론대체
git clone https://github.com/K-Dense-AI/claude-scientific-skills.git ~/.claude/skills/torchdrug

Claude Code에서 이 명령을 복사하여 붙여넣어 스킬을 설치하세요

문서

TorchDrug

Overview

TorchDrug is a comprehensive PyTorch-based machine learning toolbox for drug discovery and molecular science. Apply graph neural networks, pre-trained models, and task definitions to molecules, proteins, and biological knowledge graphs, including molecular property prediction, protein modeling, knowledge graph reasoning, molecular generation, retrosynthesis planning, with 40+ curated datasets and 20+ model architectures.

When to Use This Skill

This skill should be used when working with:

Data Types:

  • SMILES strings or molecular structures
  • Protein sequences or 3D structures (PDB files)
  • Chemical reactions and retrosynthesis
  • Biomedical knowledge graphs
  • Drug discovery datasets

Tasks:

  • Predicting molecular properties (solubility, toxicity, activity)
  • Protein function or structure prediction
  • Drug-target binding prediction
  • Generating new molecular structures
  • Planning chemical synthesis routes
  • Link prediction in biomedical knowledge bases
  • Training graph neural networks on scientific data

Libraries and Integration:

  • TorchDrug is the primary library
  • Often used with RDKit for cheminformatics
  • Compatible with PyTorch and PyTorch Lightning
  • Integrates with AlphaFold and ESM for proteins

Getting Started

Installation

TorchDrug 0.2.1 (latest on PyPI, July 2023) requires Python 3.7–3.10 and PyTorch 1.8–2.0. Install PyTorch and torch-scatter / torch-cluster first (wheel URL depends on your PyTorch and CUDA versions — see installation docs).

uv pip install torch
# Match torch/CUDA in the URL, e.g. torch-2.0.0+cu118 or cpu
uv pip install torch-scatter torch-cluster -f https://pytorch-geometric.com/whl/torch-2.0.0+cu118.html
uv pip install torchdrug==0.2.1

On Apple Silicon, compile scatter/cluster from source; TorchDrug runs on CPU only (no MPS). Conda: conda install torchdrug -c milagraph -c conda-forge -c pytorch -c pyg.

Quick Example

import torch
from torchdrug import datasets, models, tasks
from torch.utils.data import DataLoader

# Load molecular dataset
dataset = datasets.BBBP("~/molecule-datasets/")
train_set, valid_set, test_set = dataset.split()

# Define GNN model
model = models.GIN(
    input_dim=dataset.node_feature_dim,
    hidden_dims=[256, 256, 256],
    edge_input_dim=dataset.edge_feature_dim,
    batch_norm=True,
    readout="mean"
)

# Create property prediction task
task = tasks.PropertyPrediction(
    model,
    task=dataset.tasks,
    criterion="bce",
    metric=["auroc", "auprc"]
)

# Train with PyTorch
optimizer = torch.optim.Adam(task.parameters(), lr=1e-3)
train_loader = DataLoader(train_set, batch_size=32, shuffle=True)

for epoch in range(100):
    for batch in train_loader:
        loss = task(batch)
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()

Core Capabilities

1. Molecular Property Prediction

Predict chemical, physical, and biological properties of molecules from structure.

Use Cases:

  • Drug-likeness and ADMET properties
  • Toxicity screening
  • Quantum chemistry properties
  • Binding affinity prediction

Key Components:

  • 20+ molecular datasets (BBBP, HIV, Tox21, QM9, etc.)
  • GNN models (GIN, GAT, SchNet)
  • PropertyPrediction and MultipleBinaryClassification tasks

Reference: See references/molecular_property_prediction.md for:

  • Complete dataset catalog
  • Model selection guide
  • Training workflows and best practices
  • Feature engineering details

2. Protein Modeling

Work with protein sequences, structures, and properties.

Use Cases:

  • Enzyme function prediction
  • Protein stability and solubility
  • Subcellular localization
  • Protein-protein interactions
  • Structure prediction

Key Components:

  • 15+ protein datasets (EnzymeCommission, GeneOntology, PDBBind, etc.)
  • Sequence models (ESM, ProteinBERT, ProteinLSTM)
  • Structure models (GearNet, SchNet)
  • Multiple task types for different prediction levels

Reference: See references/protein_modeling.md for:

  • Protein-specific datasets
  • Sequence vs structure models
  • Pre-training strategies
  • Integration with AlphaFold and ESM

3. Knowledge Graph Reasoning

Predict missing links and relationships in biological knowledge graphs.

Use Cases:

  • Drug repurposing
  • Disease mechanism discovery
  • Gene-disease associations
  • Multi-hop biomedical reasoning

Key Components:

  • General KGs (FB15k, WN18) and biomedical (Hetionet)
  • Embedding models (TransE, RotatE, ComplEx)
  • KnowledgeGraphCompletion task

Reference: See references/knowledge_graphs.md for:

  • Knowledge graph datasets (including Hetionet with 45k biomedical entities)
  • Embedding model comparison
  • Evaluation metrics and protocols
  • Biomedical applications

4. Molecular Generation

Generate novel molecular structures with desired properties.

Use Cases:

  • De novo drug design
  • Lead optimization
  • Chemical space exploration
  • Property-guided generation

Key Components:

  • Autoregressive generation
  • GCPN (policy-based generation)
  • GraphAutoregressiveFlow
  • Property optimization workflows

Reference: See references/molecular_generation.md for:

  • Generation strategies (unconditional, conditional, scaffold-based)
  • Multi-objective optimization
  • Validation and filtering
  • Integration with property prediction

5. Retrosynthesis

Predict synthetic routes from target molecules to starting materials.

Use Cases:

  • Synthesis planning
  • Route optimization
  • Synthetic accessibility assessment
  • Multi-step planning

Key Components:

  • USPTO-50k reaction dataset
  • CenterIdentification (reaction center prediction)
  • SynthonCompletion (reactant prediction)
  • End-to-end Retrosynthesis pipeline

Reference: See references/retrosynthesis.md for:

  • Task decomposition (center ID → synthon completion)
  • Multi-step synthesis planning
  • Commercial availability checking
  • Integration with other retrosynthesis tools

6. Graph Neural Network Models

Comprehensive catalog of GNN architectures for different data types and tasks.

Available Models:

  • General GNNs: GCN, GAT, GIN, RGCN, MPNN
  • 3D-aware: SchNet, GearNet
  • Protein-specific: ESM, ProteinBERT, GearNet
  • Knowledge graph: TransE, RotatE, ComplEx, SimplE
  • Generative: GraphAutoregressiveFlow

Reference: See references/models_architectures.md for:

  • Detailed model descriptions
  • Model selection guide by task and dataset
  • Architecture comparisons
  • Implementation tips

7. Datasets

40+ curated datasets spanning chemistry, biology, and knowledge graphs.

Categories:

  • Molecular properties (drug discovery, quantum chemistry)
  • Protein properties (function, structure, interactions)
  • Knowledge graphs (general and biomedical)
  • Retrosynthesis reactions

Reference: See references/datasets.md for:

  • Complete dataset catalog with sizes and tasks
  • Dataset selection guide
  • Loading and preprocessing
  • Splitting strategies (random, scaffold)

Common Workflows

Workflow 1: Molecular Property Prediction

Scenario: Predict blood-brain barrier penetration for drug candidates.

Steps:

  1. Load dataset: datasets.BBBP()
  2. Choose model: GIN for molecular graphs
  3. Define task: PropertyPrediction with binary classification
  4. Train with scaffold split for realistic evaluation
  5. Evaluate using AUROC and AUPRC

Navigation: references/molecular_property_prediction.md → Dataset selection → Model selection → Training

Workflow 2: Protein Function Prediction

Scenario: Predict enzyme function from sequence.

Steps:

  1. Load dataset: datasets.EnzymeCommission()
  2. Choose model: ESM (pre-trained) or GearNet (with structure)
  3. Define task: PropertyPrediction with multi-class classification
  4. Fine-tune pre-trained model or train from scratch
  5. Evaluate using accuracy and per-class metrics

Navigation: references/protein_modeling.md → Model selection (sequence vs structure) → Pre-training strategies

Workflow 3: Drug Repurposing via Knowledge Graphs

Scenario: Find new disease treatments in Hetionet.

Steps:

  1. Load dataset: datasets.Hetionet()
  2. Choose model: RotatE or ComplEx
  3. Define task: KnowledgeGraphCompletion
  4. Train with negative sampling
  5. Query for "Compound-treats-Disease" predictions
  6. Filter by plausibility and mechanism

Navigation: references/knowledge_graphs.md → Hetionet dataset → Model selection → Biomedical applications

Workflow 4: De Novo Molecule Generation

Scenario: Generate drug-like molecules optimized for target binding.

Steps:

  1. Train property predictor on activity data
  2. Choose generation approach: GCPN for RL-based optimization
  3. Define reward function combining affinity, drug-likeness, synthesizability
  4. Generate candidates with property constraints
  5. Validate chemistry and filter by drug-likeness
  6. Rank by multi-objective scoring

Navigation: references/molecular_generation.md → Conditional generation → Multi-objective optimization

Workflow 5: Retrosynthesis Planning

Scenario: Plan synthesis route for target molecule.

Steps:

  1. Load dataset: datasets.USPTO50k()
  2. Train center identification model (RGCN)
  3. Train synthon completion model (GIN)
  4. Combine into end-to-end retrosynthesis pipeline
  5. Apply recursively for multi-step planning
  6. Check commercial availability of building blocks

Navigation: references/retrosynthesis.md → Task types → Multi-step planning

Integration Patterns

With RDKit

Convert between TorchDrug molecules and RDKit:

from torchdrug import data
from rdkit import Chem

# SMILES → TorchDrug molecule
smiles = "CCO"
mol = data.Molecule.from_smiles(smiles)

# TorchDrug → RDKit
rdkit_mol = mol.to_molecule()

# RDKit → TorchDrug
rdkit_mol = Chem.MolFromSmiles(smiles)
mol = data.Molecule.from_molecule(rdkit_mol)

With AlphaFold/ESM

Use predicted structures:

from torchdrug import data

# Load AlphaFold predicted structure
protein = data.Protein.from_pdb("AF-P12345-F1-model_v4.pdb")

# Build graph with spatial edges
graph = protein.residue_graph(
    node_position="ca",
    edge_types=["sequential", "radius"],
    radius_cutoff=10.0
)

With PyTorch Lightning

Wrap tasks for Lightning training:

import pytorch_lightning as pl

class LightningTask(pl.LightningModule):
    def __init__(self, torchdrug_task):
        super().__init__()
        self.task = torchdrug_task

    def training_step(self, batch, batch_idx):
        return self.task(batch)

    def validation_step(self, batch, batch_idx):
        pred = self.task.predict(batch)
        target = self.task.target(batch)
        return {"pred": pred, "target": target}

    def configure_optimizers(self):
        return torch.optim.Adam(self.parameters(), lr=1e-3)

Technical Details

For deep dives into TorchDrug's architecture:

Core Concepts: See references/core_concepts.md for:

  • Architecture philosophy (modular, configurable)
  • Data structures (Graph, Molecule, Protein, PackedGraph)
  • Model interface and forward function signature
  • Task interface (predict, target, forward, evaluate)
  • Training workflows and best practices
  • Loss functions and metrics
  • Common pitfalls and debugging

Quick Reference Cheat Sheet

Choose Dataset:

  • Molecular property → references/datasets.md → Molecular section
  • Protein task → references/datasets.md → Protein section
  • Knowledge graph → references/datasets.md → Knowledge graph section

Choose Model:

  • Molecules → references/models_architectures.md → GNN section → GIN/GAT/SchNet
  • Proteins (sequence) → references/models_architectures.md → Protein section → ESM
  • Proteins (structure) → references/models_architectures.md → Protein section → GearNet
  • Knowledge graph → references/models_architectures.md → KG section → RotatE/ComplEx

Common Tasks:

  • Property prediction → references/molecular_property_prediction.md or references/protein_modeling.md
  • Generation → references/molecular_generation.md
  • Retrosynthesis → references/retrosynthesis.md
  • KG reasoning → references/knowledge_graphs.md

Understand Architecture:

  • Data structures → references/core_concepts.md → Data Structures
  • Model design → references/core_concepts.md → Model Interface
  • Task design → references/core_concepts.md → Task Interface

Troubleshooting Common Issues

Issue: Dimension mismatch errors → Check model.input_dim matches dataset.node_feature_dim → See references/core_concepts.md → Essential Attributes

Issue: Poor performance on molecular tasks → Use scaffold splitting, not random → Try GIN instead of GCN → See references/molecular_property_prediction.md → Best Practices

Issue: Protein model not learning → Use pre-trained ESM for sequence tasks → Check edge construction for structure models → See references/protein_modeling.md → Training Workflows

Issue: Memory errors with large graphs → Reduce batch size → Use gradient accumulation → See references/core_concepts.md → Memory Efficiency

Issue: Generated molecules are invalid → Add validity constraints → Post-process with RDKit validation → See references/molecular_generation.md → Validation and Filtering

Version Notes (0.2.1)

  • PropertyPrediction.predict() returns original-scale values (not standardized); code written for older TorchDrug may need metric/threshold updates (release notes).
  • Dataset constructors prefer atom_feature / bond_feature / mol_feature; node_feature / edge_feature / graph_feature are deprecated aliases.
  • EvolutionaryScaleModeling supports ESM-2 checkpoints in addition to ESM-1b.

Resources

Official Documentation: https://torchdrug.ai/docs/ (0.2.1) GitHub: https://github.com/DeepGraphLearning/torchdrug Paper: TorchDrug: A Powerful and Flexible Machine Learning Platform for Drug Discovery

Summary

Navigate to the appropriate reference file based on your task:

  1. Molecular property predictionmolecular_property_prediction.md
  2. Protein modelingprotein_modeling.md
  3. Knowledge graphsknowledge_graphs.md
  4. Molecular generationmolecular_generation.md
  5. Retrosynthesisretrosynthesis.md
  6. Model selectionmodels_architectures.md
  7. Dataset selectiondatasets.md
  8. Technical detailscore_concepts.md

Each reference provides comprehensive coverage of its domain with examples, best practices, and common use cases.

GitHub 저장소

K-Dense-AI/claude-scientific-skills
경로: skills/torchdrug
0
agent-skillsai-scientistbioinformaticschemoinformaticsclaudeclaude-skills

연관 스킬

content-collections

메타

이 스킬은 콘텐츠 콜렉션(Content Collections)을 위한 프로덕션 검증된 설정을 제공합니다. 콘텐츠 콜렉션은 Markdown/MDX 파일을 Zod 검증이 포함된 타입 안전한 데이터 콜렉션으로 변환해주는 TypeScript 최우선 도구입니다. 블로그, 문서 사이트 또는 콘텐츠 중심의 Vite + React 애플리케이션을 구축할 때 타입 안전성과 자동 콘텐츠 검증을 보장하기 위해 사용하세요. Vite 플러그인 구성과 MDX 컴파일부터 배포 최적화 및 스키마 검증에 이르기까지 모든 것을 다룹니다.

스킬 보기

polymarket

메타

이 스킬은 개발자들이 Polymarket 예측 시장 플랫폼을 활용한 애플리케이션을 구축할 수 있도록 지원하며, 거래 및 시장 데이터를 위한 API 통합 기능을 포함합니다. 또한 WebSocket을 통한 실시간 데이터 스트리밍을 제공하여 실시간 거래와 시장 활동을 모니터링할 수 있습니다. 이를 통해 거래 전략을 구현하거나 실시간 시장 업데이트를 처리하는 도구를 생성하는 데 활용할 수 있습니다.

스킬 보기

creating-opencode-plugins

메타

이 스킬은 개발자들이 명령어, 파일, LSP 작업 등 25개 이상의 이벤트 유형에 연결되는 OpenCode 플러그인을 만들 수 있도록 돕습니다. JavaScript/TypeScript 모듈을 위한 플러그인 구조, 이벤트 API 명세, 구현 패턴을 제공합니다. OpenCode AI 어시스턴트의 라이프사이클을 사용자 정의 이벤트 기반 로직으로 가로채거나, 모니터링하거나, 확장해야 할 때 사용하세요.

스킬 보기

sglang

메타

SGLang은 RadixAttention 프리픽스 캐싱을 활용하여 JSON, 정규식, 에이전트 워크플로우를 위한 고속 구조화 생성에 특화된 고성능 LLM 서빙 프레임워크입니다. 특히 반복되는 프리픽스가 있는 작업에서 상당히 빠른 추론 속도를 제공하여 복잡한 구조화 출력 및 다중 턴 대화에 이상적입니다. 제약 디코딩이 필요하거나 광범위한 프리픽스 공유가 있는 애플리케이션을 구축할 때는 vLLM과 같은 대안보다 SGLang을 선택하십시오.

스킬 보기