Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UpstreamHitCacher.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 // :noTabs=false:tabSize=4:indentSize=4:
4 //
5 // (c) Copyright Rosetta Commons Member Institutions.
6 // (c) This file is part of the Rosetta software suite and is made available under license.
7 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
8 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
9 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
10 
11 /// @file protocols/match/output/UpstreamHitCacher.hh
12 /// @brief Declaration for class to cache and recall the conformations of upstream hits.
13 /// @author Alex Zanghellini (zanghell@u.washington.edu)
14 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com), porting to mini
15 
16 // Unit headers
18 
19 // Package headers
20 #include <protocols/match/Hit.hh>
23 
24 // Project headers
26 
27 // Utility headers
28 #include <utility/pointer/ReferenceCount.hh>
29 #include <utility/exit.hh>
30 
31 // C++ headers
32 #include <map>
33 
34 #include <utility/OrderedTuple.hh>
35 #include <utility/vector1.hh>
36 
37 
38 namespace protocols {
39 namespace match {
40 namespace output {
41 
42 
44  matcher_( matcher ),
45  n_geometric_constraints_( matcher_ ? matcher_->n_geometric_constraints() : 0 ),
46  n_confs_to_cache_( 100 ),
47  index_for_rotamer_( n_geometric_constraints_ ),
48  which_cst_being_processed_( 0 ),
49  queue_head_( n_geometric_constraints_, 0 ),
50  scafrot_pair_for_conf_( n_geometric_constraints_ ),
51  upstream_confs_( n_geometric_constraints_ )
52 {
53  resize_arrays();
54 }
55 
57 
58 void
60 {
61  n_confs_to_cache_ = n_rotamers_to_cache;
62  resize_arrays();
63 }
64 
65 
68 {
70  #pragma omp critical ( upstream_hit_cacher_upstream_conformation_for_hit )
71  {
72  ScaffoldRotamerPair srp; srp[ 1 ] = hit.scaffold_build_id(); srp[ 2 ] = hit.upstream_conf_id();
73  ScaffoldRotamerTuple srt( srp );
74  Size index = already_in_queue( cst_id, srt );
75  if ( index == 0 ) {
76  index = fetch( cst_id, srt );
77  }
78  residue = upstream_confs_[ cst_id ][ index ];
79  }
80  return residue;
81 }
82 
83 
84 void
86  Hit const & hit,
87  core::conformation::Residue const & upstream_conformation
88 )
89 {
90  runtime_assert( which_cst_being_processed_ != 0 );
91 
92  Size const cst_id = which_cst_being_processed_;
93 
94  if ( queue_head_[ cst_id ] == 0 ) {
95  /// empty queue condition
96  ++queue_head_[ cst_id ];
97  } else {
98  Size next = queue_head_[ cst_id ] + 1;
99  if ( next == n_confs_to_cache_ + 1 ) next = 1;
100 
101  if ( upstream_confs_[ cst_id ][ next ] ) {
102  // erase the entry for this rotamer in the index_for_rotamer_ map;
103  std::map< ScaffoldRotamerTuple, Size >::iterator iter =
104  index_for_rotamer_[ cst_id ].find( scafrot_pair_for_conf_[ cst_id ][ next ] );
105  runtime_assert( iter != index_for_rotamer_[ cst_id ].end() );
106  index_for_rotamer_[ cst_id ].erase( iter );
107  }
108  queue_head_[ cst_id ] = next;
109  }
110 
111  Size index = queue_head_[ cst_id ];
112 
113  upstream_confs_[ cst_id ][ index ] = new core::conformation::Residue( upstream_conformation );
114 
115  ScaffoldRotamerPair srp; srp[ 1 ] = hit.scaffold_build_id(); srp[ 2 ] = hit.upstream_conf_id();
116  ScaffoldRotamerTuple srt( srp );
117 
118  scafrot_pair_for_conf_[ cst_id ][ index ] = srt;
119  index_for_rotamer_[ cst_id ][ srt ] = index;
120 
121 }
122 
123 
124 void
126 {
127  assert( index_for_rotamer_.size() == n_geometric_constraints_ );
129  assert( upstream_confs_.size() == n_geometric_constraints_ );
130  assert( queue_head_.size() == n_geometric_constraints_ );
131 
132  std::fill( queue_head_.begin(), queue_head_.end(), 0 );
133  for ( Size ii = 1; ii <= n_geometric_constraints_; ++ii ) {
134  index_for_rotamer_[ ii ].clear();
135  scafrot_pair_for_conf_[ ii ].clear();
137  upstream_confs_[ ii ].clear();
138  upstream_confs_[ ii ].resize( n_confs_to_cache_ );
139  }
140 }
141 
142 
143 /// @brief Returns 0 if the scaffold/rotamer pair is not already in the queue, and
144 /// the non-zero index in the queue if it is.
147 {
148  std::map< ScaffoldRotamerTuple, Size >::const_iterator iter = index_for_rotamer_[ cst_id ].find( rotid );
149  if ( iter == index_for_rotamer_[ cst_id ].end() ) {
150  return 0;
151  } else {
152  return iter->second;
153  }
154 }
155 
156 /// @brief Construct the rotamer for the requested scaffold/rotamer pair and
157 /// put it into the queue, evicting the previous queue resident if necessary.
160 {
162 
163  Hit hit;
164  hit.first()[ 1 ] = rotid.data()[ 1 ];
165  hit.first()[ 2 ] = rotid.data()[ 2 ];
166 
167  matcher_->upstream_builder( cst_id )->recover_hit(
168  hit,
169  * matcher_->build_point( hit.scaffold_build_id() ),
170  * this
171  );
172 
174 
175  return queue_head_[ cst_id ];
176 }
177 
178 /*
179 private:
180  MatcherCOP matcher_;
181 
182  Size n_geometric_constraints_;
183  Size n_confs_to_cache_;
184 
185  utility::vector1< std::map< ScaffRotamerTuple, Size > > index_for_rotamer_;
186 
187  utility::vector1< Size > queue_head_;
188  utility::vector1< utility::vector1< ScaffoldRotamerTuple > > scafrot_pair_for_conf_;
189  utility::vector1< utility::vector1< core::conformation::ResidueCOP > > upstream_confs_;
190 
191 };
192 */
193 
194 }
195 }
196 }
197