Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PackDaemon.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 protocols/pack_daemon/PackDaemon.hh
11 /// @brief declaration for class PackDaemon
12 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
13 
14 #ifndef INCLUDED_protocols_pack_daemon_PackDaemon_hh
15 #define INCLUDED_protocols_pack_daemon_PackDaemon_hh
16 
17 // Unit headers
19 
20 // Package headers
22 
23 // Project headers
24 #include <core/types.hh>
25 #include <core/pose/Pose.fwd.hh>
37 
39 
40 // Utility headers
41 #include <utility/vector0.hh>
42 #include <utility/pointer/ReferenceCount.hh>
43 
44 // ObjexxFCL headers
45 // AUTO-REMOVED #include <ObjexxFCL/FArray1D.hh>
46 
47 // C++ headers
48 // AUTO-REMOVED #include <utility>
49 #include <list>
50 
51 // Boost headers
52 #include <boost/unordered_map.hpp>
53 
54 #include <utility/vector1.hh>
55 
56 #ifdef WIN32
58 #endif
59 
60 
61 namespace protocols {
62 namespace pack_daemon {
63 
65 public:
66  typedef core::Real Real;
67  typedef core::Size Size;
68 
78 
86 
93 
95  typedef std::pair< RotamerAssignment, Real > RotamerAssignmentAndEnergy;
97  typedef boost::unordered_map< EntityElements, RotamerAssignmentAndEnergy, Vec1Hash, EntElemEq > EntityToRotamerHash;
98 
99 public:
100  PackDaemon();
101  virtual ~PackDaemon();
102 
103  // Initialize the PackDaemon with the appropriate data before
104  // calling setup().
105  void set_pose_and_task( Pose const &, PackerTask const & );
106  void set_score_function( ScoreFunction const & );
108  void set_include_background_energies( bool setting );
109  /// @brief restrict the amount of memory spent on storing Rotamer Pair Energies in the
110  /// DoubleLazyInteractionGraph;
111  void set_dlig_nmeg_limit( Size setting );
112 
113  void setup(); // must be called before compute_energy_for_assignment;
114 
115  /// @brief Repack the structure with the Entity
116  /// This function proceeds in two steps: it creates a list of
117  /// rotamer indices to be used during the repacking, and then
118  /// it uses that list to repack the rotamers. The first step
119  /// is taken care of by the select_rotamer_subset method.
121 
123  select_rotamer_subset( Entity const & ) const;
124 
126  void mark_entity_as_unimportant( Entity const & );
127 
128  PoseCOP pose() const;
130  PackerTaskCOP task() const;
133  RotamerSetsCOP rot_sets() const;
134 
137 
138  PoseOP recreate_pose_for_entity( Entity const & ) const;
139  void assign_last_rotamers_to_pose( Pose & pose ) const;
140 
141  void print_entity_history() const;
142 
143 private:
145 
146 private:
147  // Primary data -- set from outside
152 
153  /// Should one-body energies for background residues and
154  /// two body energies for pairs of background residues
155  /// be included in the total energy for the state after repacking,
156  /// along with the energies of those residues which have been repacked?
159 
160  // Derived data -- set internally
164 
166  /*QuickRepackerOP repacker2_;
167  QuickRepackerOP repacker3_;
168  QuickRepackerOP repacker4_;
169  QuickRepackerOP repacker5_;
170  QuickRepackerOP repacker6_;
171  QuickRepackerOP repacker7_;
172  QuickRepackerOP repacker8_;*/
173 
179 
181 
182 };
183 
194 };
195 
197 {
198 public:
208 
211  typedef ConstDaemonList::const_iterator ConstDaemonListIter;
213  typedef DaemonList::const_iterator DaemonListIter;
214 
215  typedef std::pair< core::Size, core::Real > SizeRealPair;
216  typedef std::list< SizeRealPair > SizeRealPairs;
217  typedef std::pair< SizeRealPairs, SizeRealPairs > StateEsAndNPDs;
218 
219  typedef std::pair< core::Size, NPDPropCalculatorOP > NPDIndAndCalc;
220 public:
221  DaemonSet();
222  virtual ~DaemonSet();
223 
224  void set_entity_resfile( std::string const & resfile );
225  void set_entity_resfile( std::istream & resfile, std::string const & resfile_name );
226 
227  void set_score_function( ScoreFunction const & );
229 
230  void set_include_background_energies( bool setting );
231 
232  /// @brief restrict the amount of memory spent on storing Rotamer Pair Energies in the
233  /// DoubleLazyInteractionGraph;
234  void set_dlig_nmeg_limit( Size setting );
235 
237 
238  /// @brief Each daemon is associated with an index representing its position in
239  /// some master list somewhere. The DaemonSet is responsible for keeping this index.
240  void add_pack_daemon(
241  Size daemon_index,
242  std::string const & pdb_name,
243  std::string const & correspondence_file_name,
244  std::string const & secondary_resfile
245  );
246 
247  void
249  Size daemon_index,
250  std::string const & pose_file_name,
251  Pose const & pose,
252  std::string const & correspondence_file_filename,
253  std::istream & correspondence_file,
254  std::string const & secondary_refile_file_filename,
255  std::istream & secondary_resfile
256  );
257 
258  void
260  Size daemon_index,
261  std::string const & npd_property,
262  Size npd_index
263  );
264 
265  /// @brief call daemon->setup() on all daemons, which will trigger the
266  /// precomputation of all rotamer pair energies.
267  void setup_daemons();
268 
269  core::Size ndaemons() const;
271 
272  /// @brief Compute the state energies and, for those states requiring non-pairwise-decomposable-properties,
273  /// the non-pairwise decomposable properties as well. Return them as a pair of lists.
275  compute_energy_for_assignment( Entity const & entity );
276 
277  ConstDaemonList daemons() const;
278 
280  void mark_entity_as_unimportant( Entity const & );
281 
282  std::list< std::pair< Size, PoseOP > >
283  retrieve_relevant_poses_for_entity( Entity const &, DaemonIndices const & ) const;
284 
287 
288 #ifdef APL_MEASURE_MSD_LOAD_BALANCE
289  core::Real last_packing_runtime() const { return packing_runtime_; }
290  core::Real last_npd_runtime() const { return npd_runtime_; }
291 #endif
292 
293 
294 public:
295  /// MPI related methods
296 
297  /// @brief receive and respond to remote repacking requests from node 0 until
298  /// a spin-down signal is broadcast. This function does not return until
299  /// all MPI requests have completed.
300  void activate_daemon_mode();
301 
302 
303 private:
304  /// Private MPI related methods
305 
306  /// @brief When we recieve an add_daemons message, recieve all the
307  /// input files that go along with the set of daemons that should be added,
308  /// and then proceed to read these files. Send back a shut-down signal
309  /// and a message if any of the input files cannot be properly read. If all
310  /// goes well, send back the ok signal.
312 
313  /// @brief When we receive a evaluate_entity signal, calculate
314  /// the energies for that entity for each PackDaemon and send those
315  /// energies back to the master node.
317 
318  /// @brief When we receive a discard_entity signal, pass that
319  /// message on to the Daemons
321 
322  /// @brief When we receive a pose_request signal, have the desired PackDaemons
323  /// create the poses for that entity, and, ship them as PDB strings
324  /// back to node 0.
326 
327  /// @brief Receive an entity string from node 0 and create an Entity object from that string
328  EntityOP recieve_entity() const;
329 
330  /// @brief Accept a list of daemon indices which should return a pose based on
331  /// their state in the presence of a particular entity.
333 
334  /// @brief Call MPI_Finalize and exit.
335  void graceful_exit() const;
336 
337 private:
341 
343 
346 
347 
352 
353  std::map< std::string, NPDPropCalculatorCreatorOP > npd_calculator_creators_;
354 
359 
360 #ifdef APL_MEASURE_MSD_LOAD_BALANCE
361  core::Real packing_runtime_;
362  core::Real npd_runtime_;
363 #endif
364 
365 };
366 
367 ////////////////////////////////////////////////
368 ///////// NPDPropCalculator //////////
369 ////////////////////////////////////////////////
370 
371 
373 {
374 public:
376  virtual ~NPDPropCalculator();
377 
378  virtual
379  void
380  setup(
381  core::pose::Pose const & pose,
382  core::pack::task::PackerTask const & task
383  ); // no-op default implementation
384 
385 
386  virtual
387  core::Real
388  calculate( core::pose::Pose const & p ) = 0;
389 };
390 
392 {
393 public:
395  virtual ~NPDPropCalculatorCreator();
396 
397  virtual
399  calculator_name() const = 0;
400 
401  virtual
403  new_calculator() const = 0;
404 };
405 
406 ////////////////////////////////////////////////
407 ///////// QuickRepacker //////////
408 ////////////////////////////////////////////////
409 
411 {
412 public:
419 
420 public:
422  PoseOP pose,
426  );
427 
428  virtual ~QuickRepacker();
429 
430  virtual
432  repack( utility::vector0< int > const & rot_to_pack ) = 0;
433 
434 protected:
435  /// Read access to derived classes
436  PoseOP pose();
437  PackerTaskOP task();
440 
441  void task( PackerTaskOP ); // allow derived classes to reset their tasks
442 private:
447 };
448 
450 {
451 public:
453 
454 public:
456  PoseOP pose,
460  );
461 
462  virtual ~BasicSimAnnealerRepacker();
463 
464  virtual
466  repack( utility::vector0< int > const & rot_to_pack );
467 
468 private:
469 
474 
475 };
476 
478 {
479 public:
482 public:
484  PoseOP pose,
488  );
489 
491 
492 public:
493 
496  utility::vector0< int > const & rot_to_pack
497  );
498 
499 };
500 
502 {
503 public:
506 
507 public:
509  PoseOP pose,
512  RotamerSetsOP rotsets
513  );
514 
515  virtual ~DenseIGRepacker();
516  void set_MCA(); // once done, cannot be undone
517 
518  virtual
520  repack( utility::vector0< int > const & rot_to_pack );
521 
524  utility::vector0< int > const & rot_to_pack,
525  RotamerSubsetsOP rot_subsets
526  );
527 
528 };
529 
531 {
532 public:
535 
536 public:
538  PoseOP pose,
541  RotamerSetsOP rotsets
542  );
543 
544  virtual ~DoubleDenseIGRepacker();
545 
546  virtual
548  repack( utility::vector0< int > const & rot_to_pack );
549 
552  utility::vector0< int > const & rot_to_pack,
553  RotamerSubsetsOP rot_subsets
554  );
555 
556 };
557 
559 {
560 public:
563 
564 public:
566  PoseOP pose,
569  RotamerSetsOP rotsets
570  );
571 
572  virtual ~FASTER_IG_Repacker();
573 
574  virtual
576  repack( utility::vector0< int > const & rot_to_pack );
577 
580  utility::vector0< int > const & rot_to_pack,
581  RotamerSubsetsOP rot_subsets
582  );
583 
584  void set_num_sa( int setting );
585  void set_sa_scale( core::Real setting );
586  void set_ciBR_only( bool setting );
587 
588 private:
589  int num_sa_; // how many rounds of SA followed by sPR should the FASTERAnnealer perform?
591  bool ciBR_only_; // only perform ciBR?
592 
593 };
594 
595 }
596 }
597 
598 #endif