Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ChunkTrialMover.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
11 /// @brief Wrapper for InsertChunkMover. It can take a random template and steal coordinates of all chunks or a random one
12 /// @detailed
13 /// @author Yifan Song
14 
16 
17 #include <core/pose/PDBInfo.hh>
18 
19 #include <core/id/AtomID.hh>
20 #include <core/id/AtomID_Map.hh>
22 #include <core/fragment/Frame.hh>
26 
27 #include <protocols/loops/Loop.hh>
28 #include <protocols/loops/Loops.hh>
29 #include <protocols/loops/util.hh>
30 
31 #include <ObjexxFCL/format.hh>
32 #include <numeric/xyz.functions.hh>
33 #include <numeric/random/random.hh>
34 #include <numeric/model_quality/rms.hh>
35 #include <numeric/model_quality/maxsub.hh>
36 
37 #include <basic/options/option.hh>
38 #include <basic/options/keys/OptionKeys.hh>
39 #include <basic/options/keys/in.OptionKeys.gen.hh>
40 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
41 #include <basic/options/keys/cm.OptionKeys.gen.hh>
42 #include <basic/options/keys/rigid.OptionKeys.gen.hh>
43 #include <basic/Tracer.hh>
44 
45 static numeric::random::RandomGenerator RG(57029435);
46 static basic::Tracer TR( "protocols.hybridization.ChunkTrialMover" );
47 
48 namespace protocols {
49 namespace hybridization {
50 
51 using namespace core;
52 using namespace core::kinematics;
53 using namespace ObjexxFCL;
54 using namespace protocols::moves;
55 using namespace protocols::loops;
56 using namespace numeric::model_quality;
57 using namespace id;
58 using namespace basic::options;
59 using namespace basic::options::OptionKeys;
60 
62  utility::vector1 < core::pose::PoseCOP > const & template_poses,
63  utility::vector1 < protocols::loops::Loops > const & template_chunks,
64  Loops ss_chunks_pose,
65  bool random_template,
66  AlignOption align_option,
67  Size max_registry_shift ) :
68  template_poses_(template_poses),
69  template_chunks_(template_chunks),
70  random_template_(random_template),
71  align_option_(align_option),
72  align_chunk_(),
73  max_registry_shift_input_(max_registry_shift)
74 {
75  moves::Mover::type( "ChunkTrialMover" );
76  bool alignment_from_template = option[cm::hybridize::alignment_from_template_seqpos]();
77 
78  Size count = 0;
79  for (core::Size i_template=1; i_template<=template_poses_.size(); ++i_template) {
80  if (template_chunks_[i_template].size() != 0) ++count;
81  }
82  if (count == 0) {
83  utility_exit_with_message("Template structures need at least one secondary structure for this protocol");
84  }
85 
86  sequence_alignments_.clear();
87  for (core::Size i_template=1; i_template<=template_poses_.size(); ++i_template) {
88  std::map <core::Size, core::Size> sequence_alignment;
89  //TR << "template: " << i_template << std::endl;
90  sequence_alignment.clear();
91  if (alignment_from_template) {
92  get_alignment_from_template(template_poses_[i_template], sequence_alignment);
93  }
94  else {
95  std::map <core::Size, core::Size> chunk_mapping;
96  if (option[cm::hybridize::alignment_from_chunk_mapping].user()) {
97  for (Size i=1;i<=option[cm::hybridize::alignment_from_chunk_mapping]().size();++i) {
98  chunk_mapping[i] = option[cm::hybridize::alignment_from_chunk_mapping]()[i];
99  }
100  }
101 
102  get_alignment_from_chunk_mapping(chunk_mapping, template_chunks_[i_template], ss_chunks_pose, sequence_alignment);
103  }
104  sequence_alignments_.push_back(sequence_alignment);
105  }
106 }
107 
108 void
110  core::pose::PoseCOP template_pose,
111  std::map <core::Size, core::Size> & seqpos_alignment
112  ) {
113  // specific to this case, alignment comes from residue number
114  for (core::Size ires=1; ires<=template_pose->total_residue(); ++ires) {
115  TR.Debug << "Sequence aln: " << template_pose->pdb_info()->number(ires) << " " << ires << std::endl;
116  seqpos_alignment[template_pose->pdb_info()->number(ires)] = ires;
117  }
118 }
119 
120 void
121 ChunkTrialMover::get_alignment_from_chunk_mapping(std::map <core::Size, core::Size> const & chunk_mapping,
122  Loops const template_ss_chunks,
123  Loops const target_ss_chunks,
124  std::map <core::Size, core::Size> & sequence_alignment)
125 {
126  max_registry_shift_.resize(target_ss_chunks.size());
127  for (Size i_chunk_pose = 1; i_chunk_pose <= target_ss_chunks.size(); ++i_chunk_pose) {
128  if (chunk_mapping.find(i_chunk_pose) == chunk_mapping.end()) continue;
129  core::Size j_chunk_template = chunk_mapping.find(i_chunk_pose)->second;
130 
131  Size respos_mid_pose = (target_ss_chunks[i_chunk_pose].start() + target_ss_chunks[i_chunk_pose].stop()) / 2;
132  Size respos_mid_template = (template_ss_chunks[j_chunk_template].start() + template_ss_chunks[j_chunk_template].stop()) / 2;
133  int offset = respos_mid_template - respos_mid_pose;
134 
135  using namespace ObjexxFCL::fmt;
136  if (target_ss_chunks[i_chunk_pose].length() <= template_ss_chunks[j_chunk_template].length()) {
137  max_registry_shift_[i_chunk_pose] = max_registry_shift_input_ + template_ss_chunks[j_chunk_template].length() - target_ss_chunks[i_chunk_pose].length();
138  for (Size ires=target_ss_chunks[i_chunk_pose].start(); ires<=target_ss_chunks[i_chunk_pose].stop(); ++ires) {
139  sequence_alignment[ires] = ires+offset;
140  //std::cout << I(4, ires) << I(4, ires+offset) << std::endl;
141  }
142  }
143  else {
144  max_registry_shift_[i_chunk_pose] = max_registry_shift_input_ + target_ss_chunks[i_chunk_pose].length() - template_ss_chunks[j_chunk_template].length();
145  for (Size ires_templ=template_ss_chunks[j_chunk_template].start(); ires_templ<=template_ss_chunks[j_chunk_template].stop(); ++ires_templ) {
146  sequence_alignment[ires_templ-offset] = ires_templ;
147  //std::cout << I(4, ires_templ) << I(4, ires_templ-offset) << std::endl;
148  }
149  }
150  }
151 }
152 
154 {
155  assert(template_poses_.size() != 0);
156  set_template(0);
157  int ntrials=500;
158  while (!template_number() && --ntrials>0) {
159  set_template( RG.random_range(1, template_poses_.size()) );
161  }
162  if (ntrials == 0) {
163  utility_exit_with_message( "Fatal error in ChunkTrialMover::pick_random_template()");
164  }
165 }
166 
168 {
170 }
171 
173 {
174  return template_number_;
175 }
176 
178  int ntrials=500;
179  jump_number_ = RG.random_range(1, pose.num_jump());
180  core::Size jump_residue_pose = pose.fold_tree().downstream_jump_residue(jump_number_);
181  while ( pose.residue(jump_residue_pose).aa() == core::chemical::aa_vrt && --ntrials>0) {
182  jump_number_ = RG.random_range(1, pose.num_jump());
183  jump_residue_pose = pose.fold_tree().downstream_jump_residue(jump_number_);
184  }
185  if (ntrials == 0) {
186  utility_exit_with_message( "Fatal error in ChunkTrialMover::pick_random_chunk()");
187  }
188 }
189 
191  return align_chunk_.trial_counter(ires);
192 }
193 
194 void
197 
198  // pick a random template
199  if (random_template_) {
201  }
202  if (ignore_template_indices_.count(template_number())) return;
203 
204  //TR << "templ number: " << template_number() << std::endl;
206  template_number(),
208  );
209 
210  // random chunk or loop all chunks
211  if (align_option_ == random_chunk) {
212  // pick a random jump
213  pick_random_chunk(pose);
215 
216  // apply alignment
217  int registry_shift = RG.random_range(-max_registry_shift_[jump_number_], max_registry_shift_[jump_number_]);
218  align_chunk_.set_registry_shift(registry_shift);
219  align_chunk_.apply(pose);
220  } else {
221  // loop over all jumps (we're initializing)
222  for (core::Size jump_number=1; jump_number<=pose.num_jump(); ++jump_number) {
223  align_chunk_.set_aligned_chunk(pose, jump_number, true);
224 
225  // apply alignment
226  int registry_shift = RG.random_range(-max_registry_shift_[jump_number], max_registry_shift_[jump_number]);
227  align_chunk_.set_registry_shift(registry_shift);
228  align_chunk_.apply(pose);
229  if (!align_chunk_.success()) {
230  TR.Debug << "Warning! This chunk might not be aligned, jump number " << jump_number << std::endl;
231  }
232  }
233  }
234 }
235 
237 {
238  return "ChunkTrialMover";
239 }
240 
241 } // hybridization
242 } // protocols
243