高级用法#
使用 Bash 脚本运行推理#
在此示例中,我们创建一个简单的 bash
脚本,使用两个本地文件作为输入来启动推理,并将生成的姿势转储到 output
文件夹中。
在同一文件夹中创建一个新的空白文件,将其命名为
diffdock.sh
,并将以下内容复制到其中。
#!/bin/bash # Script: diffdock.sh - Run inference using local files as input # Usage: ./diffdock.sh [receptor].pdb [ligand].sdf protein_file=$1 ligand_file=$2 protein_bytes=`grep -E ^ATOM $protein_file | sed -z 's/\n/\\\n/g'` ligand_bytes=`sed -z 's/\n/\\\n/g' $ligand_file` ligand_format=`basename $ligand_file | awk -F. '{print $NF}'` echo "{ \"ligand\": \"${ligand_bytes}\", \"ligand_file_type\": \"${ligand_format}\", \"protein\": \"${protein_bytes}\", \"num_poses\": 10, \"time_divisions\": 20, \"steps\": 18, \"save_trajectory\": false, \"is_staged\": false }" > diffdock.json curl --header "Content-Type: application/json" \ --request POST \ --data @diffdock.json \ --output output.json \ http://127.0.0.1:8000/molecular-docking/diffdock/generate
使脚本可执行。
chmod +x diffdock.sh
从 RCSB 数据库下载输入文件并启动推理。
curl -o 8G43.pdb https://files.rcsb.org/download/8G43.pdb curl -o ZU6.sdf https://files.rcsb.org/ligands/download/ZU6_ideal.sdf ./diffdock.sh 8G43.pdb ZU6.sdf
使用
入门指南
中创建的 python 脚本转储输出。
python3 dump_output.py ls output
输出示例
rank01_confidence_0.57.sdf rank06_confidence_-0.25.sdf rank02_confidence_0.57.sdf rank07_confidence_-0.69.sdf rank03_confidence_0.55.sdf rank08_confidence_-1.31.sdf rank04_confidence_0.41.sdf rank09_confidence_-1.90.sdf rank05_confidence_0.38.sdf rank10_confidence_-2.07.sdf
运行批量对接推理#
DiffDock NIM 允许 批量对接 模式,如果在此请求中提交多分子 SDF 文件,则可以通过单个推理请求将一组配体分子与同一蛋白质受体对接。批量对接模式比运行单独的推理请求效率更高。以下示例说明了使用蛋白质 PDB 文件和从 RSCB 下载的五个分子 SDF 文件进行批量对接。
准备包含多个配体分子的 SDF 输入文件。创建一个新的空白文件,将其命名为
make-multiligand.sh
,并将以下内容复制到其中。
#!/bin/bash # Script: make-multiligand.sh # Usage: ./make-multiligand.sh [Ligand1_CCD_ID] [Ligand2_CCD_ID] ... # Example: ./make-multiligand.sh COM Q4H QPK R4W SIN ligand_files="" for lig in $* do ligand_file=${lig}.sdf echo "Download ligand file: ${ligand_file}" curl -o $ligand_file "https://files.rcsb.org/ligands/download/${lig}_ideal.sdf" ligand_files="${ligand_files} ${ligand_file}" done # Combine ligand files into a single SDF file cat $ligand_files > multi_ligands.sdf
运行以下命令以生成用于输入的
multi_ligands.sdf
。
chmod +x make-multiligand.sh ./make-multiligand.sh COM Q4H QPK R4W SIN
下载蛋白质 PDB 文件并启动推理。
curl -o 7RWO.pdb "https://files.rcsb.org/download/7RWO.pdb" ./diffdock.sh 7RWO.pdb multi_ligands.sdf
转储结果,以下是输出示例。
python3 dump_output.py ls output/* diffdock-output/ligand0: rank01_confidence_-0.74.sdf rank05_confidence_-1.15.sdf rank09_confidence_-1.55.sdf rank02_confidence_-0.92.sdf rank06_confidence_-1.25.sdf rank10_confidence_-1.93.sdf rank03_confidence_-0.93.sdf rank07_confidence_-1.46.sdf rank04_confidence_-1.04.sdf rank08_confidence_-1.46.sdf diffdock-output/ligand1: rank01_confidence_-0.25.sdf rank05_confidence_-0.55.sdf rank09_confidence_-0.72.sdf rank02_confidence_-0.28.sdf rank06_confidence_-0.55.sdf rank10_confidence_-0.77.sdf rank03_confidence_-0.34.sdf rank07_confidence_-0.56.sdf rank04_confidence_-0.49.sdf rank08_confidence_-0.57.sdf ...
使用 SMILES 进行批量对接#
除了配体分子的 SDF 格式外,DiffDock 还支持 SMILES 文本字符串作为输入。DiffDock 使用 RDKit 从 SMILES 信息生成随机分子构象异构体。纯文本文件可以用作配体输入,其中包含多行,每行都是代表分子的 SMILES 公式,以进行批量对接。
创建一个新的空白文件,将其命名为
ligands.txt
,并将以下内容复制到其中。
Cc1cc(F)c(NC(=O)NCCC(C)(C)C)cc1Nc1ccc2ncn(C)c(=O)c2c1F COc1cccc(NC(=O)c2ccc(C)c(Nc3nc(-c4cccnc4)nc4c3cnn4C)c2)c1 Cc1nn(C)c(C)c1CCOc1cc(F)ccc1-c1ccc2n[nH]c(CN(C)C)c2c1 Cc1c(C(=O)c2cccc3ccccc23)c2cccc3c2n1[C@H](CN1CCOCC1)CO3
运行以下命令以调用 DiffDock 模型。该脚本生成一个输入 JSON 文件,并在文件
output.json
中以 JSON 格式返回推理结果。
./diffdock.sh 8G43.pdb ligands.txt
转储结果并检查输出文件夹。
$ python3 dump_output.py $ ls output/* diffdock-output/ligand0: rank01_confidence_-0.98.sdf rank05_confidence_-1.30.sdf rank09_confidence_-1.77.sdf rank02_confidence_-1.00.sdf rank06_confidence_-1.36.sdf rank10_confidence_-2.27.sdf rank03_confidence_-1.03.sdf rank07_confidence_-1.58.sdf rank04_confidence_-1.21.sdf rank08_confidence_-1.61.sdf diffdock-output/ligand1: rank01_confidence_-0.15.sdf rank05_confidence_-1.25.sdf rank09_confidence_-1.55.sdf rank02_confidence_-0.54.sdf rank06_confidence_-1.29.sdf rank10_confidence_-1.66.sdf rank03_confidence_-0.91.sdf rank07_confidence_-1.38.sdf rank04_confidence_-1.03.sdf rank08_confidence_-1.39.sdf ...