Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StepWiseRNA_RotamerGenerator_Wrapper.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 //////////////////////////////////
21 
23 //////////////////////////////////
24 
25 #include <core/id/TorsionID.hh>
26 #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_wrapper" );
41 
42 namespace protocols {
43 namespace swa {
44 namespace rna {
45 
46  //////////////////////////////////////////////////////////////////////////////////////////
47 
48 
49  StepWiseRNA_RotamerGenerator_Wrapper::StepWiseRNA_RotamerGenerator_Wrapper(
50  core::pose::Pose const & pose,
51  utility::vector1< core::Size > const & moving_suite_list,
52  bool const & sample_sugar_and_base1,
53  bool const & sample_sugar_and_base2 ):
54  pose_(pose),
55  moving_suite_list_( moving_suite_list ),
56  sample_sugar_and_base1_(sample_sugar_and_base1),
57  sample_sugar_and_base2_(sample_sugar_and_base2),
58  sample_extra_rotamers_( true ),
59  fast_( false ),
60  verbose_(false),
61  sample_chi_torsion_(true), //Oct 2, 2010
62  include_syn_chi_(true),
63  bin_size_(20),
64  extra_epsilon_(false), //Aug 30, 2010
65  extra_beta_(false), //Aug 30, 2010
66  extra_anti_chi_(false), //Aug 30, 2010
67  extra_syn_chi_(false), //Aug 30, 2010
68  exclude_alpha_beta_gamma_sampling_(false),
69  allow_syn_pyrimidine_(false),
70  rotamer_generator_list_(moving_suite_list_.size(), NULL)
71  {
72 
73  /////////////////////////Check that moving_suite_list_ is correctly order/////////////////////////
74  bool const can_prepend=assert_can_prepend(moving_suite_list_); //[12,13]
75  bool const can_append=assert_can_append(moving_suite_list_); //[13,12]
76 
77  if(!can_prepend && !can_append){
78  Output_seq_num_list("working_moving_suite_list_:" , moving_suite_list_);
79  utility_exit_with_message( "Cannot prepend or append residue in moving_suite_list_" );
80  }
81 
82  if(moving_suite_list_.size()>1){
83  if(can_prepend && can_append){
84  Output_seq_num_list("working_moving_suite_list_:" , moving_suite_list_);
85  utility_exit_with_message( "moving_suite_list_.size()>1 but BOTH can_prepend=true && can_append==true!" );
86  }
87  }
88 
89  Is_prepend_=can_prepend; //WARNING THIS VARIABLE ONLY HAVE MEANING IF moving_suite_list_.size()>1.
90  /////////////////////////Check that moving_suite_list_ is correctly order/////////////////////////
91 
92  //These vectors should be empty to begin with, but not harm to ensure this.
96 
97  }
98 
99  ////////////////////////////////////////////////////////////////////////
101  ////////////////////////////////////////////////////////////////////////
102  void
104 
105  Output_title_text("Enter StepWiseRNA_RotamerGenerator::initialize_rotamer_generator_list");
106  Output_boolean("sample_sugar_and_base1_= " , sample_sugar_and_base1_);
107  Output_boolean(" sample_sugar_and_base2_= " , sample_sugar_and_base2_);
108  Output_boolean(" Is_prepend_(only_meaningful_if_#res>1)= ", Is_prepend_);
109  Output_boolean(" sample_extra_rotamers_= " , sample_extra_rotamers_);
110  Output_boolean(" include_syn_chi_= " , include_syn_chi_);
111  Output_boolean(" allow_syn_pyrimidine_= " , allow_syn_pyrimidine_);
112  std::cout << std::endl;
113  Output_boolean("exclude_alpha_beta_gamma_sampling_: ", exclude_alpha_beta_gamma_sampling_);
114  Output_boolean(" extra_beta_: ", extra_beta_ ); Output_boolean(" extra_epsilon_: ", extra_epsilon_);
115  Output_boolean(" extra_anti_chi_: ", extra_anti_chi_); Output_boolean(" extra_syn_chi_: ", extra_syn_chi_);
116  std::cout << std::endl;
117  Output_seq_num_list("working_moving_suite_list_:" , moving_suite_list_);
118  Output_seq_num_list("working_force_syn_chi_res_list_:", force_syn_chi_res_list_);
119  Output_seq_num_list("working_force_north_ribose_list_:", force_north_ribose_list_);
120  Output_seq_num_list("working_force_south_ribose_list_:", force_south_ribose_list_);
121 
122  for(Size n=1; n<=force_north_ribose_list_.size(); n++){
124  utility_exit_with_message("seq_num= " + ObjexxFCL::string_of(force_north_ribose_list_[n]) + " is in both force_north_ribose_list_ and force_south_ribose_list_! " );
125  }
126  }
127 
128 
129  //////////////////////////////////////////////////////////////////////////////////////////////////////
130 
131 
132  for(Size list_position=rotamer_generator_list_.size(); list_position>=1; list_position--){
133  std::cout << "list_position= " << list_position << " working_moving_suite= " << moving_suite_list_[list_position] << std::endl;
134  rotamer_generator_list_[list_position]=setup_rotamer_generator(list_position); //This assumes that rotamer_generator[list_position+1] is setup and properly initialized
135  }
136 
137  Output_title_text("Exit StepWiseRNA_RotamerGenerator::initialize_rotamer_generator_list");
138 
139  }
140  ////////////////////////////////////////////////////////////////////////
143 
144  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
145  bool sample_lower_sugar_and_base, sample_upper_sugar_and_base;
146 
147  if(moving_suite_list_.size()==1){
148  sample_lower_sugar_and_base=sample_sugar_and_base1_;
149  sample_upper_sugar_and_base=sample_sugar_and_base2_;
150  }else{
151  if(Is_prepend_){
152  if(list_position==1){ //5' most sample res.
153  sample_lower_sugar_and_base=sample_sugar_and_base1_;
154  sample_upper_sugar_and_base=false;
155  }else if( list_position==moving_suite_list_.size() ) { //3' most sample res.
156  sample_lower_sugar_and_base=true;
157  sample_upper_sugar_and_base=sample_sugar_and_base2_;
158  }else{
159  sample_lower_sugar_and_base=true;
160  sample_upper_sugar_and_base=false;
161  }
162  }else{//Append
163  if(list_position==1){ //3' most sample res.
164  sample_lower_sugar_and_base=false;
165  sample_upper_sugar_and_base=sample_sugar_and_base2_;
166  }else if( list_position==moving_suite_list_.size() ) { //5' most sample res.
167  sample_lower_sugar_and_base=sample_sugar_and_base1_;
168  sample_upper_sugar_and_base=true;
169  }else{
170  sample_lower_sugar_and_base=false;
171  sample_upper_sugar_and_base=true;
172  }
173  }
174  }
175 
176 
177  PuckerState const lower_res_puckerstate = Get_residue_pucker_state_internal(pose_, list_position, "lower", sample_lower_sugar_and_base);
178  PuckerState const upper_res_puckerstate = Get_residue_pucker_state_internal(pose_, list_position, "upper", sample_upper_sugar_and_base);
179 
180 
181  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
182 
183 
184  bool const Is_bulge = (list_position==1) ? false : true;
185  std::cout << "list_position=" << list_position; Output_boolean(" Is_bulge= " , Is_bulge); std::cout << std::endl;
186 
187  bool const sample_extra_rotamers= (Is_bulge) ? false : sample_extra_rotamers_;
188  bool const fast = (list_position==1) ? fast_ : false; //Only make the sampling suite fast..
189 
190  //StepWiseRNA_RotamerGeneratorOP rotamer_generator = new StepWiseRNA_RotamerGenerator( moving_suite_list_[list_position], lower_res_puckerstate, upper_res_puckerstate, Is_bulge);
191 
192  StepWiseRNA_RotamerGeneratorOP rotamer_generator = new StepWiseRNA_RotamerGenerator( moving_suite_list_[list_position],
193  sample_lower_sugar_and_base,
194  sample_upper_sugar_and_base,
195  lower_res_puckerstate,
196  upper_res_puckerstate);
197 
198  if(Is_bulge){
199  rotamer_generator->set_sample_chi_torsion( false );
200  }else{
201  rotamer_generator->set_sample_chi_torsion( sample_chi_torsion_ );
202  }
203 
204  rotamer_generator->set_fast( fast );
205  rotamer_generator->set_sample_extra_rotamers(sample_extra_rotamers);
206 
207  rotamer_generator->set_include_syn_chi(include_syn_chi_);
208  rotamer_generator->set_allow_syn_pyrimidine(allow_syn_pyrimidine_);
209  rotamer_generator->set_force_syn_chi_res_list(force_syn_chi_res_list_);
210 
211  rotamer_generator->set_bin_size(bin_size_);
212  rotamer_generator->set_extra_epsilon( ( (Is_bulge) ? false : extra_epsilon_ ) );
213  rotamer_generator->set_extra_beta( ( (Is_bulge) ? false : extra_beta_ ) );
214  rotamer_generator->set_extra_anti_chi( ( (Is_bulge) ? false : extra_anti_chi_ ) );
215  rotamer_generator->set_extra_syn_chi( ( (Is_bulge) ? false : extra_syn_chi_ ) );
216  rotamer_generator->set_exclude_alpha_beta_gamma_sampling(exclude_alpha_beta_gamma_sampling_);
217 
218 
219  rotamer_generator->initialize_rotamer_generator(pose_);
220 
221  return rotamer_generator;
222  }
223 
224  ////////////////////////////////////////////////////////////////////////
225  void
227  fast_=fast;
228 
229  }
230 
231  ////////////////////////////////////////////////////////////////////////
232  //Rewrote this function on April 30th, 2011
233  //The returned pucker_state value serves two roles
234  //First if sample_sugar_pucker==True, then pucker_state then specifies the pucker to be sampled by rotamer_generator_list_[list_position]
235  //Second if sample_sugar_pucker==False, then pucker_state then specifies the pucker determine from input pose or rotamer_generator_list_[list_position+1]
236 
238  StepWiseRNA_RotamerGenerator_Wrapper::Get_residue_pucker_state_internal( core::pose::Pose const & pose, Size const list_position, std::string const which_sugar, bool sample_sugar_pucker) const{
239 
240 
241 
242  Size const working_moving_suite = moving_suite_list_[list_position];
243  Size const working_moving_pucker= (which_sugar=="lower") ? working_moving_suite : working_moving_suite+1; //April 29, 2011
244 
245 
246  if(sample_sugar_pucker){
247 
248  if(Contain_seq_num(working_moving_pucker, force_north_ribose_list_)) return NORTH;
249 
250  if(Contain_seq_num(working_moving_pucker, force_south_ribose_list_)) return SOUTH;
251 
252  return ALL;
253 
254  }else{
255 
256  PuckerState pucker_state;
257 
258  bool Is_first_of_multiple_res_plus_internal_case=false;
259 
260  if( ( list_position==1 && moving_suite_list_.size()>1) ){
261  if(which_sugar=="lower" && Is_prepend_) Is_first_of_multiple_res_plus_internal_case=true; //Must be internal since prepend, since lower sugar is not sampled.
262  if(which_sugar=="upper" && !Is_prepend_) Is_first_of_multiple_res_plus_internal_case=true; //Must be internal since append, since lower sugar is not sampled.
263  }
264 
265  if(list_position==rotamer_generator_list_.size() || Is_first_of_multiple_res_plus_internal_case){ //the ribose belong to a prexisting input pose.
266 
267  pucker_state=Get_residue_pucker_state( pose, working_moving_pucker , true );
268 
269  }else{ //these correspond to sugars that were sampled by the rotamer_generator_list[list_position+1]
270 
271  if(moving_suite_list_.size()<2) utility_exit_with_message("moving_suite_list_.size()<2");
272 
273 
274  if(Is_prepend_){
275 
276  if(which_sugar!="upper" ) utility_exit_with_message( "which_sugar!=\"upper\"" ); //upper sugar pucker is the one not sampled if prepend
277 
278  if( (working_moving_suite+1) != rotamer_generator_list_[list_position+1]->moving_suite()){
279  utility_exit_with_message( "(moving_suite+1) != rotamer_generator_list_[list_position+1]->moving_suite()" );
280  }
281 
282  pucker_state=rotamer_generator_list_[list_position+1]->pucker_state("lower"); //if prepend, then lower of rotamer_generator_list_[list_position+1] is upper of rotamer_generator_list_[list_position]
283 
284 
285  }else{ //Append
286 
287  if(which_sugar!="lower") utility_exit_with_message( "which_sugar!=\"lower\"" ); //lower sugar pucker is the one not sampled if append
288 
289  if( (working_moving_suite-1) != rotamer_generator_list_[list_position+1]->moving_suite()){
290  utility_exit_with_message( "(moving_suite-1) != rotamer_generator_list_[list_position+1]->moving_suite()" );
291  }
292 
293  pucker_state=rotamer_generator_list_[list_position+1]->pucker_state("upper"); //if append upper of rotamer_generator_list_[list_position+1] is lower of rotamer_generator_list_[list_position]
294  }
295  }
296 
297  if(Contain_seq_num(working_moving_pucker, force_north_ribose_list_) && pucker_state!=NORTH){
298  utility_exit_with_message("Contain_seq_num(working_moving_pucker, force_north_ribose_list_) && pucker_state!=NORTH, working_moving_pucker=" + ObjexxFCL::string_of(working_moving_pucker) );
299  }
300 
301  if(Contain_seq_num(working_moving_pucker, force_south_ribose_list_) && pucker_state!=SOUTH){
302  utility_exit_with_message("Contain_seq_num(working_moving_pucker, force_south_ribose_list_) && pucker_state!=SOUTH, working_moving_pucker=" + ObjexxFCL::string_of(working_moving_pucker) );
303  }
304 
305  return pucker_state;
306 
307  }
308  }
309 
310 
311  ////////////////////////////////////////////////////////////////////////
312  bool
314 
315  for(Size list_position=rotamer_generator_list_.size(); list_position>=2; list_position--){
316  if(rotamer_generator_list_[list_position]->num_rotamer_centers() != rotamer_generator_list_[list_position]->group_rotamer()) return true;
317  }
318 
320  }
321 
322 
323  ////////////////////////////////////////////////////////////////////////
326 
327  using namespace core::id;
328 
329  assert( has_another_rotamer() );
330 
331  utility::vector1< bool > need_initialization_list(moving_suite_list_.size(), false);
332 
333  //Update rotamer_generator_list_.
334  for(Size n=1; n<=rotamer_generator_list_.size(); n++){
336  rotamer_generator_list_[n]->update_to_next_rotamer();
337  break;
338  }else{
339  need_initialization_list[n]=true;
340  std::cout << "Bulge_rotamer_ID= " << rotamer_generator_list_[2]->group_rotamer() << std::endl;
341  }
342  }
343 
344  //Need to reinitialize rotamer_generator since the pucker of other suites might change.
345  for(Size n=rotamer_generator_list_.size(); n>=1; n--){ //Important to initialize in this order.
346  if(need_initialization_list[n]==true){
347  rotamer_generator_list_[n]=setup_rotamer_generator(n); //This assumes that rotamer_generator[n+1] is setup and probably initialized
348  }
349  }
350 
351  utility::vector1< Torsion_Info > all_rotamer_list;
352  all_rotamer_list.clear();
353 
354  //Update all_rotamer_list
355  for(Size n=1; n<=moving_suite_list_.size(); n++){
356  utility::vector1< Torsion_Info > suite_rotamer_list=rotamer_generator_list_[n]->get_current_rotamer();
357  for(Size i=1; i<=suite_rotamer_list.size(); i++){
358  all_rotamer_list.push_back(suite_rotamer_list[i]);
359  }
360  }
361 
362 // std::cout << "all_rotamer_list.size()= " << all_rotamer_list.size() << std::endl;
363 
364  return all_rotamer_list;
365  }
366  /////////////////////////////////////////////////////////////////////////
367  core::Size
369  return rotamer_generator_list_[list_position]->group_rotamer();
370  }
371  /////////////////////////////////////////////////////////////////////////
372  core::Size
374  return rotamer_generator_list_[list_position]->subgroup_rotamer();
375  }
376 
377  /////////////////////////////////////////////////////////////////////////
378 
379 }
380 }
381 }