Geometry and structural losses
Express Points in Local Frames
AlphaFold2AlphaFold-MultimerOpenFold
Free account with email, Google or GitHub. Your code runs in an isolated PyTorch sandbox.
Your task
Express every world-space point in every local coordinate frame. Return a tensor whose frame and point axes enumerate all frame-point combinations.
Function signature
points_in_local_frames(
rotation: torch.Tensor,
translation: torch.Tensor,
points: torch.Tensor,
) -> torch.TensorWorked example
One point, two coordinate frames
The same point has local coordinates (1, 0, 0) in the identity frame and (0, -1, 0) in the rotated frame.
import torch
rotation = torch.tensor([[[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]], [[0.0, -1.0, 0.0], [1.0, 0.0, 0.0], [0.0, 0.0, 1.0]]]], dtype=torch.float64, requires_grad=True)
translation = torch.tensor([[[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]], dtype=torch.float64, requires_grad=True)
points = torch.tensor([[[1.0, 0.0, 0.0]]], dtype=torch.float64, requires_grad=True)
result = points_in_local_frames(rotation=rotation, translation=translation, points=points)Expected return
torch.tensor([[[[1.0, 0.0, 0.0]], [[0.0, -1.0, 0.0]]]], dtype=torch.float64)Parameters
| Parameter | Shape and meaning |
|---|---|
rotationtorch.Tensor | (B,F,3,3)Local-to-world rotation for each frame; its columns are the local basis vectors in world coordinates. |
translationtorch.Tensor | (B,F,3)World-space origin of each frame. |
pointstorch.Tensor | (B,P,3)World-space point coordinates, shared across frames within the same batch item. |
Return
torch.Tensor · (B,F,P,3)
Return Point coordinates in every local frame, in batch/frame/point/coordinate order.
Required behavior
- rotation maps local column vectors into world coordinates; translation is the frame origin in world coordinates.
- For every batch item, frame, and point, compute
p_{local}=R^\top(p_{world}-t). Subtract the frame origin before applying the transposed rotation. - Input shapes are rotation
(B,F,3,3), translation(B,F,3), and points(B,P,3). Return local_points with shape(B,F,P,3). - Batch size is positive. F or P may be zero; preserve those empty dimensions. Inputs may be strided.
- Gradients are checked for points, translations, and the nine rotation matrix entries. Use the supplied matrix directly; do not re-orthogonalize it.
Why this matters
Each residue frame supplies its own coordinate system. Comparing local coordinates measures structural agreement without first choosing one global protein alignment; the numbers of frames and points may differ.
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 points_in_local_frames(
rotation: torch.Tensor, # (B,F,3,3)
translation: torch.Tensor, # (B,F,3)
points: torch.Tensor, # (B,P,3)
) -> torch.Tensor:
"""Return a tensor with shape (B,F,P,3)."""
# Implement the operation. Inputs and test setup are supplied by BioTorch.
raise NotImplementedError("Implement points_in_local_frames")
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
A primitive exercise, not an end-to-end reproduction of the named models. No affiliation or endorsement is implied.