Skip to content

MurrellGroup/Kabsch.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kabsch.jl

Stable Dev Build Status Coverage

A Julia implementation of the Kabsch algorithm for finding the optimal rotation between paired sets of points.

Usage

using Kabsch, Manifolds

# Generate realistic test data
P = randn(3, 10)
R_true = rand(Rotations(3))  # Random rotation matrix
Q = R_true * centered(P) .+ randn(3)  # Rotate and translate P

# Find optimal alignment
R, P_centroid, Q_centroid = kabsch(P, Q)
Q_aligned = superimposed(Q, P)

# Verify perfect alignment
@assert P  Q_aligned
@assert rmsd(superimposed, Q, P)  0

Batched Operations

Process multiple alignments simultaneously:

Ps = randn(3, 50, 8)  # 8 reference point sets
Qs = randn(3, 50, 8)  # 8 point sets to align, uncorrelated for ease of showcase

Rs, P_centroids, Q_centroids = kabsch(Ps, Qs)
Q_aligned_all = superimposed(Qs, Ps)

Extensions

StaticArrays: Optimal performance for small point sets

using StaticArrays
P = @SMatrix randn(3, 5)
Q = @SMatrix randn(3, 5)  # uncorrelated for ease of showcase
R, Pt, Qt = kabsch(P, Q)

CUDA: GPU acceleration for 3D case

using CUDA
P_gpu = CUDA.randn(3, 100, 1000)  # 100 batches on GPU
Q_gpu = CUDA.randn(3, 100, 1000)  # uncorrelated for ease of showcase
R_gpu, _, _ = kabsch(P_gpu, Q_gpu)

See also

  • BioStructures.jl for rmsd and superimpose! on molecular structures (including residue alignment)

About

Kabsch algorithm for optimally aligning two paired sets of points

Topics

Resources

License

Stars

Watchers

Forks

Languages