Skip to content

Commit

Permalink
Added example, convenience function kabsch_rmsd
Browse files Browse the repository at this point in the history
  • Loading branch information
gp0 committed Mar 16, 2015
1 parent a02923f commit b8499fe
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion docs/kabsch.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

The Kabsch algorithm computes the optimal rotation matrix for two sets of points so that the RMSD (Root mean squared deviation) is minimal.

## Example

Define two matrices P, Q:
```julia
P = [1 2 3; 4 5 6; 7 8 9]
Q = [9 8 7; 6 5 4; 3 2 1]
```

RMSD the normal way:

```julia
rmsd(P, Q)
8.94427190999916
```
After rotation with the optimal rotation matrix:
```
kabsch_rmsd(P, Q)
1.6616296724220897e-15 (~ 0)
```
## Functions

### `rmsd(A, B)`
Expand Down Expand Up @@ -33,14 +52,22 @@ It's possible that the rotation matrix needs correction (basically flipping the

![Sign correction formula][correction-formula]

We check if d is < 0.0, if so, we flip the sign(s)
We check if d is < 0.0, if so, we flip the sign(s).

Finally the optimal rotation matrix U is calculated

![Optimal rotation matrix U][optu-formula]

and returned together with the matrix P.

## `rotate(P, Q)`

peforms the actual rotation

## `kabsch_rmsd(P,Q)`
Directly returns the RMSD after rotation for convenience.


[rmsd-formula]: http://upload.wikimedia.org/math/2/4/6/24612ddd0afbb048bb37093de3ac88fa.png "RMSD Formula"
[cov-formula]: http://upload.wikimedia.org/math/c/b/8/cb8ca6c9c787b2d8a0fd2bf3daad5a0f.png "Covariance matrix formula"
[svd-formula]: http://upload.wikimedia.org/math/4/3/d/43dd92d762ec8b8acf2a5e299b90038a.png "SVD Formula"
Expand Down

0 comments on commit b8499fe

Please sign in to comment.