Structure confidence heads

Relative Accessible Surface Area

MediumRaw PyTorchAbout 20 min2 public examples plus private tests

AlphaFold3

Write and run your solution Sign in

Free account with email, Google or GitHub. Your code runs in an isolated PyTorch sandbox.

Your task

Normalize residue solvent-accessible areas, smooth them along each protein chain, and report the fraction classified as disordered.

Function signature

relative_accessible_surface_area(
    activations: dict,
    masks: dict,
    structure: dict,
    rasa_window: int = 25,
    rasa_cutoff: float = 0.581,
) -> dict[str, torch.Tensor]

Worked example

Reflect at both ends of a chain

The RASA values are [0.2, 0.5, 0.8]. A width-3 reflected window uses indices [1, 0, 1], [0, 1, 2], and [1, 2, 1], giving smoothed values [0.4, 0.5, 0.6]. Only 0.6 strictly exceeds the supplied cutoff 0.55, so fraction_disordered is 1/3.

import torch

activations = {
    'accessible_surface_area': torch.tensor([[0.2, 0.5, 0.8]], dtype=torch.float64, requires_grad=True),
    'max_accessible_area': torch.tensor([1.0], dtype=torch.float64, requires_grad=True),
}
masks = {
    'token_mask': torch.tensor([[True, True, True]], dtype=torch.bool),
    'protein_mask': torch.tensor([[True, True, True]], dtype=torch.bool),
}
structure = {
    'chain_ids': torch.tensor([[0, 0, 0]], dtype=torch.int64),
    'chain_labels': torch.tensor([0], dtype=torch.int64),
    'residue_types': torch.tensor([[0, 0, 0]], dtype=torch.int64),
}
rasa_window = 3
rasa_cutoff = 0.55

result = relative_accessible_surface_area(activations=activations, masks=masks, structure=structure, rasa_window=rasa_window, rasa_cutoff=rasa_cutoff)

Expected return

{
    'rasa': torch.tensor([[0.2, 0.5, 0.8]], dtype=torch.float64),
    'smoothed_rasa': torch.tensor([[0.39999999999999997, 0.5, 0.6]], dtype=torch.float64),
    'fraction_disordered': torch.tensor([0.3333333333333333], dtype=torch.float64),
}

Parameters

ParameterShape and meaning
activationsdictSupplied intermediate tensors.
masksdictSupplied masks. Each field below defines what True includes or permits.
structuredictFields supplied together in this dictionary.
rasa_windowintDefault 25Positive odd width for chain-local reflected-window smoothing of relative accessible surface area.
rasa_cutofffloatDefault 0.581Relative accessible-area threshold used to mark disorder.

Return

dict[str, torch.Tensor]

Return exactly the named fields applicable to this operation.

Required behavior

  • Only token_mask & protein_mask entries are protein residues. Divide each included accessible_surface_area by max_accessible_area[residue_types] and clamp only the upper end to 1; absent/nonprotein entries are zero.
  • Within each chain_labels entry, preserve the original token order after filtering to included protein residues. Smooth with a centered mean of rasa_window values (default 25, positive odd). Reflect at chain endpoints without repeating the edge: for length L>1 reflect indices with period 2 (L−1); a single residue repeats itself.
  • Write smoothed values back to the original token positions and leave other positions zero. A residue is disordered only when its smoothed RASA is strictly greater than rasa_cutoff (default 0.581).
  • fraction_disordered is the number of disordered included protein residues divided by the included protein-residue count, with zero for no protein. This thresholded count is nondifferentiable; preserve gradients through rasa and smoothed_rasa.

Why this matters

Different heads answer different questions: pLDDT describes local accuracy, a distogram describes distance, and PAE describes error after alignment in a particular residue’s frame. Their probabilities feed separate summaries; they are not interchangeable confidence scales.

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 relative_accessible_surface_area(
    activations: dict,
    masks: dict,
    structure: dict,
    rasa_window: int = 25,
    rasa_cutoff: float = 0.581,
) -> dict[str, torch.Tensor]:
    """Return dict[str, torch.Tensor]:
    
    rasa: (B, N).
    smoothed_rasa: (B, N).
    fraction_disordered: (B,)."""
    # Implement the operation. Inputs and test setup are supplied by BioTorch.
    raise NotImplementedError("Implement relative_accessible_surface_area")

Ready to implement it?

3 progressive hints, a solution walkthrough, and grading that checks values, shapes and gradients are waiting in the workspace.

Write and run your solution Sign in

Free account with email, Google or GitHub. Your code runs in an isolated PyTorch sandbox.

Related exercises

Sources and further reading

A primitive exercise, not an end-to-end reproduction of the named models. No affiliation or endorsement is implied.