Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RNA_SWA_MonteCarloMover.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_SWA_MonteCarloMover
11 /// @brief SWA Monte Carlo -- generalization of Monte Carlo to permit addition/deletion of RNA residues
12 /// @detailed
13 /// @author Rhiju Das
14 
22 
23 // libRosetta headers
24 #include <core/types.hh>
25 #include <core/pose/Pose.hh>
27 #include <core/pose/util.hh>
31 #include <core/scoring/rms_util.hh>
32 #include <core/id/types.hh>
33 #include <utility/vector1.hh>
34 #include <numeric/xyzVector.hh>
38 #include <basic/Tracer.hh>
39 
40 #include <numeric/random/random.hh>
41 
42 #include <ObjexxFCL/string.functions.hh>
43 #include <ObjexxFCL/format.hh>
44 
45 
46 using namespace core;
47 using core::Real;
48 
49 //////////////////////////////////////////////////////////////////////////
50 // SWA Monte Carlo -- framework for sampling RNA through torsion moves,
51 // and moves that delete or add residues at chain termini.
52 //////////////////////////////////////////////////////////////////////////
53 
54 static numeric::random::RandomGenerator RG(29111); // <- Magic number, do not change it!
55 
56 static basic::Tracer TR( "protocols.swa.monte_carlo.rna_swa_monte_carlo_mover" ) ;
57 
58 namespace protocols {
59 namespace swa {
60 namespace monte_carlo {
61 
62 
63  //////////////////////////////////////////////////////////////////////////
64  //constructor!
65  RNA_SWA_MonteCarloMover::RNA_SWA_MonteCarloMover( RNA_AddOrDeleteMoverOP rna_add_or_delete_mover,
66  RNA_TorsionMoverOP rna_torsion_mover,
67  RNA_O2StarMoverOP rna_o2star_mover,
69  rna_add_or_delete_mover_( rna_add_or_delete_mover ),
70  rna_torsion_mover_( rna_torsion_mover ),
71  rna_o2star_mover_( rna_o2star_mover ),
72  scorefxn_( scorefxn ),
73  num_cycles_( 50000 ),
74  output_period_( 5000 ),
75  sample_range_small_( 5.0 ),
76  sample_range_large_( 50.0 ),
77  kT_( 0.5 ),
78  do_add_delete_( true ),
79  silent_file_( "" ),
80  silent_file_data_( new core::io::silent::SilentFileData )
81  {
82  initialize_next_suite_atoms(); // used in RMSD calculations.
83  }
84 
85  //////////////////////////////////////////////////////////////////////////
86  //destructor
88  {}
89 
90  //////////////////////////////////////////////////////////////////////////
91  void
93  {
94 
95  using namespace protocols::moves;
96 
97  MonteCarloOP monte_carlo = new MonteCarlo( pose, *scorefxn_, kT_ );
98 
99  //bool accepted( true );
100  std::string move_type;
101 
102  for (Size count = 1; count <= num_cycles_; count++) {
103 
104  Real const random_number = RG.uniform();
105 
106  move_type = "";
107 
109 
110  if ( (random_number < 0.01 && do_add_delete_) || moving_res_list.size() == 0 /*got to add something!*/ ) {
111  rna_add_or_delete_mover_->apply( pose, move_type );
112  }
113 
114  if ( move_type.size() == 0 /*no move yet!*/ && random_number < 0.8 ){
115 
116  Real const random_number2 = RG.uniform();
117  if ( random_number2 < 0.5 ){
118  move_type = "sml";
119  rna_torsion_mover_->apply( pose, move_type, sample_range_small_ );
120  } else {
121  move_type = "lrg";
122  rna_torsion_mover_->apply( pose, move_type, sample_range_large_ );
123  }
124  } else{
125  rna_o2star_mover_->apply( pose, move_type );
126  }
127 
128  /*accepted =*/ monte_carlo->boltzmann( pose, move_type );
129 
130  //Real const current_score = (*scorefxn_)( pose );
131 
132  if ( count % output_period_ == 0 || count == num_cycles_ ) {
133  std::cout << "On " << count << " of " << num_cycles_ << " trials." << std::endl;
134  output_silent_file( pose, count );
135  }
136 
137  }
138 
139  monte_carlo->show_counters();
140  monte_carlo->recover_low( pose );
141 
142  }
143 
144  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
145  void
147  // could initialize this once somewhere else.
148  next_suite_atoms_.clear();
149  next_suite_atoms_.push_back(" P ");
150  next_suite_atoms_.push_back(" O1P");
151  next_suite_atoms_.push_back(" O2P");
152  next_suite_atoms_.push_back(" O5*");
153  }
154 
155 
156  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
157  // Following assumed that pose is already properly aligned to native pose!
158  // stuff into RNA_SWA_MonteCarloMover.
159  void
161 
162  using namespace core::io::silent;
163  using namespace core::conformation;
164  using namespace ObjexxFCL;
165 
166  SubToFullInfo & sub_to_full_info = nonconst_sub_to_full_info_from_pose( pose );
167  utility::vector1< Size > working_res_list = sub_to_full_info.moving_res_list();
168  std::map< Size, Size > sub_to_full = sub_to_full_info.sub_to_full();
169 
170  // useful to keep track of what's a working residue and what's not.
171  utility::vector1< bool > is_working_res;
172  for ( Size i = 1; i <= pose.total_residue(); i++ ) is_working_res.push_back( false );
173  for ( Size n = 1; n <= working_res_list.size(); n++ ) is_working_res[ working_res_list[n] ] = true;
174 
175  std::string const tag = "S_"+lead_zero_string_of(count,6);
176  BinaryRNASilentStruct s( pose, tag );
177 
178  Pose const & native_pose = *get_native_pose();
179 
180  Real dev( 0.0 );
181  Real rmsd( 0.0 );
182  Size natoms( 0 );
183 
184  for ( Size n = 1; n <= working_res_list.size(); n++ ){
185  Size const i = working_res_list[ n ];
186  Size const i_full = sub_to_full[ i ];
187 
188  // std::cout << "NATIVE CHECK: " << i << ' ' << i_full << std::endl;
189 
190  Residue const & rsd = pose.residue( i );
191  Residue const & rsd_native = native_pose.residue( i_full );
192 
193  if ( rsd.aa() != rsd_native.aa() ) std::cout << "mismatch: pose " << i << ' ' << rsd.aa() << " native " << i_full << rsd_native.aa() << std::endl;
194  runtime_assert( rsd.aa() == rsd_native.aa() );
195 
196  for ( Size j = 1; j <= rsd.nheavyatoms(); j++ ){
197  if ( rsd.is_virtual( j ) ) continue; // note virtual phosphates on 5'-ends of loops.
198  std::string atom_name = rsd.atom_name( j );
199  // std::cout << "RMSD: " << i << atom_name << std::endl;
200  if ( !rsd_native.has( atom_name ) ) continue;
201  Size const j_full = rsd_native.atom_index( atom_name );
202  dev += ( rsd_native.xyz( j_full ) - rsd.xyz( j ) ).length_squared();
203  natoms++;
204  }
205 
206  // also add in atoms in next suite, if relevant (and won't be covered later in rmsd calc.)
207  if ( i < pose.total_residue() && !is_working_res[ i+1 ] && !pose.fold_tree().is_cutpoint(i) ){
208  Size const i_next = i+1;
209  Size const i_next_full = sub_to_full[ i+1 ];
210  runtime_assert( i_next_full == i_full + 1 ); //better be a connection in both the pose & native pose!
211 
212  Residue const & rsd_next = pose.residue( i_next );
213  Residue const & rsd_next_native = native_pose.residue( i_next_full );
214  runtime_assert( rsd_next.aa() == rsd_next_native.aa() );
215 
216  //std::cout << "RMSD: num_suite_atoms " << next_suite_atoms_.size() << std::endl;
217  for (Size k = 1; k <= next_suite_atoms_.size(); k++ ){
218  std::string atom_name = next_suite_atoms_[ k ];
219  //std::cout << "RMSD: " << i+1 << atom_name << std::endl;
220  runtime_assert( rsd_next.has( atom_name ) );
221  runtime_assert( rsd_next_native.has( atom_name ) );
222  Size const j = rsd_next.atom_index( atom_name );
223  Size const j_full = rsd_next_native.atom_index( atom_name );
224  dev += ( rsd_next_native.xyz( j_full ) - rsd_next.xyz( j ) ).length_squared();
225  natoms++;
226  }
227 
228  }
229 
230  }
231  if ( natoms > 0 ) rmsd = std::sqrt( dev / static_cast<Real>( natoms ) );
232 
233  s.add_energy( "rms",rmsd );
234  s.add_string_value( "count", ObjexxFCL::fmt::I(9,count) );
235 
236  std::string built_res = "";
237  if ( working_res_list.size() == 0 ) {
238  built_res = "-";
239  } else {
240  built_res += string_of( working_res_list[1] );
241  for ( Size n = 2; n <= working_res_list.size(); n++ ) built_res += "-"+string_of( sub_to_full[ working_res_list[n] ] );
242  }
243  s.add_string_value( "built_res", built_res);
244 
245  silent_file_data_->write_silent_struct( s, silent_file_, false /*score_only*/ );
246  }
247 
248 
249 
252  return "RNA_SWA_MonteCarloMover";
253  }
254 
255 }
256 }
257 }