> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-de/wissenschaft-and-forschung/esmfold.md).

# ESMFold-Proteinstruktur

**Ultraschnelle Vorhersage von Proteinstrukturen durch Meta AI** — sagt 3D-Proteinstrukturen aus Aminosäuresequenzen in Sekunden voraus, ohne multiple Sequenzalignments.

> 🧬 Entwickelt von **Meta AI Research** | MIT-Lizenz | 10x–60x schneller als AlphaFold2

***

## Was ist ESMFold?

ESMFold ist Metas KI-gestütztes System zur Vorhersage von Proteinstrukturen, das **Evolutionary Scale Modeling (ESM-2)** — das weltweit größte Protein-Sprachmodell (15 Milliarden Parameter) — nutzt, um 3D-Proteinstrukturen direkt aus Aminosäuresequenzen vorherzusagen.

### Wichtige Vorteile gegenüber AlphaFold2

| Funktion                            | ESMFold          | AlphaFold2          |
| ----------------------------------- | ---------------- | ------------------- |
| MSA erforderlich                    | ❌ Nein           | ✅ Ja                |
| Geschwindigkeit (typisches Protein) | **\~2 Sekunden** | \~10 Min.–Stunden   |
| Genauigkeit (TM-Score)              | \~0.87           | \~0.92              |
| GPU-VRAM (650 aa)                   | \~8 GB           | \~8 GB              |
| Eingabe einer einzelnen Sequenz     | ✅ Ja             | Begrenzt            |
| Verwaiste Proteine                  | ✅ Ausgezeichnet  | Hat Schwierigkeiten |

### Warum keine MSA?

AlphaFold2 erfordert **Multiple Sequence Alignment (MSA)** — das Sammeln und Ausrichten evolutionärer Verwandter des abgefragten Proteins. Das ist rechnerisch teuer und für neuartige oder konstruierte Proteine ohne evolutionäre Verwandte unmöglich.

ESMFold speichert evolutionäre Informationen **in seinen Sprachmodell-Gewichten** (trainiert auf 250 Millionen Proteinsequenzen) und eliminiert MSA vollständig. Das macht es:

* **Schneller:** Keine MSA-Suche (spart Minuten pro Vorhersage)
* **Besser skalierbar:** Gesamte Proteome effizient verarbeiten
* **Besser für neuartige Proteine:** Konstruierte Sequenzen haben keine evolutionären Verwandten

***

## Schnellstart auf Clore.ai

### Schritt 1: Einen Server auswählen

