Structure confidence heads
AlphaFold 3 Ranking Score
Free account with email, Google or GitHub. Your code runs in an isolated PyTorch sandbox.
Your task
Rank each structure by a pTM/ipTM mixture, using pTM alone when the interface score has no support. Then add the stated disorder contribution and subtract the clash penalty. Return this scalar ranking value per structure; it is not a probability.
Function signature
af3_ranking_score(
ptm: torch.Tensor,
iptm: torch.Tensor,
iptm_valid: torch.Tensor,
fraction_disordered: torch.Tensor,
masks: dict,
ranking_mix: float = 0.8,
) -> torch.TensorWorked example
Interface support and a clash penalty
For structure 0, the supported interface mixture is 0.2\times0.5+0.8\times0.75=0.7. Disorder adds 0.5\times0.2=0.1, yielding 0.8. Structure 1 has no supported interface, so it starts from pTM 0.5. Its clash penalty subtracts 100, yielding -99.5.
import torch
ptm = torch.tensor([0.5, 0.5], dtype=torch.float64, requires_grad=True)
iptm = torch.tensor([0.75, 0.75], dtype=torch.float64, requires_grad=True)
iptm_valid = torch.tensor([True, False], dtype=torch.bool)
fraction_disordered = torch.tensor([0.2, 0.0], dtype=torch.float64, requires_grad=True)
masks = {
'has_clash': torch.tensor([False, True], dtype=torch.bool),
}
ranking_mix = 0.8
result = af3_ranking_score(ptm=ptm, iptm=iptm, iptm_valid=iptm_valid, fraction_disordered=fraction_disordered, masks=masks, ranking_mix=ranking_mix)Expected return
torch.tensor([0.8, -99.5], dtype=torch.float64)Parameters
| Parameter | Shape and meaning |
|---|---|
ptmtorch.Tensor | [B]Supplied predicted TM score. |
iptmtorch.Tensor | [B]Supplied interface TM score. |
iptm_validtorch.Tensor | [B]Whether the supplied interface score has support. |
fraction_disorderedtorch.Tensor | [B]Supplied fraction of disordered protein residues. |
masksdict | Supplied masks. Each field below defines what True includes or permits. |
ranking_mixfloatDefault 0.8 | Weight of the interface-TM term in mixed ranking. |
Return
torch.Tensor · [B]
Return Combined ranking score per structure.
Required behavior
- Use
(1-mix)\,pTM+mix\,ipTM, where ranking_mix defaults to 0.8 and lies in[0,1]. Scores are supplied batch vectors; this lesson does not recompute TM probabilities. - If iptm_valid is False, replace the mixture with pTM. Then add 0.5 × fraction_disordered and subtract 100 × has_clash. Apply both adjustments after the unsupported-interface fallback; has_clash is boolean.
- Use CPU float32/float64 tensors with one shared floating dtype/device. Preserve strided layouts and do not mutate supplied tensors.
- Use raw tensor operations, not a ready-made implementation of the requested primitive. Supplied parameters and random variates must not be reinitialized.
Why this matters
AlphaFold3 combines structure confidence, disorder and a strong clash penalty to rank sampled predictions. These ingredients are already supplied; this task implements their combination.
Starter code
You write the body of this function in the BioTorch workspace. Your code runs in an isolated PyTorch sandbox; Run checks the public examples and Submit grades the full test suite, including gradients.
import torch
def af3_ranking_score(
ptm: torch.Tensor, # (B,)
iptm: torch.Tensor, # (B,)
iptm_valid: torch.Tensor, # (B,)
fraction_disordered: torch.Tensor, # (B,)
masks: dict,
ranking_mix: float = 0.8,
) -> torch.Tensor:
"""Return a tensor with shape (B,)."""
# Implement the operation. Inputs and test setup are supplied by BioTorch.
raise NotImplementedError("Implement af3_ranking_score")
Ready to implement it?
3 progressive hints, a solution walkthrough, and grading that checks values, shapes and gradients are waiting in the workspace.
Free account with email, Google or GitHub. Your code runs in an isolated PyTorch sandbox.
Related exercises
Sources and further reading
- www.nature.com
- www.nature.com
- google-deepmind/alphafold · modules.py
- google-deepmind/alphafold · confidence.py
- facebookresearch/esm · esmfold.py
- facebookresearch/esm · esmfold.py
- google-deepmind/alphafold3 · confidence_head.py
- google-deepmind/alphafold3 · confidences.py
- google-deepmind/alphafold3 · confidences.py
- google-deepmind/alphafold3 · confidences.py
- huggingface/transformers · modeling_esmfold2.py
- Biohub/esm · vqvae.py
- Biohub/esm · vqvae.py
- RosettaCommons/RFdiffusion · AuxiliaryPredictor.py
- RosettaCommons/RFdiffusion · RoseTTAFoldModel.py
A primitive exercise, not an end-to-end reproduction of the named models. No affiliation or endorsement is implied.