Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MedalMover.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 protocols/medal/MedalMover.cc
11 /// @author Christopher Miles (cmiles@uw.edu)
12 
13 // Unit headers
15 
16 // C/C++ headers
17 #include <iomanip>
18 #include <iostream>
19 #include <map>
20 #include <string>
21 
22 // External headers
23 #include <boost/bind.hpp>
24 #include <boost/format.hpp>
25 #include <boost/function.hpp>
26 
27 // Utility headers
28 #include <basic/Tracer.hh>
29 #include <basic/options/option.hh>
30 #include <basic/options/keys/OptionKeys.hh>
31 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
32 #include <basic/options/keys/in.OptionKeys.gen.hh>
33 #include <basic/options/keys/jumps.OptionKeys.gen.hh>
34 #include <basic/options/keys/nonlocal.OptionKeys.gen.hh>
35 #include <basic/options/keys/rigid.OptionKeys.gen.hh>
36 #include <numeric/interpolate.hh>
37 #include <numeric/prob_util.hh>
38 #include <utility/vector1.hh>
39 
40 // Project headers
43 #include <core/fragment/FragSet.hh>
49 #include <core/pose/Pose.hh>
50 #include <core/pose/util.hh>
62 #include <protocols/loops/Loops.hh>
72 
73 // Package headers
74 #include <protocols/medal/util.hh>
75 
76 namespace protocols {
77 namespace medal {
78 
79 typedef boost::function<void(const core::pose::Pose&)> Trigger;
80 
81 static basic::Tracer TR("protocols.medal.MedalMover");
82 
83 void on_pose_accept(const core::pose::Pose& pose) {
87 
88  static int num_accepted = 0;
89 
91  silent->fill_struct(pose, str(boost::format("accepted_pose_%d") % num_accepted++));
92 
93  SilentFileData sfd;
94  sfd.write_silent_struct(*silent, "medal.accepted.out");
95 }
96 
98  const unsigned num_residues,
99  const core::sequence::SequenceAlignment& alignment,
100  const protocols::loops::Loops& chunks,
101  const core::kinematics::FoldTree& tree,
102  const core::fragment::FragSet& fragments,
103  Probabilities* probs) const {
104  using namespace basic::options;
105  using namespace basic::options::OptionKeys;
106  using namespace std;
107  assert(probs);
108 
109  // Override automatic sampling probability computation
110  if (option[OptionKeys::rigid::sampling_prob].user()) {
111  numeric::read_probabilities_or_die(option[OptionKeys::rigid::sampling_prob](), probs);
112  } else {
113  Probabilities p_alignment, p_chunk, p_cut, p_end;
114  alignment_probabilities(num_residues, alignment, &p_alignment);
115  chunk_probabilities(chunks, &p_chunk);
116  cutpoint_probabilities(num_residues, tree, &p_cut);
117  end_bias_probabilities(num_residues, &p_end);
118 
119  // Product of probabilities
120  probs->insert(probs->begin(), p_alignment.begin(), p_alignment.end());
121  numeric::product(probs->begin(), probs->end(), p_chunk.begin(), p_chunk.end());
122  numeric::product(probs->begin(), probs->end(), p_cut.begin(), p_cut.end());
123  numeric::product(probs->begin(), probs->end(), p_end.begin(), p_end.end());
124 
125  // Zero-out probabilities of residues that would allow folding across the cut
126  invalidate_residues_spanning_cuts(tree, fragments.max_frag_length(), probs);
127  numeric::normalize(probs->begin(), probs->end());
128  }
129 
130  // Emit sampling probabilities
131  TR << "Residue" << setw(15) << "Probability" << endl;
132  for (unsigned i = 1; i <= probs->size(); ++i) {
133  TR.Debug << i << fixed << setw(15) << setprecision(5) << (*probs)[i] << endl;
134  }
135  TR.flush_all_channels();
136 }
137 
139  protocols::loops::LoopsOP & chunks) const {
140  using namespace basic::options;
141  using namespace basic::options::OptionKeys;
142  assert(chunks);
143 
144  bool loops_file_specified = option[OptionKeys::nonlocal::chunks].user();
145  if (!loops_file_specified) {
147  return;
148  }
149 
150  // Override automatic chunk selection
151  chunks = new protocols::loops::Loops( option[OptionKeys::nonlocal::chunks]() );
152 }
153 
155  using namespace basic::options;
156  using namespace basic::options::OptionKeys;
159 
160  FragmentIO io;
161  fragments_lg_ = io.read_data(option[in::file::frag9]());
162  fragments_sm_ = io.read_data(option[in::file::frag3]());
163 }
164 
166  using namespace basic::options;
167  using namespace basic::options::OptionKeys;
168  using core::pose::PoseOP;
174  using namespace protocols::moves;
175  using namespace protocols::nonlocal;
176 
177  // Information about the current set of inputs
178  ThreadingJob const * const job = protocols::nonlocal::current_job();
179  const unsigned num_residues = pose.total_residue();
180 
181  // Load the native structure (if available) to compute trajectory analytics
182  PoseOP native;
183  if (option[OptionKeys::in::file::native].user())
184  native = core::import_pose::pose_from_pdb(option[OptionKeys::in::file::native]());
185 
186  // Build up a threading model
187  LoopRelaxThreadingMover closure;
188  closure.setup();
189  closure.apply(pose);
190 
191  // Configure the score functions used in the simulation
194 
195  // Decompose the structure into chunks
196  loops::LoopsOP chunks;
197  decompose_structure(pose, chunks);
198 
199  StarTreeBuilder builder;
200  builder.set_up(*chunks, &pose);
201  TR << pose.fold_tree() << std::endl;
202 
203  // Compute per-residue sampling probabilities
204  Probabilities probs;
205  compute_per_residue_probabilities(num_residues, job->alignment(), *chunks, pose.fold_tree(), *fragments_sm_, &probs);
206 
207  // Alternating rigid body and fragment insertion moves with increasing linear_chainbreak weight.
208  // Early stages select fragments uniformly from the top 25, later stages select fragments according
209  // to Gunn cost using the entire fragment library.
212 
213  const double cb_start = score->get_weight(core::scoring::linear_chainbreak);
214  const double cb_stop = cb_start * 2;
215  const unsigned num_stages = option[OptionKeys::rigid::stages]();
216 
217  for (unsigned stage = 0; stage <= num_stages; ++stage) {
218  score->set_weight(core::scoring::linear_chainbreak,
219  numeric::linear_interpolate(cb_start, cb_stop, stage, num_stages));
220 
221  MoverOP mover =
222  create_fragment_and_rigid_mover(pose, native, score, fragments_sm_, probs,
223  (stage < (num_stages / 2)) ? "uniform" : "smooth",
224  (stage < (num_stages / 2)) ? 25 : 200);
225 
226  mover->apply(pose);
227  }
228 
229  // Alternating small and shear moves
230  MoverOP mover = create_small_mover(native, score);
231  mover->apply(pose);
233 
234  // Loop closure
235  builder.tear_down(&pose);
236  do_loop_closure(&pose);
237 
238  // Return to centroid representation and rescore
240  score->show(TR, pose);
241 }
242 
244  using namespace basic::options;
245  using namespace basic::options::OptionKeys;
250  assert(pose);
251 
252  if (!option[OptionKeys::rigid::close_loops]() || !ChainbreakUtil::has_chainbreak(*pose))
253  return;
254 
255  // Choose chainbreaks automatically
256  LoopsOP empty = new protocols::loops::Loops();
258  closure.remodel("quick_ccd");
259  closure.intermedrelax("no");
260  closure.refine("no");
261  closure.relax("no");
262  closure.loops(empty);
263 
265  fragments.push_back(fragments_sm_);
266  closure.frag_libs(fragments);
267 
268  // Use atom pair constraints when available
269  closure.cmd_line_csts(option[constraints::cst_fa_file].user());
270 
271  // Simple kinematics
272  FoldTree tree(pose->total_residue());
273  pose->fold_tree(tree);
274  closure.apply(*pose);
275 }
276 
277 /// @detail Configures the score function used during the simulation.
278 /// Precedence:
279 /// 1. User-specified patch file (i.e. -rigid:patch)
280 /// 2. User-specified options (e.g. -jumps:increase_chainbreak)
281 /// 3. Default values
283  using namespace basic::options;
284  using namespace basic::options::OptionKeys;
288 
290  option[OptionKeys::rigid::score]());
291 
292  // Configure constraints
294 
295  EnergyMethodOptions options(score->energy_method_options());
296  options.cst_max_seq_sep(option[OptionKeys::rigid::sequence_separation]());
297  score->set_energy_method_options(options);
298 
299  // Override default energy terms, weights
300  if (option[OptionKeys::rigid::patch].user()) {
301  score->apply_patch_from_file(option[OptionKeys::rigid::patch]());
302  return score;
303  }
304 
305  // Default energy terms, weights
306  score->set_weight(core::scoring::hbond_lr_bb, 0.5);
307  score->set_weight(core::scoring::hbond_sr_bb, 0.5);
308  score->set_weight(core::scoring::linear_chainbreak, option[OptionKeys::jumps::increase_chainbreak]());
309  return score;
310 }
311 
313  return "MedalMover";
314 }
315 
317  return new MedalMover(*this);
318 }
319 
321  return new MedalMover();
322 }
323 
327  core::fragment::FragSetOP fragments,
328  const Probabilities& probs,
329  const std::string& policy,
330  unsigned library_size) const {
331 
332  using namespace basic::options;
333  using namespace basic::options::OptionKeys;
334  using namespace protocols::moves;
335  using namespace protocols::simple_moves::rational_mc;
336  using namespace protocols::nonlocal;
337 
338  MoverOP fragment_mover = new BiasedFragmentMover(PolicyFactory::get_policy(policy, fragments, library_size), probs);
339 
340  RationalMonteCarloOP mover =
341  new RationalMonteCarlo(fragment_mover, score,
342  option[OptionKeys::rigid::fragment_cycles](),
343  option[OptionKeys::rigid::temperature](),
344  true);
345 
346  // Optionally record accepted moves
347  if (option[OptionKeys::rigid::log_accepted_moves]())
348  mover->add_trigger(boost::bind(&on_pose_accept, _1));
349 
350  return mover;
351 }
352 
354  const core::pose::Pose& pose,
357  core::fragment::FragSetOP fragments,
358  const Probabilities& probs,
359  const std::string& policy,
360  unsigned library_size) const {
361 
362  using namespace basic::options;
363  using namespace basic::options::OptionKeys;
364  using namespace protocols::moves;
365  using namespace protocols::simple_moves::rational_mc;
366  using namespace protocols::nonlocal;
367 
368  CyclicMoverOP meta = new CyclicMover();
369  meta->enqueue(new rigid::RigidBodyMotionMover(pose.fold_tree()));
370  meta->enqueue(new BiasedFragmentMover(PolicyFactory::get_policy(policy, fragments, library_size), probs));
371 
372  RationalMonteCarloOP mover =
373  new RationalMonteCarlo(meta,
374  score,
375  option[OptionKeys::rigid::fragment_cycles](),
376  option[OptionKeys::rigid::temperature](),
377  true);
378 
379  // Optionally record accepted moves
380  if (option[OptionKeys::rigid::log_accepted_moves]())
381  mover->add_trigger(boost::bind(&on_pose_accept, _1));
382 
383  return mover;
384 }
385 
387  using namespace basic::options;
388  using namespace basic::options::OptionKeys;
389  using namespace protocols::moves;
390  using namespace protocols::simple_moves::rational_mc;
393 
394  MoveMapOP movable = new MoveMap();
395  movable->set_bb(true);
396 
397  CyclicMoverOP meta = new CyclicMover();
398  meta->enqueue(new protocols::simple_moves::SmallMover(movable,
399  option[OptionKeys::rigid::temperature](),
400  option[OptionKeys::rigid::residues_backbone_move]()));
401 
402  meta->enqueue(new protocols::simple_moves::ShearMover(movable,
403  option[OptionKeys::rigid::temperature](),
404  option[OptionKeys::rigid::residues_backbone_move]()));
405 
406  RationalMonteCarloOP mover =
407  new RationalMonteCarlo(meta,
408  score,
409  option[OptionKeys::rigid::small_cycles](),
410  option[OptionKeys::rigid::temperature](),
411  true);
412 
413  // Optionally record accepted moves
414  if (option[OptionKeys::rigid::log_accepted_moves]())
415  mover->add_trigger(boost::bind(&on_pose_accept, _1));
416 
417  return mover;
418 }
419 
420 } // namespace medal
421 } // namespace protocols