Lesson 11 of 13 · 12 min
Structural Superposition and Alignment
Structural superposition finds the rigid-body rotation and translation that best overlays one set of atoms onto another by minimizing the root-mean-square deviation. The hard part is rarely the fit itself but the correspondence: deciding which atom in one structure matches which atom in the other. That mapping can come from a sequence alignment or from the 3D geometry directly, and the choice dictates which tool you should reach for.
Superimposer And RMSD
from Bio.PDB import PDBParser, Superimposer
parser = PDBParser(QUIET=True)
ref = parser.get_structure("ref", "1ake.pdb")[0]
mob = parser.get_structure("mob", "4ake.pdb")[0]
# One-to-one correspondence assumed here: matched CA atoms, same order.
ref_atoms = [res["CA"] for res in ref["A"] if "CA" in res]
mob_atoms = [res["CA"] for res in mob["A"] if "CA" in res]
n = min(len(ref_atoms), len(mob_atoms))
ref_atoms, mob_atoms = ref_atoms[:n], mob_atoms[:n]
sup = Superimposer()
sup.set_atoms(ref_atoms, mob_atoms) # (fixed, moving)
sup.apply(mob.get_atoms()) # mutates moving coordinates in place
rot, tran = sup.rotran # moving @ rot + tran = fitted
print(f"RMSD = {sup.rms:.3f} A over {n} CA atoms")
print("rotation:\n", rot)
print("translation:", tran)RMSD = 7.117 A over 214 CA atoms
rotation:
[[ 0.9962 -0.0808 0.0335]
[ 0.0790 0.9954 0.0521]
[-0.0376 -0.0492 0.9981]]
translation: [ 3.214 -1.087 0.556]
Warning: set_atoms takes (fixed, moving) and requires two equal-length lists whose elements already correspond one-to-one. The truncation above is only valid when the residues genuinely line up; blindly slicing to min length produces a meaningless RMSD. Also note sup.apply mutates coordinates in place, and RMSD is not length-normalized, so it is not comparable across pairs of different sizes.
TM-align And TM-score
Sequence-based correspondence aligns residues by identity and then superposes the matched atoms, which degrades once identity drops. Structure-based correspondence derives the matching from 3D geometry, so it still works for remote homologs with negligible sequence similarity. TM-align builds such a structure-based alignment directly from geometry, independent of sequence identity (though still sequential, preserving N-to-C residue order), and reports a TM-score normalized by the reference chain length, bounded in (0, 1], where values above 0.5 imply the same fold and below 0.17 indicate no more than random structural similarity.
TMalign 4ake.pdb 1ake.pdb **************************************************************************
* TM-align (Version 20190822): protein structure alignment *
**************************************************************************
Name of Chain_1: 4ake.pdb (to be superimposed onto Chain_2)
Name of Chain_2: 1ake.pdb
Length of Chain_1: 214 residues
Length of Chain_2: 214 residues
Aligned length= 196, RMSD= 2.98, Seq_ID=n_identical/n_aligned= 1.000
TM-score= 0.86028 (if normalized by length of Chain_1, i.e., LN=214, d0=5.44)
TM-score= 0.86028 (if normalized by length of Chain_2, i.e., LN=214, d0=5.44)
PyMOL Superposition Commands
from pymol import cmd
cmd.load("1ake.pdb", "ref")
cmd.load("4ake.pdb", "mob")
# align: sequence alignment + iterative outlier rejection. Best when identity is high (>~30%).
r_align = cmd.align("mob", "ref") # (mobile, target)
# super: sequence-independent, structure-based superposition. Better for low identity.
r_super = cmd.super("mob", "ref") # (mobile, target)
# cealign: Combinatorial Extension. Best for remote homologs / negligible identity.
r_ce = cmd.cealign("ref", "mob") # (target, mobile) -> dict
print("align RMSD =", round(r_align[0], 3), "over", r_align[1], "atoms")
print("super RMSD =", round(r_super[0], 3), "over", r_super[1], "atoms")
print("cealign RMSD =", round(r_ce["RMSD"], 3), "over", r_ce["alignment_length"], "residues")Try it yourself: Download 1AKE (closed) and 4AKE (open) adenylate kinase, superpose all CA atoms with Bio.PDB.Superimposer, and record the global RMSD. Then run TMalign and PyMOL super on the same pair and explain why the structure-based RMSD over the aligned core is far smaller than the rigid all-CA RMSD. Finally, decide which of align, super, and cealign you would trust for two proteins sharing under 15% sequence identity, and justify it.