1#include "math/RMSD.hpp"
8RealType RMSD::calculate_rmsd(std::vector<Vector3d> mov, Vector3d& mov_com,
9 Vector3d& mov_to_ref) {
10 assert(mov.size() == ref_.size());
12 int n_vec = ref_.size();
17 for (n = 0; n < n_vec; n++) {
21 mov_com /= (RealType)n_vec;
23 mov_to_ref = ref_com - mov_com;
27 for (n = 0; n < n_vec; n++) {
35 for (n = 0; n < n_vec; n++) {
39 E0 +=
dot(mov[n], mov[n]) +
dot(ref_[n], ref_[n]);
47 R += outProduct(mov[n], ref_[n]);
52 DynamicRectMatrix<RealType> Rtmp(3, 3, 0.0);
53 DynamicRectMatrix<RealType> vtmp(3, 3);
54 DynamicVector<RealType> stmp(3);
55 DynamicRectMatrix<RealType> wtmp(3, 3);
57 Rtmp.setSubMatrix(0, 0, R);
58 SVD<RealType> svd(Rtmp);
61 svd.getSingularValues(stmp);
68 vtmp.getSubMatrix(0, 0, v);
69 stmp.getSubVector(0, s);
70 wtmp.getSubMatrix(0, 0, w);
73 if (is_reflection) s(2) = -s(2);
75 RealType rmsd_sq = (E0 - 2.0 * s.
sum()) / (RealType)n_vec;
76 rmsd_sq = std::max(rmsd_sq, RealType(0.0));
77 RealType rmsd = std::sqrt(rmsd_sq);
81RotMat3x3d RMSD::optimal_superposition(std::vector<Vector3d> mov,
83 Vector3d& mov_to_ref) {
84 assert(mov.size() == ref_.size());
86 int n_vec = ref_.size();
91 for (n = 0; n < n_vec; n++) {
95 mov_com /= (RealType)n_vec;
97 mov_to_ref = ref_com - mov_com;
101 for (n = 0; n < n_vec; n++) {
108 for (n = 0; n < n_vec; n++) {
115 R += outProduct(mov[n], ref_[n]);
119 DynamicRectMatrix<RealType> Rtmp(3, 3, 0.0);
120 DynamicRectMatrix<RealType> vtmp(3, 3);
121 DynamicVector<RealType> stmp(3);
122 DynamicRectMatrix<RealType> wtmp(3, 3);
124 Rtmp.setSubMatrix(0, 0, R);
125 SVD<RealType> svd(Rtmp);
128 svd.getSingularValues(stmp);
135 vtmp.getSubMatrix(0, 0, v);
136 stmp.getSubVector(0, s);
137 wtmp.getSubMatrix(0, 0, w);
140 if (is_reflection) s(2) = -s(2);
142 RotMat3x3d U = v * w;
Real determinant() const
Returns the determinant of this matrix.
Real sum() const
Returns the sum of all elements of this vector.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
Real dot(const DynamicVector< Real > &v1, const DynamicVector< Real > &v2)
Returns the dot product of two DynamicVectors.