Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JumpRotamerSidechainMover.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 JumpRotamerSidechainMover class and functions
12 /// @author Colin A. Smith (colin.smith@ucsf.edu)
13 
14 
17 
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(18451125);
60 static basic::Tracer tr("protocols.simple_moves.sidechain_moves.JumpRotamerSidechainMover");
61 
62 namespace protocols {
63 namespace simple_moves {
64 namespace sidechain_moves {
65 
66 using namespace chemical;
67 using namespace conformation;
68 
69 
71 JumpRotamerSidechainMoverCreator::keyname() const {
72  return JumpRotamerSidechainMoverCreator::mover_name();
73 }
74 
76 JumpRotamerSidechainMoverCreator::create_mover() const {
77  return new JumpRotamerSidechainMover;
78 }
79 
81 JumpRotamerSidechainMoverCreator::mover_name() {
82  return "JumpRotamerSidechain";
83 }
84 
85 
86 JumpRotamerSidechainMover::JumpRotamerSidechainMover() {
87  protocols::moves::Mover::type( "JumpRotamerSidechain" );
88  set_defaults();
89 }
90 
91 JumpRotamerSidechainMover::JumpRotamerSidechainMover(
92  pack::dunbrack::RotamerLibrary const & rotamer_library
93 ) : Parent( rotamer_library ) {
94  set_defaults();
95 }
96 
98  JumpRotamerSidechainMover const & mover
99 ) : Parent ( mover ) {
100  set_defaults();
101 }
102 
106 }
107 
108 void
110  sample_rotwells_unif_=false;
111 }
112 
113 void
115  utility::tag::TagPtr const /*tag*/,
116  protocols::moves::DataMap & /*data*/,
117  protocols::filters::Filters_map const & /*filters*/,
118  protocols::moves::Movers_map const & /*movers*/,
119  pose::Pose const & /*pose*/
120 ) {
121 
122 }
123 
126  return "JumpRotamerSidechainMover";
127 }
128 
129 
130 void
132  conformation::Residue const& residue,
133  ChiVector const&,
134  ChiVector& new_chi
135 ) {
136 
137  RotamerList rotamers;
138  build_rotamer_list( residue, sample_rotwells_unif_, rotamers );
139 
140  /// temper the well probabilities
141  utility::vector1< Real > rot_probs;
142  Real normalize;
143  bool is_tempered( std::abs( temperature() - 1.0 ) > 0.01 );
144  if ( is_tempered ) {
145  compute_tempered_rotamer_probabilities( rotamers, temperature(), rot_probs, normalize );
146  }
147 
148  /// select a random rotamer
149  Size rotnum;
150  Real rand = RG.uniform();
151  //if ( rand <=0 ){
152  //tr.Debug << "RG.uniform is " << rand << std::endl;}
153  Real const inv_nrot( 1.0/rotamers.size() );
154  Real rot_prob_normalize (0);
155  runtime_assert( !is_tempered );
156  for ( rotnum=1; rotnum <=rotamers.size() &&rand > 0; ++rotnum ) {
157  rot_prob_normalize+=rotamers [rotnum].probability();
158  }
159  //tr.Debug << "rot_prob_normalized is" << rot_prob_normalize << std::endl;
160  for ( rotnum=1; rotnum <= rotamers.size() && rand > 0; ++rotnum ) {
161  if ( sample_rotwells_unif_ ) {
162  rand -= inv_nrot; //pick any rotamer with uniform probability
163  } else {
164  rand -= ( is_tempered ? rot_probs[ rotnum ]*normalize : ( rotamers[ rotnum ].probability()/rot_prob_normalize ));
165  }
166  }
167  if ( rand <= 0 ) {
168  rotnum -= 1;
169  }
170  runtime_assert( rotnum >= 1 && rotnum <= rotamers.size() );
171  //rotamer_sample_data[rotnum].assign_random_chi(last_chi_angles_,RG);
172  rotamers[rotnum].assign_random_chi( new_chi, RG, temperature() );
173 }
174 
175 ///all angles in degree
177  Residue const & new_residue,
178  Size const,
179  chemical::ResidueType const &,
180  utility::vector1<Real> const &
181 ) const {
182  utility::vector1<Real> const & new_chi( new_residue.chi() );
183  using namespace pack::dunbrack;
184  RotamerList rotamers;
185  build_rotamer_list( new_residue, sample_rotwells_unif_, rotamers );
186 
187  Real rot_density;
188  compute_rotdensities( rotamers, new_chi, rot_density );
189 
190  return rot_density;
191 }
192 
193 void
195  RotamerList const& rotamers,
196  ChiVector const& new_chi,
197  Real& rot_density
198 ) const {
199  rot_density=0;
200  //Real max_new_rot_prob(0);
201  //Real max_old_rot_prob(0);
202 
203  utility::vector1< Real > rot_probs;
204  Real normalize;
205  bool is_tempered( std::abs( temperature() - 1.0 ) > 0.01 );
206  if ( is_tempered ) {
207  compute_tempered_rotamer_probabilities( rotamers, temperature(), rot_probs, normalize );
208  }
209 
210  Real norm_prob=0;
211  for ( RotamerList::const_iterator it = rotamers.begin(); it!=rotamers.end(); ++it ) {
212  norm_prob += it->probability();
213  }
214  if ( std::abs( norm_prob - 1.0 ) > 0.00001 ) {
215  tr.Warning << "ALARM: probs are not normalized correctly: " << norm_prob << std::endl;
216  }
217  Real const inv_nrot( 1.0 / rotamers.size() );
218  for ( Size ii = 1; ii <= rotamers.size(); ++ii ) {
219  //for each rotamer evaluate the density at our new chi angles
220  Real const within_well_prob( rotamers[ii].chi_probability( new_chi, temperature() ) );
221 
222  if ( sample_rotwells_unif_ ) {
223  rot_density += inv_nrot * within_well_prob;
224  } else {
225  Real const well_prot( is_tempered ? rot_probs[ ii ]*normalize : rotamers[ii].probability()/norm_prob );
226  rot_density += exp( log( well_prot ) + log( within_well_prob ) );
227  }
228  }
229 }
230 
231 void
233  RotamerList const& rotamers,
234  core::Real,
235  utility::vector1< Real >& rot_probs,
236  core::Real& normalize
237 ) const {
238  rot_probs.clear();
239  rot_probs.resize( rotamers.size() );
240  Real const inv_T( 1.0/Parent::temperature() );
241  Real sum_prob( 0.0 );
242  for ( Size rotnum=1; rotnum <= rotamers.size(); ++rotnum ) {
243  sum_prob+=std::pow( rotamers[ rotnum ].probability(), inv_T );
244  }
245  normalize = 1.0/sum_prob;
246 }
247 
248 
249 
250 
251 
252 } // sidechain_moves
253 } // simple_moves
254 } // protocols