Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StepWiseRNA_CombineLongLoopFilterer.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_CombineLongLoopFilterer
11 /// @brief Sets up pose and job parameters for RNA stepwise building.
12 /// @detailed
13 /// @author Rhiju Das
14 
15 
16 //////////////////////////////////
18 
23 
25 //////////////////////////////////
26 
27 #include <core/types.hh>
30 #include <core/chemical/util.hh>
44 #include <core/types.hh>
45 #include <core/pose/Pose.hh>
46 #include <core/pose/util.hh>
47 #include <core/pose/util.tmpl.hh>
48 #include <basic/Tracer.hh>
49 
50 #include <core/id/TorsionID.hh>
53 #include <ObjexxFCL/string.functions.hh>
54 #include <ObjexxFCL/format.hh>
55 
56 #include <ObjexxFCL/FArray1D.hh>
57 #include <ObjexxFCL/FArray2D.hh>
58 
59 
60 #include <utility/exit.hh>
61 #include <time.h>
62 
63 #include <string>
64 #include <stdio.h>
65 #include <iostream>
66 #include <fstream>
67 #include <sstream>
68 
69 using namespace core;
70 using core::Real;
71 
72 //////////////////////////////////////////////////////////////////////////
73 //////////////////////////////////////////////////////////////////////////
74 // Add class description here!
75 //
76 //
77 //////////////////////////////////////////////////////////////////////////
78 //////////////////////////////////////////////////////////////////////////
79 //////////////////////////////////////////////////////////////////////////
80 
81 static basic::Tracer TR( "protocols.swa.rna_stepwise_rna_CombineLongLoopFilterer") ;
82 
83 namespace protocols {
84 namespace swa {
85 namespace rna {
86 
87  //////////////////////////////////////////////////////////////////////////
88  //constructor!
89  StepWiseRNA_CombineLongLoopFilterer::StepWiseRNA_CombineLongLoopFilterer( StepWiseRNA_JobParametersCOP const & job_parameters, bool const combine_helical_silent_file):
90  rsd_set_( core::chemical::ChemicalManager::get_instance()->residue_type_set( core::chemical::RNA ) ),
91  job_parameters_( job_parameters ),
92  verbose_( true ), //Parin Mar 22, 2010
93  filter_for_previous_contact_(false),
94  filter_for_previous_clash_(false),
95  undercount_ribose_rotamers_(false), //July 29, 2011
96  filter_for_chain_closable_(true),
97  filter_for_moving_res_contact_(true),
98  moving_res_to_base_contact_only_(true), //used if filter_for_movign_res_contact_ is true, buggy right now since ignoring hydrogen (non-heavy) atom in the base..
99  total_input_struct_pair_(0),
100  pass_screen_struct_pair_(0),
101  output_filename_("filter_struct.txt"), //will have to change later...perhap pass in this from the python script?
102  //best_combine_score_(99999999.99), //Feb 02, 2012; This might lead to server-test error at R47198
103  //worst_combine_score_(-99999999.99), //Feb 02, 2012; This might lead to server-test error at R47198
104  best_combine_score_(999999.99), //Feb 02, 2012;
105  worst_combine_score_(-999999.99), //Feb 02, 2012;
106  //score_diff_cut_(1000000.0), //Remove all score filtering on Jan 12, 2012
107  contact_dist_cutoff_(-1.0), //two atoms are considered in contact if their VDW radius edge is within 1.0 Angstrom of each other
108  clash_dist_cutoff_(0.8), //two atoms are considered clash if their VDW radius edge overlap by 0.8 Angstrom.
109  //0.8 is appropriate for VDW clash screen, although value about 1.2 would be more appropriate if we consider minimum H-bond distance
110  //See StepWiseRNA_VDW_Bin_Screener.cc for details.
111 // num_contact_cutoff_(9), //num of contact between the two sides before discarding pose (Used to be 1 before Nov 18, 2010)
112  num_contact_cutoff_(1), //num of contact between the two sides before discarding pose (Used to be 1 before Nov 18, 2010)
113  num_clash_cutoff_(1), // num of clash between the two sides before discarding pose.
114  max_pose_data_list_size_(200),
115  side_ONE_NUM_pose_list_(0),
116  side_TWO_NUM_pose_list_(0),
117  side_ONE_pose_list_id_(1),
118  side_TWO_pose_list_id_(1),
119  //max_decoys_(9999999999), //Feb 02, 2012; This might lead to server-test error at R47198
120  max_decoys_(999999), //Feb 02, 2012;
121  combine_helical_silent_file_(combine_helical_silent_file) //Hacky mode to build VC_two 3 way junction
122  {
123 
124  if(combine_helical_silent_file_==false){
125 
126  utility::vector1< utility::vector1< Size > > const & input_res_vectors=job_parameters_->input_res_vectors();
127 
128  if(input_res_vectors.size()!=2) utility_exit_with_message("input_res_vectors.size()!=2");
129 
130  full_to_input_res_map_ONE_=create_full_to_input_res_map(input_res_vectors[1]); //right now, only use this in figure_out_appended_and_prepended_res_list function
131  full_to_input_res_map_TWO_=create_full_to_input_res_map(input_res_vectors[2]); //right now, only use this in figure_out_appended_and_prepended_res_list function
132 
135 
136  //O3I_C5I_PLUS_ONE_MAX_DIST=3.968000
137  //max_centroid_to_atom_distance for atom: C5* base RAD: 6.18959
138  //max_centroid_to_atom_distance for atom: O3* base RAD: 6.65341
139  //For is for a A-nucleotides, more chi rotamers
140  //Suppose that moving_res is making base-stack contact to the last SWA-built residue from the another side:
141  // Then atom-atom distance must be lesser than minus_contact_dist_cutoff_(1)+atom vanderWaal radius -> for Carbon: 1.70
142 
143  //so 3.968000 + (6.18959 or 6.65341) + (1) + (3.4)=
144  moving_res_contact_dist_cutoff_=3.968000+6.65341+1+3.4;
145  std::cout << "moving_res_contact_dist_cutoff_= " << moving_res_contact_dist_cutoff_ << std::endl;
146  std::cout << "contact_dist_cutoff_= " << contact_dist_cutoff_ << std::endl;
147  std::cout << "clash_dist_cutoff_= " << clash_dist_cutoff_ << std::endl;
148  std::cout << "num_contact_cutoff_= " << num_contact_cutoff_ << std::endl;
149  std::cout << "num_clash_cutoff_= " << num_clash_cutoff_ << std::endl;
150 
151  }
152 
153  }
154 
155  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
156 
157  //destructor
159  {}
160  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
161 
162 
163  void
165 
166  //OK first find that residues that are common between two pose...there are user inputted residues
167 
168  utility::vector1< utility::vector1< Size > > const & input_res_vectors=job_parameters_->input_res_vectors();
169 
170 
171  utility::vector1<core::Size> common_res_list;
172 
173  for(Size n=1; n<=input_res_vectors[1].size(); n++){
174 
175  Size const seq_num=input_res_vectors[1][n];
176 
177  if(Contain_seq_num(seq_num, input_res_vectors[2])){
178  common_res_list.push_back(seq_num);
179  }
180 
181  }
182 
183  utility::vector1<core::Size> full_pose_appended_res_list;
185 
186  for(Size n=1; n<=input_res_vectors[1].size(); n++){
187  Size const seq_num=input_res_vectors[1][n];
188  if(Contain_seq_num(seq_num, common_res_list)==false){
189 
190  full_pose_appended_res_list.push_back(seq_num);
191  input_pose_ONE_appended_res_list_.push_back(full_to_input_res_map_ONE_.find(seq_num)->second);
192 
193  }
194  }
195 
196  utility::vector1<core::Size> full_pose_prepended_res_list;
198 
199 
200  for(Size n=1; n<=input_res_vectors[2].size(); n++){
201  Size const seq_num=input_res_vectors[2][n];
202  if(Contain_seq_num(seq_num, common_res_list)==false){
203 
204  full_pose_prepended_res_list.push_back(seq_num);
205  input_pose_TWO_prepended_res_list_.push_back(full_to_input_res_map_TWO_.find(seq_num)->second);
206 
207  }
208  }
209 
210  Output_seq_num_list("full_pose_appended_res:" , full_pose_appended_res_list);
211  Output_seq_num_list("full_pose_prepended_res:" , full_pose_prepended_res_list);
212 
213  Output_seq_num_list("input_ONE_appended_res:" , input_pose_ONE_appended_res_list_);
214  Output_seq_num_list("input_TWO_prepended_res:" , input_pose_TWO_prepended_res_list_);
215 
216 
217  }
218 
219 
220  /////////////////////////////////////////////////////////////////////////////////////////////////
221  void
223 
224  utility::vector1< utility::vector1< Size > > const & input_res_vectors=job_parameters_->input_res_vectors();
225 
226  //////////////////////////////////////////////////////////////////
227 
229 
230  if(input_pose_ONE_appended_res_list_.size()==0) utility_exit_with_message("input_pose_ONE_appended_res_list_.size()==0");
231 
232  for(Size n=1; n<= input_pose_ONE_appended_res_list_.size(); n++){
234 
236 
237  }
238  }
239 
240  //////////////////////////////////////////////////////////////////
241 
242  //input_pose_TWO_last_prepended_res_=9999999; //Feb 02, 2012: This might lead to server-test error at R47200
243  input_pose_TWO_last_prepended_res_=999999; //Feb 02, 2012
244 
245  if(input_pose_TWO_prepended_res_list_.size()==0) utility_exit_with_message("input_pose_TWO_prepended_res_list_.size()==0");
246 
247  for(Size n=1; n<= input_pose_TWO_prepended_res_list_.size(); n++){
249 
251 
252  }
253  }
254 
255  //////////////////////////////////////////////////////////////////
256 
257  Size const full_last_appended_res=input_res_vectors[1][input_pose_ONE_last_appended_res_];
258  Size const full_last_prepended_res=input_res_vectors[2][input_pose_TWO_last_prepended_res_];
259 
260 
261  std::cout << "full_pose_last_appended_res_= " << full_last_appended_res << " input_pose_ONE_last_appended_res_= " << input_pose_ONE_last_appended_res_;
262  std::cout << " full_pose_last_prepended_res_= " << full_last_prepended_res << " input_pose_TWO_last_prepended_res_= " << input_pose_TWO_last_prepended_res_ << std::endl;
263 
264 
265 /*
266  using namespace ObjexxFCL;
267 
268  bool const Is_prepend( job_parameters_->Is_prepend() );
269 
270  std::map< core::Size, core::Size > const & sub_to_full =job_parameters_->const_sub_to_full(); //make these const
271 
272  Size const moving_res( job_parameters_->working_moving_res() ); // Might not corresponds to user input.
273  Size const reference_res( job_parameters_->working_reference_res() ); //the last static_residues that this attach to the moving residues
274 
275 
276 
277  Size working_last_prepended_res, working_last_appended_res;
278 
279  if(Is_prepend){
280  working_last_prepended_res=reference_res;
281  working_last_appended_res=moving_res-1;
282  }else{
283  working_last_prepended_res=reference_res;
284  working_last_appended_res=moving_res+1;
285  }
286 
287 
288  if(sub_to_full.count(working_last_prepended_res)==0) utility_exit_with_message("sub_to_full.count(working_last_prepended_res)==0, working_last_prepended_res=" + string_of(working_last_prepended_res));
289  if(sub_to_full.count(working_last_appended_res)==0) utility_exit_with_message("sub_to_full.count(working_last_appended_res)==0, working_last_appended_res= " + string_of(working_last_appended_res) );
290 
291 
292  Size const full_last_appended_res=sub_to_full.find(working_last_prepended_res)->second;
293  Size const full_last_prepended_res=sub_to_full.find(working_last_appended_res)->second;
294 
295  if(full_to_input_res_map_ONE_.count(full_last_appended_res)==0) utility_exit_with_message("full_to_input_res_map_ONE_[full_last_appended_res].count==0");
296  if(full_to_input_res_map_TWO_.count(full_last_prepended_res)==0) utility_exit_with_message("full_to_input_res_map_TWO_[full_last_prepended_res].count==0");
297 
298  input_pose_ONE_last_appended_res_=full_to_input_res_map_ONE_.find(full_last_appended_res)->second;
299  input_pose_TWO_last_prepended_res_=full_to_input_res_map_TWO_.find(full_last_prepended_res)->second;
300 */
301 
302 
303  }
304 
305  /////////////////////////////////////////////////////////////////////////////////////////////////
308 
309  using namespace core::pose;
310  using namespace ObjexxFCL;
311 
312 // Output_title_text("Enter StepWiseRNA_CombineLongLoopFilterer::convert_silent_file_to_pose_data_list (" + path_basename(silent_file) + ")");
313 
314 
316 
317 
318 
319 /*
320  core::io::silent::SilentFileData silent_file_data;
321  silent_file_data.read_file( silent_file );
322  for ( core::io::silent::SilentFileData::iterator iter = silent_file_data.begin(), end = silent_file_data.end(); iter != end; ++iter ) {
323 
324  //iter->fill_pose( *pose_op , *(rsd_set_) );
325 
326 */
327 
328  Size min_pose_ID=((pose_list_id-1)*(max_pose_data_list_size_))+1;
329  Size max_pose_ID=((pose_list_id)*(max_pose_data_list_size_));
330 
331  Size pose_ID=0;
332  Size num_struct_in_range=0;
333 
334  silent_file_stream->reset();
335 
336  while ( silent_file_stream->has_another_pose() ) {
337 
338  pose_ID++;
339 
340  core::io::silent::SilentStructOP const silent_struct( silent_file_stream->next_struct() );
341 
342  if( (pose_ID < min_pose_ID) || (pose_ID>max_pose_ID) ) continue;
343 
344  num_struct_in_range++;
345 
346  PoseOP pose_op( new Pose );
347 
348  silent_struct->fill_pose( *pose_op,*(rsd_set_) );
349 
350  Real score( 0.0 );
351  getPoseExtraScores( *pose_op, "score", score );
352 
353  std::string const & tag( silent_struct->decoy_tag() );
354 
356  utility_exit_with_message("tag= " + tag + " is messed up!");
357  }
358 
359  pose_data_struct2 pose_data;
360  pose_data.pose_OP=pose_op;
361  pose_data.score=score;
362  pose_data.tag=tag;
363 
364  pose_data_list.push_back(pose_data);
365 
366 
367  }
368 
369  if(num_struct_in_range==0) utility_exit_with_message("num_struct_in_range==0! for pose_list_id= " + string_of(pose_list_id) + " min_pose_ID= " + string_of(min_pose_ID)+ " max_pose_ID= " + string_of(max_pose_ID) );
370 
371 // if(pose_data_list.size()==0) utility_exit_with_message("pose_data_list.size()==0" );
372 
373 // Output_title_text("Exit StepWiseRNA_CombineLongLoopFilterer::convert_silent_file_to_pose_data_list (" + path_basename(silent_file) + ")");
374 
375 
376  return pose_data_list;
377 
378  }
379 
380  /////////////////////////////////////////////////////////////////////////////////////////////////
381  void
383  utility::vector1< pose_data_struct2 > const & side_TWO_pose_data_list){
384  using namespace chemical;
385 
386  Output_title_text("Enter StepWiseRNA_CombineLongLoopFilterer::align_all_pose ");
387 
388  if(side_ONE_pose_data_list.size()==0) utility_exit_with_message("side_ONE_pose_data_list.size()==0" );
389  if(side_TWO_pose_data_list.size()==0) utility_exit_with_message("side_TWO_pose_data_list.size()==0" );
390 
391 
392  core::pose::Pose const alignment_pose=(*side_ONE_pose_data_list[1].pose_OP);
393 
394 
395  for(Size n=1; n<=side_ONE_pose_data_list.size(); n++){
396 
397  core::pose::Pose & side_ONE_pose=(*side_ONE_pose_data_list[n].pose_OP);
398 
399  id::AtomID_Map< id::AtomID > atom_ID_map; //Align the first and last residues of the two pose (which should be the same residue)
400  pose::initialize_atomid_map( atom_ID_map, side_ONE_pose, id::BOGUS_ATOM_ID );
401 
402  setup_suite_atom_id_map(side_ONE_pose.residue(1), alignment_pose.residue(1), atom_ID_map);
403  setup_suite_atom_id_map(side_ONE_pose.residue(side_ONE_pose.total_residue()), alignment_pose.residue(alignment_pose.total_residue()), atom_ID_map);
404 
405  core::scoring::superimpose_pose(side_ONE_pose, alignment_pose, atom_ID_map);
406 
407  //if(n==1) side_ONE_pose.dump_pdb( "Filterer_side_ONE_pose_"+ side_ONE_pose_data_list[n].tag +".pdb" );
408 
409  }
410 
411 
412  for(Size n=1; n<=side_TWO_pose_data_list.size(); n++){
413 
414  core::pose::Pose & side_TWO_pose=(*side_TWO_pose_data_list[n].pose_OP);
415 
416  id::AtomID_Map< id::AtomID > atom_ID_map; //Align the first and last residues of the two pose (which should be the same residue)
417  pose::initialize_atomid_map( atom_ID_map, side_TWO_pose, id::BOGUS_ATOM_ID );
418 
419  setup_suite_atom_id_map(side_TWO_pose.residue(1), alignment_pose.residue(1), atom_ID_map);
420  setup_suite_atom_id_map(side_TWO_pose.residue(side_TWO_pose.total_residue()), alignment_pose.residue(alignment_pose.total_residue()), atom_ID_map);
421 
422  core::scoring::superimpose_pose( side_TWO_pose, alignment_pose, atom_ID_map);
423 
424  //if(n==1) side_TWO_pose.dump_pdb( "Filterer_side_TWO_pose_" + side_TWO_pose_data_list[n].tag + ".pdb" );
425 
426 
427  }
428 
429 
430 
431  Output_title_text("Exit StepWiseRNA_CombineLongLoopFilterer::align_all_pose ");
432 
433 
434  }
435 
436  /////////////////////////////////////////////////////////////////////////////////////////////////
437 
438 
439 
440  bool
442  pose_data_struct2 const & side_TWO_pose_data ,
443  core::Real const overlap_dist_cutoff,
444  core::Size const num_atom_contacts_cutoff){
445 
446  core::pose::Pose const & side_ONE_pose=(*side_ONE_pose_data.pose_OP);
447  core::pose::Pose const & side_TWO_pose=(*side_TWO_pose_data.pose_OP);
448 
449  for(Size i=1; i<=input_pose_ONE_appended_res_list_.size(); i++){
450  for(Size j=1; j<=input_pose_TWO_prepended_res_list_.size(); j++){
451 
452  Size const input_pose_ONE_appended_res = input_pose_ONE_appended_res_list_[i];
453  Size const input_pose_TWO_prepended_res= input_pose_TWO_prepended_res_list_[j];
454 
455  bool const residues_in_contact=Is_residues_in_contact(input_pose_ONE_appended_res, side_ONE_pose, input_pose_TWO_prepended_res, side_TWO_pose, overlap_dist_cutoff, num_atom_contacts_cutoff);
456 
457  if(residues_in_contact) return false;
458 
459  }
460  }
461 
462  return true;
463 
464  }
465 
466  /////////////////////////////////////////////////////////////////////////////////////////////////
467 
468 
469 /*
470  core::pose::Pose const & side_ONE_pose=(*side_ONE_pose_data.pose_OP);
471  core::pose::Pose const & side_TWO_pose=(*side_TWO_pose_data.pose_OP);
472 
473  for(Size i=1; i<=input_pose_ONE_appended_res_list_.size(); i++){
474  for(Size j=1; j<=input_pose_TWO_prepended_res_list_.size(); j++){
475 
476  Size const input_pose_ONE_appended_res = input_pose_ONE_appended_res_list_[i];
477  Size const input_pose_TWO_prepended_res= input_pose_TWO_prepended_res_list_[j];
478 
479  core::conformation::Residue const & rsd_ONE=side_ONE_pose.residue(input_pose_ONE_appended_res);
480  core::conformation::Residue const & rsd_TWO=side_TWO_pose.residue(input_pose_TWO_prepended_res);
481 
482 
483  for(Size at_ONE=1; at_ONE<= rsd_ONE.natoms(); at_ONE++){
484  for(Size at_TWO=1; at_TWO<= rsd_TWO.natoms(); at_TWO++){
485 
486  if(rsd_ONE.atom_type(at_ONE).name()=="VIRT") continue;
487  if(rsd_TWO.atom_type(at_TWO).name()=="VIRT") continue;
488 
489  Real const VDW_radius_ONE=rsd_ONE.atom_type(at_ONE).lj_radius();
490  Real const VDW_radius_TWO=rsd_TWO.atom_type(at_TWO).lj_radius();
491 
492  Real const cutoff_sum_VDW_radius=VDW_radius_ONE+VDW_radius_TWO-overlap_dist_cutoff;
493 
494  if(cutoff_sum_VDW_radius<0) utility_exit_with_message("(VDW_radius_ONE+VDW_radius_TWO-overlap_dist_cutoff)<0!!" );
495 
496 
497  Real const atom_atom_dist_squared=(rsd_ONE.xyz(at_ONE)-rsd_TWO.xyz(at_TWO)).length_squared();
498 
499  if(atom_atom_dist_squared<(cutoff_sum_VDW_radius*cutoff_sum_VDW_radius)) return false;
500 
501 
502  }
503  }
504 
505  }
506  }
507 */
508 
509 
510  /////////////////////////////////////////////////////////////////////////////////////////////////
511  bool
513 
514  return (previously_builded_res_VDW_filter(side_ONE_pose_data, side_TWO_pose_data, contact_dist_cutoff_ , num_contact_cutoff_));
515 
516  }
517 
518  /////////////////////////////////////////////////////////////////////////////////////////////////
519  bool
521 
522  return (previously_builded_res_VDW_filter(side_ONE_pose_data, side_TWO_pose_data, clash_dist_cutoff_, num_clash_cutoff_));
523 
524  }
525  /////////////////////////////////////////////////////////////////////////////////////////////////
526  bool
528 
529 
530  bool const Is_prepend( job_parameters_->Is_prepend() );
531 
532 
533  core::pose::Pose const & side_ONE_pose=(*side_ONE_pose_data.pose_OP);
534  core::pose::Pose const & side_TWO_pose=(*side_TWO_pose_data.pose_OP);
535 
536 
537  core::conformation::Residue const & last_append_rsd=side_ONE_pose.residue(input_pose_ONE_last_appended_res_);
538  core::conformation::Residue const & last_prepend_rsd=side_TWO_pose.residue(input_pose_TWO_last_prepended_res_);
539 
540  numeric::xyzVector<core::Real> const anchor_atom_xyz = (Is_prepend) ? last_prepend_rsd.xyz("C5*") : last_append_rsd.xyz("O3*");
541 
542  core::conformation::Residue const & enforce_contact_rsd= (Is_prepend) ? last_append_rsd : last_prepend_rsd;
543 
544  if(enforce_contact_rsd.type().atom_name(enforce_contact_rsd.first_sidechain_atom()) !=" O2*"){
545  utility_exit_with_message( "enforce_contact_rsd.type().atom_name(enforce_contact_rsd.first_sidechain_atom()) !=\" O2*\" " );
546  }
547 
548  Size const first_at= (moving_res_to_base_contact_only_) ? (enforce_contact_rsd.first_sidechain_atom()+1) : 1;
549  Size const last_at= (moving_res_to_base_contact_only_) ? (enforce_contact_rsd.nheavyatoms()) : enforce_contact_rsd.natoms();
550  //crap this ignore hydrogen atoms in the base...rsd.nheavyatoms()
551 
552  for(Size at=first_at; at<=last_at; at++){
553 
554  Real const atom_atom_dist_squared=(enforce_contact_rsd.xyz(at)-anchor_atom_xyz).length_squared();
555 
556  if(atom_atom_dist_squared < (moving_res_contact_dist_cutoff_* moving_res_contact_dist_cutoff_) ) return true;
557 
558  }
559 
560  return false;
561 
562  }
563 
564  /////////////////////////////////////////////////////////////////////////////////////////////////
565  bool
566  StepWiseRNA_CombineLongLoopFilterer::pass_all_filters(pose_data_struct2 const & side_ONE_pose_data, pose_data_struct2 const & side_TWO_pose_data){
567 
568  using namespace ObjexxFCL;
569 
570  //if(verbose_) Output_title_text("Enter StepWiseRNA_CombineLongLoopFilterer::do_some_filtering(" + side_ONE_pose_data.tag + "," + side_TWO_pose_data.tag +")" );
571 
572 
573  //Would this slow down the code?
574 
575  Size const num_nucleotides( job_parameters_->working_moving_res_list().size() );
576  Size const previous_step_gap_size= (job_parameters_->gap_size())+num_nucleotides;
577 
578  if(previous_step_gap_size==0) utility_exit_with_message("previous_step_gap_size==0!!" );
579  ///////////////////////////////////////////////////////////////////////////
580 
581 
582  core::pose::Pose const & side_ONE_pose=(*side_ONE_pose_data.pose_OP);
583  core::pose::Pose const & side_TWO_pose=(*side_TWO_pose_data.pose_OP);
584 
585  Real const curr_combine_score=side_ONE_pose_data.score + side_TWO_pose_data.score;
586 
588 
589  //if(curr_combine_score > (best_combine_score_ + score_diff_cut_) ) return false;
590 
592 
593 
594  if((filter_for_chain_closable_==true)){
595 
596  //OK STILL HAVE TO WRITE CODE FOR THE DINUCLEOTIDE case....
597  //July 19th, 2011..This assumes that the 5' and 3' ribose is already built (not virtual!) but this might not be the case!
598 
599  if (Check_chain_closable(side_TWO_pose.residue(input_pose_TWO_last_prepended_res_).xyz("C5*") , side_ONE_pose.residue(input_pose_ONE_last_appended_res_).xyz("O3*"), previous_step_gap_size)==false) return false;
600 
602 
603  }
604 
606  if(previously_builded_res_contact_filter(side_ONE_pose_data , side_TWO_pose_data )==false) return false;
607 
609  }
610 
611  if(filter_for_previous_clash_==true){
612  if(previously_builded_res_clash_filter(side_ONE_pose_data , side_TWO_pose_data )==false) return false;
613 
615  }
616 
617 
618  if(best_combine_score_> curr_combine_score) best_combine_score_=curr_combine_score; //best_combine_score that still PASS the screen..
619 
620 
621  //DON'T include this screen to determine best_combine_score since it can lead to an artificially bad best_combine_score (still need to verify this!)
622  if((previous_step_gap_size!=1) && (filter_for_moving_res_contact_==true)){
623 
624  //INCLUDE the dinucleotide Chainbreak code since if dinucleotide...moving_res (the floating base) cannot be bulge and need to make contact.
625  if(moving_res_contact_filter(side_ONE_pose_data, side_TWO_pose_data)==false) return false;
626 
628  }
629 
630  if(worst_combine_score_< curr_combine_score) worst_combine_score_=curr_combine_score; //worst_combine_score that still PASS the screen
631 
632 
633  return true;
634 
635  }
636 
637 
638  /////////////////////////////////////////////////////////////////////////////////////////////////
639  void
641 
642 
643  using namespace ObjexxFCL;
644 
645  Output_title_text("Enter StepWiseRNA_CombineLongLoopFilterer::do_some_filtering for side_ONE_pose_list_id_=" + string_of(side_ONE_pose_list_id_) + "/" + string_of(side_ONE_NUM_pose_list_) + " side_ONE_pose_list_id_=" + string_of(side_TWO_pose_list_id_) + "/" + string_of(side_TWO_NUM_pose_list_) );
646 
647 
648 // std::ofstream outfile;
649 // outfile.open(output_filename_.c_str(), std::ios_base::out | std::ios_base::app); //This does not delete existing content
650 
651  utility::vector1< pose_data_struct2 > const side_ONE_pose_data_list=convert_silent_file_to_pose_data_list(silent_file_stream_ONE_, side_ONE_pose_list_id_); //assume this is the one build loop by append from 5' side
652  utility::vector1< pose_data_struct2 > const side_TWO_pose_data_list=convert_silent_file_to_pose_data_list(silent_file_stream_TWO_, side_TWO_pose_list_id_);//assume this is the one build loop by prepend from 3' side
653 
654  if(side_ONE_pose_data_list.size()==0) return;
655  if(side_TWO_pose_data_list.size()==0) return;
656 
657 
658  if(combine_helical_silent_file_==false){ //Nov 27 2010
659  align_all_pose(side_ONE_pose_data_list, side_TWO_pose_data_list);
660  }
661 
662  for(Size i=1; i<=side_ONE_pose_data_list.size(); i++){
663  for(Size j=1; j<=side_TWO_pose_data_list.size(); j++){
664 
666 
667  pose_data_struct2 const & side_ONE_pose_data=side_ONE_pose_data_list[i];
668  pose_data_struct2 const & side_TWO_pose_data=side_TWO_pose_data_list[j];
669 
670  if(combine_helical_silent_file_==false){
671  if(pass_all_filters(side_ONE_pose_data, side_TWO_pose_data)==false) continue;
672  }else{ //Nov 27 2010
673 
674  Real const curr_combine_score=side_ONE_pose_data.score + side_TWO_pose_data.score;
675 
677 
678  //if(curr_combine_score > (best_combine_score_ + score_diff_cut_) ) continue;
679 
681 
682  if(best_combine_score_> curr_combine_score) best_combine_score_=curr_combine_score; //best_combine_score that still PASS the screen..
683 
684  }
685 
687 
688  //ok will print to file after finish debugging
689  std::cout << "struct pair: (" << side_ONE_pose_data.tag << " ," << side_TWO_pose_data.tag << ") pass screening test. ";
690  std::cout << pass_screen_struct_pair_ << " out of " << total_input_struct_pair_ << " passed screen so far" << std::endl;
691 
692 
693  Combine_Tags_Info combine_tag_info;
694  combine_tag_info.side_one_tag=side_ONE_pose_data.tag;
695  combine_tag_info.side_two_tag=side_TWO_pose_data.tag;
696  combine_tag_info.combine_score=side_ONE_pose_data.score+side_TWO_pose_data.score;
697 
698  filterered_combine_tag_info_list_.push_back(combine_tag_info);
699 
700  }
701  }
702 
703 // outfile.flush();
704 // outfile.close();
705 
706  Output_title_text("Exit StepWiseRNA_CombineLongLoopFilterer::do_some_filtering");
707 
708 
709 
710  }
711 
712  /////////////////////////////////////////////////////////////////////////////////////////////////
713 
714  void
716 
717  silent_file_stream_ONE_->reset();
718  silent_file_stream_TWO_->reset();
719 
720 
721  Size total_pose_side_ONE=0;
722 
723  while ( silent_file_stream_ONE_->has_another_pose() ) {
724  total_pose_side_ONE++;
725  core::io::silent::SilentStructOP const silent_struct( silent_file_stream_ONE_->next_struct() );
726  }
727 
728  Size total_pose_side_TWO=0;
729 
730  while ( silent_file_stream_TWO_->has_another_pose() ) {
731  total_pose_side_TWO++;
732  core::io::silent::SilentStructOP const silent_struct( silent_file_stream_TWO_->next_struct() );
733  }
734 
735 
736  silent_file_stream_ONE_->reset();
737  silent_file_stream_TWO_->reset();
738 
739 
741 
742  while(true){
743 
744  if(total_pose_side_ONE<=(side_ONE_NUM_pose_list_*max_pose_data_list_size_) ) break;
745 
747 
748  }
749 
750 
752 
753  while(true){
754 
755  if(total_pose_side_TWO<=(side_TWO_NUM_pose_list_*max_pose_data_list_size_) ) break;
756 
758 
759  }
760 
761 
762  std::cout << "max_pose_data_list_size_= " << max_pose_data_list_size_<< std::endl;
763  std::cout << "total_pose_side_ONE= " << total_pose_side_ONE << " side_ONE_NUM_pose_list_= " << side_ONE_NUM_pose_list_<< std::endl;
764  std::cout << "total_pose_side_TWO= " << total_pose_side_TWO << " side_TWO_NUM_pose_list_= " << side_TWO_NUM_pose_list_<< std::endl;
765 
766 
767  }
768 
769  /////////////////////////////////////////////////////////////////////////////////////////////////
770  void
772 
773  silent_file_stream_ONE_->reset();
774  silent_file_stream_TWO_->reset();
775 
776  tag_to_source_map_ONE_.clear();
777  tag_to_source_map_TWO_.clear();
778 
779 
780  std::cout << "silent_file_stream_ONE_ parent_remarks" << std::endl;
781  while ( silent_file_stream_ONE_->has_another_pose() ) {
782  core::io::silent::SilentStructOP const silent_struct( silent_file_stream_ONE_->next_struct() );
783  //silent_struct->print_parent_remarks(std::cout);
784 
785  std::string const & tag( silent_struct->decoy_tag() );
786 
787  if(tag_to_source_map_TWO_.count(tag)!=0) utility_exit_with_message("tag " + tag + " already exist in tag_to_source_map_TWO_" );
788 
789  if(silent_struct->has_parent_remark("SOURCE")==false){
790  //utility_exit_with_message("silent_struct->has_parent_remark(\"SOURCE\")==false for tag: " + tag);
791  tag_to_source_map_ONE_[tag]="MISSING";
792 
793  }else{
794 
795  std::string const source_file=silent_struct->get_parent_remark("SOURCE");
796  tag_to_source_map_ONE_[tag]=source_file;
797 
798  }
799 
800  }
801  std::cout << "--------------------------------" << std::endl;
802 
803  std::cout << "silent_file_stream_TWO_ parent_remarks" << std::endl;
804  while ( silent_file_stream_TWO_->has_another_pose() ) {
805  core::io::silent::SilentStructOP const silent_struct( silent_file_stream_TWO_->next_struct() );
806  //silent_struct->print_parent_remarks(std::cout);
807 
808  std::string const & tag( silent_struct->decoy_tag() );
809 
810  if(tag_to_source_map_TWO_.count(tag)!=0) utility_exit_with_message("tag " + tag + " already exist in tag_to_source_map_TWO_" );
811 
812  if(silent_struct->has_parent_remark("SOURCE")==false){
813  //utility_exit_with_message("silent_struct->has_parent_remark(\"SOURCE\")==false for tag: " + tag);
814  tag_to_source_map_TWO_[tag]="MISSING";
815 
816  }else{
817 
818  std::string const source_file=silent_struct->get_parent_remark("SOURCE");
819  tag_to_source_map_TWO_[tag]=source_file;
820 
821  }
822 
823 
824 
825  }
826  std::cout << "--------------------------------" << std::endl;
827 
828 
829  silent_file_stream_ONE_->reset();
830  silent_file_stream_TWO_->reset();
831 
832 
833 
834  }
835 
836 
837  /////////////////////////////////////////////////////////////////////////////////////////////////
838 
839  void
841 
842  using namespace ObjexxFCL;
843 
844  if(silent_files_in_.size()!=2) utility_exit_with_message("silent_files_in_.size()!=2!, silent_files_in_.size()=" + string_of(silent_files_in_.size()) );
845 
847  silent_file_stream_ONE_->set_order_by_energy( true );
848  silent_file_stream_ONE_->set_record_source( false ); //change to false on July 29, 2011
849 
850 
851  utility::vector1< std::string > singleton_list_ONE;
852  singleton_list_ONE.push_back( silent_files_in_[1] );
853  silent_file_stream_ONE_->filenames( singleton_list_ONE ); //triggers read in of files, too.
854 
856  silent_file_stream_TWO_->set_order_by_energy( true );
857  silent_file_stream_TWO_->set_record_source( false ); //change to false on July 29, 2011
858 
859  utility::vector1< std::string > singleton_list_TWO;
860  singleton_list_TWO.push_back( silent_files_in_[2] );
861  silent_file_stream_TWO_->filenames( singleton_list_TWO ); //triggers read in of files, too.
862 
863 
864  }
865  /////////////////////////////////////////////////////////////////////////////////////////////////
866 
867 // bool
868 // StepWiseRNA_CombineLongLoopFilterer::
869  bool
871  return (tag_info_1.combine_score < tag_info_2.combine_score);
872  }
873 
874  void
875  StepWiseRNA_CombineLongLoopFilterer::sort_Combine_Tags_Info(utility::vector1< Combine_Tags_Info > & combine_tags_info_list) { //Lowest combine score on the top of the list
876  sort(combine_tags_info_list.begin(), combine_tags_info_list.end(), score_sort_citeria);
877  }
878 
879  /////////////////////////////////////////////////////////////////////////////////////////////////
880 
883 
884  if(tag_token.size()<2) utility_exit_with_message("tag_token.size()<2");
885 
886  return (tag_token[1] + "_" + tag_token[2]); //Misnomer!
887 
888  }
889 
890  bool
892 
893 
894  if(tag_token.size()>=5){ //VIRT_RIBOSE_SAMPLED tag
895 
896  //consistency check!
897  if(tag_token[3]!="sample") utility_exit_with_message("tag_token[3]!=\"sample\" for tag= " + tag);
898 
899  if(tag_token[4]!="ribose") utility_exit_with_message("tag_token[4]!=\"ribose\" for tag= " + tag);
900 
901  return true;
902 
903  }else if(tag_token.size()==2){ //standard tag
904  return false;
905  }
906 
907  utility_exit_with_message("tag_token.size()!=5 and tag_token.size()!=2 for tag= " + tag);
908  return false; //PREVENT COMPILER COMPLAINT!
909 
910  }
911 
912 
913  bool
915  std::string const & prev_tag,
916  std::map< std::string , std::string > const & tag_to_source_map) const{
917 
918 
919  utility::vector1<std::string> const curr_tag_token = Tokenize(curr_tag, "_");
920  std::string const curr_parent_tag = get_parent_tag(curr_tag_token);
921 
922  utility::vector1<std::string> const prev_tag_token = Tokenize(prev_tag, "_");
923  std::string const prev_parent_tag = get_parent_tag(prev_tag_token);
924 
925  bool const curr_tag_is_virt_sample_ribose=Is_virt_sample_ribose_tag(curr_parent_tag, curr_tag_token);
926 
927  bool const prev_tag_is_virt_sample_ribose=Is_virt_sample_ribose_tag(prev_parent_tag, prev_tag_token);
928 
929  //The parent_tag (e.g S_0) should be the same only if pose originate from the same struct before the VIRT_RIBOSE_SAMPLING!
930  if(prev_parent_tag!=curr_parent_tag) return false;
931 
932  /////More Consistency check/////
933  //If same src struct, then if one pose have the virt_ribose sampled then so must the other.
934  if(curr_tag_is_virt_sample_ribose!=prev_tag_is_virt_sample_ribose){
935  utility_exit_with_message("curr_tag_is_virt_sample_ribose!=prev_tag_is_virt_sample_ribose");
936  }
937 
938  if(tag_to_source_map.count(curr_tag)==0){
939  utility_exit_with_message("tag " + curr_tag + " doesn't exist in tag_to_source_map" );
940  }
941 
942  if(tag_to_source_map.count(prev_tag)==0){
943  utility_exit_with_message("tag " + prev_tag + " doesn't exist in tag_to_source_map" );
944  }
945 
946  std::string const curr_source_file = tag_to_source_map.find(curr_tag)->second;
947  std::string const prev_source_file = tag_to_source_map.find(prev_tag)->second;
948 
949  //if(source_file_ONE!="MISSING" && prev_source_file_ONE!="MISSING"){
950  if(curr_source_file!=prev_source_file) utility_exit_with_message("curr_source_file!=prev_source_file");
951  //}
952  ////////////////////////////
953 
954  return true;
955 
956 
957  }
958 
959 
960  /////////////////////////////////////////////////////////////////////////////////////////////////
961  void
963 
964  using namespace ObjexxFCL;
965 
966  clock_t const time_start( clock() );
967 
968  Output_title_text("Enter StepWiseRNA_CombineLongLoopFilterer:apply");
969 
970 
971  Output_boolean("parin_favorite_ouput= ", parin_favorite_output_); std::cout << std::endl;
972  Output_boolean(" combine_helical_silent_file_= ", combine_helical_silent_file_); std::cout << std::endl;
973  Output_boolean(" filter_for_previous_contact_= ", filter_for_previous_contact_); std::cout << std::endl;
974  Output_boolean(" filter_for_previous_clash_= ", filter_for_previous_clash_); std::cout << std::endl;
975  Output_boolean(" filter_for_chain_closable_= ", filter_for_chain_closable_); std::cout << std::endl;
976  Output_boolean(" filter_for_moving_res_contact_= ", filter_for_moving_res_contact_); std::cout << std::endl;
977  Output_boolean(" moving_res_to_base_contact_only_= ", moving_res_to_base_contact_only_); std::cout << std::endl;
978  std::cout << "max_decoys_(nstruct)= " << max_decoys_ << std::endl;
979 
982 
984 
985 
988 
990 
992 
994 
996 
1000  }
1001  }
1002 
1003 
1004  std::cout << "CombineLongLoopFilterer COUNTS (BEFORE FINAL SCORE SCREENING)" << std::endl;
1005  std::cout << pass_screen_struct_pair_ << " out of " << total_input_struct_pair_ << " passed screen" << std::endl;
1006 
1007 
1008  std::cout << "total_count= " << filterer_count_.total_count;
1009  std::cout << " score_cut_count= " << filterer_count_.score_cut_count;
1010  std::cout << " chain_closable= " << filterer_count_.chain_closable_screen;
1011  std::cout << " filter_for_previous_contact= " << filterer_count_.filter_for_previous_contact;
1012  std::cout << " filter_for_previous_clash= " << filterer_count_.filter_for_previous_clash;
1013  std::cout << " filter_for_moving_res_contact= " << filterer_count_.filter_for_moving_res_contact;
1014  std::cout << std::endl;
1015 
1016 
1017 
1018  std::cout << "StepWiseRNA_CombineLongLoopFilterer::apply: " << static_cast<Real>( clock() - time_start ) / CLOCKS_PER_SEC << std::endl;
1019 
1021  utility_exit_with_message(" (filterered_combine_tag_info_list_.size() ) != pass_screen_struct_pair_");
1022  }
1023 
1024  std::ofstream outfile;
1025  outfile.open(output_filename_.c_str()); //Opening the file with this command removes all prior content..
1026 
1027  Size pass_screen_struct_pair_ACT=0;
1028  Size pass_screen_struct_pair_undercount_ribose_rotamers=0;
1029 
1030 
1031  //std::cout << "best_combine_score_= " << best_combine_score_ << " score_diff_cut_= " << score_diff_cut_ << std::endl;
1032 
1033  //OK have to sort the filtererer_combine_tag_info_list.
1035 
1036  clock_t const time_start_FINAL_output( clock() );
1037 
1038  for(Size n=1; n<=filterered_combine_tag_info_list_.size(); n++){
1039 
1040  Combine_Tags_Info const combine_tag_info = filterered_combine_tag_info_list_[n];
1041 
1042  //if( (combine_tag_info.combine_score) > (best_combine_score_ + score_diff_cut_) ) continue;
1043 
1045 
1046  bool match_existing_pair=false;
1047 
1048  for(Size ii=(n-1); ii>=1; ii--){
1049 
1050  Combine_Tags_Info const prev_combine_tag_info = filterered_combine_tag_info_list_[ii];
1051 
1052  if(Is_sibling_ribose_rotamer_pose(combine_tag_info.side_one_tag, prev_combine_tag_info.side_one_tag, tag_to_source_map_ONE_)==false) continue;
1053 
1054  if(Is_sibling_ribose_rotamer_pose(combine_tag_info.side_two_tag, prev_combine_tag_info.side_two_tag, tag_to_source_map_TWO_)==false) continue;
1055 
1056  std::cout << "tag_pair: ";
1057  std::cout << "(" << std::setw(28) << std::left << combine_tag_info.side_one_tag << ",";
1058  std::cout << std::setw(28) << std::left << combine_tag_info.side_two_tag << ")" ;
1059  std::cout << " is a sibling of prev_tag_pair: ";
1060  std::cout << "(" << std::setw(28) << std::left << prev_combine_tag_info.side_one_tag << ",";
1061  std::cout << std::setw(28) << std::left << prev_combine_tag_info.side_two_tag << ")" ;
1062  std::cout << std::endl;
1063 
1064  match_existing_pair=true;
1065 
1066  break;
1067 
1068  }
1069 
1070 
1071  if(match_existing_pair==false) pass_screen_struct_pair_undercount_ribose_rotamers++;
1072 
1073  }
1074 
1075  pass_screen_struct_pair_ACT++;
1076 
1077  //new formatting, Oct 19, 2010
1078  outfile << std::setw(40) << std::left << combine_tag_info.side_one_tag; //40 spacing just to be safe!
1079  outfile << std::setw(40) << std::left << combine_tag_info.side_two_tag; //40 spacing just to be safe!
1080  outfile << std::setw(15) << std::left << combine_tag_info.combine_score;
1081  outfile << std::setw(15) << std::left << pass_screen_struct_pair_ACT;
1082  outfile << "\n";
1083 
1084  bool max_decoys_reached=false;
1085 
1087  if(pass_screen_struct_pair_undercount_ribose_rotamers>=max_decoys_) max_decoys_reached=true;
1088  }else{
1089  if(pass_screen_struct_pair_ACT>=max_decoys_) max_decoys_reached=true;
1090  }
1091 
1092  if(max_decoys_reached){
1093  std::cout <<" max_decoys_ (" << max_decoys_ << "), early break! " << std::endl;
1094  break;
1095  }
1096 
1097  }
1098 
1099  if(pass_screen_struct_pair_ACT==0){
1100  outfile << "Empty filterer_outfile. No struct_pair passed screen.\n";
1101  }
1102 
1103  outfile.flush();
1104  outfile.close();
1105 
1106  std::cout << "CombineLongLoopFilterer COUNTS (AFTER FINAL SCORE SCREENING)" << std::endl;
1107  std::cout << "pass_screen_struct_pair_ACT= " << pass_screen_struct_pair_ACT << std::endl;
1108  std::cout << "pass_screen_struct_pair_undercount_ribose_rotamers= " << pass_screen_struct_pair_undercount_ribose_rotamers << std::endl;
1109  std::cout << "StepWiseRNA_CombineLongLoopFilterer::final_output: " << static_cast<Real>( clock() - time_start_FINAL_output ) / CLOCKS_PER_SEC << std::endl;
1110  std::cout << "StepWiseRNA_CombineLongLoopFilterer::apply: " << static_cast<Real>( clock() - time_start ) / CLOCKS_PER_SEC << std::endl;
1111 
1112 
1113  Output_title_text("Exit StepWiseRNA_CombineLongLoopFilterer:apply");
1114 
1115  }
1116 }
1117 }
1118 }