Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StepWiseRNA_AnalyticalLoopCloseSampler.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_AnalyticalLoopCloseSampler
11 /// @brief Alternative SWA sampling using Analytical Loop Closure
12 /// @detailed
13 /// @author Fang-Chieh Chou
14 
15 //////////////////////////////////
28 
33 //////////////////////////////////
34 #include <core/types.hh>
40 #include <core/pose/Pose.hh>
41 #include <core/pose/util.hh>
50 
52 #include <core/scoring/Energies.hh>
55 
56 #include <core/id/TorsionID.hh>
57 #include <core/id/AtomID.hh>
58 #include <core/id/DOF_ID.hh>
61 #include <core/chemical/util.hh>
63 #include <core/chemical/AtomType.hh>
68 #include <core/io/pdb/pose_io.hh>
69 
70 #include <ObjexxFCL/format.hh>
71 #include <ObjexxFCL/string.functions.hh>
72 
73 #include <utility/exit.hh>
74 #include <time.h>
75 
76 #include <string>
77 #include <fstream>
78 #include <iostream>
79 #include <sstream>
80 #include <math.h>
81 #include <stdlib.h>
82 
83 
84 using namespace core;
85 using core::Real;
86 using io::pdb::dump_pdb;
87 
88 //////////////////////////////////////////////////////////////////////////
89 //////////////////////////////////////////////////////////////////////////
90 // Core routine for stepwise sampling of RNA
91 //////////////////////////////////////////////////////////////////////////
92 //////////////////////////////////////////////////////////////////////////
93 //////////////////////////////////////////////////////////////////////////
94 
95 
96 namespace protocols {
97 namespace swa {
98 namespace rna {
99 
100 //////////////////////////////////////////////////////////////////////////
101 //constructor!
102 StepWiseRNA_AnalyticalLoopCloseSampler::StepWiseRNA_AnalyticalLoopCloseSampler ( StepWiseRNA_JobParametersCOP & job_parameters ) :
103  job_parameters_ ( job_parameters ),
104  sfd_ ( new core::io::silent::SilentFileData ),
105  scorefxn_ ( core::scoring::ScoreFunctionFactory::create_score_function ( "rna_hires.wts" ) ), // can be replaced from the outside
106  silent_file_ ( "silent_file.txt" ),
107  output_filename_ ( "data.txt" ),
108  bin_size_ ( 20 ),
109  rep_cutoff_ ( 4.0 ),
110  num_pose_kept_ ( 108 ),
111  multiplier_ ( 2 ), //Sort and cluster poses when the number of pose is pose_data_list exceed multiplier*num_pose_kept,
112  cluster_rmsd_ ( 0.5001 ),
113  verbose_ ( false ),
114  native_rmsd_screen_ ( false ),
115  native_screen_rmsd_cutoff_ ( 2.0 ),
116  o2star_screen_ ( true ),
117  fast_ ( false ),
118  medium_fast_ ( false ),
119  centroid_screen_ ( true ),
120  VDW_atr_rep_screen_ ( true ),
121  distinguish_pucker_ ( true ),
122  current_score_cutoff_ ( 99999 ), //New option May 12, 2010
123  finer_sampling_at_chain_closure_ ( false ), //New option Jun 10 2010
124  PBP_clustering_at_chain_closure_ ( false ), //New option Aug 15 2010
125  extra_anti_chi_rotamer_(false), //Split to syn and anti on June 16, 2011
126  extra_syn_chi_rotamer_(false), //Split to syn and anti on June 16, 2011
127  use_phenix_geo_(false) //The standard geo from PHENIX
128 
129 {
130  set_native_pose ( job_parameters_->working_native_pose() );
131  ////////////////Parin Feb 28, 2010////////////////////////////////////////////////
132  utility::vector1 < core::Size > const & rmsd_res_list = job_parameters_->rmsd_res_list();
133  working_rmsd_res_ = apply_full_to_sub_mapping ( rmsd_res_list, job_parameters );
134  std::map< core::Size, bool > const & Is_prepend_map = job_parameters_->Is_prepend_map();
135  Output_is_prepend_map ( "Is_prepend_map= ", Is_prepend_map , job_parameters_->full_sequence().size(), 30 );
136  Output_seq_num_list ( "rmsd_res= ", rmsd_res_list, 30 );
137  Output_seq_num_list ( "working_rmsd_res= ", working_rmsd_res_, 30 );
138  ////////////////////////////////////////////////////////////////////////////////
139 }
140 
141 //////////////////////////////////////////////////////////////////////////
142 //destructor
144 {}
145 
146 //////////////////////////////////////////////////////////////////////////
147 bool
148 sort_criteria2 ( pose_data_struct2 pose_data_1, pose_data_struct2 pose_data_2 ) { //This function used to be call sort_criteria2
149  return ( pose_data_1.score < pose_data_2.score );
150 }
151 ////////////////////////////////////////////////////////////////////////////
152 
153 
154 void
156  using namespace ObjexxFCL;
157  Output_title_text ( "Enter StepWiseRNA_AnalyticalLoopCloseSampler::apply" );
158  clock_t const time_start ( clock() );
159  //output screen options
160  std::cout << "--------SCREEN OPTIONS---------- " << std::endl;
161  Output_boolean ( "native_rmsd_screen = ", native_rmsd_screen_ );
162  std::cout << std::endl;
163  std::cout << "native_screen_rmsd_cutoff = " << native_screen_rmsd_cutoff_ << std::endl;
164  Output_boolean ( "o2star_screen = ", o2star_screen_ );
165  std::cout << std::endl;
166  Output_seq_num_list ( "working_moving_partition_pos= ", job_parameters_->working_moving_partition_pos(), 40 );
167  Output_boolean ( "centroid_screen = ", centroid_screen_ );
168  std::cout << std::endl;
169  Output_boolean ( "VDW_atr_rep_screen = ", VDW_atr_rep_screen_ );
170  std::cout << std::endl;
171  std::cout << "--------------------------------" << std::endl;
172  Pose const pose_save = pose;
173  pose = pose_save; //this recopy is useful for triggering graphics.
174  initialize_scorefunctions(); //////////////// Sets up scorefunctions for a bunch of different screens /////////
176  standard_sampling ( pose, pose_data_list );
177  std::cout << "Total time in StepWiseRNA_AnalyticalLoopCloseSampler::apply " << static_cast<Real> ( clock() - time_start ) / CLOCKS_PER_SEC << std::endl;
178  Output_title_text ( "Exit StepWiseRNA_AnalyticalLoopCloseSampler::apply" );
179 }
180 
181 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
182 
183 void
185  using namespace core::scoring;
186  using namespace core::pose;
187  using namespace core::io::silent;
188  using namespace protocols::rna;
189  using namespace core::id;
190  Output_title_text ( "Enter StepWiseRNA_AnalyticalLoopCloseSampler::standard_sampling" );
191  clock_t const time_start ( clock() );
193  Size const moving_res ( job_parameters_->working_moving_res() ); // Might not corresponds to user input.
194  Size const moving_suite ( job_parameters_->working_moving_suite() ); // dofs betweeen this value and value+1 actually move.
195  bool const Is_prepend ( job_parameters_->Is_prepend() );
196  bool const Is_internal ( job_parameters_->Is_internal() ); // no cutpoints before or after moving_res.
197  Size const actually_moving_res ( job_parameters_->actually_moving_res() ); //Now same as moving_res
198  Size const gap_size ( job_parameters_->gap_size() ); /* If this is zero or one, need to screen or closable chain break */
199  utility::vector1 < core::Size > const & cutpoint_closed_list = job_parameters_->cutpoint_closed_list();
200  Size const num_nucleotides ( job_parameters_->working_moving_res_list().size() );
201  Size const five_prime_chain_break_res = job_parameters_->five_prime_chain_break_res();
202  Size const cutpoint_closed = cutpoint_closed_list[1];
203  std::cout << " NUM_NUCLEOTIDES= " << num_nucleotides << std::endl;
204  std::cout << " GAP SIZE " << gap_size << std::endl;
205  std::cout << " MOVING RES " << moving_res << std::endl;
206  std::cout << " MOVING SUITE " << moving_suite << std::endl;
207  Output_boolean ( " PREPEND ", Is_prepend );
208  std::cout << std::endl;
209  Output_boolean ( " INTERNAL ", Is_internal );
210  std::cout << std::endl;
211  Output_boolean ( " distinguish_pucker_ ", distinguish_pucker_ );
212  std::cout << std::endl;
213  /////////////////////////////// O2star sampling/virtualization //////////////////////////
214  Pose pose_with_virtual_O2star_hydrogen = pose;
215  Add_virtual_O2Star_hydrogen ( pose_with_virtual_O2star_hydrogen );
216 // Mod out on Apr 3, 2010 Important so that pose can remember the o2star torsion from previous minimization step. Check if this cause problems!!
217 // This is true only in the INTERNAL CASE!...May 31, 2010
218  // if o2star_screen, pose 2'-OH will be sampled!
219  pose::Pose pose_with_original_HO2star_torsion;
220 
221  if ( o2star_screen_ ) {
222  pose_with_original_HO2star_torsion = pose;
224  } else {
225  // Otherwise, virtualize the 2-OH.
226  pose = pose_with_virtual_O2star_hydrogen;
227  }
228 
229  Real base_rep_score ( -99999 ), base_atr_score ( -99999 );
230  get_base_atr_rep_score ( pose_with_virtual_O2star_hydrogen, base_atr_score, base_rep_score );
231  //////////////////////////////////////////Setup Atr_rep_screening/////////////////////////////////////////////////
232  pose::Pose screening_pose = pose_with_virtual_O2star_hydrogen; //Hard copy
233  //Necessary for the case where gap_size == 0. In this case, Pose_setup does not automatically create a VIRTUAL_PHOSPHATE.///
234  //However since screening_pose is scored before the CCD corrrectly position the chain_break phosphate atoms, ///////////////
235  // the VIRTUAL_PHOSPHATE is needed to prevent artificial crashes. Parin Jan 28, 2010////////////////////////////////////
236  if ( gap_size == 0 ) pose::add_variant_type_to_pose_residue ( screening_pose, "VIRTUAL_PHOSPHATE", five_prime_chain_break_res + 1 );
237 
238  //Start the Rotamer Sampling
239  Real /*current_score ( 0.0 ),*/ delta_rep_score ( 0.0 ), delta_atr_score ( 0.0 );
240  core::Real delta_pucker;
241  core::Real nu2_pucker;
242  core::Real nu1_pucker;
243  core::scoring::rna::RNA_FittedTorsionInfo rna_fitted_torsion_info;
244 
245 
246  RNA_LoopCloseSampler rna_loop_close_sampler ( moving_suite, cutpoint_closed );
247 
249  rna_loop_close_sampler.set_bin_size ( 10 );
250  } else {
251  rna_loop_close_sampler.set_bin_size ( 20 );
252  rna_loop_close_sampler.set_epsilon_range ( 40 );
253  }
254 
255  rna_loop_close_sampler.set_sample_only ( true );
256  rna_loop_close_sampler.set_sample_native_torsion ( true );
257  rna_loop_close_sampler.set_scorefxn ( scorefxn_ );
258 
259  Size pucker_id;
260  Size total_count = 0;
261  std::cout << "Start Generating Rotamer ..." << std::endl;
262  protocols::rna::RNA_IdealCoord const ideal_coord;
263 
264  for ( pucker_id = 0; pucker_id < 2; pucker_id ++ ) {
265  std::cout << "pucker_id = " << pucker_id << std::endl;
266 
267  if (use_phenix_geo_) {
268  if ( pucker_id == 0 ) { //Sample North Pucker
269  ideal_coord.apply( screening_pose, moving_res, true);
270  } else { //Sample South Pucker
271  ideal_coord.apply( screening_pose, moving_res, false);
272  }
273  } else {
274  if ( pucker_id == 0 ) { //Sample North Pucker
275  delta_pucker = rna_fitted_torsion_info.ideal_delta_north();
276  nu2_pucker = rna_fitted_torsion_info.ideal_nu2_north();
277  nu1_pucker = rna_fitted_torsion_info.ideal_nu1_north();
278  } else { //Sample South Pucker
279  delta_pucker = rna_fitted_torsion_info.ideal_delta_south();
280  nu2_pucker = rna_fitted_torsion_info.ideal_nu2_south();
281  nu1_pucker = rna_fitted_torsion_info.ideal_nu1_south();
282  }
283 
284  screening_pose.set_torsion ( TorsionID ( moving_res , id::BB, 4 ) , delta_pucker );
285  screening_pose.set_torsion ( TorsionID ( moving_res , id::CHI, 2 ) , nu2_pucker );
286  screening_pose.set_torsion ( TorsionID ( moving_res , id::CHI, 3 ) , nu1_pucker );
287  }
288 
289  //Loop Closure
290  std::cout << "Entering Analytical Loop Closing" << std::endl;
291  rna_loop_close_sampler.clear_all();
292  rna_loop_close_sampler.apply ( screening_pose );
293  std::cout << "Exiting Analytical Loop Closing" << std::endl;
294 
295  for ( Size ii = 1; ii <= rna_loop_close_sampler.n_construct(); ++ii ) {
296  rna_loop_close_sampler.fill_pose ( screening_pose, ii );
297  //Sample CHI torsion angle
298  BaseState base_state;
299  if ( allow_syn_pyrimidine_ ) {
300  base_state = BOTH;
301  } else {
302  base_state = ( core::scoring::rna::is_purine ( pose.residue ( moving_res ) ) ) ? BOTH : ANTI;
303  }
304 
305  PuckerState pucker_state;
306 
307  if ( pucker_id == 0 ) {
308  pucker_state = NORTH;
309  } else {
310  pucker_state = SOUTH;
311  }
312 
313  StepWiseRNA_Base_Sugar_RotamerOP base_sugar_rotamer = new StepWiseRNA_Base_Sugar_Rotamer ( base_state, pucker_state, rna_fitted_torsion_info );
314  base_sugar_rotamer->set_extra_syn_chi ( extra_syn_chi_rotamer_ );
315  base_sugar_rotamer->set_extra_anti_chi ( extra_anti_chi_rotamer_ );
316  while ( base_sugar_rotamer->get_next_rotamer() ) {
317  Real chi = base_sugar_rotamer->chi();
318  screening_pose.set_torsion ( TorsionID ( moving_res , id::CHI, 1 ) ,chi );
319 
320  //Native RMSD Screening
322  if ( suite_rmsd ( *get_native_pose(), screening_pose, actually_moving_res, Is_prepend ) > ( native_screen_rmsd_cutoff_ ) ) continue;
323 
324  if ( rmsd_over_residue_list ( *get_native_pose(), screening_pose, job_parameters_, false ) > ( native_screen_rmsd_cutoff_ ) ) continue; //Oct 14, 2010
325 
327 
328  if ( verbose_ ) std::cout << "rmsd_count = " << count_data_.rmsd_count << " total count= " << count_data_.tot_rotamer_count << std::endl;
329  }
330 
331  //Centroid Screening
332  if ( centroid_screen_ ) {
333  bool found_a_centroid_interaction_partner ( false );
334  found_a_centroid_interaction_partner = base_centroid_screener_->Update_base_stub_list_and_Check_centroid_interaction ( screening_pose, count_data_ );
335 
336  if ( gap_size > 0 && !found_a_centroid_interaction_partner ) continue;
337 
338  if ( !base_centroid_screener_->Check_that_terminal_res_are_unstacked() ) continue;
339  }
340 
341  //VDW Screening//
342  if ( !Full_atom_van_der_Waals_screening ( screening_pose, base_rep_score, base_atr_score, delta_rep_score, delta_atr_score, gap_size, Is_internal ) ) continue;
343 
344  if ( ( user_input_VDW_bin_screener_->user_inputted_VDW_screen_pose() ) && ( gap_size != 0 ) && ( Is_internal == false ) ) {
345  //not well calibrated for chain_closure move and Is_internal move yet...
346  //Also Right now the code doesn't correctly account for the phosphate of the prepend case...
347  //Ok in that it ignore the virtual phosphate but doesn't take the 3' prime phosphate into accoutn June 13, 2010..
348  if ( user_input_VDW_bin_screener_->VDW_rep_screen ( screening_pose, moving_res ) == false ) continue;
349 
351  }
352 
353 
354  //Copy the Torsion angles of screen_pose to pose
355  copy_suite_torsion ( pose, screening_pose, moving_res );
356  if (use_phenix_geo_) {
357  if ( pucker_id == 0 ) { //Sample North Pucker
358  ideal_coord.apply( pose, moving_res, true);
359  } else { //Sample South Pucker
360  ideal_coord.apply( pose, moving_res, false);
361  }
362  }
363 
364  ////////////////Add pose to pose_data_list/////
365  if ( o2star_screen_ ) sample_o2star_hydrogen ( pose , pose_with_original_HO2star_torsion );
366 
367  std::stringstream ss;
368  ss << "U" << total_count;
369  std::string tag = ss.str();
370  total_count++;
371  /*current_score =*/ Pose_selection_by_full_score ( pose_data_list, pose, tag );
372 
373  if ( verbose_ ) {
374  std::cout << tag << std::endl;
376  }
377  }
378  }
379  }
380 
381  Output_title_text ( "Final sort and clustering" );
382  std::cout << "before erasing.. pose_data_list= " << pose_data_list.size() << std::endl;
383  std::sort ( pose_data_list.begin(), pose_data_list.end(), sort_criteria2 );
384  cluster_pose_data_list ( pose_data_list );
385 
386  if ( pose_data_list.size() > num_pose_kept_ ) {
387  pose_data_list.erase ( pose_data_list.begin() + num_pose_kept_, pose_data_list.end() );
388  }
389 
390  std::cout << "after erasing.. pose_data_list= " << pose_data_list.size() << std::endl;
391  pose_data_list_ = pose_data_list;
392  //Hacky..temporary until we fix the reroot atom problem..This is just for calculating rmsd purposes... Apr 27 , 2010 Parin
393  //////////////////////////////////////////////////////////////////////////////////////////
394  std::cout << "FINAL COUNTS" << std::endl;
395 
396  if ( gap_size <= 1 ) std::cout << " chain_closable_count= " << count_data_.chain_closable_count << std::endl;
397 
398  if ( gap_size == 0 ) {
399  std::cout << " angle_n= " << count_data_.good_angle_count << " dist_n= " << count_data_.good_distance_count;
400  std::cout << " chain_break_screening= " << count_data_.chain_break_screening_count << std::endl;
401  }
402 
403  std::cout << "stack= " << count_data_.base_stack_count << " pair= " << count_data_.base_pairing_count;
404  std::cout << " strict_pair_n= " << count_data_.strict_base_pairing_count;
405  std::cout << " atr= " << count_data_.good_atr_rotamer_count;
406  std::cout << " rep= " << count_data_.good_rep_rotamer_count;
407  std::cout << " both= " << count_data_.both_count;
408  std::cout << " bulge= " << count_data_.bulge_at_chain_closure_count;
409  std::cout << " rmsd= " << count_data_.rmsd_count << " tot= " << count_data_.tot_rotamer_count << std::endl;
410  std::cout << "Total time in StepWiseRNA_AnalyticalLoopCloseSampler: " << static_cast<Real> ( clock() - time_start ) / CLOCKS_PER_SEC << std::endl;
411 }
412 
413 
414 
415 //////////////////////////////////////////////////////////////////////////////
416 void
418  using namespace core::scoring;
419  using namespace core::pose;
420  using namespace core::io::silent;
421  using namespace protocols::rna;
422  using namespace core::id;
423  pose.set_torsion ( TorsionID ( suite_num - 1, id::BB, 5 ), ref_pose.torsion ( TorsionID ( suite_num - 1, id::BB, 5 ) ) ); //epsilon-1
424  pose.set_torsion ( TorsionID ( suite_num - 1, id::BB, 6 ), ref_pose.torsion ( TorsionID ( suite_num - 1, id::BB, 6 ) ) ); //zeta-1
425  pose.set_torsion ( TorsionID ( suite_num, id::BB, 1 ), ref_pose.torsion ( TorsionID ( suite_num, id::BB, 1 ) ) ); //alpha
426  pose.set_torsion ( TorsionID ( suite_num, id::BB, 2 ), ref_pose.torsion ( TorsionID ( suite_num, id::BB, 2 ) ) ); //beta
427  pose.set_torsion ( TorsionID ( suite_num, id::BB, 3 ), ref_pose.torsion ( TorsionID ( suite_num, id::BB, 3 ) ) ); //gamma
428  pose.set_torsion ( TorsionID ( suite_num, id::BB, 4 ), ref_pose.torsion ( TorsionID ( suite_num, id::BB, 4 ) ) ); //delta
429  pose.set_torsion ( TorsionID ( suite_num, id::BB, 5 ), ref_pose.torsion ( TorsionID ( suite_num, id::BB, 5 ) ) ); //epsilon
430  pose.set_torsion ( TorsionID ( suite_num + 1, id::BB, 1 ), ref_pose.torsion ( TorsionID ( suite_num + 1, id::BB, 1 ) ) ); //alpha+1
431  pose.set_torsion ( TorsionID ( suite_num + 1, id::BB, 2 ), ref_pose.torsion ( TorsionID ( suite_num + 1, id::BB, 2 ) ) ); //beta+1
432  pose.set_torsion ( TorsionID ( suite_num + 1, id::BB, 3 ), ref_pose.torsion ( TorsionID ( suite_num + 1, id::BB, 3 ) ) ); //gamma+1
433  pose.set_torsion ( TorsionID ( suite_num, id::CHI, 1 ), ref_pose.torsion ( TorsionID ( suite_num, id::CHI, 1 ) ) ); //chi
434  pose.set_torsion ( TorsionID ( suite_num, id::CHI, 2 ), ref_pose.torsion ( TorsionID ( suite_num, id::CHI, 2 ) ) ); //nu2
435  pose.set_torsion ( TorsionID ( suite_num, id::CHI, 3 ), ref_pose.torsion ( TorsionID ( suite_num, id::CHI, 3 ) ) ); //nu1
436  return;
437 }
438 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
439 void
441  using namespace core::conformation;
442  using namespace core::scoring;
443  using namespace core::pose;
444  using namespace ObjexxFCL;
445  Size const working_moving_suite ( job_parameters_->working_moving_suite() );
446  Size const working_moving_res ( job_parameters_->working_moving_res() );
447  Size const nres = job_parameters_->working_sequence().size();
448  ///////////////////////////////Old_way////////////////////////////////////////////
449  pose::Pose base_pose_screen = pose; //hard copy
450 // std::cout << "BLAH_BLAH_BLAH May 5, 2010" << std::endl;
451  if ( verbose_ ) base_pose_screen.dump_pdb ( "base_atr_rep_before.pdb" );
452 
453 // if(working_moving_suite>=nres) utility_exit_with_message( "working_moving_suite " + string_of(working_moving_suite) + " >= nres " + string_of(nres) );
454  pose::add_variant_type_to_pose_residue ( base_pose_screen, "VIRTUAL_PHOSPHATE", working_moving_res ); //May 7...
455 
456  if ( ( working_moving_res + 1 ) <= nres ) {
457  pose::add_variant_type_to_pose_residue ( base_pose_screen, "VIRTUAL_PHOSPHATE", working_moving_res + 1 ); //May 7...
458  }
459 
460  // I think this should work... push apart different parts of the structure so that whatever fa_atr, fa_rep is left is due to "intra-domain" interactions.
461  // Crap this doesn't work when building 2 or more nucleotides.
462  Size const jump_at_moving_suite = make_cut_at_moving_suite ( base_pose_screen, working_moving_suite );
463  kinematics::Jump j = base_pose_screen.jump ( jump_at_moving_suite );
464  j.set_translation ( Vector ( 1.0e4, 0.0, 0.0 ) );
465  base_pose_screen.set_jump ( jump_at_moving_suite, j );
466  ( *atr_rep_screening_scorefxn_ ) ( base_pose_screen );
467  EnergyMap const & energy_map = base_pose_screen.energies().total_energies();
468  base_atr_score = atr_rep_screening_scorefxn_->get_weight ( fa_atr ) * energy_map[ scoring::fa_atr ]; //
469  base_rep_score = atr_rep_screening_scorefxn_->get_weight ( fa_rep ) * energy_map[ scoring::fa_rep ];
470  std::cout << "base_rep= " << base_rep_score << " base_atr= " << base_atr_score << std::endl;
471 
472  if ( verbose_ ) base_pose_screen.dump_pdb ( "base_atr_rep_after.pdb" );
473 
474  ////////////////////////////////////////////////////////////////////////////////////
475  /*
476 
477  Size const nres = job_parameters_->working_sequence().size();
478  utility::vector1< Size > const working_moving_res_list=job_parameters_->working_moving_res_list();
479 
480 
481  utility::vector1< Size > partition_0_seq_num_list;
482  utility::vector1< Size > partition_1_seq_num_list;
483 
484 
485  bool const root_partition = partition_definition( rerooted_fold_tree.root() );
486 
487  for (Size seq_num=1; seq_num<=nres; seq_num++){
488  // if(Contain_seq_num(seq_num, working_moving_res_list)) continue; //Exclude working_moving_residues (the one being sampled..)
489 
490  if ( partition_definition( seq_num ) == 0){
491  partition_0_seq_num_list.push_back( seq_num );
492  }else if( partition_definition( seq_num ) == 1){
493  partition_1_seq_num_list.push_back( seq_num );
494  }else{
495  utility_exit_with_message("seq_num " + string_of(seq_num) + " is not both in either partition!!" );
496  }
497  }
498 
499  sort_seq_num_list(partition_0_seq_num_list); //Low seq_num on the top of the list [1,2,3,4,5]
500  sort_seq_num_list(partition_1_seq_num_list); //Low seq_num on the top of the list [1,2,3,4,5]
501 
502  */
503 }
504 
505 
506 ////////////////////////////////////////////////////////////////////////////////////////
507 void
510 }
511 
512 ////////////////////////////////////////////////////////////////////////////////////////
515  return pose_data_list_;
516 }
517 
518 
519 
520 ////////////////////////////////////////////////////////////////////////////////////////
521 void
522 StepWiseRNA_AnalyticalLoopCloseSampler::Update_pose_data_list ( std::string const & tag, utility::vector1< pose_data_struct2 > & pose_data_list, pose::Pose const & current_pose, Real const & current_score ) const {
523  bool add_pose_to_list = false;
524 
525  add_pose_to_list = ( current_score < current_score_cutoff_ ) ? true : false;
526 
527  //The order of evaluation of the two expression in the if statement is important!
528  if ( add_pose_to_list ) {
529  if ( verbose_ ) {
530  std::cout << "tag= " << tag << " current_score_cutoff_ " << current_score_cutoff_ << " score= " << current_score;
531  }
532 
533  pose_data_struct2 current_pose_data;
534  current_pose_data.pose_OP = new pose::Pose;
535  ( *current_pose_data.pose_OP ) = current_pose;
536  current_pose_data.score = current_score;
537  current_pose_data.tag = tag;
538 
539  if ( get_native_pose() ) {
540  setPoseExtraScores ( *current_pose_data.pose_OP, "all_rms",
542  }
543 
544  pose_data_list.push_back ( current_pose_data );
545 
546  if ( verbose_ ) std::cout << " pose_data_list.size= " << pose_data_list.size() << std::endl;
547  }
548 }
549 
550 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
551 Real
553  using namespace core::scoring;
554  Real const current_score = ( *sampling_scorefxn_ ) ( current_pose );
555  Update_pose_data_list ( tag, pose_data_list, current_pose, current_score );
556 
557  if ( ( pose_data_list.size() == num_pose_kept_ * multiplier_ ) ) {
558  std::sort ( pose_data_list.begin(), pose_data_list.end(), sort_criteria2 );
559  cluster_pose_data_list ( pose_data_list );
560 
561  if ( pose_data_list.size() > num_pose_kept_ ) {
562  pose_data_list.erase ( pose_data_list.begin() + num_pose_kept_, pose_data_list.end() );
563  std::cout << "after erasing.. pose_data_list.size()= " << pose_data_list.size() << std::endl;
564  } else {
565  std::cout << "pose_data_list.size()= " << pose_data_list.size() << std::endl;
566  }
567  }
568 
569  return current_score;
570 }
571 
572 
573 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
574 //Dec 18, 2009...took off alot of optimization from this code since it is very fast (not rate limiting) anyways.
575 void
577  bool const Is_prepend ( job_parameters_->Is_prepend() );
578  Size const actually_moving_res = job_parameters_->actually_moving_res();
579  utility::vector1< bool > pose_state_list ( pose_data_list.size(), true );
580  Size num_clustered_pose = 0;
581 
582  for ( Size i = 1; i <= pose_data_list.size(); i++ ) {
583  if ( pose_state_list[i] == true ) {
584  num_clustered_pose++;
585 
586  for ( Size j = i + 1; j <= pose_data_list.size(); j++ ) {
587  Real rmsd;
588 
589  if ( PBP_clustering_at_chain_closure_ && job_parameters_->gap_size() == 0 ) { //new option Aug 15, 2010..include both phosphates in rmsd calculation at chain_break
590  rmsd = phosphate_base_phosphate_rmsd ( ( *pose_data_list[i].pose_OP ), ( *pose_data_list[j].pose_OP ), actually_moving_res, false /*ignore_virtual_atom*/ );
591  } else {
592  rmsd = suite_rmsd ( ( *pose_data_list[i].pose_OP ), ( *pose_data_list[j].pose_OP ), actually_moving_res, Is_prepend , false /*ignore_virtual_atom*/ );
593  }
594 
595  bool const same_pucker = Is_same_ribose_pucker ( ( *pose_data_list[i].pose_OP ), ( *pose_data_list[j].pose_OP ), actually_moving_res );
596 
597  if ( rmsd < cluster_rmsd_ && ( same_pucker || !distinguish_pucker_ ) ) {
598  pose_state_list[j] = false;
599 
600  if ( verbose_ ) {
601  std::cout << "rmsd= " << rmsd << " pose " << pose_data_list[j].tag << " is a neighbor of pose " << pose_data_list[i].tag;
602  std::cout << " same_pucker= ";
603  Output_boolean ( same_pucker );
604  print_ribose_pucker_state ( " center_pucker= ", Get_residue_pucker_state ( ( *pose_data_list[i].pose_OP ), actually_moving_res ) );
605  print_ribose_pucker_state ( " curr_pucker= ", Get_residue_pucker_state ( ( *pose_data_list[j].pose_OP ), actually_moving_res ) );
606  std::cout << std::endl;
607  }
608  }
609  }
610  }
611  }
612 
613  utility::vector1< pose_data_struct2> clustered_pose_data_list;
614 
615  for ( Size i = 1; i <= pose_data_list.size(); i++ ) {
616  if ( pose_state_list[i] == true ) {
617  clustered_pose_data_list.push_back ( pose_data_list[i] );
618  }
619  }
620 
621  pose_data_list = clustered_pose_data_list;
622 
623  ////////May 12, get the score cutoff////////
624  //check if pose_data_list size is equal to or exceed num_pose_kept_. Important to get score_cutoff here right after clustering.
625  if ( pose_data_list.size() >= num_pose_kept_ ) {
626  current_score_cutoff_ = pose_data_list[num_pose_kept_].score;
627  } else {
628  current_score_cutoff_ = 99999; //keep on adding pose to list if there are still not enough clusters
629  }
630 
631  ////////////////////////////////////////////
632 }
633 ///////////////////////////////////////////////////////////////////////////////
634 //TEMPORARY
635 bool
637  Real const & base_rep_score,
638  Real const & base_atr_score,
639  Real & delta_atr_score,
640  Real & delta_rep_score,
641  Size const & gap_size,
642  bool const & Is_internal ) {
643  using namespace core::scoring;
644 
645  if ( VDW_atr_rep_screen_ == false ) return true;
646 
647  bool close_chain = ( gap_size == 0 ) ? true : false;
648 
649  if ( close_chain && Is_internal ) return true; //Don't screen at all Mar 1, 2010
650 
651  ( *atr_rep_screening_scorefxn_ ) ( current_pose_screen );
652  EnergyMap const & energy_map = current_pose_screen.energies().total_energies();
653  Real rep_score = atr_rep_screening_scorefxn_->get_weight ( fa_rep ) * energy_map[scoring::fa_rep];
654  Real atr_score = atr_rep_screening_scorefxn_->get_weight ( fa_atr ) * energy_map[scoring::fa_atr];
655  delta_rep_score = rep_score - base_rep_score;
656  delta_atr_score = atr_score - base_atr_score;
657  Real actual_rep_cutoff = rep_cutoff_; //defualt
658 
659  if ( close_chain ) actual_rep_cutoff = 200; //Parin's old parameter
660 
661  if ( close_chain && Is_internal ) actual_rep_cutoff = 200; //Bigger chunk..easier to crash...not using this right now.
662 
663  bool pass_rep_screen = false;
664 
665  if ( delta_rep_score < actual_rep_cutoff ) {
666  pass_rep_screen = true;
667  }
668 
669  bool pass_atr_rep_screen = false;
670 
671  if ( close_chain ) {
672  pass_atr_rep_screen = pass_rep_screen;
673  } else {
674  if ( delta_atr_score < ( -1 ) && ( delta_rep_score + delta_atr_score ) < 0 ) pass_atr_rep_screen = true;
675  }
676 
677  if ( pass_atr_rep_screen ) {
678  if ( verbose_ ) {
679  std::cout << " rep= " << delta_rep_score << " atr= " << delta_atr_score;
680  std::cout << " stack_n= " << count_data_.base_stack_count << " pair_n= " << count_data_.base_pairing_count;
681  std::cout << " strict_pair_n= " << count_data_.strict_base_pairing_count;
682  std::cout << " centroid_n= " << count_data_.pass_base_centroid_screen;
683  std::cout << " bin_rep_n= " << count_data_.good_bin_rep_count;
684  std::cout << " atr_n= " << count_data_.good_atr_rotamer_count;
685  std::cout << " rep_n= " << count_data_.good_rep_rotamer_count;
686  std::cout << " both= " << count_data_.both_count << " tot= " << count_data_.tot_rotamer_count;
687  std::cout << " closable= " << count_data_.chain_closable_count;
688  std::cout << " non_clash_ribose= " << count_data_.non_clash_ribose;
689  std::cout << std::endl;
690  }
691 
692  return true;
693  } else {
694  return false;
695  }
696 }
697 ///////////////////////////////////////////////////////////////////////////////
698 bool
700  Real const & base_rep_score,
701  Real const & base_atr_score,
702  Real & delta_rep_score,
703  Real & delta_atr_score,
704  Size const & gap_size,
705  bool const & Is_internal ) {
706  using namespace core::scoring;
707  using namespace ObjexxFCL;
708 
709  if ( VDW_atr_rep_screen_ == false ) return true;
710 
711  bool close_chain = ( gap_size == 0 ) ? true : false;
712 
713  if ( close_chain && Is_internal ) return true; //Don't screen at all Mar 1, 2010
714 
715  ( *atr_rep_screening_scorefxn_ ) ( current_pose_screen );
716  EnergyMap const & energy_map = current_pose_screen.energies().total_energies();
717  Real rep_score = atr_rep_screening_scorefxn_->get_weight ( fa_rep ) * energy_map[scoring::fa_rep];
718  Real atr_score = atr_rep_screening_scorefxn_->get_weight ( fa_atr ) * energy_map[scoring::fa_atr];
719  delta_rep_score = rep_score - base_rep_score;
720  delta_atr_score = atr_score - base_atr_score;
721 
722  if ( delta_rep_score < ( -0.01 ) ) {
723  std::string const message = "delta_rep_score= " + string_of ( delta_rep_score ) + " rep_score= " + string_of ( rep_score ) + " base_rep_score= " + string_of ( base_rep_score );
724  utility_exit_with_message ( "delta_rep_score<(-0.01), " + message );
725  }
726 
727  if ( delta_atr_score > ( +0.01 ) ) {
728  std::string const message = "delta_atr_score= " + string_of ( delta_atr_score ) + " atr_score= " + string_of ( atr_score ) + " base_atr_score= " + string_of ( base_atr_score );
729  utility_exit_with_message ( "delta_atr_score>(+0.01), " + message );
730  }
731 
732  Real actual_rep_cutoff = rep_cutoff_; //defualt
733 
734  if ( close_chain ) actual_rep_cutoff = 200; //Parin's old parameter
735 
736  if ( Is_internal ) actual_rep_cutoff = 200; //Bigger chunk..easier to crash (before May 4 used to be (close_chain && Is_internal) actual_rep_cutoff=200
737 
738  bool pass_rep_screen = false;
739 
740  if ( delta_rep_score < actual_rep_cutoff ) {
741  pass_rep_screen = true;
743  }
744 
745  if ( delta_atr_score < ( -1 ) || close_chain ) count_data_.good_atr_rotamer_count++;
746 
747  bool pass_atr_rep_screen = false;
748 
749  if ( close_chain ) {
750  pass_atr_rep_screen = pass_rep_screen;
751  } else if ( Is_internal ) {
752  if ( delta_atr_score < ( -1 ) && ( delta_rep_score + delta_atr_score ) < ( actual_rep_cutoff - rep_cutoff_ ) ) pass_atr_rep_screen = true;
753  } else {
754  if ( delta_atr_score < ( -1 ) && ( delta_rep_score + delta_atr_score ) < 0 ) pass_atr_rep_screen = true;
755  }
756 
757  if ( pass_atr_rep_screen ) {
758  // if((delta_atr_score<(-1)) && ((delta_rep_score+delta_atr_score) < 200) ) { //This causes about 5times more pose to pass the screen (50,000 poses vs 10,000 poses)
760 
761  if ( verbose_ ) {
762  std::cout << " rep= " << delta_rep_score << " atr= " << delta_atr_score;
763  std::cout << " stack_n= " << count_data_.base_stack_count << " pair_n= " << count_data_.base_pairing_count;
764  std::cout << " strict_pair_n= " << count_data_.strict_base_pairing_count;
765  std::cout << " centroid_n= " << count_data_.pass_base_centroid_screen;
766  std::cout << " bin_rep_n= " << count_data_.good_bin_rep_count;
767  std::cout << " atr_n= " << count_data_.good_atr_rotamer_count;
768  std::cout << " rep_n= " << count_data_.good_rep_rotamer_count;
769  std::cout << " both= " << count_data_.both_count << " tot= " << count_data_.tot_rotamer_count << std::endl;
770  }
771 
772  return true;
773  } else {
774  return false;
775  }
776 }
777 
778 ////////////////////////////////////////////////////////////////////////
779 void
781 // utility::vector1< core::Size > const working_moving_res_list= job_parameters_->working_moving_res_list();
782  utility::vector1 < core::Size > const & working_moving_partition_pos = job_parameters_->working_moving_partition_pos();
783  utility::vector1< core::Size > const O2star_pack_seq_num = get_surrounding_O2star_hydrogen ( pose, working_moving_partition_pos, false /*verbose*/ );
784 // pack::task::PackerTaskOP task( pack::task::TaskFactory::create_packer_task( pose ));
785  o2star_pack_task_ = pack::task::TaskFactory::create_packer_task ( pose );
786 
787  for ( Size seq_num = 1; seq_num <= pose.total_residue(); seq_num++ ) {
788  if ( Contain_seq_num ( seq_num, O2star_pack_seq_num ) && pose.residue ( seq_num ).is_RNA() ) { //pack this residue!
789  o2star_pack_task_->nonconst_residue_task ( seq_num ).and_extrachi_cutoff ( 0 );
790  o2star_pack_task_->nonconst_residue_task ( seq_num ).or_ex4 ( true ); //extra O2star sampling
791  o2star_pack_task_->nonconst_residue_task ( seq_num ).or_include_current ( true );
792  // How about bump check?
793  } else {
794  o2star_pack_task_->nonconst_residue_task ( seq_num ).prevent_repacking();
795  }
796  }
797 
798  /*
799  o2star_pack_task_ = pack::task::TaskFactory::create_packer_task( pose );
800 
801  //Commented off becuase now this function is called by sample_o2star_hydrogen and this is computationally expensive? Parin S. Jan 28, 2010
802  // o2star_pack_task_->initialize_from_command_line();
803 
804  for (Size i = 1; i <= pose.total_residue(); i++) {
805  if ( !pose.residue(i).is_RNA() ) continue;
806  o2star_pack_task_->nonconst_residue_task(i).and_extrachi_cutoff( 0 );
807  // Following could be useful...
808  o2star_pack_task_->nonconst_residue_task(i).or_ex4( true ); //extra rotamers?? Parin S. Jan 28, 2010
809  o2star_pack_task_->nonconst_residue_task(i).or_include_current( true );
810  }
811  */
812 }
813 
814 ////////////////////////////////////////////////////////////////////////
815 void
817  using namespace core::id;
818  using namespace core::conformation;
819 
820  //reset the HO2star torsion to its starting value as to prevent randomness due to conformations sampling order...
821  for ( Size seq_num = 1; seq_num <= pose.total_residue(); seq_num++ ) {
822  if ( pose.residue ( seq_num ).aa() == core::chemical::aa_vrt ) continue; //FCC
823 
824  pose.set_torsion ( TorsionID ( seq_num, id::CHI, 4 ), pose_with_original_HO2star_torsion.torsion ( TorsionID ( seq_num, id::CHI, 4 ) ) );
825  }
826 
827  //std::cout << "Packing 2'-OH ... ";
828  //problem with bulge variant -- need to initialize_o2star_packer_task each time.
831 }
832 
833 ////////////////////////////////////////////////////////////////////////
834 std::string //silly function to convert to real to string
836  using namespace ObjexxFCL;
837  std::string torsion_string = "";
838  core::Real const principal_torsion = numeric::principal_angle_degrees ( torsion_value );
839  Size const principal_torsion_SIZE = Size( std::abs ( principal_torsion + 0.00001 ) ); //0.00001 is to prevent random ambiguity if the torsion decimal value is exactly .0000 Oct 12, 2010
840 
841  if ( principal_torsion > 0 ) {
842  torsion_string = "p" + lead_zero_string_of ( principal_torsion_SIZE, 3 );
843  } else {
844  torsion_string = "n" + lead_zero_string_of ( principal_torsion_SIZE, 3 );
845  }
846 
847  return torsion_string;
848 }
849 
850 ////////////////////////////////////////////////////////////////////////
851 std::string //silly function used for appending the rotamer value to the tag
853  std::string rotamer_tag = "";
854  bool const Is_prepend ( job_parameters_->Is_prepend() );
855  Size const moving_res ( job_parameters_->working_moving_res() );
856  conformation::Residue const & five_prime_rsd = ( Is_prepend ) ? pose.residue ( moving_res ) : pose.residue ( moving_res - 1 );
857  conformation::Residue const & three_prime_rsd = ( Is_prepend ) ? pose.residue ( moving_res + 1 ) : pose.residue ( moving_res );
858  rotamer_tag.append ( "_E" + create_torsion_value_string ( five_prime_rsd.mainchain_torsion ( 5 ) ) );
859  rotamer_tag.append ( "_Z" + create_torsion_value_string ( five_prime_rsd.mainchain_torsion ( 6 ) ) );
860  rotamer_tag.append ( "_A" + create_torsion_value_string ( three_prime_rsd.mainchain_torsion ( 1 ) ) );
861  rotamer_tag.append ( "_B" + create_torsion_value_string ( three_prime_rsd.mainchain_torsion ( 2 ) ) );
862  rotamer_tag.append ( "_G" + create_torsion_value_string ( three_prime_rsd.mainchain_torsion ( 3 ) ) );
863 
864  if ( Is_prepend ) {
865  rotamer_tag.append ( "_D" + create_torsion_value_string ( five_prime_rsd.mainchain_torsion ( 4 ) ) );
866  rotamer_tag.append ( "_C" + create_torsion_value_string ( five_prime_rsd.chi ( 1 ) ) );
867  } else {
868  rotamer_tag.append ( "_D" + create_torsion_value_string ( three_prime_rsd.mainchain_torsion ( 4 ) ) );
869  rotamer_tag.append ( "_C" + create_torsion_value_string ( three_prime_rsd.chi ( 1 ) ) );
870  }
871 
872  return rotamer_tag;
873 }
874 ////////////////////////////////////////////////////////////////////////
875 
878  using namespace ObjexxFCL;
879  std::string tag = prestring;
880 
881  for ( Size list_position = rotamer_generator->rotamer_generator_list_size(); list_position >= 2; list_position-- ) { //For dinucleotide
882  tag.append ( "_" + lead_zero_string_of ( rotamer_generator->group_rotamer ( list_position ), 4 ) );
883  }
884 
885  tag.append ( "_" + lead_zero_string_of ( rotamer_generator->group_rotamer ( 1 ), 4 ) );
886  tag.append ( "_" + lead_zero_string_of ( rotamer_generator->subgroup_rotamer ( 1 ), 5 ) );
887  return tag;
888 }
889 
890 //////////////////////////////////////////////////////////////////////////
891 void
893  silent_file_ = silent_file;
894 }
895 
896 //////////////////////////////////////////////////////////////////////////
897 void
899  fast_ = setting;
900 
901  if ( fast_ ) num_pose_kept_ = 2;
902 }
903 
904 //////////////////////////////////////////////////////////////////////////
905 void
907  medium_fast_ = setting;
908 
909  if ( medium_fast_ ) num_pose_kept_ = 20;
910 }
911 
912 
913 //////////////////////////////////////////////////////////////////////////
914 void
916  native_rmsd_screen_ = setting;
917  //if (native_rmsd_screen_) num_pose_kept_ = 20; Aug 16 2010..Parin S. For python_rebuild_suite.py
918 }
919 //////////////////////////////////////////////////////////////////////////
920 void
922  verbose_ = setting;
923 }
924 
925 
926 //////////////////////////////////////////////////////////////////////////
927 void
929  o2star_screen_ = setting;
930 }
931 
932 //////////////////////////////////////////////////////////////////////////
933 void
935  output_filename_ = output_filename;
936 }
937 
938 //////////////////////////////////////////////////////////////////////////
939 void
941  scorefxn_ = scorefxn;
942 }
943 
944 //////////////////////////////////////////////////////////////////////////
947  return sfd_;
948 }
949 
950 
951 //////////////////////////////////////////////////////////////////
952 void
953 StepWiseRNA_AnalyticalLoopCloseSampler::output_pose_data_list ( std::string const final_sampler_output_silent_file ) const {
954  using namespace core::io::silent;
955 
956  if ( verbose_ == false ) { //consistency check Apr 3, 2010
957  utility_exit_with_message ( "verbose_==false, but StepWiseRNA_AnalyticalLoopCloseSampler::output_pose_data_list is still called?!" );
958  }
959 
961 
962  for ( Size n = 1; n <= pose_data_list_.size(); n++ ) {
963  Output_data ( silent_file_data, final_sampler_output_silent_file, pose_data_list_[n].tag, false, * ( pose_data_list_[n].pose_OP ), get_native_pose(), job_parameters_ );
964  }
965 }
966 
967 //////////////////////////////////////////////////////////////////
968 void
970  base_centroid_screener_ = screener;
971 }
972 
973 //////////////////////////////////////////////////////////////////
974 void
976 {
977  user_input_VDW_bin_screener_ = user_input_VDW_bin_screener;
978 }
979 
980 
981 void
983  cluster_rmsd_ = setting;
984  std::cout << "Set cluster_rmsd to " << cluster_rmsd_ << std::endl;
985 }
986 
987 void
989  num_pose_kept_ = num_pose_kept ;
990  // PARIN THIS DOES NOT MAKE ANY SENSE??
991  //If fast_ or native_rmsd_scren the num_pose_kept_= 10 or 20 respectively Parin Feb 13, 2010
993  set_fast ( fast_ );
994 }
995 
996 }
997 }
998 }