Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RotamerLibrary.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/RotamerLibrary.hh
11 /// @brief Rotamer Library classes
12 /// @author Phil Bradley
13 
14 
15 #ifndef INCLUDED_core_pack_dunbrack_RotamerLibrary_hh
16 #define INCLUDED_core_pack_dunbrack_RotamerLibrary_hh
17 
18 // Unit headers
20 
21 
22 // Package headers
25 // AUTO-REMOVED #include <core/pack/dunbrack/RotamericSingleResidueDunbrackLibrary.fwd.hh>
27 // AUTO-REMOVED #include <core/scoring/types.hh>
28 
29 // Project headers
30 #include <core/chemical/AA.hh>
32 //XRW_B_T1
33 //#include <core/coarse/Translator.fwd.hh>
34 //XRW_E_T1
36 #include <core/graph/Graph.fwd.hh>
39 #include <core/pose/Pose.fwd.hh>
40 
41 #ifdef WIN32 //VC++ needs full class declaration
42 #include <core/graph/Graph.hh> // WIN32 INCLUDE
43 #endif
44 
45 // Utility headers
46 #include <utility/pointer/ReferenceCount.hh>
47 // AUTO-REMOVED #include <utility/vector1.hh>
48 // AUTO-REMOVED #include <utility/exit.hh>
49 #include <utility/io/ozstream.fwd.hh>
50 #include <utility/io/izstream.fwd.hh>
51 
52 // Numeric headers
53 #include <numeric/random/random.fwd.hh>
54 
55 // C++ headers
56 #include <map>
57 
58 #include <utility/vector1.hh>
59 
60 
61 namespace core {
62 namespace pack {
63 namespace dunbrack {
64 
65 void
67  conformation::Residue const & rsd,
68  RotVector & rot
69 );
70 
71 void
73  chemical::ResidueType const & rsd_type,
74  ChiVector const & chi,
75  RotVector & rot
76 );
77 
78 /// @brief Do not bother calling this function if you're interested in staying
79 /// up to date with changes in the rotamer library. Call rotamer_from_chi instead.
80 /// It will eventually call this function iff dun10 is not set to true.
81 void
83  ChiVector const & chi,
84  //ChiVector chi, //pass in by value and locally modified
85  chemical::AA const res, // pass an AA, not an AA &
86  RotVector & rot
87 );
88 
89 void
91  Real4 const & chi,
92  chemical::AA const res,
93  Size nchi,
94  Size4 & rot
95 );
96 
97 /// @brief Find the difference in angles between two chi values using hard-coded
98 /// symmetry information for the symmetric amino acids. Disappears for 2010 library.
99 Real
101  Real chi1,
102  Real chi2,
103  chemical::AA const & aa,
104  int chino
105 );
106 
107 ///////////////////////////////////////////////////////////////////////////////
108 // pure virtual base class
110 {
111 public:
112  virtual
114 
115  virtual
116  Real
118  conformation::Residue const & rsd,
120  ) const = 0;
121 
122 
123  virtual
124  Real
126  conformation::Residue const & rsd,
128  ) const = 0;
129 
130  /// @brief Returns the energy of the lowest-energy rotamer accessible to the given residue
131  /// (based on e.g. its current phi and psi values).
132  /// If curr_rotamer_only is true, then consider only the idealized version of the
133  /// residue's current rotamer (local optimum); otherwise, consider all rotamers (global optimum).
134  virtual
135  Real
137  conformation::Residue const & rsd,
138  bool curr_rotamer_only,
140  ) const = 0;
141 
142  /// @brief Pick a rotamer for the input residue according to the rotamer probability
143  /// distribution and assign chi angles to the input rsd. If perturb_from_rotamer_center
144  /// is true, then push the rotamer off from the center; for chi angles with a normal
145  /// distribution, the perturbation is taken from a Gaussian random number with a standard
146  /// deviation matching the chi angle's standard deviation. For chi angles that are not
147  /// normally distributed, the behavior is open to the derived classe's interpretation.
148  virtual
149  void
151  conformation::Residue const & rsd,
152  RotamerLibraryScratchSpace & scratch,
153  numeric::random::RandomGenerator & RG,
154  ChiVector & new_chi_angles,
155  bool perturb_from_rotamer_center
156  ) const = 0;
157 
158  virtual
159  void
161  pose::Pose const & pose,
162  scoring::ScoreFunction const & scorefxn,
163  pack::task::PackerTask const & task,
164  graph::GraphCOP packer_neighbor_graph,
165  chemical::ResidueTypeCOP concrete_residue,
166  conformation::Residue const& existing_residue,
167  utility::vector1< utility::vector1< Real > > const & extra_chi_steps,
168  bool buried,
169  RotamerVector & rotamers
170  ) const = 0;
171 
172  //XRW_B_T1
173  /*
174  virtual
175  SingleResidueRotamerLibraryOP
176  coarsify(coarse::Translator const &map) const = 0;
177  */
178  //XRW_E_T1
179 
180  virtual
181  void
182  write_to_file( utility::io::ozstream &out ) const = 0;
183 
184 };
185 
186 
187 ///////////////////////////////////////////////////////////////////////////////
188 ///////////////////////////////////////////////////////////////////////////////
189 
190 class RotamerLibrary // singleton -- no need to derive from RefCount : public utility::pointer::ReferenceCount
191 {
192 
193 public:
194  typedef chemical::AA AA;
197 
198 public:
199  virtual ~RotamerLibrary();
200 
201  Real
203  Residue const & rsd,
205  ) const;
206 
207  Real
209  Residue const & rsd,
210  bool curr_rotamer_only,
212  ) const;
213 
214  /// to do:
215  Real
217  Residue const & rsd,
219  ) const;
220 
221  ///
222  void
224  AA const & aa,
226  ) const;
227 
228  /// @brief Overrides the library for AA
229  void
231  ResidueType const & rsd_type,
233  ) const;
234 
235  //XRW_B_T1
236  // RotamerLibraryOP coarsify(coarse::TranslatorSet const &map_set) const;
237  //XRW_E_T1
238 
239  bool
240  rsd_library_already_loaded( chemical::ResidueType const & rsd_type ) const;
241 
243  get_rsd_library( chemical::ResidueType const & rsd_type ) const;
244 
246  get_library_by_aa( chemical::AA const & aa ) const;
247 
248  //output dunbrack library -- coarse rotamers can be cached on disk
249  void
251 
252  /// @brief Public interface to read in dunbrack libraries. dun10 option checks
253  /// are handled inside.
255 
257  get_NCAARotamerLibrary( chemical::ResidueType const & rsd_type ) const;
258 
259  static
261 
262 
263 private:
264 
265  bool decide_read_from_binary() const;
266 
267  bool decide_read_from_binary_02() const;
268  bool decide_read_from_binary_10() const;
269 
270  bool binary_is_up_to_date( utility::io::izstream & binlib ) const;
271 
272  bool binary_is_up_to_date_02( utility::io::izstream & binlib ) const;
273  bool binary_is_up_to_date_10( utility::io::izstream & binlib ) const;
274 
275  bool decide_write_binary() const;
276 
277  bool decide_write_binary_02() const;
278  bool decide_write_binary_10() const;
279 
281 
283 
286 
289 
291 
293 
296 
297 
300 
302 
305 
306  std::string random_tempname( std::string const & prefix ) const;
307 
308  template < Size T >
309  void
312  bool const nrchi_is_symmetric,
313  Real const nrchi_start_angle,
314  utility::io::izstream & rotamer_definitions,
315  utility::io::izstream & regular_library,
316  utility::io::izstream & continuous_minimization_bbdep
317  // phasing out bbind sampling -- utility::io::izstream & rnchi_bbind_probabilities
318  ) const;
319 
320  template < Size T >
321  void
324  bool const nrchi_is_symmetric,
325  Real const nrchi_start_angle
326  ) const;
327 
328  /// @brief Instantiate the appropriate RSRDL< T > library given the n_chi input and initialize
329  /// the library from the input stream. Return the string that the library returns after reading
330  /// the from the stream (which may be the empty string, or the three letter code for the next AA
331  /// in the input stream). If the first three letter code for this amino acid has already been
332  /// retrieved from the input stream, indicate so with the "first_three_letter_code_alread_read"
333  /// boolean.
336  chemical::AA aa,
337  Size const n_chi,
338  utility::io::izstream & library,
339  bool dun02,
340  std::string & next_aa_in_library,
341  bool first_three_letter_code_already_read
342  ) const;
343 
346  chemical::AA aa,
347  Size const n_chi,
348  bool dun02
349  ) const;
350 
351  /// @brief Instantiate the appropriate SRSRDL< T > library given the nchi input. nchi indicates
352  /// the number of rotameric chi -- there are nchi+1 chi described by the library, the last of which
353  /// is non-rotameric. (E.g. Tyrosine has an nchi of 1, its chi2 is non-rotameric and its chi3 is not
354  /// described by the library.) The input streams are either read or not read depending on the
355  /// boolean variables.
358  chemical::AA aa,
359  Size const nchi,
360  bool const use_bbind_rnchi_scoring,
361  bool const use_bbind_rnchi_sampling,
362  bool const nrchi_is_symmetric,
363  Real const nrchi_start_angle,
364  utility::io::izstream & rotamer_definitions,
365  utility::io::izstream & regular_library,
366  utility::io::izstream & continuous_minimization_bbdep
367  // phasing out bbind sampling -- utility::io::izstream & rnchi_bbind_probabilities
368  ) const;
369 
372  chemical::AA aa,
373  Size const nchi,
374  bool const use_bbind_rnchi_scoring,
375  bool const use_bbind_rnchi_sampling,
376  bool const nrchi_is_symmetric,
377  Real const nrchi_start_angle
378  ) const;
379 
381  create_srdl(
382  chemical::AA aa_in
383  ) const;
384 
385 public:
386  static
387  void
389  utility::vector1< chemical::AA > & rotameric_amino_acids,
390  utility::vector1< Size > & rotameric_n_chi,
392  utility::vector1< Size > & srnchi,
393  utility::vector1< bool > & scind,
394  utility::vector1< bool > & sampind,
397  );
398 
399  static
400  void
402  utility::vector1< chemical::AA > & rotameric_amino_acids,
403  utility::vector1< Size > & rotameric_n_chi
404  );
405 
406  static
407  void
409  utility::vector1< Size > & nchi_for_aa,
410  Size & n_rotameric_aas
411  );
412 
413 private:
414  void
415  write_to_binary( utility::io::ozstream & out ) const;
416 
417  void
418  read_from_binary( utility::io::izstream & in );
419 
420 
421 
422  RotamerLibrary();
423  RotamerLibrary( RotamerLibrary const & ); // unimplemented
424  RotamerLibrary const & operator = ( RotamerLibrary const & ); // unimplemented
425 
427 
428 private:
429 
430  // For thread safety, store the OPs in an unchanging and never-used vector;
431  // keep copies of the APs in a map for actual use.
432  // (OPs cannot be shared across threads because copying them onto the stack
433  // results in increment / decrement operations on the reference count.)
434  // If this doesn't make you weep for a language with real garbage collection,
435  // I don't know what would.
436  typedef std::map< AA, SingleResidueRotamerLibraryCAP > LibraryMap;
437  typedef LibraryMap::const_iterator library_iterator;
438 
439  // These entries take precedence over the entries for an amino acid.
440  // The string used for the key is ResidueType.name()
441  typedef std::map< std::string, SingleResidueRotamerLibraryCAP > ResLibraryMap;
442  typedef ResLibraryMap::const_iterator reslibrary_iterator;
443 
448  mutable std::map< std::string, pack::dunbrack::SingleResidueRotamerLibraryCOP > ncaa_rotlibs_;
449 
450 };
451 
452 // Unsure -- do the following methods really belong in this file?
453 
454 // XRW if coarse is removed than this functions signature will have to chanhge
455 /* SingleResidueDunbrackLibraryOP
456 read_single_dunbrack_library(
457  utility::io::izstream &iunit,
458  bool coarse
459 ); */
460 
461 
462 void
464  RotamerLibrary & rotamer_library
465 );
466 
467 
468 } // dunbrack
469 } // pack
470 } // core
471 
472 
473 #endif // INCLUDED_core_pack_dunbrack_RotamerLibrary_HH