Structure confidence heads
Interface pLDDT Summary
Free account with email, Google or GitHub. Your code runs in an isolated PyTorch sandbox.
Your task
Summarize supplied atom-level pLDDT scores near cross-chain interfaces, with the specified extra weight for ligand atoms.
Function signature
interface_plddt_summary(
plddt: torch.Tensor,
activations: dict,
masks: dict,
structure: dict,
count_eps: float = 1e-08,
interface_cutoff: float = 8.0,
) -> torch.TensorWorked example
Give ligand atoms twice the weight
The tokens are 4 units apart across chains, inside cutoff 8. The protein atom with pLDDT 60 has contact weight 1; the ligand atom with pLDDT 90 has weight 2. The weighted mean is (60+2\times90)/(1+2+\epsilon), approximately 80 with the default small denominator epsilon.
import torch
plddt = torch.tensor([[[60.0], [90.0]]], dtype=torch.float64, requires_grad=True)
activations = {
'representative_distances': torch.tensor([[[0.0, 4.0], [4.0, 0.0]]], dtype=torch.float64),
}
masks = {
'token_mask': torch.tensor([[True, True]], dtype=torch.bool),
'atom_mask': torch.tensor([[[True], [True]]], dtype=torch.bool),
'ligand_mask': torch.tensor([[False, True]], dtype=torch.bool),
}
structure = {
'chain_ids': torch.tensor([[0, 1]], dtype=torch.int64),
}
count_eps = 1e-08
interface_cutoff = 8.0
result = interface_plddt_summary(plddt=plddt, activations=activations, masks=masks, structure=structure, count_eps=count_eps, interface_cutoff=interface_cutoff)Expected return
torch.tensor([79.99999973333334], dtype=torch.float64)Parameters
| Parameter | Shape and meaning |
|---|---|
plddttorch.Tensor | [B,N,A]Supplied atom-level pLDDT scores. B is batch size, N tokens, and A atom slots. |
activationsdict | Supplied intermediate tensors. |
masksdict | Supplied masks. Each field below defines what True includes or permits. |
structuredict | Fields supplied together in this dictionary. |
count_epsfloatDefault 1e-08 | Positive offset in the declared TM/confidence weighted-count denominators, added after summing the relevant support. |
interface_cutofffloatDefault 8.0 | Distance threshold for selecting interface neighborhoods. |
Return
torch.Tensor · [B]
Return Weighted interface confidence mean per structure.
Required behavior
- A token has an interface contact if any valid token in a different chain has representative_distance < interface_cutoff (default 8.0). The cutoff is strict; distances are supplied, not recomputed from atoms.
- A ligand token has weight 2 whether or not it has a contact. Every other token has weight 1 if it has a contact and 0 otherwise. Apply that weight to every valid atom of the token; invalid token/atom slots have weight 0.
- Return sum(plddt × atom_weight) divided by sum(atom_weight) + count_eps (default 1e-8), separately per structure. No included atom yields zero. Do not rescale the supplied pLDDT scores.
- 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
Interface confidence summarizes atom-level confidence near contacts between chains. This teaching rule gives ligand atoms twice the weight of other interface atoms.
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 interface_plddt_summary(
plddt: torch.Tensor, # (B,N,A)
activations: dict,
masks: dict,
structure: dict,
count_eps: float = 1e-08,
interface_cutoff: float = 8.0,
) -> torch.Tensor:
"""Return a tensor with shape (B,)."""
# Implement the operation. Inputs and test setup are supplied by BioTorch.
raise NotImplementedError("Implement interface_plddt_summary")
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.