Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Extender.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/star/Extender.cc
11 /// @author Christopher Miles (cmiles@uw.edu)
12 
13 // Unit header
15 
16 // Utility headers
17 #include <basic/options/option.hh>
18 #include <basic/options/keys/OptionKeys.hh>
19 #include <basic/options/keys/abinitio.OptionKeys.gen.hh>
20 #include <numeric/random/random.hh>
21 #include <numeric/random/WeightedReservoirSampler.hh>
22 #include <utility/exit.hh>
23 #include <utility/vector1.hh>
24 
25 // Project headers
33 #include <core/pose/Pose.hh>
34 #include <core/scoring/rms_util.hh>
37 #include <protocols/loops/Loop.hh>
38 #include <protocols/loops/Loops.hh>
39 #include <protocols/loops/util.hh>
40 
41 namespace protocols {
42 namespace star {
43 
44 using core::Real;
45 using core::Size;
46 using core::pose::Pose;
47 using utility::vector1;
48 
49 static const Real EXT_PHI = -150;
50 static const Real EXT_PSI = +150;
51 static const Real EXT_OMG = +180;
52 
53 void generate_extended_pose(Pose* extended_pose, const std::string& sequence) {
54  core::pose::make_pose_from_sequence(*extended_pose, sequence, "centroid");
55 
56  for (Size i = 1; i <= extended_pose->total_residue(); ++i) {
57  extended_pose->set_phi(i, EXT_PHI);
58  extended_pose->set_psi(i, EXT_PSI);
59  extended_pose->set_omega(i, EXT_OMG);
60  }
61 }
62 
63 void copy_residues(const Pose& src, Size start, Size stop, Pose* dst) {
64  using core::id::AtomID;
66 
67  for (Size i = start; i <= stop; ++i) {
68  const Residue& r = src.conformation().residue(i);
69 
70  for (Size j = 1; j <= r.natoms(); ++j) {
71  AtomID id(j, i);
72  dst->set_xyz(id, src.xyz(id));
73  }
74  }
75 }
76 
78  : alignment_(alignment), num_residues_(num_residues) {
81  using namespace basic::options;
82  using namespace basic::options::OptionKeys;
83 
84  assert(alignment);
85  assert(num_residues > 0);
86 
87  SequenceMapping mapping = alignment->sequence_mapping(1, 2);
88  vector1<int> unaligned_res;
89 
90  for (int i = 1; i < num_residues; ++i) {
91  // unaligned: current residue doesn't map to any residue in the template
92  // broke: current residue and next residue are both aligned, but not to consecutive residues in the template
93  bool curr_aligned = mapping[i];
94  bool next_aligned = mapping[i + 1];
95  bool broke = (mapping[i] + 1 != mapping[i + 1]) && next_aligned;
96 
97  if (!curr_aligned) {
98  unaligned_res.push_back(i);
99  } else if (broke) {
100  unaligned_res.push_back(i);
101  unaligned_res.push_back(i+1);
102  }
103  }
104 
105  if (!mapping[num_residues]) { // last residue
106  unaligned_res.push_back(num_residues);
107  }
108 
109  std::sort(unaligned_res.begin(), unaligned_res.end());
110  vector1<int>::const_iterator i = std::unique(unaligned_res.begin(), unaligned_res.end());
111  unaligned_res.resize(i - unaligned_res.begin());
112 
113  int min_len = option[OptionKeys::abinitio::star::min_unaligned_len]();
114  unaligned_ = protocols::comparative_modeling::pick_loops_unaligned(num_residues, unaligned_res, min_len);
115  unaligned_->sequential_order();
116 
117  aligned_ = new Loops(unaligned_->invert(num_residues));
118  aligned_->sequential_order();
119 }
120 
124 
125  if (aligned_->num_loop() != 2) {
126  utility_exit_with_message("Unsupported operation");
127  }
128 
129  // Keep track of the cutpoints we introduce
130  cutpoints_.clear();
131 
132  const Pose reference = *pose;
133 
134  generate_extended_pose(pose, reference.sequence());
135  core::scoring::calpha_superimpose_pose(*pose, reference);
136 
137  const Loop& f1 = (*aligned_)[1];
138  const Loop& f2 = (*aligned_)[2];
139 
140  FoldTree l2r, r2l;
143 
144  pose->fold_tree(r2l);
145  copy_residues(reference, f1.start(), f1.stop(), pose);
147 
148  pose->fold_tree(l2r);
150 
151  copy_residues(reference, f2.start(), f2.stop(), pose);
153 
154  unsigned cut = choose_cutpoint(f1.stop() + 1, f2.start() - 1);
155  cutpoints_.push_back(cut);
156 }
157 
158 int Extender::choose_cutpoint(int start, int stop) const {
159  using numeric::random::WeightedReservoirSampler;
160  assert(start > 0);
161  assert(start <= stop);
162 
163  if (!pred_ss_) {
164  return numeric::random::random_range(start, stop);
165  }
166 
167  WeightedReservoirSampler<int> sampler(1);
168 
169  for (int i = start; i <= stop; ++i) {
170  double weight = pred_ss_->loop_fraction(i) + 1e-20;
171  sampler.consider_sample(i, weight);
172  }
173 
174  vector1<int> samples;
175  sampler.samples(&samples);
176  return samples[1];
177 }
178 
179 } // namespace star
180 } // namespace protocols