Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SingleResidueDunbrackLibrary.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
11 /// @brief
12 /// @author
13 
14 
15 #ifndef INCLUDED_core_pack_dunbrack_SingleResidueDunbrackLibrary_hh
16 #define INCLUDED_core_pack_dunbrack_SingleResidueDunbrackLibrary_hh
17 
18 // Unit Headers
20 
21 // Package Headers
24 // AUTO-REMOVED #include <core/pack/dunbrack/DunbrackRotamer.hh>
25 
26 // ObjexxFCL Headers
27 // AUTO-REMOVED #include <ObjexxFCL/FArray2D.hh>
28 // AUTO-REMOVED #include <ObjexxFCL/FArray3D.hh>
29 
30 // Utility Headers
31 #include <utility/assert.hh>
32 #include <utility/io/izstream.fwd.hh>
33 #include <utility/io/ozstream.fwd.hh>
34 
35 // Numeric Headers
36 #include <numeric/numeric.functions.hh>
37 
38 #include <utility/vector1.hh>
39 
40 
41 namespace core {
42 namespace pack {
43 namespace dunbrack {
44 
46 public:
47  typedef chemical::AA AA;
48 
49 public:
50  /// constants
51 
52  /// A good "phi" value to use for N-term residues
53  static Real const NEUTRAL_PHI;
54 
55  /// A good "psi" value to use for C-term residues
56  static Real const NEUTRAL_PSI;
57 
58 public:
59 
60  /// c-tor
62  AA const aa,
63  Size const n_rotameric_chi,
64  bool dun02
65  );
66 
68 
69 public:
70 
71  void read_options();
72 
73  virtual void write_to_binary( utility::io::ozstream & out ) const;
74  virtual void read_from_binary( utility::io::izstream & in );
75 
76  /// @brief Return all of the rotamer sample data given a particular phi/psi.
77  /// For N-terminus residues, hand in the phi value SingleResidueDunbrackLibrary::PHI_NEUTRAL and
78  /// for C-terminus residues, hand in the psi value SingleResidueDunbrackLibrary::PSI_NEUTRAL.
79  /// The returned samples should be in semi-decrasing order by probability; semi, because the
80  /// rotamers are constructed in sorted order by their probability in the lower phi-psi bin that
81  /// the input phi/psi perscribes.
82  virtual
85  Real phi,
86  Real psi
87  ) const = 0;
88 
89  /// @brief Return the probability for a particular rotamer where rotamers are
90  /// indexed in order of decreasing probability (or something very close to
91  /// decreasing probability).
92  virtual
93  Real
95  Real phi,
96  Real psi,
97  Size rot_ind
98  ) const = 0;
99 
100  virtual
102  get_rotamer(
103  Real phi,
104  Real psi,
105  Size rot_ind
106  ) const = 0;
107 
108  virtual
109  Real
111  conformation::Residue const & rsd
112  ) const = 0;
113 
114  virtual
115  Real
117  conformation::Residue const & rsd
118  ) const = 0;
119 
120 public:
121  /// Virtual functions the derived classes must implement
122 
123  /// @brief Derived classes should invoke base class function as well.
124  virtual Size memory_usage_in_bytes() const;
125 
126  /// @brief The number of chi represented by the library.
127  virtual
128  Size nchi() const = 0;
129 
130  virtual
131  Size n_rotamer_bins() const = 0;
132 
133  /// @brief Tell the base class the number of chi bins for each rotameric
134  /// chi dimension
135  void
137 
138 protected:
139  /// Read access for the derived class
140  bool dun02() const { return dun02_; }
141 
142  /// Worker functions available to the derived classes
143 
144  virtual Size memory_usage_static() const = 0;
145  virtual Size memory_usage_dynamic() const;
146 
147  /// @brief Read access to the n_chi_bins_ vector
149  n_chi_bins() const {
150  return n_chi_bins_;
151  }
152 
153  /// @brief The base class needs to be informed about which rotamer wells
154  /// exist in order to create the rotwell to packed rot conversion data.
155  /// set_chi_nbins must be called first.
156  void
158 
159  /// @brief After the derived class has marked all the rotwells that do exist,
160  /// the base class will create the rotwell to packerot conversion data.
161  void
163 
164  /// @brief The number of existing rotamers
165  Size
166  n_packed_rots() const {
167  return n_packed_rots_;
168  }
169 
170  /// @brief The number of possible rotamers -- product of the chi_nbins_ array
171  Size
172  n_possible_rots() const {
173  return n_possible_rots_;
174  }
175 
176 public:
177 
178  /// @brief Convert a vector of chi angles (degrees) into a integer vector of rotamer wells.
179  /// Derived class should be consistent, but may be arbitrary in how wells divide angle space.
180  virtual
181  void
183  ChiVector const & chi,
184  RotVector & rot ) const = 0;
185 
186 public:
187  /// Conversion functions
188 
189  /// @brief Convert from the rotamer bin indices for each chi to the
190  /// (non-compact) "rotamer number"
191  Size
192  rotwell_2_rotno( utility::vector1< Size > const & rotwell ) const;
193 
194  /// @brief Convert from the rotamer bin indices for each chi to the
195  /// (non-compact) "rotamer number"
196  Size
197  rotwell_2_rotno( Size4 const & rotwell ) const;
198 
199  /// @brief Convert from the rotamer number to the compacted
200  /// "packed rotamer number". Returns 0 if rotno has no corresponding packed rotno.
201  Size
202  rotno_2_packed_rotno( Size const rotno ) const;
203 
204  /// @brief Convert from the rotamer bin indices for each chi to the
205  /// compacted "packed rotamer number." Returns 0 if rotwell has no corresponding packed rotno
206  Size
207  rotwell_2_packed_rotno( utility::vector1< Size > const & rotwell ) const;
208 
209  /// @brief Convert from the rotamer bin indices for each chi to the
210  /// compacted "packed rotamer number." Returns 0 if rotwell has no corresponding packed rotno
211  Size
212  rotwell_2_packed_rotno( Size4 const & rotwell ) const;
213 
214  /// @brief Convert from the packed rotamer number to the rotamer well
215  void
216  packed_rotno_2_rotwell( Size const packed_rotno, utility::vector1< Size > & rotwell ) const;
217 
218  void
220  Size const packed_rotno,
221  Size4 & rotwell
222  ) const;
223 
225  packed_rotno_2_rotwell( Size const packed_rotno ) const;
226 
227  /// @brief Convert from the rotamer number to the rotamer well
228  void
229  rotno_2_rotwell( Size const rotno, utility::vector1< Size > & rotwell ) const;
230 
231  /// @brief, Turns out, when non-rotameric chi are taken out of the picture,
232  /// all remaining chi are binned the same way, except proline. Valid only for
233  /// Dun10 libraries.
234  inline
235  Size
237  Real chi,
238  Size which_chi
239  ) const {
240  assert( ! dun02_ );
241  assert( -180.0 <= chi && chi <= 180.0 );
242 
243  if ( aa_ == chemical::aa_pro ) {
244  if ( which_chi == 1 ) {
245  if ( chi > 0 ) { return 1; }
246  else { return 2; }
247  } else {
248  return 1;
249  }
250  }
251 
252  if ( ( chi >= 0.0 ) && ( chi <= 120.0 ) ) { return 1; }
253  else if ( std::abs(chi) >= 120.0 ) { return 2; }
254  else /*if ( ( chi_i >= -120.0 ) && ( chi_i <= 0.0 ) )*/ { return 3; }
255  }
256 
257  /// @brief This is not the right place for this code, but the numeric interpolation library
258  /// uselessly indexes by 0 and the basic functions aren't inlined...
259  inline
260  void bin_angle(
261  Real const angle_start,
262  Real const angle_step,
263  Real const ASSERT_ONLY( angle_range ),
264  Size const nbins,
265  Real const ang,
266  Size & bin_lower,
267  Size & bin_upper,
268  Real & angle_alpha
269  ) const {
270  /// very, very rarely, periodic_range( angle, 360 ) will return 180 instead of -180.
271  /// though it is supposed to return values in the range [-180, 180).
272  assert( angle_start <= ang && ang <= angle_start + angle_range );
273  assert( std::abs( nbins * angle_step - angle_range ) < 1e-15 );
274 
275  Real real_bin_lower = ( ang - angle_start ) / angle_step;
276  Size bin_prev = static_cast< Size > ( real_bin_lower );
277  bin_lower = 1 + numeric::mod( bin_prev, nbins );
278  bin_upper = numeric::mod( bin_lower, nbins ) + 1;
279  angle_alpha = ( (ang - angle_start ) - ( bin_prev * angle_step ) ) / angle_step;
280  }
281 
282 
283 public:
284  /// @brief The amino acid this library is representing
285  AA
286  aa() const {
287  return aa_;
288  }
289 
290  /// @brief When creating rotamer, what position in the CDF should one build until?
291  /// Unlikely rotamers ( < 0.5 %) are numerous, but are very infrequently useful.
292  Real
294 
295  /// @brief setters for accumulation probability cutoff (to support externally-controlled option dependence)
296  void prob_to_accumulate( Real, Real );
299 
300  ///@brief Hard coded specifics about the amino acids
301  static
302  void
304  chemical::AA const aa,
305  RotVector & rot
306  );
307 
308  /// @brief Reports information about the *rotameric* chi only; no details
309  /// about the non rotameric chi.
310  static
311  void
313  chemical::AA const aa,
314  RotVector & rot,
315  bool dun02
316  );
317 
318  /// @brief Hard coded rotamer well info for the 2002 library.
319  static
320  void
322  chemical::AA const aa,
323  RotVector & rot
324  );
325 
326 private:
327 
328  /// @brief This function forces the instantiation of virtual templated methods in the derived classes.
329  /// Functions like this one are necessary when combining polymorphism and templates. Though
330  /// these functions must be compiled, they need never be called. Do not call this function.
332 
333 
334 private:
335  /// data
336  bool const dun02_; // Are we using the 2002 definitions for rotamer wells?
337  AA const aa_;
340  utility::vector1< Size > n_chi_products_; // n_chi_products_[ i ] = prod( j in i+1 to nchi, n_chi_bins_[ j ] );
341 
343  Size n_possible_rots_; // prod( i in 1 to nchi, n_chi_bins_[ i ] );
344 
346 
349 
353 
354 };
355 
356 
357 
358 } // dunbrack
359 } // pack
360 } // core
361 
362 #endif // INCLUDED_core_pack_dunbrack_SingleResidueDunbrackLibrary_HH
363