Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ContinuousRotamerSet.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 core/pack/RotamerSet/ContinuousRotamerSet.cc
11 /// @brief Implementation of the ContinuousRotamerSet and ContinuousRotamerSets classes
12 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
13 
14 // Unit Headers
16 
17 // Package Headers
21 
22 // Project Headers
25 #include <core/pose/Pose.hh>
26 
27 // Utility headers
28 #include <utility/exit.hh>
29 
31 #include <utility/vector1.hh>
32 
33 
34 namespace core {
35 namespace pack {
36 namespace rotamer_set {
37 
38 /// @details Auto-generated virtual destructor
40 
41 
43  resid_( 0 ),
44  input_rotamer_samplingrot_index_( 0 ),
45  input_rotamer_rotblock_( 0 ),
46  n_restypes_( 0 ),
47  n_baserots_total_( 0 ),
48  n_samplingrots_total_( 0 )
49 {}
50 
52 
54  pose::Pose const & pose,
55  Size resid,
56  task::PackerTask const & task
57 )
58 {
59  resid_ = resid;
60 
61  /// Need to query the rotamer library for each available ResidueType that
62  /// the packer task suggests should be available at this position. For
63  /// the ResidueTypes that have a dunbrack library, ask the library for the
64  /// complete set of rotamer samples. For the residue types that do not have
65  /// a rotamer library (aka RotamerLibrary::get_rsd_library returns NULL),
66  /// store that fact by keeping its vector in the samples_ array at size 0.
67  /// NOTE: it's possible for there to be two rotamers at a position without
68  /// a library being present: the first for the native rotamer, the second
69  /// for the ideal rotamer.
70 
71  Size count_allowed( 0 );
73  allowed_iter = task.residue_task( resid ).allowed_residue_types_begin(),
74  allowed_end = task.residue_task( resid ).allowed_residue_types_end();
75  allowed_iter != allowed_end; ++allowed_iter ) {
76  ++count_allowed;
77  }
78  if ( count_allowed == 0 ) {
79  // save the input rotamer
80  } else {
81  n_restypes_ = count_allowed;
82  aa_for_rotblock_.resize( n_restypes_ );
84 
87 
90 
91  samples_.resize( n_restypes_ );
92  }
93 
94  Size count_restype_ind( 0 );
96  allowed_iter = task.residue_task( resid ).allowed_residue_types_begin(),
97  allowed_end = task.residue_task( resid ).allowed_residue_types_end();
98  allowed_iter != allowed_end; ++allowed_iter ) {
99  ++count_restype_ind;
100  aa_for_rotblock_[ count_restype_ind ] = (*allowed_iter)->aa();
101  restype_for_rotblock_[ count_restype_ind ] = (*allowed_iter);
104  if ( rotlib ) {
105  // OK -- two options -- we're dealing with a Dunbrack library, in which case, we should
106  // store DunbrackRotamerSampleData, or, we're dealing with some other kind of library,
107  // in which case, we need to quit (TO DO: support ligand rotamers)
109  dynamic_cast<dunbrack::SingleResidueDunbrackLibrary const * > ( rotlib() );
110  if ( dunlib ) {
111  samples_[ count_restype_ind ] = dunlib->get_all_rotamer_samples( pose.phi( resid ), pose.psi( resid ) );
112  } else {
113  utility_exit_with_message("ContinuousRotamerSet cannot support non-Dunbrack rotamer libraries at this time" );
114  }
115  } else {
116  // Ala or gly or something similar.
117  // noop
118  }
119 
120  if ( (*allowed_iter)() == & pose.residue_type( resid ) && task.residue_task( resid ).include_current() ) {
121  /// save coordinates for this residue
122  input_rotamer_rotblock_ = count_restype_ind;
123  conformation::Residue const & res = pose.residue( resid );
124  input_rotamer_coords_.resize( res.natoms() );
125  for ( Size ii = 1; ii <= res.natoms(); ++ii ) {
126  input_rotamer_coords_[ ii ] = res.xyz( ii );
127  }
128  }
129  }
130 
131  for ( Size ii = 1; ii <= n_restypes_; ++ii ) {
133  if ( ii != 1 ) {
136  } else {
137  baserots_offsets_[ ii ] = 0;
138  samplingrot_offsets_[ ii ] = 0;
139  }
142  if ( ii == input_rotamer_rotblock_ ) {
143  // mark the input rotamer as the last rotamer of the samplingrots for its restype.
145  }
146  }
147 
150  for ( Size ii = 1; ii <= n_restypes_; ++ii ) {
151  for ( Size jj = baserots_offsets_[ ii ] + 1; jj <= baserots_offsets_[ ii ] + n_baserotamers_for_rotblock_[ ii ]; ++jj ) {
152  aa_block_for_baserotamer_[ jj ] = ii;
153  }
154  for ( Size jj = samplingrot_offsets_[ ii ] + 1; jj <= samplingrot_offsets_[ ii ] + n_samplingrots_for_rotblock_[ ii ]; ++jj ) {
156  }
157  }
158 }
159 
160 /// Note, its entirely possible for two residue types to be the "same amino acid",
161 /// e.g. HIS and HIS_D.
162 Size
164 {
165  return n_restypes_;
166 }
167 
168 ///
169 //Size
170 //ContinuousRotamerSet::get_residue_type_begin( Size which_restype ) const
171 //{
172 // return n_totalrots_offsets_[ which_restype ] + 1;
173 //}
174 
175 Size
177 {
178  return n_samplingrots_for_rotblock_[ which_restype ];
179 }
180 
181 Size
183 {
184  return samples_[ which_restype ].size();
185 }
186 
187 Size
189 {
190  return aa_block_for_samplingrotamer_[ which_rotamer ];
191 }
192 
193 Size
195 
196 Size
198 
199 Size
201 {
203 }
204 
207 {
208  return input_rotamer_coords_;
209 }
210 
211 Size
213 
216 {
217  return restype_for_rotblock_[ rotblock ];
218 }
219 
220 
221 
223 ContinuousRotamerSet::baserotamer_data( Size rotblock_ind, Size rotid_for_aa ) const
224 {
225  return samples_[ rotblock_ind ][ rotid_for_aa ];
226 }
227 
228 Size
229 ContinuousRotamerSet::pick_baserotamer_from_rotblock( Size rotblock_ind, Real rand_btw_0_and_1 ) const
230 {
231  assert( rand_btw_0_and_1 >= 0.0 && rand_btw_0_and_1 <= 1.0 );
232  Real accumulated_prob( 0.0 );
233  Size const nsamples = samples_[ rotblock_ind ].size();
234  for ( Size ii = 1; ii <= nsamples; ++ii ) {
235  accumulated_prob += samples_[ rotblock_ind ][ ii ].probability();
236  //assert( accumulated_prob <= 1.0 + 1e-5 ); // should never exceed 1
237  if ( accumulated_prob > rand_btw_0_and_1 ) return ii;
238  }
239  return nsamples;
240 }
241 
242 void
244 {
245  bool restype_is_current = restype_ind == input_rotamer_rotblock_;
246  if ( samples_[ restype_ind ].size() == 0 ) {
247  // ala or gly
248  n_baserotamers_for_rotblock_[ restype_ind ] = 1;
249  n_samplingrots_for_rotblock_[ restype_ind ] = 1;
250  } else {
251  Real const prob_to_accumulate = 0.98;
252  n_baserotamers_for_rotblock_[ restype_ind ] = samples_[ restype_ind ].size();
253  Real cumulative_probability( 0.0 );
254  for ( Size ii = 1; ii <= n_baserotamers_for_rotblock_[ restype_ind ]; ++ii ) {
255  n_samplingrots_for_rotblock_[ restype_ind ] += 1;
256  cumulative_probability += samples_[ restype_ind ][ ii ].probability();
257  if ( cumulative_probability > prob_to_accumulate ) break;
258  }
259  n_samplingrots_for_rotblock_[ restype_ind ] = samples_[ restype_ind ].size();
260  }
261 
262  /// Multiply the number of totalrots by the combinations of proton chi samples.
263  /// this can be computed independently of whether we have a RotamerLibrary or not;
264  /// though, neither alanine nor glycine have proton chi...
265  for ( Size ii = 1; ii <= restype_for_rotblock_[ restype_ind ]->n_proton_chi(); ++ii ) {
266  n_samplingrots_for_rotblock_[ restype_ind ] *=
267  restype_for_rotblock_[ restype_ind ]->proton_chi_samples( ii ).size();
268  }
269 
270  if ( restype_is_current ) {
271  n_samplingrots_for_rotblock_[ restype_ind ] += 1;
272  }
273 
274 }
275 
276 /////////////// ContinuousRotamerSets ////////////////////
277 
279  pose::Pose const & pose,
280  task::PackerTask const & task
281 )
282 {
283  total_residue_ = pose.total_residue();
284  nmoltenres_ = task.num_to_be_packed();
287  rotamer_sets_.resize( nmoltenres_ );
289  Size count_moltenres( 0 );
290  for ( Size ii = 1; ii <= total_residue_; ++ii ) {
291  if ( ! task.being_packed( ii ) ) continue;
292  ++count_moltenres;
293  moltenresid_2_resid_[ count_moltenres ] = ii;
294  resid_2_moltenresid_[ ii ] = count_moltenres;
295  rotamer_sets_[ ii ].build_rotamers( pose, ii, task );
296  }
297 
298  n_sample_rotamers_ = 0;
299  for ( Size ii = 1; ii <= nmoltenres_; ++ii ) {
301  n_sample_rotamers_ += rotamer_sets_[ ii ].num_sampling_rotamers_total();
302  }
304  Size count_sample_rot = 1;
305  for ( Size ii = 1; ii <= nmoltenres_; ++ii ) {
306  Size const ii_nsamples = rotamer_sets_[ ii ].num_sampling_rotamers_total();
307  for ( Size jj = 1; jj <= ii_nsamples; ++jj, ++count_sample_rot ) {
308  moltenres_for_sample_rot_[ count_sample_rot ] = ii;
309  }
310  }
311 
312 }
313 
316 
319 
320 ContinuousRotamerSet const &
322 {
323  return rotamer_sets_[ mresid ];
324 }
325 
326 ContinuousRotamerSet const &
328 {
329  return rotamer_sets_[ resid_2_moltenresid_[ resid ]];
330 }
331 
332 Size
334 {
335  return n_sample_rotamers_;
336 }
337 
338 Size
340 {
341  return moltenres_for_sample_rot_[ sample_rotno ];
342 }
343 
344 Size
346 {
347  return sample_rotno - moltenres_sample_rot_offset_[ moltenres_for_sample_rot_[ sample_rotno ] ];
348 }
349 
350 
351 } // namespace rotamer_set
352 } // namespace pack
353 } // namespace core
354 
355