# Instructions for running fine-tuned AF2 models

Benjamin Orr

For "An improved model for prediction of de novo designed proteins with diverse geometries"

Authors: Benjamin Orr, Stephanie E. Crilly, Deniz Akpinaroglu, Eleanor Zhu, Michael J. Keiser, Tanja Kortemme

## Overview

Inference can be run with the fine-tuned AF2 models either by using a local installation of localcolabfold or by uploading the fine-tuned AF2 parameters to Google Drive and running colabfold on Google Colab.

The fine-tuned AF2 models are fine-tuned versions of AF2 model_2_ptm. The simplest way to run inference with a fine-tuned AF2 model is to rename the fine-tuned parameters to model_2_ptm.npz (from a name like StableStructSplit_params_model_2_ptm.npz; this is because AF2 expects parameter files with names like model_2_ptm.npz), move this renamed file to the --data_dir, and pass this --data_dir argument to colabfold. To run the fine-tuned model alone (and not models 1, 3, 4, or 5), provide the arguments --num_models 1 --model_order [2].

## Running fine-tuned AF2 using localcolabfold

1. Install [localcolabfold](https://github.com/YoshitakaMo/localcolabfold)

2. Rename the fine-tuned AF2 parameter file to model_2_ptm.npz and copy this file to subdirectory containing AF2 params (AF2 expects this subdirectory to be named "params"; Colabfold and localcolabfold install AF2 parameters into a subdirectory named "params").

```
# copy the fine-tuned AF2 parameters to params_model_2_ptm.npz
cp StableStructSplit_params_model_2_ptm.npz params_model_2_ptm.npz

# move the renamed fine-tuned AF2 parameters to the params/ directory
mv params_model_2_ptm.npz DATA_DIR/params
```

3. Run localcolabfold with the following arguments (note that --data_dir takes the path to DATA_DIR, and not DATA_DIR/params):

```
# "--model_type alphafold2_ptm" ensures that params_model_2_ptm.npz is used
# "--msa_mode single_sequence" skips the MSA and template generation steps (this is commonly used for predicting de novo protein sequences)
colabfold_batch --data_dir DATA_DIR --num_models 1 --model_order [2] --model_type alphafold2_ptm --msa_mode single_sequence input outputdir/
```

## Running fine-tuned AF2 using colabfold on Google Colab

Alternatively, inference can be run on Google Colab with [colabfold](https://colab.research.google.com/github/sokrypton/ColabFold/blob/main/AlphaFold2.ipynb), which requires uploading the fine-tuned AF2 parameters to Google Drive then mounting one's Google Drive in Google Colab.

1. Download the AF2 parameters

```
# download the AF2 params
wget https://storage.googleapis.com/alphafold/alphafold_params_2021-07-14.tar

# make a new directory for the parameters
mkdir params

# unzip the tar file contents into the new directory
tar -xf alphafold_params_2021-07-14.tar -C params
```

2. Rename the fine-tuned AF2 parameter file to model_2_ptm.npz and copy this file to subdirectory containing AF2 params.

```
# copy the fine-tuned AF2 parameters to params_model_2_ptm.npz
cp StableStructSplit_params_model_2_ptm.npz params_model_2_ptm.npz

# move the renamed fine-tuned AF2 parameters to the params/ directory
mv params_model_2_ptm.npz DATA_DIR/params
```

3. Open [colabfold](https://colab.research.google.com/github/sokrypton/ColabFold/blob/main/AlphaFold2.ipynb)

4. Upload the params/ directory (now containing the fine-tuned AF2 params) to Google Drive

5. Mount Google Drive in Google Colab. In a new code cell in ColabFold's AlphaFold2.ipynb, add the following lines:

```
# Mount Google Drive
from google.colab import drive
drive.mount('/content/drive', force_remount=True)

# In this example, drive/MyDrive/FT_AF2_params contains a subdirectory named "params"
data_dir = Path('drive/MyDrive/FT_AF2_params')
```

When this cell is run, a popup will require allowing the notebook to access Google Drive files.

6. Run inference using the "Run Prediction" cell in ColabFold's AlphaFold2.ipynb. Add the following arguments to colabfold.batch.run():

```
# run() is imported from colabfold.batch
results = run(
    num_models=1,
    model_order=[2],
    data_dir=data_dir,
    model_type="alphafold2_ptm", # ensures that params_model_2_ptm.npz is used
    msa_mode="single_sequence", # commonly used for predicting de novo protein sequences
    ... # other colabfold.batch.run() arguments
)
```