Auf [clore.ai](https://clore.ai) Marktplatz:

* **Mindestanforderung:** NVIDIA-GPU mit **16 GB VRAM** (das ESM-2-Sprachmodell ist groß)
* **Empfohlen:** A100 40GB, RTX 3090, RTX 4090 für das vollständige Modell
* **Kleinere Option:** Verwende `esm2_t33_650M_UR50D` für 8GB VRAM

GPU-VRAM-Leitfaden:

| Proteinlänge   | Modellvariante  | Erforderlicher VRAM |
| -------------- | --------------- | ------------------- |
| Bis zu 300 aa  | ESMFold (3B)    | \~16GB              |
| Bis zu 500 aa  | ESMFold (3B)    | \~20GB              |
| Bis zu 1000 aa | ESMFold (3B)    | \~40GB              |
| Bis zu 600 aa  | ESMFold (Chunk) | \~8 GB              |

### Schritt 2: Benutzerdefiniertes Docker-Image erstellen

```dockerfile
FROM pytorch/pytorch:2.11.0-cuda12.8-cudnn9-devel

# Systemabhängigkeiten
RUN apt-get update && apt-get install -y \
    git \
    wget \
    curl \
    openssh-server \
    libhdf5-dev \
    pkg-config \
    && rm -rf /var/lib/apt/lists/*

# SSH konfigurieren
RUN mkdir /var/run/sshd && \
    echo 'root:esmfold' | chpasswd && \
    sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

# ESMFold und Abhängigkeiten installieren
RUN pip install --no-cache-dir \
    fair-esm[esmfold] \
    torch \
    biopython \
    biotite \
    fastapi \
    uvicorn \
    pydantic \
    openmm==8.0.0 \
    pdbfixer

# OpenFold installieren (für ESMFold erforderlich)
RUN pip install "git+https://github.com/aqlaboratory/openfold.git@4b41059694619831a7db195b7e0988fc4ff3a307"

EXPOSE 22

CMD ["/usr/sbin/sshd", "-D"]
```

### Schritt 3: Auf Clore.ai bereitstellen

* **Docker-Image:** `yourname/esmfold:latest`
* **Ports:** `22` (SSH)
* **Umgebung:** `NVIDIA_VISIBLE_DEVICES=all`

***

## Installation & Einrichtung

### Methode 1: pip install

```bash
# ESMFold installieren
pip install fair-esm[esmfold]

# OpenFold installieren (erforderliche Abhängigkeit)
pip install "git+https://github.com/aqlaboratory/openfold.git@4b41059694619831a7db195b7e0988fc4ff3a307"

# Optional, aber empfohlen
pip install biotite biopython
```

### Methode 2: Aus dem Quellcode

```bash
git clone https://github.com/facebookresearch/esm.git
cd esm
pip install -e ".[esmfold]"
```

### Installation überprüfen

```python
import esm
print("ESM-Version:", esm.__version__)

# Schneller Modell-Ladetest
model = esm.pretrained.esmfold_v1()
print("ESMFold erfolgreich geladen!")
```

***

## Grundlegende Verwendung

### Eine einzelne Proteinstruktur vorhersagen

```python
import torch
import esm

# ESMFold-Modell laden
model = esm.pretrained.esmfold_v1()
model = model.eval().cuda()

# Optional: Chunk-Größe aktivieren, um VRAM zu sparen
# Erhöht die Rechenzeit, reduziert aber die VRAM-Nutzung
model.set_chunk_size(64)  # Für weniger VRAM reduzieren

# Proteinsequenz (Beispiel: Lysozym C)
sequence = "KVFGRCELAAAMKRHGLDNYRGYSLGNWVCAAKFESNFNTQATNRNTDGSTDYGILQINSRWWCNDGRTPGSRNLCNIPCSALLSSDITASVNCAKKIVSDGNGMNAWVAWRNRCKGTDVQAWIRGCRL"

# Struktur vorhersagen
with torch.no_grad():
    output = model.infer_pdb(sequence)

# PDB-Datei speichern
with open("lysozyme.pdb", "w") as f:
    f.write(output)

print(f"Struktur vorhergesagt! Gespeichert in lysozyme.pdb")
print(f"Sequenzlänge: {len(sequence)} Aminosäuren")
```

### Mehrere Sequenzen vorhersagen (Batch)

```python
import torch
import esm

model = esm.pretrained.esmfold_v1()
model = model.eval().cuda()

sequences = {
    "protein_A": "MKTAYIAKQRQISFVKSHFSRQ...",
    "protein_B": "MGDVEKGKKIFVQKCAQCHTVEK...",
    "ubiquitin": "MQIFVKTLTGKTITLEVEPSDTIENVKAKIQDKEGIPPDQQRLIFAGKQLEDGRTLSDYNIQKESTLHLVLRLRGG",
}

for name, seq in sequences.items():
    with torch.no_grad():
        output = model.infer(seq)
    
    with open(f"{name}.pdb", "w") as f:
        f.write(output)
    
    print(f"{name} vorhergesagt: {len(seq)} aa")

print("Alle Vorhersagen abgeschlossen!")
```

### Konfidenz pro Residuum abrufen (pLDDT)

```python
import torch
import esm
import numpy as np

model = esm.pretrained.esmfold_v1()
model = model.eval().cuda()

sequence = "MQIFVKTLTGKTITLEVEPSDTIENVKAKIQDKEGIPPDQQRLIFAGKQLEDGRTLSDYNIQKESTLHLVLRLRGG"

with torch.no_grad():
    output = model.infer(sequence)

# pLDDT-Werte extrahieren (Konfidenz pro Residuum)
plddt = output["plddt"].cpu().numpy()  # Form: [1, seq_len]
plddt_per_residue = plddt[0]

print(f"Mittleres pLDDT: {plddt_per_residue.mean():.2f}")
print(f"Residuen mit hoher Konfidenz (>90): {(plddt_per_residue > 90).sum()}")
print(f"Residuen mit niedriger Konfidenz (<50): {(plddt_per_residue < 50).sum()}")

# Konfidenzbereiche klassifizieren
for i, score in enumerate(plddt_per_residue):
    if score >= 90:
        confidence = "Sehr hoch (blau)"
    elif score >= 70:
        confidence = "Sicher (hellblau)"
    elif score >= 50:
        confidence = "Niedrig (gelb)"
    else:
        confidence = "Sehr niedrig (orange)"
    # print(f"Residuum {i+1}: {score:.1f} - {confidence}")  # Für vollständige Ausgabe auskommentieren
```

***

## REST-API-Server

Eine produktionsreife API für ESMFold erstellen:

```python
# api_server.py
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
import torch
import esm
import time
from typing import Optional

app = FastAPI(
    title="ESMFold-API zur Vorhersage von Proteinstrukturen",
    description="3D-Proteinstrukturen aus Aminosäuresequenzen vorhersagen",
    version="1.0.0"
)

# Modell beim Start laden
print("ESMFold-Modell wird geladen (das dauert ~30 Sekunden)...")
model = esm.pretrained.esmfold_v1()
model = model.eval().cuda()
model.set_chunk_size(64)  # Speicheroptimierung
print("ESMFold bereit!")

class PredictionRequest(BaseModel):
    sequence: str
    name: Optional[str] = "protein"

class PredictionResponse(BaseModel):
    name: str
    sequence_length: int
    pdb_content: str
    mean_plddt: float
    inference_time_seconds: float

@app.post("/predict", response_model=PredictionResponse)
async def predict_structure(request: PredictionRequest):
    """3D-Proteinstruktur aus einer Aminosäuresequenz vorhersagen."""
    
    # Sequenz validieren
    valid_aa = set("ACDEFGHIKLMNPQRSTVWY")
    sequence = request.sequence.upper().strip()
    
    invalid = set(sequence) - valid_aa
    if invalid:
        raise HTTPException(
            status_code=400,
            detail=f"Ungültige Aminosäuren in der Sequenz: {invalid}. Verwenden Sie die standardmäßigen 20 Aminosäuren."
        )
    
    if len(sequence) > 2000:
        raise HTTPException(
            status_code=400,
            detail="Sequenz zu lang (max. 2000 Aminosäuren). Für längere Sequenzen verwenden Sie die chunk-basierte Vorhersage."
        )
    
    start_time = time.time()
    
    try:
        with torch.no_grad():
            output = model.infer(sequence)
            pdb_content = model.output_to_pdb(output)[0]
            
        plddt = output["plddt"].cpu().numpy()[0]
        mean_plddt = float(plddt.mean())
        
    except torch.cuda.OutOfMemoryError:
        torch.cuda.empty_cache()
        raise HTTPException(
            status_code=507,
            detail="GPU-Speicher erschöpft. Versuchen Sie eine kürzere Sequenz oder reduzieren Sie die Chunk-Größe."
        )
    
    inference_time = time.time() - start_time
    
    return PredictionResponse(
        name=request.name,
        sequence_length=len(sequence),
        pdb_content=pdb_content,
        mean_plddt=mean_plddt,
        inference_time_seconds=round(inference_time, 2)
    )

@app.get("/health")
def health():
    gpu_mem = torch.cuda.memory_allocated() / 1024**3 if torch.cuda.is_available() else 0
    return {
        "status": "ok",
        "model": "ESMFold v1",
        "device": str(next(model.parameters()).device),
        "gpu_memory_gb": round(gpu_mem, 2)
    }

@app.get("/")
def root():
    return {"message": "ESMFold-API — /predict zum Vorhersagen von Strukturen, /docs für die Swagger-UI"}
```

```bash
# Die API ausführen
pip install fastapi uvicorn
uvicorn api_server:app --host 0.0.0.0 --port 8080 --workers 1
```

***

## API-Verwendungsbeispiele

```bash
# Struktur über die API vorhersagen
curl -X POST http://localhost:8080/predict \
  -H "Content-Type: application/json" \\
  -d '{
    "name": "ubiquitin",
    "sequence": "MQIFVKTLTGKTITLEVEPSDTIENVKAKIQDKEGIPPDQQRLIFAGKQLEDGRTLSDYNIQKESTLHLVLRLRGG"
  }' | python3 -c "
import sys, json
data = json.load(sys.stdin)
print(f\"Name: {data['name']}\")
print(f\"Länge: {data['sequence_length']} aa\")
print(f\"Mittleres pLDDT: {data['mean_plddt']:.1f}\")
print(f\"Zeit: {data['inference_time_seconds']}s\")
# PDB speichern
open('ubiquitin.pdb', 'w').write(data['pdb_content'])
print('PDB gespeichert!')
"
```

***

## Skript für Batch-Verarbeitung

```python
# batch_predict.py
import torch
import esm
import os
from pathlib import Path
from Bio import SeqIO  # pip install biopython

def predict_fasta(fasta_file: str, output_dir: str, chunk_size: int = 64):
    """Strukturen für alle Sequenzen in einer FASTA-Datei vorhersagen."""
    
    Path(output_dir).mkdir(parents=True, exist_ok=True)
    
    # Modell laden
    model = esm.pretrained.esmfold_v1()
    model = model.eval().cuda()
    model.set_chunk_size(chunk_size)
    
    # FASTA einlesen
    sequences = list(SeqIO.parse(fasta_file, "fasta"))
    print(f"Es werden Strukturen für {len(sequences)} Proteine vorhergesagt...")
    
    results = []
    for i, record in enumerate(sequences):
        seq = str(record.seq).upper()
        name = record.id
        
        print(f"[{i+1}/{len(sequences)}] {name} wird vorhergesagt ({len(seq)} aa)...")
        
        try:
            with torch.no_grad():
                output = model.infer(seq)
                pdb = model.output_to_pdb(output)[0]
            
            plddt = output["plddt"].cpu().numpy()[0].mean()
            
            # PDB speichern
            output_path = os.path.join(output_dir, f"{name}.pdb")
            with open(output_path, "w") as f:
                f.write(pdb)
            
            results.append({
                "name": name,
                "length": len(seq),
                "mean_plddt": round(float(plddt), 2),
                "output": output_path,
                "status": "success"
            })
            
        except Exception as e:
            print(f"  Fehler: {e}")
            results.append({"name": name, "status": f"error: {e}"})
    
    # Zusammenfassung schreiben
    import csv
    with open(os.path.join(output_dir, "summary.csv"), "w") as f:
        writer = csv.DictWriter(f, fieldnames=["name", "length", "mean_plddt", "output", "status"])
        writer.writeheader()
        writer.writerows(results)
    
    success = sum(1 for r in results if r.get("status") == "success")
    print(f"\nFertig! {success}/{len(sequences)} Strukturen erfolgreich vorhergesagt")
    print(f"Ergebnisse gespeichert in {output_dir}/")

if __name__ == "__main__":
    predict_fasta(
        fasta_file="./proteins.fasta",
        output_dir="./predicted_structures",
        chunk_size=64
    )
```

***

## Strukturen visualisieren

### Mit Py3Dmol (Jupyter / Python)

```python
import py3Dmol  # pip install py3Dmol

with open("protein.pdb") as f:
    pdb_data = f.read()

view = py3Dmol.view(width=800, height=600)
view.addModel(pdb_data, "pdb")
view.setStyle({"cartoon": {"colorscheme": "ssJmol"}})
view.zoomTo()
view.show()
```

### Mit PyMOL

```bash
# PyMOL installieren
apt-get install pymol

# Struktur öffnen
pymol lysozyme.pdb
```

### Programmgesteuerte Visualisierung mit Biotite

```python
import biotite.structure.io.pdb as pdb
import biotite.structure as struc
import numpy as np

# Vorhergesagte Struktur laden
pdb_file = pdb.PDBFile.read("lysozyme.pdb")
structure = pdb.get_structure(pdb_file, model=1)

# Sekundärstruktur analysieren
sse = struc.annotate_sse(structure)

helix_frac = (sse == 'a').mean() * 100
sheet_frac = (sse == 'b').mean() * 100
coil_frac = (sse == 'c').mean() * 100

print(f"Sekundärstrukturzusammensetzung:")
print(f"  Alpha-Helix:  {helix_frac:.1f}%")
print(f"  Beta-Faltblatt:   {sheet_frac:.1f}%")
print(f"  Coil/Sonstiges:   {coil_frac:.1f}%")
```

***

## Speicheroptimierung

### Anleitung zur Chunk-Größe

```python
# Niedrigerer chunk_size = weniger VRAM, langsamere Vorhersage
# Höherer chunk_size = mehr VRAM, schnellere Vorhersage

# Für 8GB VRAM (ermöglicht bis zu ~400 aa)
model.set_chunk_size(32)

# Für 16GB VRAM (bis zu ~700 aa)
model.set_chunk_size(64)

# Für 40GB VRAM (bis zu ~2000 aa, ohne Chunking)
model.set_chunk_size(None)  # Chunking deaktivieren
```

### CPU-Auslagerung für sehr lange Sequenzen

```python
# Modell auf der CPU laden, bei jeder Inferenz auf die GPU verschieben
model = esm.pretrained.esmfold_v1()
model = model.eval()

# Zur Inferenz auf die GPU verschieben, danach zurück auf die CPU
model = model.cuda()
with torch.no_grad():
    output = model.infer(sequence)
model = model.cpu()  # GPU-Speicher freigeben
torch.cuda.empty_cache()
```

***

## Fehlerbehebung

### CUDA Out of Memory

```bash
# Chunk-Größe reduzieren
model.set_chunk_size(32)  # oder sogar 16

# Freien VRAM prüfen
nvidia-smi --query-gpu=memory.free --format=csv,noheader

# Für sehr lange Proteine in Domänen aufteilen
# In der Regel können Proteine > 1000 aa sicher in Domänen von 300–500 aa aufgeteilt werden
```

### ImportError für openfold

```bash
# Mit bestimmtem Commit neu installieren
pip install "git+https://github.com/aqlaboratory/openfold.git@4b41059694619831a7db195b7e0988fc4ff3a307"

# Installation prüfen
python -c "import openfold; print('OpenFold OK')"
```

### Langsames Laden des Modells

```bash
# Beim ersten Laden werden 2,7 GB Modellgewichte heruntergeladen — das ist normal
# Nachfolgende Ladevorgänge verwenden zwischengespeicherte Gewichte (Ladezeit ~30 s)

# Cache-Speicherort prüfen
python -c "import torch; print(torch.hub.get_dir())"
ls ~/.cache/torch/hub/
```

{% hint style="warning" %}
**Hinweis zum Speicher:** ESMFolds Sprachmodell (ESM-2 mit 15 Mrd. Parametern) benötigt erheblichen VRAM. Für GPU-Server mit weniger als 16 GB VRAM verwenden Sie die `esm2_t33_650M_UR50D` Backbone-Variante oder aktivieren Sie aggressives Chunking.
{% endhint %}

{% hint style="info" %}
**pLDDT-Interpretation:**

* **>90** = Sehr hohe Konfidenz (blau in der AlphaFold-Farbgebung)
* **70–90** = Konfident (cyan/hellblau)
* **50–70** = Geringe Konfidenz (gelb) — mit Vorsicht behandeln
* **<50** = Sehr geringe Konfidenz (orange/rot) — vermutlich ungeordnete Region
  {% endhint %}

***

## GPU-Empfehlungen für Clore.ai

Der VRAM-Bedarf von ESMFold wird vom Sprachmodell ESM-2 mit 15 Mrd. Parametern dominiert. Die Sequenzlänge verursacht zusätzlichen Speicher-Overhead.

| GPU       | VRAM  | Clore.ai-Preis                            | Maximale Sequenzlänge      | Vorhersagezeit (300 AS) |
| --------- | ----- | ----------------------------------------- | -------------------------- | ----------------------- |
| RTX 3090  | 24 GB | ca. 0,07–0,21 $/h                         | \~400 AS (mit Chunking)    | \~8 Sekunden            |
| RTX 4090  | 24 GB | ca. 0,14–0,42 $/h                         | \~400 AS (mit Chunking)    | \~5 Sekunden            |
| A100 40GB | 40 GB | [Bare Metal](https://clore.ai/bare-metal) | \~800 AS problemlos        | \~3 Sekunden            |
| A100 80GB | 80 GB | [Bare Metal](https://clore.ai/bare-metal) | \~1500+ AS, große Proteine | \~4 Sekunden            |

{% hint style="warning" %}
**Mindest-VRAM: 16 GB.** ESMFold kann auf 8-GB-GPUs mit dem vollständigen ESM-2-Backbone nicht ausgeführt werden. Die RTX 3090/4090 (24 GB) kann Proteine bis zu \~400 Aminosäuren ohne Chunking verarbeiten — aktivieren Sie `chunk_size=64` in der API für längere Sequenzen.
{% endhint %}

**Bestes Preis-Leistungs-Verhältnis für die Forschung:** Die RTX 3090 für 0,07–0,21 $/h bewältigt den Großteil der Aufgaben zur Proteinstrukturvorhersage (durchschnittliches menschliches Protein: \~300–400 AS). Bei \~8 Sekunden pro Vorhersage können Sie \~450 Strukturen pro Stunde für insgesamt \~0,12 $ verarbeiten — im Vergleich zu AlphaFold2, das die Berechnung von MSA erfordert und pro Struktur Minuten braucht.

**Hochdurchsatz-Proteomik:** Für das Screening von Tausenden Sequenzen verarbeitet die A100 40 GB ([Bare Metal](https://clore.ai/bare-metal)) mit Batch-Inferenz \~1.200+ Vorhersagen pro Stunde — geeignet für Studien im Proteom-Maßstab.

***

## Ressourcen

* 🐙 **GitHub:** [github.com/facebookresearch/esm](https://github.com/facebookresearch/esm)
* 🤗 **Modelle:** [huggingface.co/facebook/esmfold\_v1](https://huggingface.co/facebook/esmfold_v1)
* 📄 **Paper:** [Evolutionäre Vorhersage der Proteinstruktur auf Atomebene mit einem Sprachmodell (Science, 2023)](https://www.science.org/doi/10.1126/science.ade2574)
* 🌐 **ESM-Metagenom-Atlas:** [esmatlas.com](https://esmatlas.com) — 772 Mio. Strukturen mit ESMFold vorhergesagt
* 💻 **Meta-AI-Blog:** [ai.meta.com/blog/protein-folding-esmfold-metagenomics](https://ai.meta.com/blog/protein-folding-esmfold-metagenomics/)
* 🔬 **ESM-Änderungsprotokoll:** [github.com/facebookresearch/esm/blob/main/CHANGELOG.md](https://github.com/facebookresearch/esm/blob/main/CHANGELOG.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-de/wissenschaft-and-forschung/esmfold.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
