入门#
先决条件#
安装 Docker
通过运行以下命令验证您的容器运行时是否支持 NVIDIA GPU
docker run --rm --runtime=nvidia --gpus all ubuntu nvidia-smi
示例输出
+-----------------------------------------------------------------------------+ | NVIDIA-SMI 525.78.01 Driver Version: 525.78.01 CUDA Version: 12.0 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | | | | MIG M. | |===============================+======================+======================| | 0 NVIDIA GeForce ... Off | 00000000:01:00.0 Off | N/A | | 41% 30C P8 1W / 260W | 2244MiB / 11264MiB | 0% Default | | | | N/A | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| +-----------------------------------------------------------------------------+
注意
有关枚举多 GPU 系统的更多信息,请参阅 NVIDIA Container Toolkit 的GPU 枚举文档
NGC (NVIDIA GPU Cloud) 帐户#
使用您的 NGC API 密钥进行 Docker 登录,使用
docker login nvcr.io --username='$oauthtoken' --password=${NGC_CLI_API_KEY}
NGC CLI 工具#
为您的操作系统下载 NGC CLI 工具。
重要提示
使用 NGC CLI 版本
3.41.1
或更高版本。以下是在 AMD64 Linux 家庭目录中安装此版本的命令
wget --content-disposition https://api.ngc.nvidia.com/v2/resources/nvidia/ngc-apps/ngc_cli/versions/3.41.3/files/ngccli_linux.zip -O ~/ngccli_linux.zip && \ unzip ~/ngccli_linux.zip -d ~/ngc && \ chmod u+x ~/ngc/ngc-cli/ngc && \ echo "export PATH=\"\$PATH:~/ngc/ngc-cli\"" >> ~/.bash_profile && source ~/.bash_profile
在本地设置您的 NGC CLI 工具(您将需要您的 API 密钥!)
ngc config set
注意
输入 API 密钥后,您可能会看到组织和团队的多个选项。根据需要选择或按 Enter 键接受默认值。
模型特定要求#
以下是 DiffDock NIM 的特定要求。
硬件#
支持的 GPU 型号
最低 GPU 内存 (GB):16
满足上述要求后,您将使用快速入门指南来拉取 NIM 容器和模型,执行健康检查,然后运行推理。
软件#
最低驱动程序版本:535.104.05
启动 DiffDock NIM#
拉取 NIM 容器。
docker pull nvcr.io/nim/mit/diffdock:2.0.1
运行容器。
注意
环境变量
NGC_API_KEY
必须在您的本地环境中定义且有效,以确保以下命令可以继续执行。有关个人 API 密钥设置的信息,请参阅此网站。
docker run --rm -it --name diffdock-nim \ --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=0 \ --shm-size=2G \ --ulimit memlock=-1 \ --ulimit stack=67108864 \ -e NGC_API_KEY=$NGC_API_KEY \ -p 8000:8000 \ nvcr.io/nim/mit/diffdock:2.0.1
打开一个新的终端,使用以下命令检查 API 的状态,直到它返回
true
。这可能需要几分钟。
curl localhost:8000/v1/health/ready ... true
运行推理#
打开一个新的终端,保持当前终端打开并运行服务。
注意
打开一个新的终端,保持当前终端打开并运行服务。
注意
“sed” 命令用于将多行文本文件转换为单行以进行 JSON 编码。
准备 JSON 格式的 post-data。此步骤需要在最常见的 bash shell 环境中启动(Linux)。用户可以使用命令 echo $0 验证当前会话是否为 bash。如果不是,请在此步骤之前运行命令 /bin/bash。
protein_bytes=`curl https://files.rcsb.org/download/8G43.pdb | grep -E '^ATOM' | sed -z 's/\n/\\\n/g'`; \ ligand_bytes=`curl https://files.rcsb.org/ligands/download/ZU6_ideal.sdf | sed -z 's/\n/\\\n/g'`; \ echo "{ \"ligand\": \"${ligand_bytes}\", \"ligand_file_type\": \"sdf\", \"protein\": \"${protein_bytes}\", \"num_poses\": 1, \"time_divisions\": 20, \"steps\": 18, \"save_trajectory\": false, \"is_staged\": false }" > diffdock.json
运行推理并保存到 output.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
输出文件
output.json
是 JSON 格式的内容,其中包含预测的对接姿势(配体原子的坐标),结构如下
导出生成的姿势#
本节中提供了一个简单的 Python 脚本,用于将推理结果(配体的对接姿势)导出到名为
output
的文件夹中。创建一个新的空白文件,将其命名为dump_output.py
,并将以下内容复制到其中。
import json import os import shutil def dump_one(folder, ligand_positions, position_confidence): os.makedirs(folder, exist_ok=True) for i, c in enumerate(position_confidence): with open('%s/rank%02d_confidence_%0.2f.sdf' % (folder, i+1, c), 'w') as f: f.write(ligand_positions[i]) shutil.rmtree('output', ignore_errors=True) os.makedirs('output', exist_ok=True) with open('output.json') as f: data = json.load(f) if type(data['status']) == str: dump_one('output', data['ligand_positions'], data['position_confidence']) else: for i in range(len(data['status'])): dump_one('output/ligand%d' % (i+1), data['ligand_positions'][i], data['position_confidence'][i])
运行以下命令以启动 Python 脚本。
python3 dump_output.py
列出 output 文件夹中的内容。
$ ls output rank01_confidence_-0.98.sdf
停止容器#
完成端点测试后,您可以通过在新终端中运行 docker stop diffdock-nim
来关闭容器。