Skip to content

Making an Antibody Structure Tokenizer Rotation-Invariant Without Retraining

A preprocessing fix made stored tokens bit-identical across 9,760 tested rotations and raised CDR-H3 loop retrieval from 0.165 to 0.531 mAP.

An AI model should recognize the same antibody however its 3D structure is turned. In all 9,760 rotation tests, turning the structure changed how our model recorded its shape. We lined up each structure before passing it to the existing model, so no retraining was needed. The saved descriptions then matched exactly in every rotation test, and the model became much better at finding antibodies with similarly shaped loops.

Read the research paper (PDF)

  • 9,760/9,760 rotations with identical stored tokens, up from 0/9,760 before the fix.
  • 99.98% of the rotation change traced to the Fourier features of box coordinates.
  • 0.531 CDR-H3 retrieval mAP in random poses, up from 0.165 and close to 0.539 in the stored pose.
  • 976/976 chain-label swaps rejected, with 0 of 6,976 valid antibodies rejected.

Why orientation should not matter

Our antibody Fv tokenizer turns each Cα bead into one 192-value bfloat16 token: 32 coordinate values that store the bead's position, and 160 learned features written by a 3.9-million-parameter message-passing encoder. Downstream models read the learned features, so they should describe the antibody, not the coordinate frame the structure happened to be saved in.

We moved each of 976 held-out antibodies by eight random rotations, two near-180° rotations and four translations. The tokenizer passed every translation (learned features bit-identical in 3,904 of 3,904) and failed every rotation: none of the 9,760 rotated copies kept its learned features.

Finding the cause

The encoder sees bead pairs only through their distances, which rotation does not change, so the dependence had to enter through the per-bead inputs. The original preprocessing fits a box to the structure along the x, y and z axes and gives the encoder Fourier features of each bead's fractional position in that box. Rotate the antibody and the box changes shape, so those fractional coordinates change although the molecule has not. An exact Shapley attribution over the four input blocks that can carry pose put 99.98% of the change on the Fourier features; pair distances contributed about 7 × 10−15.

Re-centring, re-scaling or re-shaping the box changed the size of the effect but never removed it. Only putting the structure into a canonical frame first did.

Rotation stability by preprocessing choice

976 held-out antibodies · median over 10 rotations

Learned-feature cosine to the unrotated encoding

Original preprocessing
0.177
Smaller box (1.25× span)
0.100
Box centred on the centroid
0.272
Cube box
0.352
Larger box (2.0× span)
0.372
Box rotated with the input
0.905
PCA frame
1.000
Sequence-anchored frame
1.000

Rotating the box with the input breaks decoding. Both canonical frames were invariant to the bit.

Figure 1. Changing the box alone never made the tokenizer rotation-invariant; the best frame-free variant reached 0.372. Both canonical frames kept the learned features bit-identical; the sequence-anchored frame is the fix we evaluated in full.

The fix: anchor the frame to the sequence

The fix numbers both chains with IMGT, fits the Cα atoms at the conserved framework positions of VH and VL jointly to a fixed reference, and applies that rigid transform before the unchanged preprocessing and encoder. The transform is kept as a float64 sidecar, so decoded coordinates map back to the input frame exactly. No weights change.

An antibody in any pose passes a heavy- and light-chain label guard, is fitted to a fixed reference using VH and VL framework anchors, then runs through the frozen encoder. A float64 sidecar returns decoded coordinates to the input frame.
Figure 2. The guard checks the heavy and light chain labels; the fit puts every pose of an antibody into the same frame before the unchanged tokenizer runs.

The sequence-anchored frame passed every preregistered test on the 976 antibodies:

  • Stored tokens were bit-identical under all 9,760 rotations.
  • Coordinates decoded from the coordinate values followed each rigid motion to within a median 1.4 × 10−14 Å.
  • The decoding error was 0.999 times the original.
  • The tokens kept 99.6% of the original response to a real CDR-H3 loop movement.

Rigid motions are the easy case: once the frame is fixed, rotating a structure and aligning it back is exact by construction. Two structures of the same antibody also differ slightly in the framework, and that moves the fitted frame. Adding 0.5 Å noise to the framework anchors used for the fit moved the frame by a median 0.24° and left the learned features at cosine 0.99996 to the clean result; dropping 20% of the anchors gave 0.22° and 0.99996. We have not yet compared genuinely different structures of one antibody, such as two crystal forms or a predicted and an experimental model.

Comparing the fixes

We tested two standard alternatives alongside the sequence-anchored frame: averaging the encoder over principal-axis frames (frame averaging), and replacing it with hand-built invariant features. All three are rotation-stable. They differ in what the tokens still carry.

