Pairwise structural alignment of two protein structures from PDB — reports the TM-score (normalized by each chain length), RMSD over the aligned core, aligned length, the rotation + translation that superposes chain 1 onto chain 2, and the residue alignment. A clean-room Rust reimplementation of TMalign.
rsomics-tm-align a.pdb b.pdb # TM-scores, RMSD, rotation, alignment
rsomics-tm-align a.pdb b.pdb --json # machine-readable scores
rsomics-tm-align a.pdb b.pdb -o out.txt
The first chain of the first model is read from each file (Cα trace, blank/A
altloc), matching TMalign's default monomer behaviour.
TM-score of an aligned residue set is
TM-score = (1/L) · Σ 1 / (1 + (d_i / d0)²), d0 = 1.24·(L − 15)^(1/3) − 1.8
with L the normalization chain length and d_i the distance between an aligned
pair after optimal superposition. The alignment is found by Zhang & Skolnick's
heuristic: several initial correspondences (gapless threading at every offset, a
secondary-structure Needleman-Wunsch, and a fragment seed) are cheaply ranked by
a single Kabsch + TM-score; the strongest few are refined by iterating
{TM-score-maximizing superposition ↔ dynamic-programming re-alignment} to a fixed
point. The reported aligned length and RMSD use TMalign's d8 cutoff.
Validated against TMalign (Version 20220412) on same-fold pairs, where the
TM-score is a well-defined, reproducible quantity:
| pair | fold relation | TMalign TM (1/2) | ours TM (1/2) | Δ |
|---|---|---|---|---|
| 1UBQ vs 1UBQ | self | 1.0000 / 1.0000 | 1.0000 / 1.0000 | 0 |
| 1UBQ vs 1UBI | identical (ubiquitin) | 0.9991 / 0.9991 | 0.9991 / 0.9991 | 0.0000 |
| 1MBN vs 1HHO | globin fold | 0.8397 / 0.9048 | 0.8396 / 0.9046 | 0.0002 |
Max deviation: ΔTM = 0.0002, ΔRMSD = 0.00 Å, Δaligned = 0. tests/compat.rs
runs this differential when a TMalign binary is present (loud-skip otherwise).
For unrelated folds (TM ≲ 0.4) the superposition landscape is flat and full of near-degenerate optima; independent heuristics legitimately disagree there by ~0.02, and the TM-align paper itself treats TM < 0.5 as "different fold". That regime is exercised only as a bounded smoke test, not an equality gate.
Single-threaded, against TMalign 20220412 on an Intel Xeon Gold 6238R
(hyperfine, ≥12 runs):
| pair | size | ours -t1 |
TMalign | speedup |
|---|---|---|---|---|
| 1DPE vs 1GAI | 507 × 472 | 58.7 ms | 627 ms | 10.7× |
| 1J6Z vs 3HBT | 368 × 359 | 31.2 ms | 123 ms | 3.9× |
With -t8, 1DPE vs 1GAI reaches 24× (the initial-seed refinement parallelizes
over rayon). The win comes from ranking gapless-threading offsets cheaply and
paying the full O(n·m) DP only on the few strongest seeds, rather than refining
every offset.
This crate is an independent Rust reimplementation of TMalign based on:
- The published method: Y. Zhang and J. Skolnick, "TM-align: a protein structure alignment algorithm based on the TM-score", Nucleic Acids Research 33.7 (2005) 2302–2309, doi:10.1093/nar/gki524.
- The TM-score definition: Y. Zhang and J. Skolnick, "Scoring function for automated assessment of protein structure template quality", Proteins 57 (2004) 702–710, doi:10.1002/prot.20264.
- The public PDB file-format spec.
- Black-box behaviour testing against the
TMalignbinary.
No source code from TMalign was copied into this implementation. Test fixtures are real public PDB entries (1UBQ, 1UBI, 1MBN, 1HHO, 1CRN).
License: MIT OR Apache-2.0. Upstream credit: TMalign (Zhang lab) https://zhanggroup.org/TM-align/.