Implemetation of Kabsch algoritm for finding the best rotation matrix --------------------------------------------------------------------------- x - x(i,m) are coordinates of atom m in set x (input) y - y(i,m) are coordinates of atom m in set y (input) n - n is number of atom pairs (input) mode - 0:calculate rms only
| 3160 | t - t(i) is translation vector for best superposition (output) |
| 3161 | **************************************************************************/ |
| 3162 | bool Kabsch(double **x, double **y, int n, int mode, double *rms, |
| 3163 | double t[3], double u[3][3]) |
| 3164 | { |
| 3165 | int i, j, m, m1, l, k; |
| 3166 | double e0, rms1, d, h, g; |
| 3167 | double cth, sth, sqrth, p, det, sigma; |
| 3168 | double xc[3], yc[3]; |
| 3169 | double a[3][3], b[3][3], r[3][3], e[3], rr[6], ss[6]; |
| 3170 | double sqrt3 = 1.73205080756888, tol = 0.01; |
| 3171 | int ip[] = { 0, 1, 3, 1, 2, 4, 3, 4, 5 }; |
| 3172 | int ip2312[] = { 1, 2, 0, 1 }; |
| 3173 | |
| 3174 | int a_failed = 0, b_failed = 0; |
| 3175 | double epsilon = 0.00000001; |
| 3176 | |
| 3177 | //initialization |
| 3178 | *rms = 0; |
| 3179 | rms1 = 0; |
| 3180 | e0 = 0; |
| 3181 | double c1[3], c2[3]; |
| 3182 | double s1[3], s2[3]; |
| 3183 | double sx[3], sy[3], sz[3]; |
| 3184 | for (i = 0; i < 3; i++) |
| 3185 | { |
| 3186 | s1[i] = 0.0; |
| 3187 | s2[i] = 0.0; |
| 3188 | |
| 3189 | sx[i] = 0.0; |
| 3190 | sy[i] = 0.0; |
| 3191 | sz[i] = 0.0; |
| 3192 | } |
| 3193 | |
| 3194 | for (i = 0; i<3; i++) |
| 3195 | { |
| 3196 | xc[i] = 0.0; |
| 3197 | yc[i] = 0.0; |
| 3198 | t[i] = 0.0; |
| 3199 | for (j = 0; j<3; j++) |
| 3200 | { |
| 3201 | u[i][j] = 0.0; |
| 3202 | r[i][j] = 0.0; |
| 3203 | a[i][j] = 0.0; |
| 3204 | if (i == j) |
| 3205 | { |
| 3206 | u[i][j] = 1.0; |
| 3207 | a[i][j] = 1.0; |
| 3208 | } |
| 3209 | } |
| 3210 | } |
| 3211 | |
| 3212 | if (n<1) return false; |
| 3213 | |
| 3214 | //compute centers for vector sets x, y |
| 3215 | for (i = 0; i<n; i++) |
| 3216 | { |
| 3217 | for (j = 0; j < 3; j++) |
| 3218 | { |
| 3219 | c1[j] = x[i][j]; |
no outgoing calls
no test coverage detected