Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CoarseRNA_Fragments.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 relax_protocols
11 /// @brief protocols that are specific to RNA_Fragments
12 /// @detailed
13 /// @author Rhiju Das
14 
15 
23 #include <core/id/AtomID.hh>
24 // AUTO-REMOVED #include <core/io/pdb/pose_io.hh>
27 // AUTO-REMOVED #include <core/scoring/rna/RNA_Util.hh>
28 #include <core/pose/Pose.hh>
29 #include <core/pose/MiniPose.hh>
30 #include <core/pose/util.hh>
31 
32 // ObjexxFCL Headers
33 #include <ObjexxFCL/FArray1D.hh>
34 // AUTO-REMOVED #include <ObjexxFCL/FArray3D.hh>
35 
36 #include <core/types.hh>
37 #include <basic/Tracer.hh>
38 
39 #include <numeric/random/random.hh>
40 #include <numeric/xyzVector.hh>
41 
42 // External library headers
43 
44 
45 //C++ headers
46 #include <vector>
47 #include <string>
48 #include <sstream>
49 
50 //Auto Headers
51 #include <utility/vector1.hh>
52 #include <utility/io/izstream.hh>
53 
54 
55 using namespace core;
56 using basic::T;
57 
58 static basic::Tracer TR( "protocols.coarse_rna.coarse_rna_fragment_mover" ) ;
59 
60 static numeric::random::RandomGenerator RG(22811440); // <- Magic number, do not change it!
61 
62 namespace protocols {
63 namespace coarse_rna {
64 
65 SourcePositions::~SourcePositions() {}
66 
67 CoarseRNA_Fragments::~CoarseRNA_Fragments() {}
68 
69  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
70  // This sort of repeats a lot of stuff in protocols/rna/RNA_Fragments
71  //
72  // Not quite sure whether we should unify, or make subclasses of a Fragments class...
73  //
74  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
75  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
76  CoarseRNA_Fragments::CoarseRNA_Fragments( std::string const & frag_source_file ):
77  RNA_Fragments(),
78  frag_source_file_( frag_source_file )
79  {
81  }
82 
83  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
84  void
86 
87  using namespace core::chemical;
88  using namespace core::pose;
89  using namespace core::kinematics;
90 
91  ResidueTypeSetCAP rsd_set( ChemicalManager::get_instance()->residue_type_set( "coarse_rna" ) );
92 
93  if ( frag_source_file_.substr( frag_source_file_.size()-4, frag_source_file_.size() ) == ".pdb" ){
94  Pose pose;
98  frag_source_pose_ = new MiniPose( pose );
99  } else {
100 
101  // Figure out correspondence: P,S,CEN,X,Y --> 1,2,3,4,5. Hopefully!
102  ResidueTypeCOPs const & rsd_types( rsd_set->aa_map( na_rad ) );
103  ResidueTypeCOP const & rsd_type = rsd_types[ 1 ]; //This better work.
104  for( Size i = 1; i <= rsd_type->natoms(); i++ ){
105  coarse_rna_name_to_num_[ rsd_type->atom_name( i ) ] = i;
106  }
107 
108  std::string line;
109  char dummy_char;
110  Real x,y,z;
111  std::string sequence = "";
114  utility::io::izstream coords_in( frag_source_file_.c_str() );
115  while ( getline( coords_in, line) ){
116 
117  std::istringstream line_stream( line );
118  line_stream >> dummy_char;
119  sequence += dummy_char;
120 
121  line_stream >> dummy_char;
122  frag_source_secstruct_ += dummy_char;
123 
125  while ( line_stream.good() ) {
126  line_stream >> x >> y >> z;
127  res_coords.push_back( Vector( x,y,z) );
128  }
129  if ( res_coords.size() != coarse_rna_name_to_num_.size() ) utility_exit_with_message( "Should only have 5? atoms in mini ppose file.");
130  all_res_coords.push_back( res_coords );
131  }
132 
133  // std::cout << "SIZE ! " << all_res_coords.size() << std::endl;
134  // std::cout << "SEQUENCE ! " << sequence << std::endl;
135  // std::cout << "SECSTRUCT! " << frag_source_secstruct_ << std::endl;
136  frag_source_pose_ = new MiniPose( all_res_coords, FoldTree( all_res_coords.size() ), sequence );
137 
138  }
139 
140  }
141 
142  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
143  void
145  core::pose::Pose & pose,
146  Size const & insert_res,
147  Size const & source_res,
148  Size const & frag_size,
149  protocols::toolbox::AllowInsertOP allow_insert ){
150 
151  using namespace core::id;
152 
153  std::map< Size, Size > res_map;
154 
155  for ( Size offset = 0; offset < frag_size; offset ++ ) {
156 
157  Size const insert_offset = insert_res + offset;
158  Size const source_offset = source_res + offset;
159 
160  if ( (insert_offset) > pose.total_residue() ) continue;
161  if ( (source_offset) > frag_source_pose_->total_residue() ) continue;
162 
163  res_map[ insert_offset ] = source_offset;
164 
165  }
166  // std::cout << std::endl;
167 
168  std::map< AtomID, AtomID > atom_id_map;
169  allow_insert->calculate_atom_id_map( pose, res_map, frag_source_pose_->fold_tree(), atom_id_map );
170  copy_dofs( pose, *frag_source_pose_, atom_id_map, allow_insert->calculate_atom_id_domain_map( pose ) );
171 
172  }
173 
174  ///////////////////////////////////////////////////////////////////////////////////////
175  void
177 
178  using namespace protocols::rna;
179 
180  SourcePositionsOP source_positions = new SourcePositions;
181 
182  std::string const RNA_string = key.first;
183  std::string const RNA_secstruct_string = key.second;
184 
185  Size const size = RNA_string.length();
186  static Distance const DIST_CUTOFF( 10.0 ); /*distance of S to next P*/
187 
188  runtime_assert( RNA_string.length() == RNA_secstruct_string.length() );
189 
190  // dummy initialization.
191  std::string vall_current_sequence ( RNA_string );
192  std::string vall_current_secstruct( RNA_secstruct_string );
193 
194  std::string const & source_secstruct( frag_source_secstruct_ );
195  std::string const & source_sequence( frag_source_pose_->sequence() );
196 
197  for (Size i = 1; i <= source_sequence.size() - size + 1; i++ ){
198 
199  bool match( true );
200 
201  for (Size offset = 0; offset < size; offset++ ){
202  vall_current_sequence [offset] = source_sequence[ i - 1 + offset ];
203  vall_current_secstruct[offset] = source_secstruct[ i - 1 + offset ];
204 
205  if (
206  !compare_RNA_char( vall_current_sequence[offset], RNA_string[ offset ] ) ||
207  !compare_RNA_secstruct( vall_current_secstruct[offset], RNA_secstruct_string[ offset ] ) ) {
208  match = false;
209  break;
210  }
211  // check for chainbreak
212  if ( offset > 1 &&
213  ( ( frag_source_pose_->xyz( id::AtomID( 2, i+offset-1 ) ) -
214  frag_source_pose_->xyz( id::AtomID( 1, i+offset ) ) ).length() > DIST_CUTOFF ) ) continue;
215 
216  }
217 
218  if (match) {
219  source_positions->push_back( i );
220  }
221 
222  }
223 
224  std::cout << "Picked Fragment Library for sequence " << RNA_string << " " <<
225  " and sec. struct " << RNA_secstruct_string << " ... found " <<
226  source_positions->size() << " potential fragments" << std::endl;
227 
228  source_positions_map_[ key ] = source_positions;
229 
230  }
231 
232  ///////////////////////////////////////////////////////////////////////////////////////
233  Size
235  std::string const RNA_string,
236  std::string const RNA_secstruct_string,
237  Size const type ){
238 
239  std::string const RNA_string_local = protocols::rna::convert_based_on_match_type( RNA_string, type );
240 
241  SequenceSecStructPair const key( std::make_pair( RNA_string_local, RNA_secstruct_string ) );
242 
243  if (! source_positions_map_.count( key ) ){
244  find_source_positions( key );
245  }
246 
247  SourcePositionsOP source_positions = source_positions_map_[ key ];
248 
249  Size const num_frags = source_positions->size();
250 
251  if (num_frags == 0) { //trouble.
252  std::cout << "Fragment Library: zero fragments found for " << RNA_string_local << std::endl;
253  std::cerr << "Fragment Library: zero fragments found for " << RNA_string_local << std::endl;
254  utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
255  }
256 
257  Size const which_frag = static_cast <Size> ( RG.uniform() * num_frags) + 1;
258 
259  return (*source_positions)[ which_frag ];
260 
261  }
262 
263  ///////////////////////////////////////////////////////////////////////////////////////
264  ///////////////////////////////////////////////////////////////////////////////////////
265  Size
267  core::pose::Pose & pose,
268  Size const position,
269  Size const size,
270  Size const type ){
271 
272  std::string const & RNA_sequence( pose.sequence() );
273  std::string const & RNA_string = RNA_sequence.substr( position - 1, size );
274 
275  std::string const & RNA_secstruct( protocols::rna::get_rna_secstruct( pose ) );
276  std::string const & RNA_secstruct_string = RNA_secstruct.substr( position - 1, size );
277 
278  return pick_random_fragment( RNA_string, RNA_secstruct_string, type );
279 
280  }
281 
282  ////////////////////////////////////////////////////////////////////////////////////////
283  void
285  core::pose::Pose & pose,
286  core::Size const position,
287  core::Size const size,
288  core::Size const type,
289  protocols::toolbox::AllowInsertOP allow_insert )
290  {
291  Size const source_res = pick_random_fragment( pose, position, size, type );
292  // std::cout << "applying to fragment position " << position << " from source position " << source_res << std::endl;
293  insert_fragment( pose, position, source_res, size, allow_insert );
294  }
295 
296  ////////////////////////////////////////////////////////////////////////////////////////
297  bool
299 
300 
301 
302 
303 } // namespace rna
304 } // namespace protocols