Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StepWiseRNA_OutputData.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_OutputData.cc (Created on Sept 26, 2011)
11 /// @brief Output silent_file_data functions for Stepwise Assembly RNA.
12 /// @detailed
13 /// @author Parin Sripakdeevong
14 
15 
16 //////////////////////////////////
17 #include <protocols/swa/rna/StepWiseRNA_OutputData.hh> //Oct 22, 2011...Not sure why the code worked without this!
23 
24 
28 
29 #include <core/scoring/ScoreType.hh> //Parin Sept 20, 2011.
30 //////////////////////////////////
31 
32 #include <core/types.hh>
34 #include <core/chemical/util.hh>
40 #include <core/pose/Pose.hh>
41 #include <core/io/pdb/pose_io.hh>
59 
60 #include <ObjexxFCL/FArray1D.hh>
61 #include <ObjexxFCL/FArray2D.hh>
62 
63 #include <numeric/conversions.hh>
64 #include <numeric/NumericTraits.hh>
65 
66 #include <iostream>
67 #include <fstream>
68 #include <sstream>
69 #include <ObjexxFCL/format.hh>
70 #include <set>
71 #include <time.h>
72 #include <map>
73 
74 #include <stdio.h> //Sept 26, 2011
75 
76 //for process_mem_usage:
77 #include <ios>
78 
79 
80 using namespace core;
81 
82 namespace protocols {
83 namespace swa {
84 namespace rna {
85 
86 
87 
88  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
89 
91  get_binary_rna_silent_struct_safe(pose::Pose const & const_pose, std::string const & tag, std::string const & silent_file){
92 
93  using namespace core::io::silent;
94  using namespace core::scoring;
95  using namespace core::pose;
96  using namespace core::chemical;
97  using namespace core::conformation;
98 
99 
100  std::string const debug_silent_file=silent_file+"_CONVERSION_DEBUG";
101  std::string const debug_tag=tag+"_CONVERSION_DEBUG";
102  const Real RADS_PER_DEG = numeric::NumericTraits<Real>::pi() / 180.;
103 
104  SilentFileData silent_file_data;
105 
107  residue_type_set( core::chemical::RNA );
108 
109  Size NUM_trails=10;
110  Real const local_angle_bin_size=20;
111  Real const local_z_bin_size=0.05;
112 
113  pose::Pose first_trail_pose_from_silent_file;
114  pose::Pose first_trail_pose;
115 
116 
117 
118  for(Size trail_num=1; trail_num<=NUM_trails; trail_num++){ //Found that just rigid problem rotation of the pose solves the silent_file conversion problem
119 
120  pose::Pose pose=const_pose;
121 
122  if(trail_num!=1){
123 
124  ///////////////////////////get centoid of the structure/////////////////////////////
125 
126  numeric::xyzVector<core::Real> centroid=Vector( 0.0, 0.0, 0.0 );
127  Size numatoms = 0;
128 
129  for(Size seq_num=1; seq_num<=pose.total_residue(); seq_num++){
130 
131  conformation::Residue const & rsd(pose.residue(seq_num));
132 
133  for( Size at = 1; at <= rsd.natoms(); at++){
134 
135  if(rsd.is_virtual(at)) continue;
136 
137  centroid += rsd.xyz(at);
138  numatoms++;
139  }
140  }
141 
142  if(numatoms==0) utility_exit_with_message("numatoms==0");
143 
144  centroid = centroid/numatoms;
145 
146  ////////////////////////////////////////////////////////////////////////////////
147 
148 
149  Euler_angles euler_angles;
150 
151  Matrix rotation_matrix;
152 
153  euler_angles.alpha=(0.25*trail_num)*local_angle_bin_size*(RADS_PER_DEG);
154  euler_angles.gamma=(0.25*trail_num)*local_angle_bin_size*(RADS_PER_DEG);
155 
156  euler_angles.z=(0.25*trail_num)*local_z_bin_size; //MAKE SURE THIS DOESN'T GET OUT OF BOUND!
157  euler_angles.beta=acos(euler_angles.z);
158 
159  convert_euler_to_coordinate_matrix(euler_angles, rotation_matrix);
160 
161  //numeric::xyzVector<core::Real> const offset_vector=Vector( 0.0, 0.0, 1.0*(trail_num-1) );
162 
163  for(Size seq_num=1; seq_num<=pose.total_residue(); seq_num++){
164 
165  conformation::Residue const & rsd(pose.residue(seq_num));
166 
167  for( Size at = 1; at <= rsd.natoms(); at++){
168 
169  id::AtomID const id( at, seq_num);
170 
171  pose.set_xyz( id, pose.xyz( id) - centroid ); //This should minimize the error introoduced by the right body rotation!
172  pose.set_xyz( id, rotation_matrix * pose.xyz(id));
173  }
174  }
175  }
176 
177  BinaryRNASilentStruct DEBUG_silent_struct( pose, debug_tag );
178  BinaryRNASilentStruct const silent_struct( pose, tag );
179 
180  if(file_exists(debug_silent_file)) remove_file(debug_silent_file);
181 
182  silent_file_data.write_silent_struct(DEBUG_silent_struct, debug_silent_file, false);
183 
184  ///////////////////////////////////////////////////////////////////////////////
185 
186  core::io::silent::SilentFileData import_silent_file_data;
187  import_silent_file_data.read_file( debug_silent_file );
188  pose::Pose pose_from_silent_file;
189 
190  bool found_tag= false;
191  Size num_struct=0;
192 
193  for ( core::io::silent::SilentFileData::iterator iter = import_silent_file_data.begin(), end = import_silent_file_data.end(); iter != end; ++iter ){
194  num_struct+=1;
195  if ( iter->decoy_tag() != debug_tag ) continue;
196  found_tag = true;
197  iter->fill_pose( pose_from_silent_file, *rsd_set );
198  }
199 
200  if(num_struct!=1) utility_exit_with_message( "num_struct=("+string_of(num_struct)+")!=1");
201  if(found_tag==false ) utility_exit_with_message( "Could not find specified tag (" + debug_tag + ") in silent file (" + debug_silent_file + ")!" );
202 
203  if(file_exists(debug_silent_file)==false){
204  utility_exit_with_message("debug_silent_file ("+debug_silent_file+") SHOULD exist!");
205  }
206 
207  remove_file(debug_silent_file);
208 
209  if(trail_num==1){
210  first_trail_pose_from_silent_file=pose_from_silent_file;
211  first_trail_pose=pose;
212  }
213 
214  //pose.dump_pdb( "SILENT_FILE_CONVERSION_TEST_" + tag +"_TRAIL_" + lead_zero_string_of(trail_num, 3) + ".pdb" );
215  //pose_from_silent_file.dump_pdb( "IMPORTED_SILENT_FILE_CONVERSION_TEST_" + tag +"_TRAIL_" + lead_zero_string_of(trail_num, 3) + ".pdb" );
216 
217  if(check_for_messed_up_structure(pose_from_silent_file, debug_tag)==false){
218  return silent_struct;
219 
220  }else{
221  std::cout << "WARNING: Problem with writing pose (" << debug_tag << ") to silent_file [Attempt #" << trail_num << "]" << std::endl;
222  }
223 
224  }
225 
226 
227  first_trail_pose_from_silent_file.dump_pdb( "SILENT_FILE_CONVERSION_PROBLEM_" + tag + "_pose_from_silent_file.pdb" );
228  first_trail_pose.dump_pdb( "SILENT_FILE_CONVERSION_PROBLEM_" + tag + ".pdb" );
229  BinaryRNASilentStruct ERROR_silent_struct( first_trail_pose, debug_tag );
230  std::string const ERROR_silent_file="SILENT_FILE_CONVERSION_PROBLEM_" + tag + ".out";
231  silent_file_data.write_silent_struct(ERROR_silent_struct, ERROR_silent_file, false);
232 
233  utility_exit_with_message("Fail to write pose (" + debug_tag + ") to silent_file after "+string_of(NUM_trails)+" trails ");
234 
235  ////////////This is just to prevent compiler WARNING MESSAGES/////////
236  BinaryRNASilentStruct EMPTY_silent_struct;
237  return EMPTY_silent_struct;
238  //////////////////////////////////////////////////////////////////////
239 
240  }
241 
242 
243  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
244 
246  get_binary_rna_silent_struct_safe_wrapper(pose::Pose const & const_pose, std::string const & tag, std::string const & silent_file, bool const write_score_only){
247 
248  using namespace core::io::silent;
249  using namespace core::scoring;
250  using namespace core::pose;
251 
252  if(write_score_only){
253 
254  BinaryRNASilentStruct s( const_pose, tag ); //If write score only, don't have to safe about pose to silent_struct conversion!
255  return s;
256 
257  }else{
258 
259  return (get_binary_rna_silent_struct_safe( const_pose, tag, silent_file));
260 
261  }
262 
263  ////////////This is just to prevent compiler WARNING MESSAGES/////////
264  BinaryRNASilentStruct EMPTY_silent_struct;
265  return EMPTY_silent_struct;
266  //////////////////////////////////////////////////////////////////////
267 
268  }
269 
270  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
271  //Accept the job_parameter instead.
272  void
273  Output_data(core::io::silent::SilentFileData& silent_file_data, std::string const & silent_file, std::string const & tag, bool const write_score_only, pose::Pose const & pose, core::pose::PoseCOP native_poseCOP, StepWiseRNA_JobParametersCOP job_parameters_){
274 
275  using namespace core::io::silent;
276  using namespace core::scoring;
277  using namespace core::pose;
278 
279  utility::vector1 < core::Size > const & rmsd_res_list = job_parameters_->rmsd_res_list();
280  std::map< core::Size, core::Size > const & full_to_sub = job_parameters_->const_full_to_sub();
281  std::map< core::Size, bool > const & Is_prepend_map = job_parameters_->Is_prepend_map();
282  bool const Is_prepend( job_parameters_->Is_prepend() ); // if true, moving_suite+1 is fixed. Otherwise, moving_suite is fixed.
283  Size const moving_base_residue( job_parameters_->actually_moving_res() );
284 
285  BinaryRNASilentStruct s=get_binary_rna_silent_struct_safe_wrapper( pose, tag, silent_file, write_score_only);
286 
287  //s.print_header( std::cout );
288  //s.precision(5); REALLY COOL. SET higher precision so that their is no energy rank ambiguity!.
289 
290  bool const output_extra_RMSDs=job_parameters_->output_extra_RMSDs();
291 
292  if ( native_poseCOP ){
293 
294  if(write_score_only){ //Basically the optimal alignment, align working_res as well if it is part of the alignment res list.
295 
296  s.add_energy( "all_rms", rms_at_corresponding_heavy_atoms( pose, *native_poseCOP ) );
297 
298  // This assumes that pose and native_pose are correctly syperimposed.
299  // I added a function in Pose_Setup to make sure this happens. Parin Jan 28, 2010
300 
301  s.add_energy( "rmsd", suite_rmsd( pose, *native_poseCOP, moving_base_residue, Is_prepend, false));
302  s.add_energy( "loop_rmsd", rmsd_over_residue_list( pose, *native_poseCOP, rmsd_res_list, full_to_sub, Is_prepend_map, false, false) );
303 
304  s.add_energy( "V_rms", suite_rmsd( pose, *native_poseCOP, moving_base_residue, Is_prepend, true));
305  s.add_energy( "V_loop_rms", rmsd_over_residue_list( pose, *native_poseCOP, rmsd_res_list, full_to_sub, Is_prepend_map, false, true) );
306 
307  if(job_parameters_->gap_size()==0){
308  s.add_energy( "PBP_rmsd", phosphate_base_phosphate_rmsd( pose, *native_poseCOP, moving_base_residue, false));
309  }else{
310  s.add_energy( "PBP_rmsd", 0.0);
311  }
312 
313  }else{
314 
315  utility::vector1< core::Size > const & working_native_alignment = job_parameters_->working_native_alignment();
316  utility::vector1< core::Size > const & working_best_alignment = job_parameters_->working_best_alignment();
317 
318  if(output_extra_RMSDs){
319 
320  s.add_energy( "all_rms", rms_at_corresponding_heavy_atoms( pose, *native_poseCOP ) );
321 
322  pose::Pose current_pose=pose; //hard copy, computationally expensive
323 
324  if(working_native_alignment.size()!=0){ //user specify which residue to align with native.
325  align_poses(current_pose, tag, *native_poseCOP, "native", working_native_alignment);
326  }else{ //default
327  align_poses(current_pose, tag, *native_poseCOP, "native", working_best_alignment);
328  }
329  s.add_energy( "O_rmsd", suite_rmsd( current_pose, *native_poseCOP, moving_base_residue, Is_prepend, false));
330  s.add_energy( "O_loop_rmsd", rmsd_over_residue_list( current_pose, *native_poseCOP, rmsd_res_list, full_to_sub, Is_prepend_map, false, false) );
331 
332  s.add_energy( "O_V_rms", suite_rmsd( current_pose, *native_poseCOP, moving_base_residue, Is_prepend, true));
333  s.add_energy( "O_V_loop_rms", rmsd_over_residue_list( current_pose, *native_poseCOP, rmsd_res_list, full_to_sub, Is_prepend_map, false, true) );
334 
335  if(job_parameters_->gap_size()==0){
336  s.add_energy( "O_PBP_rmsd", phosphate_base_phosphate_rmsd( current_pose, *native_poseCOP, moving_base_residue, false));
337  }else{
338  s.add_energy( "O_PBP_rmsd", 0.0);
339  }
340  }
341 
342  ////////Simple loop RMSD exclude only virtual atoms in native_pdb (mostly just the native virtual_res)//////////////
343  core::pose::Pose curr_pose_no_variants=pose;
344  remove_all_variant_types(curr_pose_no_variants); //This remove all virtual_atoms!
345 
346  if(working_native_alignment.size()!=0){ //user specify which residue to align with native.
347  align_poses(curr_pose_no_variants, tag +"_no_variants", (*native_poseCOP), "native", working_native_alignment);
348  }else{ //default
349  align_poses(curr_pose_no_variants, tag +"_no_variants", (*native_poseCOP), "native", working_best_alignment);
350  }
351 
352  s.add_energy( "NAT_rmsd", rmsd_over_residue_list( curr_pose_no_variants, *native_poseCOP, rmsd_res_list, full_to_sub, Is_prepend_map, false /*verbose*/, true /*ignore_virtual_atom*/) );
353 
354  }
355  }
356 
357 
358  silent_file_data.write_silent_struct(s, silent_file, write_score_only);
359 
360  }
361 
362 }
363 }
364 }