Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PcsDataLanthanide.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  //////////////////////////////////////////////
11  /// @begin
12  ///
13  /// @file protocols/scoring/methods/pcs2/PcsDataLanthanide.cc
14  ///
15  /// @brief
16  ///
17  /// @detailed
18  ///
19  /// @param
20  ///
21  /// @return
22  ///
23  /// @remarks
24  ///
25  /// @references
26  ///
27  /// @authorsv Christophe Schmitz
28  ///
29  /// @last_modified February 2010
30  ////////////////////////////////////////////////
31 
32 
33 // Unit headers
35 
36 // Package headers
39 // AUTO-REMOVED #include <protocols/scoring/methods/pcs2/PcsInputCenter.hh>
40 
41 // Project headers
42 #include <basic/Tracer.hh>
43 #include <basic/options/option.hh>
44 #include <basic/options/keys/PCS.OptionKeys.gen.hh>
45 
46 // Utility headers
47 #include <utility/exit.hh>
48 
49 #include <utility/vector1.hh>
50 
51 
52 // Numeric headers
53 
54 // Objexx headers
55 
56 // C++ headers
57 
58 namespace protocols{
59 namespace scoring{
60 namespace methods{
61 namespace pcs2{
62 
63 using namespace ObjexxFCL;
64 
65 basic::Tracer TR_PcsDataLanthanide("protocols.scoring.methods.pcs.PcsDataLanthanide");
66 
68 }
69 
71  filename_(""), weight_(0)
72 {
73  utility_exit_with_message( "You shouldn't call the empty constructor for PcsDataLanthanide class" );
74 }
75 
77  filename_(other.filename_), weight_(other.weight_), svd_s_(other.svd_s_)
78 {
79 
80  // TR_PcsDataLanthanide << " () called" << std::endl;
81 
82  n_pcs_ = other.n_pcs_;
83  A_index_ = other.A_index_;
84  // fstyle_A_ = other.fstyle_A_;
85  cstyle_A_ = other.cstyle_A_;
86  // fstyle_b_ = other.fstyle_b_;
87  cstyle_b_ = other.cstyle_b_;
95 
96 }
97 
100  return weight_;
101 }
102 
103 
106  return individual_scale_;
107 }
108 
109 
112  return normalization_factor_;
113 }
114 
115 
119 }
120 
121 
124 {
125 
126  // TR_PcsDataLanthanide << " = called" << std::endl;
127 
128  if ( this != &other ) {
129  n_pcs_ = other.n_pcs_;
130  A_index_ = other.A_index_;
131  // fstyle_A_ = other.fstyle_A_;
132  cstyle_A_ = other.cstyle_A_;
133  // fstyle_b_ = other.fstyle_b_;
134  cstyle_b_ = other.cstyle_b_;
137  svd_s_ = other.svd_s_;
143  }
144  return *this;
145 }
146 
147 void
149  core::Size i, j;
150  for(i = 1; i <= A_index_.size(); ++i){
151  for(j = 1; j <= 5; ++j){
152  cstyle_A_[i][j] = A_all[A_index_[i]][j];
153  }
154  }
155  svd_s_.set_matrix_A(cstyle_A_);
156  //svd_s_.set_matrix_A_point(&cstyle_A_);
157 }
158 
159 void
161  core::Size i, j;
162  for(i = 1; i <= A_index_.size(); ++i){
163  for(j = 1; j <= 5; ++j){
164  cstyle_A_[i][j] = A_all[A_index_[i]][j];
165  }
166  }
167 }
168 
169 
172 
173  core::Real score;
174 
175  if(weight_ == 0){ //This is the individual weight for each lanthanide
176  return 0;
177  }
178 
179  svd_s_.run_decomp_svd();
180  score = svd_s_.run_score_svd_without_solving();
181  return(score*weight_/normalization_factor_);
182 }
183 
184 void
186 
187  // FArray1D< core::Real > const & X(svd_s_.get_svd_solution());
188  utility::vector1<core::Real> const & f (svd_s_.get_svd_solution());
189  pcs_t.reset_tensor(f[1], f[2], f[3], f[4], f[5]);
190  // pcs_t.reset_tensor(X(1), X(2), X(3), X(4), X(5));
191 
192 }
193 
196 
197  core::Real score;
198 
199  //#define FAST_SCORING
200  //FAST SCORING is actually not faster (nor slower)
201  //FAST SCORING gives the PCS score without actually solving Ax = b
202  //(but still, the matrix has to be decomposed.
203  //So FAST_SCORING doesn't give the tensor parameters...
204  //FAST SCORING might become handy when working on unassigned data, that's why I keep it.
205 
206  if(weight_ == 0){ //This is the individual weight for each lanthanide
207  return 0;
208  }
209 
210  svd_s_.run_decomp_svd();
211 
212 #ifdef FAST_SCORING
213  score = svd_s_.run_score_svd_without_solving();
214  pcs_t.reset_tensor(0, 0, 0, 0, 0); //Junk tensor to avoid warning at compilation
215 #else
216  svd_s_.run_solve_svd();
217  score = svd_s_.run_score_svd_on_matrix(cstyle_A_);
218  // The 2 following calls are not that necessary for just scoring
219  // FArray1D<core::Real> const & f (svd_s_.get_svd_solution());
220 
221  utility::vector1<core::Real> const & f (svd_s_.get_svd_solution());
222  // pcs_t.reset_tensor(f(1), f(2), f(3), f(4), f(5));
223  pcs_t.reset_tensor(f[1], f[2], f[3], f[4], f[5]);
224 #endif
225 
226  //Weight is the individual weight for each lanthanide
227 
228  return(score*weight_/normalization_factor_);
229 }
230 
231 void
233 
234  // core::Real score;
235  svd_s_.run_decomp_svd();
236  svd_s_.run_solve_svd();
237  // FArray1D<core::Real> f (svd_s_.get_svd_solution());
238  // pcs_t.reset_tensor(f(1), f(2), f(3), f(4), f(5));
239  utility::vector1<core::Real> const & f (svd_s_.get_svd_solution());
240  pcs_t.reset_tensor(f[1], f[2], f[3], f[4], f[5]);
241 }
242 
243 
244 
245 
248  return (n_pcs_);
249 }
250 
253  return(A_index_);
254 }
255 
258  return(cstyle_b_);
259 }
260 
261 
265 }
266 
269  return(cstyle_A_);
270 }
271 
272  /*
273 const FArray1D< core::Real > &
274 PcsDataLanthanide::get_fstyle_b() const{
275  return(fstyle_b_);
276 }
277 
278 const FArray2D< core::Real > &
279 PcsDataLanthanide::get_fstyle_A() const{
280  return(fstyle_A_);
281 }
282  */
283 
284 bool
286  core::Size residue_number(pcs_i_l.get_residue_num());
287 
288  if(start == 0){
289  return false;
290  }
291 
292  if((residue_number >= start)&&(residue_number <= end)){
293  return false;
294  }
295  return true;
296 }
297 
300  core::Size i;
301  core::Size n_pcs_reduced(0);
302 
303  for (i = 1; i <= pcs_i_l_v.size(); ++i){
304  PcsInputLine pcs_i_l (pcs_i_l_v[i]);
305  if(do_I_skip(pcs_i_l, start, end)){
306  continue;
307  }
308  n_pcs_reduced ++;
309  }
310  // std::cerr<< n_pcs_reduced << " instead of " << pcs_i_l_v.size() << std::endl;
311  return(n_pcs_reduced);
312 }
313 
314 
316  core::Real const weight,
319  core::Size end,
320  core::Real individual_scale):
321  filename_(filename), weight_(weight), svd_s_(basic::svd::SVD_Solver(reduced_size(pcs_i_l_v, start, end), 5))
322 {
323 
324  // TR_PcsDataLanthanide << " constructor called" << std::endl;
325  using namespace core;
326  using namespace basic::options;
327  using namespace basic::options::OptionKeys;
328 
329  core::Size i;
330  core::Size M, N;
331  // utility::vector1<PcsInputLine>::iterator it;
332  individual_scale_ = individual_scale;
333 
334  n_pcs_ = reduced_size(pcs_i_l_v, start, end);
335  A_index_.resize(n_pcs_);
336 
337  M = n_pcs_;
338  N = 5;
339 
340  svd_s_ = basic::svd::SVD_Solver(M, N);
342  // fstyle_A_.dimension(M, N);
343  // fstyle_b_.dimension(M);
344 
345  cstyle_b_.resize(M);
346  cstyle_b_individual_scale_.resize(M);
347 
348  cstyle_A_.resize(M);
349  for(i = 1; i <= M; i++){
350  (cstyle_A_[i]).resize(N);
351  }
352 
353  normalization_1_ = 0;
354  core::Real sum (0);
355 
356  core::Size reduced_i(1);
357  for (i = 1; i <= pcs_i_l_v.size(); ++i){
358  PcsInputLine & pcs_i_l = pcs_i_l_v[i];
359  if(do_I_skip(pcs_i_l, start, end)){
360  continue;
361  }
362  vec_temp.push_back(pcs_i_l.get_PCS_experimental());
363  // fstyle_b_(i) = pcs_i_l.get_PCS_experimental();
364  cstyle_b_[reduced_i] = pcs_i_l.get_PCS_experimental();
365 
366  if(individual_scale >= 0.0){
367  if(i == 1){
368  std::cerr << "WARNING: INDIVIDUAL_NOARMALIZATION ON (message2) with " << individual_scale << std::endl;
369  }
370  cstyle_b_individual_scale_[reduced_i] = 1.0 / (pcs_i_l.get_PCS_experimental() * pcs_i_l.get_PCS_experimental() + individual_scale) ;
372 
373  }
374  else{
376  }
377 
378  sum += pcs_i_l.get_PCS_experimental();
379  reduced_i++;
380  }
381  svd_s_.set_vector_b(vec_temp);
383 
385 
386  core::Real average(sum/M);
387 
388  normalization_2_ = 0;
389  reduced_i = 1;
390  for (i = 1; i <= pcs_i_l_v.size(); ++i){
391  if(do_I_skip(pcs_i_l_v[i], start, end)){
392  continue;
393  }
394  normalization_2_ += (cstyle_b_[reduced_i] - average) * (cstyle_b_[reduced_i] - average);
395  reduced_i++;
396  }
397  normalization_2_ = sqrt( normalization_2_ / M );
398 
399  if( option[ basic::options::OptionKeys::PCS::normalization_id ].user() ){
400  core::Size norma_id (option[ basic::options::OptionKeys::PCS::normalization_id ]());
401 
402  switch (norma_id){
403  case 1:{
404  TR_PcsDataLanthanide << "Using Normalization '1': " << normalization_1_ << ". Normalize each data set by SQRT( SUM( PCSexp(i)^2 ) ) for " << filename_ << std::endl;
406  break;
407  }
408  case 2:{
409  TR_PcsDataLanthanide << "Using Normalization '2': " << normalization_2_ << ". Normalize each data set by Standard Deviation for " << filename_ << std::endl;
411  break;
412  }
413  case 3:{
414  TR_PcsDataLanthanide << "Using Normalization '3': " << normalization_3_ << ". Normalize each data set by SQRT( SUM( PCSexp(i)^2 ) / N) for " << filename_ << std::endl;
416  break;
417  }
418  default:{
419  TR_PcsDataLanthanide << "Normalization '"<< norma_id << "' id not recognized " << std::endl;
420  utility_exit_with_message("You should use a valid normalization id ('1' or '2' or '3')");
421  break;
422  }
423  }
424  }
425  else{
426  normalization_factor_ = 1.0;
427  }
428 
430 
431  // std::cerr << "OK" << std::endl;
432 }
433 
436  return (filename_);
437 }
438 
439 void
441  A_index_[j] = index;
442 }
443 
444 std::ostream &
445 operator<<(std::ostream& out, const PcsDataLanthanide &me){
446  core::Size i; //, j;
447  out << std::setprecision(4) << std::endl;
448  out << " Filename : " << me.get_filename() << std::endl;
449  out << " Number of pcs : " << me.get_n_pcs() << std::endl;
450  out << " b vector (pcs values) : " << std::endl;
451 
452  for ( i = 1; i <= me.get_n_pcs(); ++i){
453  out << " " << std::setw(4) << i << ":"<< std::setw(10) <<me.cstyle_b_[i] << std::endl;
454  }
455  out << std::endl;
456 
457  out << " A_index : " << std::endl;
458  for ( i = 1; i <= me.get_n_pcs(); ++i){
459  out << " " << std::setw(4) << i << ":" << std::setw(4) <<me.A_index_[i];
460  out << std::endl;
461  }
462  /*
463  out << " Matrix A:"<< std::endl;
464  for( i = 1; i <= me.n_pcs_ ; ++i ){
465  out << " " << std::setw(4) << i << ":";
466  for (j = 1; j <= 5; ++j){
467  out << " " << std::setw(12) << me.fstyle_A_( i, j);
468  }
469  out << std::endl;
470  }
471  */
472  return out;
473 }
474 
475 }//namespcacs PCS
476 }//namespace methods
477 }//namespace scoring
478 }//namespace protocols