AF3 Cropper类解读
AlphaFold3 protein_datamodule 模块 Cropper
类用于裁剪蛋白质输入数据的 PyTorch nn.Module
模块。在 ProteinDataModule
的数据预处理流程中,它是 transform
组合的一部分,主要作用是将蛋白质的相关特征裁剪为固定长度(如 384 residues),以适配下游模型的输入要求。
源代码:
class Cropper(nn.Module):
"""A transformation that crops the protein elements."""
def __init__(self, crop_size: int = 384):
super().__init__()
self.crop_size = crop_size
def forward(self, protein_dict: dict):
"""Crop the protein
:param protein_dict: the protein dictionary with the elements
- 'X': 3D coordinates of N, C, Ca, O, `(total_L, 4, 3)`,
- 'S': sequence indices (shape `(total_L)`),
- 'mask': residue mask (0 where coordinates are missing, 1 otherwise; with interpolation 0s are replaced
with 1s), (total_L),
- 'mask_original': residue mask (0 where coordinates are missing, 1 otherwise; not changed with
interpolation), `(total_L)`,
- 'residue_idx': residue indices (from 0 to length of sequence, +100 where chains change),
`(total_L)`,
- 'chain_encoding_all&#