快速入门指南#

注意

本页面假设您已安装并设置 先决条件软件(Docker、NGC CLI、NGC 注册表访问)。

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

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

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

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

此命令将启动 NIM 容器并暴露端口 8000,供用户与 NIM 交互。它会将模型拉取到本地文件系统上的 $LOCAL_NIM_CACHE 缓存中。注意:此下载可能需要很长时间(在 100+Mbps 的互联网连接上需要 4-10 小时)。

  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/predict-structure-from-sequence' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{"sequence": "MNVIDIAIAMAI"}' > output.json

在 python 中

import requests
import json

url = "http://127.0.0.1:8000/protein-structure/alphafold2/predict-structure-from-sequence"  # Replace with the actual URL
sequence = "MNVIDIAIAMAI"  # Replace with the actual sequence value

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

data = {
    "sequence": sequence,
    "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/predict-structure-from-sequence' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{"sequences": "MNVIDIAIAMAI"}' | jq