Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BumpGrid.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/BumpGrid.hh
12 /// @brief
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_BumpGrid_hh
17 #define INCLUDED_protocols_match_BumpGrid_hh
18 
19 // Unit headers
21 
22 // Package headers
23 
24 // Project headers
25 #include <core/types.hh>
27 #include <core/pose/Pose.fwd.hh>
28 
29 // Utility headers
30 #include <utility/fixedsizearray1.hh>
31 // AUTO-REMOVED #include <utility/vector0.hh>
32 // AUTO-REMOVED #include <utility/vector1.hh>
33 #include <utility/pointer/ReferenceCount.hh>
34 
35 // Numeric headers
36 #include <numeric/xyzVector.hh>
37 #include <numeric/geometry/BoundingBox.hh>
38 #include <numeric/geometry/hashing/SixDHasher.fwd.hh> // typedefs for Bin3D.
39 
40 // C++ headers
41 // AUTO-REMOVED #include <list>
42 #include <string>
43 #include <iosfwd>
44 
45 #include <utility/vector0_bool.hh>
46 #include <utility/vector1.hh>
47 
48 
49 namespace protocols {
50 namespace match {
51 
53 {
54 public:
55  typedef core::Real Real;
57  typedef numeric::geometry::BoundingBox< core::Vector > BoundingBox;
58  typedef numeric::geometry::hashing::Bin3D Bin3D;
59  typedef utility::fixedsizearray1< Vector, 8 > CornerPoints;
60  typedef std::pair< Bool3DGrid::Size, unsigned char > index_mask_pair;
61 
62 public:
63  /// Creation and initialization
64  Bool3DGrid();
65  virtual ~Bool3DGrid();
66 
67  void set_bounding_box( BoundingBox const & bb );
68  void set_bin_width( Real width );
69 
70  /// @brief create a grid for the input sphere that aligns to this grid,
71  /// such that it is large enough to hold a particular sphere.
73  create_grid_for_sphere( Vector const & center, Real radius ) const;
74 
75  /// @brief create a grid for the input bounding box that aligns to this grid
77  create_grid_for_bb( BoundingBox const & bb );
78 
79 public:
80  /// Accessors
81  Bin3D dimsizes() const;
82 
83  Real bin_width() const { return bin_width_; }
84 
85  CornerPoints corners( Bin3D const & bin ) const;
86 
87  /// @brief bounding box points for a bin.
88  BoundingBox bin_extrema( Bin3D const & bin ) const;
89 
90  Vector
91  bin_center( Bin3D const & bin ) const;
92 
93  bool occupied( Vector const & ) const;
94 
95  bool occupied( Bin3D const & bin ) const;
96 
97  BoundingBox actual_bb() const { return bb_extended_; }
98 
99 public:
100  // Mutators
101 
102  /// @brief set the boolean value for a particular bin.
103  /// The bin dimensions are indexed from 0 to nbins-1.
104  void set_value_for_bin( Bin3D const & bin, bool setting );
105 
106  /// @brief Set the value to true for any voxel that is wholy contained
107  /// by the given sphere. A voxel is wholy contained iff all 8 corners
108  /// of the voxel are within the sphere.
109  void
110  or_by_sphere_conservative( Vector const & center, Real radius );
111 
112 
113  /// @brief Set the value to true for any voxel that is partially contained
114  /// by a given sphere. A voxel is partially contained iff any of the 8 corners
115  /// of the voxel are within the sphere.
116  void
117  or_by_sphere_liberal( Vector const & center, Real radius );
118 
119  /// @brief Consider a voxel filled if each of its corners are covered,
120  /// even if they are covered by seperate spheres. Dangerous, in that some
121  /// voxels will be counted as being fully occupied when they are only partially occupied.
122  void
124  utility::vector1< std::pair< Vector, Real > > const & spheres
125  );
126 
127  //// @brief Turn the values of all the bins that overlap with the
128  /// volume in this bounding box to true.
129  void
131  BoundingBox const & bb
132  );
133 
134  /// @brief Performs a boolean OR on the voxels shared by the two grids,
135  /// and ignores all voxels that are not shared by the two grids. These grids
136  /// must be "compatible", in that the lower corner of other must lie on a grid
137  /// point of this.
138  void or_with( Bool3DGrid const & other );
139 
140  /// @brief Performs a boolean AND on the voxels shared by the two grids,
141  /// and ignores all voxels that are not shared by the two grids. These grids
142  /// must be "compatible", in that the lower corner of other must lie on a grid
143  /// point of this.
144  void and_with( Bool3DGrid const & other );
145 
146  /// @brief Sets any voxel on this grid to "false" which is true on the other grid.
147  /// but does not set any voxel to "true" on this grid -- even if the other voxel is "false".
148  void subtract( Bool3DGrid const & other );
149 
150  /// @brief Set all values in all bins to false
151  void clear();
152 
153 private:
155  index_and_mask_for_point( Vector const & point ) const;
156 
158  index_and_mask_for_bin( Bin3D const & bin ) const;
159 
160  Bin3D bin_for_point( Vector const & point ) const;
161 
162  void
163  reset_grid();
164 
165  unsigned char
166  mask_from_offsets( Size xmod2, Size ymod2, Size zmod2 ) const;
167 
168  unsigned char
169  negmask_from_offsets( Size xmod2, Size ymod2, Size zmod2 ) const;
170 
171  Size
172  byte_index_from_doublebin( Bin3D const & halfbin ) const;
173 
174 
175 private:
176  BoundingBox bb_; // user defined volume of space covered by this grid.
177  BoundingBox bb_extended_; // the actual volume of space covered by this grid.
178 
184 
185  Bin3D halfdimsizes_; // the double-bins are twice as large as the bins in each dimension
187 
188  Bin3D supervoxel_dimsizes_; // super voxels hold several double-bins, as defined by the
190 
191  /// creates super voxels of size 8x8x8 = 512 bits -> 64 bytes = cache line size on Core2 Duo,
192  /// though this size should not have a very large effect for caches of larger or smaller size.
193  /// The main point of the super voxel is to allow data locality as it's very often the same
194  /// region of space that's being queried repeatedly during rotamer building.
196 
197  /// Each byte represents the boolean "covered" status for 8 voxels
198  /// in a double-voxel. The double voxel
200 
201 };
202 
204 {
205 public:
209  typedef std::pair< Vector, core::Real > Sphere;
210  typedef core::Real Real;
212 
213 public:
214  BumpGrid();
215  BumpGrid( BumpGrid const & );
216  virtual ~BumpGrid();
217 
218  BumpGrid const & operator = ( BumpGrid const & );
219 
220 
221 public:
222  /// Initialization
223  void set_bounding_box( BoundingBox const & bb );
224 
225  //// @brief Set the tolerance for sphere overlap between all sphere types.
226  /// All tolerances must be set *before* any spheres are ORed into the grid.
227  void set_general_overlap_tolerance( Real tolerated_overlap );
228 
229  //// @brief Set the overlap tolerance for a specific pair of sphere types (e.g. OXY/NIT)
230  /// The specific tolerance is combined with the general overlap tolerance.
231  /// All tolerances must be set *before* any spheres are ORed into the grid.
232  void set_pair_overlap_tolerance( ProbeRadius rad1, ProbeRadius rad2, Real tolerated_overlap );
233 
234 public:
235  BumpGrid
236  create_bump_grid_for_bb( BoundingBox const & bb ) const;
237 
238  BumpGridOP
239  create_new_bump_grid_for_bb( BoundingBox const & bb ) const;
240 
241  void or_with( BumpGrid const & );
242  void and_with( BumpGrid const & );
243 
244  void or_by_sphere( Sphere const & );
245  void or_by_sphere( Vector const & center, ProbeRadius radius_type );
246 
247  bool overlaps( BumpGrid const & ) const;
248 
249  /// @brief Collision detection by a point p with a given (fixed) radius type.
250  /// Collision detection is performed in "configuration space", where the obstacles
251  /// have been convolved with a spherical probe of a given radius. This collision
252  /// detection is conservative: it will not report a collision to exist that does not,
253  /// but may miss a collision that does exist.
254  bool occupied( ProbeRadius radius_type, Vector const & p ) const;
255 
256  static Real probe_radius( ProbeRadius radtype ) {
257  switch ( radtype ) {
258  case ZERO : return 0.0;
259  case H_ARO : return 1.0;
260  case H_ALA : return 1.17;
261  case OXY : return 1.40;
262  case NIT : return 1.55;
263  case C_CAR : return 1.65;
264  case C_ALA : return 1.75;
265  case SULPH : return 1.85;
266  }
267  return 0.0;
268  }
269 
271 
272  Bool3DGrid const &
273  grid( ProbeRadius radtype ) const {
274  return * grids_[ radtype ];
275  }
276 
277  inline
278  Real
280  if ( rad1 == ZERO || rad2 == ZERO ) return 0.0;
281  return std::max( probe_radius( rad1 ) + probe_radius( rad2 )
282  - pair_permit_overlap_[ rad1 ][ rad2 ]
283  - general_permit_overlap_, 0.0 );
284  }
285 
286 private:
287 
289 
290  /// allow some pairs of atom types to overlap by a certain amount -- e.g. O and N
292 
293  /// allow all pairs of atom types to overlap by a certain amount
295 
296 };
297 
300 
303 
304 
305 /// @brief Construct a BumpGrid that encloses a single residue. Use the
306 /// original_grid as a starting point, copying over all pertinent data
307 /// such that the two grids can later be merged together.
310  core::conformation::Residue const & residue,
311  BumpGrid const & original_grid
312 );
313 
314 /// @brief Construct a BumpGrid that encloses the backbone atoms for a single residue.
315 /// Use the original_grid as a starting point, copying over all pertinent data
316 /// such that the two grids can later be merged together.
319  core::conformation::Residue const & residue,
320  BumpGrid const & original_grid
321 );
322 
323 
324 void
326  core::conformation::Residue const & residue,
327  BumpGrid & grid
328 );
329 
330 void
332  core::conformation::Residue const & residue,
333  BumpGrid & grid
334 );
335 
336 void
338  core::conformation::Residue const & residue,
339  BumpGrid & grid
340 );
341 
342 
343 
345 {
346 public:
347  typedef core::Real Real;
348  typedef core::Size Size;
350  typedef numeric::geometry::hashing::Bin3D Bin3D;
351 
352 public:
355 
356  void set_unselectable( bool unselectable );
357  void set_line_color( std::string const & line_color );
358  void set_master( std::string const & master );
359  void set_shrink_factor( Real shrink_factor );
360  void set_skip_completely_buried_positions( bool skip_completely_buried_positions );
361 
364 
365  void set_write_facets( bool write_facets );
366  void set_facet_master( std::string const & facet_master );
367  void set_facet_color( std::string const & facet_color );
368  void set_transparent_facets( bool transparent_facets );
369  void set_facet_alpha( Real facet_alpha );
370 
372  std::ostream & ostr,
373  std::string const & group_name,
374  Bool3DGrid const & grid ) const;
375 
376  void write_grid_to_file(
377  std::string const & fname,
378  std::string const & group_name,
379  Bool3DGrid const & grid
380  ) const;
381 
382 private:
388 
391 
397 
398 };
399 
400 }
401 }
402 
403 #endif