Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RNA_Minimizer.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_Minimizer
12 /// @detailed
13 /// @author Rhiju Das (rhiju@stanford.edu), Parin Sripakdeevong (sripakpa@stanford.edu)
14 
15 
18 
19 #include <protocols/swa/rna/StepWiseRNA_Util.hh> //Parin Sripakdeevong
26 #include <core/id/AtomID_Map.hh>
27 #include <core/id/AtomID.hh>
28 #include <core/id/NamedAtomID.hh>
29 #include <core/id/DOF_ID.hh>
30 #include <core/id/TorsionID.hh>
31 #include <core/pose/Pose.hh>
32 #include <core/pose/util.hh>
34 
39 
41 
42 #include <basic/options/option.hh>
43 // AUTO-REMOVED #include <basic/options/util.hh>
44 
45 //Minimizer stuff
49 
50 //Packer stuff
55 
56 // ObjexxFCL Headers
57 #include <ObjexxFCL/FArray1D.hh>
58 
59 #include <core/types.hh>
60 #include <basic/Tracer.hh>
61 
62 // AUTO-REMOVED #include <numeric/conversions.hh>
63 
64 // External library headers
65 
66 
67 //C++ headers
68 #include <vector>
69 #include <string>
70 #include <sstream>
71 // AUTO-REMOVED #include <fstream>
72 #ifdef WIN32
73 #include <ctime>
74 #endif
75 
76 
77 // option key includes
78 
79 #include <basic/options/keys/score.OptionKeys.gen.hh>
80 #include <basic/options/keys/rna.OptionKeys.gen.hh>
81 
82 #include <utility/vector0.hh>
83 #include <utility/vector1.hh>
84 
85 //Auto Headers
88 
89 
90 using namespace core;
91 using basic::T;
92 
93 static basic::Tracer TR( "protocols.rna.rna_minimizer" ) ;
94 
95 namespace protocols {
96 namespace rna {
97 
98 RNA_Minimizer::RNA_Minimizer():
99  Mover(),
100  deriv_check_( false ),
101  use_coordinate_constraints_( false ), // DO NOT CHECK IN
102  coord_sdev_( 10.0 * std::sqrt(10.0) ), // awkward, but matches an old setting.
103  coord_cst_weight_( 1.0 ),
104  rounds_( basic::options::option[ basic::options::OptionKeys::rna::minimize_rounds ] ),
105  skip_o2star_trials_( false ),
106  perform_minimizer_run_( true ),
107  vary_bond_geometry_( false ),
108  include_default_linear_chainbreak_( true ),
109  verbose_( false ), //Parin S. Jan 07, 2012
110  do_dump_pdb_( false ),
111  move_first_rigid_body_( false ),
112  min_type_( "dfpmin" ) //Parin S. Jan 12, 2012
113 {
114  Mover::type("RNA_Minimizer");
115  if ( basic::options::option[ basic::options::OptionKeys::score::weights ].user() ) {
116  scorefxn_ = core::scoring::ScoreFunctionFactory::create_score_function( basic::options::option[ basic::options::OptionKeys::score::weights ]() );
117  } else {
119  }
120 }
121 
122 /// @details Apply the RNA full atom minimizer.
123 ///
125 {
126 
127  using namespace core::scoring;
128  using namespace core::kinematics;
129  using namespace core::optimization;
130  using namespace basic::options;
131  using namespace basic::options::OptionKeys;
132 
133  if(verbose_){
134  TR << "Check it! SEQUENCE " << pose.sequence() << std::endl;
135  TR << "In protocols.rna.rna_minimizer.apply()" << std::endl;
136  TR << "min_type_=" << min_type_ << std::endl;
137  protocols::swa::rna::Output_boolean("deriv_check_: ", deriv_check_ ); std::cout << std::endl;
138  protocols::swa::rna::Output_boolean("use_coordinate_constraints_: ", use_coordinate_constraints_ ); std::cout << std::endl;
139  protocols::swa::rna::Output_boolean("skip_o2star_trials_: ", skip_o2star_trials_ ); std::cout << std::endl;
140  protocols::swa::rna::Output_boolean("perform_minimizer_run_: ", perform_minimizer_run_); std::cout << std::endl;
141  protocols::swa::rna::Output_boolean("vary_bond_geometry_: ", vary_bond_geometry_ ); std::cout << std::endl;
142  protocols::swa::rna::Output_boolean("include_default_linear_chainbreak_: ", include_default_linear_chainbreak_ ); std::cout << std::endl;
143  protocols::swa::rna::Output_boolean("do_dump_pdb_: ", do_dump_pdb_ ); std::cout << std::endl;
144  protocols::swa::rna::Output_boolean("verbose_: ", verbose_ ); std::cout << std::endl;
145  }
146 
147 
148  time_t pdb_start_time = time(NULL);
149 
150  if (pose.constraint_set()->has_constraints() ){
151  if ( !scorefxn_->has_nonzero_weight( atom_pair_constraint ) ) scorefxn_->set_weight( atom_pair_constraint, 1.0 );
152  if ( !scorefxn_->has_nonzero_weight( coordinate_constraint ) ) scorefxn_->set_weight( coordinate_constraint, 1.0 );
153  }
154 
155  if ( vary_bond_geometry_ ) scorefxn_->set_weight( rna_bond_geometry, 1.0 );
156 
157  if( include_default_linear_chainbreak_ && !scorefxn_->has_nonzero_weight( linear_chainbreak ) ){
158  // New as of 2011 (based on results with minimizing in SWA work
159  scorefxn_->set_weight( linear_chainbreak, 5.0 );
160  }
161 
162  /////////////////////////////////////////////////////
163  scoring::constraints::ConstraintSetOP save_pose_constraints = pose.constraint_set()->clone();
165  scoring::constraints::ConstraintSetOP pose_constraints_with_coordinate_tethers = pose.constraint_set()->clone();
166 
167  /////////////////////////////////////////////////////
168  AtomTreeMinimizer minimizer;
169  float const dummy_tol( 0.0000025);
170  bool const use_nblist( true );
171  MinimizerOptions options( min_type_, dummy_tol, use_nblist, deriv_check_, deriv_check_ );
172  options.nblist_auto_update( true );
173 
174  /////////////////////////////////////////////////////
176  if (!allow_insert_) allow_insert_ = new toolbox::AllowInsert( pose ); // initialized to let all dofs move.
178  setup_movemap( mm, pose );
179 
180  Real const fa_rep_final( scorefxn_->get_weight( fa_rep ) );
181 
182  if(do_dump_pdb_) pose.dump_pdb( "RNA_Minimizer_START.pdb" );
183 
184  for (Size r = 1; r <= rounds_; r++ ) {
185 
186  ScoreFunctionOP minimize_scorefxn_ = scorefxn_->clone();
187 
188  Real const suppress = static_cast<Real>(r)/rounds_;
189  minimize_scorefxn_->set_weight( fa_rep, fa_rep_final * suppress );
190 
191  if(do_dump_pdb_) pose.dump_pdb( "RNA_Minimizer_round_" + ObjexxFCL::string_of(r) + "_before_o2star_trials.pdb" );
192 
193  if (!skip_o2star_trials_) o2star_trials( pose, minimize_scorefxn_ );
194 
195  if(do_dump_pdb_) pose.dump_pdb( "RNA_Minimizer_round_" + ObjexxFCL::string_of(r) +"_after_o2star_trials.pdb" );
196 
197  //Prevent explosions on first minimize.
198  // this is silly. in first round, just make sure coordinate_constraint is one, and use constraints 'supplemented' with coordinate constraints.
200  if ( r == 1 ) {
201  if ( !minimize_scorefxn_->has_nonzero_weight( coordinate_constraint ) ) minimize_scorefxn_->set_weight( coordinate_constraint, coord_cst_weight_ );
202  pose.constraint_set( pose_constraints_with_coordinate_tethers );
203  } else {
204  pose.constraint_set( save_pose_constraints );
205  }
206  }
207  TR << "Minimizing...round= " << r << std::endl;
208  if (perform_minimizer_run_) minimizer.run( pose, mm, *minimize_scorefxn_, options );
209 
210  if (do_dump_pdb_) pose.dump_pdb( "RNA_Minimizer_round_" + ObjexxFCL::string_of(r) + "_after_minimizer_run.pdb" );
211 
212  }
213 
214  time_t pdb_end_time = time(NULL);
215 
216  //scorefxn_->show( std::cout, pose );
217 
218  pose.constraint_set( save_pose_constraints );
219 
220  if(verbose_) std::cout << "----------After minimizing:----------" << std::endl;
221 
222  (*scorefxn_)( pose );
223  scorefxn_->show( std::cout, pose );
224 
225  if(do_dump_pdb_) pose.dump_pdb( "RNA_Minimizer_FINISH.pdb" );
226 
227  TR << "RNA minimizer finished in " << (long)(pdb_end_time - pdb_start_time) << " seconds." << std::endl;
228 
229 
230 }
231 
232 
233 ///////////////////////////////////////////////////////////////////////////////
234  ////////////////////////
237  return "RNA_Minimizer";
238 }
239 
240 
241 ///////////////////////////////////////////////////////////////////////////////
242 // Make this its own Mover?
243 void
245  core::pose::Pose & pose,
246  core::scoring::ScoreFunctionOP const & packer_scorefxn_ ) const
247 {
248 
249  pack::task::PackerTaskOP task( pack::task::TaskFactory::create_packer_task( pose ));
250  //task->initialize_from_command_line(); //Jan 20, 2012 Testing.
251 
252  for (Size i = 1; i <= pose.total_residue(); i++) {
253  if ( !pose.residue(i).is_RNA() ) continue;
254 
255  task->nonconst_residue_task(i).and_extrachi_cutoff( 0 );
256  task->nonconst_residue_task(i).or_include_current( true );
257 
258  }
259 
260  TR << "Orienting 2' hydroxyls..." << std::endl;
261 
262  pack::rotamer_trials( pose, *packer_scorefxn_, task);
263 
264 }
265 
266 ////////////////////////////////////////////////////////////////////////////////////////////////////////
267 void
269 
270  using namespace core::id;
271  using namespace core::scoring::rna;
272 
273  Size const nres( pose.total_residue() );
274 
275  mm.set_bb( false );
276  mm.set_chi( false );
277  mm.set_jump( false );
278 
279  // torsions
280  for (Size i = 1; i <= nres; i++ ) {
281 
282  if ( !pose.residue(i).is_RNA() ) continue;
283 
284  for (Size j = 1; j <= NUM_RNA_TORSIONS; j++) {
285  id::TorsionID rna_torsion_id( i, id::BB, j );
286  if ( j > NUM_RNA_MAINCHAIN_TORSIONS) rna_torsion_id = id::TorsionID( i, id::CHI, j - NUM_RNA_MAINCHAIN_TORSIONS );
287 
288  if ( !allow_insert_->get( rna_torsion_id, pose.conformation() ) ) continue;
289 
290  DOF_ID dof_id( pose.conformation().dof_id_from_torsion_id( rna_torsion_id ) );
291  mm.set( dof_id, true );
292 
293  }
294 
295  }
296 
297  // jumps
298  for (Size n = 1; n <= pose.fold_tree().num_jump(); n++ ){
299  Size const jump_pos1( pose.fold_tree().upstream_jump_residue( n ) );
300  std::string const jump_atom1( pose.fold_tree().upstream_atom( n ) );
301  AtomID jump_atom_id1( 1, jump_pos1 );
302  if (jump_atom1.size() > 0) jump_atom_id1 = named_atom_id_to_atom_id( NamedAtomID( jump_atom1, jump_pos1 ), pose );
303 
304  Size const jump_pos2( pose.fold_tree().downstream_jump_residue( n ) );
305  std::string const jump_atom2( pose.fold_tree().downstream_atom( n ) );
306  AtomID jump_atom_id2( 1, jump_pos2 );
307  if (jump_atom2.size() > 0) jump_atom_id2 = named_atom_id_to_atom_id( NamedAtomID( jump_atom2, jump_pos2 ), pose );
308 
309  if ( allow_insert_->get( jump_atom_id1 ) || allow_insert_->get( jump_atom_id2 ) ) mm.set_jump( n, true );
310 
311  }
312 
313  // allow rigid body movements... check for virtual residue at end and at least two chunks with jumps to it.
315 
316  // vary bond geometry
317  if ( vary_bond_geometry_ ) {
318  // Let additional degrees of freedom vary -- but apply constraints to stay near
319  // ideal bond lengths and angles!
322  CTIMover.set_movemap(mmop);
323  CTIMover.set_AllowInsert(allow_insert_);
324  CTIMover.apply(pose);
325  mm = (*CTIMover.get_movemap());
326  }
327 
328 }
329 
330 /////////////////////////////////////////////////////////////////////////////////
331 void
333 
334  if ( extra_minimize_res_.size() == 0 ) return;
335 
336  utility::vector1< id::AtomID > atom_ids_to_move;
337 
338  for ( Size n = 1; n <= extra_minimize_res_.size(); n++ ){
339 
340  Size const i = extra_minimize_res_[n];
341  runtime_assert( pose.residue( i ).is_RNA() );
342 
343  for ( Size j = 1; j <= pose.residue(i).natoms(); j++ ){
344  if ( pose.residue(i).is_virtual( j ) ) continue;
345  atom_ids_to_move.push_back( id::AtomID( j, i ) );
346  }
347 
348  if ( pose.fold_tree().is_cutpoint( i ) ) continue;
349  if ( i > pose.total_residue() ) continue;
350  if ( !pose.residue( i+1 ).is_RNA() ) continue;
351 
352  // go ahead and minimize backbone torsions up to next pucker.
353  atom_ids_to_move.push_back( named_atom_id_to_atom_id( id::NamedAtomID( " O1P", i+1 ), pose ) );
354  atom_ids_to_move.push_back( named_atom_id_to_atom_id( id::NamedAtomID( " O2P", i+1 ), pose ) );
355  atom_ids_to_move.push_back( named_atom_id_to_atom_id( id::NamedAtomID( " P ", i+1 ), pose ) );
356  atom_ids_to_move.push_back( named_atom_id_to_atom_id( id::NamedAtomID( " O5*", i+1 ), pose ) );
357 
358  }
359 
360  for ( Size n = 1; n <= atom_ids_to_move.size(); n++ ){
361  if ( allow_insert_->has_domain( atom_ids_to_move[n] ) ) allow_insert_->set( atom_ids_to_move[n], true );
362  }
363  // We should do a double check that we're not introducing movement that would mess up a domain?
364 
365 }
366 
367 /////////////////////////////////////////////////////////////////////////////////
368 void
370  scorefxn_ = scorefxn->clone();
371 }
372 
373 /////////////////////////////////////////////////////////////////////////////////
374 void
376  allow_insert_ = allow_insert->clone();
377 }
378 
379 /////////////////////////////////////////////////////////////////////////////////
380 void
382  extra_minimize_res_ = setting;
383 }
384 
385 } // namespace rna
386 } // namespace protocols
387