14 #ifndef INCLUDED_core_scoring_trie_trie_vs_trie_hh
15 #define INCLUDED_core_scoring_trie_trie_vs_trie_hh
33 #include <ObjexxFCL/FArray2D.hh>
34 #include <ObjexxFCL/FArray2A.hh>
39 #include <utility/vector1_bool.hh>
53 template <
class AT,
class CPDAT1,
class CPDAT2,
class CPFXN,
class SFXN >
59 SFXN & score_function,
60 ObjexxFCL::FArray2D< core::PackerEnergy > & pair_energy_table,
61 ObjexxFCL::FArray2D< core::PackerEnergy > & temp_table
72 using namespace ObjexxFCL;
74 ObjexxFCL::FArray2A< core::PackerEnergy > rot_rot_table(
82 Size const trie1_natoms = trie1.
atoms().size();
86 Size const trie2_natoms = trie2.
atoms().size();
94 FArray2D< core::PackerEnergy > at_v_rot_stack( trie2_num_unique_rotamers, trie1_max_branch_depth, 0.0);
96 FArray2D_int parent_heavy_wi_hydrogen_cutoff(trie2_num_heavyatoms, trie1_max_heavyatom_depth,
true);
97 FArray2D_int r_heavy_skip_s_subtree(trie2_num_heavyatoms, trie1_max_heavyatom_depth,
false);
110 s_sibling_stack[1] = trie2_natoms + 1;
112 s_sibling_stack[ii] = 0;
115 Size r_curr_stack_top = 2;
116 Size s_curr_stack_top;
117 Size r_rotamers_seen = 0;
118 Size s_rotamers_seen;
119 Size s_heavyatoms_seen;
121 r_heavy_depth_stack[1] = 0;
123 for (
Size ii = 1; ii <= trie1_natoms; ++ii )
130 s_heavyatoms_seen = 0;
144 for (
Size jj = 1, litop = at_v_rot_stack.index( 1, r_curr_stack_top ),
145 liprev = at_v_rot_stack.index( 1, r_curr_stack_top - 1 );
146 jj <= trie2_num_unique_rotamers; ++jj, ++litop, ++liprev ) {
147 at_v_rot_stack[ litop ] = at_v_rot_stack[ liprev ];
150 r_heavy_depth_stack[ r_curr_stack_top ] = r_heavy_depth_stack[ r_curr_stack_top-1 ];
156 if (! r.
is_hydrogen() ) ++r_heavy_depth_stack[ r_curr_stack_top ];
168 s_curr_stack_top = 2;
169 s_heavy_depth_stack[1] = 0;
172 for (
Size jj = 1; jj <= trie2_natoms; ++jj ) {
187 energy_stack[s_curr_stack_top] = energy_stack[s_curr_stack_top - 1];
188 s_heavy_depth_stack[ s_curr_stack_top] = s_heavy_depth_stack[ s_curr_stack_top - 1];
191 s_sibling_stack[s_curr_stack_top] = s.
sibling();
197 ++s_heavy_depth_stack[s_curr_stack_top];
198 parent_heavy_wi_hcut_stack[s_heavy_depth_stack[s_curr_stack_top]]
199 = parent_heavy_wi_hydrogen_cutoff(s_heavyatoms_seen, r_heavy_depth_stack[ r_curr_stack_top ] );
201 if ( r_heavy_skip_s_subtree(s_heavyatoms_seen, r_heavy_depth_stack[ r_curr_stack_top ]) ) {
202 if (energy_stack[s_curr_stack_top] != 0.0f ) {
203 for (
Size kk = s_rotamers_seen + 1;
206 at_v_rot_stack(kk, r_curr_stack_top) += energy_stack[s_curr_stack_top];
210 jj = s_sibling_stack[s_curr_stack_top] - 1;
216 if ( parent_heavy_wi_hcut_stack[s_heavy_depth_stack[s_curr_stack_top] ] &&
219 e = score_function.hydrogenatom_hydrogenatom_energy(r.
atom(), s.
atom(), path_dist );
220 energy_stack[ s_curr_stack_top ] += weight * e;
224 e = score_function.hydrogenatom_heavyatom_energy( r.
atom(), s.
atom(), path_dist );
225 energy_stack[ s_curr_stack_top ] += weight * e;
232 at_v_rot_stack(s_rotamers_seen, r_curr_stack_top) += energy_stack[ s_curr_stack_top ];
236 s_curr_stack_top = 2;
237 s_heavy_depth_stack[1] = 0;
241 liskip = r_heavy_skip_s_subtree.index( 1, r_heavy_depth_stack[ r_curr_stack_top ] );
242 jj <= trie2_num_heavyatoms; ++jj, ++liskip ) {
243 r_heavy_skip_s_subtree[ liskip ] =
false;
246 for (
Size jj = 1; jj <= trie2_natoms; ++jj ) {
261 energy_stack[s_curr_stack_top] = energy_stack[s_curr_stack_top - 1];
262 s_heavy_depth_stack[ s_curr_stack_top] = s_heavy_depth_stack[ s_curr_stack_top - 1];
265 s_sibling_stack[s_curr_stack_top] = s.
sibling();
270 Real weight(1.0);
Size path_dist(0);
271 if (parent_heavy_wi_hcut_stack[s_heavy_depth_stack[s_curr_stack_top]] &&
274 energy_stack[ s_curr_stack_top ] += weight * e;
283 ++s_heavy_depth_stack[s_curr_stack_top];
291 e = score_function.heavyatom_heavyatom_energy(r.
atom(), s.
atom(), d2, path_dist);
293 energy_stack[s_curr_stack_top] += weight * e;
296 d2 = r.
atom().xyz().distance_squared( s.
atom().xyz() );
299 parent_heavy_wi_hcut_stack[s_heavy_depth_stack
300 [s_curr_stack_top]] =
301 parent_heavy_wi_hydrogen_cutoff(s_heavyatoms_seen, r_heavy_depth_stack[ r_curr_stack_top ]) =
305 r_heavy_skip_s_subtree(s_heavyatoms_seen, r_heavy_depth_stack[ r_curr_stack_top ]) =
true;
306 if (energy_stack[s_curr_stack_top] != 0. ) {
307 for (
Size kk = s_rotamers_seen + 1,
308 li_avrstack = at_v_rot_stack.index( kk, r_curr_stack_top );
310 ++kk, ++li_avrstack ) {
311 at_v_rot_stack[ li_avrstack ] += energy_stack[s_curr_stack_top];
315 jj = s_sibling_stack[s_curr_stack_top] - 1;
323 at_v_rot_stack(s_rotamers_seen, r_curr_stack_top) += energy_stack[s_curr_stack_top];
337 for (
Size jj = 1; jj <= trie2_num_unique_rotamers; ++jj ) {
338 rot_rot_table( jj, r_rotamers_seen ) = at_v_rot_stack( jj, r_curr_stack_top );
359 delete [] parent_heavy_wi_hcut_stack;