Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CoarseRNA_DeNovoProtocol.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 RNA de novo fragment assembly
11 /// @brief protocols that are specific to CoarseRNA_DeNovoProtocol
12 /// @detailed
13 /// @author Rhiju Das
14 
15 
16 // Unit headers
18 
19 // Package headers
21 
22 // Project headers
34 // AUTO-REMOVED #include <core/chemical/ChemicalManager.hh>
35 // AUTO-REMOVED #include <core/conformation/Residue.hh>
36 #include <core/scoring/rms_util.hh>
41 // AUTO-REMOVED #include <core/scoring/rna/RNA_Util.hh>
42 #include <core/id/AtomID.hh>
43 #include <core/id/DOF_ID.hh>
44 #include <core/pose/Pose.hh>
45 // AUTO-REMOVED #include <core/pose/util.hh>
46 #include <basic/database/open.hh>
47 // AUTO-REMOVED #include <core/io/silent/RNA_SilentStruct.hh>
50 #include <core/io/pdb/pose_io.hh>
53 
54 #include <utility/file/file_sys_util.hh>
55 // AUTO-REMOVED #include <time.h>
56 
57 #include <core/types.hh>
58 #include <basic/Tracer.hh>
59 
60 #include <numeric/random/random.hh>
61 // AUTO-REMOVED #include <numeric/conversions.hh>
62 
63 // External library headers
64 
65 //C++ headers
66 #include <vector>
67 #include <list>
68 #include <string>
69 #include <sstream>
70 #include <fstream>
71 #ifdef WIN32
72 #include <ctime>
73 #endif
74 
75 //Auto Headers
76 #include <utility/vector1.hh>
77 #include <ObjexxFCL/format.hh>
78 
79 using namespace ObjexxFCL::fmt; // AUTO USING NS
80 
81 //////////////////////////////////////////////////////////////////////////////////////
82 //////////////////////////////////////////////////////////////////////////////////////
83 //////////////////////////////////////////////////////////////////////////////////////
84 // This was originally meant to be separate from RNA_DeNovoProtocol, but its
85 // basically converging -- might be a good idea to unify the two classes in the
86 // near future -- Rhiju, March 2010.
87 //////////////////////////////////////////////////////////////////////////////////////
88 //////////////////////////////////////////////////////////////////////////////////////
89 //////////////////////////////////////////////////////////////////////////////////////
90 
91 using namespace core;
92 using basic::T;
93 
94 namespace protocols {
95 namespace coarse_rna {
96 
97 static numeric::random::RandomGenerator RG(129920); // <- Magic number, do not change it!
98 
99 static basic::Tracer TR( "protocols.coarse_rna.coarse_rna_denovo_protocol" ) ;
100 
101 CoarseRNA_DeNovoProtocol::CoarseRNA_DeNovoProtocol(
102  Size const nstruct,
103  Size const monte_carlo_cycles,
104  std::string const silent_file ):
105  Mover(),
106  nstruct_( nstruct ),
107  monte_carlo_cycles_( monte_carlo_cycles ),
108  rounds_( 10 ),
109  silent_file_( silent_file ),
110  freeze_domains_( false ),
111  dump_pdb_( false ),
112  domain_move_frequency_( 0.0 ),
113  m_Temperature_( 5.0 ),
114  sim_anneal_( true ),
115  staged_constraints_( false ),
116  frag_size_( 0 ),
117  rna_params_file_( "" ),
118  rna_data_file_( "" ),
119  all_rna_fragments_file_( basic::database::full_name("1jj2_coarse_coords.txt") ),
120  jump_library_file_( basic::database::full_name("chemical/rna/1jj2_coarse_jumps.dat" ) ),
121  lores_scorefxn_( "coarse_rna.wts" ),
122  rna_structure_parameters_( new protocols::rna::RNA_StructureParameters ),
123  rna_data_reader_( new protocols::rna::RNA_DataReader ),
124  rna_loop_closer_( new protocols::coarse_rna::CoarseRNA_LoopCloser ),
125  close_loops_( false ),
126  choose_best_solution_( false ),
127  force_ideal_chainbreak_( false ),
128  add_base_pair_constraints_( true ),
129  view_monte_carlo_( false )
130 {
131  Mover::type("CoarseRNA_DeNovoProtocol");
132 }
133 
134 /// @brief Clone this object
136  return new CoarseRNA_DeNovoProtocol(*this);
137 }
138 
139 //////////////////////////////////////////////////
141 {
142 }
143 
144 /// @details Apply the RNA de novo modeling protocol to a pose.
145 ///
147 
148  using namespace core::pose;
149  using namespace core::scoring;
150  using namespace core::io::pdb;
151  using namespace core::io::silent;
152 
153  ///////////////////////////////////////////////////////////////////////////
154  // A bunch of initialization
155  ///////////////////////////////////////////////////////////////////////////
157 
159 
160  rna_structure_parameters_->initialize( pose, rna_params_file_, jump_library_file_, true /*ignore_secstruct*/ );
161 
162  rna_data_reader_->initialize( pose, rna_data_file_ );
163 
164  if( input_res_.size() > 0 ) {
166  } else {
168  }
169  rna_structure_parameters_->set_allow_insert( rna_chunk_library_->allow_insert() );
170  rna_structure_parameters_->setup_fold_tree_and_jumps_and_variants( pose );
171 
172  if (add_base_pair_constraints_) rna_structure_parameters_->setup_base_pair_constraints( pose );
173 
174  rna_chunk_library_->initialize_random_chunks( pose, dump_pdb_ );
175 
176  if ( dump_pdb_) std::cout << "Allow insert: " << std::endl; rna_structure_parameters_->allow_insert()->show();
177 
179  frag_mover_ = new protocols::rna::RNA_FragmentMover( rna_fragments, rna_structure_parameters_->allow_insert() );
180 
181  rna_data_reader_->initialize( pose, rna_data_file_ );
182  initialize_constraints( pose );
183 
184  // "force_ideal_chainbreak" means you can't change angles and dists at cutpoints.
185  // This will also disallow torsion angle changes in OVL1, OVL2, OVU1 virtual atoms during fragment closure...
186  rna_chunk_library_->allow_insert()->set_force_ideal_chainbreak( force_ideal_chainbreak_ );
187  rna_loop_closer_->set_allow_insert( rna_structure_parameters_->allow_insert() );
188  if ( choose_best_solution_ ) rna_loop_closer_->choose_best_solution_based_on_score_function( denovo_scorefxn_ );
189 
192  domain_move_frequency_ = ( multiple_domain_mover_->num_domains() > 1 && !freeze_domains_ ) ? 0.7: 0.0;
193 
195 
196  if (dump_pdb_) pose.dump_pdb( "start.pdb" );
197  std::cout << "FOLD TREE " << pose.fold_tree();
198 
199  Pose start_pose = pose;
200 
202 
204 
205  ///////////////////////////////////////////////////////////////////////////
206  // Main Loop.
207  ///////////////////////////////////////////////////////////////////////////
208  for (Size n = 1; n <= nstruct_; n++ ) {
209 
210  std::string const out_file_tag = "S_"+lead_zero_string_of( n, 6 );
211  if (tag_is_done_[ out_file_tag ] ) continue; // put this in later!
212 
213  pose = start_pose;
214 
215  if ( domain_move_frequency_ > 0.0 ) multiple_domain_mover_->randomize_pose_rigid_bodies( pose );
216 
217  monte_carlo_->reset( pose );
218 
219  TR << "Beginning main loop... " << std::endl;
220 
221  frag_size_ = 3;
222 
223  clock_t const time_start( clock() );
224 
225  for (Size r = 1; r <= rounds_; r++ ) {
226 
227  monte_carlo_->score_function( *denovo_scorefxn_ );
228 
229  pose = monte_carlo_->lowest_score_pose();
230 
231  // Introduce constraints in stages.
232  update_pose_constraints( r, rounds_, pose );
233 
235 
236  monte_carlo_->reset( pose );
237  monte_carlo_->set_temperature( get_temperature( r, rounds_ ) );
238 
239  //////////////////////
240  // This is it ... do the loop.
241  //////////////////////
242  for( Size i=1; i <= monte_carlo_cycles_/rounds_ ; ++i ) {
243  RNA_move_trial( pose );
244  }
245 
246  if ( get_native_pose() ) {
247  Real const rmsd = rms_at_corresponding_heavy_atoms( *get_native_pose(), pose );
248  TR << "All atom rmsd: " << rmsd << std::endl;
249  }
250 
251  monte_carlo_->recover_low( pose );
252  monte_carlo_->show_counters();
253  monte_carlo_->reset_counters();
254  }
255 
256  pose = monte_carlo_->lowest_score_pose();
257  denovo_scorefxn_->show( std::cout, pose );
258 
259  TR << "Finished fragment assembly of " << out_file_tag << " in " << static_cast<Real>( clock() - time_start ) / CLOCKS_PER_SEC << " seconds. " << std::endl;
260 
261  if ( dump_pdb_ ) pose.dump_pdb( out_file_tag + ".pdb" );
262  output_to_silent_file( pose, silent_file_, out_file_tag );
263 
264  } //nstruct
265 
266 }
267 
268 ///////////////////////////////////////////////////////////////////////////////////////////////////////
271  return "CoarseRNA_DeNovoProtocol¯";
272 }
273 
274 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
276 CoarseRNA_DeNovoProtocol::get_temperature( Size const & r, Size const & rounds ) const{
277 
278  Real temperature = m_Temperature_;
279  if ( sim_anneal_ ) {
280  temperature = m_Temperature_ * ( (rounds - static_cast<Real>(r)) / rounds );
281  }
282 
283  std::cout << "Will set temperature to: " << temperature << std::endl;
284  return temperature;
285 }
286 
287 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
288 void
290 {
291 
292  using namespace core::io::silent;
293 
294  tag_is_done_.clear();
295 
297 
298  SilentFileData silent_file_data;
300  tags_done = silent_file_data.read_tags_fast( silent_file_ );
301  for ( utility::vector1< std::string >::const_iterator iter = tags_done.begin(); iter != tags_done.end(); iter++ ) {
302  std::cout << "Already done: " << *iter << std::endl;
303  tag_is_done_[ *iter ] = true;
304  }
305  }
306 
307 }
308 
309 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
310 void
311 CoarseRNA_DeNovoProtocol::output_to_silent_file( core::pose::Pose & pose, std::string const & silent_file, std::string const & out_file_tag, bool const score_only /* = false */) const
312 {
313 
314  using namespace core::io::silent;
315  using namespace core::scoring;
316 
317  static SilentFileData silent_file_data;
318  TR << "Making silent struct for " << out_file_tag << std::endl;
319 
320  BinaryRNASilentStruct s( pose, out_file_tag );
321 
322  if ( get_native_pose() ){
323 
324  s.add_energy( "all_rms", all_atom_rmsd( *get_native_pose(), pose ) );
325 
326  std::list< Size > stem_residues( rna_structure_parameters_->get_stem_residues( pose ) );
327  Real rmsd_stems( 0.0 );
328  if ( stem_residues.size() > 0 ) {
329  rmsd_stems = all_atom_rmsd( *get_native_pose(), pose, stem_residues );
330  TR << "All atom rmsd over stems: " << rmsd_stems << " for " << out_file_tag << std::endl;
331  }
332  s.add_energy( "rms_stem", rmsd_stems );
333 
334  }
335 
336  silent_file_data.write_silent_struct( s, silent_file, score_only );
337 
338 }
339 
340 
341 ////////////////////////////////////////////////////////////////////////////////////////
342 void
344 
345  if ( RG.uniform() < domain_move_frequency_ ) {
346  random_domain_move_trial( pose );
347  } else {
348  random_fragment_trial( pose );
349  }
350 
351 }
352 
353 ////////////////////////////////////////////////////////////////
354 void
356 
357  using core::id::NamedAtomID;
358 
359  pairing_dists_.clear();
360  std::map< Size, Size> const & pairs = rna_structure_parameters_->connections();
361 
362  for ( std::map< Size, Size >::const_iterator it = pairs.begin();
363  it != pairs.end(); it ++ ) {
364  Size const i = it->first;
365  Size const j = it->second;
366  pairing_dists_.push_back( ( pose.xyz( NamedAtomID( " CEN", i ) ) -
367  pose.xyz( NamedAtomID( " CEN", j ) ) ).length() );
368  }
369 
370 }
371 
372 
373 ////////////////////////////////////////////////////////////////////////////////////////
374 void
376 
377  using core::id::NamedAtomID;
378  Size count( 0 );
379  bool OK( true );
380 
381  std::map< Size, Size> const & pairs = rna_structure_parameters_->connections();
382 
383  for ( std::map< Size, Size >::const_iterator it = pairs.begin();
384  it != pairs.end(); it ++ ) {
385  Size const i = it->first;
386  Size const j = it->second;
387  Real const dist_new = ( pose.xyz( NamedAtomID( " CEN", i ) ) -
388  pose.xyz( NamedAtomID( " CEN", j ) ) ).length();
389  count++;
390  if ( std::abs( dist_new - pairing_dists_[ count ] ) > 1e-3 ) {
391  std::cout << "AFTER frag insert at " << frag_pos << " CHANGED PAIRING " << i << " " << j << std::endl;
392  OK = false;
393  }
394 
395  }
396  if ( !OK ) std::cout << pose.fold_tree() << std::endl;
397 }
398 
399 
400 ////////////////////////////////////////////////////////////////////////////////////////
401 void
403 
404  if ( freeze_domains_ ) return;
405 
406  // std::cout << "BEFORE: " << (*denovo_scorefxn_)( pose ) << std::endl;
407 
408  Size const jumpno = multiple_domain_mover_->apply_and_return_jump( pose );
409 
410  // std::cout << "AFTER1: " << (*denovo_scorefxn_)( pose ) << std::endl;
411 
412  rna_loop_closer_->apply_after_jump_change( pose, jumpno );
413 
414  // std::cout << "AFTER2: " << (*denovo_scorefxn_)( pose )<< std::endl;
415 
416  monte_carlo_->boltzmann( pose, "domain" );
417 
418 }
419 
420 
421 ////////////////////////////////////////////////////////////////////////////////////////
422 void
424 
425  // The check_pairing_dists_ is not typically one -- clutters up code. Remove when we're confident?
426 
428 
429  Size const frag_pos = frag_mover_->random_fragment_insertion( pose, frag_size_ );
430 
431  if ( check_pairing_dists_ ) check_new_pairing_dists( pose, frag_pos );
433 
434  if ( close_loops_ ) rna_loop_closer_->apply( pose, frag_pos );
435 
436  Size const dummy_pos( 0 );
437  if ( check_pairing_dists_ ) check_new_pairing_dists( pose, dummy_pos );
438 
439  // std::cout << "frag_pos " << frag_pos << std::endl;
440  // std::cout << "; after: " << ( pose.xyz( id::NamedAtomID( " Y ", 6 ) ) - pose.xyz( id::NamedAtomID( " Y ", 7 ) ) ).length() << std::endl;
441 
442  monte_carlo_->boltzmann( pose, "frag" + SS(frag_size_) );
443 
444 }
445 
446 ////////////////////////////////////////////////////////////////////////////////////////
447 Size
449 {
450 
451  //Keep score function coarse for early rounds.
452  Real const suppress = ( r )/(rounds - 2.0);
453 
454  Size separation_cutoff = static_cast< Size > ( suppress * max_dist ) + 2;
455  if ( separation_cutoff > max_dist ) separation_cutoff = max_dist;
456 
457  return separation_cutoff;
458 
459 }
460 
461 
462 ////////////////////////////////////////////////////////////////////////////////////////
463 void
465 {
466  using namespace core::scoring::constraints;
467 
468  if ( !staged_constraints_) return;
469 
470  if ( !constraint_set_ ) return;
471 
473 
474  static core::kinematics::ShortestPathInFoldTree shortest_path_in_fold_tree( pose.fold_tree() );
475  Size const separation_cutoff = figure_out_constraint_separation_cutoff( r, rounds, shortest_path_in_fold_tree.max_dist() );
476  TR << "ROUND " << r << " out of " << rounds << std::endl;
477  TR << "FOLD_TREE CURRENT SEPARATION CUTOFF " << separation_cutoff << " out of " << shortest_path_in_fold_tree.max_dist() << std::endl;
478 
479  ConstraintCOPs csts( constraint_set_->get_all_constraints() );
480 
481  for ( Size n = 1; n <= csts.size(); n++ ) {
482 
483  ConstraintCOP const & cst( csts[n] );
484 
485  if ( cst->natoms() == 2 ) { // currently only defined for pairwise distance constraints.
486  Size const i = cst->atom( 1 ).rsd();
487  Size const j = cst->atom( 2 ).rsd();
488  Size const dist( shortest_path_in_fold_tree.dist( i , j ) );
489  if ( dist > separation_cutoff ) continue;
490  }
491 
492  cst_set_new->add_constraint( cst );
493  }
494 
495  pose.constraint_set( cst_set_new );
496 
497  TR << "NUM CONSTRAINTS " << pose.constraint_set()->get_all_constraints().size() << " out of " <<
498  csts.size() << std::endl;
499 
500 }
501 
502 ////////////////////////////////////////////////////////////////////////////////////////
503 void
505 
506  Real const scale_factor = ( static_cast<Real>( rounds - r + 1) / rounds );
507  Real const rot_mag = 5.0 * scale_factor;
508  Real const trans_mag = 1.0 * scale_factor;
509 
510  multiple_domain_mover_->update_rot_trans_mag( rot_mag, trans_mag );
511 
512 }
513 
514 ///////////////////////////////////////////////////////////////////////////////////////////////////////
515 void
517 
518  using namespace core::scoring;
519 
520  if (pose.constraint_set()->has_constraints() ) {
521  denovo_scorefxn_->set_weight( atom_pair_constraint, 1.0 );
522  constraint_set_ = pose.constraint_set()->clone();
523  }
524 
525 }
526 
527 
528 
529 } // namespace rna
530 } // namespace protocols