Lesson 8 of 14 · 12 min
How AlphaFold thinks: MSA, coevolution and the Evoformer
AlphaFold2 reframes structure prediction as reasoning over evolutionary information rather than physics. Instead of folding a single sequence with a force field, it reads the mutational history of a protein family and infers the geometry that is consistent with it.
Coevolution encodes contacts
Two residues that sit close in the folded structure tend to mutate in a correlated way, because a destabilizing substitution at one position is often compensated by a substitution at its spatial partner. Raw statistics like mutual information conflate these direct couplings with transitive chains of correlation, so classical methods fit a global Potts model (direct coupling analysis) to isolate the pairs that are genuinely in contact. AlphaFold skips the explicit Potts model and instead learns to extract the coevolutionary signal directly from the alignment inside its network.
# Build a deep MSA for the query with iterative HMM-HMM search
hhblits -i query.fasta \
-d databases/uniclust30_2018_08/uniclust30_2018_08 \
-oa3m query.a3m -n 3 -e 0.001 -cpu 8
# Count sequences in the resulting alignment (query + hits)
grep -c '^>' query.a3m00:00:00 INFO: Searching uniclust30_2018_08 with query.fasta
00:01:12 INFO: Iteration 1, 512 hits
00:02:47 INFO: Iteration 2, 3106 hits
00:04:19 INFO: Iteration 3, 4097 hits
00:04:20 INFO: Alignment written to query.a3m
4098
Accuracy tracks the amount of independent evolutionary signal, not the raw sequence count, because near-duplicate sequences add little information about coevolution. The standard summary is the effective number of sequences Neff, computed by down-weighting each sequence by how many neighbors it has above an identity threshold (commonly 80 percent). Shallow or redundant alignments starve the pair representation, which is the main reason orphan proteins and fast-evolving families are predicted less reliably.
import numpy as np
def read_a3m(path):
seqs, cur = [], []
for line in open(path):
if line.startswith(">"):
if cur: seqs.append("".join(cur)); cur = []
else:
cur.append(line.rstrip())
if cur: seqs.append("".join(cur))
return seqs
# In a3m format lowercase letters are insertions relative to the query;
# drop them so every sequence shares the same match-column length.
seqs = ["".join(c for c in s if not c.islower()) for s in read_a3m("query.a3m")]
msa = np.array([list(s) for s in seqs])
# Effective count: weight each sequence by 1 / (neighbors >= 80% identity)
N = msa.shape[0]
weights = np.empty(N)
for i in range(N):
identity = (msa == msa[i]).mean(axis=1)
weights[i] = 1.0 / (identity >= 0.8).sum()
print(f"N = {N} Neff = {weights.sum():.1f}")N = 4098 Neff = 1129.7
The Evoformer
The network carries two coupled tensors: an MSA representation of shape (Nseq, Nres, c) and a pair representation of shape (Nres, Nres, c) that encodes relationships between every residue pair. Information flows from the MSA into the pair track through an outer-product mean, and the Evoformer refines the pair track with triangle multiplicative updates and triangle self-attention that enforce geometric consistency analogous to the triangle inequality on distances. Axial attention lets each track reason along rows and columns cheaply, and the whole trunk is run several times through recycling, feeding refined outputs back as inputs to sharpen the prediction.
The structure module turns the abstract single and pair representations into coordinates by treating each residue as a rigid frame, an element of SE(3) with a rotation and translation, all initialized at the origin. Invariant point attention updates these frames with geometry-aware attention that is invariant to global rotation and translation, while a torsion-angle head predicts the backbone and side-chain angles needed to place every atom. Training minimizes the frame-aligned point error (FAPE), which compares predicted and true atom positions in every local frame.
Tip: This machinery is exactly why the later confidence metrics are interpretable. pLDDT reflects the structure module's local certainty about frame placement, and the predicted aligned error (PAE) is read straight from the pair representation, so both degrade predictably when the MSA is shallow or low in Neff.