Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OnTheFlyInteractionGraph.cc
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/OnTheFlyInteractionGraph.hh
11 /// @brief
12 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
13 
14 // Unit headers
16 
17 // Package headers
20 
21 // Project headers
23 #include <core/pose/Pose.hh>
25 #include <core/scoring/util.hh>
27 
28 // Utility headers
29 #include <basic/Tracer.hh>
30 
31 #include <iostream>
32 
33 #include <utility/vector1.hh>
34 
35 
36 namespace core {
37 namespace pack {
38 namespace interaction_graph {
39 
40 bool const debug = { false };
41 static basic::Tracer T("core.pack.interaction_graph.otf_ig", basic::t_error );
42 
43 /// @brief main constructor, no default or copy constructors
44 ///
45 /// @detailed
47  InteractionGraphBase * owner,
48  int node_id,
49  int num_states
50 ) :
51  FixedBBNode( owner, node_id, num_states ),
52  rotamer_set_( 0 ),
53  rotamers_( num_states ),
54  sc_bounding_spheres_( num_states, std::make_pair( Vector( 0.0 ), Real( 0.0 ) ) ),
55  bb_bounding_sphere_( std::make_pair( Vector( 0.0 ), Real( 0.0 ) )),
56  num_aa_types_( get_on_the_fly_owner()->get_num_aatypes() ),
57  num_states_for_aatype_( num_aa_types_, 0 ),
58  state_offset_for_aatype_( num_aa_types_, 0 ),
59  sparse_mat_info_for_state_( num_states ),
60  one_body_energies_( num_states, 0.0 ),
61  distinguish_backbone_and_sidechain_( false ) // by default, do not
62 {
63 
64 }
65 
66 /// @details
68 {}
69 
70 /// @details avoid polymorphic lookup later by nabbing rotamers now.
71 void
74 )
75 {
76  assert( rotamers->num_rotamers() == (Size) get_num_states() );
77  rotamer_set_ = rotamers;
78  for ( Size ii = 1; ii <= rotamer_set_->num_rotamers(); ++ii ) {
79  rotamers_[ ii ] = rotamer_set_->rotamer( ii );
80  if ( ii == 1 ) {
83  }
86  }
87 
88  // figure out which residue-type group each rotamer is a member of
89  Size curr_restype = 1;
90  Size count_for_restype = 1;
91  Size const num_aa_types_ = rotamers->get_n_residue_types();
92  //num_states_for_aatype_.resize( num_aa_types_ );
93  for ( Size ii = 1; ii <= rotamers_.size(); ++ii ) {
94 
95  sparse_mat_info_for_state_[ ii ].set_aa_type( curr_restype );
96  sparse_mat_info_for_state_[ ii ].set_state_ind_for_this_aa_type( count_for_restype );
97  ++count_for_restype;
98  ++num_states_for_aatype_[ curr_restype ];
99  while ( count_for_restype > rotamers->get_n_rotamers_for_residue_group( curr_restype )) {
100  // increment curr_restype and skip over restypes with 0 rotamers
101  ++curr_restype;
102  count_for_restype = 1;
103  if ( curr_restype > num_aa_types_ ) break;
104  state_offset_for_aatype_[ curr_restype ] = ii;
105  }
106  }
107 }
108 
109 void
111 {
112  if ( get_num_incident_edges() != 0 ) {
113  utility_exit_with_message( "ERROR:: Must set distinguish_backbone_and_sidechain before adding edges" );
114  }
116 }
117 
118 
119 void
121 {
122  std::fill( one_body_energies_.begin(), one_body_energies_.end(), 0.0f );
123 }
124 
125 void
126 OnTheFlyNode::add_to_one_body_energies( ObjexxFCL::FArray1_float & energy1b )
127 {
128  for ( Size ii = 1; ii <= one_body_energies_.size(); ++ii ) {
129  one_body_energies_[ ii ] += energy1b( ii );
130  }
131 }
132 
133 void
135 {
136  one_body_energies_[ state ] = energy;
137 }
138 
139 
140 /// @details sets one body energies for a given state
141 void
143 {
144  one_body_energies_[ state ] = energy;
145 }
146 
147 /// @details increments one body energies for a given state
148 void
150 {
151  one_body_energies_[ state ] += energy;
152 }
153 
154 
155 
156 void
158 {
159  one_body_energies_[ state ] = 0;
160 }
161 
162 /// @details reports the amount of dynamic memory this node allocates
163 /// recursing to its base class
164 unsigned int
166 {
167  unsigned int total_memory = NodeBase::count_dynamic_memory();
168 
169  total_memory += rotamers_.size() * sizeof ( conformation::ResidueCOP );
170  total_memory += num_states_for_aatype_.size() * sizeof( int );
171  total_memory += state_offset_for_aatype_.size() * sizeof( int );
172  total_memory += sparse_mat_info_for_state_.size() * sizeof( SparseMatrixIndex );
173  total_memory += one_body_energies_.size() * sizeof( core::PackerEnergy );
174 
175  return total_memory;
176 }
177 
178 
181  int edge_making_energy_request,
182  int state_this,
183  int state_other
184 ) const
185 {
186  using namespace scoring;
187  using namespace scoring::methods;
188 
189  core::PackerEnergy esum( 0.0 );
190 
191  OnTheFlyEdge const & spanning_edge( * get_incident_otf_edge( edge_making_energy_request ) );
192  OnTheFlyNode const & neighbor( * get_adjacent_otf_node( edge_making_energy_request ) );
193 
195 
196  if ( spanning_edge.short_range_interactions_exist() ) {
197  EnergyMap tbody_emap;
198 
199  switch ( spanning_edge.eval_type( get_node_index() )) {
200  case ( sc_sc ) :
202  get_rotamer( state_this ),
203  neighbor.get_rotamer( state_other ),
204  sc_bounding_sphere( state_this ).first,
205  neighbor.sc_bounding_sphere( state_other ).first,
206  sc_bounding_sphere( state_this ).second,
207  neighbor.sc_bounding_sphere( state_other ).second,
210  tbody_emap );
211 
212  /*get_on_the_fly_owner()->score_function().eval_ci_2b_sc_sc(
213  get_rotamer( state_this ),
214  neighbor.get_rotamer( state_other ),
215  get_on_the_fly_owner()->pose(),
216  tbody_emap );
217 
218  get_on_the_fly_owner()->score_function().eval_cd_2b_sc_sc(
219  get_rotamer( state_this ),
220  neighbor.get_rotamer( state_other ),
221  get_on_the_fly_owner()->pose(),
222  tbody_emap
223  );*/
224 
225  break;
226  case ( sc_whole ) :
228  get_rotamer( state_this ),
229  neighbor.get_rotamer( state_other ),
231  tbody_emap );
232 
234  get_rotamer( state_this ),
235  neighbor.get_rotamer( state_other ),
237  tbody_emap
238  );
239  /// Also evaluate the bb/sc energy between other/this
241  neighbor.get_rotamer( state_other ),
242  get_rotamer( state_this ),
244  tbody_emap );
245 
247  neighbor.get_rotamer( state_other ),
248  get_rotamer( state_this ),
250  tbody_emap
251  );
252 
253  break;
254  case ( whole_sc ) :
256  get_rotamer( state_this ),
257  neighbor.get_rotamer( state_other ),
259  tbody_emap );
260 
262  get_rotamer( state_this ),
263  neighbor.get_rotamer( state_other ),
265  tbody_emap
266  );
267  /// Also evaluate the bb/sc energy between this/other
269  get_rotamer( state_this ),
270  neighbor.get_rotamer( state_other ),
272  tbody_emap );
273 
275  get_rotamer( state_this ),
276  neighbor.get_rotamer( state_other ),
278  tbody_emap
279  );
280 
281 
282  break;
283  case ( whole_whole ) :
284 
286  get_rotamer( state_this ),
287  neighbor.get_rotamer( state_other ),
289  tbody_emap );
290 
292  get_rotamer( state_this ),
293  neighbor.get_rotamer( state_other ),
295  tbody_emap
296  );
297 
298  break;
299  }
300  esum += static_cast< core::PackerEnergy > ( get_on_the_fly_owner()->score_function().weights().dot( tbody_emap ) );
301 
302  }
303 
304  /// Gen-Borne will currently evaluate too many long range energies...
305  /// For now, long range interactions are computed for the whole residue, and do not divide it into pieces
306  if ( get_incident_otf_edge( edge_making_energy_request )->long_range_interactions_exist() ) {
307  EnergyMap emap;
310  iter != iter_end; ++iter ) {
311  (*iter)->residue_pair_energy(
312  get_rotamer( state_this ),
313  get_adjacent_otf_node( edge_making_energy_request )->get_rotamer( state_other ),
314  get_on_the_fly_owner()->pose(),
315  get_on_the_fly_owner()->score_function(),
316  emap );
317  }
318  esum += static_cast< core::PackerEnergy > ( get_on_the_fly_owner()->score_function().weights().dot( emap ) );
319  }
320 
321 
322  if ( get_adjacent_otf_node( edge_making_energy_request )->get_rotamer( state_other ).aa() == chemical::aa_pro )
323  {
324  esum += get_incident_otf_edge( edge_making_energy_request )->
325  get_proline_correction_for_node( get_node_index(), state_this );
326  }
327  if ( get_rotamer( state_this ).aa() == chemical::aa_pro )
328  {
329  esum += get_incident_otf_edge( edge_making_energy_request )->
330  get_proline_correction_for_node( get_index_of_adjacent_node( edge_making_energy_request ),
331  state_other
332  );
333  }
334 
335 
336  return get_incident_edge( edge_making_energy_request )->edge_weight() * esum;
337 
338  // if ( ! get_on_the_fly_owner()->check_empty_weight_map() ) {
339  //esum *= get_on_the_fly_owner()->get_residue_weights(this_rotamer.get_resid(), aa_this,
340  // other_rotamer.get_resid(), aa_other);
341 
342  //return esum;
343 
344 }
345 
346 
347 //-------------------------------------------------------------//
348 
350  InteractionGraphBase * owner,
351  int first_node_ind,
352  int second_node_ind
353 )
354 :
355  FixedBBEdge( owner, first_node_ind, second_node_ind ),
356  long_range_interactions_exist_( false ),
357  short_range_interactions_exist_( false )
358 {
359  bool distinguish_sc_bb[ 2 ];
360  for ( int ii = 0; ii < 2; ++ii) {
361  proline_corrections_[ ii ].resize( get_num_states_for_node( ii ) );
362  std::fill( proline_corrections_[ ii ].begin(), proline_corrections_[ ii ].end(), 0.0f );
363  distinguish_sc_bb[ ii ] = get_otf_node( ii )->distinguish_backbone_and_sidechain();
364  }
365 
366  if ( distinguish_sc_bb[ 0 ] && distinguish_sc_bb[ 1 ] ) {
367  eval_types_[ 0 ] = eval_types_[ 1 ] = sc_sc;
368  } else if ( ! distinguish_sc_bb[ 0 ] && distinguish_sc_bb[ 1 ] ) {
369  eval_types_[ 0 ] = whole_sc;
370  eval_types_[ 1 ] = sc_whole;
371  } else if ( distinguish_sc_bb[ 0 ] && ! distinguish_sc_bb[ 1 ] ) {
372  eval_types_[ 1 ] = whole_sc;
373  eval_types_[ 0 ] = sc_whole;
374  } else {
375  eval_types_[ 1 ] = eval_types_[ 0 ] = whole_whole;
376  }
377 }
378 
379 
381 
382 void
384  int node_not_necessarily_proline,
385  int state,
386  core::PackerEnergy bb_nonprobb_E,
387  core::PackerEnergy bb_probb_E,
388  core::PackerEnergy sc_nonprobb_E,
389  core::PackerEnergy sc_probb_E
390 )
391 {
392  int const which_node = node_not_necessarily_proline == get_node_index( 0 ) ? 0 : 1;
393 
394  proline_corrections_[ which_node ][ state ] =
395  sc_probb_E + 0.5 * bb_probb_E -
396  (sc_nonprobb_E + 0.5 * bb_nonprobb_E);
397 }
398 
399 
400 unsigned int
402 {
403  unsigned int total_memory_usage = EdgeBase::count_dynamic_memory();
404 
405  total_memory_usage += proline_corrections_[ 0 ].size() * sizeof( core::PackerEnergy );
406  total_memory_usage += proline_corrections_[ 1 ].size() * sizeof( core::PackerEnergy );
407 
408  return total_memory_usage;
409 }
410 
411 //-------------------------------------------------------------//
412 
414 :
415  FixedBBInteractionGraph( num_nodes ),
416  num_aa_types_( 0 )
417 {}
418 
420 {}
421 
422 bool
424 {
426 }
427 
428 void
430 {
432 }
433 
434 
435 void
437  rotamer_set::RotamerSetsBase const & rot_sets_base
438 )
439 {
440  rotamer_set::RotamerSets const & rot_sets( static_cast< rotamer_set::RotamerSets const & > (rot_sets_base) );
441 
442  // determine max # of residue types
443  Size max_nresgroups = 0;
444  for ( Size ii = 1; ii <= rot_sets.nmoltenres(); ++ii ) {
445  Size ii_nresgroups = rot_sets.rotamer_set_for_moltenresidue( ii )->get_n_residue_groups();
446  if ( ii_nresgroups > max_nresgroups ) max_nresgroups = ii_nresgroups;
447  }
448 
449  //"aa types" means "distinct groups of rotamers" -- this ig has no idea
450  // what an amino acid is or why they might be different from one another
451  num_aa_types_ = max_nresgroups;
452 
453 
454  for ( Size ii = 1; ii <= rot_sets.nmoltenres(); ++ii ) {
455  Size const ii_num_states = rot_sets.rotamer_set_for_moltenresidue( ii )->num_rotamers();
456  set_num_states_for_node( ii, ii_num_states );
458  }
459 
460 }
461 
462 void
464 {
465  score_function_ = sfxn.clone();
466  if ( pose_ ) (*score_function_)(*pose_); // rescore the pose with the input score function
467 }
468 
469 void
471 {
472  pose_ = new pose::Pose( pose );
473  if ( score_function_ ) (*score_function_)(*pose_);
474 }
475 
476 void
478  int node_ind,
479  int state
480 )
481 {
482  get_on_the_fly_node( node_ind )->zero_one_body_energy( state );
483 }
484 
485 void
487  int node_ind,
488  int state,
489  core::PackerEnergy one_body_energy
490 )
491 {
492  get_on_the_fly_node( node_ind )->add_to_one_body_energy( state, one_body_energy);
493 }
494 
495 void
497  int node_ind,
498  int state,
499  core::PackerEnergy one_body_energy
500 )
501 {
502  get_on_the_fly_node( node_ind )->set_one_body_energy( state, one_body_energy);
503 }
504 
505 
508 {
509  return get_on_the_fly_node( node )->get_one_body_energy( state );
510 }
511 
512 void
514 {
515  num_rpe_calcs_ = 0;
516 }
517 
518 
519 Size
521 {
522  return num_rpe_calcs_;
523 }
524 
525 
526 void
528  int node1,
529  int node2,
530  FArray2_bool const & sparse_conn_info
531 )
532 {
533  OnTheFlyEdge* edge = (OnTheFlyEdge*) find_edge( node1, node2 );
534  if (edge != 0) {
535  edge->set_sparse_aa_info( sparse_conn_info );
536  }
537 }
538 
539 void
541  int node1,
542  int node2,
543  int node_not_neccessarily_proline,
544  int state,
545  core::PackerEnergy bb_nonprobb_E,
546  core::PackerEnergy bb_probb_E,
547  core::PackerEnergy sc_nonprobb_E,
548  core::PackerEnergy sc_probb_E
549 )
550 {
551  OnTheFlyEdge* edge = (OnTheFlyEdge*) find_edge( node1, node2 );
552  if (edge != 0)
553  {
555  node_not_neccessarily_proline, state,
556  bb_nonprobb_E, bb_probb_E, sc_nonprobb_E, sc_probb_E );
557  }
558 }
559 
560 void
562  int node1,
563  int node2
564 )
565 {
566  OnTheFlyEdge* edge = (OnTheFlyEdge*) find_edge( node1, node2 );
567  if (edge != 0) {
569  }
570 }
571 
572 void
574  int node1,
575  int node2
576 )
577 {
578  OnTheFlyEdge* edge = (OnTheFlyEdge*) find_edge( node1, node2 );
579  if (edge != 0) {
581  }
582 }
583 
584 
585 unsigned int
587 {
588  unsigned int total_memory = InteractionGraphBase::count_dynamic_memory();
589  return total_memory;
590 }
591 
592 } // namespace interaction_graph
593 } // namespace pack
594 } // namespace core