14 #if (defined _WIN32) && (!defined WIN_PYROSETTA)
15 #define ZLIB_WINAPI // REQUIRED FOR WINDOWS
23 #include <ObjexxFCL/FArray2D.hh>
28 #include <basic/Tracer.hh>
31 #include <utility/io/ozstream.hh>
32 #include <utility/exit.hh>
36 #include <numeric/xyz.functions.hh>
43 #include <utility/vector1.hh>
44 #include <numeric/model_quality/RmsData.hh>
50 using namespace ObjexxFCL;
52 static basic::Tracer
tr(
"protocols.evaluation.PCA",basic::t_info);
55 using namespace numeric::model_quality;
71 coords( d, i ) = xyz[ d-1 ];
83 Size const natoms( nres );
90 FArray1D_double transvec( 3 );
91 FArray1D_double ref_transvec( 3 );
92 reset_x( natoms, coords, weights, transvec );
93 reset_x( natoms, ref_coords, weights, ref_transvec );
105 Vector toCenter( transvec( 1 ), transvec( 2 ), transvec( 3 ));
106 Vector toFitCenter( ref_transvec( 1 ), ref_transvec( 2 ), ref_transvec( 3 ));
118 if (
tr.Trace.visible() ) {
121 for (
Size pos = 1; pos <= natoms; ++pos ) {
122 tr.Trace <<
" fit_coords vs pose_coords: ";
123 for (
Size d = 1; d <= 3; ++d )
tr.Trace << coords( d, pos ) <<
" ";
124 for (
Size d = 1; d <= 3; ++d )
tr.Trace << pose_coords( d, pos ) <<
" ";
125 tr.Trace << std::endl;
131 void superimpose(
Size natoms, FArray1_double
const& weights, FArray2_double& ref_coords, FArray2_double& coords ) {
134 FArray1D_double transvec( 3 );
135 reset_x( natoms, ref_coords, weights, transvec );
136 reset_x( natoms, coords, weights, transvec );
142 void superimpose(
Size natoms, FArray1_double
const& weights, FArray2_double& ref_coords, FArray2_double& coords,
Matrix &
R ) {
144 FArray1D_double transvec( 3 );
145 reset_x( natoms, ref_coords, weights, transvec );
146 reset_x( natoms, coords, weights, transvec );
158 void jacobi(
double a[6][6],
double d[],
double v[6][6],
int *nrot);
167 for ( i =0 ; i<nr; ++i ) {
168 for ( k =0 ; k<nr; ++k )
169 tr.Debug << a[i][k] <<
" ";
198 for(j=0; j<natoms; j++) {
201 for(r=0; r<
DIM; r++) {
204 x[j][r]+=R[r][c]*x_old[c];
210 for (
int i=0; i<natoms; i++ ) {
211 for (
int j = 0; j<
DIM; j++ ) {
212 x[i][j]+=transvec[j];
217 void reset_x(
Size n, FArray2_double& x, FArray1_double
const& wts, FArray1_double& transvec ) {
220 transvec = FArray1D_double( 3, 0.0 );
222 for (
Size j = 1; j <= n; ++j ) {
225 for (
Size d = 1; d <= dim; ++d ) {
226 transvec( d ) += x( d, j )*wts( j );
229 for (
Size d = 1; d <= dim; ++d ) {
230 transvec( d ) = -transvec( d )/mass;
232 for (
Size j = 1; j <= n; ++j ) {
233 for (
Size d = 1; d<= dim; ++d ) {
234 x( d, j ) += transvec( d );
241 utility::io::ozstream out( filename );
242 for (
Size i = 1; i <= n; ++i ) {
244 sprintf(buf,
"ATOM %5d %-4s%-3s %4d %8.3f%8.3f%8.3f%6.2f%6.2f", (
int) i,
"CA",
"ALA", (
int) i,
245 x( 1, i ) + transvec( 1 ),
246 x( 2, i ) + transvec( 2 ),
247 x( 3, i ) + transvec( 3 ), 1.0, 1.0 );
248 out << buf << std::endl;
259 xgmx =
new rvec[ natoms ];
260 xrefgmx =
new rvec[ natoms ];
261 weights_gmx =
new Real[ natoms ];
265 for (
Size i = 1; i<=natoms ; i++) {
266 weights_gmx[i-1] = weights( i );
267 for (
Size d = 1; d<=3; d++ ) {
268 xgmx[i-1][d-1]= coords(d, i);
269 xrefgmx[i-1][d-1]=ref_coords(d,i);
274 calc_fit_R( natoms, weights_gmx, xrefgmx, xgmx, Rot );
276 R.row_x(
Vector( Rot[ 0 ][ 0 ], Rot[ 0 ][ 1 ], Rot[ 0 ][ 2 ] ) );
277 R.row_y(
Vector( Rot[ 1 ][ 0 ], Rot[ 1 ][ 1 ], Rot[ 1 ][ 2 ] ) );
278 R.row_z(
Vector( Rot[ 2 ][ 0 ], Rot[ 2 ][ 1 ], Rot[ 2 ][ 2 ] ) );
280 for (
Size i = 1; i<=natoms ; i++) {
281 Vector x( coords( 1, i ), coords( 2, i), coords( 3, i ) );
283 coords( 1, i ) = x( 1 );
284 coords( 2, i ) = x( 2 );
285 coords( 3, i ) = x( 3 );
290 delete[] weights_gmx;
293 #define ROTATE(a,i,j,k,l) g=a[i][j];h=a[k][l];a[i][j]=g-s*(h+g*tau); \
294 a[k][l]=h+s*(g-h*tau);
315 double d[
DIM6 ],xnr,xpc;
321 for(i=0; i<
DIM6; i++) {
323 for(j=0; j<
DIM6; j++) {
330 for (
int i=0; i<
DIM;i++) {
331 for (
int j=0; j<
DIM; j++) u[i][j]=0;
335 for ( n=0; n<natoms; n++ ) {
336 if ( (mn = weights[ n ]) != 0.0 ) {
337 for ( c=0; c<
DIM; c++) {
339 for(r=0; (r<
DIM); r++) {
349 for(r=0; r<
DIM6; r++) {
350 for(c=0; c<=r; c++) {
351 if (r>=DIM && c<DIM) {
352 omega[r][
c]=u[r-
DIM][
c];
353 omega[
c][r]=u[r-
DIM][
c];
362 jacobi( omega,d,om,&irot);
376 for(i=0; i<
DIM6; i++)
382 for(i=0; i<
DIM; i++) {
383 vh[j][i]=sqrt(2.0)*om[i][index];
384 vk[j][i]=sqrt(2.0)*om[i+
DIM][index];
394 oprod(vh[0],vh[1],vh[2]);
395 oprod(vk[0],vk[1],vk[2]);
402 R[r][c] = vk[0][r]*vh[0][c] +
408 #define ROTATE(a,i,j,k,l) g=a[i][j];h=a[k][l];a[i][j]=g-s*(h+g*tau); \
409 a[k][l]=h+s*(g-h*tau);
415 void jacobi(
double a[6][6],
double d[],
double v[6][6],
int *nrot)
419 double tresh,theta,tau,
t,sm,s,h,g,
c;
423 for (ip=0; ip<n; ip++) {
424 for (iq=0; iq<n; iq++) v[ip][iq]=0.0;
427 for (ip=0; ip<n;ip++) {
428 b[ip]=d[ip]=a[ip][ip];
432 for (i=1; i<=50; i++) {
434 for (ip=0; ip<n-1; ip++) {
435 for (iq=ip+1; iq<n; iq++)
436 sm += fabs(a[ip][iq]);
445 for (ip=0; ip<n-1; ip++) {
446 for (iq=ip+1; iq<n; iq++) {
447 g=100.0*fabs(a[ip][iq]);
448 if (i > 4 && fabs(d[ip])+g == fabs(d[ip])
449 && fabs(d[iq])+g == fabs(d[iq]))
451 else if (fabs(a[ip][iq]) > tresh) {
453 if (fabs(h)+g == fabs(h))
456 theta=0.5*h/(a[ip][iq]);
457 t=1.0/(fabs(theta)+sqrt(1.0+theta*theta));
458 if (theta < 0.0) t = -
t;
469 for (j=0; j<ip; j++) {
472 for (j=ip+1; j<iq; j++) {
475 for (j=iq+1; j<n; j++) {
478 for (j=0; j<n; j++) {
485 for (ip=0; ip<n; ip++) {