Developer docs / AI Fabric tutorials

Protein binder design (ESMFold2 fan-out)

  • GPU
  • Batch / map
  • Volume
  • Image DSL

Designing a protein binder is a numbers game: you generate hundreds of candidate sequences and you need to know, fast, which ones actually fold into a confident structure. Folding them one at a time is the bottleneck, but each candidate is independent, so there's no reason to. Hand the whole list to AI Fabric and every sequence folds at the same time, each in its own GPU container.

In this tutorial you'll fold a batch of candidate binder sequences with ESMFold and score each by its mean pLDDT, the model's own confidence in the predicted structure. .map() fans the work out across GPUs and collects the results in order, so you can rank candidates and keep only the promising ones.

Before you start

Install and authenticate the AI Fabric CLI with blade setup. Each fold runs on its own RTX A4500 and builds on fabric/torch, the catalog image with CUDA and PyTorch already installed; only transformers and biotite are added on top.

Create the app and a weights Volume

Create protein_binders.py. Declare the app and a Volume for the ESMFold weights so the multi-gigabyte download is shared and cached, not repeated per container. Build the image on fabric/torch and point TRANSFORMERS_CACHE at the mounted Volume:

protein_binders.py
import bladekit

app = bladekit.app("protein-binders")

weights_vol = bladekit.Volume.from_name("esm-weights", create_if_missing=True)

image = (
    bladekit.Image.from_catalog("fabric/torch")
    .pip_install("torch", "transformers", "biotite")
    .env({"TRANSFORMERS_CACHE": "/weights"})
)

Write the per-sequence fold function

The unit of work is folding one sequence. Request the GPU, the image, and the mounted Volume, then load ESMFold and run a no-grad forward pass. Instead of a full structure, this function returns the sequence alongside its mean pLDDT, a compact confidence score that's all you need to triage candidates:

Python
@app.function(
    gpu="RTX-A4500",
    image=image,
    timeout=300,
    volumes={"/weights": weights_vol},
)
def fold_sequence(sequence: str) -> dict:
    import torch
    from transformers import AutoTokenizer, EsmForProteinFolding

    tok = AutoTokenizer.from_pretrained("facebook/esmfold_v1")
    model = EsmForProteinFolding.from_pretrained(
        "facebook/esmfold_v1", low_cpu_mem_usage=True
    ).to("cuda")

    inputs = tok([sequence], return_tensors="pt", add_special_tokens=False).to("cuda")
    with torch.no_grad():
        outputs = model(**inputs)

    plddt = outputs.plddt.mean().item()
    return {"sequence": sequence, "mean_plddt": plddt}

Fan out the candidates with .map()

In the entrypoint, collect your candidate sequences into a list and pass it to fold_sequence.map(...). AI Fabric launches one GPU container per sequence and folds them all simultaneously, returning results in input order. return_exceptions=True means one bad sequence reports an error instead of sinking the whole batch:

Python
@app.local_entrypoint()
def main():
    candidates = [
        "MKTAYIAKQRQISFVKSHFSRQLEERLGLIEVQAPILSRVGDGTQDNLSGAEKAVQVKVKALPDAQFEVVHSLAKWKRQTLGQHDFSAGEGLYTHMKALRPDEDRLSPLHSVYVDQWDWERVMGDGERQFSTLKSTVEAIWAGIKATEAAVSEEFGLAPFLPDQIHFVHSQELLSRYPDLDAKGRERAIAKDLGAVFLVGIGGKLSDGHRHDVRAPDYDDWSTPSELGHAGLNGDILVWNPVLEDAFELSSMGIRVDADTLKHQLALTGDEDRLELEWHQALLRGEMPQTIGGGIGQSRLTMLLLQLPHIGQVQAGVWPAAVRESVPSLL",
        "ACDEFGHIKLMNPQRSTVWY" * 5,
        "MAEGEITTFTALTEKFNLPPGNYKKPKLLYCSNGGHFLRILPDGTVDGTRDRSDQHIQLQLSAESVGEVYIKSTETGQYLAMDTSGLLYGSQTPSEECLFLERLEENHYNTYTSKKHAEKNWFVGLKKNGSCKRGPRTHYGQKAILFLPLPV",
    ]
    results = list(fold_sequence.map(candidates, return_exceptions=True))
    for r in results:
        if isinstance(r, Exception):
            print(f"FAILED: {r}")
        else:
            print(f"pLDDT={r['mean_plddt']:.2f}  seq={r['sequence'][:30]}...")

Run it

Launch the batch with one command:

Terminal
blade run protein_binders.py

Each candidate folds in its own GPU container at the same time, and the entrypoint prints the mean pLDDT for each. Filter by mean_plddt > 70 to keep the confidently folded structures and discard the rest. To screen thousands of candidates, pass a longer list and AI Fabric auto-provisions more containers to fold them in parallel.

Take it for a spin

Everything above in one file, ready to run.

protein_binders.py
import bladekit

app = bladekit.app("protein-binders")

weights_vol = bladekit.Volume.from_name("esm-weights", create_if_missing=True)

image = (
    bladekit.Image.from_catalog("fabric/torch")
    .pip_install("torch", "transformers", "biotite")
    .env({"TRANSFORMERS_CACHE": "/weights"})
)

@app.function(
    gpu="RTX-A4500",
    image=image,
    timeout=300,
    volumes={"/weights": weights_vol},
)
def fold_sequence(sequence: str) -> dict:
    import torch
    from transformers import AutoTokenizer, EsmForProteinFolding

    tok = AutoTokenizer.from_pretrained("facebook/esmfold_v1")
    model = EsmForProteinFolding.from_pretrained(
        "facebook/esmfold_v1", low_cpu_mem_usage=True
    ).to("cuda")

    inputs = tok([sequence], return_tensors="pt", add_special_tokens=False).to("cuda")
    with torch.no_grad():
        outputs = model(**inputs)

    plddt = outputs.plddt.mean().item()
    return {"sequence": sequence, "mean_plddt": plddt}

@app.local_entrypoint()
def main():
    candidates = [
        "MKTAYIAKQRQISFVKSHFSRQLEERLGLIEVQAPILSRVGDGTQDNLSGAEKAVQVKVKALPDAQFEVVHSLAKWKRQTLGQHDFSAGEGLYTHMKALRPDEDRLSPLHSVYVDQWDWERVMGDGERQFSTLKSTVEAIWAGIKATEAAVSEEFGLAPFLPDQIHFVHSQELLSRYPDLDAKGRERAIAKDLGAVFLVGIGGKLSDGHRHDVRAPDYDDWSTPSELGHAGLNGDILVWNPVLEDAFELSSMGIRVDADTLKHQLALTGDEDRLELEWHQALLRGEMPQTIGGGIGQSRLTMLLLQLPHIGQVQAGVWPAAVRESVPSLL",
        "ACDEFGHIKLMNPQRSTVWY" * 5,
        "MAEGEITTFTALTEKFNLPPGNYKKPKLLYCSNGGHFLRILPDGTVDGTRDRSDQHIQLQLSAESVGEVYIKSTETGQYLAMDTSGLLYGSQTPSEECLFLERLEENHYNTYTSKKHAEKNWFVGLKKNGSCKRGPRTHYGQKAILFLPLPV",
    ]
    results = list(fold_sequence.map(candidates, return_exceptions=True))
    for r in results:
        if isinstance(r, Exception):
            print(f"FAILED: {r}")
        else:
            print(f"pLDDT={r['mean_plddt']:.2f}  seq={r['sequence'][:30]}...")

Concepts used: GPU, Run

Contact the team

Loading the form…