Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StarTreeBuilder.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/StarTreeBuilder.cc
11 /// @author Christopher Miles (cmiles@uw.edu)
12 
13 // Unit headers
15 
16 // C/C++ headers
17 #include <string>
18 #include <utility>
19 
20 // External headers
21 // AUTO-REMOVED #include <boost/format.hpp>
22 // AUTO-REMOVED #include <boost/math/distributions/normal.hpp>
23 #include <boost/unordered/unordered_map.hpp>
24 
25 // Utility headers
26 #include <basic/options/option.hh>
27 #include <basic/options/keys/OptionKeys.hh>
28 #include <basic/options/keys/in.OptionKeys.gen.hh>
29 #include <numeric/util.hh>
30 #include <numeric/xyzVector.hh>
31 #include <numeric/random/DistributionSampler.hh>
32 #include <ObjexxFCL/FArray1D.hh>
33 #include <ObjexxFCL/FArray2D.hh>
34 #include <utility/vector1.hh>
35 
36 // Project headers
37 #include <core/types.hh>
40 #include <core/pose/Pose.hh>
41 #include <core/pose/util.hh>
42 #include <core/scoring/rms_util.hh>
43 #include <protocols/loops/Loop.hh>
44 #include <protocols/loops/Loops.hh>
45 
46 //Auto Headers
48 namespace protocols {
49 namespace nonlocal {
50 
51 // Static member initialization
54 
55 StarTreeBuilder::StarTreeBuilder() : virtual_res_(-1) {}
56 
57 /// Note: assumes <chunks> are sorted in increasing order of start position
59  using core::Size;
60  using core::Real;
63  using utility::vector1;
64 
65  assert(pose);
66  assert(chunks.num_loop());
67 
68  // Number of residues before addition of virtual residue
69  Size num_residues = pose->total_residue();
70 
71  // Add a virtual residue at the center of mass (updates the fold tree)
73  chunks.center_of_mass(*pose, &center);
74  core::pose::addVirtualResAsRoot(center, *pose);
75 
76  // Initialize member variable <virtual_res_> with the index of the newly added
77  // virtual residue. Subsequently, <virtual_res_> can serve as a proxy for
78  // <num_residues>
79  virtual_res_ = pose->total_residue();
80 
81  // Define jumps, cuts
82  vector1<int> cuts;
84  for (Loops::const_iterator i = chunks.begin(); i != chunks.end(); ++i) {
85  const Loop& chunk = *i;
86  const Size cut_point = chunk.stop();
87  const Size jump_point = choose_anchor_position(chunk);
88 
89  cuts.push_back(cut_point);
90  jumps.push_back(std::make_pair(virtual_res_, jump_point));
91  }
92 
93  // Remember to include the original cutpoint at the end of the chain
94  // (before the virtual residue)
95  cuts.push_back(num_residues);
96 
97  ObjexxFCL::FArray2D_int ft_jumps(2, jumps.size());
98  for (Size i = 1; i <= jumps.size(); ++i) {
99  ft_jumps(1, i) = std::min(jumps[i].first, jumps[i].second);
100  ft_jumps(2, i) = std::max(jumps[i].first, jumps[i].second);
101  }
102 
103  ObjexxFCL::FArray1D_int ft_cuts(cuts.size());
104  for (Size i = 1; i <= cuts.size(); ++i) {
105  ft_cuts(i) = cuts[i];
106  }
107 
108  // Construct the star fold tree from the set of jumps and cuts above.
109  // Reorder the resulting fold tree so that <virtual_res> is the root.
111  bool status = tree.tree_from_jumps_and_cuts(virtual_res_, // nres_in
112  jumps.size(), // num_jump_in
113  ft_jumps, // jump_point
114  ft_cuts, // cuts
115  virtual_res_); // root
116  if (!status)
117  utility_exit_with_message("StarTreeBuilder: failed to build fold tree from cuts and jumps");
118 
119  // Update the pose's fold tree
120  pose->fold_tree(tree);
121 
122  // When native is available, compute RMSD over jump residues. Results stored
123  // as comments in the pose with format: rmsd_jump_residue_X rmsd
125 }
126 
128  using namespace basic::options;
129  using namespace basic::options::OptionKeys;
130  using boost::unordered_map;
131  using core::Real;
132  using core::Size;
133  using core::pose::Pose;
134  assert(model);
135 
136  if (!option[OptionKeys::in::file::native].user())
137  return;
138 
139  // Compute RMSD of jump residues (jump point +/- 1 residue)
140  unordered_map<Size, Real> rmsds;
141  Pose native = *core::import_pose::pose_from_pdb(option[OptionKeys::in::file::native]());
142  core::scoring::compute_jump_rmsd(native, *model, &rmsds);
143 
144  // Write results to <model> as comments
145  for (unordered_map<Size, Real>::const_iterator i = rmsds.begin(); i != rmsds.end(); ++i) {
146  Size residue = i->first;
147  Real rmsd = i->second;
149  (boost::format("%1% rmsd_jump_residue_%2%") % prefix % residue).str(),
150  (boost::format("%1%") % rmsd).str());
151  }
152 }
153 
155  assert(pose);
156  if (virtual_res_ == -1) {
157  return;
158  } else {
161  virtual_res_ = -1;
162  }
163 }
164 
165 /// mu- midpoint of the chunk
166 /// sigma- linear function of chunk length
168  using boost::math::normal;
169  using core::Size;
170  using numeric::random::DistributionSampler;
171 
172  double mu = chunk.start() + chunk.length() / 2.0;
173  double sigma = chunk.length() / 5.0;
174  normal distribution(mu, sigma);
175  DistributionSampler<normal> sampler(distribution);
176 
177  // Clamp insertion position to closed interval [start, stop]
178  Size position = static_cast<Size>(sampler.sample());
179  return numeric::clamp<Size>(position, chunk.start(), chunk.stop());;
180 }
181 
182 } // namespace nonlocal
183 } // namespace protocols