Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WeightedFragmentTrialMover.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 Fragment insertion and trial, each residue has a customized weight for the frequency of insertion
12 /// @author Yifan Song
13 
15 
16 #include <core/fragment/Frame.hh>
18 
19 #include <numeric/random/random.hh>
20 #include <utility/exit.hh>
21 
22 static numeric::random::RandomGenerator RG(8401848);
23 
24 namespace protocols {
25 namespace hybridization {
26 
29  utility::vector1< core::Real > const residue_weights,
30  utility::vector1< core::Size > const anchor_residues,
31  core::Size const nr_frags)
32 {
33  moves::Mover::type( "WeightedFragmentTrialMover" );
34  frag_libs_ = frag_libs;
35  anchor_reses_ = anchor_residues;
36  weighted_sampler_.resize(frag_libs.size());
37  update_sampler_weights(residue_weights);
38  nr_frags_ = nr_frags;
39 }
40 
42 {
43  total_frames_ = 0;
44  for (Size i_frag_set = 1; i_frag_set<=frag_libs_.size(); ++i_frag_set) {
45  utility::vector1< core::Real > frame_weights(frag_libs_[i_frag_set]->nr_frames(), 0.0);
46  for (Size i_frame = 1; i_frame <= frag_libs_[i_frag_set]->nr_frames(); ++i_frame) {
47  core::fragment::FrameIterator frame_it = frag_libs_[i_frag_set]->begin(); // first frame of the fragment library
48  advance(frame_it, i_frame-1); // point frame_it to the i_frame of the library
49  core::Size seqpos_start = (*frame_it)->start(); // find starting and ending residue seqpos of the inserted fragment
50  core::Size seqpos_end = (*frame_it)->end();
51 
52  // disallow insertion across anchors
53  bool cross_anchor = false;
54  for (Size i_anchor = 1; i_anchor <= anchor_reses_.size() && !cross_anchor; ++i_anchor) {
55  if (anchor_reses_[i_anchor]>=seqpos_start && anchor_reses_[i_anchor]<=seqpos_end) cross_anchor = true;
56  }
57  if (cross_anchor) continue;
58 
59  for (Size seqpos = seqpos_start; seqpos <= seqpos_end; ++seqpos) { // accumulate the weights of all residues in the fragment
60  if (seqpos < 1 || seqpos > residue_weights.size()) {
61  utility_exit_with_message("FATAL. Fragment library size doesn't match with the size of protein.");
62  }
63  frame_weights[i_frame] += residue_weights[seqpos];
64  }
65  if (frame_weights[i_frame] > 0.0) total_frames_++;
66  }
67  weighted_sampler_[i_frag_set].weights(frame_weights);
68  }
69 }
70 
72 {
73  // pick fragment set
74  Size i_frag_set = RG.random_range(1, frag_libs_.size());
75  // pick insertion position
76  Size insert_pos = weighted_sampler_[i_frag_set].random_sample(RG);
77 
78  core::fragment::FrameIterator frame_it = frag_libs_[i_frag_set]->begin();
79  advance(frame_it, insert_pos-1);
80  core::Size nr_frags = frame_it->nr_frags();
81  if (nr_frags_ && nr_frags_ < nr_frags) nr_frags = nr_frags_;
82  Size i_frag = RG.random_range(1, nr_frags);
83 
84  frame_it->apply( i_frag, pose );
85 }
86 
88 {
89  return "WeightedFragmentTrialMover";
90 }
91 
92 } // hybridization
93 } // protocols