Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SymmLinMemInteractionGraph.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/SymmLinMemInteractionGraph.hh
11 /// @brief
12 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
13 
14 #ifndef INCLUDED_core_pack_interaction_graph_SymmLinMemInteractionGraph_hh
15 #define INCLUDED_core_pack_interaction_graph_SymmLinMemInteractionGraph_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 
34 {
35 public:
36  /// @brief main constructor, no default ctor, uncopyable
38  InteractionGraphBase * owner,
39  int node_id,
40  int num_states
41  );
42 
43  /// @brief virtual dstor
44  virtual ~SymmLinearMemNode();
45 
46  //virtual methods inherited from NodeBase
47  /// @brief symmlinmem ig does not have to do anything before sim annealing begins
48  virtual void prepare_for_simulated_annealing();
49  /// @brief write internal energy and bookkeeping data to standard out
50  virtual void print() const;
51  /// @brief state 0 represents the unasigned state
52  virtual bool state_unassigned() const { return current_state_ == 0;}
53  /// @brief return the total energy for this node; includes full energies to neighboring residues
55 
56  /// @brief set to state 0
57  void assign_zero_state();
58  /// @brief set to a particular state -- updates the energies internally
59  void assign_state(int new_state);
60  /// @brief first half of an entire-graph state assignment that avoids unnecessary energy updates
61  /// as produced in assign_state. Adjust all node's states first, then update all energies.
62  void partial_assign_state( int new_state );
63  /// @brief second half of the entire-graph state assignment.
65 
66  /// @brief return the index of the currently assigned state
67  inline
68  int get_current_state() const
69  { return current_state_; }
70 
71 
72  /// @brief return the "recent state id" for the currently assigned state
73  inline
75  { return rhq_.head_of_queue(); }
76 
77  /// @brief return the one-body energy for the currently assigned state
78  inline
80  { return curr_state_one_body_energy_; }
81 
82  /// @brief compute the change in energy induced by substituting the currently assigned state with
83  /// some alternative state
85  (
86  int alternate_state,
87  core::PackerEnergy & prev_node_energy
88  );
89 
90  /// @brief proceed to change the currently assigned state to the alternative state considered in
91  /// the last call to project_deltaE_for_substitution
93 
94  /// @brief update bookkeeping info to acknolwedge that the last alternative state considered was not
95  /// in fact chosen for the currently assigned state.
97 
98  /// @brief comupute the interaction energy between the currently assigned state on this residue and
99  /// the currently assigned state on a neighboring residue, identified by the index of the edge connecting
100  /// the two
101  core::PackerEnergy compute_pair_energy_for_current_state( int edge_making_energy_request );
102  /// @brief comupute the interaction energy between the alternate state being considered on this residue and
103  /// the currently assigned state on a neighboring residue, identified by the index of the edge connecting
104  /// the two
105  core::PackerEnergy compute_pair_energy_for_alternate_state( int edge_making_energy_request );
106 
107  inline
109  int edge_to_altered_neighbor,
110  core::PackerEnergy new_edge_energy,
111  int other_node_new_state,
112  int other_node_recent_history_index
113  );
114 
115  void
117  int edge_to_altered_neighbor,
118  int other_node_new_state,
119  int other_state_recent_history_index
120  );
121 
122  void set_recent_history_size( int num_states_to_maintain_in_recent_history );
123  int get_recent_history_size() const;
124 
125  void print_internal_energies() const;
126 
128 
129  virtual unsigned int count_static_memory() const;
130  virtual unsigned int count_dynamic_memory() const;
131 
132 private:
133 
135 
136 public:
137  inline
138  SymmLinearMemEdge const * get_incident_symmlinmem_edge( int index ) const;
139 
140  inline
142 
143  inline
144  SymmLinearMemNode const * get_adjacent_symmlinmem_node( int index ) const;
145 
146  inline
148 
149  inline
151  get_symmlinmem_ig_owner() const;
152 
153  inline
156 
157 private:
158 
159  int update_recent_history( int state );
160 
161 private:
162  /// Data
163  utility::recent_history_queue rhq_;
164 
167 
172 
177 
180 
185 
186  static const int ACCEPTED = 1;
187  static const int REJECTED = 0;
188 
189  static const int ACCEPTANCE_REJECTION_HISTORY_LENGTH = 100;
191 };
192 
194 {
195 public:
197  InteractionGraphBase* owner,
198  int first_node_ind,
199  int second_node_ind
200  );
201 
202  virtual ~SymmLinearMemEdge();
203 
204  virtual core::PackerEnergy get_two_body_energy( int const node1state, int const node2state) const;
205 
206  //virtual methods inherited from EdgeBase
207  virtual void prepare_for_simulated_annealing();
208 
210 
212  int node_ind,
213  int new_state,
214  int bumped_recent_history_index,
215  int new_state_recent_history_index,
216  core::PackerEnergy & new_energy
217  );
218  void acknowledge_state_zeroed( int node_ind );
219 
221  int node_ind,
222  int new_state,
223  int bumped_recent_history_index,
224  int new_state_recent_history_index
225  );
226 
228 
230  int node_index,
231  int state,
232  int recent_history_id
233  );
234 
237  bool store_rpes,
238  int changing_node_index,
239  int alternate_state,
240  int alternate_state_recent_history_index,
241  int other_node_curr_state,
242  int other_node_state_recent_history_index
243  );
244 
245  inline
247  int substituted_node_index,
248  core::PackerEnergy const curr_state_energy,
249  int nodes_new_state,
250  int bumped_recent_history_index,
251  int new_state_recent_history_index,
252  int neighbors_curr_state
253  );
254 
255  int get_two_body_table_size() const;
256  virtual void declare_energies_final();
257 
258  void print_current_energy() const;
259 
260  static core::PackerEnergy const NOT_YET_COMPUTED_ENERGY; //an energy lower than any RPE could ever be
261 
262  virtual unsigned int count_static_memory() const;
263  virtual unsigned int count_dynamic_memory() const;
264 
265  virtual void set_edge_weight( Real weight );
266 
267 public:
268 
269  inline SymmLinearMemNode const * get_symmlinmem_node( int index ) const;
270  inline SymmLinearMemNode * get_symmlinmem_node( int index );
273 
274 private:
275 
276  void
278  int node_substituted,
279  int node_not_substituted,
280  int bumped_recent_history_index
281  );
282 
284 
285  void wipe( int node );
286 
287 private:
288  bool store_rpes_[ 2 ];
289  ObjexxFCL::FArray2D< core::PackerEnergy > stored_rpes_[ 2 ];
294 
295  //no default constructor, uncopyable
299 
300 };
301 
303 {
304 public:
305  SymmLinearMemoryInteractionGraph( int numNodes );
307 
308  //virtual methods inherited from InteractionGraphBase
309  virtual void blanket_assign_state_0();
310  virtual core::PackerEnergy set_state_for_node(int node_ind, int new_state);
311  virtual core::PackerEnergy set_network_state( ObjexxFCL::FArray1_int & node_states);
312  virtual void consider_substitution(
313  int node_ind,
314  int new_state,
315  core::PackerEnergy & delta_energy,
316  core::PackerEnergy & prev_energy_for_node
317  );
320  virtual int get_edge_memory_usage() const;
321  virtual void print_current_state_assignment() const;
322  virtual void set_errorfull_deltaE_threshold( core::PackerEnergy deltaE );
323  virtual core::PackerEnergy get_energy_sum_for_vertex_group( int group_id );
324  virtual void prepare_for_simulated_annealing();
325 
326  //bool build_sc_only_rotamer() const;
327 
328  virtual unsigned int count_static_memory() const;
329  virtual unsigned int count_dynamic_memory() const;
330 
331 protected:
332 
333  virtual NodeBase* create_new_node( int node_index, int num_states);
334  virtual EdgeBase* create_new_edge( int index1, int index2);
335 
336  //Hooks for SASAInterationGraph< V, E, G >
339 
340  inline
341  SymmLinearMemNode const * get_symmlinmem_node(int index) const
342  {
343  return static_cast< SymmLinearMemNode const * > (get_node( index ));
344  }
345 
346  inline
348  {
349  return static_cast< SymmLinearMemNode * > (get_node( index ));
350  }
351 
352 private:
354  //static int get_cmdline_history_size();
355 
361 
363 
364  static const int COMMIT_LIMIT_BETWEEN_UPDATES = 1024; // 2^10
365 
366  //no default constructor, uncopyable
370 };
371 
372 
373 inline
376 {
377  return static_cast< SymmLinearMemoryInteractionGraph const * > (get_owner());
378 }
379 
380 inline
383 {
384  return static_cast< SymmLinearMemoryInteractionGraph * > (get_owner());
385 }
386 
387 inline
388 SymmLinearMemEdge const *
390 {
391  return static_cast< SymmLinearMemEdge const * > (get_incident_edge( index ));
392 }
393 
394 inline
397 {
398  return static_cast< SymmLinearMemEdge * > (get_incident_edge( index ));
399 }
400 
401 inline
402 SymmLinearMemNode const *
404 {
405  return static_cast< SymmLinearMemNode const * > (get_adjacent_node( index ));
406 }
407 
408 inline
411 {
412  return static_cast< SymmLinearMemNode * > (get_adjacent_node( index ));
413 }
414 
415 inline
416 SymmLinearMemNode const *
418 {
419  return static_cast< SymmLinearMemNode const * > (get_node( index ));
420 }
421 
422 inline
425 {
426  return static_cast< SymmLinearMemNode * > (get_node( index ));
427 }
428 
429 
430 inline
433 {
434  return static_cast< SymmLinearMemoryInteractionGraph const * > (get_owner());
435 }
436 
437 inline
440 {
441  return static_cast< SymmLinearMemoryInteractionGraph * > (get_owner());
442 }
443 
444 
445 inline
446 void
448  int substituted_node_index,
449  core::PackerEnergy const curr_state_energy,
450  int nodes_new_state,
451  int bumped_recent_history_index,
452  int new_state_recent_history_index,
453  int neighbors_curr_state
454 )
455 {
456  int node_substituted = substituted_node_index == get_node_index(0) ? 0 : 1;
457  int node_not_substituted = ! node_substituted;
458 
460  node_substituted,
461  node_not_substituted,
462  bumped_recent_history_index );
463 
464  curr_state_energy_ = curr_state_energy;
465  if ( neighbors_curr_state != 0 ) {
466  stored_rpes_[ node_substituted ]
467  ( neighbors_curr_state, new_state_recent_history_index ) =
469  }
470 
471  get_symmlinmem_node( node_not_substituted )->
472  acknowledge_neighbors_state_substitution
473  (
474  get_edges_position_in_nodes_edge_vector( node_not_substituted ),
476  nodes_new_state,
477  new_state_recent_history_index
478  );
479 
480  return;
481 }
482 
483 inline
484 void
486  int edge_to_altered_neighbor,
487  core::PackerEnergy new_edge_energy,
488  int other_node_new_state,
489  int other_node_recent_history_index
490 )
491 {
493  new_edge_energy - curr_state_two_body_energies_[ edge_to_altered_neighbor ];
494  curr_state_two_body_energies_[ edge_to_altered_neighbor ] = new_edge_energy;
495  neighbors_curr_state_[ edge_to_altered_neighbor ] = other_node_new_state;
496  neighbors_state_recent_history_index_[ edge_to_altered_neighbor ] =
497  other_node_recent_history_index;
498  return;
499 }
500 
501 
502 }
503 }
504 }
505 
506 #endif
507