Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TensorsOptimizerSvd.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/TensorsOptimizerSvd.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
37 
38 // Package headers
39 
40 // Project headers
41 #include <basic/Tracer.hh>
42 
43 // Utility headers
44 #include <utility/exit.hh>
45 
46 // Numeric headers
47 #include <numeric/constants.hh>
48 
49 // Objexx headers
50 
51 // C++ headers
52 // AUTO-REMOVED #include <iomanip>
53 
55 #include <utility/vector1.hh>
56 
57 
58 namespace protocols{
59 namespace scoring{
60 namespace methods{
61 namespace pcs2{
62 
63 using namespace core::optimization;
64 
65 basic::Tracer TR_TensorsOptimizerSvd("protocols.scoring.methods.pcs.TensorsOptimizerSvd");
66 
67  /*
68 TensorsOptimizerSvd::TensorsOptimizerSvd():
69  pcs_d_c_(PcsDataCenter())
70 {
71 
72  utility_exit_with_message("You shouldn't call the empty constructor for class TensorsOptimizerSvd");
73 }
74  */
75 
77  pcs_d_c_(pcs_d_c)
78 {
79 }
80 
82 }
83 
84 
85 bool
87 
88  // return false;
89 
90  core::Real limit(4000);
91  core::Size i;
92  core::Size n_la;
93 
94  n_la = pcs_d_c_.get_n_lanthanides();
95 
96  core::Real xM(vars[1]);
97  core::Real yM(vars[1]);
98  core::Real zM(vars[1]);
99  if( (xM*xM + yM*yM + zM*zM) > 90000){
100  return true;
101  }
102 
103  for (i = 1; i <= n_la; i++){
104  core::Real Xxx(vars[3 + 5*(i-1) + 1]);
105  core::Real Xxy(vars[3 + 5*(i-1) + 2]);
106  core::Real Xxz(vars[3 + 5*(i-1) + 3]);
107  core::Real Xyy(vars[3 + 5*(i-1) + 4]);
108  core::Real Xyz(vars[3 + 5*(i-1) + 5]);
109  if((fabs(Xxx) + fabs(Xxy) + fabs(Xxz) + fabs(Xyy) + fabs(Xyz)) > limit){
110  return true;
111  }
112  }
113  return false;
114 }
115 
118  core::Size i; //, j, idx;
119  core::Size n_la;//, n_pcs;
120  core::Real score; //PCS_calc, PCS_exp, score_la;;
122 
123 
124  score = 0;
125  n_la = pcs_d_c_.get_n_lanthanides();
126 
127  //those are the lanthanides current coordinates.
128  core::Real xM(vars[1]);
129  core::Real yM(vars[2]);
130  core::Real zM(vars[3]);
131 
132  PcsTensor pcs_t(0, 0, 0, 0, 0, "");
133 
135  // std::cerr << "updating from func" << std::endl;
136  // std::cerr << std::setprecision(20) << xM << " " << yM << " " << zM << std::endl;
138 
139  if(n_la != pcs_d_l_vec.size()){
140  utility_exit_with_message("The number of lanthanides is inconsistent");
141  }
142 
143 
144  // utility::vector1< utility::vector1<core::Real> > const & A_all(pcs_d_c_.get_A_all());
145 
146 
147  for (i = 1; i <= n_la; i++){
148  PcsDataLanthanide & pcs_d_l(pcs_d_l_vec[i]);
149 
150  // core::Real weight(pcs_d_l.get_weight());
151  // score += pcs_d_l.calculate_cost_only_with_svd();
152 
153  score += pcs_d_l.calculate_tensor_and_cost_with_svd(pcs_t);
154  //score += pcs_d_l.calculate_cost_only_with_svd();// * weight * pcs_d_l.get_normalization_factor_inversed();
155  //weight and normalization_factor allready applied in cost_with_svd function!
156 
157  }
158 
159  return(score);
160 }
161 
162 void
165  ) const{
166 
167  core::Size i;
168  core::Real delta(0.0001);
169 
170  for(i = 1; i <= vars.size(); i++){
171  core::optimization::Multivec vars_bis_pd (vars);
172  core::optimization::Multivec vars_bis_md (vars);
173  vars_bis_pd[i] += delta;
174  vars_bis_md[i] -= delta;
175  core::Real value_pd (func(vars_bis_pd) / delta / 2.0);
176  core::Real value_md (func(vars_bis_md) / delta / 2.0);
177  dE_dvars[i] = value_pd - value_md;
178  }
179 }
180 
181 void
184  ) const{
185 
186  dfunc_exact(vars, dE_dvars);
187  //dfunc_numeric(vars, dE_dvars);
188  /*
189  core::Size i;
190  std::cerr << "df_exact ";
191  for(i = 1; i <= vars.size(); i++){
192  std::cerr << std::setw(8) << dE_dvars[i] << " " ;
193  }
194  std::cerr << std::endl;
195 
196  dfunc_numeric(vars, dE_dvars);
197  std::cerr << "df_numer ";
198  for(i = 1; i <= vars.size(); i++){
199  std::cerr << std::setw(8)<< dE_dvars[i] << " " ;
200  }
201  std::cerr << std::endl;
202  */
203 }
204 
205 
206 
209  return(func(vars));
210 }
211 
212 void
215  ) const{
216  core::Size i, j, idx;
217  core::Size n_la, n_pcs;
218  core::Real x, y, z, xS, yS, zS;
219  core::Real PCS_calc, PCS_exp, common2, common3;
220  core::Real r5, r2, r3;
221 
223 
224  n_la = pcs_d_c_.get_n_lanthanides();
225 
226  //lets' init everyone to zero because we are going to use +=
227  for (i = 1; i <= dE_dvars.size(); i++){
228  dE_dvars[i] = 0;
229  }
230 
232  vec_temp.resize(dE_dvars.size(), 0);
233 
234  //those are the lanthanides current coordinates.
235  core::Real xM(vars[1]);
236  core::Real yM(vars[2]);
237  core::Real zM(vars[3]);
238 
240 
242 
246 
247 
248  if(n_la != pcs_d_l_vec.size()){
249  utility_exit_with_message("The number of lanthanides is inconsistent");
250  }
251 
252 
253  PcsTensor pcs_t(0, 0, 0, 0, 0, "");
254  for (i = 1; i <= n_la; i++){
255  PcsDataLanthanide & pcs_d_l(pcs_d_l_vec[i]);
256  utility::vector1<core::Size> const & A_index( pcs_d_l.get_A_index());
257  utility::vector1< core::Real > const & cstyle_b(pcs_d_l.get_cstyle_b());
258  core::Real weight(pcs_d_l.get_weight());
259 
260  pcs_d_l.retrieve_tensor_from_svd(pcs_t);
261 
262  core::Real Xxx(pcs_t.get_chi_xx());
263  core::Real Xxy(pcs_t.get_chi_xy());
264  core::Real Xxz(pcs_t.get_chi_xz());
265  core::Real Xyy(pcs_t.get_chi_yy());
266  core::Real Xyz(pcs_t.get_chi_yz());
267 
268  core::Size p;
269  for (p = 1; p <= vec_temp.size(); p++){
270  vec_temp[p] = 0;
271  }
272 
273 
274  n_pcs = pcs_d_l.get_n_pcs();
275 
276  core::Real square_sum = 0;
277 
278  for (j = 1; j <= n_pcs; j++){
279  idx = A_index[j]; //index on the vector X_all_, Y_all_, Z_all_
280  xS = X_all[idx];
281  yS = Y_all[idx];
282  zS = Z_all[idx];
283  PCS_calc = A_all[idx][1]*Xxx + A_all[idx][2]*Xxy + A_all[idx][3]*Xxz + A_all[idx][4]*Xyy + A_all[idx][5]*Xyz;
284  PCS_exp = cstyle_b[j];
285 
286  core::Real deviation(PCS_calc - PCS_exp);
287 
288  square_sum += deviation * deviation;
289 
290  //This is for the derivatve of xM, yM, zM; could be a little bit optimized?
291  x=xS-xM;
292  y=yS-yM;
293  z=zS-zM;
294  r2=x*x+y*y+z*z;
295  r3=sqrt(r2)*r2;
296  r5=r3*r2;
297 
298  common2 = FACT_20_PI_OVER_10000*PCS_calc*r3;
299  common3 = deviation/r5;
300 
301  vec_temp[1] += (x*common2 - 2*( x*Xxx + y*Xxy + z*Xxz)) * common3;
302  vec_temp[2] += (y*common2 - 2*( x*Xxy + y*Xyy + z*Xyz)) * common3;
303  vec_temp[3] += (z*common2 - 2*(-z*Xxx + x*Xxz - z*Xyy + y*Xyz)) * common3;
304  }
305  // std::cerr << "square_sum" <<square_sum << std::endl;
306  core::Real one_over_RMSD(1.0/sqrt(square_sum));
307  core::Real common_temp( one_over_RMSD * weight * pcs_d_l.get_normalization_factor_inversed() );
308 
309  dE_dvars[1] += common_temp * vec_temp[1];
310  dE_dvars[2] += common_temp * vec_temp[2];
311  dE_dvars[3] += common_temp * vec_temp[3];
312  }
313 
314  dE_dvars[1] *= FACT_10000_OVER_4PI;
315  dE_dvars[2] *= FACT_10000_OVER_4PI;
316  dE_dvars[3] *= FACT_10000_OVER_4PI;
317 
318 }
319 
320 }//namespace pcs2
321 }//namespace methods
322 }//namespace scoring
323 }//namespace protocols