Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LoopMover_Backrub.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 // This file is part of the Rosetta software suite and is made available under license.
5 // The Rosetta software is developed by the contributing members of the Rosetta Commons consortium.
6 // (C) 199x-2009 Rosetta Commons participating institutions and developers.
7 // For more information, see http://www.rosettacommons.org/.
8 
9 /// @file protocols/loops/LoopMover_Backrub.cc
10 /// @brief backrub loop refine
11 /// @author J. Karanicolas
12 
13 //// Unit Headers
17 #include <protocols/loops/Loop.hh>
18 #include <protocols/loops/Loops.hh>
22 //
23 //// Rosetta Headers
25 #include <core/id/TorsionID.hh>
26 // AUTO-REMOVED #include <core/kinematics/MoveMap.hh>
27 #include <basic/options/option.hh>
28 #include <core/pose/Pose.hh>
29 // AUTO-REMOVED #include <core/pose/util.hh>
32 
36 // AUTO-REMOVED #include <core/pack/rotamer_trials.hh>
38 
39 #include <basic/options/keys/run.OptionKeys.gen.hh>
40 
41 // AUTO-REMOVED #include <basic/options/util.hh>
42 // AUTO-REMOVED #include <basic/options/after_opts.hh>
43 // AUTO-REMOVED #include <basic/options/option_macros.hh>
44 
45 // AUTO-REMOVED #include <basic/prof.hh> // profiling
46 #include <basic/Tracer.hh>
47 
48 //Utility Headers
49 #include <numeric/random/random.hh>
50 // AUTO-REMOVED #include <utility/io/izstream.hh>
51 
52 // C++ Headers
53 #include <iostream>
54 #include <map>
55 #include <string>
56 
57 // option key includes
58 
59 // AUTO-REMOVED #include <basic/options/keys/out.OptionKeys.gen.hh>
60 #include <basic/options/keys/loops.OptionKeys.gen.hh>
61 #include <basic/options/keys/packing.OptionKeys.gen.hh>
62 
63 #include <utility/vector0.hh>
64 #include <utility/vector1.hh>
65 #include <utility/keys/Key3Vector.hh>
66 
67 //Auto Headers
68 
69 
70 
71 namespace protocols {
72 namespace loops {
73 namespace loop_mover {
74 namespace refine {
75 
76 ///////////////////////////////////////////////////////////////////////////////
77 using namespace core;
78 
79 static numeric::random::RandomGenerator RG(42678);
80 
81 static basic::Tracer TR("protocols.loops..LoopMover_Refine_Backrub");
82 
84  LoopMover()
85 {
87  protocols::moves::Mover::type("LoopMover_Refine_Backrub");
89 }
90 
93 ) : LoopMover( loops_in )
94 {
96  protocols::moves::Mover::type("LoopMover_Refine_Backrub");
98 }
99 
101  protocols::loops::LoopsOP loops_in,
103 ) : LoopMover( loops_in )
104 {
105  set_scorefxn( scorefxn );
106  protocols::moves::Mover::type("LoopMover_Refine_Backrub");
108 }
109 
110 //destructor
112 
115 
116 
118  core::pose::Pose & pose
119 ){
120 
121  using namespace core;
122  using namespace scoring;
123  using namespace basic::options;
124 
125  /// must be called once the Pose has become available.
126  resolve_loop_indices( pose );
127 
128  // Note: based heavily on KIC loop refine
129 
130  // scheduler
131  int const fast = option[OptionKeys::loops::fast];
132  int outer_cycles(3);
133  if ( option[ OptionKeys::loops::outer_cycles ].user() ) {
134  outer_cycles = option[ OptionKeys::loops::outer_cycles ]();
135  }
136  if ( option[ OptionKeys::run::test_cycles ]() ) {
137  outer_cycles = 2;
138  }
139  int max_inner_cycles( 200 );
140  if ( option[ OptionKeys::loops::max_inner_cycles ].user() ) {
141  max_inner_cycles = option[ OptionKeys::loops::max_inner_cycles ]();
142  }
143  if ( option[ OptionKeys::run::test_cycles ]() ) {
144  max_inner_cycles = 2;
145  }
146 
147  int const inner_cycles = std::min( Size(max_inner_cycles), fast ? (Size)( loops()->loop_size() ) : 10 * (Size)( loops()->loop_size() ) );
148  int repack_period = 20; // should be an option
149  if ( option[ OptionKeys::loops::repack_period ].user() ) {
150  repack_period = option[ OptionKeys::loops::repack_period ]();
151  }
152 
153  int ntrials_per_cycle = 10;
154  if ( option[ OptionKeys::loops::backrub_trials ].user() ) {
155  ntrials_per_cycle = option[ OptionKeys::loops::backrub_trials ]();
156  }
157 
158  // scorefxn
160  if ( scorefxn() != 0 ) scorefxn = scorefxn()->clone();
161  else {
163  }
164  (*scorefxn)(pose);
165 
166  // set up BackrubMover and read from the database
168  backrubmover.branchopt().read_database();
169 
170  //clear segments and set the input pose
171  backrubmover.clear_segments();
172  pose::PoseOP input_poseOP ( new pose::Pose( pose ) );
173  backrubmover.set_input_pose( input_poseOP );
174 
175  // set backrub segments
176  Size const nres( pose.total_residue() );
177  utility::vector1< bool > is_loop( nres, false );
178  for ( Loops::const_iterator it=loops()->begin(), it_end=loops()->end(); it != it_end; ++it ) {
179  for ( core::Size seg_start = it->start(); seg_start <= it->stop(); ++seg_start ) {
180  is_loop[seg_start] = true;
181  for ( core::Size seg_end = seg_start + 2; seg_end <= it->stop(); ++seg_end ) {
182  id::AtomID start_atom_id = id::AtomID( pose.residue( seg_start ).atom_index("CA") , seg_start );
183  id::AtomID end_atom_id = id::AtomID( pose.residue( seg_end ).atom_index("CA"), seg_end );
184  // add segment to the mover
185  backrubmover.add_segment( start_atom_id, end_atom_id, 0 );
186  }
187  }
188  }
189 
190  // optimize branch angles and idealize side chains
191  backrubmover.optimize_branch_angles( pose );
192  (*scorefxn)(pose);
193 
194  // setup monte carlo
195  float const init_temp( option[ OptionKeys::loops::refine_init_temp ]() );
196  float const final_temp( option[ OptionKeys::loops::refine_final_temp ]() );
197  float const gamma = std::pow( (final_temp/init_temp), 1.0f/(outer_cycles*inner_cycles) );
198  float temperature = init_temp;
199  protocols::moves::MonteCarlo mc( pose, *scorefxn, temperature );
200  mc.reset(pose);
201 
202  // setup PackerTask
203  // default move map
204  bool const fix_natsc = option[OptionKeys::loops::fix_natsc];
205  // the following TaskFactory usage allows user-defined PackerTask creation on-demand
206  using namespace pack::task;
207  if ( task_factory == 0 ) {
208  task_factory = new TaskFactory;
209  // TaskOperations replace the following kind of code:
210  // base_packer_task->initialize_from_command_line().or_include_current( true );
211  task_factory->push_back( new operation::InitializeFromCommandline );
212  task_factory->push_back( new operation::IncludeCurrent );
213  if ( option[ OptionKeys::packing::resfile ].user() ) {
214  // Note - resfile is obeyed, so use NATAA as default to maintain protocol behavior
216  tr() << "Activating design" << std::endl;
217  }
218  }
219  PackerTaskOP base_packer_task = task_factory->create_task_and_apply_taskoperations( pose );
220  // this could also be handled/controlled by a [externally-defined] TaskOperation
221  if ( redesign_loop ) {
222  // allow design at loop positions
223  for ( Size i=1; i<= nres; ++i ) {
224  if ( !is_loop[i] ) base_packer_task->nonconst_residue_task( i ).restrict_to_repacking();
225  }
226  } else {
227  // restrict to repacking at all positions
228  base_packer_task->restrict_to_repacking();
229  }
230  base_packer_task->set_bump_check( true );
231 
232  // perform initial repack trial
233  pack::task::PackerTaskOP this_packer_task( base_packer_task->clone() );
234  utility::vector1<bool> allow_repacked( nres, false );
235  pose.update_residue_neighbors(); // to update 10A nbr graph
236  select_loop_residues( pose, *loops(), !fix_natsc, allow_repacked, 10.0 /* neighbor_cutoff */);
237  this_packer_task->restrict_to_residues( allow_repacked );
238  core::pack::pack_rotamers( pose, *scorefxn, this_packer_task );
239  std::string move_type = "repack";
240  pose.update_residue_neighbors(); // to update 10A nbr graph
241  mc.boltzmann( pose, move_type );
242 
243  std::string backrub_move_type = backrubmover.type();
244  for (int i=1; i<=outer_cycles; ++i) {
245  tr() << "loopmover backrub outer refinement cycle " << i << std::endl;
246  mc.score_function( *scorefxn );
247  mc.recover_low( pose );
248 
249  for ( int j=1; j<=inner_cycles; ++j ) {
250  temperature *= gamma;
251  mc.set_temperature( temperature );
252 
253  for ( int trial = 1; trial <= ntrials_per_cycle; ++trial ) {
254  backrubmover.apply(pose);
255  mc.boltzmann(pose, backrub_move_type);
256  }
257 
258  // main_repack_trial
259  if ( (j%repack_period)==0 || j==inner_cycles ) {
260  // repack trial
261  //pack::task::PackerTaskOP this_packer_task( base_packer_task->clone() );
262  // DJM: try updating existing packer task
263  utility::vector1<bool> allow_repacked( nres, false );
264  select_loop_residues( pose, *loops(), !fix_natsc, allow_repacked, 10.0 /* neighbor_cutoff */);
265  this_packer_task->restrict_to_residues( allow_repacked );
266  pack::pack_rotamers( pose, *scorefxn, this_packer_task );
267  std::string move_type = "repack";
268  mc.boltzmann( pose, move_type );
269  }
270  } //inner_cycle
271  } //outer_cycle
272 
273  pose = mc.lowest_score_pose();
274 
275 }
276 
279  return "LoopMover_Refine_Backrub";
280 }
281 
282 basic::Tracer & LoopMover_Refine_Backrub::tr() const
283 {
284  return TR;
285 }
286 
288 
290  return new LoopMover_Refine_Backrub();
291 }
292 
294  return "LoopMover_Refine_Backrub";
295 }
296 
297 } // namespace refine
298 } // namespace loop_mover
299 } // namespace loops
300 } // namespace protocols