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 ) {
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;
634 double const & offset_val,
655 double XPC, YPC, ZPC, XEC, YEC, ZEC;
660 COMAS(xx,ww,npoints,XPC,YPC,ZPC);
661 COMAS(yy,ww,npoints,XEC,YEC,ZEC);
663 for ( i = 1; i <= npoints; ++i ) {
667 xx(3,i) -= offset_val;
668 yy(3,i) += offset_val;
672 for ( k = 1; k <= 3; ++k ) {
673 for ( j = 1; j <= 3; ++
j ) {
675 for ( i = 1; i <= npoints; ++i ) {
676 temp1 += ww(i)*yy(k,i)*xx(j,i);
678 m_moment(k,j) = temp1 /(temp3);
681 det =
det3(m_moment);
696 for ( i = 1; i <= 3; ++i ) {
697 for ( j = i; j <= 3; ++
j ) {
698 rr_moment(j,i) = rr_moment(i,j) =
699 m_moment(1,i)*m_moment(1,j) +
700 m_moment(2,i)*m_moment(2,j) +
701 m_moment(3,i)*m_moment(3,j);
711 if ( ev(2) > ev(3) ) {
712 if ( ev(3) > ev(1) ) {
718 if ( ev(2) > ev(1) ) {
748 for ( i = 1; i <= npoints; ++i ) {
750 xx(3,i) += offset_val;
751 yy(3,i) -= offset_val;
753 for ( j = 1; j <= 3; ++
j ) {
754 t(j) = R(j,1)*yy(1,i) + R(j,2)*yy(2,i) + R(j,3)*yy(3,i);
767 handedness*std::sqrt(
std::abs(ev(3)));
774 for ( i = 1; i <= npoints; ++i ) {
775 for ( j = 1; j <= 3; ++
j ) {
776 rms_sum += ww(i)*( ( yy(j,i) * yy(j,i) ) + ( xx(j,i) * xx(j,i) ) );
784 esq = std::sqrt(
std::abs( rms_sum - ( 2.0 * rms_ctx ) ) / natsel );
813 double rms_ctx,rms2_sum;
823 mass = rmsdata->
count();
824 double xre = rmsdata->
xre();
825 double xrp = rmsdata->
xrp();
834 come(1) = xse(1)/mass;
835 come(2) = xse(2)/mass;
836 come(3) = xse(3)/mass;
838 comp(1) = xsp(1)/mass;
839 comp(2) = xsp(2)/mass;
840 comp(3) = xsp(3)/mass;
845 for (
int k = 1; k <= 3; ++k ) {
846 for (
int j = 1;
j <= 3; ++
j ) {
847 m_moment(k,
j) = xm(k,
j)/mass - come(k)*comp(
j);
851 det =
det3(m_moment);
871 for (
int i = 1; i <= 3; ++i ) {
872 for (
int j = i;
j <= 3; ++
j ) {
873 rr_moment(
j,i) = rr_moment(i,
j) =
874 m_moment(1,i)*m_moment(1,
j) +
875 m_moment(2,i)*m_moment(2,
j) +
876 m_moment(3,i)*m_moment(3,
j);
887 if ( ev(2) > ev(3) ) {
888 if ( ev(3) > ev(1) ) {
894 if ( ev(2) > ev(1) ) {
913 for (
int i = 1; i <= npoints; ++i ) {
914 for (
int k = 1; k <= 3; ++k ) {
915 yy(k,i) = yy0(k,i)-come(k);
916 xx(k,i) = xx0(k,i)-comp(k);
918 for (
int j = 1;
j <= 3; ++
j ) {
924 t(
j) = r(
j,1)*yy(1,i) + r(
j,2)*yy(2,i) + r(
j,3)*yy(3,i);
939 handedness*std::sqrt(
std::abs(ev(3)));
945 temp1 = ( come(1) * come(1) ) + ( come(2) * come(2) ) + ( come(3) * come(3) ) +
946 ( comp(1) * comp(1) ) + ( comp(2) * comp(2) ) + ( comp(3) * comp(3) );
948 rms2_sum = (xre + xrp)/mass - temp1;
954 esq = std::sqrt(
std::abs(rms2_sum-2.0*rms_ctx));
965 m(1,3)*( m(2,1)*m(3,2) - m(2,2)*m(3,1) ) -
966 m(2,3)*( m(1,1)*m(3,2) - m(1,2)*m(3,1) ) +
967 m(3,3)*( m(1,1)*m(2,2) - m(1,2)*m(2,1) );
981 double xx,yy,zz,xy,xz,yz;
983 std::complex< double > f1,f2,f3,f4,f5;
985 static std::complex< double >
const unity = std::complex< double >(1.0,0.0);
986 static std::complex< double >
const sqrt_3i =
987 std::sqrt( 3.0 ) * std::complex< double >(0.0,1.0);
999 b = -xx*zz-xx*yy-yy*zz+xy*xy+xz*xz+yz*yz;
1000 c = xx*yy*zz-xz*xz*yy-xy*xy*zz-yz*yz*xx+2*xy*xz*yz;
1011 if ( norm > 1.0E50 ) {
1014 c /= norm * norm *
norm;
1021 double const a2 = a *
a;
1022 double const a3 = a * a *
a;
1029 s0 = ( -12.0 * ( b * b *
b ) ) - ( 3.0 * ( b *
b ) * a2 ) +
1030 ( 54.0 * c * b *
a ) + ( 81.0 * ( c * c ) ) + ( 12.0 * c * a3 );
1033 f1 = b*a/6.0 + c/2.0 + a3/27.0 + std::sqrt(s0*unity)/18.0;
1037 f3 = (-b/3.0 - a2/9.0)/f2;
1041 f5 = sqrt_3i * (f2+f3);
1046 ev(1) = norm*(ev(1)+s0 );
1048 ev(2) = (-f4+f5).
real();
1049 ev(2) = norm*(ev(2)*0.5 + s0 );
1050 ev(3) = (-f4-f5).
real();
1051 ev(3) = norm*(ev(3)*0.5 + s0);
1074 for (
int i = 1; i <= 2; ++i ) {
1078 for (
int j = 1;
j <= 3; ++
j ) {
1080 for (
int k = 1; k <= 3; ++k ) {
1081 temp(
j,i) += mvec(k,i)*
mm(
j,k);
1087 temp(1,3) = temp(2,1)*temp(3,2) - temp(2,2)*temp(3,1);
1088 temp(2,3) = -temp(1,1)*temp(3,2) + temp(1,2)*temp(3,1);
1089 temp(3,3) = temp(1,1)*temp(2,2) - temp(1,2)*temp(2,1);
1091 for (
int i = 1; i <= 3; ++i ) {
1092 for (
int j = 1;
j <= 3; ++
j ) {
1094 for (
int k = 1; k <= 3; ++k ) {
1095 rot(
j,i) += temp(i,k)*mvec(
j,k);
1114 double xx,yy,xy,zx,yz;
1115 double e1,e2,e3,znorm;
1124 if ( ev(1) != ev(2) ) {
1126 for (
int i = 1; i <= 2; ++i ) {
1138 znorm = std::sqrt( ( e1 * e1 ) + ( e2 * e2 ) + ( e3 * e3 ) );
1140 mvec(1,i) = e1/znorm;
1141 mvec(2,i) = e2/znorm;
1142 mvec(3,i) = e3/znorm;
1147 mvec(1,3) = mvec(2,1)*mvec(3,2) - mvec(2,2)*mvec(3,1);
1148 mvec(2,3) = -mvec(1,1)*mvec(3,2) + mvec(1,2)*mvec(3,1);
1149 mvec(3,3) = mvec(1,1)*mvec(2,2) - mvec(1,2)*mvec(2,1);
1157 if ( ev(2) != ev(3) ) {
1158 std::cerr <<
" hey is this the right thing to be doing??? " << std::endl;
1160 for (
int i = 2; i <= 3; ++i ) {
1172 znorm = std::sqrt( ( e1 * e1 ) + ( e2 * e2 ) + ( e3 * e3 ) );
1174 mvec(1,i) = e1/znorm;
1175 mvec(2,i) = e2/znorm;
1176 mvec(3,i) = e3/znorm;
1181 mvec(1,1) = mvec(2,2)*mvec(3,3) - mvec(2,3)*mvec(3,2);
1182 mvec(2,1) = -mvec(1,2)*mvec(3,3) + mvec(1,3)*mvec(3,2);
1183 mvec(3,1) = mvec(1,2)*mvec(2,3) - mvec(1,3)*mvec(2,2);
1191 std::cerr <<
"warning: all eigen values are equal" << std::endl;
1193 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)
StringOptionKey const realign
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)
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
void rmsfitca2(int npoints, ObjexxFCL::FArray2A< double > xx, ObjexxFCL::FArray2A< double > yy, ObjexxFCL::FArray1A< double > ww, int natsel, double &esq, double const &offset_val, bool const realign)
computes the rms between two weighted point vectors.
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.
FileVectorOptionKey const t
FArray1D: Fortran-Compatible 1D Array.