Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PerturbRotamerSidechainMover.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/simple_moves/sidechain_moves/SidechainMoverBase.cc
11 /// @brief implementation of PerturbRotamerSidechainMover class and functions
12 /// @author Oliver Lange ( oliver.lange@tum.de )
13 
14 
18 // Procols Headers
20 
21 // Core Headers
26 #include <core/id/DOF_ID_Range.hh>
27 #include <core/id/TorsionID.hh>
31 #include <core/pose/Pose.hh>
36 #include <core/types.hh>
37 #include <basic/Tracer.hh>
38 #include <basic/basic.hh>
39 #include <basic/prof.hh>
40 
41 // Numeric Headers
42 #include <numeric/angle.functions.hh>
43 #include <numeric/constants.hh>
44 #include <numeric/conversions.hh>
45 #include <numeric/random/random.hh>
46 
47 // Utility
48 #include <utility/string_util.hh>
49 #include <utility/tag/Tag.hh>
50 #include <utility/exit.hh>
51 
52 // C++ Headers
53 #include <sstream>
54 #include <fstream>
55 #include <utility/fixedsizearray1.hh>
56 using namespace core;
57 using namespace core::pose;
58 
59 static numeric::random::RandomGenerator RG(18611125);
60 static basic::Tracer TR("protocols.simple_moves.sidechain_moves.PerturbRotamerSidechainMover");
61 
62 namespace protocols {
63 namespace simple_moves {
64 namespace sidechain_moves {
65 
66 using namespace chemical;
67 using namespace conformation;
68 
69 
71 PerturbRotamerSidechainMoverCreator::keyname() const {
72  return PerturbRotamerSidechainMoverCreator::mover_name();
73 }
74 
76 PerturbRotamerSidechainMoverCreator::create_mover() const {
78 }
79 
81 PerturbRotamerSidechainMoverCreator::mover_name() {
82  return "PerturbRotamerSidechain";
83 }
84 
85 
86 PerturbRotamerSidechainMover::PerturbRotamerSidechainMover() {
87  protocols::moves::Mover::type( "PerturbRotamerSidechain" );
88  set_defaults();
89 }
90 
91 PerturbRotamerSidechainMover::PerturbRotamerSidechainMover(
92  pack::dunbrack::RotamerLibrary const & rotamer_library
93 ) : Parent( rotamer_library ) {
94  protocols::moves::Mover::type( "PerturbRotamerSidechain" );
95  set_defaults();
96 }
97 
99  PerturbRotamerSidechainMover const & mover
100 ) : Parent ( mover ) {
101  set_defaults();
102 }
103 
107 }
108 
109 void
111  temperature_ = 1;
112 }
113 
114 void
116  utility::tag::TagPtr const /*tag*/,
117  protocols::moves::DataMap & /*data*/,
118  protocols::filters::Filters_map const & /*filters*/,
119  protocols::moves::Movers_map const & /*movers*/,
120  pose::Pose const & /*pose*/
121 ) {
122 
123 }
124 
127  return "PerturbRotamerSidechainMover";
128 }
129 
130 void
132  Residue const& residue,
133  ChiVector const& old_chi,
134  ChiVector& new_chi
135 ) {
136 
137  RotamerList rotamers;
138  build_rotamer_list( residue, false, rotamers );
139 
140  // find the rotamer that has the highest probability of proposing the previous chi angles
141  Real max_rot_prob = 0;
142  Size max_rot_num = 0;
143  //Real rot_prob_normalize (0);
144 
145  for (Size ii = 1; ii <= rotamers.size() ; ++ii) {
146  //TR << "rotamer.size is " << rotamers.size() << " rotamer number is " << ii << std::endl;
147  Real rot_prob( rotamers[ii].chi_probability( old_chi, temperature_ )*rotamers[ ii ].probability());
148  //Real rot_prob( rotamers[ii].chi_probability( old_chi, temperature_ ));
149  if ( rot_prob > max_rot_prob ) {
150  max_rot_num = ii;
151  max_rot_prob = rot_prob;
152  }
153  //TR << "number is " << ii << " rot_prob is " << rot_prob << std::endl;
154  }
155 
156  new_chi=old_chi;
157  //TR << " max_rot_num is " << max_rot_num << std::endl;
158  rotamers[ max_rot_num ].assign_random_chi( new_chi, RG, temperature_ );
159  //TR << " new chi is " << new_chi << std::endl;
160 }
161 
162 ///all angles in degree
164  Residue const & new_residue,
165  Size const,
166  chemical::ResidueType const &,
167  ChiVector const& old_chi /* in degree */
168 ) const {
169 
170  utility::vector1<Real> const & new_chi( new_residue.chi() );
171 
172  RotamerList rotamers;
173  build_rotamer_list( new_residue, false /*no filtering*/, rotamers );
174 
175  //Real rot_density;
176  Real within_rot_density;
177  //compute_rotdensities( rotamers, old_chi, new_chi, within_rot_density );
178  compute_rotdensities( rotamers, old_chi, new_chi, within_rot_density );
179  return within_rot_density;
180 }
181 
182 ///all angles in degree
183 void
185  Residue const& residue,
186  bool filter_low_probabilities,
187  RotamerList& rotamers
188 ) const {
189  using namespace pack::dunbrack;
190  rotamers.clear();
191  rotamers.reserve( 200 ); //no idea but that should be plenty.
192 
193  SingleResidueRotamerLibraryCAP residue_rotamer_library(
194  rotamer_library().get_rsd_library( residue.type() )
195  );
196 
197  SingleResidueDunbrackLibraryCAP residue_dunbrack_library(
198  dynamic_cast< SingleResidueDunbrackLibrary const * >( residue_rotamer_library.get() )
199  );
200 
201  if ( !residue_dunbrack_library ) return;
202 
203  //get phi-psi dependent rotamer library
204  Real const phi( residue_dunbrack_library->get_phi_from_rsd( residue ) );
205  Real const psi( residue_dunbrack_library->get_psi_from_rsd( residue ) );
206  RotamerList rotamers_raw( residue_dunbrack_library->get_all_rotamer_samples( phi, psi ) );
207 
208  //make short list of most probable rotamers
209  if ( !filter_low_probabilities ) {
210  rotamers=rotamers_raw;
211  } else {
212  utility::vector1< DunbrackRotamerSampleData > most_probable_rotamers;
213  most_probable_rotamers.reserve( rotamers.size() );
214  Real probability_threshold = 0.01;
215  Size i = 1;
216  while ( i <= rotamers.size() &&
217  rotamers[ i ].probability() > probability_threshold ) {
218  rotamers.push_back( rotamers[ i ] );
219  i++;
220  }
221  }
222 }
223 
224 void
226  RotamerList const& rotamers,
227  ChiVector const& old_chi,
228  ChiVector const& new_chi,
229  Real& within_rot_density
230 ) const {
231 
232  Real max_new_rot_prob(0);
233  Real max_old_rot_prob(0);
234  Real norm_prob(0);
235  //Real const inv_nrot( 1.0 / rotamers.size() );
236 
237  for (Size jj=1; jj <= rotamers.size(); ++jj) {
238  norm_prob+=rotamers[jj].probability();
239  }
240  //if ( std::abs( norm_prob - 1.0 ) > 0.00001 ) {
241  //TR.Warning << "ALARM: probs are not normalized correctly: " << norm_prob << std::endl;
242  //}
243 
244  for ( Size ii = 1; ii <= rotamers.size(); ++ii ) {
245  //for each rotamer evaluate the density at our new chi angles
246  Real well_prob( rotamers[ii].probability() );
247  Real const new_rot_prob( rotamers[ii].chi_probability( new_chi, temperature() )*well_prob );
248 
249  Real const old_rot_prob( rotamers[ii].chi_probability( old_chi, temperature() )*well_prob );
250  if (old_rot_prob > max_old_rot_prob) {
251  max_old_rot_prob = old_rot_prob;
252  max_new_rot_prob = new_rot_prob;
253  }
254  }
255  within_rot_density = max_new_rot_prob;
256 }
257 
258 
259 
260 } // sidechain_moves
261 } // simple_moves
262 } // protocols