Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LinearMemoryInteractionGraph.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/pack/interaction_graph/LinearMemoryInteractionGraph.hh
11 /// @brief
12 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
13 
14 #ifndef INCLUDED_core_pack_interaction_graph_LinearMemoryInteractionGraph_hh
15 #define INCLUDED_core_pack_interaction_graph_LinearMemoryInteractionGraph_hh
16 
17 // Unit Headers
19 
20 // Package Headers
22 
23 #include <ObjexxFCL/FArray3D.hh>
24 
25 #include <utility/vector1.hh>
26 #include <utility/recent_history_queue.hh>
27 
28 
29 namespace core {
30 namespace pack {
31 namespace interaction_graph {
32 
33 /// @brief for storing three peices of associated data describing
34 /// the recent history structure on a LinearMemNode.
36 {
40 };
41 
43 {
44 public:
45  /// @brief main constructor, no default ctor, uncopyable
47  InteractionGraphBase * owner,
48  int node_id,
49  int num_states
50  );
51 
52  /// @brief virtual dstor
53  virtual ~LinearMemNode();
54 
55  //virtual methods inherited from NodeBase
56  /// @brief linmem ig does not have to do anything before sim annealing begins
57  virtual void prepare_for_simulated_annealing();
58  /// @brief write internal energy and bookkeeping data to standard out
59  virtual void print() const;
60  /// @brief state 0 represents the unasigned state
61  virtual bool state_unassigned() const { return current_state_ == 0;}
62  /// @brief return the total energy for this node; includes full energies to neighboring residues
64 
65  /// @brief set to state 0
66  void assign_zero_state();
67  /// @brief set to a particular state -- updates the energies internally
68  void assign_state(int new_state);
69  /// @brief first half of an entire-graph state assignment that avoids unnecessary energy updates
70  /// as produced in assign_state. Adjust all node's states first, then update all energies.
71  void partial_assign_state( int new_state );
72  /// @brief second half of the entire-graph state assignment.
74 
75  /// @brief return the index of the currently assigned state
76  inline
77  int get_current_state() const
78  { return current_state_; }
79 
80 
81  /// @brief return the "recent state id" for the currently assigned state
82  inline
84  { return rhq_.head_of_queue(); }
85 
86  /// @brief return the one-body energy for the currently assigned state
87  inline
89  { return curr_state_one_body_energy_; }
90 
91  /// @brief compute the change in energy induced by substituting the currently assigned state with
92  /// some alternative state
94  (
95  int alternate_state,
96  core::PackerEnergy & prev_node_energy
97  );
98 
99  /// @brief proceed to change the currently assigned state to the alternative state considered in
100  /// the last call to project_deltaE_for_substitution
102 
103  /// @brief update bookkeeping info to acknolwedge that the last alternative state considered was not
104  /// in fact chosen for the currently assigned state.
106 
107  /// @brief comupute the interaction energy between the currently assigned state on this residue and
108  /// the currently assigned state on a neighboring residue, identified by the index of the edge connecting
109  /// the two
110  core::PackerEnergy compute_pair_energy_for_current_state( int edge_making_energy_request );
111  /// @brief comupute the interaction energy between the alternate state being considered on this residue and
112  /// the currently assigned state on a neighboring residue, identified by the index of the edge connecting
113  /// the two
114  core::PackerEnergy compute_pair_energy_for_alternate_state( int edge_making_energy_request );
115 
116  inline
118  int edge_to_altered_neighbor,
119  core::PackerEnergy new_edge_energy,
120  int other_node_new_state,
121  SparseMatrixIndex const & other_node_new_state_sparse_info,
122  int other_node_recent_history_index
123  );
124 
125  void
127  int edge_to_altered_neighbor,
128  int other_node_new_state,
129  SparseMatrixIndex const & other_node_new_state_sparse_info,
130  int other_state_recent_history_index
131  );
132 
133  inline
134  SparseMatrixIndex const &
136 
137  void set_recent_history_size( int num_states_to_maintain_in_recent_history );
138  int get_recent_history_size() const;
139 
140  void print_internal_energies() const;
141 
143 
144  virtual unsigned int count_static_memory() const;
145  virtual unsigned int count_dynamic_memory() const;
146 
147 protected:
148 
149  inline
150  conformation::Residue const &
152  {
153  return get_rotamer( current_state_ );
154  }
155 
156  //Hooks for SASANode< V, E, G > class
157  //i.e. for non-PD classes which are templated to use either PD or OTF graphs
160  void set_alternate_state( int alt ) { alternate_state_ = alt; }
161  int get_alternate_state() const { return alternate_state_; }
162  void calc_deltaEpd( int alternate_state );
163 
165  {
167  }
168 
169 private:
170 
172 
173  inline
174  LinearMemEdge const * get_incident_linmem_edge( int index ) const;
175 
176  inline
178 
179  inline
180  LinearMemNode const * get_adjacent_linmem_node( int index ) const;
181 
182  inline
184 
185  inline
187  get_linmem_ig_owner() const;
188 
189  inline
192 
193  int update_recent_history( int state );
194 
195 private:
196  /// Data
197  utility::recent_history_queue rhq_;
198 
199  ObjexxFCL::FArray3D< unsigned char > aa_neighbors_for_edges_;
203 
209 
215 
218 
223 
224  static const int ACCEPTED = 1;
225  static const int REJECTED = 0;
226 
227  static const int ACCEPTANCE_REJECTION_HISTORY_LENGTH = 100;
229 };
230 
232 {
233 public:
235  InteractionGraphBase* owner,
236  int first_node_ind,
237  int second_node_ind
238  );
239 
240  virtual ~LinearMemEdge();
241 
242  virtual
243  void
245  ObjexxFCL::FArray2_bool const &
246  );
247 
248  virtual
249  void force_aa_neighbors( int node1aa, int node2aa);
250 
251  virtual
252  void force_all_aa_neighbors();
253 
254  virtual
255  bool
257  int node1aa,
258  int node2aa
259  ) const;
260 
261  virtual core::PackerEnergy get_two_body_energy( int const node1state, int const node2state) const;
262 
263 
264  //virtual methods inherited from EdgeBase
265  virtual void prepare_for_simulated_annealing();
266 
268 
270  int node_ind,
271  int new_state,
272  SparseMatrixIndex const & new_state_sparse_info,
273  int bumped_recent_history_index,
274  int new_state_recent_history_index,
275  core::PackerEnergy & new_energy
276  );
277  void acknowledge_state_zeroed( int node_ind );
278 
280  int node_ind,
281  int new_state,
282  SparseMatrixIndex const & new_state_sparse_info,
283  int bumped_recent_history_index,
284  int new_state_recent_history_index
285  );
286 
288 
290  int node_index,
291  int state,
292  int recent_history_id
293  );
294 
297  (
298  bool store_rpes,
299  int changing_node_index,
300  int alternate_state,
301  int alternate_state_recent_history_index,
302  int other_node_curr_state,
303  int other_node_state_recent_history_index
304  );
305 
306  inline
308  int substituted_node_index,
309  core::PackerEnergy const curr_state_energy,
310  int nodes_new_state,
311  SparseMatrixIndex const & nodes_new_state_sparse_info,
312  int bumped_recent_history_index,
313  int new_state_recent_history_index,
314  int neighbors_curr_state
315  );
316 
317  int get_two_body_table_size() const;
318  virtual void declare_energies_final();
319 
320  void print_current_energy() const;
321 
322 
323  ObjexxFCL::FArray2D< unsigned char > const & get_sparse_aa_neighbor_info( );
324  //ObjexxFCL::FArray1D_int const & get_second_node_num_states_per_aa();
325 
326  static core::PackerEnergy const NOT_YET_COMPUTED_ENERGY; //an energy lower than any RPE could ever be
327 
328  virtual unsigned int count_static_memory() const;
329  virtual unsigned int count_dynamic_memory() const;
330 
331  virtual void set_edge_weight( Real weight );
332 
333 protected:
334 
335  //Hooks for SASAEdge< V, E, G > class
338  bool pd_edge_table_all_zeros() const { return false;}
339 
340 
341 private:
342 
343  inline LinearMemNode const * get_linmem_node( int index ) const;
344  inline LinearMemNode * get_linmem_node( int index );
345  inline LinearMemoryInteractionGraph const * get_linmem_ig_owner() const;
347 
348  void
350  int node_substituted,
351  int node_not_substituted,
352  int bumped_recent_history_index
353  );
354 
356 
357  void wipe( int node );
358 
359  bool store_rpes_[ 2 ];
360  ObjexxFCL::FArray2D< core::PackerEnergy > stored_rpes_[ 2 ];
361  ObjexxFCL::FArray2D< unsigned char > sparse_aa_neighbors_;
366 
367  //no default constructor, uncopyable
368  LinearMemEdge();
369  LinearMemEdge( LinearMemEdge const & );
371 
372 };
373 
375 {
376 public:
377  LinearMemoryInteractionGraph( int numNodes );
379 
380  //virtual methods inherited from InteractionGraphBase
381  virtual void blanket_assign_state_0();
382  virtual core::PackerEnergy set_state_for_node(int node_ind, int new_state);
383  virtual core::PackerEnergy set_network_state( ObjexxFCL::FArray1_int & node_states);
384  virtual void consider_substitution(
385  int node_ind,
386  int new_state,
387  core::PackerEnergy & delta_energy,
388  core::PackerEnergy & prev_energy_for_node
389  );
392  virtual int get_edge_memory_usage() const;
393  virtual void print_current_state_assignment() const;
394  virtual void set_errorfull_deltaE_threshold( core::PackerEnergy deltaE );
395  virtual core::PackerEnergy get_energy_sum_for_vertex_group( int group_id );
396  virtual void prepare_for_simulated_annealing();
397 
398  //bool build_sc_only_rotamer() const;
399 
400  virtual unsigned int count_static_memory() const;
401  virtual unsigned int count_dynamic_memory() const;
402 
403 protected:
404 
405  virtual NodeBase* create_new_node( int node_index, int num_states);
406  virtual EdgeBase* create_new_edge( int index1, int index2);
407 
408  //Hooks for SASAInterationGraph< V, E, G >
411 
412  inline
413  LinearMemNode const * get_linmem_node(int index) const
414  {
415  return static_cast< LinearMemNode const * > (get_node( index ));
416  }
417 
418  inline
420  {
421  return static_cast< LinearMemNode * > (get_node( index ));
422  }
423 
424 private:
426  //static int get_cmdline_history_size();
427 
433 
435 
436  static const int COMMIT_LIMIT_BETWEEN_UPDATES = 1024; // 2^10
437 
438  //no default constructor, uncopyable
442 };
443 
444 
445 inline
448 {
449  return static_cast< LinearMemoryInteractionGraph const * > (get_owner());
450 }
451 
452 inline
455 {
456  return static_cast< LinearMemoryInteractionGraph * > (get_owner());
457 }
458 
459 inline
460 LinearMemEdge const *
462 {
463  return static_cast< LinearMemEdge const * > (get_incident_edge( index ));
464 }
465 
466 inline
469 {
470  return static_cast< LinearMemEdge * > (get_incident_edge( index ));
471 }
472 
473 inline
474 LinearMemNode const *
476 {
477  return static_cast< LinearMemNode const * > (get_adjacent_node( index ));
478 }
479 
480 inline
483 {
484  return static_cast< LinearMemNode * > (get_adjacent_node( index ));
485 }
486 
487 inline
488 LinearMemNode const *
490 {
491  return static_cast< LinearMemNode const * > (get_node( index ));
492 }
493 
494 inline
497 {
498  return static_cast< LinearMemNode * > (get_node( index ));
499 }
500 
501 
502 inline
505 {
506  return static_cast< LinearMemoryInteractionGraph const * > (get_owner());
507 }
508 
509 inline
512 {
513  return static_cast< LinearMemoryInteractionGraph * > (get_owner());
514 }
515 
516 
517 inline
518 SparseMatrixIndex const &
520 {
522 }
523 
524 inline
525 void
527  int substituted_node_index,
528  core::PackerEnergy const curr_state_energy,
529  int nodes_new_state,
530  SparseMatrixIndex const & nodes_new_state_sparse_info,
531  int bumped_recent_history_index,
532  int new_state_recent_history_index,
533  int neighbors_curr_state
534 )
535 {
536  int node_substituted = substituted_node_index == get_node_index(0) ? 0 : 1;
537  int node_not_substituted = ! node_substituted;
538 
540  node_substituted,
541  node_not_substituted,
542  bumped_recent_history_index );
543 
544  curr_state_energy_ = curr_state_energy;
545  if ( neighbors_curr_state != 0 ) {
546  stored_rpes_[ node_substituted ]
547  ( neighbors_curr_state, new_state_recent_history_index ) =
549  }
550 
551  get_linmem_node( node_not_substituted )->
552  acknowledge_neighbors_state_substitution
553  (
554  get_edges_position_in_nodes_edge_vector( node_not_substituted ),
556  nodes_new_state,
557  nodes_new_state_sparse_info,
558  new_state_recent_history_index
559  );
560 
561  return;
562 }
563 
564 inline
565 void
567  int edge_to_altered_neighbor,
568  core::PackerEnergy new_edge_energy,
569  int other_node_new_state,
570  SparseMatrixIndex const & other_node_new_state_sparse_info,
571  int other_node_recent_history_index
572 )
573 {
575  new_edge_energy - curr_state_two_body_energies_[ edge_to_altered_neighbor ];
576  curr_state_two_body_energies_[ edge_to_altered_neighbor ] = new_edge_energy;
577  neighbors_curr_state_[ edge_to_altered_neighbor ] = other_node_new_state;
578  neighbors_curr_state_sparse_info_[ edge_to_altered_neighbor ] =
579  other_node_new_state_sparse_info;
580  neighbors_state_recent_history_index_[ edge_to_altered_neighbor ] =
581  other_node_recent_history_index;
582  return;
583 }
584 
585 
586 }
587 }
588 }
589 
590 #endif
591