> This page is for RFdiffusion, version 2.3.0 (Latest) (default).
> For other versions, use one of these documentation indexes:
> - 2.3.0 (Latest) (default): https://docs.nvidia.com/nim/bionemo/rfdiffusion/2.3.0/llms.txt
> - 2.2.0: https://docs.nvidia.com/nim/bionemo/rfdiffusion/2.2.0/llms.txt
> - 2.0.0: https://docs.nvidia.com/nim/bionemo/rfdiffusion/2.0.0/llms.txt
> - 1.0.0: https://docs.nvidia.com/nim/bionemo/rfdiffusion/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.

# Quickstart for RFdiffusion

> Start the RFdiffusion NIM container, check its health, and run your first protein generation request with the Python and Shell client examples.

This Quickstart Guide walks you through starting the RFdiffusion NIM container, checking its health, and running your first protein generation request.

## Prerequisites

Review the following note before you begin.

<Note>
This page assumes you have completed the [Prerequisites](/nim/bionemo/rfdiffusion/get-started/prerequisites) (NGC account, API key, NGC registry login, and client software) and installed the software listed in the [Support Matrix](/nim/bionemo/rfdiffusion/get-started/support-matrix) (Docker, NVIDIA Drivers, and the NVIDIA Container Toolkit).
</Note>

## Start NIM

Complete the following steps to start the NIM:

1. Export `NGC_API_KEY` variable.

```bash
export NGC_API_KEY=<your personal NGC key>
```

2. Set up a local cache directory.

   The NIM container automatically downloads models; providing a cache lets it reuse already downloaded models, saving time and bandwidth. Execute the following command to set up the cache directory.

```bash
export LOCAL_NIM_CACHE=~/.cache/nim
mkdir -p "$LOCAL_NIM_CACHE"
sudo chmod 0777 -R "$LOCAL_NIM_CACHE"
```

3. Run the NIM container with the following commands.

```bash
docker run -it \
    --runtime=nvidia \
    --gpus='"device=0"' \
    -p 8000:8000 \
    -e NGC_API_KEY \
    -v "$LOCAL_NIM_CACHE":/opt/nim/.cache \
    nvcr.io/nim/ipd/rfdiffusion:2
```

This command will start the NIM container and expose port 8000 for the user to interact with the NIM.

4. Open a new terminal, leaving the terminal open with the just launched service.

5. Wait until the health check endpoint returns `{"status":"ready"}` before proceeding.

   This can take a couple of minutes. In the new terminal, you can use the following command to query the health check.

```bash
curl http://localhost:8000/v1/health/ready
```

## Python Client Example

Complete the following steps to run a request with the Python client:

1. Save the following Python example to a file named `nim_client.py`.

```python
#!/usr/bin/env python3
import requests
import os
import json
from pathlib import Path

def get_reduced_pdb():
    pdb = Path("1R42.pdb")
    if not pdb.exists():
        pdb.write_text(requests.get(f"https://files.rcsb.org/download/{pdb}").text)
    lines = filter(lambda line: line.startswith("ATOM"), pdb.read_text().split("\n"))
    return "\n".join(list(lines)[:400])

r = requests.post(
    url="http://localhost:8000/biology/ipd/rfdiffusion/generate",
    json={
        "input_pdb": get_reduced_pdb(),
        "contigs": "A20-60/0 50-100",
        "hotspot_res": ["A50","A51","A52","A53","A54"],
        "diffusion_steps": 15,
    },
)
print(r, "Saving to output.pdb:\n", r.text[:200], "...")
Path("output.pdb").write_text(json.loads(r.text)["output_pdb"])
```

2. Execute the example.

```bash
chmod +x nim_client.py

./nim_client.py
```

3. The example saves results to the `output.pdb` file in PDB format. You can view the file using the following command.

```bash
less output.pdb
```

## Shell Client Example

Complete the following steps to run a request with the Shell client:

1. Save the following Shell example to a file named `nim_client.sh`.

```bash
#!/usr/bin/env bash
set -e

URL=http://localhost:8000/biology/ipd/rfdiffusion/generate

if [ ! -e 1R42.pdb ]; then curl -O https://files.rcsb.org/download/1R42.pdb; fi

pdb=$(cat 1R42.pdb | grep ^ATOM | head -n 400 | awk '{printf "%s\\n", $0}')

request='{
 "input_pdb": "'"$pdb"'",
 "contigs": "A20-60/0 50-100",
 "hotspot_res": ["A50","A51","A52","A53","A54"],
 "diffusion_steps": 15
}'
curl -H 'Content-Type: application/json' \
     -d "$request" "$URL"
```

2. Execute the example.

   The example displays the results to the terminal in JSON format.

```bash
chmod +x nim_client.sh

./nim_client.sh
```

## Stop the Container

When you are done, press `Ctrl+C` in the terminal running the container, or run `docker stop` with the container ID shown by `docker ps`. Because the command does not use `--rm`, the stopped container remains; remove it with `docker rm` and the container ID shown by `docker ps -a`.

## Next Steps

Now that you have a working setup, explore the following resources in greater detail:

<CardGroup cols={2}>
  <Card title="Endpoints" href="/rfdiffusion/endpoints">
    The RFdiffusion NIM API endpoints and parameters.
  </Card>
  <Card title="Advanced Usage" href="/rfdiffusion/advanced-usage">
    Configure logging levels and NIM telemetry.
  </Card>
  <Card title="Benchmarking" href="/rfdiffusion/benchmarking">
    Measure accuracy and performance locally.
  </Card>
</CardGroup>