Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TensorsOptimizerFix.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/TensorsOptimizerFix.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
36 // Package headers
37 
38 // Project headers
39 #include <basic/Tracer.hh>
40 
41 // Utility headers
42 #include <utility/exit.hh>
43 
44 // Numeric headers
45 #include <numeric/constants.hh>
46 
47 // Objexx headers
48 
49 // C++ headers
50 // AUTO-REMOVED #include <iomanip>
51 
52 #include <utility/vector1.hh>
53 
54 
55 namespace protocols{
56 namespace scoring{
57 namespace methods{
58 namespace pcs2{
59 
60 basic::Tracer TR_TensorsOptimizerFix("protocols.scoring.methods.pcs.TensorsOptimizerFix");
61 
63  pcs_d_c_(PcsDataCenter())//, xM_(0), yM_(0), zM_(0)
64 {
65  utility_exit_with_message("You shouldn't call the empty constructor for class TensorsOptimizerFix");
66 }
67 
68  TensorsOptimizerFix::TensorsOptimizerFix(PcsDataCenter const & pcs_d_c/*, core::Real xM, core::Real yM, core::Real zM*/):
69  pcs_d_c_(pcs_d_c)//, xM_(xM), yM_(yM), zM_(zM)
70 {
71  /*
72  core::Size i;
73  const utility::vector1<core::Real> & X_all(pcs_d_c_.get_X_all());
74  const utility::vector1<core::Real> & Y_all(pcs_d_c_.get_Y_all());
75  const utility::vector1<core::Real> & Z_all(pcs_d_c_.get_Z_all());
76 
77  utility::vector1<core::Real> A(5, 0);
78 
79  for(i = 1; i <= X_all.size(); i++){
80  fill_A_line(A, xM_, yM_, zM_, X_all[i], Y_all[i], Z_all[i]);
81  Xxx_coef_vect_.push_back(A[1]);
82  Xxy_coef_vect_.push_back(A[2]);
83  Xxz_coef_vect_.push_back(A[3]);
84  Xyy_coef_vect_.push_back(A[4]);
85  Xyz_coef_vect_.push_back(A[5]);
86  }
87  */
88 }
89 
91 }
92 
93 
96  core::Size i, j, idx;
97  core::Size n_la, n_pcs;
98  // core::Real x, y, z;
99  core::Real PCS_calc, PCS_exp, score, score_la;;
101 
102  score = 0;
103  n_la = pcs_d_c_.get_n_lanthanides();
104 
105  if(n_la != (vars.size()) / 5){
106  TR_TensorsOptimizerFix << "n_la: " << n_la << " (vars.size()) / 5):" << (vars.size()) / 5 << " vars.size(): " << vars.size() <<std::endl;
107  utility_exit_with_message("The number of lanthanides is inconsistent with the derivatives size of vars");
108  }
109 
110 
113  /*
114  const utility::vector1<core::Real> & X_all(pcs_d_c_.get_X_all());
115  const utility::vector1<core::Real> & Y_all(pcs_d_c_.get_Y_all());
116  const utility::vector1<core::Real> & Z_all(pcs_d_c_.get_Z_all());
117  */
118 
119  if(n_la != pcs_d_l_vec.size()){
120  utility_exit_with_message("The number of lanthanides is inconsistent");
121  }
122 
123  for (i = 1; i <= n_la; i++){
124  core::Real Xxx(vars[5*(i-1) + 1]);
125  core::Real Xxy(vars[5*(i-1) + 2]);
126  core::Real Xxz(vars[5*(i-1) + 3]);
127  core::Real Xyy(vars[5*(i-1) + 4]);
128  core::Real Xyz(vars[5*(i-1) + 5]);
129 
130  PcsDataLanthanide const & pcs_d_l(pcs_d_l_vec[i]);
131  utility::vector1<core::Size> const & A_index( pcs_d_l.get_A_index());
132  utility::vector1< core::Real > const & cstyle_b(pcs_d_l.get_cstyle_b());
133 
134  core::Real weight(pcs_d_l.get_weight());
135  //if weight = 0???
136 
137  n_pcs = pcs_d_l.get_n_pcs();
138 
139  score_la = 0;
140  for (j = 1; j <= n_pcs; j++){
141  idx = A_index[j]; //index on the vector X_all_, Y_all_, Z_all_
142  /*
143  x = X_all[idx];
144  y = Y_all[idx];
145  z = Z_all[idx];
146  fill_A_line(A, xM_, yM_, zM_, x, y, z);
147  PCS_calc = A[1]*Xxx + A[2]*Xxy + A[3]*Xxz + A[4]*Xyy + A[5]*Xyz;
148  */
149  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;
150  /*
151  PCS_calc =
152  Xxx_coef_vect_[idx]*Xxx +
153  Xxy_coef_vect_[idx]*Xxy +
154  Xxz_coef_vect_[idx]*Xxz +
155  Xyy_coef_vect_[idx]*Xyy +
156  Xyz_coef_vect_[idx]*Xyz;
157  */
158 
159  PCS_exp = cstyle_b[j];
160  score_la += (PCS_calc-PCS_exp) * (PCS_calc-PCS_exp);
161  }
162 
163  score += sqrt(score_la) * weight / pcs_d_l.get_normalization_factor();
164  }
165 
166  // std::cerr << score << std::endl;
167  return(score);
168 }
169 
170 void
173  ) const{
174 
175  core::Size i;
176  core::Real delta(0.0001);
177 
178  for(i = 1; i <= vars.size(); i++){
179  core::optimization::Multivec vars_bis_pd (vars);
180  core::optimization::Multivec vars_bis_md (vars);
181  vars_bis_pd[i] += delta;
182  vars_bis_md[i] -= delta;
183  core::Real value_pd (func(vars_bis_pd) / delta / 2);
184  core::Real value_md (func(vars_bis_md) / delta / 2);
185  dE_dvars[i] = value_pd - value_md;
186  }
187 }
188 
189 void
192  ) const{
193 
194  dfunc_exact(vars, dE_dvars);
195  /*
196  core::Size i;
197  std::cerr << "df_exact ";
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  dfunc_numeric(vars, dE_dvars);
204  std::cerr << "df_numer ";
205  for(i = 1; i <= vars.size(); i++){
206  std::cerr << std::setw(8)<< dE_dvars[i] << " " ;
207  }
208  std::cerr << std::endl;
209  */
210 }
211 
212 
213 
216  return(func(vars));
217 }
218 
219 void
222  ) const{
223  core::Size i, j, k, idx;
224  core::Size n_la, n_pcs;
225  // core::Real x, y, z, xS, yS, zS;
226  core::Real PCS_calc, PCS_exp;
227  // core::Real common2, common3;
228  // core::Real r5, r2, r3;
229 
231 
232  n_la = pcs_d_c_.get_n_lanthanides();
233 
234  if(n_la != (dE_dvars.size()) / 5){
235  utility_exit_with_message("The number of lanthanides is inconsistent with the derivativessize of dE_dvars");
236  }
237 
238  //lets' init everyone to zero because we are going to use +=
239  for (i = 1; i <= dE_dvars.size(); i++){
240  dE_dvars[i] = 0;
241  }
242 
244  vec_temp.resize(dE_dvars.size(), 0);
245 
246  //those are the lanthanides current coordinates.
247 
250  /*
251  const utility::vector1<core::Real> & X_all(pcs_d_c_.get_X_all());
252  const utility::vector1<core::Real> & Y_all(pcs_d_c_.get_Y_all());
253  const utility::vector1<core::Real> & Z_all(pcs_d_c_.get_Z_all());
254  */
255 
256  if(n_la != pcs_d_l_vec.size()){
257  utility_exit_with_message("The number of lanthanides is inconsistent");
258  }
259 
260 
261 
262  for (i = 1; i <= n_la; i++){
263  core::Size p;
264  for (p = 1; p <= vec_temp.size(); p++){
265  vec_temp[p] = 0;
266  }
267 
268  core::Real Xxx(vars[5*(i-1) + 1]);
269  core::Real Xxy(vars[5*(i-1) + 2]);
270  core::Real Xxz(vars[5*(i-1) + 3]);
271  core::Real Xyy(vars[5*(i-1) + 4]);
272  core::Real Xyz(vars[5*(i-1) + 5]);
273 
274 
275  PcsDataLanthanide const & pcs_d_l(pcs_d_l_vec[i]);
276  utility::vector1<core::Size> const & A_index( pcs_d_l.get_A_index());
277  utility::vector1< core::Real > const & cstyle_b(pcs_d_l.get_cstyle_b());
278 
279  core::Real weight(pcs_d_l.get_weight());
280  n_pcs = pcs_d_l.get_n_pcs();
281 
282  core::Real square_sum = 0;
283 
284  for (j = 1; j <= n_pcs; j++){
285  idx = A_index[j]; //index on the vector X_all_, Y_all_, Z_all_
286  /*
287  xS = X_all[idx];
288  yS = Y_all[idx];
289  zS = Z_all[idx];
290  fill_A_line(A, xM_, yM_, zM_, xS, yS, zS);
291  PCS_calc = A[1]*Xxx + A[2]*Xxy + A[3]*Xxz + A[4]*Xyy + A[5]*Xyz;
292  */
293  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;
294  /*
295  PCS_calc =
296  Xxx_coef_vect_[idx]*Xxx +
297  Xxy_coef_vect_[idx]*Xxy +
298  Xxz_coef_vect_[idx]*Xxz +
299  Xyy_coef_vect_[idx]*Xyy +
300  Xyz_coef_vect_[idx]*Xyz;
301  */
302 
303  PCS_exp = cstyle_b[j];
304 
305  core::Real deviation(PCS_calc - PCS_exp);
306 
307  square_sum += deviation * deviation;
308 
309  //This is for the derivatve of Xxx, Xxy, Xxz, Xyy, Xyz
310 
311  for (k = 1; k <= 5; k++){
312  // vec_temp[5*(i-1) + k] += deviation * A[k];
313  vec_temp[5*(i-1) + k] += deviation * A_all[idx][k];
314  }
315 
316  /*
317  vec_temp[5*(i-1) + 1] += deviation * Xxx_coef_vect_[idx];
318  vec_temp[5*(i-1) + 2] += deviation * Xxy_coef_vect_[idx];
319  vec_temp[5*(i-1) + 3] += deviation * Xxz_coef_vect_[idx];
320  vec_temp[5*(i-1) + 4] += deviation * Xyy_coef_vect_[idx];
321  vec_temp[5*(i-1) + 5] += deviation * Xyz_coef_vect_[idx];
322  */
323  }
324 
325  core::Real one_over_RMSD(1.0/sqrt(square_sum));
326  core::Real common_temp( one_over_RMSD * weight / pcs_d_l.get_normalization_factor() );
327  for (k = 1; k <= 5; k++){
328  dE_dvars[5*(i-1) + k] += vec_temp[5*(i-1) + k] * common_temp;
329  }
330  }
331 
332 }
333 
334 }//namespace pcs2
335 }//namespace methods
336 }//namespace scoring
337 }//namespace protocols