Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StepWiseRNA_VirtualRiboseSampler.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_VitualRiboseSampler
11 /// @brief Not particularly fancy, just minimizes a list of poses.
12 /// @detailed
13 /// @author Parin Sripakdeevong
14 
15 
16 //////////////////////////////////
18 #include <protocols/swa/rna/StepWiseRNA_OutputData.hh> //Sept 26, 2011
20 //#include <protocols/swa/rna/StepWiseRNA_FloatingBase_Sampler_Util.hh>
31 
34 #include <core/id/TorsionID.hh>
35 //////////////////////////////////
36 #include <core/pose/util.hh>
37 #include <basic/Tracer.hh>
38 #include <core/types.hh>
40 #include <core/chemical/util.hh>
43 #include <core/chemical/AtomType.hh>
47 #include <core/pose/Pose.hh>
48 #include <core/io/pdb/pose_io.hh>
64 //#include <core/id/AtomID_Map.Pose.hh>
65 #include <set>
66 #include <numeric/conversions.hh>
67 #include <iostream>
68 #include <fstream>
69 #include <sstream>
70 #include <ObjexxFCL/format.hh>
71 #include <ObjexxFCL/string.functions.hh>
73 #include <core/scoring/Energies.hh>
76 
77 using namespace core;
78 
79 static basic::Tracer TR( "protocols.swa.stepwise_rna_virtual_ribose_sampler" );
80 
81 namespace protocols {
82 namespace swa {
83 namespace rna {
84 
85 
86 
87 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
88 
89 
90 
91  bool
92  fast_full_atom_VDW_repulsion_screen(core::pose::Pose const & pose, core::Size const res_1, core::Size const res_2, bool const Is_prepend){
93 
94  conformation::Residue const & rsd_1=pose.residue(res_1);
95  conformation::Residue const & rsd_2=pose.residue(res_2);
96 
97 
98  for( Size n_1 = 1; n_1 <= rsd_1.natoms(); n_1++){
99 
100  //atom 1-4 are " P ", " O1P", " O2P" and " O5*"
101  Size const act_res_1= (Is_prepend && n_1 <= 4) ? res_1 + 1: res_1;
102 
103  if(pose.residue(act_res_1).atom_type(n_1).name()=="VIRT" ) continue;
104 
105  for( Size n_2 = 1; n_2 <= rsd_2.natoms(); n_2++){
106 
107  Size const act_res_2= (Is_prepend && n_2 <= 4) ? res_2 + 1: res_2;
108 
109  if(pose.residue(act_res_2).atom_type(n_2).name()=="VIRT" ) continue;
110 
111  Real const VDW_radius_1=pose.residue(act_res_1).atom_type(n_1).lj_radius();
112  Real const VDW_radius_2=pose.residue(act_res_2).atom_type(n_2).lj_radius();
113 
114  Real const clash_dist_cutoff=0.8; //Fail van der Waals replusion screen if two atoms radius within 0.5 Angstrom of each other
115 
116  Real const clash_radius=VDW_radius_1+VDW_radius_2-clash_dist_cutoff;
117 
118  if( (pose.residue(act_res_1).xyz( n_1) - pose.residue(act_res_2).xyz(n_2) ).length_squared() < clash_radius*clash_radius ){
119  return false; //OK consider fail screening if find even one crash...
120  }
121 
122  }
123  }
124  return true;
125  }
126 
127 
128  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
129  //Duplication of Full_atom_van_der_Waals_screening from StepWiseRNA_ResidueSampler.cc. NEED TO MERGE THEM BACK TOGETHER AFTER TESTING! Apr 20,2010. Parin S.
130  bool
132  core::Real const & base_rep_score,
133  core::scoring::ScoreFunctionOP const & atr_rep_screening_scorefxn,
134  SillyCountStruct & count_data,
135  bool const verbose){
136 
137  using namespace core::scoring;
138 
139  (*atr_rep_screening_scorefxn)(current_pose_screen);
140 
141  EnergyMap const & energy_map = current_pose_screen.energies().total_energies();
142  Real rep_score = atr_rep_screening_scorefxn->get_weight(fa_rep) * energy_map[scoring::fa_rep];
143 
144  Real delta_rep_score=rep_score-base_rep_score;
145 
146  Real actual_rep_cutoff=10; //defualt
147 
148  bool pass_rep_screen=false;
149 
150  if( delta_rep_score < actual_rep_cutoff ){
151  pass_rep_screen=true;
152  count_data.good_rep_rotamer_count++;
153 
154  if ( verbose ) {
155  std::cout << "rep= " << delta_rep_score;
156  std::cout << " rep_n= " << count_data.good_rep_rotamer_count;
157  std::cout << " fast_rep_count= " << count_data.fast_full_atom_VDW_replusion_screen;
158  std::cout << " bin_rep_count= " << count_data.good_bin_rep_count;
159  std::cout << " tot= " << count_data.tot_rotamer_count << std::endl;
160  }
161  return true;
162  } else {
163  return false;
164  }
165  }
166 
167 
168  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
169 
170  //Duplication of Chain_break_screening function from StepWiseRNA_ResidueSampler.cc. NEED TO MERGE THEM BACK TOGETHER AFTER TESTING! Apr 20,2010. Parin S.
171  bool
173  core::scoring::ScoreFunctionOP const & chainbreak_scorefxn,
174  SillyCountStruct & count_data,
175  core::Size const & five_prime_res,
176  std::string const & tag,
177  bool const verbose){
178 
179  using namespace core::scoring;
180  using namespace core::scoring::rna;
181 
182  static protocols::rna::RNA_LoopCloser rna_loop_closer;
183 
184  set_CCD_torsions_to_zero(chain_break_screening_pose, five_prime_res); //Testing Oct 1, 2010
185 
186  rna_loop_closer.apply( chain_break_screening_pose, five_prime_res);
187 
188  (*chainbreak_scorefxn)(chain_break_screening_pose);
189 
190  scoring::EMapVector & energy_map= chain_break_screening_pose.energies().total_energies();
191  Real angle_score = energy_map[scoring::angle_constraint];
192  Real distance_score = energy_map[scoring::atom_pair_constraint];
193 
194 
195  if(angle_score<5) count_data.good_angle_count++;
196  if(distance_score<5) count_data.good_distance_count++;
197  if((angle_score<5) && (distance_score<5)){
198  count_data.chain_break_screening_count++;
199 
200  if(verbose){
201  std::cout << " tag= " << tag;
202  std::cout << " chain_closable_count= " << count_data.chain_closable_count;
203  std::cout << " angle= " << angle_score << " dist= " << distance_score;
204  std::cout << " angle_n= " << count_data.good_angle_count;
205  std::cout << " dist_n= " << count_data.good_distance_count;
206  std::cout << " chain_break_screening= " << count_data.chain_break_screening_count;
207  std::cout << " in_range_CCD_torsion= " << count_data.in_range_CCD_torsion;
208  std::cout << " tot= " << count_data.tot_rotamer_count << std::endl;
209  }
210  return true;
211  } else {
212  return false;
213  }
214  }
215 
216 
217 
218  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
219 
222  FloatingBaseChainClosureJobParameter const & FB_job_params,
223  core::scoring::ScoreFunctionOP const & atr_rep_screening_scorefxn,
224  core::scoring::ScoreFunctionOP const & full_scorefxn,
225  pose::Pose & viewer_pose,
226  bool const do_minimize){
227 
228  using namespace ObjexxFCL;
229  using namespace ObjexxFCL::fmt;
230  using namespace core::id;
231  using namespace core::chemical;
232  using namespace core::conformation;
233  using namespace core::scoring::rna;
234  using namespace protocols::rna;
235  using namespace core::scoring;
236  using namespace core::optimization;
237  using namespace core::pose;
238 
239  pose::Pose const viewer_pose_copy=viewer_pose;
240 
241  clock_t const time_start( clock() );
242 
243  core::scoring::rna::RNA_FittedTorsionInfo const rna_fitted_torsion_info;
244 
245  utility::vector1< FB_Pose_Data > pose_data_list; //This is the output pose_data_list;
246 
247  if(input_pose_data_list.size()==0) {return pose_data_list;} //return empty list
248  /////////////////////////////////////////////////////////////////////////////////////////////////////
249 
250 
251  StepWiseRNA_Base_Sugar_RotamerOP base_sugar_rotamer = new StepWiseRNA_Base_Sugar_Rotamer( FB_job_params.moving_res_base_state, FB_job_params.moving_res_pucker_state, rna_fitted_torsion_info);
252 
253  //July 28th, 2011 Could set extra_chi here, BUT necessary?
254 
255  int num_input_pose_data_pass_screen=0;
256  for(Size n=1; n<=input_pose_data_list.size(); n++){
257 
258  bool input_pose_data_pass_screen=false;
259 
260  pose_data_struct2 input_pose_data=input_pose_data_list[n];
261  base_sugar_rotamer->reset();
262  Size count=0;
263 
264  while(base_sugar_rotamer->get_next_rotamer()){
265  count++;
266 
267 // bool verbose = (n==1 && count==1) ? true: false;
268  bool verbose = true;
269 
270 
271  FB_Pose_Data pose_data;
272  pose_data.base_tag=input_pose_data.tag;
273 
274  pose_data.tag=input_pose_data.tag + "_" + base_sugar_rotamer->current_tag();
275 
276 
277  pose_data.score=0.0;
278 
279  pose::Pose pose_with_ribose=(*input_pose_data.pose_OP); //Hard copy
280 
281  pose_data.starting_fold_tree=pose_with_ribose.fold_tree();
282 
283  pose_data.starting_cst_set_OP= pose_with_ribose.constraint_set()->clone();
284  assert( pose_data.starting_cst_set_OP ); //if ( !cst_set ) cst_set = new ConstraintSet();
285 
286 
287 
288  (*atr_rep_screening_scorefxn)(pose_with_ribose);
289  Real const without_ribose_rep_score = atr_rep_screening_scorefxn->get_weight(fa_rep) * pose_with_ribose.energies().total_energies()[ scoring::fa_rep ];
290 
291  pose::remove_variant_type_from_pose_residue( pose_with_ribose, "VIRTUAL_RIBOSE", FB_job_params.moving_res );
292 
293  Add_harmonic_chainbreak_constraint(pose_with_ribose, FB_job_params.five_prime_chain_break );
294 
295  setup_chain_break_jump_point( pose_with_ribose, FB_job_params.moving_res, FB_job_params.reference_res, FB_job_params.five_prime_chain_break, verbose);
296 
297  ///////////////////////////////////////////////////////////////////////////////////////////////////
298 
299 
300  if(verbose){
301  std::cout << " delta1= " << F(8, 3, base_sugar_rotamer->delta()) << " chi_1= " << F(8, 3, base_sugar_rotamer->chi());
302  std::cout << " nu2_1= " << F(8, 3, base_sugar_rotamer->nu2()) << " nu1_1= " << F(8, 3, base_sugar_rotamer->nu1());
303  std::cout << std::endl;
304  }
305 
306  pose_with_ribose.set_torsion( TorsionID( FB_job_params.moving_res , id::BB, 4 ) , base_sugar_rotamer->delta());
307  pose_with_ribose.set_torsion( TorsionID( FB_job_params.moving_res , id::CHI, 1 ) , base_sugar_rotamer->chi());
308  pose_with_ribose.set_torsion( TorsionID( FB_job_params.moving_res , id::CHI, 2 ) , base_sugar_rotamer->nu2());
309  pose_with_ribose.set_torsion( TorsionID( FB_job_params.moving_res , id::CHI, 3 ) , base_sugar_rotamer->nu1());
310 
311  //testing
312  //pose_with_ribose.dump_pdb( "pose_with_ribose_before_minimize_"+ string_of(count) + ".pdb" );
313 
314  //////////////////////////////////////minimize to remove ribose clashes (May 23, 2010)/////////////////////////////////////
315  if(do_minimize==true){
316 
317  core::scoring::ScoreFunctionOP ribose_scorefxn = full_scorefxn->clone();
318  ribose_scorefxn->set_weight( linear_chainbreak, 0.0);
319  ribose_scorefxn->set_weight( angle_constraint, 0.0 );
320  ribose_scorefxn->set_weight( atom_pair_constraint, 0.0 );
321  ribose_scorefxn->set_weight( coordinate_constraint, 0.1 );
322  core::scoring::ScoreFunctionOP ribose_scorefxn_without_ch_bond = ribose_scorefxn->clone();
323  ribose_scorefxn_without_ch_bond->set_weight( ch_bond, 0.0 );
324  //This makes sure that there are no chain_break score involved.
325 
326  //////////////////////Sept 20, 2011 To solve the problem with the floating base res expoding when minimizing/////////////////////////////////////////////////////////////////
327  //////////////////////Problem case occur when flaoting base res is the 1st working res///////////////////////////////////////////////////////////////////////////////////////
328  //////////////////////Note that this error doesn't seem to occur if virtual_ribose is sampled in same step as SAMPLER/ (no Hbond_tripped!)///////////////////////////////////
329  //////////////////////The non-rescale scorefxn does however causes the floating base from moving far away from the starting point even in the same step as SAMPLER case//////
330  //////////////////////Also generally the minimizer same and seperate step virtual sampler doesn't give the same results!/////////////////////////////////////////////////////
331  std::cout << "--------------START Creating rescaled one_tenth_ribose_score_fxn_without_ch_bond--------------" << std::endl;
332  core::scoring::ScoreFunctionOP rescaled_ribose_score_fxn_without_ch_bond=rescale_scorefxn(ribose_scorefxn_without_ch_bond, 0.1);
333  std::cout << "--------------FINISH Creating rescaled one_tenth_ribose_score_fxn_without_ch_bond--------------" << std::endl;
334  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
335 
336  AtomTreeMinimizer minimizer;
337  bool const use_nblist( true );
338 
339  //float const dummy_tol( 0.00000025);
340  //MinimizerOptions options_standard( "dfpmin", dummy_tol, use_nblist, false, false );
341 
342  //float const tolerance= 0.25; //Tested for dfpmin_atol, this lead to different result which is NOT worst than the energy score with 0.00000025 dfpmin_atol in every case!
343  //float const tolerance= 0.00000025; //If use this tolerance value, different result for dfp_min and dfpmin_atol.
344  float const tolerance= 0.000000000000025; //Sept 21, 2011, same result for dfp_min and dfpmin_atol| converge to identical energy score with 0.00000025 of dfpmin_atol!
345 
346  MinimizerOptions options_standard( "dfpmin_atol", tolerance, use_nblist, false, false ); //Switch to absolute tolerance on Sept 21, 2011
347  MinimizerOptions options_armijo( "dfpmin_armijo_atol", tolerance, use_nblist, false, false ); //Add this on Sept 21, 2011
348 
349  std::cout << "options_standard: min_type= " << options_standard.min_type() << " minimize_tolerance= " << options_standard.minimize_tolerance() << std::endl;
350  std::cout << "options_armijo : min_type= " << options_armijo.min_type() << " minimize_tolerance= " << options_armijo.minimize_tolerance() << std::endl;
351 
352  options_standard.nblist_auto_update( true );
353  options_armijo.nblist_auto_update( true );
354 
356 
357  mm.set_bb(false);
358  mm.set_chi(false);
359 
360 
361  if(verbose) std::cout << "pose.fold_tree().num_jump()= " << pose_with_ribose.fold_tree().num_jump() << std::endl;
362 
363  Size bulge_jump_1, bulge_jump_2, bulge_cutpoint;
364  if(FB_job_params.moving_res>FB_job_params.reference_res){//consistency check (from setup_chain_break_jump_point function)
365  bulge_jump_1=FB_job_params.reference_res;
366  bulge_jump_2=FB_job_params.moving_res;
367  bulge_cutpoint=FB_job_params.moving_res-1;
368  }else{
369  bulge_jump_1=FB_job_params.moving_res;
370  bulge_jump_2=FB_job_params.reference_res;
371  bulge_cutpoint=FB_job_params.moving_res;
372  }
373 
374  if(verbose) std::cout << "bulge_cutpoint= " << bulge_cutpoint << " bulge_jump_1= " << bulge_jump_1 << " bulge_jump_2= " << bulge_jump_2 << std::endl;
375 
376 
377  bool found_desired_jump_ID=false;
378  for (Size jump_ID = 1; jump_ID <= pose_with_ribose.fold_tree().num_jump(); jump_ID++ ){
379  Size const jump_pos1( pose_with_ribose.fold_tree().upstream_jump_residue( jump_ID ) );
380  Size const jump_pos2( pose_with_ribose.fold_tree().downstream_jump_residue( jump_ID ) );
381  Size const cutpoint=pose_with_ribose.fold_tree().cutpoint(jump_ID);
382 
383  if(verbose) std::cout << "jump at jump_ID= " << jump_ID << " cutpoint= " << cutpoint << " jump_pos1= " << jump_pos1 << " jump_pos2= " << jump_pos2 << std::endl;
384 
385  if( (jump_pos1==bulge_jump_1 && jump_pos2==bulge_jump_2 ) || (jump_pos1==bulge_jump_2 && jump_pos1==bulge_jump_2 ) ) {
386  found_desired_jump_ID=true;
387  if(verbose) std::cout << "add movemap jump at jump_ID= " << jump_ID << " cutpoint= " << cutpoint << " jump_pos1= " << jump_pos1 << " jump_pos2= " << jump_pos2 << std::endl;
388  mm.set_jump( jump_ID, true );
389  }
390  }
391 
392  if(found_desired_jump_ID==false) utility_exit_with_message( "cannot find desired jump_ID" );
393 
394  //Rigid body movement...no free torsion!!
395  // core::scoring::constraints::add_coordinate_constraints( pose_with_ribose );//crap I left this on for May_28_1CSL_SYN_CHI_floating_base_use_May_18_data run!
396 
397  viewer_pose= pose_with_ribose;
398  std::cout << "removing ribose clashes pose # " << n << " sugar_rotamer # " << count << " " << std::endl;
399 
400  /////////////Switch to armijo on Sept 21, 2011///////////////////////////////////////////////////////////////////////////////////////
401  /////////////My understanding is that dfpmin_armijo is a "inexact" line search whereas the standard dfpmin is a exact line search///////
402  /////////////It seem to indicate the dfpmin should be slower (require more function evaluation) but at the same time more accurate//////
403  /////////////See http://www.rosettacommons.org/manuals/archive/rosetta3.3_user_guide/minimization_overview.html for details/////////////
404  /////////////However standard dfpmin seem to lead cases where the floating base just "explode" and more far away from starting point////
405  /////////////This sometimes lead to the Hbond tripped error/////////////////////////////////////////////////////////////////////////////
406  /////////////Side note: switching to dfpmin_atol (atol-> absolute tolerance didn't help!)///////////////////////////////////////////////
407  /////////////So switching to dfpmin_armijo which doesn't seem to exhibit this behavior//////////////////////////////////////////////////
408  /////////////Note that there is a currently a bug in in dfpmin_armijo:
409  /////////////core.optimization.LineMinimizer: Inaccurate G! step= 9.53674e-07 Deriv= -0.0226443 Finite Diff= 0.00628252/////////////////
410  /////////////Rhiju mention that this bug is fixed in the latest Rosetta version in trunk////////////////////////////////////////////////
411  /////////////So will keep using standard dfp_min except at the first minimiziation step/////////////////////////////////////////////////
412  /////////////Also tried two round minimizations with the first using options_armijo. This fix the "explode" bug but led to worst score!/
413 
414  minimize_with_constraints(viewer_pose, mm, rescaled_ribose_score_fxn_without_ch_bond, options_armijo ); //Add this round on Sept 20, 2011, Switch to armijo on Sept 21, 2011
415  minimizer.run( viewer_pose, mm, *(rescaled_ribose_score_fxn_without_ch_bond), options_armijo ); //Add this round on Sept 20, 2011, Switch to armijo on Sept 21, 2011
416  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
417  minimize_with_constraints(viewer_pose, mm, ribose_scorefxn_without_ch_bond, options_standard );
418  minimizer.run( viewer_pose, mm, *(ribose_scorefxn_without_ch_bond), options_standard );
419 
420  minimize_with_constraints(viewer_pose, mm, ribose_scorefxn, options_standard );
421  minimizer.run( viewer_pose, mm, *(ribose_scorefxn), options_standard );
422 
423  pose_with_ribose=viewer_pose;
424  }
425 
426  //testing
427  //pose_with_ribose.dump_pdb( "pose_with_ribose_after_minimize_"+ string_of(count) + ".pdb" );
428 
429 
430  ////////////////////////////////////////////Screens/////////////////////////////////////////////
431  //OK check that with this sugar, the chain can be theoretically closed..
432  std::string const moving_atom_name= (FB_job_params.Is_prepend) ? "O3*" : " C5*";
433  std::string const reference_atom_name= (FB_job_params.Is_prepend) ? " C5*" : "O3*";
434  Distance O3i_C5iplus2_distance=(pose_with_ribose.residue(FB_job_params.moving_res).xyz(moving_atom_name) - pose_with_ribose.residue(FB_job_params.reference_res).xyz(reference_atom_name) ).length();
435 
436  (*atr_rep_screening_scorefxn)(pose_with_ribose);
437  pose_data.base_rep_score = atr_rep_screening_scorefxn->get_weight(fa_rep) * pose_with_ribose.energies().total_energies()[ scoring::fa_rep ];
438 
439  std::cout << "tag= " << pose_data.tag << " with_ribose_rep= " << pose_data.base_rep_score << " without_ribose_rep_score= " << without_ribose_rep_score << " O3i_C5iplus2_dist= " << O3i_C5iplus2_distance;
440 
441 
442  if(O3i_C5iplus2_distance>O3I_C5IPLUS2_MAX_DIST){
443  std::cout << " O3i_C5iplus2_dist>O3I_C5IPLUS2_MAX_DIST(" << O3I_C5IPLUS2_MAX_DIST << ") " << std::endl;
444  continue;
445  }
446 
447  if((pose_data.base_rep_score-without_ribose_rep_score)>10){
448  std::cout << " RIBOSE_rep_score>10! "<< std::endl;
449  continue;
450  }
451  input_pose_data_pass_screen=true;
452  /////////////////////////////////////////////////////////////////////////////////////////////////////
453 
454  // Add to the CCD loop closure phosphate...this is always the 3' chain_break res...
455 
456  remove_virtual_rna_residue_variant_type(pose_with_ribose, FB_job_params.bulge_res);
457  pose::add_variant_type_to_pose_residue( pose_with_ribose, "VIRTUAL_PHOSPHATE", FB_job_params.five_prime_chain_break+1 );
458 
459  pose_data.pose_OP=new pose::Pose;
460  (*pose_data.pose_OP)=pose_with_ribose;
461  pose_data.Is_chain_close=false;
462  pose_data_list.push_back(pose_data);
463 
464  }
465  if(input_pose_data_pass_screen) num_input_pose_data_pass_screen++;
466  }
467 
468  Output_title_text("");
469 
470  std::cout << "input_pose_data_list.size()= " << input_pose_data_list.size() << " num_input_pose_data_pass_screen= " << num_input_pose_data_pass_screen;
471  std::cout << " pose_data_list.size()= " << pose_data_list.size() << std::endl;
472 
473  std::cout << "Total time in Floating_base_chain_closure SETUP: " << static_cast<Real>( clock() - time_start ) / CLOCKS_PER_SEC << std::endl;
474 
475  viewer_pose=viewer_pose_copy;
476 
477  return pose_data_list;
478  }
479 
480 
481  /////////////////////////////////////////////////////////////////////////////////////
482 
483  void
485  core::pose::Pose & viewer_pose,
486  FloatingBaseChainClosureJobParameter const & FB_job_params,
487  core::scoring::ScoreFunctionOP const & chainbreak_scorefxn,
488  core::scoring::ScoreFunctionOP const & atr_rep_screening_scorefxn,
489  StepWiseRNA_VDW_Bin_ScreenerOP const & VDW_bin_screener,
490  bool const CCD_grid_index_screen){
491 
492  Output_title_text("Floating_base_chain_closure SAMPLING");
493 
494  if(pose_data_list.size()==0) return; //early return
495 
496  //std::map<PuckerState, std::map<Base_bin , int , compare_base_bin> > chain_closure_grid_index; //"CCD_grid_index_screen no longer supported!"
497 
498  if(CCD_grid_index_screen){
499  utility_exit_with_message("CCD_grid_index_screen no longer supported!");
500  //chain_closure_grid_index[NORTH]=create_chain_closable_grid_index(FB_job_params, viewer_pose, NORTH);
501  //chain_closure_grid_index[SOUTH]=create_chain_closable_grid_index(FB_job_params, viewer_pose, SOUTH);
502  }
503 
504  clock_t const time_start_sampling( clock() );
505 
506  using namespace core::id;
507  using namespace core::chemical;
508  using namespace core::conformation;
509  using namespace core::scoring::rna;
510  using namespace protocols::rna;
511  using namespace core::scoring;
512  using namespace ObjexxFCL;
513 
514  core::scoring::rna::RNA_FittedTorsionInfo const rna_fitted_torsion_info;
515 
516  viewer_pose=(*pose_data_list[1].pose_OP);
517  pose::Pose screening_pose=viewer_pose;
518 
519  ///Ok we need to create different rotamer_generator for the 1. backbone/exclude delta, 2. delta. and chi. (depend on delta)
520  ///This is necessary for optimization since CCD solution doesn't depend on chi torsion value
521 
522  std::cout << "setup backbone_rotamer_generator" << std::endl;
523  utility::vector1< core::Size > bulge_suite_list;
524  bulge_suite_list.clear();
525  bulge_suite_list.push_back(FB_job_params.bulge_suite);
526 
527  bool sample_sugar_and_base1( false ), sample_sugar_and_base2( false );
528 
529  if ( FB_job_params.Is_prepend ) {
530  sample_sugar_and_base1 = true;
531  } else {
532  sample_sugar_and_base2 = true;
533  }
534 
535 
536  //Will generate both NORTH AND SOUTH PUCKER HERE EVEN IF FB_job_params.bulge_res_pucker_state!=ALL..BUT OK SINCE WILL PERFORM MATCH WITH Base_Sugar_RotamerOP in the actual loop.
537  StepWiseRNA_RotamerGenerator_WrapperOP backbone_rotamer_generator =
538  new StepWiseRNA_RotamerGenerator_Wrapper( viewer_pose, bulge_suite_list, sample_sugar_and_base1, sample_sugar_and_base2);
539 
540  backbone_rotamer_generator->set_fast( false );
541  backbone_rotamer_generator->set_sample_chi_torsion(false);
542  backbone_rotamer_generator->set_include_syn_chi(true);
543  backbone_rotamer_generator->set_bin_size(20);
544 
545  bool more_rotamers=true;
546  if(more_rotamers){
547  backbone_rotamer_generator->set_extra_epsilon(true);
548  //backbone_rotamer_generator->set_extra_beta(true);
549  }
550 
551  backbone_rotamer_generator->initialize_rotamer_generator_list();
552 
553  std::cout << "setup_delta_rotamer_generator" << std::endl;
554 
555  StepWiseRNA_Base_Sugar_RotamerOP bulge_base_sugar_rotamer = new StepWiseRNA_Base_Sugar_Rotamer( FB_job_params.bulge_res_base_state, FB_job_params.bulge_res_pucker_state, rna_fitted_torsion_info);
556 
557  //July 28th, 2011 Could set extra_chi here, BUT necessary?
558 
559  SillyCountStruct count_data;
560  RNA_LoopCloser rna_loop_closer;
561 
562  Size num_closed_chain_pose=0;
563 
564  while( backbone_rotamer_generator->has_another_rotamer() ){ //BUT EPSILON DEPENDS on DELTA!
565  bulge_base_sugar_rotamer->reset();
566 
567  if(num_closed_chain_pose==pose_data_list.size()){
568  break; //early break, all pose had been closed...
569  }
570 
571  utility::vector1< Torsion_Info > const & BB_rotamer = backbone_rotamer_generator->get_next_rotamer();
572 
573  //optimization since CCD solution doesn't depend on chi torsion value, potential 6 fold speed up...
574  utility::vector1< bool > CCD_fail_for_BB_rotamer(pose_data_list.size(), false);
575 
576 
577  while( bulge_base_sugar_rotamer->get_next_rotamer() ){
578 
579  Real BB_delta_value=0.0;
580 
581  Size num_BB_delta_ID=0;
582  Size num_chi_torsion_ID=0;
583 
584  core::id::TorsionID const chi_torsion_ID=TorsionID( FB_job_params.bulge_res , id::CHI, 1 );
585  core::id::TorsionID const delta_torsion_ID=TorsionID( FB_job_params.bulge_res , id::BB, 4 );
586 
587  for( Size n = 1; n <= BB_rotamer.size(); n++ ){
588 
589  if(BB_rotamer[n].id==delta_torsion_ID){
590  BB_delta_value=BB_rotamer[n].value;
591  num_BB_delta_ID++;
592  }
593 
594  ////////Update this on May 1st, 2011, after updating RotamerGeneartor class to not include chi torsion ID when CHI torsion is not sampled.
595  if(BB_rotamer[n].id==chi_torsion_ID){
596  num_chi_torsion_ID++;
597  }
598 
599  }
600  if(num_BB_delta_ID!=1) utility_exit_with_message( "Error: num_BB_delta_ID in BB_rotamer !=1" );
601  if(num_chi_torsion_ID!=0) utility_exit_with_message( "Error: num_chi_torsion_ID in BB_rotamer !=0" );
602 
603  if(BB_rotamer.size()!=8) utility_exit_with_message( "BB_rotamer.size()=" + ObjexxFCL::string_of(BB_rotamer.size()) + "!=8!" ); //consistency_check
604 
605  if( (BB_delta_value < (bulge_base_sugar_rotamer->delta()-0.1) ) || ( BB_delta_value > (bulge_base_sugar_rotamer->delta()+0.1) ) ) continue;
606 
607  utility::vector1< Torsion_Info > current_rotamer = BB_rotamer;
608 
609  Torsion_Info chi_torsion_info;
610  chi_torsion_info.id=chi_torsion_ID;
611  chi_torsion_info.value=bulge_base_sugar_rotamer->chi();
612  current_rotamer.push_back(chi_torsion_info);
613 
614  if(current_rotamer.size()!=9) utility_exit_with_message( "current_rotamer.size()=" + ObjexxFCL::string_of(current_rotamer.size()) + " !=9!" ); //consistency check
615 
616  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
617  count_data.tot_rotamer_count++;
618 
619  apply_rotamer( screening_pose, current_rotamer);
620 
621  apply_rotamer( viewer_pose, current_rotamer);
622  viewer_pose.residue(1).xyz("C5*"); //This is just to force the viewer_pose to update...
623 
624 
625  //VDW_screen_bin
626  if( VDW_bin_screener->VDW_rep_screen(screening_pose, FB_job_params.bulge_res)==false) continue;
627 
628  count_data.good_bin_rep_count++;
629 
630  for(Size n=1; n<=pose_data_list.size(); n++){
631 
632  //if(CCD_fail_for_BB_rotamer[n]==true) continue; //already checked that this BB rotamer doesn't have a CCD solution. Feb 08, 2012: Commented out until further testing
633 
634  FB_Pose_Data & pose_data=pose_data_list[n];
635  if(pose_data.Is_chain_close==true) continue; //chain is already close...
636 
637  pose::Pose & current_pose=(*pose_data.pose_OP);
638 
639  if(FB_job_params.Is_prepend){
640  if(Check_chain_closable_floating_base(current_pose, screening_pose, FB_job_params.five_prime_chain_break, 0 )==false) continue;
641  }else{
642  if(Check_chain_closable_floating_base(screening_pose, current_pose, FB_job_params.five_prime_chain_break, 0 )==false) continue;
643  }
644  count_data.chain_closable_count++;
645 
646  apply_rotamer( current_pose, current_rotamer);
647 
648  //NEED THIS:Quick check that there is no VDW clash between bulge_res and moving_res
649  if( fast_full_atom_VDW_repulsion_screen(current_pose, FB_job_params.bulge_res, FB_job_params.moving_res, FB_job_params.Is_prepend) == false) continue;
650  count_data.fast_full_atom_VDW_replusion_screen++;
651 
652  if( floating_base_full_atom_van_der_Waals_screening(current_pose, pose_data.base_rep_score, atr_rep_screening_scorefxn, count_data, true)==false ) continue;
653 
654  if( floating_base_chain_break_screening(current_pose, chainbreak_scorefxn, count_data, FB_job_params.five_prime_chain_break, pose_data.tag, true)==false ){
655 
656  //CCD_fail_for_BB_rotamer[n]=true; //Feb 08, 2012. FIX ERROR, used to be == instead of =. Feb 08, 2012: Commented out until further testing
657 
658  continue;
659  }
660 
661  if( CCD_grid_index_screen){
662  utility_exit_with_message("CCD_grid_index_screen no longer supported!");
663  //if(floating_base_chain_break_grid_index_screening(current_pose, count_data, FB_job_params, chain_closure_grid_index)==false) continue;
664  }
665 
666  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
667 
668 // //Ok now phosphate torsion are defined remove virtual phosphate and check for clashes. Still need to implement this....May 14, 2010
669 // pose::remove_variant_type_from_pose_residue( viewer_pose , "VIRTUAL_PHOSPHATE", FB_job_params.five_prime_chain_break+1 );
670 //
671 // if( floating_base_full_atom_van_der_Waals_screening(current_pose, pose_data.base_rep_score, atr_rep_screening_scorefxn, count_data, true)==false){
672 // pose::add_variant_type_to_pose_residue( pose_with_ribose, "VIRTUAL_PHOSPHATE", FB_job_params.five_prime_chain_break+1 ); //Add back the virtual phosphate..
673 // continue;
674 // }
675 
676  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
677 
678  pose_data.Is_chain_close=true;
679  num_closed_chain_pose++;
680 
681 
682 
683  viewer_pose=current_pose; //Crap this is hard copy...computationally expensive!!
684  viewer_pose.residue(1).xyz("C5*"); //This is just to force the viewer_pose to update...
685  }
686  }
687  }
688 
689  std::cout << " bin_rep_count= " << count_data.good_bin_rep_count;
690  std::cout << " fast_rep_count= " << count_data.fast_full_atom_VDW_replusion_screen;
691  std::cout << " chain_closable= " << count_data.chain_closable_count;
692  std::cout << " angle_n= " << count_data.good_angle_count << " dist_n= " << count_data.good_distance_count;
693  std::cout << " rep= " << count_data.good_rep_rotamer_count;
694  std::cout << " rmsd= " << count_data.rmsd_count << " tot= " << count_data.tot_rotamer_count << std::endl;
695  std::cout << " " << num_closed_chain_pose << " out of " << pose_data_list.size() << " pose were closable" << std::endl;
696  std::cout << "Total time in Floating_base_chain_closure SAMPLING: " << static_cast<Real>( clock() - time_start_sampling ) / CLOCKS_PER_SEC << std::endl;
697  }
698 
699 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
700 
703  core::pose::Pose & viewer_pose,
704  core::scoring::ScoreFunctionOP const & sampling_scorefxn,
705  FloatingBaseChainClosureJobParameter const & FB_job_params,
706  bool const rm_chain_break_jump_point){
707 
708  using namespace core::optimization;
709  using namespace core::scoring;
710  using namespace core::pose;
711  using namespace core::io::silent;
712  using namespace protocols::rna;
713  using namespace core::id;
714  using namespace ObjexxFCL;
715 
716  Output_title_text("Floating_base_chain_closure POST_PROCESSING");
717  //clock_t const time_start_post_processing( clock() );
718 
719  utility::vector1< pose_data_struct2 > output_pose_data_list;
720 
721  if( pose_data_list.size()==0) {return output_pose_data_list;} //return empty list
722 
723  //Quick minimize to remove error in CCD?///////////////////////////
724  AtomTreeMinimizer minimizer;
725  float const dummy_tol( 0.00000025);
726  bool const use_nblist( true );
727  MinimizerOptions options( "dfpmin", dummy_tol, use_nblist, false, false );
728  options.nblist_auto_update( true );
729 
731 
732  mm.set_bb(false);
733  mm.set_chi(false);
734 
735  //The whole richardson's suite ... avoid delta, nu2, nu1, WARNING VIRTUAL_PHOSPHATE is ON at this point...
736  mm.set( TorsionID( FB_job_params.bulge_res-1 , id::BB, 5 ), true ); //epsilon
737  mm.set( TorsionID( FB_job_params.bulge_res-1 , id::BB, 6 ), true ); //zeta
738 
739  mm.set( TorsionID( FB_job_params.bulge_res , id::BB, 1 ), true ); //alpha
740  mm.set( TorsionID( FB_job_params.bulge_res , id::BB, 2 ), true ); //beta
741  mm.set( TorsionID( FB_job_params.bulge_res , id::BB, 3 ), true ); //gamma
742  mm.set( TorsionID( FB_job_params.bulge_res , id::BB, 5 ), true ); //epsilon
743  mm.set( TorsionID( FB_job_params.bulge_res , id::BB, 6 ), true ); //zeta
744  mm.set( TorsionID( FB_job_params.bulge_res , id::CHI, 1 ), true ); //chi (torsion between base and ribose sugar)
745 
746  mm.set( TorsionID( FB_job_params.bulge_res+1 , id::BB, 1 ), true ); //alpha
747  mm.set( TorsionID( FB_job_params.bulge_res+1 , id::BB, 2 ), true ); //beta
748  mm.set( TorsionID( FB_job_params.bulge_res+1 , id::BB, 3 ), true ); //gamma
749 
750  core::scoring::ScoreFunctionOP bulge_chain_closure_scorefxn = new ScoreFunction;
751  bulge_chain_closure_scorefxn->set_weight( fa_rep , 0.12 );
752  bulge_chain_closure_scorefxn->set_weight( angle_constraint, 1.0 );
753  bulge_chain_closure_scorefxn->set_weight( atom_pair_constraint, 1.0 );
754  bulge_chain_closure_scorefxn->set_weight( linear_chainbreak, 5.0);
755 
756  ////Hacky fix: this shouldn't be necessary but is required to fix bug (rna_sugar_close score adn geom_sol doesn't check for virtual_atoms)////////
757  ////PREVENT RANDOM ENERGETIC PENALTY!////
758  //bulge_chain_closure_scorefxn->set_weight( geom_sol, 62); //100X normal weight //MOD OUT July 23, 2011. GEOM_SOL and CI_GEOM_SOL NOW DOES CHECK FOR VIRTUAL_ATOM!
759  //bulge_chain_closure_scorefxn->set_weight( CI_geom_sol, 62); //100X normal weight //ADD AND MOD OUT July 23, 2011. GEOM_SOL and CI_GEOM_SOL NOW DOES CHECK FOR VIRTUAL_ATOM!
760 
761  bulge_chain_closure_scorefxn->set_weight( rna_sugar_close, 70); //100X normal weight
762 
763  mm.set( TorsionID( FB_job_params.bulge_res , id::CHI, 2 ), true ); //nu2
764  mm.set( TorsionID( FB_job_params.bulge_res , id::CHI, 3 ), true ); //nu1
765 
766  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
767 
768  for(Size n=1; n<=pose_data_list.size(); n++){
769  if(pose_data_list[n].Is_chain_close==false) continue;
770 
771  viewer_pose= (*pose_data_list[n].pose_OP);
772 
773  std::cout << "POST_PROCESSING pose # " << n << " out of " << pose_data_list.size() << " " << std::endl;;
774  minimizer.run( viewer_pose, mm, *(bulge_chain_closure_scorefxn), options );
775 
776  viewer_pose.constraint_set( pose_data_list[n].starting_cst_set_OP);
777 
778  if(rm_chain_break_jump_point) remove_chain_break_jump_point(viewer_pose, FB_job_params.five_prime_chain_break, pose_data_list[n].starting_fold_tree);
779 
780  pose::remove_variant_type_from_pose_residue( viewer_pose , "VIRTUAL_PHOSPHATE", FB_job_params.five_prime_chain_break+1 );
781  apply_virtual_rna_residue_variant_type( viewer_pose, FB_job_params.bulge_res);
782 
783  pose_data_list[n].score=(*sampling_scorefxn)(viewer_pose); //for output purposes...
784 
785  (*pose_data_list[n].pose_OP)=viewer_pose;
786 
787  //////////////////////////////////////////
788  //Warning data_data_list and output_pose_data_list doesn't have the same underlying structure!! Apr 20, 2010
789  pose_data_struct2 pose_data;
790  pose_data.pose_OP=pose_data_list[n].pose_OP;
791  pose_data.score=pose_data_list[n].score;
792  pose_data.tag=pose_data_list[n].tag;
793 
794  output_pose_data_list.push_back(pose_data);
795  }
796 
797 
798  return output_pose_data_list;
799  // The following line would never have been reached. ~Labonte
800  //std::cout << "Total time in Floating_base_chain_closure_post_processing: " <<
801  //static_cast<Real>( clock() - time_start_post_processing ) / CLOCKS_PER_SEC << std::endl;
802 
803  }
804 
805  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
806 
807  void
810  utility::vector1< pose_data_struct2 > & pose_data_list,
811  core::scoring::ScoreFunctionOP const & sampling_scorefxn,
812  StepWiseRNA_JobParametersCOP const & job_parameters,
813  bool const virtual_ribose_is_from_prior_step){
814 
815  using namespace core::optimization;
816  using namespace core::scoring;
817  using namespace core::pose;
818  using namespace core::io::silent;
819  using namespace protocols::rna;
820  using namespace core::id;
821  using namespace ObjexxFCL;
822 
823  Output_title_text("Enter minimize_all_sampled_floating_bases");
824 
825  pose::Pose const viewer_pose_copy=viewer_pose;
826 
827 
828  if(FB_JP_list.size()==0) return;
829  if(pose_data_list.size()==0) return;
830 
831  AtomTreeMinimizer minimizer;
832  float const dummy_tol( 0.00000025);
833  bool const use_nblist( true );
834  MinimizerOptions options( "dfpmin", dummy_tol, use_nblist, false, false );
835  options.nblist_auto_update( true );
836 
837 
839 
840  mm.set_bb(false);
841  mm.set_chi(false);
842 
843  for(Size n=1; n<=FB_JP_list.size(); n++){
844 
845  FloatingBaseChainClosureJobParameter const & FB_job_params=FB_JP_list[n];
846 
847  mm.set( TorsionID( FB_job_params.bulge_res-1 , id::BB, 5 ), true ); //epsilon
848  mm.set( TorsionID( FB_job_params.bulge_res-1 , id::BB, 6 ), true ); //zeta
849 
850  mm.set( TorsionID( FB_job_params.bulge_res , id::BB, 1 ), true ); //alpha
851  mm.set( TorsionID( FB_job_params.bulge_res , id::BB, 2 ), true ); //beta
852  mm.set( TorsionID( FB_job_params.bulge_res , id::BB, 3 ), true ); //gamma
853  mm.set( TorsionID( FB_job_params.bulge_res , id::BB, 5 ), true ); //epsilon
854  mm.set( TorsionID( FB_job_params.bulge_res , id::BB, 6 ), true ); //zeta
855  mm.set( TorsionID( FB_job_params.bulge_res , id::CHI, 1 ), true ); //chi (torsion between base and ribose sugar)
856 
857  mm.set( TorsionID( FB_job_params.bulge_res+1 , id::BB, 1 ), true ); //alpha
858  mm.set( TorsionID( FB_job_params.bulge_res+1 , id::BB, 2 ), true ); //beta
859  mm.set( TorsionID( FB_job_params.bulge_res+1 , id::BB, 3 ), true ); //gamma
860 
861  }
862 
863  for(Size n=1; n<=pose_data_list.size(); n++){
864 
865  viewer_pose= (*pose_data_list[n].pose_OP);
866 
867  utility::vector1 < core::Size > const & working_moving_partition_pos = job_parameters->working_moving_partition_pos();
868  utility::vector1 < core::Size > already_virtualized_res_list;
869 
870  if(virtual_ribose_is_from_prior_step){ //Virtualize the other partition since it doesn't exist in prior step!
871 
872  for(Size ii=1; ii<=working_moving_partition_pos.size(); ii++){
873  Size const seq_num=working_moving_partition_pos[ii];
874  if(viewer_pose.residue(seq_num).has_variant_type("VIRTUAL_RNA_RESIDUE")){
875  already_virtualized_res_list.push_back(seq_num);
876  continue;
877  }
878 
879  pose::add_variant_type_to_pose_residue( viewer_pose, "VIRTUAL_RNA_RESIDUE", seq_num );
880 
881  }
882 
883  if (job_parameters->gap_size() == 0) pose::add_variant_type_to_pose_residue( viewer_pose, "VIRTUAL_PHOSPHATE", job_parameters->five_prime_chain_break_res()+1 );
884  }
885 
886  std::cout << "minimize_all_sampled_floating_bases pose # " << n << " out of " << pose_data_list.size() << " " << std::endl;;
887  minimizer.run( viewer_pose, mm, (*sampling_scorefxn), options );
888 // o2star_minimize(viwer_pose, sampling_scorefxn)
889 // minimizer.run( viewer_pose, mm, (*sampling_scorefxn), options );
890 
891  if(virtual_ribose_is_from_prior_step){ //Virtualize the other partition since it doesn't exist in prior step!
892 
893  for(Size ii=1; ii<=working_moving_partition_pos.size(); ii++){
894  Size const seq_num=working_moving_partition_pos[ii];
895 
896  if(Contain_seq_num(seq_num, already_virtualized_res_list)) continue;
897 
898  pose::remove_variant_type_from_pose_residue( viewer_pose, "VIRTUAL_RNA_RESIDUE", seq_num );
899  }
900 
901  if (job_parameters->gap_size() == 0) pose::remove_variant_type_from_pose_residue( viewer_pose, "VIRTUAL_PHOSPHATE", job_parameters->five_prime_chain_break_res()+1 );
902  }
903 
904 
905  (*pose_data_list[n].pose_OP)=viewer_pose;
906  }
907 
908  viewer_pose=viewer_pose_copy;
909 
910  Output_title_text("Exit minimize_all_sampled_floating_bases");
911 
912  }
913 
914 
915  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
916  bool
917  Is_ribose_virtual( core::pose::Pose const & pose, core::Size const ribose_res, core::Size const bulge_res){
918 
919  using namespace core::chemical;
920  using namespace core::conformation;
921  using namespace ObjexxFCL;
922 
923  Size const nres= pose.total_residue();
924 
925  if( ( ribose_res+1)!= bulge_res && ( ribose_res-1)!= bulge_res ) {
926  std::cout << "ribose_res= " << ribose_res << " bulge_res= " << bulge_res << std::endl;
927  utility_exit_with_message( "( ribose_res+1)!= bulge_res && ( ribose_res-1)!= bulge_res)" );
928  }
929 
930  if(ribose_res<1 || ribose_res> nres){
931  utility_exit_with_message( "ribose_res<1 || ribose_res> nres("+ string_of(nres) +")!. ribose_res= " + string_of(ribose_res) );
932  }
933 
934  if(pose.residue(ribose_res).has_variant_type("VIRTUAL_RIBOSE") ) {
935 
936  //ok consistency checks:
937  if(bulge_res<1 || bulge_res> nres){
938  utility_exit_with_message( "bulge_res<1 || bulge_res> nres("+ string_of(nres) +")!. bulge_res= " + string_of(bulge_res) );
939  }
940 
941  if(pose.residue(bulge_res).has_variant_type("VIRTUAL_RNA_RESIDUE")==false){
942  utility_exit_with_message("pose.residue(bulge_res).has_variant_type(\"VIRTUAL_RNA_RESIDUE\")==false" );
943  }
944 
945  return true;
946  }else{
947  return false;
948  }
949  }
950 
951  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
952  void
954 
955  using namespace ObjexxFCL;
956  using namespace core::io::silent;
957  using namespace core::id;
958 
959  pose::remove_variant_type_from_pose_residue( pose, "VIRTUAL_RIBOSE", FB_job_params.moving_res );
960 
961  std::map< core::Size, core::Size > res_map; //This is map from sub numbering to input_res numbering..
962  res_map[ FB_job_params.moving_res ] = FB_job_params.moving_res;
963  res_map[ FB_job_params.bulge_res ] = FB_job_params.bulge_res;
964  res_map[ FB_job_params.reference_res ] = FB_job_params.reference_res;
965 
966  //copy_dofs( pose, template_pose, res_map, true , false /*not verbose*/ ); //need to make sure this works for every case!
967 
968  //Dec 24, 2011 Parin S.:Convert to Rhiju's NEW version
969  copy_dofs_match_atom_names( pose, template_pose, res_map, false /*backbone_only*/, false /*ignore_virtual*/);
970 
971  }
972 
973  //////////////////////////////////////////////////////////////////////////
974  bool
975  sort_pose_data_by_score(pose_data_struct2 pose_data_1, pose_data_struct2 pose_data_2) { //Duplicate!
976  return (pose_data_1.score < pose_data_2.score);
977  }
978 
979 
980  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
981  ////////July 21, 2011 Move from StepWiseRNA_ResidueSampler.cc ////////////////////////////////////////////////
982  ////////Code used to be part of the function StepWiseRNA_ResidueSampler::previous_floating_base_chain_closure();
983 
984  //Dec 9, 2010
985  //Warning, currently the code doesn't handle the case of i-1, i-3 (and potentially i-5 and so on) bulges very well. Basically will sample the sugar conformation of base i. But even though base i-2, i-4 have virtual riboses, these sugars are not sampled (use the one that currently exist in the pose) which is NOT a complete fail, since the ribose did pass distance check of Check_chain_closable()(correctly implement this on Dec 9,2010) and VDW screening.
986  //Possible ways to fix this (HOWEVER lets not fix this until we actual find a REAL existing case where i-1 and i-3 are bulge res):
987 
988  //Will have to at least rewrite both floating_base_chain_closure_setup() and floating_base_chain_closure_sampling() to sample both i and i-2 ribose.
989  //Hardest 1. To change this would have to recursively sample the conformation of the bulge and corresponding virtual ribose starting from the bulge that is futhest away. If assuem that each bulge conformation is independent of the other bulges then this is not very computationally expensive. Although this would require sampling two ribose for each bulge except for the bulge that is futhest again. A trace back is then needed to find combinations of all the bulge conformation which is closable.
990  //Medium 2. Another possibility is to simple assume that i-2 base can assume all bulge conformation subjected to check_chain_closable.
991  //Easiest 3. Just set chain_closure_sampling to false in this function. This will just keep all possible bulge conformation in pose_data_list that pass O3i_C5iplus2_distance>O3I_C5IPLUS2_MAX_DIST (in setup)
992  //However in Easiest 3. case, there is a problem is problem in that O3i_C5iplus2_distance has determined with fixed i-2 ribose.
993 
996  FloatingBaseChainClosureJobParameter const & FB_job_params,
997  std::string const name,
998  core::scoring::ScoreFunctionOP const & scorefxn,
999  core::scoring::ScoreFunctionOP const & sampling_scorefxn,
1000  core::scoring::ScoreFunctionOP const & atr_rep_screening_scorefxn,
1001  core::scoring::ScoreFunctionOP const & chainbreak_scorefxn,
1002  StepWiseRNA_JobParametersCOP & job_parameters,
1003  bool const virtual_ribose_is_from_prior_step){
1004 
1005  using namespace ObjexxFCL;
1006  using namespace core::io::silent;
1007 
1008  Output_title_text("Enter sample_virtual_ribose_and_bulge_and_close_chain()");
1009  clock_t const time_start( clock() );
1010 
1011  pose::Pose const viewer_pose_copy=viewer_pose; //BACKUP
1012 
1013  FB_job_params.check_compatibility(viewer_pose.total_residue());
1014 
1015  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1016  ///Switch order so that virtualize before creating VDW_bin_screener July 18, 2010
1017 
1018  pose_data_struct2 pose_data;
1019  pose_data.pose_OP=new pose::Pose;
1020  (*pose_data.pose_OP)= viewer_pose;
1021  pose_data.score = 0.0;
1022  pose_data.tag="";
1023 
1024  pose::Pose & input_pose= (*pose_data.pose_OP);
1025 
1026  utility::vector1 < core::Size > other_partition_pos; //June 13, 2011..Before used to just use moving_partition_pos here since bulge_res was always in the root_partition!
1027  utility::vector1 < core::Size > already_virtualized_res_list;
1028  ////////////////////////////////////////////////////////////
1029  if(virtual_ribose_is_from_prior_step){ //Virtualize the other partition since it doesn't exist in prior step!
1030 
1031  Size const nres = job_parameters->working_sequence().size();
1032  ObjexxFCL::FArray1D< bool > const & partition_definition = job_parameters->partition_definition();
1033  bool const bulge_res_partition_value=partition_definition(FB_job_params.bulge_res);
1034 
1035  if( bulge_res_partition_value!=partition_definition(FB_job_params.moving_res) ){ //Check that these three nts are in the same paritition!
1036  utility_exit_with_message("bulge_res_partition_value!=partition_definition(FB_job_params.moving_res)");
1037  }
1038 
1039  if( bulge_res_partition_value!=partition_definition(FB_job_params.reference_res) ){ //Check that these three nts are in the same paritition!
1040  utility_exit_with_message("bulge_res_partition_value!=partition_definition(FB_job_params.reference_res)");
1041  }
1042 
1043  for(Size seq_num=1; seq_num<=nres; seq_num++){
1044  if ( partition_definition( seq_num ) != bulge_res_partition_value ) other_partition_pos.push_back( seq_num );
1045  }
1046 
1047  for(Size ii=1; ii<=other_partition_pos.size(); ii++){
1048  Size const seq_num=other_partition_pos[ii];
1049  if(input_pose.residue(seq_num).has_variant_type("VIRTUAL_RNA_RESIDUE")){
1050  already_virtualized_res_list.push_back(seq_num);
1051  continue;
1052  }
1053  pose::add_variant_type_to_pose_residue( input_pose, "VIRTUAL_RNA_RESIDUE", seq_num );
1054  }
1055 
1056  if(job_parameters->gap_size() == 0){
1057  if(input_pose.residue(job_parameters->five_prime_chain_break_res()+1).has_variant_type("VIRTUAL_PHOSPHATE")==true){
1058  utility_exit_with_message( "input_pose.residue(job_parameters_->five_prime_chain_break_res()+1).has_variant_type(\"VIRTUAL_PHOSPHATE\")==true" );
1059  }
1060  pose::add_variant_type_to_pose_residue( input_pose, "VIRTUAL_PHOSPHATE", job_parameters->five_prime_chain_break_res()+1);
1061  }
1062  }else{
1063  if(job_parameters->gap_size() == 0) utility_exit_with_message( "job_parameters_->gap_size() == 0" ); //If virt_ribse is from current step, then it should not be the last step!
1064  }
1065  ////////////////////////////////////////////////////////////
1066 
1067  //////////////////////////////////////////////////////////////////////create_VDW_screen_bin//////////////////////////////////////////////////////////////////////////////////////////
1068 
1069  core::kinematics::Stub reference_stub;
1070  reference_stub.v=core::scoring::rna::get_rna_base_centroid( input_pose.residue( FB_job_params.reference_res ) , true);
1071  reference_stub.M=core::scoring::rna::get_rna_base_coordinate_system( input_pose.residue( FB_job_params.reference_res ) , reference_stub.v);
1072 
1073 
1074  utility::vector1 < core::Size > ignore_res_list;
1075  ignore_res_list.push_back(FB_job_params.moving_res);
1076  ignore_res_list.push_back(FB_job_params.bulge_res);
1077  ignore_res_list.push_back(FB_job_params.reference_res);
1078 
1079  StepWiseRNA_VDW_Bin_ScreenerOP prev_floating_base_VDW_bin_screener= new StepWiseRNA_VDW_Bin_Screener();
1080 
1081  //Feb 21, 2011...one thing is that the 2'-OH hydrogen is not virtualized here...
1082  //But OK, since consistent with the actual input_pose not having virtualized 2'-OH.
1083  prev_floating_base_VDW_bin_screener->create_VDW_screen_bin( input_pose, ignore_res_list, FB_job_params.Is_prepend, reference_stub.v, true /*verbose*/ );
1084 
1085  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1086 
1087 
1088  utility::vector1< pose_data_struct2 > input_pose_data_list; //Singleton list.
1089  input_pose_data_list.push_back(pose_data);
1090 
1091  utility::vector1< FB_Pose_Data > pose_data_list= floating_base_chain_closure_setup(input_pose_data_list, FB_job_params, atr_rep_screening_scorefxn, scorefxn, viewer_pose, true /*do_minimize*/);
1092 
1093  bool const chain_closure_sampling=true;
1094 
1095  if(chain_closure_sampling){
1096  floating_base_chain_closure_sampling(pose_data_list, viewer_pose, FB_job_params, chainbreak_scorefxn, atr_rep_screening_scorefxn, prev_floating_base_VDW_bin_screener , false);
1097  }else{
1098  for(Size n=1; n<=pose_data_list.size(); n++) {pose_data_list[n].Is_chain_close=true; }
1099  }
1100 
1101  bool const rm_CB_JP_during_post_process=true;
1102 
1103  utility::vector1< pose_data_struct2 > final_pose_data_list=floating_base_chain_closure_post_process(pose_data_list, viewer_pose, sampling_scorefxn, FB_job_params, rm_CB_JP_during_post_process);
1104 
1105  SilentFileData silent_file_data;
1106 
1107  for(Size n=1; n<=final_pose_data_list.size(); n++){
1108  pose::Pose & current_pose=(*final_pose_data_list[n].pose_OP);
1109 
1110  if(false) Output_data(silent_file_data, "post_process_" + name + ".out", name + final_pose_data_list[n].tag , false, current_pose, job_parameters->working_native_pose(), job_parameters);
1111  ////////////////////////////////////////////////////////////
1112  if(virtual_ribose_is_from_prior_step){ //Virtualize the other partition since it doesn't exist in prior step!
1113 
1114  for(Size ii=1; ii<=other_partition_pos.size(); ii++){
1115  Size const seq_num=other_partition_pos[ii];
1116  if(Contain_seq_num(seq_num, already_virtualized_res_list)) continue;
1117  pose::remove_variant_type_from_pose_residue( current_pose, "VIRTUAL_RNA_RESIDUE", seq_num);
1118  }
1119  if (job_parameters->gap_size() == 0) pose::remove_variant_type_from_pose_residue( current_pose, "VIRTUAL_PHOSPHATE", job_parameters->five_prime_chain_break_res()+1 );
1120  }else{
1121  if(job_parameters->gap_size() == 0) utility_exit_with_message( "job_parameters->gap_size() == 0" ); //If virt_ribse is from current step, then it should not be the last step!
1122  }
1123  ////////////////////////////////////////////////////////////
1124 
1125  }
1126 
1127  std::cout << "Time in sample_virtual_ribose_and_bulge_and_close_chain(): " << static_cast<Real>( clock() - time_start ) / CLOCKS_PER_SEC << std::endl;
1128 
1129  Output_title_text("Exit sample_virtual_ribose_and_bulge_and_close_chain()");
1130 
1131  viewer_pose=viewer_pose_copy;
1132 
1133  return final_pose_data_list;
1134 
1135  }
1136 
1137  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1138  void
1141  core::pose::Pose const & pose){
1142 
1143  pose::Pose const pose_copy= pose;
1144 
1145  utility::vector1< Size > sugar_ID_counter_list(FB_CC_JP_list.size(), 1);
1146 
1147  while(true){
1148 
1149  pose_data_struct2 start_pose_data;
1150 
1151  start_pose_data.pose_OP=new pose::Pose;
1152  (*start_pose_data.pose_OP)=pose_copy;
1153  pose::Pose & start_pose=(*start_pose_data.pose_OP);
1154 
1155  start_pose_data.score=0;
1156  start_pose_data.tag="";
1157 
1158  for(Size n=1; n<=FB_CC_JP_list.size(); n++){
1159 
1160  FloatingBaseChainClosureJobParameter const & curr_FB_JP = FB_CC_JP_list[n];
1161  Size const sugar_ID=sugar_ID_counter_list[n];
1162 
1163  start_pose_data.tag+= curr_FB_JP.PDL[sugar_ID].tag;
1164  copy_bulge_res_and_ribose_torsion(curr_FB_JP, start_pose, (*curr_FB_JP.PDL[sugar_ID].pose_OP) );
1165 
1166  }
1167 
1168  starting_pose_data_list.push_back(start_pose_data);
1169 
1170  ///////////////////////////Counter/////////////////////////////
1171  sugar_ID_counter_list[1]++;
1172 
1173  for(Size n=1; n<FB_CC_JP_list.size(); n++){
1174  if( sugar_ID_counter_list[n]==(FB_CC_JP_list[n].PDL.size()+1) ){
1175  sugar_ID_counter_list[n]=1;
1176  sugar_ID_counter_list[n+1]++;
1177  }
1178  }
1179 
1180  if( sugar_ID_counter_list[FB_CC_JP_list.size()]==(FB_CC_JP_list[FB_CC_JP_list.size()].PDL.size()+1) ) break;
1181  ////////////////////////////////////////////////////////////////
1182 
1183  }
1184 
1185  }
1186 
1187  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1188 
1190  setup_FB_CC_JP_list(pose::Pose const & pose, utility::vector1< std::string > const & sample_virtual_ribose_string_list, StepWiseRNA_JobParametersCOP & job_parameters){
1191 
1192  using namespace ObjexxFCL;
1193 
1195 
1196  std::string const & working_sequence= job_parameters->working_sequence();
1197 
1198  for(Size n=1; n<=sample_virtual_ribose_string_list.size(); n++){
1199 
1200  utility::vector1< std::string > const tokenize_list=Tokenize(sample_virtual_ribose_string_list[n], "-");
1201  if(tokenize_list.size()!=2) utility_exit_with_message("tokenize_list!=2");
1202 
1203  if(tokenize_list[2]!="A" && tokenize_list[2]!="P"){
1204  utility_exit_with_message("tokenize_list[2]!=\"A\" && tokenize_list[2]!=\"P\" (" + tokenize_list[2] + ")" );
1205  }
1206 
1207  bool const Is_prepend= (tokenize_list[2]=="P") ? true : false;
1208 
1209  Size const full_ribose_res=string_to_int( tokenize_list[1] );
1210  Size const full_bulge_res=(Is_prepend) ? full_ribose_res+1 : full_ribose_res-1;
1211  Size const full_ref_res= (Is_prepend) ? full_ribose_res+2 : full_ribose_res-2;
1212 
1213  std::cout << "Case: " << sample_virtual_ribose_string_list[n];
1214  std::cout << " full_ribose_res= " << full_ribose_res << " full_bulge_res= " << full_bulge_res << " full_ref_res= " << full_ref_res;
1215  Output_boolean(" Is_prepend= " , Is_prepend);
1216 
1217  if( pose.total_residue()!=working_sequence.size() ){
1218  utility_exit_with_message( "pose.total_residue()=("+string_of(pose.total_residue())+")!="+string_of(working_sequence.size())+") working_sequence().size()");
1219  }
1220 
1221  if(check_is_working_res(full_ribose_res, job_parameters)){
1222 
1223  Size const working_ribose_res=check_validity_and_get_working_res(full_ribose_res, job_parameters);
1224 
1225  bool const ribose_is_virtual=pose.residue(working_ribose_res).has_variant_type("VIRTUAL_RIBOSE");
1226 
1227  std::cout << " | working_ribose_res= " << working_ribose_res;
1228  Output_boolean(" ribose_is_virtual= " , ribose_is_virtual);
1229 
1230  if(ribose_is_virtual){
1231 
1232  Size const working_bulge_res=check_validity_and_get_working_res(full_bulge_res, job_parameters);
1233  Size const working_ref_res=check_validity_and_get_working_res(full_ref_res, job_parameters);
1234 
1235  std::cout << " | working_bulge_res= " << working_bulge_res << " working_ref_res= " << working_ref_res;
1236 
1237  if(Is_prepend){
1238  if(working_ribose_res!=(working_bulge_res-1)) utility_exit_with_message("prepend but working_ribose_res!=(working_bulge_res-1)");
1239  if(working_ribose_res!=(working_ref_res - 2)) utility_exit_with_message("prepend but working_ribose_res!=(working_ref_res - 2)");
1240  }else{
1241  if(working_ribose_res!=(working_bulge_res+1)) utility_exit_with_message("append but working_ribose_res!=(working_bulge_res+1)");
1242  if(working_ribose_res!=(working_ref_res + 2)) utility_exit_with_message("prepend but working_ribose_res!=(working_ref_res + 2)");
1243  }
1244 
1245  //ribose_is_virtual=Is_ribose_virtual(pose, working_ribose_res, working_bulge_res);
1246 
1247  if(pose.residue(working_bulge_res).has_variant_type("VIRTUAL_RNA_RESIDUE")==false){
1248  utility_exit_with_message("pose.residue(working_bulge_res).has_variant_type(\"VIRTUAL_RNA_RESIDUE\")==false" );
1249  }
1250 
1252 
1253  curr_FB_JP=FloatingBaseChainClosureJobParameter(working_ribose_res, working_ref_res);
1254 
1255  FB_CC_JP_list.push_back(curr_FB_JP);
1256 
1257  }
1258 
1259 
1260  }else{
1261 
1262  std::cout << " | full_ribose_res is not a working res! ";
1263 
1264  }
1265 
1266  std::cout << std::endl;
1267  }
1268 
1269  return FB_CC_JP_list;
1270 
1271  }
1272 
1273  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1274 
1275  void
1276  sample_user_specified_virtual_riboses(pose::Pose & pose, utility::vector1< std::string > const & sample_virtual_ribose_string_list,
1277  StepWiseRNA_JobParametersCOP & job_parameters , core::scoring::ScoreFunctionOP const & scorefxn,
1278  std::string const silent_file_out, std::string const input_tag){
1279 
1280 
1281  using namespace ObjexxFCL;
1282  using namespace core::io::silent;
1283  using namespace core::id;
1284  using namespace core::scoring;
1285  using namespace core::conformation;
1286 
1287  Output_title_text("Enter StepWiseRNA_VirtualRiboseSampler::sample_virtual_ribose");
1288 
1289  // clock_t const time_start( clock() ); // Unused variable causes warning.
1290 
1291 
1292  /////////////////////Copy the conformation but nothing else. No energy and no cache data (having cache data can cause problem with column_name order in output silent_file!)//////////////////////////////
1293 
1294  ConformationOP copy_conformation = new Conformation();
1295 
1296  (*copy_conformation)=pose.conformation();
1297 
1298  pose::Pose new_pose;
1299  new_pose.set_new_conformation( copy_conformation );
1300 
1301  pose=new_pose;
1302 
1303  ///////////////////////////////////////////////////////////////
1304 
1305  pose::Pose const pose_save = pose;
1306  pose = pose_save; //this recopy is useful for triggering graphics.
1307 
1308  ///////////////////////////////////////////////////////////////
1309 
1310 
1311 
1312  core::scoring::ScoreFunctionOP atr_rep_screening_scorefxn, chainbreak_scorefxn, sampling_scorefxn, o2star_pack_scorefxn;
1313 
1314  initialize_common_scorefxns(scorefxn, sampling_scorefxn, atr_rep_screening_scorefxn, chainbreak_scorefxn, o2star_pack_scorefxn);
1315 
1316  utility::vector1< FloatingBaseChainClosureJobParameter > FB_CC_JP_list=setup_FB_CC_JP_list(pose, sample_virtual_ribose_string_list, job_parameters);
1317 
1318  std::cout << "num_virtual_ribose= " << FB_CC_JP_list.size() << std::endl;
1319 
1320  if(FB_CC_JP_list.size()==0){
1321  std::cout << "no_virtual_ribose (FB_CC_JP_list.size()==0). EARLY RETURN/NO OUTPUT SILENT_FILE!" << std::endl;
1322 
1323  std::ofstream outfile;
1324  outfile.open(silent_file_out.c_str()); //Opening the file with this command removes all prior content..
1325  outfile << "no_virtual_ribose (FB_CC_JP_list.size()==0).\n";
1326  outfile.flush();
1327  outfile.close();
1328 
1329  return;
1330  }
1331 
1332 
1333  for(Size n=1; n<=FB_CC_JP_list.size(); n++){
1334 
1335  FloatingBaseChainClosureJobParameter & curr_FB_JP = FB_CC_JP_list[n];
1336 
1337  curr_FB_JP.set_base_and_pucker_state(pose, job_parameters);
1338 
1339  curr_FB_JP.PDL=sample_virtual_ribose_and_bulge_and_close_chain(pose, curr_FB_JP, "VIRT_RIBOSE_NUM_" + string_of(n), //ACTUAL COMPUTATION OCCUR HERE!!
1340  scorefxn, sampling_scorefxn, atr_rep_screening_scorefxn, chainbreak_scorefxn, job_parameters,
1341  false /*virtual_ribose_is_from_prior_step*/);
1342 
1343  std::sort(curr_FB_JP.PDL.begin(), curr_FB_JP.PDL.end(), sort_pose_data_by_score);
1344 
1345 
1346  if(curr_FB_JP.PDL.size()==0){
1347  std::cout << "Case n= " << n << " Is_sugar_virt==True but curr_FB_JP.PDL.size()==0. EARLY RETURN!" << std::endl;
1348 
1349  std::ofstream outfile;
1350  outfile.open(silent_file_out.c_str()); //Opening the file with this command removes all prior content..
1351  outfile << "num_virtual_ribose != 0 but for one of the sampled virtual_ribose, curr_FB_JP.PDL.size()==0.\n";
1352  outfile.flush();
1353  outfile.close();
1354  return;
1355  }
1356  }
1357 
1358  ///////////////////////////////////////////////////////////////////////////////////
1359  utility::vector1< pose_data_struct2 > starting_pose_data_list;
1360 
1361  enumerate_starting_pose_data_list(starting_pose_data_list, FB_CC_JP_list, pose);
1362 
1363  minimize_all_sampled_floating_bases(pose, FB_CC_JP_list, starting_pose_data_list, sampling_scorefxn, job_parameters, false /*virtualize_other_partition*/);
1364 
1365  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1366 
1367  SilentFileData silent_file_data;
1368  for(Size n=1; n<=starting_pose_data_list.size(); n++){
1369  pose=(*starting_pose_data_list[n].pose_OP); //set viewer_pose;
1370 
1371  std::string starting_pose_tag=input_tag + "_sample_ribose" + starting_pose_data_list[n].tag;
1372 
1373  if (job_parameters->gap_size() == 0) utility_exit_with_message( "job_parameters_->gap_size() == 0" );
1374 
1375  (*scorefxn)(pose);
1376 
1377  //std::cout << "starting_pose_tag= " << starting_pose_tag= << std::endl;
1378  //pose.energies().show();
1379 
1380 
1381  Output_data(silent_file_data, silent_file_out , starting_pose_tag , false, pose, job_parameters->working_native_pose(), job_parameters);
1382 
1383  }
1384 
1385  }
1386 
1387 
1388  /////////////////////////////////////////////////////////////////////////////////////
1389 
1390 
1391 } //rna
1392 } //swa
1393 } // protocols
1394