Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DunbrackRotamer.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/DunbrackRotamer.hh
11 /// @brief Fixed-sized dunbrack rotamer object
12 /// @author Andrew Leaver-Fay
13 
14 
15 #ifndef INCLUDED_core_pack_dunbrack_DunbrackRotamer_hh
16 #define INCLUDED_core_pack_dunbrack_DunbrackRotamer_hh
17 
18 // Unit headers
20 
21 // Package headers
24 // AUTO-REMOVED #include <core/scoring/types.hh>
25 #include <core/types.hh>
26 
27 // Project headers
29 // AUTO-REMOVED #include <core/conformation/Residue.fwd.hh>
30 // AUTO-REMOVED #include <core/pack/task/PackerTask.fwd.hh>
32 
33 // Numeric headers
34 #include <numeric/random/random.fwd.hh>
35 
36 // Utility headers
37 #include <utility/fixedsizearray1.hh>
38 #include <utility/pointer/ReferenceCount.hh>
39 // AUTO-REMOVED #include <utility/vector1.hh>
40 // AUTO-REMOVED #include <utility/exit.hh>
41 
42 #include <utility/vector1_bool.hh>
43 
44 
45 
46 namespace core {
47 namespace pack {
48 namespace dunbrack {
49 
50 /// @brief A class who's size is known at compile time. A vector of these objects
51 /// will occupy a perfectly contiguous region of memory, with no extra space
52 /// allocated for pointers. These objects may be rapidly allocated and deallocated
53 /// on the stack.
54 ///
55 /// @details S for Size, P for Precision. Now incorporating the bicubic spline
56 /// code from numerical recipies that was ported to Rosetta from the Meiler lab
57 /// code base (biotools?) by Steven Combs.
58 template < Size S, class P >
59 class DunbrackRotamerMeanSD {
60 public:
62  rotamer_probability_( P( 0.0 ) ),
63  rotE_( 0 ),
64  rotE_dsecophi_( P( 0.0 ) ),
65  rotE_dsecopsi_( P( 0.0 ) ),
66  rotE_dsecophipsi_( P( 0.0 ) )
67  {
68  for ( Size ii = 1; ii <= S; ++ii ) {
69  chi_mean_[ ii ] = P( 0.0 );
70  //chi_mean_dsecophi_[ ii ] = P( 0.0 );
71  //chi_mean_dsecopsi_[ ii ] = P( 0.0 );
72  //chi_mean_dsecophipsi_[ ii ] = P( 0.0 );
73  chi_sd_[ ii ] = P( 0.0 );
74  //chi_sd_dsecophi_[ ii ] = P( 0.0 );
75  //chi_sd_dsecopsi_[ ii ] = P( 0.0 );
76  //chi_sd_dsecophipsi_[ ii ] = P( 0.0 );
77  }
78  }
79 
81  typename utility::vector1< P > const & chimean_in,
82  typename utility::vector1< P > const & chisd_in,
83  P const prob_in
84  ) :
85  rotamer_probability_( prob_in ),
86  rotE_( P(0.0) ),
87  rotE_dsecophi_( P( 0.0 ) ),
88  rotE_dsecopsi_( P( 0.0 ) ),
89  rotE_dsecophipsi_( P( 0.0 ) )
90  {
91  for ( Size ii = 1; ii <= S; ++ii ) {
92  chi_mean_[ ii ] = chimean_in[ ii ];
93  //chi_mean_dsecophi_[ ii ] = P( 0.0 );
94  //chi_mean_dsecopsi_[ ii ] = P( 0.0 );
95  //chi_mean_dsecophipsi_[ ii ] = P( 0.0 );
96  chi_sd_ [ ii ] = chisd_in [ ii ];
97  //chi_sd_dsecophi_[ ii ] = P( 0.0 );
98  //chi_sd_dsecopsi_[ ii ] = P( 0.0 );
99  //chi_sd_dsecophipsi_[ ii ] = P( 0.0 );
100  }
101  }
102 
103  P chi_mean( Size which_chi ) const {
104  return chi_mean_[ which_chi ];
105  }
106 
107  //P chi_mean_dsecophi( Size which_chi ) const {
108  // return chi_mean_dsecophi_[ which_chi ];
109  //}
110 
111  //P chi_mean_dsecopsi( Size which_chi ) const {
112  // return chi_mean_dsecopsi_[ which_chi ];
113  //}
114 
115  //P chi_mean_dsecophipsi( Size which_chi ) const {
116  // return chi_mean_dsecophipsi_[ which_chi ];
117  //}
118 
119  P chi_sd( Size which_chi ) const {
120  return chi_sd_[ which_chi ];
121  }
122 
123  //P chi_sd_dsecophi( Size which_chi ) const {
124  // return chi_sd_dsecophi_[ which_chi ];
125  //}
126 
127  //P chi_sd_dsecopsi( Size which_chi ) const {
128  // return chi_mean_dsecopsi_[ which_chi ];
129  //}
130 
131  //P chi_sd_dsecophipsi( Size which_chi ) const {
132  // return chi_mean_dsecophipsi_[ which_chi ];
133  //}
134 
135  P
137  return rotamer_probability_;
138  }
139 
140  P
141  rotE() const {
142  return rotE_;
143  }
144 
145  P
146  rotE_dsecophi() const {
147  return rotE_dsecophi_;
148  }
149 
150  P
151  rotE_dsecopsi() const {
152  return rotE_dsecopsi_;
153  }
154 
155  P
157  return rotE_dsecophipsi_;
158  }
159 
160 
161  P &
162  chi_mean( Size which_chi ) {
163  return chi_mean_[ which_chi ];
164  }
165 
166  //P & chi_mean_dsecophi( Size which_chi ) {
167  // return chi_mean_dsecophi_[ which_chi ];
168  //}
169 
170  //P & chi_mean_dsecopsi( Size which_chi ) {
171  // return chi_mean_dsecopsi_[ which_chi ];
172  //}
173 
174  //P & chi_mean_dsecophipsi( Size which_chi ) {
175  // return chi_mean_dsecophipsi_[ which_chi ];
176  //}
177 
178  P &
179  chi_sd( Size which_chi ) {
180  return chi_sd_[ which_chi ];
181  }
182 
183  //P & chi_sd_dsecophi( Size which_chi ) {
184  // return chi_sd_dsecophi_[ which_chi ];
185  //}
186 
187  //P & chi_sd_dsecopsi( Size which_chi ) {
188  // return chi_mean_dsecopsi_[ which_chi ];
189  //}
190 
191  //P & chi_sd_dsecophipsi( Size which_chi ) {
192  // return chi_mean_dsecophipsi_[ which_chi ];
193  //}
194 
195  P &
197  return rotamer_probability_;
198  }
199 
200  P & rotE() {
201  return rotE_;
202  }
203 
204  P &
206  return rotE_dsecophi_;
207  }
208 
209  P &
211  return rotE_dsecopsi_;
212  }
213 
214  P &
216  return rotE_dsecophipsi_;
217  }
218 
219  void chi_mean ( Size which_chi, P chi_mean_in ) {
220  chi_mean_[ which_chi ] = chi_mean_in;
221  }
222 
223  void chi_sd ( Size which_chi, P chi_sd_in ) {
224  chi_sd_[ which_chi ] = chi_sd_in;
225  }
226 
227  void rotamer_probability( P rotprob_in ) {
228  rotamer_probability_ = rotprob_in;
229  }
230 
231 private:
232  utility::fixedsizearray1< P, S > chi_mean_;
233  //utility::fixedsizearray1< P, S > chi_mean_dsecophi_; // second order derivatives for chi mean wrt phi
234  //utility::fixedsizearray1< P, S > chi_mean_dsecopsi_; // second order derivatives for chi mean wrt psi
235  //utility::fixedsizearray1< P, S > chi_mean_dsecophipsi_; // second order derivatives for chi mean wrt to both phi and psi
236  utility::fixedsizearray1< P, S > chi_sd_;
237  //utility::fixedsizearray1< P, S > chi_sd_dsecophi_; // second order derivatives for the standard deviation of chi wrt phi
238  //utility::fixedsizearray1< P, S > chi_sd_dsecopsi_; // second order derivatives for the standard deviation of chi wrt psi
239  //utility::fixedsizearray1< P, S > chi_sd_dsecophipsi_; // second order derivatives for the standard deviation of chi wrt to both phi and psi
241  P rotE_; // -log(rotamer probability)
242  P rotE_dsecophi_; // second order derivatives for the rotamer probability wrt phi
243  P rotE_dsecopsi_; // second order derivatives for the rotamer probability wrt psi
244  P rotE_dsecophipsi_; // second order derivatives for the rotamer probability wrt phi and psi
245 };
246 
247 template < Size S, class P >
248 class DunbrackRotamer : public DunbrackRotamerMeanSD< S, P > {
249 public:
251 
252 public:
253 
255  parent()
256  {
257  for ( Size ii = 1; ii <= S; ++ii ) {
258  rotwell_[ ii ] = 0;
259  }
260  }
261 
263  typename utility::vector1< P > const & chimean_in,
264  typename utility::vector1< P > const & chisd_in,
265  P const prob_in,
266  typename utility::vector1< Size > const & rotwell_in
267  ) :
268  parent( chimean_in, chisd_in, prob_in )
269  {
270  for ( Size ii = 1; ii <= S; ++ii ) {
271  rotwell_[ ii ] = rotwell_in[ ii ];
272  }
273  }
274 
275  Size rotwell( Size which_chi ) const {
276  return rotwell_[ which_chi ];
277  }
278 
279 
280  Size &
281  rotwell( Size which_chi ) {
282  return rotwell_[ which_chi ];
283  }
284 
285 
286  void rotwell( Size which_chi, Size rotwell_in ) {
287  rotwell_[ which_chi ] = rotwell_in;
288  }
289 
290 private:
291  utility::fixedsizearray1< Size, S > rotwell_;
292 };
293 
294 
295 template < Size S, class P >
296 class PackedDunbrackRotamer : public DunbrackRotamerMeanSD< S, P > {
297 public:
299 
300 public:
301 
303  parent(),
304  packed_rotno_( 0 )
305  {}
306 
308  typename utility::vector1< P > const & chimean_in,
309  typename utility::vector1< P > const & chisd_in,
310  P const prob_in,
311  Size const packed_rotno_in
312  ) :
313  parent( chimean_in, chisd_in, prob_in ),
314  packed_rotno_( packed_rotno_in )
315  {}
316 
318  DunbrackRotamer< S, P > const & sibling,
319  Size const packed_rotno_in
320  ) :
321  parent( sibling ),
322  packed_rotno_( packed_rotno_in )
323  {}
324 
325 
326  Size &
328  return packed_rotno_;
329  }
330 
331  void
332  packed_rotno( Size packed_rotno_in ) {
333  packed_rotno_ = packed_rotno_in;
334  }
335 
336  Size
337  packed_rotno() const {
338  return packed_rotno_;
339  }
340 
341 
342 private:
343 
345 
346 };
347 
349 {
350 public:
352  DunbrackRotamerSampleData( bool is_nrchi_sample );
354 
355 public:
356  /// Setters
357 
358  void set_nrchi_sample( bool setting );
359  void set_nchi( Size nchi );
360  void set_rotwell( Size chi_index, Size rotwell );
361  void set_rotwell( utility::vector1< Size > const & );
362  void set_chi_mean( Size chi_index, Real mean );
363  void set_chi_sd( Size chi_index, Real sd );
364  void set_prob( Real probability );
365 
366  void set_nrchi_lower_boundary( Real low );
367  void set_nrchi_upper_boundary( Real high );
368  void set_nrchi_probability( Real nrchi_prob );
369 
370  bool nrchi_sample() const { return nrchi_sample_; }
371  bool chi_is_nonrotameric( Size chi ) const { return nrchi_sample_ && chi == nchi_; }
372  Size nchi() const { return nchi_; }
373  Size4 const & rot_well() const { return rot_well_; }
374  Real4 const & chi_mean() const { return chi_mean_; }
375  Real4 const & chi_sd() const { return chi_sd_; }
376  Real probability() const { return probability_; }
377 
381 
382  void assign_random_chi( utility::vector1< Real > & chi_angles, numeric::random::RandomGenerator & RG, core::Real factor=1.0) const;
383  Real chi_probability( utility::vector1< Real > const & chi_angles, core::Real factor=1.0 ) const;
384 
385 private:
386  bool nrchi_sample_; /// Does this sample describe a semi-rotameric residue?
387  Size nchi_; /// The number of chi values the library describes; Between 1 & 4.
388  Size4 rot_well_; /// The integer description of the rotamer conformation
389  Real4 chi_mean_; /// The chi angle at the center of the distribution
390  Real4 chi_sd_; /// Standard deviation from the center for each chi.
391  Real probability_; /// The probability of finding the rotamer in this rot_well.
392 
393  Real nrchi_lower_boundary_; /// Requires nrchi_sample_. The lower boundary of the non-rotameric chi well, in degrees.
394  Real nrchi_upper_boundary_; /// Requires nrchi_sample_. The upper boundary of the non-rotameric chi well, in degrees.
395  Real nrchi_probability_; /// Requires nrchi_sample_. The probability that the non-rotameric chi ends up in this well given its rotameric-chi assignment.
396 };
397 
398 
399 /// @brief a simple class for passing data around in virtual function
400 /// calls of the rotamer creating process. Derived classes will be simple
401 /// containers for interpolated rotameric data that 1) has to be available
402 /// to the derived class when building rotamers and 2) cannot be stored as
403 /// member data in the derived class in a thread-safe manner. Derived classes
404 /// of the RotamerBuildingData can be declared on the stack, passed into
405 /// the RotamericSingleResidueDunbrackLibrary::build_chi_sets function,
406 /// and then in the (virtual) chisamples_for_rotamer function, the derived classes
407 /// may be downcast.
409 {
410 public:
411  virtual ~RotamerBuildingData() = 0;
412 };
413 
414 
415 
416 /// Should this be here?
417 
418 void
420  pack::task::ExtraRotSample ex_samp_level,
421  chemical::ResidueTypeCOP concrete_residue,
422  Size proton_chi,
423  utility::vector1< ChiSetOP > & chi_set_vector
424 );
425 
426 
428  Real v00, Real d2dx200, Real d2dy200, Real d4dx2y200,
429  Real v01, Real d2dx201, Real d2dy201, Real d4dx2y201,
430  Real v10, Real d2dx210, Real d2dy210, Real d4dx2y210,
431  Real v11, Real d2dx211, Real d2dy211, Real d4dx2y211,
432  Real dxp, // in the range [0..1) representing the distance to the left bin boundary
433  Real dyp, // in the range [0..1) representing the distance to the lower bin boundary
434  Real binwx, // the size of the bin witdh for x
435  Real binwy, // the size of the bin width for y
436  Real & val,
437  Real & dvaldx,
438  Real & dvaldy
439 );
440 
441 void
443  Real v000, Real dvdx000, Real dvdy000, Real dvdz000, Real dvdxy000, Real dvdxz000, Real dvdyz000, Real dvdxyz000,
444  Real v001, Real dvdx001, Real dvdy001, Real dvdz001, Real dvdxy001, Real dvdxz001, Real dvdyz001, Real dvdxyz001,
445  Real v010, Real dvdx010, Real dvdy010, Real dvdz010, Real dvdxy010, Real dvdxz010, Real dvdyz010, Real dvdxyz010,
446  Real v011, Real dvdx011, Real dvdy011, Real dvdz011, Real dvdxy011, Real dvdxz011, Real dvdyz011, Real dvdxyz011,
447  Real v100, Real dvdx100, Real dvdy100, Real dvdz100, Real dvdxy100, Real dvdxz100, Real dvdyz100, Real dvdxyz100,
448  Real v101, Real dvdx101, Real dvdy101, Real dvdz101, Real dvdxy101, Real dvdxz101, Real dvdyz101, Real dvdxyz101,
449  Real v110, Real dvdx110, Real dvdy110, Real dvdz110, Real dvdxy110, Real dvdxz110, Real dvdyz110, Real dvdxyz110,
450  Real v111, Real dvdx111, Real dvdy111, Real dvdz111, Real dvdxy111, Real dvdxz111, Real dvdyz111, Real dvdxyz111,
451  Real dxp, Real dyp, Real dzp,
452  Real binwx, Real binwy, Real binwz,
453  Real & val,
454  Real & dvaldx,
455  Real & dvaldy,
456  Real & dvaldz
457 );
458 
460  DunbrackRotamer< FOUR > const & rot00,
461  DunbrackRotamer< FOUR > const & rot10,
462  DunbrackRotamer< FOUR > const & rot01,
463  DunbrackRotamer< FOUR > const & rot11,
464  Real phi_err, Real psi_err, Real binrange,
465  Size nchi_aa,
466  DunbrackRotamer< FOUR, Real > & interpolated_rotamer
467 );
468 
469 template < Size S >
472  DunbrackRotamer< S, DunbrackReal > const & original_rotamer
473 )
474 {
475  DunbrackRotamer< S, Real > new_rotamer;
476  for ( Size ii = 1; ii <= S; ++ii ) {
477  new_rotamer.chi_mean( ii ) = static_cast< Real > ( original_rotamer.chi_mean( ii ) );
478  new_rotamer.chi_sd( ii ) = static_cast< Real > ( original_rotamer.chi_sd( ii ) );
479  new_rotamer.rotwell( ii ) = original_rotamer.rotwell( ii );
480  }
481  new_rotamer.rotamer_probability() = static_cast< Real > ( original_rotamer.rotamer_probability() );
482  return new_rotamer;
483 }
484 
485 
486 } //dunbrack
487 } //scoring
488 } // core
489 
490 #endif