Rosetta 3.5
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
protocols
nonlocal
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
14
#include <
protocols/nonlocal/BiasedFragmentMover.hh
>
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
>
33
#include <
core/fragment/FrameIterator.hh
>
34
#include <
core/kinematics/FoldTree.hh
>
35
#include <
core/kinematics/MoveMap.hh
>
36
#include <
core/pose/Pose.hh
>
37
#include <
protocols/moves/Mover.hh
>
38
39
// Package headers
40
#include <
protocols/nonlocal/Policy.hh
>
41
42
#include <
core/fragment/FrameIteratorWorker_.hh
>
43
44
//Auto Headers
45
#include <numeric/random/random.fwd.hh>
46
47
namespace
protocols {
48
namespace
nonlocal {
49
50
typedef
utility::vector1<double>
Probabilities
;
51
52
BiasedFragmentMover::BiasedFragmentMover
(
const
PolicyOP
& policy,
const
Probabilities
& pdf)
53
: policy_(policy), pdf_(pdf) {
54
assert(policy);
55
fragments_
= policy->fragments();
56
initialize_library
();
57
initialize_probabilities
();
58
59
// Avoid repeated MoveMap construction in apply()
60
movable_
.
set_bb
(
true
);
61
}
62
63
/// @detail Creates a position-indexable Frame lookup
64
void
BiasedFragmentMover::initialize_library
() {
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.
73
void
BiasedFragmentMover::initialize_probabilities
() {
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
79
void
BiasedFragmentMover::verify_probabilities_or_die
(
const
core::kinematics::FoldTree
& tree)
const
{
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
95
void
BiasedFragmentMover::apply
(
core::pose::Pose
& pose) {
96
// Verify user-specified sampling probabilities
97
verify_probabilities_or_die
(pose.
fold_tree
());
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
108
unsigned
BiasedFragmentMover::random_position
()
const
{
109
Probabilities::const_iterator i = std::lower_bound(
cdf_
.begin(),
cdf_
.end(), numeric::random::uniform());
110
return
i -
cdf_
.begin() + 1;
111
}
112
113
std::string
BiasedFragmentMover::get_name
()
const
{
114
return
"BiasedFragmentMover"
;
115
}
116
117
}
// namespace nonlocal
118
}
// namespace protocols
Generated on Sat Jun 1 2013 12:01:42 for Rosetta 3.5 by
1.8.4