Skip to content

Commit

Permalink
convenience function to directly get RMSD of two matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
gp0 committed Mar 16, 2015
1 parent 0780112 commit a02923f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 9 additions & 2 deletions src/KABSCH/kabsch.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Kabsch
export calc_centroid, kabsch, rotate, rmsd, translate_points
export calc_centroid, kabsch, rotate, rmsd, translate_points, kabsch_rmsd
# Calculate root mean square deviation of two matrices A, B
# http://en.wikipedia.org/wiki/Root-mean-square_deviation_of_atomic_positions
function rmsd(A, B)
Expand Down Expand Up @@ -48,7 +48,7 @@ export calc_centroid, kabsch, rotate, rmsd, translate_points
A = *(P', Q)

# calculate SVD (singular value decomposition) of covariance matrix
# http://de.wikipedia.org/wiki/Singul%C3%A4rwertzerlegung
# http://de.wikipedia.org/wiki/Singul%C3%A4rwertzerlegunggo
V, S, W = svd(A)

# decide if rotation matrix needs correction (ensures right-handed coordinate system)
Expand All @@ -69,4 +69,11 @@ export calc_centroid, kabsch, rotate, rmsd, translate_points
U, P = kabsch(P,Q)
return *(P, U)
end

# directly return RMSD for matrices P, Q for convenience
function kabsch_rmsd(P, Q)
P_1, Q_1 = translate_points(P, Q)
P = rotate(P, Q)
return rmsd(P, Q_1)
end
end
6 changes: 1 addition & 5 deletions src/KABSCH/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,4 @@ Q = [9 8 7; 6 5 4; 3 2 1]

@test_approx_eq_eps rmsd(P,Q) 8.94427191 1e-4

# Q needs to be translated to the origin of the coordinate system, otherwise the comparison makes no sense
P_1, Q_1 = translate_points(P,Q)
P = rotate(P, Q)

@test_approx_eq_eps rmsd(P,Q_1) 2.4323767778e-15 1e-6
@test_approx_eq_eps kabsch_rmsd(P,Q) 2.4323767778e-15 1e-6

0 comments on commit a02923f

Please sign in to comment.