快速入门指南#

注意

本指南假设您已安装并设置所有软件准备工作,包括 Docker 身份验证、NGC CLI 安装、NGC 注册表访问以及为 NIM 模型缓存创建位置。

  1. 使用以下命令拉取 NIM 容器。

docker pull nvcr.io/nim/deepmind/alphafold2-multimer:1.0.0
  1. 使用以下命令运行 NIM 容器。

export LOCAL_NIM_CACHE=~/.cache/nim
export NGC_CLI_API_KEY=<Your NGC CLI API Key>

docker run -it --rm --name alphafold2-multimer --runtime=nvidia \
    -e NGC_CLI_API_KEY \
    -v $LOCAL_NIM_CACHE:/opt/nim/.cache \
    -p 8000:8000 \
    nvcr.io/nim/deepmind/alphafold2-multimer:1.0.0

此命令将启动 NIM 容器并暴露端口 8000,供用户与 NIM 交互。它会将模型拉取到本地文件系统上的 $LOCAL_NIM_CACHE 缓存中。

注意

下载 AlphaFold2 模型可能需要很长时间,在 100+ Mbps 的互联网连接上可能需要 4-10 小时。如果在下载 AlphaFold2 模型后,docker run 命令因文件权限错误而失败,请运行以下命令:sudo chmod -R 777 $LOCAL_NIM_CACHE。之后,使用 docker run 命令重新运行 NIM。

  1. 打开一个新的终端,保持当前终端打开并运行已启动的服务。

  2. 在新终端中,等待健康检查端点返回 {"status":"ready"} 后再继续。这可能需要几分钟。您可以使用以下命令查询健康检查。

curl -X 'GET' \
    'http://127.0.0.1:8000/v1/health/ready' \
    -H 'accept: application/json'

如果您想通过 python 检查 NIM 的状态,可以使用 requests 模块(安装后通过 pip install requests

import requests

url = "http://127.0.0.1:8000/v1/health/ready"  # Replace with the actual URL

headers = {
    "content-type": "application/json"
}
try:
    response = requests.get(url, headers=headers)

    # Check if the request was successful
    if response.ok:
        print("Request succeeded:", response.json())
    else:
        print("Request failed:", response.status_code, response.text)
except Exception as E:
    print("Request failed:", E)
  1. 运行推理以获取氨基酸序列的预测蛋白质结构,使用以下命令。

curl -X 'POST' \
    'http://127.0.0.1:8000/protein-structure/alphafold2/multimer/predict-structure-from-sequences' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{"sequences": ["MNVIDIAIAMAI", "IAMNVIDIAAI"]}' > output.json

在 python 中

import requests
import json

url = "http://127.0.0.1:8000/protein-structure/alphafold2/multimer/predict-structure-from-sequences"  # Replace with the actual URL.
sequences = ["MNVIDIAIAMAI", "IAMNVIDIAAI"]  # Replace with the actual sequences you want to perform structure prediction on.

headers = {
    "content-type": "application/json"
}

data = {
    "sequences": sequences,
    "databases": ["uniref90", "small_bfd"]
}

response = requests.post(url, headers=headers, data=json.dumps(data))

# Check if the request was successful
if response.ok:
    print("Request succeeded:", response.json())
else:
    print("Request failed:", response.status_code, response.text)
  1. 查看输出。您可以使用 cat 工具将输出打印到命令行,如下所示。

cat output.json

但是,我们建议安装 jq,这是一个命令行工具,可以格式化 JSON 以提高可读性。您可以使用 jq 可视化文件中的输出(注意,您必须安装 jq;在 Linux 上可以使用 apt-get install jq 完成安装)

jq . output.json

或者您可以将输出直接管道传输到 jq,如下面的命令所示

curl -X 'POST' \
    'http://127.0.0.1:8000/protein-structure/alphafold2/multimer/predict-structure-from-sequences' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{"sequences": ["MNVIDIAIAMAI", "IAMNVIDIAAI"]}' | jq