Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SmoothPolicy.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/SmoothPolicy.cc
11 /// @author Christopher Miles (cmiles@uw.edu)
12 
13 // Unit header
15 
16 // C/C++ headers
17 #include <cmath>
18 
19 // Utility headers
20 #include <numeric/random/WeightedReservoirSampler.hh>
21 #include <utility/minmax.hh>
22 #include <utility/vector1.hh>
23 
24 // Project headers
25 #include <core/types.hh>
26 #include <core/fragment/FragSet.hh>
27 #include <core/fragment/Frame.hh>
28 
29 //Auto Headers
30 namespace protocols {
31 namespace nonlocal {
32 
34 
35 /// @brief Convenience method for retrieving the single highest-weighted sample
36 core::Size make_selection(numeric::random::WeightedReservoirSampler<core::Size>* sampler) {
37  assert(sampler);
39  sampler->samples(&results);
40  return results[1];
41 }
42 
44  : Policy(fragments) {}
45 
47  const core::pose::Pose& pose) {
48  using core::Size;
49  using numeric::random::WeightedReservoirSampler;
50  assert(frame.nr_frags() > 0);
51 
52  ScoreList scores;
53  scorer_.score(frame, pose, scores);
54 
55  WeightedReservoirSampler<Size> sampler(1);
56  for (Size i = 1; i <= scores.size(); ++i) {
57  double score = scores[i];
58  double fitness = std::sqrt(scorer_.cutoff() - score);
59 
60  if (score < scorer_.cutoff()) {
61  sampler.consider_sample(i, fitness);
62  }
63  }
64 
65  // If no candidates met the score threshold, return the best scoring fragment.
66  // Otherwise, randomly choose among the candidates by score.
67  if (sampler.num_considered() == 0) {
68  return utility::argmin(scores);
69  } else {
70  return make_selection(&sampler);
71  }
72 }
73 
74 } // namespace nonlocal
75 } // namespace protocols