Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MatchSet.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 // :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/OccupiedSpaceHash.hh
12 /// @brief Declaration for classes in 6D hasher
13 /// @author Alex Zanghellini (zanghell@u.washington.edu)
14 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com), porting to mini
15 
16 #ifndef INCLUDED_protocols_match_MatchSet_hh
17 #define INCLUDED_protocols_match_MatchSet_hh
18 
19 // Unit headers
21 
22 // Package headers
24 
25 //numeric headers
26 #include <numeric/geometry/hashing/SixDHasher.hh>
27 
28 // Utility headers
29 #include <utility/pointer/ReferenceCount.hh>
30 #include <utility/fixedsizearray1.hh>
31 #include <utility/FixedSizeLexicographicalIterator.fwd.hh>
32 
33 // AUTO-REMOVED #include <utility/vector1.hh>
34 
35 /// Boost headers
36 // AUTO-REMOVED #include <boost/cstdint.hpp>
37 #include <boost/unordered_map.hpp>
38 
39 /// C++ headers
40 #include <list>
41 
42 #include <utility/vector1_bool.hh>
43 
44 
45 namespace protocols {
46 namespace match {
47 
48 
49 /// @brief This object hashes hits into 6D voxels. This hash can then be traversed
50 /// to retrieve the hits that hash to the same voxel (matches!). There are 64 hashes
51 /// representing the 2^6 ways to perturb the bins in 6D by 1/2 of their bin width.
52 ///
53 /// @details The hit hasher expects someone else to own the hits. It takes as input
54 /// constant pointers to the hits that exist and uses their addresses to hash upon.
55 /// The hit hasher should only be used if you can guarantee that the hits it points
56 /// to will outlive the hasher.
58 public:
59  typedef core::Real Real;
60  typedef core::Size Size;
62  typedef numeric::geometry::BoundingBox< Vector > BoundingBox;
65  typedef boost::unordered_map< boost::uint64_t, MatchSet, numeric::geometry::hashing::bin_index_hasher > HitHash;
66 
67 public:
68  HitHasher();
69  virtual ~HitHasher();
70 
71  void
73  BoundingBox const & bb
74  );
75 
76  void
77  set_uniform_xyz_bin_width( Real bin_width );
78 
79  void
80  set_uniform_euler_angle_bin_width( Real bin_width_degrees );
81 
82  void
83  set_xyz_bin_widths( Vector const & bin_widths );
84 
85  void
86  set_euler_bin_widths( Vector const & euler_bin_widths );
87 
88  void
89  set_nhits_per_match( Size num_geometric_constraints );
90 
91  void
92  initialize();
93 
94  /// @brief Insert a hits into all 64 hash maps
95  void
96  insert_hit( Size geometric_constraint_id, Hit const * hit );
97 
98  /// @brief Insert a hits into a particular hash maps
99  void
100  insert_hit( Size which_hash_map, Size geometric_constraint_id, Hit const * hit );
101 
102  void
103  clear_hash_map( Size which_hash_map );
104 
105  HitHash::const_iterator
106  hit_hash_begin( Size which_hash_map ) const;
107 
108  HitHash::const_iterator
109  hit_hash_end( Size which_hash_map ) const;
110 
111  numeric::geometry::hashing::SixDCoordinateBinner const &
112  binner( Size which_hash_map ) const {
113  return * hit_hashes_[ which_hash_map ].first;
114  }
115 
116 private:
117  static Size const N_HASH_MAPS = 64; // 2^6 -- all combinations of offsets for 6 dimensions
118 
120 
122 
123  utility::fixedsizearray1< Real, 3 > xyz_bin_widths_;
124  utility::fixedsizearray1< Real, 3 > euler_bin_widths_;
126 
128 
129 };
130 
131 /// Class for finding hit neighbors in 6D considering all 64 origin definitions (but without
132 /// forming all 64 hashes).
134 {
135 public:
136  typedef core::Real Real;
137  typedef core::Size Size;
139  typedef numeric::geometry::BoundingBox< Vector > BoundingBox;
140  typedef numeric::geometry::hashing::Bin6D Bin6D;
141 
142  typedef std::list< Hit const * > HitPtrList;
143  typedef std::list< std::pair< core::Size, Hit const * > > HitIndexList;
144  typedef boost::unordered_map< boost::uint64_t, HitIndexList, numeric::geometry::hashing::bin_index_hasher > HitHash;
145 
146 public:
148  virtual ~HitNeighborFinder();
149 
150  /// @brief Use the same bounding box as the HitHasher / OccupiedSpaceHash
151  void
153  BoundingBox const & bb
154  );
155 
156  /// @brief Give the same xyz bin witdh given to the HitHasher / OccupiedSpaceHash.
157  void
158  set_uniform_xyz_bin_width( Real bin_width );
159 
160  /// @brief Give the same euler-angle bin witdh given to the HitHasher / OccupiedSpaceHash.
161  void
162  set_uniform_euler_angle_bin_width( Real bin_width_degrees );
163 
164 
165  /// @brief Give the same xyz bin witdhs given to the HitHasher / OccupiedSpaceHash.
166  void
167  set_xyz_bin_widths( Vector const & bin_widths );
168 
169  /// @brief Give the same euler-angle bin witdhs given to the HitHasher / OccupiedSpaceHash.
170  void
171  set_euler_bin_widths( Vector const & euler_bin_widths );
172 
173  /// @brief Call this after the bounding-box and the bin-widths have been set up. Must
174  /// be called before "add_hits" it called. This initializes the SixDCoordinateBinner.
175  void
176  initialize();
177 
178 
179  /// @brief Add all hits (using hit pointers!) from one list of hits
180  void add_hits( std::list< Hit > const & hitlist );
181 
182  /// @brief Add hit pointers from the input list
183  void add_hits( HitPtrList const & hitptrlist );
184 
185  /// @brief Compute the set of connected components for the set of input hits.
186  /// This search iterates across the 2^6 halfbin neighbors of each hit and creates
187  /// an adjacency graph to determine the connected components (CCs). The CCs are
188  /// returned in a vector where each element contains a list of hit pointers to the
189  /// elements of each connected component.
191  connected_components() const;
192 
193 
194  /// @brief Find the neighbors of the given set of query hits. This search iterates
195  /// across both the upper and the lower neighbors of the query hits (3^6 neighbors).
196  HitPtrList
197  neighbor_hits( HitPtrList const & queryhits ) const;
198 
199 private:
200  /// @brief Put the hits that have been added to "all_hits" into the hash_
201  void hash_hits();
202 
203  Size
205  Real6 orig_point,
206  Real6 offsets,
207  utility::FixedSizeLexicographicalIterator< 6 > const & halfbin_lex,
208  Bin6D & next_bin
209  ) const;
210 
211  bool
212  within_reach(
213  Bin6D const & query_halfbin,
214  Bin6D const & nb_halfbin,
215  Bin6D const & nbbin,
216  utility::FixedSizeLexicographicalIterator< 6 > const & halfbin_lex
217  ) const;
218 
219 
220 private:
221 
223 
225 
226  utility::fixedsizearray1< Real, 3 > xyz_bin_widths_;
227  utility::fixedsizearray1< Real, 3 > euler_bin_widths_;
228 
230 
231  numeric::geometry::hashing::SixDCoordinateBinnerOP binner_;
233 };
234 
235 /// Class for counting the number of matches given a particular discretization level.
237 {
238 public:
239  typedef core::Real Real;
240  typedef core::Size Size;
242  typedef numeric::geometry::BoundingBox< Vector > BoundingBox;
243  typedef numeric::geometry::hashing::Bin6D Bin6D;
244 
246  typedef boost::unordered_map< boost::uint64_t, HitCounts, numeric::geometry::hashing::bin_index_hasher > HitHash;
247 
248 public:
249  MatchCounter();
250  virtual ~MatchCounter();
251 
252  /// @brief Use the same bounding box as the HitHasher / OccupiedSpaceHash
253  void
255  BoundingBox const & bb
256  );
257 
258  void
259  set_n_geometric_constraints( Size ngeomcsts );
260 
261  /// @brief Give the same xyz bin witdh given to the HitHasher / OccupiedSpaceHash.
262  void
263  set_uniform_xyz_bin_width( Real bin_width );
264 
265  /// @brief Give the same euler-angle bin witdh given to the HitHasher / OccupiedSpaceHash.
266  void
267  set_uniform_euler_angle_bin_width( Real bin_width_degrees );
268 
269 
270  /// @brief Give the same xyz bin witdhs given to the HitHasher / OccupiedSpaceHash.
271  void
272  set_xyz_bin_widths( Vector const & bin_widths );
273 
274  /// @brief Give the same euler-angle bin witdhs given to the HitHasher / OccupiedSpaceHash.
275  void
276  set_euler_bin_widths( Vector const & euler_bin_widths );
277 
278  /// @brief Call this after the bounding-box and the bin-widths have been set up. Must
279  /// be called before "add_hits" it called. This initializes the SixDCoordinateBinner.
280  void
281  initialize();
282 
283  /// @brief Add hits from a list of hits for a particular geometric constraint.
284  void add_hits( Size geomcst_id, std::list< Hit > const & hitlist );
285 
286  /// @brief Add hit from the input list of hits for a particular geometric constraint.
287  void add_hits( Size geomcst_id, std::list< Hit const * > const & hitptrlist );
288 
289  /// @brief Possibly slow method to predict the total number of matches given a set of
290  /// hits and a particular grid resolution. (The main function that this class provides).
291  Size
292  count_n_matches() const;
293 
294 
295 private:
296  /*
297  /// @brief Put the hits that have been added to "all_hits" into the hash_
298  void hash_hits();
299 
300  Size
301  find_next_bin(
302  Real6 orig_point,
303  Real6 offsets,
304  utility::FixedSizeLexicographicalIterator< 6 > const & halfbin_lex,
305  Bin6D & next_bin
306  ) const;
307 
308  bool
309  within_reach(
310  Bin6D const & query_halfbin,
311  Bin6D const & nb_halfbin,
312  Bin6D const & nbbin,
313  utility::FixedSizeLexicographicalIterator< 6 > const & halfbin_lex
314  ) const;
315  */
316 
317 private:
318 
320 
323 
324  utility::fixedsizearray1< Real, 3 > xyz_bin_widths_;
325  utility::fixedsizearray1< Real, 3 > euler_bin_widths_;
326 
327  numeric::geometry::hashing::SixDCoordinateBinnerOP binner_;
329 };
330 
331 /// @brief Increment the euler angles and then wrap them into their appropriate ranges
334  numeric::geometry::hashing::Real3 const & orig_angles,
335  numeric::geometry::hashing::Real3 const & offsets
336 );
337 
338 
340 
342 
343  bool
344  operator() ( match_lite const & lhs, match_lite const & rhs ) const {
345  if ( lhs.size() != rhs.size() ) return false;
346  for ( core::Size ii = 1; ii <= lhs.size(); ++ii ) {
347  if ( lhs[ ii ] != rhs[ ii ] ) {
348  return false;
349  }
350  }
351  return true;
352  }
353 
354 };
355 
357 public:
358  typedef core::Size Size;
359 
360 public:
361  Size
362  operator() ( match_lite const & m ) const {
363  /// Crazy hash function!
364  Size hash = 1;
365  for ( core::Size ii = 1; ii <= m.size(); ++ii ) {
366  hash += ( hash * reinterpret_cast< Size > ( m[ ii ] ) * ii ) % 5527;
367  }
368  return hash % 7351;
369  }
370 };
371 
373 {
374 public:
375 
376  typedef boost::unordered_map< match_lite, bool, match_lite_hasher, match_lite_equals > MatchHash;
377 
378 public:
380 
381  void
382  note_output_match( match_lite const & );
383 
384  bool
385  match_has_been_output( match_lite const & m ) const;
386 
387 private:
389 
390 };
391 
392 
393 }
394 }
395 
396 #endif