# Alphafold

> Skill for protein structure prediction and analysis with AlphaFold. Use this skill whenever a user wants to predict or fetch a protein 3D structure, download structures from the AlphaFold Database (AFDB), run ColabFold for novel proteins, parse pLDDT confidence scores or PAE (predicted aligned error) from AlphaFold outputs, predict structures of protein complexes or multimers, or work with AlphaF…

- **Type:** Skill
- **Install:** `agentstack add skill-naity-fm4life-alphafold`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [naity](https://agentstack.voostack.com/s/naity)
- **Installs:** 0
- **Category:** [Databases](https://agentstack.voostack.com/c/databases)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [naity](https://github.com/naity)
- **Source:** https://github.com/naity/FM4Life/tree/main/skills/alphafold

## Install

```sh
agentstack add skill-naity-fm4life-alphafold
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# AlphaFold: Protein Structure Prediction

## Overview

AlphaFold is DeepMind's protein structure prediction system. **Most users don't need to install AlphaFold locally** — there are faster, lighter alternatives that cover the majority of use cases:

| Need | Best approach |
|---|---|
| Known UniProt protein | **AFDB API** — fetch precomputed structure instantly |
| Novel protein sequence | **ColabFold** — no local databases needed |
| Novel protein, batch/HPC | **Local AF2 (Docker)** — full pipeline |
| Protein + DNA/RNA/ligand | **AlphaFold3** (web server or local) |
| Fast, no MSA | **ESMFold** (see `skills/esm2`) |

## Approach 1: AlphaFold Database (AFDB) API

The AFDB covers **>200 million proteins** from UniRef90 with precomputed structures. If your protein has a UniProt accession, fetch it in seconds — no GPU, no installation.

```python
import requests

def fetch_afdb_structure(uniprot_id: str, output_dir: str = ".") -> dict:
    """
    Fetch AlphaFold structure for a UniProt ID.
    Returns metadata dict with paths to downloaded files.
    """
    from pathlib import Path

    # Get prediction metadata
    url = f"https://alphafold.ebi.ac.uk/api/prediction/{uniprot_id}"
    response = requests.get(url)
    response.raise_for_status()
    prediction = response.json()[0]  # list with one entry

    out_dir = Path(output_dir)
    out_dir.mkdir(parents=True, exist_ok=True)
    downloaded = {}

    # Download PDB
    pdb_url = prediction["pdbUrl"]
    pdb_path = out_dir / f"{uniprot_id}.pdb"
    pdb_path.write_bytes(requests.get(pdb_url).content)
    downloaded["pdb"] = str(pdb_path)

    # Download PAE JSON (pairwise confidence)
    if pae_url := prediction.get("paeDocUrl"):
        pae_path = out_dir / f"{uniprot_id}_pae.json"
        pae_path.write_bytes(requests.get(pae_url).content)
        downloaded["pae"] = str(pae_path)

    print(f"Downloaded {uniprot_id}: {pdb_path}")
    print(f"  pLDDT (mean): {prediction.get('globalMetricValue', 'N/A'):.1f}")
    print(f"  Model: {prediction.get('modelCreatedDate', 'N/A')}")
    return downloaded

# Example
files = fetch_afdb_structure("P00533")  # EGFR
```

See `scripts/fetch_afdb.py` for a CLI to batch-fetch many proteins.

### Find a UniProt ID by gene/protein name

```python
def find_uniprot_id(query: str, organism: str = "human") -> list[dict]:
    """Search UniProt by gene name or protein name."""
    url = "https://rest.uniprot.org/uniprotkb/search"
    params = {
        "query": f"{query} AND organism_name:{organism}",
        "format": "json",
        "fields": "accession,protein_name,gene_names,length",
        "size": 5,
    }
    r = requests.get(url, params=params)
    r.raise_for_status()
    results = r.json()["results"]
    return [
        {
            "uniprot_id": e["primaryAccession"],
            "name": e.get("proteinDescription", {}).get("recommendedName", {}).get("fullName", {}).get("value", ""),
            "gene": e.get("genes", [{}])[0].get("geneName", {}).get("value", ""),
            "length": e.get("sequence", {}).get("length", 0),
        }
        for e in results
    ]

hits = find_uniprot_id("EGFR", organism="human")
for h in hits:
    print(h)
```

## Approach 2: ColabFold (Novel Proteins)

ColabFold uses MMseqs2 for fast MSA generation (no local databases needed) and runs AlphaFold2 on top. It's the practical choice for novel proteins not in the AFDB.

### Installation

```bash
pip install colabfold[alphafold-without-jax]
# Then install JAX with GPU support:
pip install "jax[cuda12]" -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html
```

Or use LocalColabFold for a fully self-contained install:
```bash
# See: https://github.com/YoshitakaMo/localcolabfold
```

### Running ColabFold

```bash
# Single sequence / batch
colabfold_batch input.fasta output_dir/

# With templates (more accurate, slower)
colabfold_batch input.fasta output_dir/ --templates

# Multimer (protein complex)
colabfold_batch complex.fasta output_dir/ --model-type alphafold2_multimer_v3

# Fewer recycles for speed (default 3)
colabfold_batch input.fasta output_dir/ --num-recycle 1
```

Input FASTA for a monomer:
```fasta
>protein_name
MKTAYIAKQRQISFVKSHFSRQLEERLGLIEVQAPILSRVGD...
```

Input FASTA for a complex (chain break with `:` in sequence or multiple entries):
```fasta
>chainA
MKTAYIAKQRQISFVK
>chainB
AGLIVHSPQWFYK
```

ColabFold outputs the same file format as AlphaFold2 (see Output Formats below).

## Approach 3: Local AlphaFold2 (Docker)

Only needed when running at scale, on an HPC, or when reproducibility with official AF2 matters. Requires:
- Linux (macOS/Windows not supported)
- NVIDIA GPU (A100 recommended)
- ~2.62 TB disk for databases (SSD preferred)

```bash
# Clone and build
git clone https://github.com/google-deepmind/alphafold.git && cd alphafold
docker build -f docker/Dockerfile -t alphafold .

# Download databases (~556 GB download, ~2.62 TB unzipped)
scripts/download_all_data.sh /data/alphafold

# Run a monomer
python3 docker/run_docker.py \
  --fasta_paths=protein.fasta \
  --max_template_date=2022-01-01 \
  --model_preset=monomer \
  --data_dir=/data/alphafold \
  --output_dir=/results/

# Run a multimer (protein complex)
python3 docker/run_docker.py \
  --fasta_paths=complex.fasta \
  --model_preset=multimer \
  --data_dir=/data/alphafold \
  --output_dir=/results/
```

**Model presets:**
- `monomer` — single chain, CASP14 model (recommended default)
- `monomer_ptm` — adds pTM and PAE outputs
- `multimer` — protein complexes (runs 25 predictions: 5 models × 5 seeds)

**Database presets:**
- `full_dbs` — full accuracy (default)
- `reduced_dbs` — faster, needs only ~600 GB, still good quality

## AlphaFold3

AlphaFold3 handles **proteins, DNA, RNA, small molecules, and ions** in a single unified model. Released May 2024.

- **Web server:** https://alphafoldserver.com (free, 20 jobs/day limit)
- **Local install:** https://github.com/google-deepmind/alphafold3 (requires application for model weights)
- License: non-commercial for local use; commercial requires agreement with Google DeepMind

AF3 is the right choice when your system contains **ligands, nucleic acids, or post-translational modifications**.

## Output Formats

All AlphaFold variants produce the same core outputs:

```
output_dir/
├── ranked_0.pdb          ← best structure (highest mean pLDDT)
├── ranked_1.pdb          ← second best, etc.
├── relaxed_model_1.pdb   ← after Amber energy minimization
├── unrelaxed_model_1.pdb ← raw model output
├── result_model_1.pkl    ← raw numpy arrays (pLDDT, PAE, distogram)
├── ranking_debug.json    ← pLDDT scores for each model
└── timings.json
```

**pLDDT** (0–100) is stored in the B-factor column of PDB files. **Higher = more confident.** Thresholds:
- 90–100: very high confidence (dark blue in AF2 coloring)
- 70–90: confident (light blue)
- 50–70: low confidence (yellow)
- < 50: very low confidence, likely disordered (orange/red)

See `references/outputs.md` for parsing pLDDT and PAE programmatically.

## Scripts

```bash
# Fetch one or many proteins from AFDB by UniProt ID
python scripts/fetch_afdb.py P00533 P38398 Q9Y6K9 --output-dir structures/

# Fetch from a text file of UniProt IDs (one per line)
python scripts/fetch_afdb.py --from-file uniprot_ids.txt --output-dir structures/
```

## Choosing Between AlphaFold and ESMFold

| | AlphaFold2 (via AFDB/ColabFold) | ESMFold |
|---|---|---|
| Accuracy | Higher (uses MSA) | Lower but still good |
| Speed | Slower (MSA generation) | Seconds per protein |
| Dependencies | MMseqs2 (ColabFold) or AFDB | HuggingFace transformers |
| Precomputed DB | Yes (AFDB) | No |
| Ligand/DNA/RNA | No (AF3 only) | No |

Use **ESMFold** when you need fast, large-scale folding with no MSA. Use **AlphaFold** when accuracy matters or the structure is in the AFDB.

## Resources

- **AFDB:** https://alphafold.ebi.ac.uk
- **ColabFold:** https://github.com/sokrypton/ColabFold
- **AlphaFold3 server:** https://alphafoldserver.com
- **AF2 paper:** Jumper et al., Nature 2021 — https://doi.org/10.1038/s41586-021-03819-2
- **AF3 paper:** Abramson et al., Nature 2024 — https://doi.org/10.1038/s41586-024-07487-w
- **Multimer paper:** Evans et al., 2021 — https://doi.org/10.1101/2021.10.04.463034

## References

- `references/outputs.md` — parsing pLDDT, PAE, distogram from PDB and pickle outputs; confidence interpretation
- `references/colabfold.md` — ColabFold installation options, MSA customization, advanced run options

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [naity](https://github.com/naity)
- **Source:** [naity/FM4Life](https://github.com/naity/FM4Life)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** yes
- **Filesystem access:** yes
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-naity-fm4life-alphafold
- Seller: https://agentstack.voostack.com/s/naity
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
