Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
util.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/util.cc
11 /// @author Christopher Miles (cmiles@uw.edu)
12 
13 // Unit headers
14 #include <protocols/medal/util.hh>
15 
16 // C/C++ headers
17 #include <cmath>
18 #include <set>
19 
20 // External headers
21 #include <boost/unordered/unordered_set.hpp>
22 
23 // Utility headers
24 #include <numeric/prob_util.hh>
25 #include <utility/iter_util.hh>
26 #include <utility/vector1.hh>
27 
28 // Project headers
29 #include <core/types.hh>
33 #include <core/pose/Pose.hh>
36 #include <protocols/loops/Loop.hh>
37 #include <protocols/loops/Loops.hh>
38 
39 namespace protocols {
40 namespace medal {
41 
43 
44 /// @brief Lower sampling probability near termini
45 void end_bias_probabilities(const unsigned num_residues, Probabilities* p) {
46  assert(p);
47 
48  // Penalize 10% lowest, highest residues
49  const unsigned offset_left = static_cast<unsigned>(std::ceil(0.1 * num_residues));
50  const unsigned offset_right = num_residues - offset_left + 1;
51 
52  p->clear();
53  for (unsigned i = 1; i <= num_residues; ++i) {
54  bool near_terminus = i <= offset_left || i >= offset_right;
55  p->push_back(near_terminus ? 0.2 : 0.8);
56  }
57  numeric::normalize(p->begin(), p->end());
58 }
59 
60 void alignment_probabilities(const unsigned num_residues,
61  const core::sequence::SequenceAlignment& alignment,
62  Probabilities* p) {
63  assert(p);
64 
65  p->clear();
66  core::id::SequenceMapping mapping = alignment.sequence_mapping(1, 2);
67  for (unsigned i = 1; i <= num_residues; ++i) {
68  p->push_back(mapping[i] > 0 ? 0.2 : 0.8);
69  }
70  numeric::normalize(p->begin(), p->end());
71 }
72 
73 /// @detail Linear voting based on chunk length
74 /// Assumes <chunks> are in ascending order
78  assert(p);
79 
80  p->clear();
81  for (Loops::const_iterator i = chunks.begin(); i != chunks.end(); ++i) {
82  const Loop& chunk = *i;
83  for (unsigned j = chunk.start(); j <= chunk.stop(); ++j) {
84  p->push_back(chunk.length());
85  }
86  }
87  numeric::normalize(p->begin(), p->end());
88 }
89 
90 void cutpoint_probabilities(const unsigned num_residues, const core::kinematics::FoldTree& tree, Probabilities* p) {
91  assert(p);
92 
93  // List of cutpoints sorted by position
94  std::set<unsigned> cutpoints;
95  for (int i = 1; i <= tree.num_cutpoint(); ++i) {
96  unsigned cutpoint = tree.cutpoint(i);
97  if (cutpoint == num_residues) // cutpoint at end of chain
98  continue;
99 
100  cutpoints.insert((unsigned)cutpoint);
101  }
102 
103  p->clear();
104  for (unsigned residue = 1; residue <= num_residues; ++residue) {
105  const double nearest_cutpoint = *utility::find_closest(cutpoints.begin(), cutpoints.end(), residue);
106  const double distance = std::abs(nearest_cutpoint - residue);
107  p->push_back(std::pow(distance + 1, -3));
108  }
109  numeric::normalize(p->begin(), p->end());
110 }
111 
112 /// @detail Given a fold tree and fragment library, zero out residues whose modification
113 /// would span a cutpoint boundary
115  const core::Size fragment_len,
116  Probabilities* probs) {
117  for (int i = 1; i <= tree.num_cutpoint(); ++i) {
118  const unsigned cutpoint = tree.cutpoint(i);
119  for (unsigned j = (cutpoint - fragment_len + 2); j <= cutpoint; ++j) {
120  (*probs)[j] = 0;
121  }
122  }
123 }
124 
125 void as_set(protocols::loops::LoopsCOP loops, boost::unordered_set<core::Size>* s) {
126  assert(s);
127  assert(loops);
128 
129  s->clear();
130 
131  for (protocols::loops::Loops::const_iterator i = loops->begin(); i != loops->end(); ++i) {
132  for (core::Size j = i->start(); j <= i->stop(); ++j) {
133  s->insert(j);
134  }
135  }
136 }
137 
139  assert(pose);
140  if (!pose->is_centroid())
142 }
143 
144 } // namespace medal
145 } // namespace protocols