Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InteratomicVarianceMatrix.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file protocols/jd2/Job.hh
11 /// @brief header file for ThreadingJob classes, part of August 2008 job distributor as planned at RosettaCon08. This file is responsible for three ideas: "inner" jobs, "outer" jobs (with which the job distributor works) and job container (currently just typdefed in the .fwd.hh)
12 /// @author Steven Lewis smlewi@gmail.com
13 
14 
16 // AUTO-REMOVED #include <protocols/toolbox/superimpose.hh>
17 
18 #include <core/types.hh>
19 // AUTO-REMOVED #include <ObjexxFCL/FArray3D.hh>
20 #include <ObjexxFCL/FArray2D.hh>
21 // AUTO-REMOVED #include <utility/excn/Exceptions.hh>
22 // AUTO-REMOVED #include <core/pose/Pose.hh>
23 // AUTO-REMOVED #include <core/conformation/Residue.hh>
24 
25 
26 // ObjexxFCL Headers
27 
28 // Utility headers
29 #include <basic/Tracer.hh>
30 #include <utility/io/ozstream.hh>
31 #include <utility/exit.hh>
32 // AUTO-REMOVED #include <numeric/model_quality/rms.hh>
33 // AUTO-REMOVED #include <numeric/model_quality/maxsub.hh>
34 
35 //// C++ headers
36 #include <string>
37 #include <iostream>
38 
39 #include <numeric/model_quality/RmsData.hh>
40 #include <ObjexxFCL/FArray3.hh>
41 
42 
43 namespace protocols {
44 namespace toolbox {
45 
46 using namespace ObjexxFCL;
47 
48 static basic::Tracer tr("protocols.evaluation.PCA",basic::t_info);
49 
50 using namespace core;
51 using namespace numeric::model_quality; //for rms functions
52 
53 ///@brief
54 //compute matrix of distance variances:
55 // in: coords : 3 x natoms x ndecoys
56 // out: ivm_ : natoms x natoms with ivm(i,j) = VAR_n ( | x_i( n ) - x_j ( n ) | ) n==decoys, i,j=atoms
57 void InteratomicVarianceMatrix::init( Size atoms_in, Size n_decoys, ObjexxFCL::FArray3_double const& coords ) {
58  n_atoms_ = atoms_in;
59  ivm_.redimension( n_atoms_, n_atoms_, 0.0 );
60  Real const invn( 1.0/n_decoys );
61  tr.Debug << "IVM-Matrix \n";
62  for ( Size i = 1; i <= n_atoms(); i++ ) {
63  for ( Size j = i+1; j<=n_atoms(); j++ ) {
64  Real var( 0.0 );
65  Real av( 0.0 );
66 
67  for ( Size n = 1; n<=n_decoys; n++ ) {
68  Vector xi( coords( 1, i, n ), coords( 2, i, n ), coords( 3, i, n ));
69  Vector xj( coords( 1, j, n ), coords( 2, j, n ), coords( 3, j, n ));
70  Real dist = xi.distance(xj);
71  var += dist * dist * invn;
72  av += dist * invn;
73  }
74  ivm_( j, i ) = var - av*av;
75  ivm_( i, j ) = ivm_( j, i);
76  tr.Debug << i << " " << j << " " << ivm_( i, j ) << "\n";
77  }
78  }
79  tr.Debug << std::endl;
80 
81  utility::io::ozstream os("ivm.dat");
82  for ( Size i = 1; i <= n_atoms(); i++ ) {
83  for ( Size j = 1; j<=n_atoms(); j++ ) os << ivm_( i, j ) << " ";
84  os << std::endl;
85  }
86 }
87 
88 
89 ///@brief compute order parameter for atom i, defined as number of j atoms whose ivm(i,j)<epsilon^2
90 void InteratomicVarianceMatrix::order_parameter( Real epsilon, ObjexxFCL::FArray1_double& T ) {
91  Real const epsilon2( epsilon*epsilon );
92  tr.Debug << "T( " << epsilon << " )\n";
93  for ( Size i = 1; i<=n_atoms(); i++ ) {
94  T( i ) = 0.0;
95  Real invn = 1.0/n_atoms();
96  for ( Size j = 1; j<=n_atoms(); j++ ) {
97  if ( ivm_( i, j) < epsilon2 ) T( i ) += invn;
98  }
99  tr.Debug << i << " " << T( i ) << "\n";
100  }
101  tr.Debug << std::endl;
102 }
103 
104 ///@brief compute order parameter for atom i, defined as number of j atoms whose ivm(i,j)<epsilon^2
105 Real InteratomicVarianceMatrix::kurtosis( ObjexxFCL::FArray1_double& T ) {
106  Real invn = 1.0/n_atoms();
107  Real second_moment = 0.0;
108  Real fourth_moment = 0.0;
109  Real av = 0.0;
110  for ( Size j = 1; j<=n_atoms(); j++ ) {
111  av += T( j )*invn;
112  }
113  for ( Size j = 1; j<=n_atoms(); j++ ) {
114  Real x = T( j ) - av;
115  Real x2 = x*x;
116  second_moment += x2*invn;
117  fourth_moment += x2 * x2 *invn;
118  }
119  return fourth_moment / (second_moment*second_moment);
120 }
121 
123  Real depsilon = ( ub - lb ) / ngrid;
124  Real epsilon = lb;
125  FArray1D_double grid( ngrid, 0.0 );
126  FArray1D_double kurt( ngrid, 0.0 );
127 
128  FArray2D_double T( n_atoms(), ngrid, 0.0 );
129  tr.Info << "kurtosis computed:\n";
130  for ( Size i = 1; i <= ngrid; i++ ) {
131  FArray1P_double Tslice( T( 1, i ), n_atoms() );
132  grid( i ) = epsilon;
133  order_parameter( epsilon, Tslice );
134  kurt( i ) = kurtosis( Tslice );
135  tr.Info << epsilon << " " << kurt( i ) << "\n";
136  epsilon += depsilon;
137  }
138  tr.Info << std::endl;
139  {
140  utility::io::ozstream os("order.dat");
141  for ( Size j = 1; j<= n_atoms(); j++ ) {
142  for ( Size i = 1; i<= ngrid; i++ ) os << T( j, i ) << " ";
143  os << "\n";
144  }
145  }
146  {
147  utility::io::ozstream os("kurt.dat");
148  for ( Size i = 1; i<= ngrid; i++ ) os << grid( i ) << " " << kurt( i ) << "\n";
149  }
150 }
151 
152 } //evaluation
153 } //protocols
154 
155