Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RotamericSingleResidueDunbrackLibrary.hh
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/scoring/dunbrack/RotamericSingleResidueDunbrackLibrary.hh
11 /// @brief Declaration of rotameric rotamer libraries from Jun08 (as opposed to semi-rotameric)
12 /// @author Andrew Leaver-Fay
13 
14 
15 #ifndef INCLUDED_core_pack_dunbrack_RotamericSingleResidueDunbrackLibrary_hh
16 #define INCLUDED_core_pack_dunbrack_RotamericSingleResidueDunbrackLibrary_hh
17 
18 // Unit Headers
20 
21 // Package Headers
25 
26 // Project Headers
28 
29 // ObjexxFCL Headers
30 // AUTO-REMOVED #include <ObjexxFCL/FArray2D.hh>
31 #include <ObjexxFCL/FArray3D.hh>
32 
33 #include <utility/vector1.hh>
34 
35 
36 namespace core {
37 namespace pack {
38 namespace dunbrack {
39 
40 template < Size T >
42 {
43 public:
45  :
46  rotamer_( rotamer_in )
47  {}
48 
49  virtual ~RotamericData() {}
50 
52  rotamer() const {
53  return rotamer_;
54  }
55 
56 private:
58 
59 };
60 
61 template < Size T >
63 {
64 public:
66 
67 private:
68  /// No default ctor
69  ///RotamericSingleResidueDunbrackLibrary();
70 
71 public:
73  AA const aa_in,
74  bool dun02
75  );
76 
78 
80 
81 public:
82  /// Virtual functions required by the base classes
83 
84  virtual
85  Real
87  conformation::Residue const & rsd,
89  ) const;
90 
91  virtual
92  Real
94  conformation::Residue const & rsd,
96  ) const;
97 
98  /// @brief Returns the energy of the lowest-energy rotamer accessible to the given residue
99  /// (based on e.g. its current phi and psi values).
100  /// If curr_rotamer_only is true, then consider only the idealized version of the
101  /// residue's current rotamer (local optimum); otherwise, consider all rotamers (global optimum).
102  virtual
103  Real
105  conformation::Residue const & rsd,
106  bool curr_rotamer_only,
108  ) const;
109 
110  virtual
111  void
113  conformation::Residue const & rsd,
114  RotamerLibraryScratchSpace & scratch,
115  numeric::random::RandomGenerator & RG,
116  ChiVector & new_chi_angles,
117  bool perturb_from_rotamer_center
118  ) const;
119 
120  virtual
121  void
123  pose::Pose const & pose,
124  scoring::ScoreFunction const & scorefxn,
125  pack::task::PackerTask const & task,
126  graph::GraphCOP packer_neighbor_graph,
127  chemical::ResidueTypeCOP concrete_residue,
128  conformation::Residue const & existing_residue,
129  utility::vector1< utility::vector1< Real > > const & extra_chi_steps,
130  bool buried,
132  ) const;
133 
134  /// @brief Return all of the rotamer sample data given a particular phi/psi.
135  /// For N-terminus residues, hand in the phi value SingleResidueDunbrackLibrary::PHI_NEUTRAL and
136  /// for C-terminus residues, hand in the psi value SingleResidueDunbrackLibrary::PSI_NEUTRAL.
137  /// The returned samples should be in semi-decrasing order by probability; semi, because the
138  /// rotamers are constructed in sorted order by their probability in the lower phi-psi bin that
139  /// the input phi/psi perscribes.
140  virtual
143  Real phi,
144  Real psi
145  ) const;
146 
147  virtual
148  Real
150  Real phi,
151  Real psi,
152  Size rot_ind
153  ) const;
154 
155  virtual
157  get_rotamer(
158  Real phi,
159  Real psi,
160  Size rot_ind
161  ) const;
162 
163  virtual
164  Size nchi() const;
165 
166  virtual
167  Size n_rotamer_bins() const;
168 
169  //XRW_B_T1
170  /*
171  virtual
172  SingleResidueRotamerLibraryOP
173  coarsify(coarse::Translator const &map) const;
174  */
175  //XRW_E_T1
176 
177  virtual
178  void
179  write_to_file( utility::io::ozstream &out ) const;
180 
181  virtual void write_to_binary( utility::io::ozstream & out ) const;
182  virtual void read_from_binary( utility::io::izstream & in );
183 
184  virtual
185  void
187  ChiVector const & chi,
188  RotVector & rot
189  ) const;
190 
191 protected:
192 
193  void
195 
196  /// @brief When given a statically sized fixedsizearray, use this method.
197  void
199  ChiVector const & chi,
200  Size4 & rot
201  ) const;
202 
203  /// @brief When given a statically sized fixedsizearray, use this method.
204  void
206  Real4 const & chi,
207  Size4 & rot
208  ) const;
209 
210 
211 public:
212 
213  /// @brief Read from input stream; stream may contain data for other amino acids.
214  /// Quit once another amino acid is specified in the input file, returning the
215  /// name of the next amino acid specifed (since it's already been extracted from
216  /// the input stream). Return the empty string if no other amino acid is specified.
219  utility::io::izstream & in,
220  bool first_line_three_letter_code_already_read
221  );
222 
223 protected:
224  // hard coded constants
225  static Size const N_PHIPSI_BINS = 36;
226  static Real const PHIPSI_BINRANGE;
227 
228 protected:
229  /// Read and write access for derived classes
230 
231  typename ObjexxFCL::FArray3D< PackedDunbrackRotamer< T > > const &
232  rotamers() const {
233  return rotamers_;
234  }
235 
236  typename ObjexxFCL::FArray3D< PackedDunbrackRotamer< T > > &
238  return rotamers_;
239  }
240 
241  ObjexxFCL::FArray3D< Size > const &
244  }
245 
246  ObjexxFCL::FArray3D< Size > &
249  }
250 
251 //change it back
252 protected:
253  /// Worker functions
254 
255  virtual Size memory_usage_static() const;
256  virtual Size memory_usage_dynamic() const;
257 
258  /// @brief Evaluates the score and chi-deviation penalty for the rotameric
259  /// chi (in this class, that means all the chi) and stores the answers in
260  /// the scratch object. If eval_deriv is true, then at the end of this
261  /// function, scratch contains up-to-date dchidevpen_dbb, dchidevpen_dchi,
262  /// chimean, chisd, chidev, chidevpen, dchimean_d(phi/psi), dchisd_d(phi/psi)
263  /// rotwell and rotprob data.
264  Real
266  conformation::Residue const & rsd,
267  RotamerLibraryScratchSpace & scratch,
268  bool eval_deriv
269  ) const;
270 
271 public:
272  Size
274  conformation::Residue const & rsd,
275  Size4 & rotwell
276  ) const;
277 
278 
279  void
281  conformation::Residue const & rsd,
282  RotamerLibraryScratchSpace & scratch,
283  Size const packed_rotno,
284  PackedDunbrackRotamer< T, Real > & interpolated_rotamer
285  ) const;
286 
287 protected:
288  void
290  RotamerLibraryScratchSpace & scratch,
291  Size const packed_rotno,
292  Size const phibin,
293  Size const psibin,
294  Size const phibin_next,
295  Size const psibin_next,
296  Real const phi_alpha,
297  Real const psi_alpha,
298  PackedDunbrackRotamer< T, Real > & interpolated_rotamer
299  ) const;
300 
301  /// @brief Assigns random chi angles and returns the packed_rotno for the chosen random rotamer.
302  void
304  conformation::Residue const & rsd,
305  RotamerLibraryScratchSpace & scratch,
306  numeric::random::RandomGenerator & RG,
307  ChiVector & new_chi_angles,
308  bool perturb_from_rotamer_center,
309  Size & packed_rotno
310  ) const;
311 
312  void
314  PackedDunbrackRotamer< T, Real > const & interpolated_rotamer,
315  conformation::Residue const & rsd,
316  numeric::random::RandomGenerator & RG,
317  ChiVector & new_chi_angles,
318  bool perturb_from_rotamer_center
319  ) const;
320 
321  void
323  conformation::Residue const & rsd,
325  ) const;
326 
327  void
329  Real phi,
330  Real psi,
331  Size & phibin,
332  Size & psibin,
333  Size & phibin_next,
334  Size & psibin_next,
335  Real & phi_alpha,
336  Real & psi_alpha
337  ) const;
338 
339  void
341  Real phi,
342  Real psi,
343  Size & phibin,
344  Size & psibin
345  ) const;
346 
347  Real
349  conformation::Residue const & rsd
350  ) const;
351 
352  Real
354  conformation::Residue const & rsd
355  ) const;
356 
357 
358 private:
359  /// @brief After an interpolated rotamer has been created, this method appends new
360  /// rotamers to the vector of rotamers, taking extra samples at designated chi intervals
361  /// if instructed to do so in the extra_chi_steps argument.
362  void
364  pose::Pose const & pose,
365  scoring::ScoreFunction const & scorefxn,
366  pack::task::PackerTask const & task,
367  graph::GraphCOP packer_neighbor_graph,
368  chemical::ResidueTypeCOP concrete_residue,
369  conformation::Residue const& existing_residue,
370  utility::vector1< utility::vector1< Real > > const & extra_chi_steps,
371  bool buried,
373  PackedDunbrackRotamer< T, Real > const & interpolated_rotamer
374  ) const;
375 
376 
377  void verify_phipsi_bins(
378  Real phi,
379  Real psi,
380  Size const phibin,
381  Size const psibin,
382  Size const phibin_next,
383  Size const psibin_next
384  ) const;
385 
386 protected:
387 
388  template< class P >
391  PackedDunbrackRotamer< T, P > const & packedrot
392  ) const;
393 
394  /// @brief This member function constructs a list of all combinations of chi angles
395  /// for a rotamer sample. It relies on a virtual function chisamples_for_rotamer_chi
396  /// that may be overridden by derived classes. With a list of samples for each chi,
397  /// this function then enumerates all combinations.
398  void
400  chemical::ResidueType const & rsd_type,
401  pack::task::PackerTask const & task,
402  Size const seqpos,
403  bool buried,
404  RotamericData< T > const & rotamer_data,
405  utility::vector1< utility::vector1< Real > > const & extra_chi_steps,
406  utility::vector1< ChiSetOP > & chi_set_vector
407  ) const;
408 
409  /// @brief Used in tandem with enumerate_chi_sets, this function pushes
410  /// back chi sample data into the four input vectors: the 1. chi value sample,
411  /// 2. the rotamer well #, 3. a discription of the kind of sample
412  /// (how far off the ideal rotamer) and 4. the probability of observing this
413  /// chi at that sample. The rotamer_data that's input is the same data that
414  /// was handed to the enumerate_chi_sets call (may be downcast as needed).
415  virtual
416  void
418  chemical::ResidueType const & rsd_type,
419  pack::task::ResidueLevelTask const & rtask,
420  bool buried,
421  Size const chi_index,
422  RotamericData< T > const & rotamer_data,
423  utility::vector1< Real > const & extra_steps,
424  utility::vector1< Real > & total_chi,
425  utility::vector1< int > & total_rot,
426  utility::vector1< Real > & total_ex_steps,
427  utility::vector1< Real > & chisample_prob
428  ) const;
429 
430  /// @brief Once all the chi have been enumerated, building the rotamers is a trivial task.
431  /// This function is protected so that derived classes may simply enumerate their chi and then
432  /// invoke this function.
433  /// This arguably should be moved into the SingleResidueRotamerLibrary base class.
434  void
436  pose::Pose const & pose,
437  scoring::ScoreFunction const & scorefxn,
438  pack::task::PackerTask const & task,
439  graph::GraphCOP packer_neighbor_graph,
440  chemical::ResidueTypeCOP concrete_residue,
441  conformation::Residue const& existing_residue,
442  utility::vector1< ChiSetOP > const & chi_set_vector,
444  ) const;
445 
446 private:
447 
448  /// The (chi_mean, chi_sd, packed_rotno, and prob) data for the chi dihedrals
449  /// The FArray3D is indexed into by (phi, psi, sorted_index ), where
450  /// sorted index simply means the order for a particular packed_rotno in the
451  /// list of rotamers sorted by probability.
452  typename ObjexxFCL::FArray3D< PackedDunbrackRotamer< T > > rotamers_;
453 
454  /// Quick lookup that lists the sorted position for the packed rotamer number
455  /// given a phi/psi. Indexed by (phi, psi, packed_rotno ).
456  ObjexxFCL::FArray3D< Size > packed_rotno_2_sorted_rotno_;
457 
458 
459  /// Maximum probability of any rotamer, stored by phi,psi bin.
460  /// Could be derived from rotset_ but stored here for easy lookup.
461  /// Wasteful.
462  /// typename ObjexxFCL::FArray2D< DunbrackReal > max_rotprob_;
463 
464 };
465 
466 
467 } // namespace dunbrack
468 } // namespace scoring
469 } // namespace core
470 
471 #endif // INCLUDED_core_pack_dunbrack_RotamericSingleResidueDunbrackLibrary_HH