skills/torchdrug/references/protein_modeling.md
TorchDrug 0.2.1 documents protein data structures, datasets, sequence encoders, and geometry-aware graph models in its data, dataset, and model APIs. The primary tutorial index focuses on molecular and knowledge-graph workflows, so avoid inventing a protein tutorial API that upstream does not provide.
from torchdrug import data
protein = data.Protein.from_sequence(
"MKTAYIAKQRQISFVKSHFSRQ",
atom_feature=None,
bond_feature=None,
residue_feature="default",
)
print(protein.to_sequence())
For sequence-only work, setting atom and bond features to None avoids the cost
of constructing a full atom-level representation.
protein = data.Protein.from_pdb(
"protein.pdb",
atom_feature="default",
bond_feature="default",
residue_feature="default",
)
Use trusted local PDB files and validate chain selection, missing residues, alternate locations, and nonstandard residues before training.
Documented conversion methods include:
Protein.from_sequenceProtein.from_pdbProtein.from_moleculeProtein.to_sequenceProtein.to_pdbProtein.to_moleculePacked equivalents operate on lists:
PackedProtein.from_sequence(sequences)PackedProtein.from_pdb(pdb_files)PackedProtein.from_molecule(mols)Documented dataset families include:
BetaLactamase, BinaryLocalization,
SubcellularLocalizationEnzymeCommission, GeneOntology, AlphaFoldDBFold, SecondaryStructureHumanPPI, YeastPPI, PPIAffinityBindingDB, PDBBindExample:
from torchdrug import datasets
dataset = datasets.EnzymeCommission(
"~/protein-datasets/",
atom_feature=None,
bond_feature=None,
residue_feature="default",
)
train_set, valid_set, test_set = dataset.split()
Class signatures differ. Options such as branch, test_cutoff, lazy, or
species/split IDs are dataset-specific; check the API before using them.
models.ESM is the alias for EvolutionaryScaleModeling. The constructor takes
a directory for downloaded weights, not a checkpoint filename:
from torchdrug import models
model = models.ESM(
path="~/model-weights/esm/",
model="ESM-2-150M",
readout="mean",
)
TorchDrug 0.2.1 supports these ESM-2 names:
ESM-2-8MESM-2-35MESM-2-150MESM-2-650MESM-2-3BESM-2-15BIt also supports ESM-1b and ESM-1v. Maximum sequence input is 1022 residues
before special tokens. Large checkpoints require substantial memory; start with
ESM-2-8M or ESM-2-35M for pipeline validation.
Documented classes include:
models.ProteinCNNmodels.ProteinResNetmodels.ProteinLSTMmodels.ProteinBERTThese models require explicit input/hidden dimensions. Derive input dimensions from the dataset's residue feature configuration.
Documented structure-aware models include:
models.GearNetmodels.SchNetGCN, GAT, GIN, and RGCNSchNet requires node_position. GearNet requires a graph whose relation and
geometric feature configuration matches its constructor.
Use TorchDrug graph-construction and geometry layers to create sequential,
radius, and nearest-neighbor relations. Do not use a nonexistent
protein.residue_graph(...) method.
Before training a structure model, inspect:
print(protein.num_node)
print(protein.num_residue)
print(protein.node_position.shape)
print(protein.residue_feature.shape)
Confirm whether nodes represent atoms or residues and ensure the model input matches that choice.
Protein-level classification or regression can use the same task abstraction as molecules:
from torchdrug import tasks
task = tasks.PropertyPrediction(
model,
task=dataset.tasks,
criterion="bce",
metric=("auprc", "auroc"),
)
Choose criterion and metrics from the actual dataset target:
For large multi-label ontology tasks, inspect
tasks.MultipleBinaryClassification rather than treating labels as one
multiclass target.
Use models.ESM(path=<directory>, model=<supported-name>). Do not pass a
downloaded .pt filename as path.
Choose a smaller ESM model, reduce batch size, crop or filter long sequences, or freeze the encoder and precompute embeddings.
Sequence-created proteins do not acquire experimental 3D coordinates. Load a PDB or another validated structure source before using coordinate-dependent models.
Build the same relation types expected by the structure model and set
num_relation accordingly.