Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RNA_LoopCloseSampler.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 RNA_LoopCloseSampler
11 /// @brief Loop Close Sampler...
12 /// @detailed
13 /// @author Rhiju Das
14 
15 
16 //////////////////////////////////
22 
23 //////////////////////////////////
24 #include <core/types.hh>
25 #include <core/id/AtomID.hh>
26 #include <core/pose/Pose.hh>
27 #include <core/pose/util.hh>
37 #include <core/io/pdb/pose_io.hh>
39 #include <core/scoring/Energies.hh>
42 #include <core/id/TorsionID.hh>
44 #include <core/chemical/util.hh>
46 #include <numeric/conversions.hh>
47 #include <numeric/xyz.functions.hh>
48 #include <numeric/angle.functions.hh>
49 #include <ObjexxFCL/format.hh>
50 #include <ObjexxFCL/string.functions.hh>
51 #include <utility/tools/make_vector1.hh>
52 #include <utility/exit.hh>
53 #include <time.h>
54 
55 #include <string>
56 #include <fstream>
57 #include <iostream>
58 #include <sstream>
59 #include <map>
60 
61 
62 using namespace core;
63 using core::Real;
64 
65 
66 namespace protocols {
67 namespace swa {
68 namespace rna {
69 
70 //////////////////////////////////////////////////////////////////////////
71 //constructor!
72 RNA_LoopCloseSampler::RNA_LoopCloseSampler ( Size const moving_suite, Size const chainbreak_suite ) :
73  moving_suite_ ( moving_suite ),
74  chainbreak_suite_ ( chainbreak_suite ),
75  scorefxn_ ( core::scoring::getScoreFunction() ),
76  bin_size_ ( 20 ),
77  n_construct_ ( 0 ),
78  rep_cutoff_ ( 0.1 ),
79  torsion_range_ ( 20.0 ),
80  torsion_increment_ ( 5.0 ),
81  epsilon_range_ ( 40.0 ),
82  just_output_score_ ( false ),
83  sample_only_ ( false ),
84  sample_native_torsion_ ( false ) {
85  RNA_AnalyticLoopCloser rna_analytic_loop_closer ( moving_suite, chainbreak_suite );
87 }
88 
89 //////////////////////////////////////////////////////////////////////////
90 //destructor
92 {}
93 
94 //////////////////////////////////////////////////////////////////////////
95 void
97  using namespace pose;
98  using namespace scoring;
99  using namespace io::silent;
100  using namespace chemical;
101  using namespace id;
102  using namespace scoring::rna;
103  using namespace protocols::swa;
104  using namespace protocols::swa::rna;
105  using namespace numeric::conversions;
106  Real const fa_rep_score_baseline = initialize_fa_rep ( pose, utility::tools::make_vector1 ( moving_suite_ ), rep_scorefxn_ );
107  // iterate over 4 dofs:
108  // epsilon1, zeta1, alpha1; alpha2
109  // solve for the other 6 by chain closure:
110  // beta1, gamma1; epsilon2, zeta2, beta2, gamma2
111  // This should probably be encapsulated into a PoseSampleGenerator or something similar
112  // int const bins1_ = 360 / bin_size_ ; //This is total bins, default is 18
113  // int const bins2_ = bins1_ / 2; //This is total bins divided by 2; default is 9
114  PuckerState pucker_state1 = Get_residue_pucker_state ( pose, moving_suite_ );
115  // following is only used if we are estimating jacobians (numerically).
116  utility::vector1< utility::vector1< utility::vector1< Real > > > perturbed_solution_torsions;
117  utility::vector1< utility::vector1< Real > > J; // 6 x 6 Jacobian.
118  utility::vector1< Real > six_zeros;
119 
120  for ( int i = 1; i <= 6; i++ ) six_zeros.push_back ( 0.0 );
121 
122  for ( int i = 1; i <= 6; i++ ) J.push_back ( six_zeros );
123 
124  Real epsilon1_center = ( pucker_state1 == NORTH ) ? -150.17 : -98.45;
125  Real epsilon1_min = epsilon1_center - epsilon_range_;
126  Real epsilon1_max = epsilon1_center + epsilon_range_;
127  if (pucker_state1 == SOUTH && epsilon1_min > -178) epsilon1_min = -178.45;
128  Real epsilon1_increment = bin_size_;
129  Real alpha1_min = 20.0;
130  Real alpha1_max = 340.0 - bin_size_;
131  Real alpha1_increment = bin_size_;
132  Real alpha2_min = 20.0;
133  Real alpha2_max = 340.0 - bin_size_;
134  Real alpha2_increment = bin_size_;
135  Real zeta1_min = 20.0;
136  Real zeta1_max = 340.0 - bin_size_;
137  Real zeta1_increment = bin_size_;
138 
139  PoseCOP native_pose = get_native_pose();
140  Real const epsilon1_native = pose.torsion ( TorsionID ( moving_suite_ , id::BB, EPSILON ) );
141  Real const zeta1_native = pose.torsion ( TorsionID ( moving_suite_ , id::BB, ZETA ) );
142  Real const alpha1_native = pose.torsion ( TorsionID ( moving_suite_ + 1, id::BB, ALPHA ) );
143  Real const alpha2_native = pose.torsion ( TorsionID ( chainbreak_suite_ + 1, id::BB, ALPHA ) );
144 
145  RNA_AnalyticLoopCloser rna_analytic_loop_closer ( moving_suite_, chainbreak_suite_ );
146 
147  for ( Real epsilon1 = epsilon1_min; epsilon1 <= epsilon1_max; epsilon1 += epsilon1_increment ) {
148  for ( Real alpha1 = alpha1_min; alpha1 <= alpha1_max; alpha1 += alpha1_increment ) {
149  for ( Real alpha2 = alpha2_min; alpha2 <= alpha2_max; alpha2 += alpha2_increment ) {
150  for ( Real zeta1 = zeta1_min; zeta1 <= zeta1_max; zeta1 += zeta1_increment ) {
151  pose.set_torsion ( TorsionID ( moving_suite_, id::BB, EPSILON ), epsilon1 );
152  pose.set_torsion ( TorsionID ( moving_suite_, id::BB, ZETA ), zeta1 );
153  pose.set_torsion ( TorsionID ( moving_suite_ + 1, id::BB, ALPHA ), alpha1 );
154  pose.set_torsion ( TorsionID ( chainbreak_suite_ + 1, id::BB, ALPHA ), alpha2 );
155 
156  //close loop.
157  rna_analytic_loop_closer.apply ( pose );
158 
159  // iterate over solutions -- anything with OK repulsive?
160  for ( Size n = 1; n <= rna_analytic_loop_closer.nsol(); n++ ) {
161  rna_analytic_loop_closer.fill_solution ( pose, n );
162 
164 
165  if ( !sample_only_ ) {
166  if ( !check_clash ( pose, fa_rep_score_baseline, rep_cutoff_, rep_scorefxn_ ) ) continue;
167  }
168 
169  // save data
170  n_construct_++;
171  torsion_info_.clear();
172  torsion_info_.push_back ( pose.torsion ( TorsionID ( moving_suite_ , id::BB, EPSILON ) ) );
173  torsion_info_.push_back ( pose.torsion ( TorsionID ( moving_suite_ , id::BB, ZETA ) ) );
174  torsion_info_.push_back ( pose.torsion ( TorsionID ( moving_suite_ + 1, id::BB, ALPHA ) ) );
175  torsion_info_.push_back ( pose.torsion ( TorsionID ( moving_suite_ + 1, id::BB, BETA ) ) );
176  torsion_info_.push_back ( pose.torsion ( TorsionID ( moving_suite_ + 1, id::BB, GAMMA ) ) );
177  torsion_info_.push_back ( pose.torsion ( TorsionID ( chainbreak_suite_ , id::BB, EPSILON ) ) );
178  torsion_info_.push_back ( pose.torsion ( TorsionID ( chainbreak_suite_ , id::BB, ZETA ) ) );
179  torsion_info_.push_back ( pose.torsion ( TorsionID ( chainbreak_suite_ + 1, id::BB, ALPHA ) ) );
180  torsion_info_.push_back ( pose.torsion ( TorsionID ( chainbreak_suite_ + 1, id::BB, BETA ) ) );
181  torsion_info_.push_back ( pose.torsion ( TorsionID ( chainbreak_suite_ + 1, id::BB, GAMMA ) ) );
182  all_torsion_info_.push_back ( torsion_info_ );
183  }
184  }
185  }
186  }
187  }
188 
189 
190  if ( sample_native_torsion_ ) {
191  pose.set_torsion ( TorsionID ( moving_suite_, id::BB, EPSILON ), epsilon1_native );
192  pose.set_torsion ( TorsionID ( moving_suite_, id::BB, ZETA ), zeta1_native );
193  pose.set_torsion ( TorsionID ( moving_suite_ + 1, id::BB, ALPHA ), alpha1_native );
194  pose.set_torsion ( TorsionID ( chainbreak_suite_ + 1, id::BB, ALPHA ), alpha2_native );
195 
196  //close loop.
197  rna_analytic_loop_closer.apply ( pose );
198 
199  // iterate over solutions -- anything with OK repulsive?
200  for ( Size n = 1; n <= rna_analytic_loop_closer.nsol(); n++ ) {
201  rna_analytic_loop_closer.fill_solution ( pose, n );
202 
204 
205  if ( !sample_only_ ) {
206  if ( !check_clash ( pose, fa_rep_score_baseline, rep_cutoff_, rep_scorefxn_ ) ) continue;
207  }
208 
209  // save data
210  n_construct_++;
211  torsion_info_.clear();
212  torsion_info_.push_back ( pose.torsion ( TorsionID ( moving_suite_ , id::BB, EPSILON ) ) );
213  torsion_info_.push_back ( pose.torsion ( TorsionID ( moving_suite_ , id::BB, ZETA ) ) );
214  torsion_info_.push_back ( pose.torsion ( TorsionID ( moving_suite_ + 1, id::BB, ALPHA ) ) );
215  torsion_info_.push_back ( pose.torsion ( TorsionID ( moving_suite_ + 1, id::BB, BETA ) ) );
216  torsion_info_.push_back ( pose.torsion ( TorsionID ( moving_suite_ + 1, id::BB, GAMMA ) ) );
217  torsion_info_.push_back ( pose.torsion ( TorsionID ( chainbreak_suite_ , id::BB, EPSILON ) ) );
218  torsion_info_.push_back ( pose.torsion ( TorsionID ( chainbreak_suite_ , id::BB, ZETA ) ) );
219  torsion_info_.push_back ( pose.torsion ( TorsionID ( chainbreak_suite_ + 1, id::BB, ALPHA ) ) );
220  torsion_info_.push_back ( pose.torsion ( TorsionID ( chainbreak_suite_ + 1, id::BB, BETA ) ) );
221  torsion_info_.push_back ( pose.torsion ( TorsionID ( chainbreak_suite_ + 1, id::BB, GAMMA ) ) );
222  all_torsion_info_.push_back ( torsion_info_ );
223  }
224  }
225 }
226 //////////////////////////////////////////////////////////////////////////
227 void
228 RNA_LoopCloseSampler::fill_pose ( pose::Pose & pose, Size construct_number ) {
229  using namespace pose;
230  using namespace scoring;
231  using namespace io::silent;
232  using namespace chemical;
233  using namespace id;
234  using namespace scoring::rna;
235  using namespace protocols::swa;
236  using namespace protocols::swa::rna;
237  using namespace numeric::conversions;
238  utility::vector1< Real > & torsion_info = all_torsion_info_[construct_number];
239  pose.set_torsion ( TorsionID ( moving_suite_ , id::BB, EPSILON ), torsion_info[1] );
240  pose.set_torsion ( TorsionID ( moving_suite_ , id::BB, ZETA ), torsion_info[2] );
241  pose.set_torsion ( TorsionID ( moving_suite_ + 1, id::BB, ALPHA ), torsion_info[3] );
242  pose.set_torsion ( TorsionID ( moving_suite_ + 1, id::BB, BETA ), torsion_info[4] );
243  pose.set_torsion ( TorsionID ( moving_suite_ + 1, id::BB, GAMMA ), torsion_info[5] );
244  pose.set_torsion ( TorsionID ( chainbreak_suite_ , id::BB, EPSILON ), torsion_info[6] );
245  pose.set_torsion ( TorsionID ( chainbreak_suite_ , id::BB, ZETA ), torsion_info[7] );
246  pose.set_torsion ( TorsionID ( chainbreak_suite_ + 1, id::BB, ALPHA ), torsion_info[8] );
247  pose.set_torsion ( TorsionID ( chainbreak_suite_ + 1, id::BB, BETA ), torsion_info[9] );
248  pose.set_torsion ( TorsionID ( chainbreak_suite_ + 1, id::BB, GAMMA ), torsion_info[10] );
249  return;
250 }
251 ///////////////////////////////
252 void
254  all_torsion_info_.clear();
255  n_construct_ = 0;
256  return;
257 }
258 
259 //////////////////////////////////////////////////////////////////////////
260 void
262  using namespace core::scoring;
264  rep_scorefxn_->set_weight ( fa_rep, 0.12 );
265 }
266 
267 ///////////////////////////////////////////////////////////////
268 Real
270  utility::vector1< Size > const & moving_suites,
271  scoring::ScoreFunctionOP rep_scorefxn ) {
272  using namespace pose;
273  using namespace kinematics;
274  using namespace scoring;
275  using namespace protocols::swa;
276 
277  if ( sample_only_ ) {
278  return 0;
279  }
280 
281  Pose pose_expand = pose;
282 
283  for ( Size n = 1; n <= moving_suites.size(); n++ ) {
284  Size const jump_at_moving_suite = make_cut_at_moving_suite ( pose_expand, moving_suites[n] );
285  Jump j = pose_expand.jump ( jump_at_moving_suite );
286  j.set_translation ( Vector ( 1.0e4 * n, 0.0, 0.0 ) );
287  pose_expand.set_jump ( jump_at_moving_suite, j );
288  }
289 
290  ( *rep_scorefxn ) ( pose_expand );
291  EnergyMap const & energy_map = pose_expand.energies().total_energies();
292  return energy_map[ fa_rep ] * rep_scorefxn->get_weight ( fa_rep );
293 }
294 
295 
296 ///////////////////////////////////////////////////////////////
297 bool
299  Real const & fa_rep_score_baseline,
300  Real const & rep_cutoff_,
301  scoring::ScoreFunctionOP rep_scorefxn ) {
302  using namespace scoring;
303  ( *rep_scorefxn ) ( pose );
304  EnergyMap const & energy_map = pose.energies().total_energies();
305  Real const fa_rep_score = energy_map[ fa_rep ] * rep_scorefxn->get_weight ( fa_rep );
306  // std::cout << fa_rep_score << " " << fa_rep_score_baseline << std::endl;
307 
308  if ( ( fa_rep_score - fa_rep_score_baseline ) > rep_cutoff_ ) return false;
309 
310  static Real const tolerance ( 1.0e-3 );
311 
312  if ( ( fa_rep_score - fa_rep_score_baseline ) < -1.0 * tolerance ) {
313  std::cout << fa_rep_score << " " << fa_rep_score_baseline << std::endl;
314  // utility_exit_with_message( "Weird fa_rep?" );
315  }
316 
317  return true;
318 }
319 
320 //////////////////////////////////////////////////////////////////////////
321 void
323  scorefxn_ = scorefxn;
324 }
325 
326 //////////////////////////////////////////////////////////////////////////
327 bool
329  Size const moving_suite,
330  Size const chainbreak_suite ) {
331  using namespace id;
332  using namespace core::scoring::rna;
333  using namespace protocols::swa::rna;
334 
335  static Size const epsilonmin_n = 155, epsilonmax_n = 310;
336  static Size const epsilonmin_s = 175, epsilonmax_s = 310;
337  static Size const gammapmin = 20, gammapmax = 95;
338  static Size const gammatmin = 140, gammatmax = 215;
339  static Size const gammammin = 260, gammammax = 335;
340  static Size const betamin = 50, betamax = 290;
341  static Size const alphamin = 25, alphamax = 335;
342  static Size const zetamin = 25, zetamax = 335;
343 
344  //Beta
345  Real beta1 = numeric::principal_angle_degrees ( pose.torsion ( TorsionID ( moving_suite + 1, id::BB, BETA ) ) );
346  if (beta1 < 0) beta1 += 360;
347  if ( beta1 < betamin || beta1 > betamax ) return false;
348 
349  Real beta2 = numeric::principal_angle_degrees ( pose.torsion ( TorsionID ( chainbreak_suite + 1, id::BB, BETA ) ) );
350  if (beta2 < 0) beta2 += 360;
351  if ( beta2 < betamin || beta2 > betamax ) return false;
352 
353  //Gamma
354  Real gamma1 = numeric::principal_angle_degrees ( pose.torsion ( TorsionID ( moving_suite + 1, id::BB, GAMMA ) ) );
355  if (gamma1 < 0) gamma1 += 360;
356  if ( ( gamma1 < gammapmin || gamma1 > gammapmax ) &&
357  ( gamma1 < gammatmin || gamma1 > gammatmax ) &&
358  ( gamma1 < gammammin || gamma1 > gammammax ) ) {
359  return false;
360  }
361 
362  Real gamma2 = numeric::principal_angle_degrees ( pose.torsion ( TorsionID ( chainbreak_suite + 1, id::BB, GAMMA ) ) );
363  if (gamma2 < 0) gamma2 += 360;
364  if ( ( gamma2 < gammapmin || gamma2 > gammapmax ) &&
365  ( gamma2 < gammatmin || gamma2 > gammatmax ) &&
366  ( gamma2 < gammammin || gamma2 > gammammax ) ) {
367  return false;
368  }
369 
370  //Epsilon
371  PuckerState pucker_state1 = Get_residue_pucker_state ( pose, chainbreak_suite );
372  Real epsilon1 = numeric::principal_angle_degrees ( pose.torsion ( TorsionID ( moving_suite, id::BB, EPSILON ) ) );
373  if (epsilon1 < 0) epsilon1 += 360;
374  if (pucker_state1 == NORTH) {
375  if ( epsilon1 < epsilonmin_n || epsilon1 > epsilonmax_n ) return false;
376  } else {
377  if ( epsilon1 < epsilonmin_s || epsilon1 > epsilonmax_s ) return false;
378  }
379 
380  PuckerState pucker_state2 = Get_residue_pucker_state ( pose, chainbreak_suite );
381  Real epsilon2 = numeric::principal_angle_degrees ( pose.torsion ( TorsionID ( chainbreak_suite, id::BB, EPSILON ) ) );
382  if (epsilon2 < 0) epsilon2 += 360;
383  if (pucker_state2 == NORTH) {
384  if ( epsilon2 < epsilonmin_n || epsilon2 > epsilonmax_n ) return false;
385  } else {
386  if ( epsilon2 < epsilonmin_s || epsilon2 > epsilonmax_s ) return false;
387  }
388 
389  //Zeta
390  Real zeta1 = numeric::principal_angle_degrees ( pose.torsion ( TorsionID ( moving_suite, id::BB, ZETA ) ) );
391  if (zeta1 < 0) zeta1 += 360;
392  if ( zeta1 < zetamin || zeta1 > zetamax ) return false;
393 
394  Real zeta2 = numeric::principal_angle_degrees ( pose.torsion ( TorsionID ( chainbreak_suite, id::BB, ZETA ) ) );
395  if (zeta2 < 0) zeta2 += 360;
396  if ( zeta2 < zetamin || zeta1 > zetamax ) return false;
397 
398  //Alpha
399  Real alpha1 = numeric::principal_angle_degrees ( pose.torsion ( TorsionID ( moving_suite + 1, id::BB, ALPHA ) ) );
400  if (alpha1 < 0) alpha1 += 360;
401  if ( alpha1 < alphamin || alpha1 > alphamax ) return false;
402 
403  Real alpha2 = numeric::principal_angle_degrees ( pose.torsion ( TorsionID ( chainbreak_suite + 1, id::BB, ALPHA ) ) );
404  if (alpha2 < 0) alpha2 += 360;
405  if ( alpha2 < alphamin || alpha2 > alphamax ) return false;
406 
407  return true;
408 }
409 
410 }
411 }
412 }