🛠️ Torchdrug
薬の発見やタンパク質の研究、知識グラフ
📺 まず動画で見る(YouTube)
▶ 【衝撃】最強のAIエージェント「Claude Code」の最新機能・使い方・プログラミングをAIで効率化する超実践術を解説! ↗
※ jpskill.com 編集部が参考用に選んだ動画です。動画の内容と Skill の挙動は厳密には一致しないことがあります。
📜 元の英語説明(参考)
PyTorch-native graph neural networks for molecules and proteins. Use when building custom GNN architectures for drug discovery, protein modeling, or knowledge graph reasoning. Best for custom model development, protein property prediction, retrosynthesis. For pre-trained models and diverse featurizers use deepchem; for benchmark datasets use pytdc.
🇯🇵 日本人クリエイター向け解説
薬の発見やタンパク質の研究、知識グラフ
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o torchdrug.zip https://jpskill.com/download/4252.zip && unzip -o torchdrug.zip && rm torchdrug.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/4252.zip -OutFile "$d\torchdrug.zip"; Expand-Archive "$d\torchdrug.zip" -DestinationPath $d -Force; ri "$d\torchdrug.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
torchdrug.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
torchdrugフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-17
- 取得日時
- 2026-05-18
- 同梱ファイル
- 9
💬 こう話しかけるだけ — サンプルプロンプト
- › Torchdrug を使って、最小構成のサンプルコードを示して
- › Torchdrug の主な使い方と注意点を教えて
- › Torchdrug を既存プロジェクトに組み込む方法を教えて
これをClaude Code に貼るだけで、このSkillが自動発動します。
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
[スキル名] torchdrug
TorchDrug
概要
TorchDrugは、創薬および分子科学のための包括的なPyTorchベースの機械学習ツールボックスです。グラフニューラルネットワーク、事前学習済みモデル、およびタスク定義を分子、タンパク質、生物学的知識グラフに適用し、分子特性予測、タンパク質モデリング、知識グラフ推論、分子生成、逆合成計画など、40以上の厳選されたデータセットと20以上のモデルアーキテクチャを提供します。
このスキルを使用する場面
このスキルは、以下を扱う際に使用してください。
データ型:
- SMILES文字列または分子構造
- タンパク質配列または3D構造(PDBファイル)
- 化学反応と逆合成
- 生物医学知識グラフ
- 創薬データセット
タスク:
- 分子特性(溶解度、毒性、活性)の予測
- タンパク質機能または構造の予測
- 薬物-標的結合の予測
- 新しい分子構造の生成
- 化学合成経路の計画
- 生物医学知識ベースにおけるリンク予測
- 科学データに対するグラフニューラルネットワークのトレーニング
ライブラリと統合:
- TorchDrugが主要なライブラリです
- ケモインフォマティクスにはRDKitと併用されることが多いです
- PyTorchおよびPyTorch Lightningと互換性があります
- タンパク質についてはAlphaFoldおよびESMと統合します
はじめに
インストール
uv pip install torchdrug
# またはオプションの依存関係を含める場合
uv pip install torchdrug[full]
簡単な例
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()
コア機能
1. 分子特性予測
構造から分子の化学的、物理的、生物学的特性を予測します。
ユースケース:
- 薬物らしさおよびADMET特性
- 毒性スクリーニング
- 量子化学特性
- 結合親和性予測
主要コンポーネント:
- 20以上の分子データセット(BBBP、HIV、Tox21、QM9など)
- GNNモデル(GIN、GAT、SchNet)
- PropertyPredictionおよびMultipleBinaryClassificationタスク
参照: 完全なデータセットカタログ、モデル選択ガイド、トレーニングワークフローとベストプラクティス、特徴量エンジニアリングの詳細については、references/molecular_property_prediction.mdを参照してください。
2. タンパク質モデリング
タンパク質配列、構造、および特性を扱います。
ユースケース:
- 酵素機能予測
- タンパク質の安定性と溶解度
- 細胞内局在
- タンパク質-タンパク質相互作用
- 構造予測
主要コンポーネント:
- 15以上のタンパク質データセット(EnzymeCommission、GeneOntology、PDBBindなど)
- 配列モデル(ESM、ProteinBERT、ProteinLSTM)
- 構造モデル(GearNet、SchNet)
- さまざまな予測レベルに対応する複数のタスクタイプ
参照: タンパク質固有のデータセット、配列モデルと構造モデルの比較、事前学習戦略、AlphaFoldおよびESMとの統合については、references/protein_modeling.mdを参照してください。
3. 知識グラフ推論
生物学的知識グラフにおける欠落したリンクと関係を予測します。
ユースケース:
- 薬物再利用
- 疾患メカニズムの発見
- 遺伝子-疾患関連
- マルチホップ生物医学推論
主要コンポーネント:
- 一般的なKG(FB15k、WN18)および生物医学KG(Hetionet)
- 埋め込みモデル(TransE、RotatE、ComplEx)
- KnowledgeGraphCompletionタスク
参照: 知識グラフデータセット(45kの生物医学エンティティを含むHetionetを含む)、埋め込みモデルの比較、評価指標とプロトコル、生物医学的応用については、references/knowledge_graphs.mdを参照してください。
4. 分子生成
望ましい特性を持つ新規分子構造を生成します。
ユースケース:
- デノボ創薬
- リード最適化
- 化学空間探索
- 特性ガイド付き生成
主要コンポーネント:
- 自己回帰生成
- GCPN(ポリシーベース生成)
- GraphAutoregressiveFlow
- 特性最適化ワークフロー
参照: 生成戦略(無条件、条件付き、足場ベース)、多目的最適化、検証とフィルタリング、特性予測との統合については、references/molecular_generation.mdを参照してください。
5. 逆合成
標的分子から出発物質への合成経路を予測します。
ユースケース:
- 合成計画
- 経路最適化
- 合成可能性評価
- 多段階計画
主要コンポーネント:
- USPTO-50k反応データセット
- CenterIdentification(反応中心予測)
- SynthonCompletion(反応物予測)
- エンドツーエンドのRetrosynthesisパイプライン
参照: タスク分解(中心ID → シントン補完)、多段階合成計画、市販品確認、他の逆合成ツールとの統合については、references/retrosynthesis.mdを参照してください。
6. グラフニューラルネットワークモデル
さまざまなデータ型とタスクに対応するGNNアーキテクチャの包括的なカタログです。
利用可能なモデル:
- 一般的なGNN: GCN、GAT、GIN、RGCN、MPNN
- 3D対応: SchNet、GearNet
- タンパク質固有: ESM、ProteinBERT、GearNet
- 知識グラフ: TransE、RotatE、ComplEx、SimplE
- 生成: GraphAutoregressiveFlow
参照: 詳細なモデルの説明、タスクとデータセットによるモデル選択ガイド、アーキテクチャの比較、実装のヒントについては、references/models_architectures.mdを参照してください。
7. データセット
化学、生物学にわたる40以上の厳選されたデータセット
(原文がここで切り詰められています)
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
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
uv pip install torchdrug
# Or with optional dependencies
uv pip install torchdrug[full]
Quick Example
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:
- Load dataset:
datasets.BBBP() - Choose model: GIN for molecular graphs
- Define task:
PropertyPredictionwith binary classification - Train with scaffold split for realistic evaluation
- 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:
- Load dataset:
datasets.EnzymeCommission() - Choose model: ESM (pre-trained) or GearNet (with structure)
- Define task:
PropertyPredictionwith multi-class classification - Fine-tune pre-trained model or train from scratch
- 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:
- Load dataset:
datasets.Hetionet() - Choose model: RotatE or ComplEx
- Define task:
KnowledgeGraphCompletion - Train with negative sampling
- Query for "Compound-treats-Disease" predictions
- 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:
- Train property predictor on activity data
- Choose generation approach: GCPN for RL-based optimization
- Define reward function combining affinity, drug-likeness, synthesizability
- Generate candidates with property constraints
- Validate chemistry and filter by drug-likeness
- 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:
- Load dataset:
datasets.USPTO50k() - Train center identification model (RGCN)
- Train synthon completion model (GIN)
- Combine into end-to-end retrosynthesis pipeline
- Apply recursively for multi-step planning
- 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.mdorreferences/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
Resources
Official Documentation: https://torchdrug.ai/docs/ 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:
- Molecular property prediction →
molecular_property_prediction.md - Protein modeling →
protein_modeling.md - Knowledge graphs →
knowledge_graphs.md - Molecular generation →
molecular_generation.md - Retrosynthesis →
retrosynthesis.md - Model selection →
models_architectures.md - Dataset selection →
datasets.md - Technical details →
core_concepts.md
Each reference provides comprehensive coverage of its domain with examples, best practices, and common use cases.
同梱ファイル
※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。
- 📄 SKILL.md (14,146 bytes)
- 📎 references/core_concepts.md (14,394 bytes)
- 📎 references/datasets.md (10,951 bytes)
- 📎 references/knowledge_graphs.md (8,480 bytes)
- 📎 references/models_architectures.md (13,694 bytes)
- 📎 references/molecular_generation.md (10,074 bytes)
- 📎 references/molecular_property_prediction.md (5,667 bytes)
- 📎 references/protein_modeling.md (7,737 bytes)
- 📎 references/retrosynthesis.md (11,537 bytes)