P2PXML
Model Introduction
P2PXML is a deep geometric learning framework for predicting antibody-antigen binding affinity. The model jointly uses protein sequence information and three-dimensional PDB structural information from the antibody and antigen to predict binding affinity in terms of IC50.
Paper: Deep geometric framework to predict antibody–antigen binding affinity
Model Description
The P2PXML combined model consists of two parallel branches:
- Structural branch: Constructs antibody and antigen graphs from PDB atomic coordinates and extracts structural representations using GCN, GAT, and graph pooling;
- Sequence branch: Extracts amino acid sequences from PDB files, performs one-hot encoding, and uses attention, Transformer, and cross-attention modules to model sequence-level and interaction representations;
- Fusion output: Combines the regression outputs of the structural and sequence branches to predict antibody-antigen binding affinity.
The model takes one antibody PDB file and one antigen PDB file as input.
The maximum sequence lengths supported by the official demonstration model are:
- Antibody: 669 amino acids;
- Antigen: 3102 amino acids.
Use Cases
| Use Case | Description |
|---|---|
| Antibody-antigen binding affinity prediction | Predict IC50 from antibody and antigen PDB structures. |
| Antibody candidate screening | Compare the predicted affinity trends of multiple antibody-antigen structure pairs. |
| Model compatibility validation | Validate PyTorch Geometric inference and training in the SCNet DCU environment. |
| P2PXML method reproduction | Perform training or evaluation using the official P2PXML_Structure dataset. |
Usage
1. OneCode
You can use the OneCode online environment for an intelligent one-click AI4S programming experience:
Try OneCode for AI4S Programming
2. Manual Installation
Hardware Requirements
- The model supports CPU as well as CUDA-, ROCm-, and DTK-compatible accelerator devices supported by PyTorch;
- GPU or DCU is recommended for inference and training;
- CPU can be used for functional validation, but PDB graph construction and model computation are significantly slower;
- The model and graph features use
float64, so actual device-memory and host-memory requirements depend on the number of atoms in the antibody and antigen structures and on the training batch size; - Full-dataset training generates graph caches and checkpoints and therefore requires substantially more disk space than single-sample inference.
Download the Model Package
Install the Hugging Face command-line tool and download the model package containing the adapted code, pretrained weights, and example data:
python -m pip install -U huggingface_hub
hf download OneScience-Group/P2PXML --local-dir ./P2PXML
cd P2PXML
All commands below should be executed from the repository root unless otherwise specified.
Install the Runtime Environment
DCU Environment
# Activate DTK and Conda first
conda create -n onescience311 python=3.11 -y
conda activate onescience311
pip install onescience[bio-dcu] \
-i http://mirrors.onescience.ai:3141/pypi/simple/ \
--trusted-host mirrors.onescience.ai
GPU Environment
# Activate Conda first
conda create -n onescience311 python=3.11 -y
conda activate onescience311
python -m pip install "onescience[bio-gpu]" \
-i http://mirrors.onescience.ai:3141/pypi/simple/ \
--trusted-host mirrors.onescience.ai
Install the additional dependencies required by P2PXML:
python -m pip install -r requirements.txt
If an independent Jupyter kernel is required, register one with:
python -m ipykernel install \
--user \
--name evo_bio \
--display-name "Python (onescience311)"
Weights and Data Preparation
The main assets included in the Hugging Face model package are:
| Asset | Location | Purpose |
|---|---|---|
| Official combined-model weights | weight/model_weights.pth |
Antibody-antigen binding affinity inference |
| Official antibody example | conf/data/10-1074.pdb |
Quick-inference antibody input |
| Official antigen example | conf/data/0013095_2_11.pdb |
Quick-inference antigen input |
| SCNet inference notebook | scripts/smoke/P2PXML_Demonstration_SCNet.ipynb |
Local-weight and PDB inference |
| Structural training data | conf/P2PXML_Structure/ |
Real-data subset or full-dataset training |
The complete official dataset is available from Zenodo:
https://zenodo.org/records/11531319
The current local P2PXML_structure.csv contains:
- 8,475 antibody-antigen records;
- 655 antibody PDB structures;
- 469 antigen PDB structures.
Basic DCU/PyG Validation
Use the following script to verify PyTorch, PyTorch Geometric, GCN, GAT, and accelerator execution:
python - <<'PY'
import torch
import torch_geometric
from torch_geometric.nn import GATConv, GCNConv
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
x = torch.randn(
4,
4,
dtype=torch.float64,
device=device,
)
edge_index = torch.tensor(
[[0, 1, 2, 3, 0, 2], [1, 0, 3, 2, 2, 0]],
dtype=torch.long,
device=device,
)
gcn = GCNConv(4, 8).to(device).double()
gat = GATConv(4, 8, heads=2).to(device).double()
print("torch:", torch.__version__)
print("torch_geometric:", torch_geometric.__version__)
print("device:", device)
print("GCN:", gcn(x, edge_index).shape)
print("GAT:", gat(x, edge_index).shape)
PY
Quick Inference
Run the inference notebook on a DCU compute node with the complete DTK dynamic-library environment loaded:
export P2PXML_ROOT=$PWD
cd scripts/smoke
P2PXML_ROOT="$P2PXML_ROOT" \
jupyter nbconvert \
--to notebook \
--execute P2PXML_Demonstration_SCNet.ipynb \
--output P2PXML_Demonstration_SCNet_output.ipynb \
--ExecutePreprocessor.kernel_name=evo_bio \
--ExecutePreprocessor.timeout=-1
After successful execution, the resulting notebook is saved as:
scripts/smoke/P2PXML_Demonstration_SCNet_output.ipynb
The warning:
IProgress not found
only affects notebook progress-bar display and does not affect the inference results.
Real-Data Subset Training
The script:
model/integrated_model_v1_dataset_smoke.py
supports selecting the number of training samples, number of epochs, output directory, and initialization checkpoint through environment variables.
The following example trains on 50 real structural records for one epoch:
cd "$P2PXML_ROOT"
P2PXML_DATA_LIMIT=50 \
P2PXML_EPOCHS=1 \
P2PXML_RUN_DIR=./scripts/training_runs/n50 \
P2PXML_INIT_CHECKPOINT=./weight/model_weights.pth \
python model/integrated_model_v1_dataset_smoke.py
The current upstream Dataset implementation recursively switches to the next sample when graph construction fails.
As a result, this training workflow can complete even when individual samples fail, but some effective training samples may be repeated.
Therefore, this run should only be interpreted as validation that the real-data training pipeline is executable.
It should not be treated as:
- A strict training-performance benchmark;
- A complete data-integrity validation;
- A final accuracy result.
Full-Dataset Single-Epoch Training
To run one epoch on the complete structural dataset:
cd "$P2PXML_ROOT"
P2PXML_DATA_LIMIT=0 \
P2PXML_EPOCHS=1 \
P2PXML_RUN_DIR=./scripts/training_runs/full_epoch1 \
P2PXML_INIT_CHECKPOINT=./weight/model_weights.pth \
python model/integrated_model_v1_dataset_smoke.py
Before running full-dataset training, verify that every Ab and Ag identifier in the CSV file has a corresponding PDB structure and handle any missing or invalid structures.
Initial graph construction computes pairwise distances between PDB atoms, with computational complexity approaching:
O(N²)
The generated graph data is cached under:
conf/P2PXML_Structure/graph_data/
Therefore, the first complete training run has substantially higher runtime and disk-space requirements than subsequent epochs.
It is recommended to retain the graph cache and gradually scale validation from:
50 samples
→ 500 samples
→ full dataset
before running complete training.
OneScience Official Resources
| Platform | OneScience Main Repository | Skills Repository |
|---|---|---|
| Gitee | https://gitee.com/onescience-ai/onescience | https://gitee.com/onescience-ai/oneskills |
| GitHub | https://github.com/onescience-ai/OneScience | https://github.com/onescience-ai/oneskills |
Citation and License
- Paper: Deep geometric framework to predict antibody–antigen binding affinity
- Official implementation: https://github.com/Drug-Discovery-ENTC/p2pxml
- Official dataset: P2PXML Dataset
The upstream P2PXML source code is distributed under the MIT License.
The official P2PXML notebook states that the dataset is distributed under the CC BY-NC-SA 4.0 license. Users must comply with the corresponding attribution, non-commercial-use, and share-alike requirements when using or redistributing the dataset.
This Hugging Face model package provides runtime adaptation and directory organization based on the official implementation. It does not modify or extend the original copyright status, licenses, or terms of use of the paper, source code, model weights, datasets, or other third-party resources.
中文说明
模型简介
P2PXML 是用于预测抗体与抗原结合亲和力的深度几何学习框架。模型结合抗体和抗原的蛋白质序列信息及三维 PDB 结构信息,预测以 IC50 表示的结合亲和力。
模型描述
P2PXML 组合模型由两个并行分支构成。
- 结构分支根据 PDB 原子坐标构建抗体图和抗原图,并使用 GCN、GAT 和图池化提取结构表征
- 序列分支从 PDB 文件提取氨基酸序列,执行独热编码,并使用注意力、Transformer 和交叉注意力模块建立序列级及相互作用表征
- 融合输出结合结构分支和序列分支的回归输出,预测抗体与抗原结合亲和力。
模型以一个抗体 PDB 文件和一个抗原 PDB 文件为输入。
官方演示模型支持的最大序列长度如下。
- 抗体为 669 个氨基酸
- 抗原为 3102 个氨基酸。
使用场景
| 使用场景 | 说明 |
|---|---|
| 抗体与抗原结合亲和力预测 | 根据抗体和抗原的 PDB 结构预测 IC50。 |
| 候选抗体筛选 | 比较多组抗体与抗原结构对的预测亲和力趋势。 |
| 模型兼容性验证 | 在 SCNet DCU 环境中验证 PyTorch Geometric 推理(inference)和训练。 |
| P2PXML 方法复现 | 使用官方 P2PXML_Structure 数据集进行训练或评估。 |
使用指南
1. OneCode
可通过 OneCode 在线环境体验智能一键 AI4S 编程。
2. 手动安装
硬件要求
- 模型支持 CPU,以及 PyTorch 支持的、与 CUDA、ROCm 或 DTK 兼容的加速器设备
- 建议使用 GPU 或 DCU 进行推理及训练
- CPU 可用于功能验证,但构建 PDB 图及模型计算的速度明显较慢
- 模型和图特征使用
float64,因此实际显存和主机内存需求取决于抗体和抗原结构的原子数及训练批大小 - 全量数据集训练会生成图缓存和模型权重(检查点)(checkpoint),因此所需磁盘空间远超单样本推理。
下载模型包
安装 Hugging Face 命令行工具,并下载包含适配代码、预训练权重和示例数据的模型包。
python -m pip install -U huggingface_hub
hf download OneScience-Group/P2PXML --local-dir ./P2PXML
cd P2PXML
除非另有说明,以下命令均应在仓库根目录执行。
安装运行环境
DCU 环境
# Activate DTK and Conda first
conda create -n onescience311 python=3.11 -y
conda activate onescience311
pip install onescience[bio-dcu] \
-i http://mirrors.onescience.ai:3141/pypi/simple/ \
--trusted-host mirrors.onescience.ai
GPU 环境
# Activate Conda first
conda create -n onescience311 python=3.11 -y
conda activate onescience311
python -m pip install "onescience[bio-gpu]" \
-i http://mirrors.onescience.ai:3141/pypi/simple/ \
--trusted-host mirrors.onescience.ai
安装 P2PXML 所需的额外依赖。
python -m pip install -r requirements.txt
如果需要独立的 Jupyter 内核,可使用以下命令注册。
python -m ipykernel install \
--user \
--name evo_bio \
--display-name "Python (onescience311)"
权重和数据准备
Hugging Face 模型包内的主要资源如下。
| 资源 | 位置 | 用途 |
|---|---|---|
| 官方组合模型权重 | weight/model_weights.pth |
抗体与抗原结合亲和力推理 |
| 官方抗体示例 | conf/data/10-1074.pdb |
快速推理的抗体输入 |
| 官方抗原示例 | conf/data/0013095_2_11.pdb |
快速推理的抗原输入 |
| SCNet 推理 notebook | scripts/smoke/P2PXML_Demonstration_SCNet.ipynb |
使用本地权重和 PDB 进行推理 |
| 结构训练数据 | conf/P2PXML_Structure/ |
真实数据子集或全量数据集训练 |
完整官方数据集可从 Zenodo 获取。
https://zenodo.org/records/11531319
当前本地 P2PXML_structure.csv 包含以下内容。
- 8,475 条抗体与抗原记录
- 655 个抗体 PDB 结构
- 469 个抗原 PDB 结构。
基础 DCU/PyG 验证
使用以下脚本验证 PyTorch、PyTorch Geometric、GCN、GAT 及加速器执行。
python - <<'PY'
import torch
import torch_geometric
from torch_geometric.nn import GATConv, GCNConv
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
x = torch.randn(
4,
4,
dtype=torch.float64,
device=device,
)
edge_index = torch.tensor(
[[0, 1, 2, 3, 0, 2], [1, 0, 3, 2, 2, 0]],
dtype=torch.long,
device=device,
)
gcn = GCNConv(4, 8).to(device).double()
gat = GATConv(4, 8, heads=2).to(device).double()
print("torch:", torch.__version__)
print("torch_geometric:", torch_geometric.__version__)
print("device:", device)
print("GCN:", gcn(x, edge_index).shape)
print("GAT:", gat(x, edge_index).shape)
PY
快速推理
在已加载完整 DTK 动态库环境的 DCU 计算节点上运行推理 notebook。
export P2PXML_ROOT=$PWD
cd scripts/smoke
P2PXML_ROOT="$P2PXML_ROOT" \
jupyter nbconvert \
--to notebook \
--execute P2PXML_Demonstration_SCNet.ipynb \
--output P2PXML_Demonstration_SCNet_output.ipynb \
--ExecutePreprocessor.kernel_name=evo_bio \
--ExecutePreprocessor.timeout=-1
执行成功后,生成的 notebook 保存到以下位置。
scripts/smoke/P2PXML_Demonstration_SCNet_output.ipynb
以下警告
IProgress not found
仅影响 notebook 的进度条显示,推理结果不受影响。
真实数据子集训练
以下脚本
model/integrated_model_v1_dataset_smoke.py
支持通过环境变量选择训练样本数量、训练轮数、输出目录及初始化模型权重(检查点)。
以下示例使用 50 条真实结构记录训练一轮。
cd "$P2PXML_ROOT"
P2PXML_DATA_LIMIT=50 \
P2PXML_EPOCHS=1 \
P2PXML_RUN_DIR=./scripts/training_runs/n50 \
P2PXML_INIT_CHECKPOINT=./weight/model_weights.pth \
python model/integrated_model_v1_dataset_smoke.py
当前上游 Dataset 实现在图构建失败时会递归切换到下一个样本。
因此,即使个别样本处理失败,训练流程仍可完成,但部分实际使用的训练样本可能重复。
因此,此次运行仅能证明真实数据训练流程可执行。
不应视为以下结果。
- 严格的训练性能基准测试
- 完整的数据完整性验证
- 最终精度结果。
全量数据集单轮训练
如需在完整结构数据集上训练一轮,可运行以下命令。
cd "$P2PXML_ROOT"
P2PXML_DATA_LIMIT=0 \
P2PXML_EPOCHS=1 \
P2PXML_RUN_DIR=./scripts/training_runs/full_epoch1 \
P2PXML_INIT_CHECKPOINT=./weight/model_weights.pth \
python model/integrated_model_v1_dataset_smoke.py
运行全量数据集训练前,验证 CSV 中每个 Ab 和 Ag 标识符都有对应的 PDB 结构,并处理缺失或无效结构。
初次构建图时计算 PDB 原子之间的两两距离,计算复杂度接近以下值。
O(N²)
生成的图数据缓存于以下位置。
conf/P2PXML_Structure/graph_data/
因此,首次完整训练所需的运行时间和磁盘空间远高于后续训练轮次。
建议保留图缓存,并在完整训练前按以下规模逐步扩大验证。
50 samples
→ 500 samples
→ full dataset
完成上述验证后再运行完整训练。
OneScience 官方资源
| 平台 | OneScience 主仓库 | Skills 仓库 |
|---|---|---|
| Gitee | https://gitee.com/onescience-ai/onescience | https://gitee.com/onescience-ai/oneskills |
| GitHub | https://github.com/onescience-ai/OneScience | https://github.com/onescience-ai/oneskills |
引用与许可证
上游 P2PXML 源代码采用 MIT 许可证发布。
官方 P2PXML notebook 说明数据集采用 CC BY-NC-SA 4.0 许可证。使用或再分发数据集时,用户必须遵守对应的署名、非商业性使用及相同方式共享要求。
本 Hugging Face 模型包基于官方实现进行运行时适配和目录整理。论文、源代码、模型权重、数据集及其他第三方资源的原始版权状态、许可证及使用条款继续适用。
- Downloads last month
- 17