> This page is for AlphaFold2, version 2.1.0 (Latest) (default).
> For other versions, use one of these documentation indexes:
> - 2.1.0 (Latest) (default): https://docs.nvidia.com/nim/bionemo/alphafold2/2.1.0/llms.txt
> - 2.0.0: https://docs.nvidia.com/nim/bionemo/alphafold2/2.0.0/llms.txt
> - 1.2.0: https://docs.nvidia.com/nim/bionemo/alphafold2/1.2.0/llms.txt
> - 1.0.0: https://docs.nvidia.com/nim/bionemo/alphafold2/1.0.0/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nim/bionemo/llms.txt.

# Deploy the AlphaFold2 NIM

> Pull, run, monitor, and cache the AlphaFold2 NIM container, with a detailed walkthrough of the run command and its options.

This guide provides a detailed walkthrough for deploying the AlphaFold2 NIM, including viewing the available container image tags, pulling the image, running it with the recommended options, checking its status, and caching the model. For a fast first run, refer to the [Quickstart Guide](/nim/bionemo/alphafold2/get-started/quickstart-guide).

## Prerequisites

Before you start, complete the following prerequisites:

1. Install Docker, the NVIDIA Container Toolkit, and the NVIDIA drivers, and set up NGC registry access.

   Refer to [Prerequisites](/nim/bionemo/alphafold2/get-started/prerequisites).

2. Generate an NGC API key and log in to `nvcr.io`.

## Deploy the NIM

To deploy the AlphaFold2 NIM, complete the following steps:

1. View the available container image tags.

   Container image tags can be seen with the following command, similar to other container images on NGC.

   ```bash
   ngc registry image info nvcr.io/nim/deepmind/alphafold2:2.1.0
   ```
   

2. Pull the container image using Docker or the NGC SDK.

   Using Docker:

   ```bash
   docker pull nvcr.io/nim/deepmind/alphafold2:2.1.0
   ```
   

   Using the NGC SDK:

   ```bash
   ngc registry image pull nvcr.io/nim/deepmind/alphafold2:2.1.0
   ```
   

3. Set the required environment variables and run the container.

   As in the [Quickstart Guide](/nim/bionemo/alphafold2/get-started/quickstart-guide), run the following command to start the AlphaFold2 NIM.

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

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

   The command and its options are:

   - **`docker run`**: This is the command to run a new container from a Docker image.
   - **`--rm`**: This flag tells Docker to automatically remove the container when it exits. This property is useful for one-off runs or testing, as it prevents the container from being left behind.

   - **`--name alphafold2`**: This flag gives the container the name "alphafold2".
   

   - **`--runtime=nvidia`**: This flag specifies the runtime to use for the container. In this case, it is set to "nvidia", which is used for GPU acceleration.
   - **`-e NGC_API_KEY`**: This passes the `NGC_API_KEY` environment variable (and the value set in the parent terminal) to the container. This is used for authentication with NGC, including downloading the model data if it is not present in the NIM cache.
   - **`-p 8000:8000`**: This flag maps port 8000 on the host machine to port 8000 in the container. This allows you to access the container's services from the host machine.
   - **`-v <source>:<dest>`**: Mounts the host directory `~/.cache/nim` in the container as `/opt/nim/.cache` so that it can be used for storing and reusing downloaded models.

4. (Optional) Set optional runtime variables for performance tuning. `NIM_CACHE_PATH` is the cache path inside the container and matches the volume destination `/opt/nim/.cache`. `NIM_PARALLEL_THREADS_PER_MSA` is 10, the same value used in the runtime example.

   ```bash
   docker run --rm --name alphafold2 --runtime=nvidia \
       -e CUDA_VISIBLE_DEVICES=0 \
       -e NGC_API_KEY \
       -e NIM_CACHE_PATH=/opt/nim/.cache \
       -e NIM_PARALLEL_MSA_RUNNERS=3 \
       -e NIM_PARALLEL_THREADS_PER_MSA=12 \
       -p 8000:8000 \
       -v $LOCAL_NIM_CACHE:/opt/nim/.cache \
       nvcr.io/nim/deepmind/alphafold2:2.1.0
   ```
   

   - **`-e CUDA_VISIBLE_DEVICES=0`**: This flag sets an environment variable `CUDA_VISIBLE_DEVICES` to the value "0." This variable controls which GPU devices are visible to the container. In this case, it is set to 0, so the container will use only the first GPU (if available).

   - **`nvcr.io/nim/deepmind/alphafold2:2.1.0`**: This is the Docker image name and tag. The image is hosted on NVIDIA's container registry (`nvcr.io`) and is named `alphafold2`. The tag `2.1.0` specifies a specific version of the image.
   

5. Check the NIM status.

   View running Docker containers on your system by using the following command.

   ```bash
   docker ps
   ```

   This returns output that looks like the following if the NIM is running:

   ```text
   CONTAINER ID   IMAGE            COMMAND                  CREATED          STATUS          PORTS                                                                                                          NAMES
   d114948j4f55   alphafold2   "/opt/nvidia/nvidia_…"   46 minutes ago   Up 46 minutes   6006/tcp, 0.0.0.0:8000->8000/tcp, :::8000->8000/tcp, 8888/tcp, 0.0.0.0:50051->50051/tcp, :::50051->50051/tcp   test1
   ```

The first column is the Docker container ID, which you can use to interact with the container. The remaining fields describe the image the container is running, the command (in this case, the NIM server software), when the container was built, its status, how long it has been running, any open ports, and finally its name (given by the startup command). If the NIM is not running, only the header is returned.

6. (Optional) Stop a running container.

   If your container has entered a state in which you cannot interact with it, or for any reason it must be killed, use the following command with the ID obtained from the `docker ps` command. The following example uses the ID from the previous step.

   ```bash
   docker kill d114948j4f55
   ```

   This immediately terminates the running container.

   <Note>
   Any in-flight requests are canceled, and data can be lost.
   </Note>

7. (Optional) Cache the model checkpoint.

   On initial startup, the container downloads the AlphaFold2 parameters and supporting data from NGC. You can skip this download step on future runs by caching the model weights locally using a cache directory.

   ```bash
   # Create the cache directory on the host machine
   export LOCAL_NIM_CACHE=~/.cache/nim
   mkdir -p $LOCAL_NIM_CACHE
   ```

Run the container with the cache directory mounted in the appropriate location:

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

   <Note>
   Caching the model checkpoint can save a considerable amount of time on subsequent container runs.
   </Note>

## Next Steps

Now that the AlphaFold2 NIM is deployed, explore the following resources:

<CardGroup cols={3}>
  <Card title="Endpoints" href="/alphafold2/endpoints">
    Send structure and MSA prediction requests to the running NIM.
  </Card>
  <Card title="Performance" href="/alphafold2/performance">
    Benchmarks and tuning guidance for the NIM.
  </Card>
  <Card title="Configuring the NIM at Runtime" href="/alphafold2/configuring-nim-runtime">
    Runtime environment variables and configuration options.
  </Card>
</CardGroup>