Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StepWiseRNA_BaseCentroidScreener.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_BaseCentroidScreener
11 /// @brief Parameters to be passed between different modules of stepwise RNA building.
12 /// @detailed
13 /// @author Rhiju Das
14 
15 
16 //////////////////////////////////
21 #include <core/id/TorsionID.hh>
22 #include <core/kinematics/Stub.hh>
24 #include <core/pose/Pose.hh>
26 #include <basic/Tracer.hh>
28 #include <ObjexxFCL/FArray1D.hh>
29 #include <ObjexxFCL/FArray2D.hh>
30 #include <ObjexxFCL/format.hh>
31 #include <ObjexxFCL/string.functions.hh>
32 
33 #include <string>
34 
35 using namespace core;
36 using basic::T;
37 using core::Real;
38 using ObjexxFCL::fmt::F;
39 
40 static basic::Tracer TR( "protocols.swa.rna.base_centroid_screener" );
41 
42 namespace protocols {
43 namespace swa {
44 namespace rna {
45 
46  //////////////////////////////////////////////////////////////////////////////////////////
47  // Constructor
48  StepWiseRNA_BaseCentroidScreener::StepWiseRNA_BaseCentroidScreener( core::pose::Pose const & pose, StepWiseRNA_JobParametersCOP & job_parameters ):
49  job_parameters_( job_parameters ),
50  rna_centroid_info_( new core::scoring::rna::RNA_CentroidInfo ),
51  base_stack_dist_cutoff_( 6.364 ),
52  base_stack_z_offset_max_( 4.5 ),
53  base_stack_z_offset_min_( 2.5 ),
54  base_stack_axis_cutoff_( 0.707 /*Rhiju value is 0.650*/),
55  base_stack_planarity_cutoff_( 0.707 /*Rhiju value is 0.5*/),
56  base_pair_dist_min_( 5.0 ),
57  base_pair_dist_max_( 12.0 ),
58  base_pair_z_offset_cutoff_( 3.0 ),
59  base_pair_axis_cutoff_( 0.5 ),
60  base_pair_planarity_cutoff_( 0.866 ),
61  base_pair_rho_min_( 5 ),
62  base_pair_rho_max_( 10 )
63  {
64  Initialize_is_virtual_base( pose, true /*verbose*/);
65  Initialize_base_stub_list( pose, true /*verbose*/ );
67  }
68  ////////////////////////////////////////////////////////////////////////
70 
71  /////////////////////////////////////////////////////////////////////////////////////////////////////////
72  void
74 
75  Size const & nres = pose.total_residue();
76  is_virtual_base_.dimension( nres, false );
77 
78  for (Size seq_num=1; seq_num <= nres; seq_num++){
79 
80  conformation::Residue const & residue_object=pose.residue( seq_num );
81 
82  if(residue_object.has_variant_type( "VIRTUAL_RNA_RESIDUE" )){
83  std::cout << "Residue " << seq_num << " is a VIRTUAL_RNA_RESIDUE!" << std::endl;
84  is_virtual_base_( seq_num ) = true;
85  }
86 
87  if(residue_object.has_variant_type( "BULGE" )){
88  std::cout << "Residue " << seq_num << " is a BULGE!" << std::endl;
89  is_virtual_base_( seq_num ) = true;
90  }
91  }
92  }
93 
94  /////////////////////////////////////////////////////////////////////////////////////////////////////////
95  void
97 
98  ObjexxFCL::FArray1D< bool > const & partition_definition = job_parameters_->partition_definition();
99 
100  //Used to be this before March 19, 2012. Fang switched to the version below to fix a memory leak problem.
101  //bool const root_partition = partition_definition( pose.fold_tree().root() );
102 
103  //To Fang: This version is buggy since it assumes full-length pose which is not always the case!
104  //Fang modified to this version On March 18, 2012
105  //Size const moving_res = job_parameters_ -> moving_res();
106  //bool const moving_partition = partition_definition( moving_res );
107 
108  Size const working_moving_res = job_parameters_->working_moving_res();
109  utility::vector1 < core::Size > const & working_moving_partition_pos = job_parameters_->working_moving_partition_pos();
110 
111  if(working_moving_partition_pos.size()==0) utility_exit_with_message("working_moving_partition_pos.size()==0!");
112 
113  bool const moving_partition = partition_definition( working_moving_res );
114  bool const moving_partition_check = partition_definition( working_moving_partition_pos[1] );
115 
116  if(moving_partition!=moving_partition_check){
117  std::cout << "working_moving_res= " << working_moving_res << std::endl;
118  Output_seq_num_list("working_moving_partition_pos= ", job_parameters_->working_moving_partition_pos(), 40);
119  std::cout << "moving_partition= " << moving_partition << std::endl;
120  std::cout << "moving_partition_check= " << moving_partition_check << std::endl;
121  utility_exit_with_message("moving_partition!=moving_partition_check!");
122  }
123 
124  moving_residues_.clear();
125  fixed_residues_.clear();
126  base_stub_list_.clear();
127 
128 
129  Size const & nres = pose.total_residue();
130  is_moving_res_.dimension( nres, false );
131  is_fixed_res_.dimension( nres, false );
132 
133  for (Size seq_num=1; seq_num <= nres; seq_num++){
134  conformation::Residue const & residue_object=pose.residue( seq_num );
135  if (residue_object.aa()==core::chemical::aa_vrt) continue;
136  core::kinematics::Stub base_stub;
137 
138  if(is_virtual_base_( seq_num )==true){
139  base_stub=core::kinematics::Stub(); //"default" tub, this will never be called
140  }else{
141  Vector const centroid = rna_centroid_info_->get_base_centroid( residue_object);
142  base_stub = rna_centroid_info_->get_base_coordinate_system( residue_object, centroid );
143  }
144 
145  base_stub_list_.push_back( base_stub );
146 
147  if(is_virtual_base_( seq_num )==true) continue;
148 
149  if ( partition_definition( seq_num ) != moving_partition ) {
150  // This is a "fixed" residue -- on the same side of the moving suite as the root.
151  fixed_residues_.push_back( seq_num );
152  if ( verbose ) std::cout << " FIXED POSITION --> " << seq_num << std::endl;
153  is_fixed_res_( seq_num ) = true;
154  } else {
155  moving_residues_.push_back( seq_num );
156  if ( verbose ) std::cout << " MOVING POSITION --> " << seq_num << std::endl;
157  is_moving_res_( seq_num ) = true;
158  }
159  }
160 
161 
162 // moving_residues_ does not necessarily equal job_parameters_->working_moving_partition_pos since job_parameters_->working_moving_partition_pos include virtual residues. May 25, 2010
163 // if(Is_equivalent_vector(moving_residues_,job_parameters_->working_moving_partition_pos())==false){
164 // Output_seq_num_list("moving_residues_= " , moving_residues_, 50);
165 // Output_seq_num_list("job_parameters_->working_moving_partition_pos()= " , job_parameters_->working_moving_partition_pos(), 50);
166 // utility_exit_with_message( "moving_residues_,job_parameters_->working_moving_partition_pos()) ==false ");
167 // }
168 
169  }
170 
171 
172  //////////////////////////////////////////////////////////////////////////////////////////////////////
173  void
175 
176  using namespace ObjexxFCL;
177 
178 
179  terminal_res_ = job_parameters_->working_terminal_res();
180 
181  Size const & nres = pose.total_residue();
182  is_terminal_res_.dimension( nres, false );
183  stacked_on_terminal_res_in_original_pose_.dimension( nres, nres, false );
184 
185  for ( Size n = 1; n <= terminal_res_.size(); n++ ) {
186 
187  // std::cout << "NRES " << pose.total_residue() << " " << is_terminal_res_.size() << " " << terminal_res_[ n ] << std::endl;
188  Size const terminal_res = terminal_res_[ n ];
189 
190  if(is_virtual_base_( terminal_res )==true){
191  utility_exit_with_message( "working_res: " + string_of(terminal_res) + " is a terminal res but has a virtual! ");
192  }
193 
194  is_terminal_res_( terminal_res ) = true;
195 
196  for ( Size m = 1; m <= nres; m++ ) {
197 
198  // std::cout << " about to check stack: --- " << std::endl;
199  // std::cout << " TERMINAL_RES " << terminal_res << " " << is_moving_res_( terminal_res ) << " " << is_fixed_res_( terminal_res ) << std::endl;
200  // std::cout << " M " << m << " " << is_moving_res_( m ) << " " << is_fixed_res_( m ) << std::endl;
201 
202  if ( ( is_moving_res_( terminal_res ) && is_moving_res_( m ) ) ||
203  ( is_fixed_res_( terminal_res ) && is_fixed_res_( m ) ) ){
204 
205  stacked_on_terminal_res_in_original_pose_( terminal_res, m ) = check_stack_base( terminal_res, m );
206  //if ( stacked_on_terminal_res_in_original_pose_( terminal_res, m ) ) std::cout << "ALREADY STACKED: " << terminal_res << " " << m << std::endl;
207 
208  }
209  }
210  }
211 
212  }
213 
214 
215  //////////////////////////////////////////////////////////////////////////////////////////////////////
216  bool
217  StepWiseRNA_BaseCentroidScreener::check_stack_base( core::kinematics::Stub const & rebuild_residue_base_stub, core::kinematics::Stub const & base_stub , bool const verbose ) const{
218 
219  numeric::xyzVector<Real> const other_z_vector=base_stub.M.col_z();
220  numeric::xyzVector<Real> rebuild_z_vector=rebuild_residue_base_stub.M.col_z();
221 
222  numeric::xyzVector<Real> centroid_diff;
223  subtract( rebuild_residue_base_stub.v, base_stub.v, centroid_diff);
224  Real centroid_distance=centroid_diff.length();
225  if ( verbose ) std::cout << "Centroid Distance: " << centroid_distance << std::endl;
226  if(centroid_distance > base_stack_dist_cutoff_) return false;
227 
228  Real base_z_offset_one=std::abs(dot( centroid_diff, other_z_vector));
229  Real base_z_offset_two=std::abs(dot( centroid_diff, rebuild_z_vector));
230 
231  if ( verbose ) std::cout << "Base Z offset 1: " << base_z_offset_one << std::endl;
232  if ( verbose ) std::cout << "Base Z offset 2: " << base_z_offset_two << std::endl;
233 
234  if ( (base_z_offset_one > base_stack_z_offset_max_ || base_z_offset_one < base_stack_z_offset_min_) &&
235  (base_z_offset_two > base_stack_z_offset_max_ || base_z_offset_two < base_stack_z_offset_min_)) return false;
236 
237  Real base_axis_one=base_z_offset_one/centroid_distance;
238  Real base_axis_two=base_z_offset_two/centroid_distance;
239 
240  if ( verbose ) std::cout << "Base Axis 1: " << base_axis_one << std::endl;
241  if ( verbose ) std::cout << "Base Axis 2: " << base_axis_two << std::endl;
242 
243  if ( base_axis_one < base_stack_axis_cutoff_ && base_axis_two < base_stack_axis_cutoff_) return false;
244 
245  Real base_planarity = std::abs(dot( other_z_vector, rebuild_z_vector));
246 
247  if ( verbose ) std::cout << "Base planarity: " << base_planarity << std::endl;
248 
249  if (base_planarity < base_stack_planarity_cutoff_ ) return false;
250 
251  return true;
252  }
253 
254  //////////////////////////////////////////////////////////////////////////////////////////////////////////
255  bool
256  StepWiseRNA_BaseCentroidScreener::check_base_pairing( core::kinematics::Stub const & rebuild_residue_base_stub, core::kinematics::Stub const & base_stub ) const{
257 
258  numeric::xyzVector<Real> const other_z_vector = base_stub.M.col_z();
259  numeric::xyzVector<Real> rebuild_z_vector = rebuild_residue_base_stub.M.col_z();
260 
261  numeric::xyzVector<Real> centroid_diff;
262  subtract( rebuild_residue_base_stub.v, base_stub.v, centroid_diff);
263 
264  Real centroid_distance=centroid_diff.length();
265  if(centroid_distance < base_pair_dist_min_ || centroid_distance > base_pair_dist_max_ ) return false;
266 
267  Real base_z_offset_one=std::abs(dot( centroid_diff, other_z_vector));
268  Real base_z_offset_two=std::abs(dot( centroid_diff, rebuild_z_vector));
269 
270  if( base_z_offset_one> base_pair_z_offset_cutoff_ && base_z_offset_two > base_pair_z_offset_cutoff_ ) return false;
271 
272  Real base_axis_one=base_z_offset_one/centroid_distance;
273  Real base_axis_two=base_z_offset_two/centroid_distance;
274  if ( base_axis_one> base_pair_axis_cutoff_ && base_axis_two> base_pair_axis_cutoff_) return false; //This is a stronger condition compare to baze_z_offset check
275 
276  Real base_planarity=std::abs(dot( rebuild_z_vector, other_z_vector));
277  if ( base_planarity < base_pair_planarity_cutoff_ ) return false;
278 
279  numeric::xyzVector<Real> centroid_diff_parallel_one=dot( centroid_diff, other_z_vector)*other_z_vector;
280  numeric::xyzVector<Real> centroid_diff_perpendicular_one= centroid_diff-centroid_diff_parallel_one;
281  Real rho_one=centroid_diff_perpendicular_one.length();
282  numeric::xyzVector<Real> centroid_diff_parallel_two=dot( centroid_diff, rebuild_z_vector)*rebuild_z_vector;
283  numeric::xyzVector<Real> centroid_diff_perpendicular_two= centroid_diff-centroid_diff_parallel_two;
284  Real rho_two=centroid_diff_perpendicular_two.length();
285 
286  if ( (rho_one<base_pair_rho_min_ || rho_one>base_pair_rho_max_) &&
287  (rho_two<base_pair_rho_min_ || rho_two>base_pair_rho_max_) ) return false;
288 
289  //If reach this point means success!
290  return true;
291  }
292 
293 
294  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
295  bool
297  Update_base_stub_list( pose );
298  return Check_centroid_interaction(count_data);
299  }
300 
301 
302  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
303  void
305 
306  for ( Size m = 1; m <= moving_residues_.size(); m++ ) {
307 
308  Size const moving_res( moving_residues_[ m ] );
309 
310  core::conformation::Residue const & residue_object( pose.residue( moving_res ) );
311 
312  Vector const centroid = rna_centroid_info_->get_base_centroid( residue_object);
313  core::kinematics::Stub base_stub = rna_centroid_info_->get_base_coordinate_system( residue_object, centroid );
314  base_stub_list_[ moving_res ] = base_stub;
315 
316  }
317 
318  }
319 
320 
321  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
322  bool
324 
325  bool stack_base( false ), base_pairing( false );
326 
327  for ( Size m = 1; m <= moving_residues_.size(); m++ ) {
328 
329  core::kinematics::Stub const & rebuild_residue_base_stub = base_stub_list_[ moving_residues_[ m ] ];
330  stack_base = false;
331 
332  for(Size i = 1; i <= fixed_residues_.size(); i++){
333  stack_base = check_stack_base( rebuild_residue_base_stub, base_stub_list_[ fixed_residues_[ i ] ] );
334  if ( stack_base ) break;
335  }
336 
337  base_pairing=false;
338 
339  for(Size i = 1; i <= fixed_residues_.size(); i++ ) {
340  base_pairing = check_base_pairing( rebuild_residue_base_stub, base_stub_list_[ fixed_residues_[ i ] ] );
341  if ( base_pairing ) break;
342  }
343 
344  if ( base_pairing || stack_base) break; // found an interaction!
345 
346  }
347 
348  if(base_pairing) count_data.base_pairing_count++;
349  if(stack_base) count_data.base_stack_count++;
350  if(base_pairing || stack_base) count_data.pass_base_centroid_screen++;
351 
352  // if ( stack_base ) count_data_.base_stack_count++;
353  // if ( base_pairing ) count_data_.base_pairing_count++;
354 
355  if ( !base_pairing && !stack_base ) return false;
356 
357 
358  // std::cout << " BASE_PAIRING " << base_pairing << " BASE_STACKING " << stack_base << std::endl;
359  return true;
360 
361  }
362 
363  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
364  bool
366  if ( reinitialize ) {
368  } else {
369  Update_base_stub_list( pose );
370  }
371  bool const passed = Check_that_terminal_res_are_unstacked( false /*verbose*/ );
372  return passed;
373  }
374 
375 
376  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
377  bool
378  StepWiseRNA_BaseCentroidScreener::check_stack_base( Size const & pos1, Size const & pos2, bool const verbose /* = false */ ) {
379 
380  if(is_virtual_base_( pos1 )== true || is_virtual_base_( pos2 )== true){
381  utility_exit_with_message( "is_virtual_base_( pos1 )== true || is_virtual_base_( pos2 )== true !");
382  }
383 
384  if ( pos1 == pos2 ) return true;
385  return check_stack_base( base_stub_list_[ pos1 ], base_stub_list_[ pos2 ], verbose );
386 
387  }
388 
389  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
390  bool
392 
393  // bool stack_base( false );//, base_pairing( false );
394 
395  // Look through all terminal_res
396  for ( Size i = 1; i <= terminal_res_.size(); i++ ) {
397  Size const & terminal_res = terminal_res_[ i ];
398 
399  for ( Size m = 1; m <= moving_residues_.size(); m++ ) {
400  Size const & moving_res = moving_residues_[ m ];
401  if (verbose) std::cout << "about to check stack: " << terminal_res << " " << moving_res << " " << stacked_on_terminal_res_in_original_pose_( terminal_res, moving_res ) << std::endl;
402  if ( !stacked_on_terminal_res_in_original_pose_( terminal_res, moving_res ) &&
403  check_stack_base( terminal_res, moving_res, verbose ) ) return false;
404  }
405 
406  for ( Size m = 1; m <= fixed_residues_.size(); m++ ) {
407  Size const & fixed_res = fixed_residues_[ m ];
408  if (verbose) std::cout << "about to check stack: " << terminal_res << " " << fixed_res << " " << stacked_on_terminal_res_in_original_pose_( terminal_res, fixed_res ) << std::endl;
409  if ( !stacked_on_terminal_res_in_original_pose_( terminal_res, fixed_res ) &&
410  check_stack_base( terminal_res, fixed_res, verbose ) ) return false;
411  }
412 
413  }
414 
415  return true;
416 
417  }
418 
419 
420 }
421 }
422 }