Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FlexbbInteractionGraph.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/flexpack/interaction_graph/FlexbbIteractionGraph.hh
11 /// @brief Declaration for flexible-backbone-packing interaction graph interface & base classes
12 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
13 
14 #ifndef INCLUDED_protocols_flexpack_interaction_graph_FlexbbInteractionGraph_hh
15 #define INCLUDED_protocols_flexpack_interaction_graph_FlexbbInteractionGraph_hh
16 
17 /// Unit headers
19 
20 /// Package headers
22 
23 /// Project headers
25 
26 /// Utility headers
27 // AUTO-REMOVED #include <utility/vector0.hh>
28 
29 // ObjexxFCL Headers
30 // AUTO-REMOVED #include <ObjexxFCL/FArray1A.hh>
31 
32 /// C++ headers
33 /// TEMP
34 // AUTO-REMOVED #include <iostream>
35 
36 #include <utility/vector0_bool.hh>
37 #include <ObjexxFCL/FArray1A.fwd.hh>
38 
39 
40 namespace protocols {
41 namespace flexpack {
42 namespace interaction_graph {
43 
45 {
46 public:
49  typedef core::Size Size;
50 
51 public:
52 
53  FlexbbNode( FlexbbInteractionGraph * owner, int node_id, int num_states);
54  virtual ~FlexbbNode();
55  virtual void print() const;
56 
57  void set_num_distinct_backbones( int nbbconfs );
58  int get_num_distinct_backbones() const { return num_bb_; }
60  int get_bb_for_state( int state ) const { return state_info_[ state ].get_bb(); }
61  int get_num_states_for_bb( int bbconf ) const;
62  int get_state_offset_for_bb( int bbconf ) const;
64  utility::vector1< Size > & state_list,
65  int offset
66  ) const;
67  void get_all_states(
68  utility::vector1< Size > & rotlist,
69  int offset
70  ) const;
71 
72  void set_closest_states_on_other_bbs( ObjexxFCL::FArray2D_int const & );
73 
75  ObjexxFCL::FArray1A_int getNumStatesPerAAPerBB( int aa );
76 
77 
78  virtual void add_to_one_body_energies( ObjexxFCL::FArray1< PackerEnergy > & energies );
79  virtual void add_to_one_body_energy( int state, PackerEnergy energy );
80  virtual void update_one_body_energy( int state, PackerEnergy energy);
81  virtual void zero_one_body_energies();
82  virtual bool state_unassigned() const;
83 
84  PackerEnergy get_one_body_energy( int state ) const;
85 
86  virtual void prepare_for_simulated_annealing();
87 
88  int get_current_state() const;
90  void write_current_state_to_state_array( ObjexxFCL::FArray1_int & nodes_states);
91 
92  /// @brief Preliminatry bookkeeping for the node the Graph contacted about a backbone move.
93  /// This node is the "root" of the DFS traversal.
94  //void
95  //register_contacted_node_for_bb_jump();
96 
97  /// @brief Preliminary bookkeeping for DFS-backbone-motion inducing state substitution
98  /// initiated by a separate node. Returns false if the current state is unassigned.
99  //bool prepare_for_bb_jump( int alt_bb );
101 
102  /// @brief Did the alterenate state assigned during a flexbb move actually preserve the currently assigned bb?
103  //bool
104  //bb_move_actually_kept_original_bb() const;
105 
106  bool
108  {
109  return state_info_[ state ].get_bb() == current_state_info_.get_bb();
110  }
111 
112 
113  //inline PackerEnergy project_deltaE_for_alt_bb_state (
114  // int alternate_state,
115  // PackerEnergy & curr_frag_etotal,
116  // bool & valid_motion
117  //);
118 
119  //inline PackerEnergy project_deltaE_for_alt_bb(
120  // int alternate_backbone,
121  // PackerEnergy & curr_frag_etotal,
122  // bool & valid_motion
123  //);
124 
125  //PackerEnergy get_altE_for_bb_move
126  //(
127  // PackerEnergy & curr_frag_etotal
128  //);
129 
130  //void commit_considered_substitution();
131  //void commit_considered_substitution( FArray1_int & rotamer_on_node );
132  //void commit_alt_bb_substitution( FArray1_int & rotamer_on_node );
133 
134  //inline
135  //void acknowledge_neighbors_state_substitution(
136  // int edge_to_altered_neighbor,
137  // PackerEnergy new_edge_energy
138  //);
139 
140  //virtual void note_last_considered_bbsub_uncommitted() = 0;
141 
142  int get_num_states_for_aa_type_for_bb( int aa_type, int bb ) const;
144 
146 
147  virtual unsigned int count_dynamic_memory() const;
148 
149 protected:
150 
151  /// Downcast pointers to incident edges, adjacent nodes, and the owning graph
152  /// ^--- Oxford comma. See Vampire Weekend's objection.
153  inline
154  FlexbbEdge const * get_incident_flexbb_edge( int index ) const;
155 
156  inline
157  FlexbbEdge * get_incident_flexbb_edge( int index );
158 
159  inline
160  FlexbbNode const * get_adjacent_flexbb_node( int index ) const;
161 
162  inline
163  FlexbbNode * get_adjacent_flexbb_node( int index );
164 
165  inline
167 
168  inline
170 
171 protected:
174 
175 public:
176  /// Read access to private data to both derived classes and the world
177  int num_aa_types() const { return num_aa_types_; }
178  int num_bbconfs() const { return num_bb_; }
181  ObjexxFCL::FArray2D_int const & num_states_for_aa_for_bb() { return num_states_for_aa_for_bb_; }
182  ObjexxFCL::FArray2D_int const & state_offsets_for_aa_for_bb() { return state_offsets_for_aa_for_bb_; }
183 
184  ObjexxFCL::FArray2D_int const & closest_state_on_alt_bb() const { return closest_state_on_alt_bb_; }
185  FlexbbSparseMatrixIndex const & state_info( int state ) const { return state_info_[ state ]; }
187 
188  int current_state() const { return current_state_; }
190  int curr_bb() const { return current_state_info_.get_bb(); }
194 
195 
196  int alternate_state() const { return alternate_state_; }
198  int alt_bb() const { return alternate_state_info_.get_bb(); }
199 
200 
205 
207 
208  /// @brief Convention for acumulating energies between flexsegmates during a backbone move:
209  /// The smaller-indexed node counts the interaction, the larger-indexed node does not.
210  bool count_energy_to_node_in_my_fragtotalE( int edge_index ) const { return edge_index > get_num_edges_to_smaller_indexed_nodes(); }
212 
213 protected:
214 
215  /// Limited write acces to private data
217  void set_current_state( int setting ) { current_state_ = setting; current_state_info_ = state_info_[ setting ]; }
222 
223  void set_alternate_state( int setting ) { alternate_state_ = setting; alternate_state_info_ = state_info_[ setting ]; }
225  //if ( get_node_index() == 17 && alternate_state_ == 63 ) { std::cout << "SETTING ALT STATE 1BE: " << setting << std::endl; }
227  }
231 
233 
234  void partial_state_assignment( int new_state );
236 
237  //// @brief bookkeeping for DFS traversal. Derived classes should consult this at the beginning of node
238  /// "get_energies" traversals. Calling this function for a node effectively declares that the code which
239  /// follows will project the delta energy: after the first time this functio is called, it will return true.
240  /// Must be proceeded by a call to prepare_for_bb_jump().
241  /// Depricated.
242  ///bool energies_already_projected() const;
243 
244  /// @brief Copy over the energy data local to this node from "alternate_*" to "current_*"
246 
247  /// @brief Have all incident edges copy their data from "alternate_*" to "current_*"
249 
250  /// @brief Have a subset of the incident edges copy their data from "alternate_*" to "current_*"
251  /// where this subset includes all edges to non-flexsegmates as well as all
252  /// all upper edges to flexsegmates. Threadsafe if it can be fruitfully parallelized.
254 
255 private:
256 
258  int num_bb_;
259 
262  ObjexxFCL::FArray2D_int num_states_for_aa_for_bb_; // Indexed (aa, bb)
263  ObjexxFCL::FArray2D_int state_offsets_for_aa_for_bb_; // Indexed (aa, bb)
264  ObjexxFCL::FArray2D_int closest_state_on_alt_bb_;
265 
266  /// vector0 so that assigning state 0 does not index out-of-bounds.
267  utility::vector0< FlexbbSparseMatrixIndex > state_info_; // stores aa index and bb index for each state.
268  //utility::vector1< int > num_states_for_aatype_; // ?!
269 
271 
277 
283 
285 
287  //bool told_edges_alt_state_for_bb_move_;
288  //mutable bool projected_energies_for_bb_move_; // is it necessary that the calling function is const?
289  //bool resolved_considered_bb_move_;
290  //bool node_contacted_by_graph_about_bb_move_;
291 
292  // uncopyable
293  FlexbbNode();
294  FlexbbNode( FlexbbNode const & );
295 
296 };
297 
299 {
300 public:
303  typedef core::Real Real;
304  typedef core::Size Size;
305 
306 public:
307  FlexbbEdge(
308  FlexbbInteractionGraph * owner,
309  int first_node_ind,
310  int second_node_ind
311  );
312 
313  virtual ~FlexbbEdge();
314 
315  //virtual void set_nodes_from_same_flexseg( bool same_flexseg );
318  }
319 
320  /// @brief Called by FlexbbNode in prepare_for_bb_jump: Edges must know the alternate
321  /// states that nodes are considering. Precondition: alt_state_ for a fixed node must
322  /// match its cur_state_
323  void
324  set_alt_state( int node_index, int new_state, FlexbbSparseMatrixIndex const & state_info );
325 
326  void
327  acknowledge_partial_state_assignment( int node_index, int new_state, FlexbbSparseMatrixIndex const & state_info );
328 
329  /// @brief Copy alt data to current data after a state substitution
330  void
332 
333  /// @brief After a rejected state substitution, the FlexbbNode will call this function
334  /// to reset the alt_state data to establish the invariant that the alternate state held
335  /// on the flexbb edges reflect the the current state of those nodes not considering a
336  /// state substitution
337  void
339 
340  virtual unsigned int count_dynamic_memory() const;
341 
342  PackerEnergy cur_energy() const { return cur_energy_; }
343  PackerEnergy alt_energy() const { assert( alt_e_up_to_date_ ); return alt_energy_; }
344 
345 
346 protected:
347 
348  inline
349  FlexbbNode const * get_flexbb_node( int index ) const
350  { return static_cast< FlexbbNode const * > (get_node( index )); }
351 
352  inline
354  { return static_cast< FlexbbNode * > (get_node( index )); }
355 
356  inline
358 
359  inline
361 
362 protected:
363 
364  inline
365  int
366  num_bb( int node ) {
367  assert( node == 0 || node == 1 );
368  return nodes_num_bb_[ node ];
369  }
370 
371  inline
372  bool
375  }
376 
377  inline
378  bool
381  }
382 
383  inline
384  void
387  }
388 
389  int nodes_cur_state( int node ) const { assert( node == 0 || node == 1 ); return nodes_cur_state_[ node ]; }
390  FlexbbSparseMatrixIndex const & nodes_cur_info( int node ) const { assert( node == 0 || node == 1 ); return nodes_cur_info_[ node ]; }
391  int nodes_alt_state( int node ) const { assert( node == 0 || node == 1 ); return nodes_alt_state_[ node ]; }
392  FlexbbSparseMatrixIndex const & nodes_alt_info( int node ) const { assert( node == 0 || node == 1 ); return nodes_alt_info_[ node ]; }
393  bool alt_e_up_to_date() const { return alt_e_up_to_date_; }
394 
395 
396  /// @brief Set the currently assigned state for a node; node == 0 || 1
397  void set_nodes_cur_state( int node, int setting ) { nodes_cur_state_[ node ] = setting; }
398  void set_nodes_cur_info( int node, FlexbbSparseMatrixIndex const & setting ) { nodes_cur_info_[ node ] = setting; }
399  /// @brief Set the altnernate state being considered for a node; node == 0 || 1
400  void set_nodes_alt_state( int node, int setting ) { nodes_alt_state_[ node ] = setting; }
401  void set_nodes_alt_info( int node, FlexbbSparseMatrixIndex const & setting ) { nodes_alt_info_[ node ] = setting; }
402  void set_cur_energy( PackerEnergy setting ) { cur_energy_ = setting; }
403  void set_alt_energy( PackerEnergy setting ) { alt_energy_ = setting; alt_e_up_to_date_ = true; }
404 
407 
408 private:
409 
412 
415 
418 
421 
424 
425 
426  // uncopyable
427  FlexbbEdge();
428  FlexbbEdge( FlexbbEdge const & );
429 };
430 
431 
433 {
434 public:
438 
439 public:
441 
442 public:
443  virtual ~FlexbbInteractionGraph();
444  FlexbbInteractionGraph(int num_nodes);
445 
446  virtual void initialize(core::pack::rotamer_set::RotamerSetsBase const & rot_sets );
447 
448 private:
449  /// Private functions called during initialize()
450  void set_num_flexsegs(int num_flexsegs);
451  void set_total_num_backbones( int num_backbones );
452 
453 public:
454  int get_num_aa_types() const { assert( num_aa_types_ != 0 ); return num_aa_types_; }
455  //void set_representitive_node_for_flexseg( int flexseg, int node_index);
456  //int get_flexseg_representative( int flexseg ) const { return flexseg_representative_[ flexseg ]; }
458  flexseg_members( int flexseg ) const {
459  return flexseg_members_[ flexseg ];
460  }
461  int get_flexseg_for_bb( int bb ) const { return flexseg_for_bb_[ bb ]; }
462  int get_flexseg_bb_offset( int flexseg_id ) const { return flexseg_bb_offset_[ flexseg_id ]; }
463  bool nodes_from_same_flexseg( int node1, int node2 ) const;
464 
465 private:
466  void set_num_bb_for_node( int node, int numbb);
467  void set_num_states_per_backbone_for_node( int node, utility::vector1< int > const & states_per_bb);
468 
469 public:
470  int get_num_states_per_backbone_for_node( int node, int bb ) const;
471  int get_bb_for_state( int node, int state ) const;
472 
473 private:
474  void set_aatypes_for_node(int node_ind, utility::vector1< int > const & aatypes);
475  void set_closest_states_on_other_bbs( int node_index, ObjexxFCL::FArray2D_int const & );
476 
477 public:
478  //void set_edge_connecting_nodes_on_same_flexseg(int, int); // knowable at edge construction time!
479 
480  virtual
482  int bb_id,
483  core::PackerEnergy & delta_energy,
484  core::PackerEnergy & prev_flexseg_energy,
485  bool & valid_motion,
486  int & num_nodes_changing_state
487  ) = 0;
488 
489  virtual
491  int node_ind,
492  int new_state,
493  core::PackerEnergy & delta_energy,
494  core::PackerEnergy & prev_energy_for_flexseg,
495  bool & valid_motion,
496  int & num_nodes_changing_state
497  ) = 0;
498 
499  virtual
502  ObjexxFCL::FArray1_int & rotamer_on_node
503  ) = 0;
504 
506  Subsitution move_mode,
507  utility::vector1< Size > & rotlist
508  ) const;
509 
510  void get_backbone_list(
511  utility::vector1< Size > & bblist
512  ) const;
513 
514  /// @brief Is the backbone conformation (in the global enumertion of backbone conformations) already
515  /// assigned to the network? False if any residue on the flexible segment that this bbid corresponds to
516  /// is assigned state 0.
517  bool get_backbone_currently_assigned( int bbid ) const;
518 
519  /// @brief FlexbbNodes will ask: am I allowed to have a state that breaks the backbone?
520  /// There are brief periods when the backbone is "broken" as the graph assigns new states to
521  /// nodes on the same flexible segment.
522  bool get_enforce_bb_contiguity() const;
523 
524  /// @brief Owner keeps a count of the number of nodes undergoing a
525  /// simultaneous rotamer substitution as the backbone moves.
527 
528  virtual unsigned int count_dynamic_memory() const;
529 
530 protected:
531 
532  /// Downcasts
533  FlexbbNode const * get_flexbb_node( int index ) const
534  { return static_cast< FlexbbNode const * > (get_node( index )); }
535 
537  { return static_cast< FlexbbNode * > (get_node( index )); }
538 
539  FlexbbEdge const * find_flexbb_edge( int node1, int node2 ) const
540  {
541  core::pack::interaction_graph::EdgeBase const * edge = find_edge( node1, node2 );
542  if ( edge ) return static_cast< FlexbbEdge const * > ( edge );
543  else return 0;
544  }
545 
546  FlexbbEdge * find_flexbb_edge( int node1, int node2 )
547  {
548  core::pack::interaction_graph::EdgeBase * edge = find_edge( node1, node2 );
549  if ( edge ) return static_cast< FlexbbEdge * > ( edge );
550  else return 0;
551  }
552 
553  FlexbbEdge const * cast_flexbb_edge( EdgeBase const * edge ) const
554  { assert( mine( edge ) ); return static_cast< FlexbbEdge const * > ( edge ); }
555 
557  { assert( mine( edge ) ); return static_cast< FlexbbEdge * > ( edge ); }
558 
559 
560 protected:
561 
562  void set_enforce_bb_contiguity(bool);
567 
571  }
573 
574  /// @details at the beginning of backbone-changing substitutions,
575  /// derived classes must invoke this function to get a proper count
576  /// of the number of nodes undergoing a simultaneous rotamer substitution
578  int get_num_nodes_changing_state() const;
579 
582 
583  /// @brief Only allowed to ask for the node considering an alternate
584  /// state during a fixed-backbone substitution
586 
587  /// @brief Only allowed to ask for the flexible segment considering an alternate
588  /// backbone conformation during a backbone-moving substitution
590 
592 
593  int flexseg_for_moltenres( int moltenres ) const {
594  return flexseg_for_moltenres_[ moltenres ];
595  }
596 
599 
600  /// @brief Track the last node at which a fixed-backbone substitution took place
601  void set_node_considering_alt_state( int setting ) {
603  node_considering_alt_state_ = setting;
604  }
605  /// @brief Track the last flexible segment at which a moving-backbone substitution took place
606  void set_flexseg_considering_alt_bb( int setting ) {
607  flexseg_considering_alt_bb_ = setting;
609  }
611 
612 
613  virtual void update_internal_energy_totals();
614 
615 private:
616 
618 
623 
626  //utility::vector1< int > flexseg_representative_;
632 
639 
640 
642  static const int COMMIT_LIMIT_BETWEEN_UPDATES = 20; //1024; // 2^10
643 
646 
647 
648 };
649 
650 inline
652 { return static_cast< FlexbbEdge const * > ( get_incident_edge( index )); }
653 
654 inline
656 { return static_cast< FlexbbEdge * > ( get_incident_edge( index )); }
657 
658 inline
660 { return static_cast< FlexbbNode const * > ( get_adjacent_node( index )); }
661 
662 inline
664 { return static_cast< FlexbbNode * > ( get_adjacent_node( index )); }
665 
666 
667 inline
669 { return static_cast< FlexbbInteractionGraph const * > (get_owner()); }
670 
671 inline
673 { return static_cast< FlexbbInteractionGraph * > (get_owner()); }
674 
675 
676 inline
678 { return static_cast< FlexbbInteractionGraph const * > (get_owner()); }
679 
680 inline
682 { return static_cast< FlexbbInteractionGraph * > (get_owner()); }
683 
684 
685 
686 }
687 }
688 }
689 
690 #endif
691