Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StepWiseRNA_RotamerGenerator.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 StepWiseRNA_RotamerGenerator
11 /// @brief Parameters to be passed between different modules of stepwise RNA building.
12 /// @detailed
13 /// @author Rhiju Das
14 
15 
16 //////////////////////////////////
22 //////////////////////////////////
23 
24 #include <core/id/TorsionID.hh>
25 #include <core/pose/Pose.hh>
28 #include <basic/Tracer.hh>
29 
30 #include <ObjexxFCL/FArray1D.hh>
31 #include <ObjexxFCL/format.hh>
32 #include <ObjexxFCL/string.functions.hh>
33 
34 #include <string>
35 
36 using namespace core;
37 using core::Real;
38 using ObjexxFCL::fmt::F;
39 
40 static basic::Tracer TR( "protocols.swa.rna.stepwise_rna_rotamer_generator" );
41 
42 namespace protocols {
43 namespace swa {
44 namespace rna {
45 
46 
47  ////////////////////////////////////////////////////////////////////////
48  // Constructor
49  StepWiseRNA_RotamerGenerator::StepWiseRNA_RotamerGenerator(
50  Size const moving_suite,
51  bool const sample_lower_sugar_and_base,
52  bool const sample_upper_sugar_and_base,
53  PuckerState const pucker1,
54  PuckerState const pucker2):
55  moving_suite_( moving_suite ),
56  sample_lower_sugar_and_base_(sample_lower_sugar_and_base),
57  sample_upper_sugar_and_base_(sample_upper_sugar_and_base),
58  pucker1_specified_( pucker1 ),
59  pucker2_specified_( pucker2 ),
60  sample_extra_rotamers_( true ),
61  fast_( false ),
62  bin_size_( 20 ), // must be 20, 10, or 5
63  verbose_(true),
64  sample_chi_torsion_(true), //Oct 2, 2010
65  include_syn_chi_(true),
66  extra_epsilon_(false), //Aug 30, 2010
67  extra_beta_(false), //Aug 30, 2010
68  extra_anti_chi_(false), //Aug 30, 2010
69  extra_syn_chi_(false), //Aug 30, 2010
70  exclude_alpha_beta_gamma_sampling_(false),
71  allow_syn_pyrimidine_(false), //Nov 14, 2010
72  lower_base_state_( NONE ), //Will be initialized by initialize_sample_base_states, April 29, 2011
73  upper_base_state_( NONE ) //Will be initialized by initialize_sample_base_states, April 29, 2011
74  {
75 
76  //These vectors should be empty to begin with, but not harm to ensure this.
78  }
79 
80  ////////////////////////////////////////////////////////////////////////
82  ////////////////////////////////////////////////////////////////////////
83 
84  //This function is called only after all the parameter setting functions (set_bin_size, set_include_syn_chi, set_sample_extra_rotamers, set_fast and etc..) had been called!...
85  void
87  Output_title_text("Enter StepWiseRNA_RotamerGenerator::initialize_rotamer_generator");
88 
89  bins1_= 360/bin_size_; //This is total bins, default is 18
90  bins2_= bins1_/2; //This is total bins divided by 2; default is 9
91  bins3_= bins1_/3; //This is total bins divided by 3; default is 6
92 
93  //beta_bins_ = (extra_beta_) ? (bins1_) : ((bins1_/2)+2) ; //Before Mar 14, 2011
94  beta_bins_ = (extra_beta_) ? (bins1_) : ( (200/bin_size_)+1 ) ; //Mar 14, 2011
95  eps_bins_= (extra_epsilon_) ? (1+120/bin_size_) : (1 +40/bin_size_) ;
96 
100  reset();
101  Output_title_text("Exit StepWiseRNA_RotamerGenerator::initialize_rotamer_generator");
102  }
103 
104  ////////////////////////////////////////////////////////////////////////
107  return torsion_ids_;
108  }
109 
110  ////////////////////////////////////////////////////////////////////////
111  bool
113  return ( group_rotamer_ <= rotamer_centers_.size() &&
114  (!fast_ || group_rotamer_ <= 2 ) /*premature stop*/ );
115  }
116 
117  ////////////////////////////////////////////////////////////////////////
118  void
120  group_rotamer_ = 1;
121  subgroup_rotamer_ = 1;
122  }
123 
124  ////////////////////////////////////////////////////////////////////////
127 
128  using namespace core::id;
129 
130  //A variable declared static in a function retains its state between calls to that function. Parin Feb 6, 2010
131  static scoring::rna::RNA_FittedTorsionInfo const rna_fitted_torsion_info;
132  Real const DELTA_CUTOFF( rna_fitted_torsion_info.delta_cutoff() );
133 
134  TorsionID const & torsion_id= (which_sugar=="lower") ? TorsionID( moving_suite_ , BB, 4 ) : TorsionID( moving_suite_+1 , BB, 4 );
135 
136  Real delta_value;
137 
138  for(Size n=1; n<=torsion_ids_.size(); n++){
139  if(torsion_ids_[n]==torsion_id){
140  delta_value=rotamer_centers_[group_rotamer_][n];
141 
142  std::cout << " DELTA_CUTOFF angle=" << DELTA_CUTOFF << " delta angle=" << delta_value << std::endl;
143 
144  if((delta_value>1.0 && delta_value<179.00)==false){
145  utility_exit_with_message( "delta angle out of range!" );
146  }
147 
148  if (delta_value <= DELTA_CUTOFF) {
149  return NORTH;
150  } else {
151  return SOUTH;
152  }
153  }
154  }
155 
156  utility_exit_with_message( "torsion_ids does not contain the desire delta torsion id" );
157  exit (1); //Prevent compiler warning!
158 
159  }
160  ////////////////////////////////////////////////////////////////////////
161  void
163 
164  using namespace core::id;
165 
166  assert( has_another_rotamer() );
167  rotamer_list_.clear();
168 
169  for(Size n=1; n<=torsion_ids_.size(); n++){
170  Torsion_Info torsion_info;
171  torsion_info.id=torsion_ids_[n];
172  torsion_info.value=rotamer_centers_[group_rotamer_][n];
173  rotamer_list_.push_back(torsion_info);
174  }
175 
176 // rotamer_values_ = rotamer_centers_[ group_rotamer_ ];
177 
178  if ( sample_extra_rotamers_ ) {
179 
180  for ( Size i = 1; i <= perturb_torsion_ids_.size(); i++ ){
181  TorsionID const & torsion_id = perturb_torsion_ids_[ i ] ;
182 
183  // Need to figure out which torsion calue to add on to.
184  for ( Size n = 1; n <= rotamer_list_.size(); n++ ){
185  if ( rotamer_list_[n].id == torsion_id ){
187  }
188  }
189  }
190 
193  if(verbose_) std::cout << "Done with rotamer ... " << group_rotamer_ << " out of " << rotamer_centers_.size() << std::endl;
194  subgroup_rotamer_ = 1;
195  group_rotamer_++;
196  }
197 
198 
199  } else {
200  group_rotamer_++;
201  }
202 
203  //Added in Aug 30 to ensure that dihedral torsion angle is in [-180:180] range.
204  for(Size n=1; n<=rotamer_list_.size(); n++){
205  rotamer_list_[ n ].value=numeric::principal_angle_degrees(rotamer_list_[ n ].value);
206  }
207 
208  }
209 
210  ////////////////////////////////////////////////////////////////////////
211  void
213  using namespace core::scoring::rna;
214 
215  /* BEFORE APRIL 29, 2011
216  if(include_syn_chi_){
217  if(allow_syn_pyrimidine_){
218  sample_syn_chi1_= true;
219  sample_syn_chi2_= true;
220  }else{
221  sample_syn_chi1_ = is_purine( pose.residue( moving_suite_ ) );
222  sample_syn_chi2_ = is_purine( pose.residue( moving_suite_+1 ) );
223  }
224  }else{
225  sample_syn_chi1_= false;
226  sample_syn_chi2_= false;
227  }
228  */
229 
230 
233 
234  if(include_syn_chi_==true){
237  }
238 
240  if( (is_purine( pose.residue( moving_suite_ ) )==false) && (allow_syn_pyrimidine_==false) ){
241  utility_exit_with_message("forcing working_res= "+ ObjexxFCL::string_of(moving_suite_ ) +" to be syn chi but residue is pyrimidine and allow_syn_pyrimidine_==false!");
242  }
244  }
245 
247  if( (is_purine( pose.residue( moving_suite_+1 ) )==false) && (allow_syn_pyrimidine_==false) ){
248  utility_exit_with_message("forcing working_res= "+ ObjexxFCL::string_of(moving_suite_+1) +" to be syn chi but residue is pyrimidine and allow_syn_pyrimidine_==false!");
249  }
251  }
252 
253  if( sample_chi_torsion_==false){
256  }
257 
258 
259  if ( sample_lower_sugar_and_base_==false /* DON'T sample sugar+base */) lower_base_state_=NONE;
260  if ( sample_upper_sugar_and_base_==false /* DON'T sample sugar+base */) upper_base_state_=NONE;
261 
262  }
263 
264  ////////////////////////////////////////////////////////////////////////
265  //This check for repeats. Parin Feb 4, 2010
266  void
268 
269  // Check that the torsion_id is not already in the TorsionID list
270  for ( Size n = 1; n <= torsion_ids_.size(); n++ ){
271  if ( torsion_ids_[n] == torsion_id ){
272  utility_exit_with_message( "Error: torsion_id is already in the torsion_id_list!" );
273  }
274  }
275 
276  torsion_ids_.push_back(torsion_id);
277 
278  }
279 
280 
281  ////////////////////////////////////////////////////////////////////////
282  void
284 
285  using namespace core::id;
286 
287 
288 
289  core::scoring::rna::RNA_FittedTorsionInfo rna_fitted_torsion_info;
290 
291  torsion_ids_.clear();
292  rotamer_centers_.clear();
293 
294  ///////////////////////////////////////////////////////////////////////////////////////
295  if ( sample_lower_sugar_and_base_ /* sample it */ ){
296  add_torsion_id(TorsionID( moving_suite_ , BB, 4 )); //delta1
297  add_torsion_id(TorsionID( moving_suite_ , CHI, 2 )); //nu2_1
298  add_torsion_id(TorsionID( moving_suite_ , CHI, 3 )); //nu1_1
299  }
300 
301  if(lower_base_state_!=NONE){
302  add_torsion_id(TorsionID( moving_suite_ , CHI, 1 )); //chi_1
303  }
304 
305  add_torsion_id( TorsionID( moving_suite_ , BB, 5 ) ); // epsilon1
306  add_torsion_id( TorsionID( moving_suite_ , BB, 6 ) ); // zeta1
307  add_torsion_id( TorsionID( moving_suite_ + 1, BB, 1 ) ); // alpha2
308  add_torsion_id( TorsionID( moving_suite_ + 1, BB, 2 ) ); // beta2
309  add_torsion_id( TorsionID( moving_suite_ + 1, BB, 3 ) ); // gamma2
310 
311  if ( sample_upper_sugar_and_base_ /* sample it */){
312  add_torsion_id( TorsionID( moving_suite_ + 1, BB, 4 ) ); //delta2
313  add_torsion_id( TorsionID( moving_suite_ + 1, CHI, 2 ) ); //nu2_2 (this is the one that include the delta bond atom)
314  add_torsion_id( TorsionID( moving_suite_ + 1, CHI, 3 ) ); //nu1_2 (this is the one that include the base nitrogen atom), actually nearer to chi
315  }
316 
317  if(upper_base_state_!=NONE){
318  add_torsion_id( TorsionID( moving_suite_ + 1, CHI, 1 ) ); //chi_2
319  }
320 
321  if(verbose_){
322  std::cout << "moving_suite_= " << moving_suite_ << " bin_size= " << bin_size_ << " bins1_= " << bins1_ << " bins2_= " << bins2_ << " bins3_= " << bins3_ << std::endl;
323  Output_boolean("extra_beta_: ", extra_beta_ ); Output_boolean(" extra_epsilon_: ", extra_epsilon_);
324  Output_boolean(" extra_anti_chi_: ", extra_anti_chi_); Output_boolean(" extra_syn_chi_: ", extra_syn_chi_);
325  std::cout << " beta_bins_= " << beta_bins_ << " eps_bins_ = " << eps_bins_ << std::endl;
326  Output_boolean("sample_chi_torsion_= ", sample_chi_torsion_ );
327  Output_boolean(" sample_extra_rotamers_= ", sample_extra_rotamers_);
328  Output_boolean(" exclude_alpha_beta_gamma_sampling_: ", exclude_alpha_beta_gamma_sampling_);
329  std::cout << std::endl;
330  Output_boolean("sample_lower_sugar_and_base_= " , sample_lower_sugar_and_base_);
331  print_ribose_pucker_state(" pucker1_specified= ", pucker1_specified_);
332  print_base_state(" lower_base_state= ", lower_base_state_);
333  Output_boolean(" sample_upper_sugar_and_base_= " , sample_upper_sugar_and_base_);
334  print_ribose_pucker_state(" pucker2_specified_= ", pucker2_specified_);
335  print_base_state(" upper_base_state= ", upper_base_state_ );
336  std::cout << std::endl;
337  }
338 
340  utility_exit_with_message("pucker1_specified==ALL but sample_lower_sugar_and_base_==false");
341  }
342 
344  utility_exit_with_message("pucker2_specified==ALL but sample_upper_sugar_and_base_==false");
345  }
346 
347  Real epsilon1( 0.0 ), zeta1( 0.0 ), alpha2( 0.0 ), beta2( 0.0 ), gamma2( 0.0 );
348 
349  StepWiseRNA_Base_Sugar_RotamerOP lower_base_sugar_rotamer = new StepWiseRNA_Base_Sugar_Rotamer( lower_base_state_, pucker1_specified_, rna_fitted_torsion_info, bin_size_);
350  StepWiseRNA_Base_Sugar_RotamerOP upper_base_sugar_rotamer = new StepWiseRNA_Base_Sugar_Rotamer( upper_base_state_, pucker2_specified_, rna_fitted_torsion_info, bin_size_);
351 
352  lower_base_sugar_rotamer->set_extra_anti_chi(extra_anti_chi_);
353  upper_base_sugar_rotamer->set_extra_anti_chi(extra_anti_chi_);
354 
355  lower_base_sugar_rotamer->set_extra_syn_chi(extra_syn_chi_);
356  upper_base_sugar_rotamer->set_extra_syn_chi(extra_syn_chi_);
357 
358 
359  while(lower_base_sugar_rotamer->get_next_rotamer()){
360 
361  upper_base_sugar_rotamer->reset();
362 
363  while(upper_base_sugar_rotamer->get_next_rotamer()){
364 // std::cout << "Exit upper_base_sugar_rotamer->get_next_rotamer()" << std::endl;
365 
366  std::cout << " delta1= " << F(8, 3, lower_base_sugar_rotamer->delta()) << " chi_1= " << F(8, 3, lower_base_sugar_rotamer->chi());
367  std::cout << " nu2_1= " << F(8, 3, lower_base_sugar_rotamer->nu2()) << " nu1_1= " << F(8, 3, lower_base_sugar_rotamer->nu1());
368  std::cout << " delta2= " << F(8, 3, upper_base_sugar_rotamer->delta()) << " chi_2= " << F(8, 3, upper_base_sugar_rotamer->chi());
369  std::cout << " nu2_2= " << F(8, 3, upper_base_sugar_rotamer->nu2()) << " nu1_2= " << F(8, 3, upper_base_sugar_rotamer->nu1());
370  std::cout << std::endl;
371 
372  //epsilon depends on delta of same residue...
373  for (int e1 = 1; e1 <= 1; e1++ ) {
374  for (int z1 = 1; z1 <= 2; z1++ ) {
375  // zeta depends on alpha of next residue... note that in original nested loop
376  // we looped on alpha2 first, then zeta1, since they are now sampled completely,
377  // in 20 degree bins.
378  for (int a2 = 1; a2 <= 3; a2++ ) {
379  for (int b2 = 1; b2 <= 1; b2++ ) {
380  for (int g2 = 1; g2 <= 3; g2++ ) {
381 
383  if(a2!=1 || b2!=1 || g2!=1) continue;
384  }
385 
386  // -150.17 and -98.45 MIGHT but match the value in RNA_FittedTorsionInfo? If that is the case, then value came from Parin calculatation which exclude A-form
387  //The mean is shifted in the extra_epsilon mode since the distribution is for both North and South are uneven.
388  //For North the tail is longer in the right side. For South the tail is longer in the left side
389  if(extra_epsilon_){ //+/- 60 degrees, added on Aug 30 2010 to fix BB torsion between Bulged G and the nucleotide 3' of it. Epsilon=-167.7 Delta=SOUTH
390  epsilon1= (lower_base_sugar_rotamer->current_pucker_state() == NORTH) ? -130.17 : -118.45;
391  }else{ // +/- 20 degrees standard mode
392  epsilon1= (lower_base_sugar_rotamer->current_pucker_state() == NORTH) ? -150.17 : -98.45;
393  }
394 
395  if(z1==1) zeta1= 0.0;
396  if(z1==2) zeta1= 180.0;
397 
398  if(a2==1) alpha2= 240.0;
399  if(a2==2) alpha2= 0.0;
400  if(a2==3) alpha2= 120.0;
401 
402  beta2 = 180.0;
403 
404  if(g2==1) gamma2= 240.0;
405  if(g2==2) gamma2= 0.0;
406  if(g2==3) gamma2= 120.0;
407 
408  utility::vector1 < Real > rotamer_center;
409 
410  if ( sample_lower_sugar_and_base_ /* sample it */) {
411  rotamer_center.push_back( lower_base_sugar_rotamer->delta()); //1
412  rotamer_center.push_back( lower_base_sugar_rotamer->nu2() ); //3
413  rotamer_center.push_back( lower_base_sugar_rotamer->nu1() ); //4
414  }
415 
416  if(lower_base_state_!=NONE){
417  rotamer_center.push_back( lower_base_sugar_rotamer->chi()); //2
418  }
419 
420  rotamer_center.push_back( epsilon1 ); //5
421  rotamer_center.push_back( zeta1 ); //6
422  rotamer_center.push_back( alpha2 ); //7
423  rotamer_center.push_back( beta2 ); //8
424  rotamer_center.push_back( gamma2 ); //9
425 
426  if ( sample_upper_sugar_and_base_ /* sample it */) {
427  rotamer_center.push_back( upper_base_sugar_rotamer->delta() ); //10
428  rotamer_center.push_back( upper_base_sugar_rotamer->nu2() ); //12
429  rotamer_center.push_back( upper_base_sugar_rotamer->nu1()); //13
430  }
431 
432  if(upper_base_state_!=NONE){
433  rotamer_center.push_back( upper_base_sugar_rotamer->chi() ); //11
434  }
435 
436  rotamer_centers_.push_back( rotamer_center );
437  }
438  }
439  }
440  }
441  }
442  }
443  }
444 
445  std::cout << "rotamer_centers_[1].size()= " << rotamer_centers_[1].size() << " torsion_ids_.size()= " << torsion_ids_.size() << std::endl;
446  if(rotamer_centers_[1].size()!=torsion_ids_.size()){
447  utility_exit_with_message( "rotamer_centers_[1].size()!=torsion_ids_.size()" );
448  }
449 
450  }
451 
452 
453  ////////////////////////////////////////////////////////////////////////
454  void
456 
457  using namespace core::id;
458 
459  ///////////////////////////////////////////////////////////////////////////////////////
460  perturb_torsion_ids_.clear();
462 
463  perturb_torsion_ids_.push_back( TorsionID( moving_suite_ , BB, 5 ) ); // epsilon1
464  perturb_torsion_ids_.push_back( TorsionID( moving_suite_ , BB, 6 ) ); // zeta1
465  perturb_torsion_ids_.push_back( TorsionID( moving_suite_ + 1, BB, 1 ) ); // alpha2
466  perturb_torsion_ids_.push_back( TorsionID( moving_suite_ + 1, BB, 2 ) ); // beta2
467  perturb_torsion_ids_.push_back( TorsionID( moving_suite_ + 1, BB, 3 ) ); // gamma2
468 
469  Real perturb_epsilon1( 0.0 ), perturb_zeta1( 0.0 ), perturb_alpha2( 0.0 ), perturb_beta2( 0.0 ), perturb_gamma2( 0.0 );
470 
471  for ( int e1_std = 1; e1_std <= static_cast<int>(eps_bins_); e1_std++ ) {
472 
473  if(extra_epsilon_){
474  perturb_epsilon1 = bin_size_*(e1_std-1) - 60.0;
475  }else{
476  perturb_epsilon1 = bin_size_*(e1_std-1) - 20.0;
477  }
478 
479 
480  for ( int z1_std = 1; z1_std <= bins2_; z1_std++ ) {
481 
482  perturb_zeta1 = bin_size_ * z1_std;
483 
484  for ( int a2_std = 1; a2_std <= bins3_; a2_std++ ) {
485 
486  perturb_alpha2 = bin_size_ * a2_std;
487 
488  for ( int b2_std = 1; b2_std <= beta_bins_; b2_std++ ) {
489 
490  if(extra_beta_){
491  perturb_beta2 = bin_size_ * static_cast<Real>( b2_std - 1 ); //perturb: (0, +340) actual: (180,520) --> (-180, -160,-140,-120,-100,-80,-60.....140, 160 ) :18 bins
492  }else{
493  perturb_beta2 = bin_size_ * static_cast<Real>( b2_std - (beta_bins_+1)/2 ); // beta_bins=11 perturb: (-100,100) actual: (80, -80) --> (80, 100, 120, 140, .....-140, -120, -100, -80) : 9 bins
494 
495 //Before Oct 12, 2010 beta_bins=9 perturb: (-80,80) actual: (100, -100) --> (100, 120, 140, .....-140, -120, -100) : 9 bins
496  }
497 
498  for ( int g2_std = 1; g2_std <= bins3_; g2_std++ ) {
499 
500  perturb_gamma2 = bin_size_ * g2_std;
501 
503  if(a2_std!=1 || b2_std!=1 || g2_std!=1) continue;
504  }
505 
506 
507  utility::vector1 < Real > rotamer_perturbation;
508 
509  rotamer_perturbation.push_back( perturb_epsilon1 );
510  rotamer_perturbation.push_back( perturb_zeta1 );
511  rotamer_perturbation.push_back( perturb_alpha2 );
512  rotamer_perturbation.push_back( perturb_beta2 );
513  rotamer_perturbation.push_back( perturb_gamma2 );
514 
515  extra_rotamer_perturbations_.push_back( rotamer_perturbation );
516  }
517  }
518  }
519  }
520  }
521 
522  std::cout << "extra_rotamer_perturbations_[1].size()= " << extra_rotamer_perturbations_[1].size() << " perturb_torsion_ids_.size()= " << perturb_torsion_ids_.size() << std::endl;
524  utility_exit_with_message( "extra_rotamer_perturbations_[1].size()!=perturb_torsion_ids_.size()" );
525  }
526  }
527 
528  //////////////////////////////////////////////////////////////////////////////////////
529  core::Size
531 
532  //////////////////////////////////////////////////////////////////////////////////////
533  core::Size const &
535 
536  //////////////////////////////////////////////////////////////////////////////////////
537  core::Size const &
539 
540  //////////////////////////////////////////////////////////////////////////////////////
541  core::Size const &
543  /////////////////////////////////////////////////////////////////////////
544 
545 }
546 }
547 }