Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
trie_vs_path.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/scoring/trie/trie_vs_trie.hh
11 /// @brief
12 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
13 
14 #ifndef INCLUDED_core_scoring_trie_trie_vs_path_hh
15 #define INCLUDED_core_scoring_trie_trie_vs_path_hh
16 
17 // Package Headers
18 // AUTO-REMOVED #include <core/scoring/trie/RotamerTrie.hh>
19 
20 // Project Headers
21 #include <core/types.hh>
22 
23 // STL Headers
24 // AUTO-REMOVED #include <iostream>
25 
26 // ObjexxFCL Headers
27 // AUTO-REMOVED #include <ObjexxFCL/FArray1D.hh>
28 // AUTO-REMOVED #include <ObjexxFCL/FArray1A.hh>
29 #include <ObjexxFCL/FArray2D.hh>
30 // AUTO-REMOVED #include <ObjexxFCL/FArray2A.hh>
31 
32 // Utility Headers
33 // AUTO-REMOVED #include <utility/vector1.hh>
34 
36 #include <utility/vector1_bool.hh>
37 
38 
39 namespace core {
40 namespace scoring {
41 namespace trie {
42 
43 void
45  utility::vector1< Size > const & total_rotamers_2_unique_rotamers,
46  utility::vector1< core::PackerEnergy > & pair_energy_vector,
47  utility::vector1< Energy > const & temp_vector
48 );
49 
50 
51 /// @brief trie vs path algorithm, templated on the Atom type that each TrieAtom is templated on,
52 /// along with the Count Pair data (two tries must share the same Atom type to be used for the
53 /// trie-vs-trie algorithm, but may contain different peices of count-pair data), on the kind of
54 /// count pair function used, and finally, on the score function itself.
55 ///
56 template < class AT, class CPDAT1, class CPDAT2, class CPFXN, class SFXN >
57 void
59  RotamerTrie< AT, CPDAT1 > const & trie1,
60  RotamerTrie< AT, CPDAT2 > const & trie2,
61  CPFXN & count_pair,
62  SFXN & score_function,
63  utility::vector1< core::PackerEnergy > & pair_energy_vector,
65 )
66 {
67  using namespace ObjexxFCL;
68 
69  DistanceSquared const hydrogen_interaction_cutoff = score_function.hydrogen_interaction_cutoff2();
70 
71  Size trie2_num_atoms = trie2.atoms().size();
72  Size const trie2_num_heavyatoms = trie2.num_heavy_atoms();
73 
74  Size const trie1_num_atoms = trie1.atoms().size();
75 
76  //trie_node* this_trie = get_trie_for_curr_bb();
77  //trie_node* bg_trie = bg.get_trie_for_curr_bb();
78 
79  typename utility::vector1< TrieNode < AT, CPDAT1 > > const & trie1_atoms = trie1.atoms();
80  typename utility::vector1 < TrieNode < AT, CPDAT2 > > const & trie2_atoms = trie2.atoms();
81 
82  Size const trie1_max_branch_depth = trie1.max_branch_depth();
83 
84  utility::vector1< Energy > energy_sum( trie1.max_atom_depth() + 1 );
85  energy_sum[1] = 0;
86  //FArray2D_bool parent_heavy_wi_hydrogen_cutoff( trie2_num_heavyatoms, trie1.max_heavyatom_depth(), true);
87  //FArray2D_bool r_heavy_skip_s_subtree(trie2_num_heavyatoms, trie1.max_heavyatom_depth(), false);
88  FArray2D_int parent_heavy_wi_hydrogen_cutoff( trie2_num_heavyatoms, trie1.max_heavyatom_depth(), true);
89  FArray2D_int r_heavy_skip_s_subtree(trie2_num_heavyatoms, trie1.max_heavyatom_depth(), false);
90 
91 
92  utility::vector1< Size > r_heavy_depth_stack( trie1_max_branch_depth );
93  r_heavy_depth_stack[1] = 0;
94 
95  Size r_num_rotamers_seen = 0;
96  Size r_curr_stack_top = 2;
97  Size s_heavy_depth;
98 
99  for ( Size ii = 1; ii <= trie1_num_atoms; ++ii ) {
100  TrieNode< AT, CPDAT1 > const & r = trie1_atoms[ ii ];
101 
102  if (r.first_atom_in_branch()) --r_curr_stack_top;
103  if (r.has_sibling() ) { //push - copy stack downwards
104  ++r_curr_stack_top;
105  energy_sum[ r_curr_stack_top ] = energy_sum[ r_curr_stack_top - 1];
106  r_heavy_depth_stack[ r_curr_stack_top ] = r_heavy_depth_stack[ r_curr_stack_top-1 ];
107  }
108 
109  //++r_tree_depth_stack[ r_curr_stack_top ];
110  if (! r.is_hydrogen() ) ++r_heavy_depth_stack[ r_curr_stack_top ];
111 
112  //FArray1A_bool parent_wi_h_dist
113  // ( parent_heavy_wi_hydrogen_cutoff( 1,r_heavy_depth_stack[ r_curr_stack_top ] ) );
114  //parent_wi_h_dist.dimension(trie2_num_heavyatoms);
115 
116  //FArray1A_int r_heavy_skip_s_subtree_proxy
117  // ( r_heavy_skip_s_subtree(1, r_heavy_depth_stack[ r_curr_stack_top ] ));
118  //r_heavy_skip_s_subtree_proxy.dimension(trie2_num_heavyatoms);
119 
120  s_heavy_depth = 0;
121 
122  if ( r.is_hydrogen() )
123  {
124  for ( Size jj = 1; jj <= trie2_num_atoms; ++jj )
125  {
126  //trie_node & s = bg_trie[jj];
127  TrieNode< AT, CPDAT2 > const & s = trie2_atoms[ jj ];
128  Real weight( 1.0 ); Energy e( 0.0 ); Size path_dist(0);
129  if ( s.is_hydrogen() )
130  {
131  if ( parent_heavy_wi_hydrogen_cutoff( s_heavy_depth, r_heavy_depth_stack[ r_curr_stack_top ] ) &&
132  count_pair( r.cp_data(), s.cp_data(), weight, path_dist ) ) {
133  e = score_function.hydrogenatom_hydrogenatom_energy( r.atom(), s.atom(), path_dist );
134  energy_sum[ r_curr_stack_top ] += weight * e;
135  }
136  } else {
137  ++s_heavy_depth;
138 
139  if (r_heavy_skip_s_subtree(s_heavy_depth,r_heavy_depth_stack[ r_curr_stack_top ])) break;
140 
141  if ( parent_heavy_wi_hydrogen_cutoff(s_heavy_depth, r_heavy_depth_stack[ r_curr_stack_top ] ) &&
142  count_pair( r.cp_data(), s.cp_data(), weight, path_dist )) {
143  e = score_function.hydrogenatom_heavyatom_energy( r.atom(), s.atom(), path_dist );
144  energy_sum[ r_curr_stack_top ] += e * weight;
145  }
146 
147  }
148  }
149  } else { //else r is a heavy atom
150  for ( Size jj = 1; jj <= trie2_num_heavyatoms; ++jj ) {
151  r_heavy_skip_s_subtree( jj, r_heavy_depth_stack[ r_curr_stack_top ] ) = false;
152  }
153  for ( Size jj = 1; jj <= trie2_num_atoms; ++jj ) {
154  TrieNode< AT, CPDAT2 > const & s = trie2_atoms[ jj ];
155  Real weight( 1.0 ); Energy e( 0.0 ); Size path_dist(0);
156  if ( s.is_hydrogen()) {
157  if (parent_heavy_wi_hydrogen_cutoff( s_heavy_depth, r_heavy_depth_stack[ r_curr_stack_top ] ) &&
158  count_pair( r.cp_data(), s.cp_data(), weight, path_dist ) ) {
159  e = score_function.heavyatom_hydrogenatom_energy( r.atom(), s.atom(), path_dist );
160  energy_sum[ r_curr_stack_top ] += weight * e;
161  }
162  } else {
163  ++s_heavy_depth;
164  DistanceSquared d2;
165 
166  if ( count_pair( r.cp_data(), s.cp_data(), weight, path_dist ) ) {
167  e = score_function.heavyatom_heavyatom_energy(r.atom(), s.atom(), d2, path_dist);
168  //std::cout << "hv/hv atom pair energy: " << ii << " & " << jj << " = " << weight * e << "( unweighted: " << e << ") estack: " << energy_stack[ s_curr_stack_top ] << std::endl;
169  energy_sum[ r_curr_stack_top ] += weight * e;
170  } else {
171  /// compute d2
172  d2 = r.atom().xyz().distance_squared( s.atom().xyz() );
173  }
174 
175  parent_heavy_wi_hydrogen_cutoff( s_heavy_depth, r_heavy_depth_stack[ r_curr_stack_top ] ) = (d2 < hydrogen_interaction_cutoff);
177  r_heavy_skip_s_subtree(s_heavy_depth, r_heavy_depth_stack[ r_curr_stack_top ]) = true;
178  break;
179  }
180  }
181  }
182  }
183 
184  if ( r.is_rotamer_terminal() )
185  {
186  ++r_num_rotamers_seen;
187  temp_vector[r_num_rotamers_seen] = energy_sum[ r_curr_stack_top ];
188  }
189  }
190 
193  pair_energy_vector,
194  temp_vector );
195 
196 }
197 
198 /* accidental path-vs-path alg in mini format -- use this later
199 {
200 
201 
202  Energy esum = 0;
203  Size s_heavy_depth = 0;
204 
205  Size const trie1_num_atoms = trie1.atoms().size();
206  Size const trie2_num_atoms = trie2.atoms().size();
207  Size const trie2_num_heavyatoms = trie2.num_heavy_atoms();
208  Size const trie2_num_heavyatoms_p_1 = trie2_num_heavyatoms + 1;
209 
210  //trie_node* rt_trie = rt.get_trie_for_curr_bb();
211  //trie_node* this_trie = get_trie_for_curr_bb();
212 
213  typename utility::vector1< TrieNode < AT, CPDAT1 > > const & trie1_atoms = trie1.atoms();
214  typename utility::vector1 < TrieNode < AT, CPDAT2 > > const & trie2_atoms = trie2.atoms();
215 
216  //FArray1D_bool parent_wi_h_dist( rt_num_heavyatoms, false );
217  bool parent_wi_h_dist[ 40 ]; //<--- replace this magic number ASAP
218  //FArray1D_bool r_heavy_skip_s_subtree( rt_num_heavyatoms, false );
219  Size r_heavy_skip_s_subtree_depth = rt_num_heavyatoms_p_1;
220 
221  for (int Size = 1; ii <= trie1_num_atoms; ++ii )
222  {
223  //trie_node & r = this_trie[ii];
224  TrieNode< AT, CPDAT1 > const & r = trie1_atoms[ ii ];
225  if ( r.is_hydrogen() && r_heavy_skip_s_subtree_depth == 1)
226  {
227  continue;
228  }
229 
230  //unsigned short * r_class_masks = NULL;
231  //for (int eq_class = 0; eq_class < 6; ++eq_class)
232  //{ if (this_equivalence_class_bitmasks[eq_class] & r.flags2_)
233  // { r_class_masks = rt_equivalence_class_bitmasks[eq_class];
234  // break;
235  // }
236  //}
237  //assert( r_class_masks );
238 
239  s_heavy_depth = 0;
240  if ( r.is_hydrogen() ) {
241  for ( Size jj = 1; jj <= trie2_num_atoms; ++jj ) {
242  //trie_node & s = rt_trie[jj];
243  TrieNode< AT, CPDAT2 > const & s = trie2_atoms[ jj ];
244  Real weight( 1.0 ), e( 0.0 );
245  if ( s.is_hydrogen() ) {
246  if (parent_wi_h_dist[ s_heavy_depth ] &&
247  count_pair( r.cp_data(), s.cp_data(), weight)) {
248  e = score_function.hydrogenatom_hydrogenatom_energy(r.atom(), s.atom() );
249  esum += weight * e;
250  }
251  } else {
252  ++s_heavy_depth;
253 
254  if (r_heavy_skip_s_subtree_depth == s_heavy_depth) break;
255 
256  if ( parent_wi_h_dist[s_heavy_depth] &&
257  count_pair( r.cp_data(), s.cp_data(), weight)) {
258  e = score_function.hydrogenatom_heavyatom_energy( r.atom(), s.atom() );
259  esum += e * weight;
260  }
261  }
262  }
263  } else {
264  r_heavy_skip_s_subtree_depth = rt_num_heavyatoms_p_1;
265  for ( Size jj = 1; jj <= rt_num_atoms; ++jj) {
266  trie_node & s = rt_trie[jj];
267  Real weight( 1.0 );
268  if ( s.is_hydrogen()) {
269  if (parent_wi_h_dist[ s_heavy_depth ] &&
270  count_pair( r.cp_data(), s.cp_data(), weight) ) {
271  Energy e = score_function.heavyatom_hydrogenatom_energy( r.atom(), s.atom() );
272  esum += e * weight;
273  }
274  }
275  else
276  {
277  ++s_heavy_depth;
278  DistanceSquared d2;
279  if ( count_pair( r.cp_data(), s.cp_data(), weight) ) {
280  Energy e = score_function.heavyatom_heavyatom_energy(r.atom(), s.atom(), d2);
281  //std::cout << "hv/hv atom pair energy: " << ii << " & " << jj << " = " << weight * e << "( unweighted: " << e << ") estack: " << energy_stack[ s_curr_stack_top ] << std::endl;
282  esum += weight * e;
283  } else {
284  /// compute d2
285  d2 = r.atom().xyz().distance_squared( s.atom().xyz() );
286  }
287 
288  parent_wi_h_dist[s_heavy_depth] = (d2 < hydrogen_interaction_cutoff);
289  if (d2 > s.subtree_interaction_sphere_square_radius())
290  {
291  r_heavy_skip_s_subtree_depth = s_heavy_depth;
292  break;
293  }
294  }
295  }
296  }
297  }
298 
299  return esum;
300 }
301 */
302 
303 } // namespace trie
304 } // namespace scoring
305 } // namespace core
306 
307 
308 #endif