Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SemiRotamericSingleResidueDunbrackLibrary.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/SemiRotamericSingleResidueDunbrackLibrary.hh
11 /// @brief Declaration of semi-rotameric rotamer libraries from Jun08
12 /// @author Andrew Leaver-Fay
13 
14 
15 #ifndef INCLUDED_core_pack_dunbrack_SemiRotamericSingleResidueDunbrackLibrary_hh
16 #define INCLUDED_core_pack_dunbrack_SemiRotamericSingleResidueDunbrackLibrary_hh
17 
18 // Unit Headers
20 
21 // Package Headers
25 
26 // Project Headers
28 
29 // ObjexxFCL Headers
30 #include <ObjexxFCL/FArray2D.hh>
31 #include <ObjexxFCL/FArray3D.hh>
32 #include <ObjexxFCL/FArray4D.hh>
33 
34 #include <utility/vector1.hh>
35 
36 
37 namespace core {
38 namespace pack {
39 namespace dunbrack {
40 
41 template < class P = DunbrackReal >
43 
44 template < class P = DunbrackReal >
46 
47 /// P for precision
48 template < class P >
49 class BBDepNRChiSample
50 {
51 public:
53  packed_rotno_( 0 ),
54  nrchi_bin_( 0 ),
55  nrchi_mean_( 0.0 ),
56  nrchi_sd_( 0.0 ),
57  prob_( 0.0 )
58  {}
59 
60  /// The packed_rotno_ information is sufficient to determine the
61  /// mean and standard deviation of the rotameric chis; it is used
62  /// as an index into another table containing this data.
68 };
69 
70 template < class P >
71 class BBIndNRChiSample
72 {
73 public:
75  left_( P( 0.0 ) ),
76  median_( P( 0.0 ) ),
77  right_( P( 0.0 ) ),
78  prob_( P( 0.0 ) )
79  {}
80 
85 };
86 
87 /// @brief A class to hold rotamer building data on the stack and yet have it
88 /// accessible to derived classes when invoking base class functions. An
89 /// alternative would have been to store mutable member data in the Library
90 /// class itself. This option, however, is not thread safe.
91 /// This data is used by the SemiRotamericSRDL class for when building
92 /// backbone dependent rotamers.
93 template < Size T >
95 {
96 public:
98 
99 public:
101  DunbrackRotamer< T, Real > const & rotamer_in,
102  BBDepNRChiSample< Real > const & bbdep_nrchi_sample_in
103  )
104  :
105  parent( rotamer_in ),
106  bbdep_nrchi_sample_( bbdep_nrchi_sample_in )
107  {}
108 
110 
113  return bbdep_nrchi_sample_;
114  }
115 
116 private:
118 
119 };
120 
122 {
123 public:
125  value_(0.0),
126  dsecox_(0.0),
127  dsecoy_(0.0),
128  dsecoz_(0.0),
129  dsecoxy_(0.0),
130  dsecoxz_(0.0),
131  dsecoyz_(0.0),
132  dsecoxyz_(0.0)
133  {}
134 
135  DunbrackReal value_; ///< f(x,y,z)
136  DunbrackReal dsecox_; ///< second order derivative for x -- d**2/dx**2 f(x,y,z)
137  DunbrackReal dsecoy_; ///< second order derivative for y
138  DunbrackReal dsecoz_; ///< second order derivative for z
139  DunbrackReal dsecoxy_; ///< second order derivative for x and y
140  DunbrackReal dsecoxz_; ///< second order derivative for x and z
141  DunbrackReal dsecoyz_; ///< second order derivative for y and z
142  DunbrackReal dsecoxyz_; ///< second order derivative for x y and z
143 };
144 
145 
146 /// @brief A class to hold rotamer building data on the stack and yet have it
147 /// accessible to derived classes when invoking base class functions. An
148 /// alternative would have been to store mutable member data in the Library
149 /// class itself. This option, however, is not thread safe.
150 /// This data is used by the SemiRotamericSRDL class for when building
151 /// backbone independent rotamers.
152 template < Size T >
154 {
155 public:
157 public:
160  BBIndNRChiSample<> const & bbind_nrchi_sample_in,
161  Size const nrchi_bin_id_in
162  )
163  :
164  parent( rotamer ),
165  bbind_nrchi_sample_( bbind_nrchi_sample_in ),
166  nrchi_bin_id_( nrchi_bin_id_in )
167  {}
168 
170 
171  BBIndNRChiSample<> const &
173  return bbind_nrchi_sample_;
174  }
175 
176  Size
177  nrchi_bin_id() const {
178  return nrchi_bin_id_;
179  }
180 
181 private:
182 
185 };
186 
187 
188 
190 public:
193 };
194 
195 bool
197 
198 
199 /// @brief This class is meant to represent the non-rotameric chi observed in
200 /// several amino acids (asn, asp, gln, glu, his, phe, trp, tyr ) which are rotameric
201 /// for the chi closest to the backbone and non rotameric for exactly one chi angle.
202 /// This non-rotameric chi (abv. nrchi) is the last chi for each of these 8 amino acids
203 /// except tyrosine, where this chi is the last heavy-atom chi. The last chi on tyrosine
204 /// governs a hydroxyl.
205 /// Unlike in the fully rotameric residues, the last heavyatom chi in semi-rotameric residues
206 /// do not "communicate" to the rotameric chi. That is, in the rotameric chi, the mean chi1 value
207 /// is sensitive to the chi3 value. If the third diherdal switches from trans to g+, then chi1
208 /// would shift in response. Changes to the non-rotameric chi do not effect the rotameric chi.
209 /// The data structure here is good for this model but no other.
210 template < Size T >
212 {
213 public:
216 
217 public:
218 
219  /// @brief The constructor determines the path the library takes: whether
220  /// it uses a backbone dependent or independent score function for the
221  /// non-rotameric chi (the rotameric chi score function is always backbone dependent)
222  /// and whether it uses a backbone dependent or independent rotamer sampling
223  /// scheme. All four combinations are possible, though backbone independent scoring
224  /// and backbone dependent rotamer sampling seems a poor combination.
226  chemical::AA const aa_in,
227  bool const backbone_independent_scoring, // true uses less memory
228  bool const backbone_independent_rotamer_sampling // true uses less memory
229  );
230 
232 
234 public:
235  /// Virtual functions required by the base classes
236 
237  virtual
238  Real
240  conformation::Residue const & rsd,
242  ) const;
243 
244  virtual
245  Real
247  conformation::Residue const & rsd,
249  ) const;
250 
251 
252  /// @brief Returns the energy of the lowest-energy rotamer accessible to the given residue
253  /// (based on e.g. its current phi and psi values).
254  /// If curr_rotamer_only is true, then consider only the idealized version of the
255  /// residue's current rotamer (local optimum); otherwise, consider all rotamers (global optimum).
256  virtual
257  Real
259  conformation::Residue const & rsd,
260  bool curr_rotamer_only,
262  ) const;
263 
264  virtual
265  void
267  conformation::Residue const & rsd,
268  RotamerLibraryScratchSpace & scratch,
269  numeric::random::RandomGenerator & RG,
270  ChiVector & new_chi_angles,
271  bool perturb_from_rotamer_center
272  ) const;
273 
274  virtual
275  void
277  pose::Pose const & pose,
278  scoring::ScoreFunction const & scorefxn,
279  pack::task::PackerTask const & task,
280  graph::GraphCOP packer_neighbor_graph,
281  chemical::ResidueTypeCOP concrete_residue,
282  conformation::Residue const & existing_residue,
283  utility::vector1< utility::vector1< Real > > const & extra_chi_steps,
284  bool buried,
286  ) const;
287 
288  /// @brief Return all of the rotamer sample data given a particular phi/psi.
289  /// For N-terminus residues, hand in the phi value SingleResidueDunbrackLibrary::PHI_NEUTRAL and
290  /// for C-terminus residues, hand in the psi value SingleResidueDunbrackLibrary::PSI_NEUTRAL.
291  /// The returned samples should be in semi-decrasing order by probability; semi, because the
292  /// rotamers are constructed in sorted order by their probability in the lower phi-psi bin that
293  /// the input phi/psi perscribes.
294  virtual
297  Real phi,
298  Real psi
299  ) const;
300 
301  virtual
302  Real
304  Real phi,
305  Real psi,
306  Size rot_ind
307  ) const;
308 
309  virtual
311  get_rotamer(
312  Real phi,
313  Real psi,
314  Size rot_ind
315  ) const;
316 
317  virtual
318  Size nchi() const;
319 
320  virtual
321  Size n_rotamer_bins() const;
322 
323  //XRW_B_T1
324  /*
325  // stubbed out
326  virtual
327  SingleResidueRotamerLibraryOP
328  coarsify(coarse::Translator const &map) const;
329  */
330  //XRW_E_T1
331 
332  // stubbed out
333  virtual
334  void
335  write_to_file( utility::io::ozstream & out ) const;
336 
337  virtual void write_to_binary( utility::io::ozstream & out ) const;
338 
339  /// @brief Initialize either a backbone-independent or a backbone-dependent SRSRDL
340  /// from the set of four files which describe both (not all files are read).
341  void read_from_files(
342  utility::io::izstream & in_rotdef,
343  utility::io::izstream & in_rotameric,
344  utility::io::izstream & in_continmin_bbdep,
345  utility::io::izstream & in_continmin_bbind
346  );
347 
348  /// @brief Initialize a backbone-dependent SRSRDL from the set of three files
349  /// which describe it.
350  void
352  utility::io::izstream & in_rotdef,
353  utility::io::izstream & in_rotameric,
354  utility::io::izstream & in_continmin_bbdep
355  );
356 
357  virtual void read_from_binary( utility::io::izstream & in );
358 
359  virtual
360  void
362  ChiVector const & chi,
363  RotVector & rot
364  ) const;
365 
366 public:
367  /// Initialization functions that must be called before reading the input libraries.
368 
369 
370  /// @brief For the non rotameric chi, how many asymmetric degrees are there? (e.g. 360 for asn, 180 for asp)
371  void
372  set_nrchi_periodicity( Real angle_in_degrees );
373 
374  /// @brief What angle do the interpolation data start from?
375  void
376  set_nonrotameric_chi_start_angle( Real angle_in_degrees );
377 
378  /// @brief What is the angular step size of the bbdep score?
379  void
380  set_nonrotameric_chi_bbdep_scoring_step_size( Real step_size_in_degrees );
381 
382  /// @brief What is the angular step size of the bbind score?
383  void
384  set_nonrotameric_chi_bbind_scoring_step_size( Real step_size_in_degrees );
385 
386 protected:
387 
388  virtual Size memory_usage_static() const;
389  virtual Size memory_usage_dynamic() const;
390 
391  Real
393  conformation::Residue const & rsd,
394  RotamerLibraryScratchSpace & scratch,
395  bool eval_deriv
396  ) const;
397 
398  Real
400  conformation::Residue const & rsd,
401  RotamerLibraryScratchSpace & scratch,
402  bool eval_deriv
403  ) const;
404 
405  void
407  conformation::Residue const & rsd,
408  RotamerLibraryScratchSpace & scratch,
409  numeric::random::RandomGenerator & RG,
410  ChiVector & new_chi_angles,
411  bool perturb_from_rotamer_center
412  ) const;
413 
414  void
416  conformation::Residue const & rsd,
417  RotamerLibraryScratchSpace & scratch,
418  numeric::random::RandomGenerator & RG,
419  ChiVector & new_chi_angles,
420  bool perturb_from_rotamer_center
421  ) const;
422 
423  Real
425  conformation::Residue const & rsd,
426  RotamerLibraryScratchSpace & scratch,
427  Real & dnrchi_score_dnrchi
428  ) const;
429 
430  Real
432  conformation::Residue const & rsd,
433  RotamerLibraryScratchSpace & scratch,
434  Real & dnrchi_score_dnrchi,
435  Real & dnrchi_score_dphi,
436  Real & dnrchi_score_dpsi
437  ) const;
438 
439 
440  void
442  pose::Pose const & pose,
443  scoring::ScoreFunction const & scorefxn,
444  pack::task::PackerTask const & task,
445  graph::GraphCOP packer_neighbor_graph,
446  chemical::ResidueTypeCOP concrete_residue,
447  conformation::Residue const & existing_residue,
448  utility::vector1< utility::vector1< Real > > const & extra_chi_steps,
449  bool buried,
451  ) const;
452 
453  void
455  pose::Pose const & pose,
456  scoring::ScoreFunction const & scorefxn,
457  pack::task::PackerTask const & task,
458  graph::GraphCOP packer_neighbor_graph,
459  chemical::ResidueTypeCOP concrete_residue,
460  conformation::Residue const & existing_residue,
461  utility::vector1< utility::vector1< Real > > const & extra_chi_steps,
462  bool buried,
464  ) const;
465 
468  Real phi,
469  Real psi
470  ) const;
471 
474  Real phi,
475  Real psi
476  ) const;
477 
478  Real
480  Real phi,
481  Real psi,
482  Size rot_ind
483  ) const;
484 
485  Real
487  Real phi,
488  Real psi,
489  Size rot_ind
490  ) const;
491 
494  Real phi,
495  Real psi,
496  Size rot_ind
497  ) const;
498 
499 
502  Real phi,
503  Real psi,
504  Size rot_ind
505  ) const;
506 
507  /// @brief overrides parent class for the non-rotameric chi, but falls back
508  /// on the parent class functionality for all other chi.
509  virtual
510  void
512  chemical::ResidueType const & rsd_type,
513  pack::task::ResidueLevelTask const & rtask,
514  bool buried,
515  Size const chi_index,
516  RotamericData< T > const & rotamer_data,
517  utility::vector1< Real > const & extra_steps,
518  utility::vector1< Real > & total_chi,
519  utility::vector1< int > & total_rot,
520  utility::vector1< Real > & total_ex_steps,
521  utility::vector1< Real > & chisample_prob
522  ) const;
523 
524 
525 private:
526  void
527  read_rotamer_definitions( utility::io::izstream & in_rotdef );
528 
529  void
530  read_bbdep_continuous_minimization_data( utility::io::izstream & in_contmin );
531 
532  void
533  read_bbind_continuous_minimization_data( utility::io::izstream & in_contmin );
534 
535  void
536  read_rotameric_data( utility::io::izstream & in_rotameric );
537 
538  void
540  pose::Pose const & pose,
541  scoring::ScoreFunction const & scorefxn,
542  pack::task::PackerTask const & task,
543  graph::GraphCOP packer_neighbor_graph,
544  chemical::ResidueTypeCOP concrete_residue,
545  conformation::Residue const& existing_residue,
546  utility::vector1< utility::vector1< Real > > const & extra_chi_steps,
547  bool buried,
548  PackedDunbrackRotamer< T, Real > const & interpolated_rotamer,
549  BBDepNRChiSample< Real > const interpolated_sample,
551  ) const;
552 
553  void
555  pose::Pose const & pose,
556  scoring::ScoreFunction const & scorefxn,
557  pack::task::PackerTask const & task,
558  graph::GraphCOP packer_neighbor_graph,
559  chemical::ResidueTypeCOP concrete_residue,
560  conformation::Residue const& existing_residue,
561  utility::vector1< utility::vector1< Real > > const & extra_chi_steps,
562  bool buried,
563  PackedDunbrackRotamer< T, Real > const & interpolated_rotamer,
564  Size const nrchi_rotno,
565  BBIndNRChiSample<> const & interpolated_sample,
567  ) const;
568 
569  void
571  chemical::ResidueType const & rsd_type,
572  pack::task::ResidueLevelTask const & rtask,
573  bool buried,
574  Size const chi_index,
575  RotamericData< T > const & rotamer_data,
576  utility::vector1< Real > const & extra_steps,
577  utility::vector1< Real > & total_chi,
578  utility::vector1< int > & total_rot,
579  utility::vector1< Real > & total_ex_steps,
580  utility::vector1< Real > & chisample_prob
581  ) const;
582 
583  void
585  chemical::ResidueType const & rsd_type,
586  pack::task::ResidueLevelTask const & rtask,
587  bool buried,
588  Size const chi_index,
589  RotamericData< T > const & rotamer_data,
590  utility::vector1< Real > const & extra_steps,
591  utility::vector1< Real > & total_chi,
592  utility::vector1< int > & total_rot,
593  utility::vector1< Real > & total_ex_steps,
594  utility::vector1< Real > & chisample_prob
595  ) const;
596 
597  Real clip_to_nrchi_range( Real chi ) const;
598 
599  void get_bbdep_nrchi_bin(
600  Real nrchi,
601  Size & bin_lower,
602  Size & bin_upper,
603  Real & nrchi_alpha
604  ) const;
605 
606  void get_bbind_nrchi_bin(
607  Real nrchi,
608  Size & bin_lower,
609  Size & bin_upper,
610  Real & nrchi_alpha
611  ) const;
612 
615  Size const packed_rotno,
616  Size const nrchi_bin,
617  Size const phibin,
618  Size const psibin,
619  Size const phibin_next,
620  Size const psibin_next,
621  Real const phi_alpha,
622  Real const psi_alpha
623  ) const;
624 
627  BBDepNRChiSample<> const & nrchi_sample_00,
628  BBDepNRChiSample<> const & nrchi_sample_01,
629  BBDepNRChiSample<> const & nrchi_sample_10,
630  BBDepNRChiSample<> const & nrchi_sample_11,
631  Real const phi_alpha,
632  Real const psi_alpha
633  ) const;
634 
635 private:
636  /// @brief no default ctor
637  ///SemiRotamericSingleResidueDunbrackLibrary();
638 
639 private:
640 
641  bool const bbind_nrchi_scoring_; // Score non-rotameric chi independently of the backbone?
642  bool const bbind_nrchi_sampling_; // Sample non-rotameric chi independently of the backbone?
643 
644  Real nrchi_periodicity_; // 360 w/o symmetry; 180 w/.
645  Real nrchi_lower_angle_; // Starting angle for both bbdep and bbind nrchi data
646 
647  /// The non rotameric chi is n_rotameric_chi + 1;
648  /// The FArray3D is indexed as (phi, psi, nrchi). Probabilities are input; the
649  /// parameters for tricubic interpolation are stored. The supporting information is used to snap chi values stored in a
650  /// residue to a meaningful periodic range and to make tricubic interpolation possible.
651  /// This data is used only if bbind_nrchi_scoring is false.
655 
656  /// If bbind_nrchi_scoring_ is true, then this array holds the continuous minimization data for
657  /// each of the packed rotamers.
658  ObjexxFCL::FArray2D< Real > bbind_non_rotameric_chi_scores_;
661 
662 
663  /// For rotamer sampling, "pseudo rotamers" are defined for the non rotameric chi. These
664  /// rotamers are arbitrary bins in chi space, and each bin gives a left and right edge
665  /// as well as a median (mode?) angle which is used for rotamer sampling iff bbind_nrchi_sampling_
666  /// is true. The bins do not have a uniform width.
667 
668  // Used in both bbind and bbdep rotamer building. Read from rotamer definition file.
670 
671 
672  /// This variable is used iff bbind_nrchi_sampling_ is true;
673  /// Space is not allocated if it is false.
674  /// The algorithm for creating the top 95% most probable rotamers relies on a
675  /// sorted order for these rotamers, which is why we need bbind_rotamers_sorted_by_probability_.
676  ObjexxFCL::FArray2D< BBIndNRChiSample<> > bbind_rotamers_to_sample_;
677  ObjexxFCL::FArray2D< Size > bbind_rotamers_sorted_by_probability_;
678 
679  /// This variable is used iff bbind_nrchi_sampling_ is false;
680  /// Space is not allocated if it is true.
681  ObjexxFCL::FArray3D< BBDepNRChiSample<> > bbdep_rotamers_to_sample_;
682  ObjexxFCL::FArray4D< Size > bbdep_rotsample_sorted_order_;
683 
684 };
685 
686 
687 } // namespace dunbrack
688 } // namespace scoring
689 } // namespace core
690 
691 #endif // INCLUDED_core_pack_dunbrack_SemiRotamericSingleResidueDunbrackLibrary_HH