DiffDock 工作流实战指南:从单分子对接、虚拟筛选到下游分析集成

发布时间:2026/9/10 10:13:20
DiffDock 工作流实战指南:从单分子对接、虚拟筛选到下游分析集成 DiffDock 工作流实战指南从单分子对接、虚拟筛选到下游分析集成【免费下载链接】scientific-agent-skillsTurn any AI agent into an AI Scientist. The #1 Agent Skills library for science, used by 190,000 scientists worldwide. 165 ready-to-use validated skills plus 100 scientific databases covering biology, chemistry, medicine, and drug discovery. Compatible with Cursor, Claude Code, Codex, Pi, Antigravity, and the open Agent Skills standard.项目地址: https://gitcode.com/GitHub_Trending/cl/scientific-agent-skills本篇指南系统讲解基于扩散模型的分子对接工具 DiffDock 在 scientific-agent-skills 仓库skills/diffdock中的完整实战用法涵盖 Conda/Docker 环境安装、单个蛋白-配体对接、序列到结构对接、批量对接与高通量虚拟筛选、集合对接、GNINA 重打分与 OpenMM 能量最小化等下游集成以及自定义推理配置与常见问题排查。读完本文你将能独立搭建 DiffDock 环境并用命令行完成从一条 SMILES 一个蛋白结构到上千个化合物库的虚拟筛选的完整对接流程正确解读置信度分数并规划验证路径。环境准备与首次运行DiffDock 官方推荐 Python 3.9 环境仓库提供的 setup_check.py 脚本可以在正式开工前一键核验环境它会检查 Python 版本、PyTorch 与 CUDA 可用性、PyTorch Geometric 系列包torch-geometric / torch-scatter / torch-sparse / torch-cluster、RDKit、Biopython、pytorch-lightning、PyYAML 以及 ESM 蛋白语言模型还会确认当前目录是否存在inference.py、default_inference_args.yaml、environment.yml等关键文件源码依据。# 在 DiffDock 仓库根目录执行 python scripts/setup_check.py # 查看更详细的依赖版本信息 python scripts/setup_check.py --verboseConda 安装推荐# 克隆 DiffDock 上游仓库 git clone https://github.com/gcorso/DiffDock.git cd DiffDock # 用 environment.yml 创建 conda 环境Python 3.9 conda env create --file environment.yml conda activate diffdockDocker 安装# 拉取官方镜像 docker pull rbgcsail/diffdock # 以 GPU 模式启动容器直接进入 bash docker run -it --gpus all --entrypoint /bin/bash rbgcsail/diffdock # 容器内激活环境 micromamba activate diffdock首次运行的注意事项首次执行会预计算 SO(2) 与 SO(3) 旋转查找表耗时约几分钟之后每次运行会直接复用无需等待模型检查点score model 与 confidence model约 500MB若本地缺失会在首次运行自动下载到./workdir/v1.1/目录GPU 强烈推荐使用相对 CPU 约有 10~100 倍加速若没有 GPUsetup_check.py 会给出明确的性能提示与云端 GPU 替代建议当前上游版本为 DiffDock v1.1.3默认使用 DiffDock-L 模型线default_inference_args.yaml中的默认模型目录即指向./workdir/v1.1/。Workflow 1单个蛋白-配体对接单分子对接是其余所有工作流的基础输入为蛋白PDB 文件或氨基酸序列 配体SMILES 或结构文件。使用 PDB 文件与 SMILES 字符串python -m inference \ --config default_inference_args.yaml \ --protein_path examples/protein.pdb \ --ligand_description COc1ccc(C(O)Nc2ccccc2)cc1 \ --out_dir results/single_docking/输出目录结构默认samples_per_complex10因此生成 10 个预测姿态results/single_docking/ └── complex_0/ ├── rank1.sdf # 排名第一预测的便捷副本 ├── rank1_confidence0.87.sdf # 带置信度分数的排名第一预测 ├── rank2_confidence0.42.sdf # 排名第二的预测 ├── ... └── rank10_confidence-1.23.sdf # 第 10 个预测参数拼写提醒当前上游inference.py注册的是--ligand_description旧版 README 中出现的--ligand写法已弃用除非你的本地 checkout 额外添加了别名否则应统一使用--ligand_description。使用配体结构文件python -m inference \ --config default_inference_args.yaml \ --protein_path protein.pdb \ --ligand_description ligand.sdf \ --out_dir results/ligand_file/支持的配体格式SDF、MOL2以及任何 RDKit 可读取的格式。当配体不是 SMILES 时DiffDock 会通过 RDKit 读取其 3D 构象因此若手头有合理的构象文件直接传入可提升初始构象质量。Workflow 2蛋白序列到结构对接当蛋白结构尚未解析不在 PDB 中、需要模拟突变/变异体或验证 de novo 蛋白设计时可以只提供氨基酸序列由 DiffDock 内部调用 ESMFold 先折叠出蛋白结构再执行对接。python -m inference \ --config default_inference_args.yaml \ --protein_sequence MSKGEELFTGVVPILVELDGDVNGHKFSVSGEGEGDATYGKLTLKFICTTGKLPVPWPTLVTTFSYGVQCFSRYPDHMKQHDFFKSAMPEGYVQERTIFFKDDGNYKTRAEVKFEGDTLVNRIELKGIDFKEDGNILGHKLEYNYNSHNVYIMADKQKNGIKVNFKIRHNIEDGSVQLADHYQQNTPIGDGPVLLPDNHYLSTQSALSKDPNEKRDHMVLLEFVTAAGITHGMDELYK \ --ligand_description CC(C)Cc1ccc(cc1)C(C)C(O)O \ --out_dir results/sequence_docking/典型使用场景蛋白结构在 PDB 中不可用例如新测序的蛋白建模突变体或变异体的结合行为从头蛋白设计的对接验证。注意ESMFold 折叠会增加计算时间一般约 30 秒到 5 分钟具体取决于序列长度。若对同一蛋白反复对接多个配体更高效的做法是预计算一次 ESM embedding见 Workflow 4避免每次重复折叠。Workflow 3批量处理多个复合物批量模式面向多个蛋白-配体对的对接任务是虚拟筛选的基础形态。准备批量 CSV创建complexes.csv必须包含以下四列complex_name,protein_path,ligand_description,protein_sequence complex1,proteins/protein1.pdb,CC(O)Oc1ccccc1C(O)O, complex2,,COc1ccc(C#N)cc1,MSKGEELFTGVVPILVELDGDVNGHKF... complex3,proteins/protein3.pdb,ligands/ligand3.sdf,列说明列名含义填写规则complex_name复合物的唯一标识符必填不可为空protein_path蛋白 PDB 文件路径使用序列时留空ligand_descriptionSMILES 字符串或配体文件路径必填protein_sequence氨基酸序列使用 PDB 时留空仓库提供了 batch_template.csv 模板并配套 prepare_batch_csv.py 脚本用于生成与校验# 生成带示例行的模板 python scripts/prepare_batch_csv.py --create --output batch_input.csv # 校验现有 CSV检查必需列、文件路径存在性与 SMILES 合法性 python scripts/prepare_batch_csv.py my_input.csv --validate # 用自定义基准目录解析 CSV 中的相对路径 python scripts/prepare_batch_csv.py my_input.csv --validate --base-dir /path/to/data/从源码看该校验脚本会逐行检查complex_name是否缺失、每行必须提供protein_path或protein_sequence二者其一同时提供时以protein_path为准并给出警告、蛋白/配体文件是否存在、SMILES 是否被 RDKit 合法解析源码依据。RDKit 不可用时脚本会跳过 SMILES 校验并给出提示源码依据。运行批量对接python -m inference \ --config default_inference_args.yaml \ --protein_ligand_csv complexes.csv \ --out_dir results/batch_predictions/ \ --batch_size 10输出目录结构每个复合物一个子目录子目录内同样是带置信度的 rank 文件。results/batch_predictions/ ├── complex1/ │ ├── rank1.sdf │ ├── rank1_confidence0.87.sdf │ ├── rank2_confidence0.42.sdf │ └── ... ├── complex2/ │ ├── rank1.sdf │ └── ... └── complex3/ └── ...用 analyze_results.py 分析结果对接完成后可用 analyze_results.py 解析置信度并排序# 分析全部结果 python scripts/analyze_results.py results/batch/ # 每个复合物只看前 5 个预测 python scripts/analyze_results.py results/batch/ --top 5 # 按置信度阈值过滤 python scripts/analyze_results.py results/batch/ --threshold 0.0 # 导出为 CSV 供下游分析 python scripts/analyze_results.py results/batch/ --export summary.csv # 跨所有复合物列出整体 Top 20 预测 python scripts/analyze_results.py results/batch/ --best 20该脚本从文件名如rank1_confidence0.87.sdf提取置信度兼容旧版confidence_scores.txt与 SDF 属性两种回退解析方式将置信度分类为 High0、Moderate-1.5~0、Low-1.5输出每个复合物的均值/最大/最小置信度统计并可导出 CSV源码依据。Workflow 4高通量虚拟筛选对同一蛋白靶点、海量配体库进行筛选是 DiffDock 最典型的规模化用法。准备筛选输入 CSV# generate_screening_csv.py import pandas as pd # 加载配体库含 SMILES 列 ligands pd.read_csv(ligand_library.csv) # Contains SMILES # 生成 DiffDock 输入 screening_data { complex_name: [fscreen_{i} for i in range(len(ligands))], protein_path: [target_protein.pdb] * len(ligands), ligand_description: ligands[smiles].tolist(), protein_sequence: [] * len(ligands) } df pd.DataFrame(screening_data) df.to_csv(screening_input.csv, indexFalse)预计算 ESM embedding 并运行筛选对同一蛋白做大规模筛选时务必预计算一次 ESM embedding 并复用避免每个配体重复计算蛋白表示# 预计算蛋白 ESM embedding python datasets/esm_embedding_preparation.py \ --protein_ligand_csv screening_input.csv \ --out_file protein_embeddings.pt # 使用预计算 embedding 运行对接 python -m inference \ --config default_inference_args.yaml \ --protein_ligand_csv screening_input.csv \ --esm_embeddings_path protein_embeddings.pt \ --out_dir results/virtual_screening/ \ --batch_size 32后处理提取 Top Hits# analyze_screening_results.py import pandas as pd import re from pathlib import Path results [] results_dir Path(results/virtual_screening/) for complex_dir in results_dir.iterdir(): if not complex_dir.is_dir(): continue scores [] for sdf_file in complex_dir.glob(rank*_confidence*.sdf): match re.search(rconfidence(-?\d(?:\.\d)?), sdf_file.name) if match: scores.append(float(match.group(1))) if scores: results.append({complex: complex_dir.name, top_confidence: max(scores)}) # 按置信度排序 df pd.DataFrame(results) df_sorted df.sort_values(top_confidence, ascendingFalse) # 取前 100 个命中 top_hits df_sorted.head(100) top_hits.to_csv(top_hits.csv, indexFalse)注意此处的置信度分数只代表模型对姿态正确性的把握不代表结合亲和力。筛选出的候选必须进一步用打分函数如 GNINA、MM/GBSA重打分才能作为亲和力排序依据详见 Workflow 6。Workflow 5集合对接蛋白质柔性当蛋白存在已知柔性如结合口袋随构象变化、来自分子动力学快照或多种晶体结构时可对同一配体对接多个蛋白构象形成集合对接。# create_ensemble_csv.py import pandas as pd conformations [ protein_conf1.pdb, protein_conf2.pdb, protein_conf3.pdb, protein_conf4.pdb ] ligand CC(C)Cc1ccc(cc1)C(C)C(O)O data { complex_name: [fensemble_{i} for i in range(len(conformations))], protein_path: conformations, ligand_description: [ligand] * len(conformations), protein_sequence: [] * len(conformations) } pd.DataFrame(data).to_csv(ensemble_input.csv, indexFalse)运行集合对接时建议提高每个构象的采样数python -m inference \ --config default_inference_args.yaml \ --protein_ligand_csv ensemble_input.csv \ --out_dir results/ensemble_docking/ \ --samples_per_complex 20 # 每个构象更多采样Workflow 6与下游分析集成DiffDock 输出的是结合姿态 置信度亲和力评估需要与外部打分/优化工具串联。示例DiffDock GNINA 重打分# 1. 运行 DiffDock开启可视化保存输出 SDF python -m inference \ --config default_inference_args.yaml \ --protein_path protein.pdb \ --ligand_description CC(O)OC1CCCCC1C(O)O \ --out_dir results/diffdock_poses/ \ --save_visualisation # 2. 用 GNINA 对每个姿态重打分 for pose in results/diffdock_poses/complex_0/*confidence*.sdf; do gnina -r protein.pdb -l $pose --score_only -o ${pose%.sdf}_gnina.sdf done示例DiffDock OpenMM 能量最小化# minimize_poses.py from openmm import app, LangevinIntegrator, Platform from openmm.app import ForceField, Modeller, PDBFile from rdkit import Chem from pathlib import Path # 加载蛋白 protein PDBFile(protein.pdb) forcefield ForceField(amber14-all.xml, amber14/tip3pfb.xml) # 逐个处理 DiffDock 姿态 pose_dir Path(results/diffdock_poses/complex_0) for pose_path in pose_dir.glob(*confidence*.sdf): # 加载配体 mol Chem.SDMolSupplier(str(pose_path))[0] # 合并蛋白 配体 modeller Modeller(protein.topology, protein.positions) # ... 将配体加入 modeller ... # 构建系统并做能量最小化 system forcefield.createSystem(modeller.topology) integrator LangevinIntegrator(300, 1.0, 0.002) simulation app.Simulation(modeller.topology, system, integrator) simulation.minimizeEnergy(maxIterations1000) # 保存最小化后的结构 positions simulation.context.getState(getPositionsTrue).getPositions() PDBFile.writeFile(simulation.topology, positions, open(fminimized_{pose_path.stem}.pdb, w))推荐的完整工作流DiffDock 生成姿态与置信度分数可视化检查结构合理性氢键、疏水接触、空间互补性用 GNINA 或 MM/GBSA 重打分并按亲和力排序实验验证IC50/Kd 测定、X 射线或冷冻电镜结构验证。更详细的置信度解读与工具边界可阅读仓库中的 confidence_and_limitations.md。Workflow 7图形界面启动 Web 界面python app/main.py访问界面浏览器打开http://localhost:7860。界面功能上传蛋白 PDB 文件或直接输入氨基酸序列输入配体 SMILES 或上传配体结构文件通过 GUI 调整推理参数交互式可视化结果直接下载预测结果。在线替代方案若本地环境不便搭建也可以使用官方部署在 Hugging Face Spaces 上的在线演示无需本地安装适合快速体验或小规模试算。高级配置自定义推理参数仓库提供了带完整注释与四套场景预设的配置模板 custom_inference_config.yaml复制后修改即可cp assets/custom_inference_config.yaml my_config.yaml # 编辑参数后运行 python -m inference \ --config my_config.yaml \ --protein_path protein.pdb \ --ligand_description CC(O)OC1CCCCC1C(O)O \ --out_dir results/custom_config/配置模板核心内容含默认值# 模型路径 model_dir: ./workdir/v1.1/score_model confidence_model_dir: ./workdir/v1.1/confidence_model ckpt: best_ema_inference_epoch_model.pt confidence_ckpt: best_model_epoch75.pt # 模型版本开关 old_score_model: false # 设为 true 使用原始 DiffDock 而非 DiffDock-L old_filtering_model: true # 推理步数 inference_steps: 20 # 提高如 25-30可能提升精度 actual_steps: 19 no_final_step_noise: true # 采样参数 samples_per_complex: 10 # 困难体系提高到 20-40 sigma_schedule: expbeta inf_sched_alpha: 1 inf_sched_beta: 1 initial_noise_std_proportion: 1.46 # 采样温度控制预测多样性越高越多样 temp_sampling_tr: 1.17 # 平移采样温度 temp_sampling_rot: 2.06 # 旋转采样温度 temp_sampling_tor: 7.04 # 扭转角采样温度柔性配体可提高 # Psi 角温度 temp_psi_tr: 0.73 temp_psi_rot: 0.90 temp_psi_tor: 0.59 # Sigma data 温度 temp_sigma_data_tr: 0.93 temp_sigma_data_rot: 0.75 temp_sigma_data_tor: 0.69 # 功能开关 no_model: false no_random: false no_random_pocket: false resample_rdkit: false ode: false # 设为 true 使用 ODE 求解器替代 SDE different_schedules: false limit_failures: 5 # 输出 # save_visualisation: true # 取消注释以保存 SDF 文件四套场景预设模板中内置了四套可直接启用的预设模板原文预设适用场景samples_per_complexinference_stepstemp_sampling_tor预设 1High Accuracy追求精度的慢速全面对接30256.5预设 2Fast Screening快速初筛5157.5预设 3Flexible Ligands柔性配体更多构象多样性20208.5预设 4Rigid Ligands刚性配体更聚焦的预测10206.0命令行覆盖与优先级所有 YAML 参数均可被命令行参数覆盖命令行优先于配置文件python -m inference --config default_inference_args.yaml --samples_per_complex 20完整的参数清单、默认值与取值范围见 parameters_reference.md。常见问题排查问题显存不足Out of Memory解法调低批量大小。python -m inference ... --batch_size 2问题运行缓慢解法确认推理真正跑在 GPU 上。import torch print(torch.cuda.is_available()) # 应为 True问题大配体预测质量差解法提高采样多样性特别是扭转角温度。python -m inference ... --samples_per_complex 40 --temp_sampling_tor 9.0问题蛋白链数过多解法限制链数或先隔离结合位点。python -m inference ... --chain_cutoff 4或预先处理 PDB只保留与结合相关的链。此外若所有预测置信度都很低可排查配体是否过大/异常、结合位点是否清晰、蛋白柔性是否过高此时考虑集合对接并核对蛋白结构是否缺少残基需补全或残留远端水分子。最佳实践总结从小做起先跑单个复合物验证流程再进入批量处理GPU 是刚需实际应用务必使用 GPUCPU 仅适合极少量试算多样采样每个复合物生成 10~40 个采样以获得稳健预测可视化验证用分子可视化软件检查姿态合理性再做下游分析理性看待置信度置信度只用于初步排序不是最终决策依据更不能当作亲和力迭代参数针对具体体系调节温度与步数先默认后微调预计算 embedding同一蛋白反复使用时应预计算 ESM embedding工具组合与打分函数、能量最小化工具联动完成亲和力评估记录参数为可复现性记录每次运行的配置参数实验验证关键结论尽量用实验生化实验或结构解析验证。更多进阶主题置信度分数深度解读、模型适用范围与局限、与 PDBBind/BindingMOAD 训练数据相关的能力边界可继续阅读同目录下的 confidence_and_limitations.md 与 parameters_reference.md以及技能总览 SKILL.md。【免费下载链接】scientific-agent-skillsTurn any AI agent into an AI Scientist. The #1 Agent Skills library for science, used by 190,000 scientists worldwide. 165 ready-to-use validated skills plus 100 scientific databases covering biology, chemistry, medicine, and drug discovery. Compatible with Cursor, Claude Code, Codex, Pi, Antigravity, and the open Agent Skills standard.项目地址: https://gitcode.com/GitHub_Trending/cl/scientific-agent-skills创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考