ApproachRotation-stableH3 responseH3 mAPVH–VL ρ
Original tokenizer, stored poseReference1.0000.539
[0.529, 0.548]
0.758
[0.744, 0.771]
Original tokenizer, random pose0/976–0.165
[0.158, 0.172]
0.421
[0.398, 0.444]
Frame averaging976/9760.6610.371
[0.362, 0.380]
0.715
[0.701, 0.730]
Invariant features976/9760.0650.644
[0.635, 0.653]
0.466
[0.443, 0.487]
Cα loop-angle baselineby design–0.634
[0.625, 0.644]
–
Sequence-anchored frame976/9760.9960.531
[0.522, 0.541]
0.781
[0.769, 0.793]

Rotation-stable counts antibodies whose learned features stayed above cosine 0.9999 in every pose. H3 response measures response to a CDR-H3 loop movement, relative to the original tokenizer in the stored pose. H3 mAP (CDR-H3 retrieval at 1 Å) and VH–VL ρ (orientation probe) use 6,000 new antibodies, each in a random pose. Brackets indicate 95% bootstrap intervals over CDR-H3 sequence clusters. Invariant features enter the VH–VL probe as 16 values, against 160 for the learned features.

The invariant features and the loop-angle baseline retrieve CDR-H3 loops best at the strict 1 Å cutoff (0.644 and 0.634 against 0.531); at 1.5 Å the sequence-anchored tokens lead (0.676 against 0.628 and 0.616). But the tokenizer is not a retrieval index: its tokens must also decode back to coordinates, follow loop movements and keep the VH–VL orientation, and invariant features do none of these well. Only the sequence-anchored frame keeps all of it in any pose, close to the stored-pose level: 0.531 against 0.539 on retrieval (difference −0.008 [−0.011, −0.005]) and 0.781 against 0.758 on orientation.

A guard for swapped chain labels

Anchoring on the sequence brought one new failure mode. VH and VL frameworks share a fold, so when we swapped the heavy and light labels, the unguarded fit still accepted all 976 structures. We added a guard that accepts an input only if the chain labelled heavy scores as heavy against human and mouse germline profiles, the chain labelled light scores as light, and the framework fits better with the labels as given than swapped. It rejected all 976 swaps in every pose and none of 6,976 correctly labelled antibodies. Every stored token array we re-encoded through it came out byte-identical: 31,520 arrays, from 16 poses and four loop movements for each of the 976 held-out antibodies and two random poses for each of the 6,000 new ones.

Where it applies. The fix needs IMGT numbering of both chains and a mostly complete framework, with at least 60 anchor positions per chain. Heavy-chain-only inputs are rejected by design, so nanobodies (VHH) are not covered, and structures that lose 40% of their framework anchors get no token. The guard's germline profiles are human and mouse only, so rabbit, camelid and other species are untested. Every test used Cα-level predicted structures.

Why it went unnoticed

Our structures were already stored close to one frame: a median of 1.4°, and at most 6.4°, from the canonical pose. A uniformly random rotation lands that close with probability about 7 × 10−5, so tests on the stored poses could not reveal the problem.

Results

MeasureOriginalWith the fixSet
Rotations with bit-identical stored tokens0/9,7609,760/9,760976 held-out
Learned-feature cosine under rotation, median0.1771.000976 held-out
Coordinate-value equivariance error, median–1.4 × 10−14 Å976 held-out
Decoding error relative to the original1.0000.999976 held-out
CDR-H3 retrieval mAP, random pose0.165
[0.158, 0.172]
0.531
[0.522, 0.541]
6,000 new
VH–VL angle probe ρ, random pose0.421
[0.398, 0.444]
0.781
[0.769, 0.793]
6,000 new
Chain-label swaps rejected, with guard–976/976976 held-out

The 6,000 new antibodies exclude the held-out set and every training structure, and retrieval never counts a match from the query's own CDR-H3 sequence cluster.

What made it work

The defect was in preprocessing, not in the network, so the fix belongs in preprocessing too and the trained weights stay untouched. Measuring the stored bytes, rather than floating-point activations, turned invariance into a pass-or-fail test. Testing the fix for its own failure modes found the chain-label swap before it could reach a downstream model.

How we measured

  • Preregistration. The protocol, thresholds and analyses were frozen before any measurement, and no threshold changed afterwards. The guard's rule and thresholds were frozen before the guard was measured.
  • Stored bytes. Every token metric was computed from bfloat16 tokens written to disk, synced, closed and reopened. Each held-out antibody received 16 transforms: two identity controls, eight uniformly random rotations with translations, two near-180° rotations and four translations.
  • Compute. NVIDIA H100 GPUs, float32 arithmetic, deterministic algorithms, TF32 disabled and batch size 1. GPU and CPU cosines agreed to 3.4 × 10−7. The study used 1.51 GPU-hours and no training.
  • Utility. The 6,000 new antibodies each received a random pose, and intervals come from a bootstrap over CDR-H3 sequence clusters.

References