37 namespace model_quality {
51 assert( p1_coords.size() == p2_coords.size() );
52 Size const natoms( p1_coords.size() );
57 for (
Size i = 1; i <= natoms; ++i ) {
58 for (
Size k = 1; k <= 3; ++k ) {
59 p1a(k,i) = p1_coords[i](k);
60 p2a(k,i) = p2_coords[i](k);
75 rmsfitca2(natoms,p1a,p2a,ww,natoms,bogus);
79 for (
int i = 1; i <= natoms; ++i ) {
80 for (
int j = 1; j <= 3; ++j ) {
81 tot +=
std::pow( p1a(i,j) - p2a(i,j), 2 );
85 return std::sqrt(tot/natoms);
100 findUU( p1a, p2a, ww, natoms, uu, ctx );
153 for (
int k = 1; k <= npoints; ++k ) {
155 for (
int j = 1; j <= 3; ++j ) {
158 rms += ww_k * ( ( xx_jk * xx_jk ) + ( yy_jk * yy_jk ) );
165 rms_out = std::sqrt(
std::abs(rms/npoints));
250 for (
int i = 1; i <= 3; ++i ) {
251 for (
int k = 1; k <= 3; ++k ) {
253 if ( i == k ) UU(i,i) = 1.0;
261 for (
int k = 1; k <= 3; ++k ) {
265 for (
int j = 1; j <= Npoints; ++j ) {
266 temp1 += XX(k,j) * WW(j);
267 temp2 += YY(k,j) * WW(j);
270 if ( temp3 > 0.001 ) temp1 /= temp3;
271 if ( temp3 > 0.001 ) temp2 /= temp3;
273 for (
int j = 1; j <= Npoints; ++j ) {
280 for (
int k = 1; k <= 3; ++k ) {
281 for (
int j = 1; j <= 3; ++j ) {
283 for (
int i = 1; i <= Npoints; ++i ) {
284 temp1 += WW(i) * YY(k,i) * XX(j,i);
286 m_moment(k,j) = temp1;
302 for (
int i = 1; i <= 3; ++i ) {
303 w_w( i ) = xyz_w_w( i );
304 for (
int j = 1; j <= 3; ++j ) {
305 eVec( i, j ) = xyz_eVec( i, j );
310 for (
int i = 1; i <= 3; ++i ) {
314 if ( w_w(1) < w_w(2) ) {
319 if ( w_w(sort(2)) < w_w(3) ) {
323 if ( w_w(sort(1)) < w_w(3) ) {
331 if ( w_w(sort(2)) == 0.0 ) {
333 for (
int i = 1; i <= 3; ++i ) {
334 for (
int k = 1; k <= 3; ++k ) {
339 if ( w_w(sort(1)) < 0.0 ) {
340 w_w(sort(1)) =
std::abs(w_w(sort(1)));
342 sigma3 = std::sqrt(w_w(sort(1)));
348 temp1 = w_w(sort(1));
349 temp2 = w_w(sort(2));
350 w_w(3) = w_w(sort(3));
354 for (
int i = 1; i <= 3; ++i ) {
355 temp1 = eVec(i,sort(1));
356 temp2 = eVec(i,sort(2));
374 for (
int j = 1; j <= 3; ++j ) {
381 for (
int j = 1; j <= 2; ++j ) {
382 temp1 = 1.0/std::sqrt(w_w(j));
383 for (
int k = 1; k <= 3; ++k ) {
398 for (
int j = 1; j <= 3; ++j ) {
399 sigma3 += bb(j,3)*Ra(j);
404 if ( sigma3 < 0.0 ) {
435 findUU(XX_Farray,YY_Farray,WW_Farray,Npoints,UU_Farray,sigma3);
491 MatrixMult(A,n,np,transposeA,B,m,transposeB,AxB_out);
548 if ( transposeA == 0 ) {
549 if ( transposeB == 0 ) {
550 for (
int k = 1; k <= m; ++k ) {
551 for (
int j = 1; j <= n; ++j ) {
552 for (
int i = 1; i <= np; ++i ) {
553 AxB_out(k,j) +=
A(k,i)*B(i,j);
558 for (
int k = 1; k <= m; ++k ) {
559 for (
int j = 1; j <= n; ++j ) {
560 for (
int i = 1; i <= np; ++i ) {
561 AxB_out(k,j) +=
A(k,i)*B(j,i);
567 if ( transposeB == 0 ) {
568 for (
int k = 1; k <= m; ++k ) {
569 for (
int j = 1; j <= n; ++j ) {
570 for (
int i = 1; i <= np; ++i ) {
571 AxB_out(k,j) +=
A(i,k)*B(i,j);
576 for (
int k = 1; k <= m; ++k ) {
577 for (
int j = 1; j <= n; ++j ) {
578 for (
int i = 1; i <= np; ++i ) {
579 AxB_out(k,j) +=
A(i,k)*B(j,i);
614 numeric::Real const m_v_13 = m_v(2,1)*m_v(3,2) - m_v(3,1)*m_v(2,2);
615 numeric::Real const m_v_23 = m_v(3,1)*m_v(1,2) - m_v(1,1)*m_v(3,2);
616 numeric::Real const m_v_33 = m_v(1,1)*m_v(2,2) - m_v(2,1)*m_v(1,2);
619 ( ( m_v_13 * m_v_13 ) + ( m_v_23 * m_v_23 ) + ( m_v_33 * m_v_33 ) ) );
621 m_v(1,3) = m_v_13 *
norm;
622 m_v(2,3) = m_v_23 *
norm;
623 m_v(3,3) = m_v_33 *
norm;
653 double XPC, YPC, ZPC, XEC, YEC, ZEC;
658 COMAS(xx,ww,npoints,XPC,YPC,ZPC);
659 COMAS(yy,ww,npoints,XEC,YEC,ZEC);
661 for ( i = 1; i <= npoints; ++i ) {
670 for ( k = 1; k <= 3; ++k ) {
671 for ( j = 1; j <= 3; ++j ) {
673 for ( i = 1; i <= npoints; ++i ) {
674 temp1 += ww(i)*yy(k,i)*xx(j,i);
676 m_moment(k,j) = temp1 /(temp3);
679 det =
det3(m_moment);
694 for ( i = 1; i <= 3; ++i ) {
695 for ( j = i; j <= 3; ++j ) {
696 rr_moment(j,i) = rr_moment(i,j) =
697 m_moment(1,i)*m_moment(1,j) +
698 m_moment(2,i)*m_moment(2,j) +
699 m_moment(3,i)*m_moment(3,j);
709 if ( ev(2) > ev(3) ) {
710 if ( ev(3) > ev(1) ) {
716 if ( ev(2) > ev(1) ) {
746 for ( i = 1; i <= npoints; ++i ) {
747 for ( j = 1; j <= 3; ++j ) {
748 t(j) = R(j,1)*yy(1,i) + R(j,2)*yy(2,i) + R(j,3)*yy(3,i);
761 handedness*std::sqrt(
std::abs(ev(3)));
768 for ( i = 1; i <= npoints; ++i ) {
769 for ( j = 1; j <= 3; ++j ) {
770 rms_sum += ww(i)*( ( yy(j,i) * yy(j,i) ) + ( xx(j,i) * xx(j,i) ) );
778 esq = std::sqrt(
std::abs( rms_sum - ( 2.0 * rms_ctx ) ) / natsel );
807 double rms_ctx,rms2_sum;
817 mass = rmsdata->
count();
818 double xre = rmsdata->
xre();
819 double xrp = rmsdata->
xrp();
828 come(1) = xse(1)/mass;
829 come(2) = xse(2)/mass;
830 come(3) = xse(3)/mass;
832 comp(1) = xsp(1)/mass;
833 comp(2) = xsp(2)/mass;
834 comp(3) = xsp(3)/mass;
839 for (
int k = 1; k <= 3; ++k ) {
840 for (
int j = 1; j <= 3; ++j ) {
841 m_moment(k,j) = xm(k,j)/mass - come(k)*comp(j);
845 det =
det3(m_moment);
865 for (
int i = 1; i <= 3; ++i ) {
866 for (
int j = i; j <= 3; ++j ) {
867 rr_moment(j,i) = rr_moment(i,j) =
868 m_moment(1,i)*m_moment(1,j) +
869 m_moment(2,i)*m_moment(2,j) +
870 m_moment(3,i)*m_moment(3,j);
881 if ( ev(2) > ev(3) ) {
882 if ( ev(3) > ev(1) ) {
888 if ( ev(2) > ev(1) ) {
907 for (
int i = 1; i <= npoints; ++i ) {
908 for (
int k = 1; k <= 3; ++k ) {
909 yy(k,i) = yy0(k,i)-come(k);
910 xx(k,i) = xx0(k,i)-comp(k);
912 for (
int j = 1; j <= 3; ++j ) {
918 t(j) = r(j,1)*yy(1,i) + r(j,2)*yy(2,i) + r(j,3)*yy(3,i);
933 handedness*std::sqrt(
std::abs(ev(3)));
939 temp1 = ( come(1) * come(1) ) + ( come(2) * come(2) ) + ( come(3) * come(3) ) +
940 ( comp(1) * comp(1) ) + ( comp(2) * comp(2) ) + ( comp(3) * comp(3) );
942 rms2_sum = (xre + xrp)/mass - temp1;
948 esq = std::sqrt(
std::abs(rms2_sum-2.0*rms_ctx));
959 m(1,3)*( m(2,1)*m(3,2) - m(2,2)*m(3,1) ) -
960 m(2,3)*( m(1,1)*m(3,2) - m(1,2)*m(3,1) ) +
961 m(3,3)*( m(1,1)*m(2,2) - m(1,2)*m(2,1) );
975 double xx,yy,zz,xy,xz,yz;
977 std::complex< double > f1,f2,f3,f4,f5;
979 static std::complex< double >
const unity = std::complex< double >(1.0,0.0);
980 static std::complex< double >
const sqrt_3i =
981 std::sqrt( 3.0 ) * std::complex< double >(0.0,1.0);
993 b = -xx*zz-xx*yy-yy*zz+xy*xy+xz*xz+yz*yz;
994 c = xx*yy*zz-xz*xz*yy-xy*xy*zz-yz*yz*xx+2*xy*xz*yz;
1005 if ( norm > 1.0E50 ) {
1008 c /= norm * norm *
norm;
1015 double const a2 = a *
a;
1016 double const a3 = a * a *
a;
1023 s0 = ( -12.0 * ( b * b *
b ) ) - ( 3.0 * ( b *
b ) * a2 ) +
1024 ( 54.0 * c * b *
a ) + ( 81.0 * ( c * c ) ) + ( 12.0 * c * a3 );
1027 f1 = b*a/6.0 + c/2.0 + a3/27.0 + std::sqrt(s0*unity)/18.0;
1031 f3 = (-b/3.0 - a2/9.0)/f2;
1035 f5 = sqrt_3i * (f2+f3);
1040 ev(1) = norm*(ev(1)+s0 );
1042 ev(2) = (-f4+f5).real();
1043 ev(2) = norm*(ev(2)*0.5 + s0 );
1044 ev(3) = (-f4-f5).real();
1045 ev(3) = norm*(ev(3)*0.5 + s0);
1068 for (
int i = 1; i <= 2; ++i ) {
1072 for (
int j = 1; j <= 3; ++j ) {
1074 for (
int k = 1; k <= 3; ++k ) {
1075 temp(j,i) += mvec(k,i)*
mm(j,k);
1081 temp(1,3) = temp(2,1)*temp(3,2) - temp(2,2)*temp(3,1);
1082 temp(2,3) = -temp(1,1)*temp(3,2) + temp(1,2)*temp(3,1);
1083 temp(3,3) = temp(1,1)*temp(2,2) - temp(1,2)*temp(2,1);
1085 for (
int i = 1; i <= 3; ++i ) {
1086 for (
int j = 1; j <= 3; ++j ) {
1088 for (
int k = 1; k <= 3; ++k ) {
1089 rot(j,i) += temp(i,k)*mvec(j,k);
1108 double xx,yy,xy,zx,yz;
1109 double e1,e2,e3,znorm;
1118 if ( ev(1) != ev(2) ) {
1120 for (
int i = 1; i <= 2; ++i ) {
1132 znorm = std::sqrt( ( e1 * e1 ) + ( e2 * e2 ) + ( e3 * e3 ) );
1134 mvec(1,i) = e1/znorm;
1135 mvec(2,i) = e2/znorm;
1136 mvec(3,i) = e3/znorm;
1141 mvec(1,3) = mvec(2,1)*mvec(3,2) - mvec(2,2)*mvec(3,1);
1142 mvec(2,3) = -mvec(1,1)*mvec(3,2) + mvec(1,2)*mvec(3,1);
1143 mvec(3,3) = mvec(1,1)*mvec(2,2) - mvec(1,2)*mvec(2,1);
1151 if ( ev(2) != ev(3) ) {
1152 std::cerr <<
" hey is this the right thing to be doing??? " << std::endl;
1154 for (
int i = 2; i <= 3; ++i ) {
1166 znorm = std::sqrt( ( e1 * e1 ) + ( e2 * e2 ) + ( e3 * e3 ) );
1168 mvec(1,i) = e1/znorm;
1169 mvec(2,i) = e2/znorm;
1170 mvec(3,i) = e3/znorm;
1175 mvec(1,1) = mvec(2,2)*mvec(3,3) - mvec(2,3)*mvec(3,2);
1176 mvec(2,1) = -mvec(1,2)*mvec(3,3) + mvec(1,3)*mvec(3,2);
1177 mvec(3,1) = mvec(1,2)*mvec(2,3) - mvec(1,3)*mvec(2,2);
1185 std::cerr <<
"warning: all eigen values are equal" << std::endl;
1187 for (
int i = 1; i <= 3; ++i ) {
ocstream cerr(std::cerr)
Wrapper around std::cerr.
xyzVector< T > eigenvector_jacobi(xyzMatrix< T > const &a, T const &tol, xyzMatrix< T > &J)
Classic Jacobi algorithm for the eigenvalues and eigenvectors of a real symmetric matrix...
int count()
returns the number of points in this RmsData
void fixEigenvector(FArray2A< numeric::Real > m_v)
RMS functions imported from rosetta++.
Coordinate norm(Coordinate const &a)
void calc_rms_fast(float &rms_out, FArray2A< numeric::Real > xx, FArray2A< numeric::Real > yy, FArray1A< numeric::Real > ww, int npoints, numeric::Real ctx)
companion function for findUU ( it is optional ) computes the minimum RMS deviation beteen XX and YY ...
FArray1A & dimension(IR const &I_a)
Dimension by IndexRanges.
FArray2A: Fortran-Compatible 2D Argument Array.
FArray1A: Fortran-Compatible 1D Argument Array.
FArray1: Fortran-Compatible 1D Array Abstract Base Class.
utility::vector1< xyzVector< T > > FArray_to_vector_of_xyzvectors(ObjexxFCL::FArray2D< T > const &input)
convert an FArray2D to a vector of xyzVectors
void rsym_eigenval(ObjexxFCL::FArray2A< double > m, ObjexxFCL::FArray1A< double > ev)
computes the eigen values of a real symmetric 3x3 matrix
Fstring::size_type index(Fstring const &s, Fstring const &ss)
First Index Position of a Substring in an Fstring.
xyzVector: Fast (x,y,z)-coordinate numeric vector
FArray2A & dimension(IR const &I1_a, IR const &I2_a)
Dimension by IndexRange.
ObjexxFCL::FArray1D< double > xsp()
FArray2: Fortran-Compatible 2D Array Abstract Base Class.
static RmsData * instance()
T abs(T const &x)
std::abs( x ) == | x |
std::vector with 1-based indexing
RmsData is a class intended to replace the global rms_obj namespace from rosetta++. Initial implementation is with a singleton design pattern to mimic a global namespace from rosetta++.
ObjexxFCL::FArray2D< double > xm()
numeric::Real rms_wrapper_slow_and_correct(int natoms, FArray2D< numeric::Real > p1a, FArray2D< numeric::Real > p2a)
rosetta project type declarations. Should be kept updated with core/types.hh. This exists because num...
void MatrixMult(FArray2A< numeric::Real > A, int n, int np, int transposeA, FArray2A< numeric::Real > B, int m, int transposeB, FArray2A< numeric::Real > AxB_out)
void rmsfitca2(int npoints, ObjexxFCL::FArray2A< double > xx, ObjexxFCL::FArray2A< double > yy, ObjexxFCL::FArray1A< double > ww, int natsel, double &esq)
computes the rms between two weighted point vectors.
DimensionExpressionPow pow(Dimension const &dim1, Dimension const &dim2)
pow( Dimension, Dimension )
void BlankMatrixMult(FArray2A< numeric::Real > A, int n, int np, int transposeA, FArray2A< numeric::Real > B, int m, int transposeB, FArray2A< numeric::Real > AxB_out)
numeric::Real rms_wrapper(int natoms, FArray2D< numeric::Real > p1a, FArray2D< numeric::Real > p2a)
vector1: std::vector with 1-based indexing
xyzMatrix: Fast 3x3 xyz matrix template
void findUU(FArray2< numeric::Real > &XX, FArray2< numeric::Real > &YY, FArray1< numeric::Real > const &WW, int Npoints, FArray2< numeric::Real > &UU, numeric::Real &sigma3)
intended to rotate one protein xyz array onto another one such that the point-by-point rms is minimiz...
numeric::xyzMatrix< T > FArray_to_xyzmatrix(ObjexxFCL::FArray2D< T > const &input)
convert a 3x3 FArray 2D to an xyzMatrix
double det3(FArray2A< double > m)
determinant of a 3x3 matrix
xyzVector and xyzMatrix functions
ObjexxFCL::FArray1D< double > xse()
Fast (x,y,z)-coordinate numeric vector.
void rmsfitca3(int npoints, ObjexxFCL::FArray2A< double > xx0, ObjexxFCL::FArray2A< double > xx, ObjexxFCL::FArray2A< double > yy0, ObjexxFCL::FArray2A< double > yy, double &esq)
void COMAS(ObjexxFCL::FArray1A_double C, ObjexxFCL::FArray1A_double WT, int NAT, double &XC, double &YC, double &ZC)
T sign_transfered(S const &sigma, T const &x)
Sign transfered value.
numeric::Real calc_rms(utility::vector1< xyzVector< Real > > p1_coords, utility::vector1< xyzVector< Real > > p2_coords)
void rsym_evector(ObjexxFCL::FArray2A< double > m, ObjexxFCL::FArray1A< double > ev, ObjexxFCL::FArray2A< double > mvec)
Author: charlie strauss (cems) 2001 given original matrix plus its eigen values compute the eigen vec...
void rsym_rotation(ObjexxFCL::FArray2A< double > mm, ObjexxFCL::FArray2A< double > m, ObjexxFCL::FArray1A< double > ev, ObjexxFCL::FArray2A< double > rot)
finds a (proper) rotation matrix that minimizes the rms.
FArray2D: Fortran-Compatible 2D Array.
FArray1D: Fortran-Compatible 1D Array.