Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BiasedFragmentMover.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/nonlocal/BiasedFragmentMover.cc
11 /// @author Christopher Miles (cmiles@uw.edu)
12 
13 // Unit header
15 
16 // C/C++ headers
17 #include <algorithm>
18 #include <iterator>
19 #include <string>
20 
21 // External headers
22 #include <boost/format.hpp>
23 
24 // Utility headers
25 #include <numeric/prob_util.hh>
26 // AUTO-REMOVED #include <numeric/random/random.hh>
27 #include <utility/exit.hh>
28 #include <utility/vector1.hh>
29 
30 // Project headers
31 #include <core/fragment/FragSet.hh>
32 #include <core/fragment/Frame.hh>
36 #include <core/pose/Pose.hh>
37 #include <protocols/moves/Mover.hh>
38 
39 // Package headers
41 
43 
44 //Auto Headers
45 #include <numeric/random/random.fwd.hh>
46 
47 namespace protocols {
48 namespace nonlocal {
49 
51 
53  : policy_(policy), pdf_(pdf) {
54  assert(policy);
55  fragments_ = policy->fragments();
58 
59  // Avoid repeated MoveMap construction in apply()
60  movable_.set_bb(true);
61 }
62 
63 /// @detail Creates a position-indexable Frame lookup
65  unsigned position;
66  for (core::fragment::FrameIterator i = fragments_->begin(); i != fragments_->end(); ++i) {
67  position = (*i)->start();
68  frames_[position] = **i;
69  }
70 }
71 
72 /// @detail Computes cdf from pdf. cumulative() takes care of normalization.
74  std::copy(pdf_.begin(), pdf_.end(), std::back_inserter(cdf_));
75  numeric::cumulative(cdf_.begin(), cdf_.end());
76 }
77 
78 /// @detail Verifies that the probability of selecting invalid positions is 0
80  const unsigned fragment_len = fragments_->max_frag_length();
81 
82  for (int i = 1; i <= tree.num_cutpoint(); ++i) {
83  const unsigned cutpoint = tree.cutpoint(i);
84 
85  // In order to avoid folding across the cut, certain residues must have zero probability of selection
86  for (unsigned j = (cutpoint - fragment_len + 2); j <= cutpoint; ++j) {
87  const double prob = pdf_[j];
88  if (prob > 0) {
89  utility_exit_with_message((boost::format("Non-zero selection probability for unmodifiable residue %1%") % j).str());
90  }
91  }
92  }
93 }
94 
96  // Verify user-specified sampling probabilities
98 
99  // Select insertion position and fragment
100  const unsigned insertion_pos = random_position();
101  const core::fragment::Frame& frame = frames_[insertion_pos];
102  const unsigned fragment_num = policy_->choose(frame, pose);
103 
104  frame.apply(movable_, fragment_num, pose);
105 }
106 
107 /// @detail Selects the insertion position in a weighted random fashion using binary search on the cdf
109  Probabilities::const_iterator i = std::lower_bound(cdf_.begin(), cdf_.end(), numeric::random::uniform());
110  return i - cdf_.begin() + 1;
111 }
112 
114  return "BiasedFragmentMover";
115 }
116 
117 } // namespace nonlocal
118 } // namespace protocols