Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LoopHashMap.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 protocols/loophash/LoopHashMap.hh
11 /// @brief
12 /// @author Mike Tyka
13 /// @author Ken Jung
14 
15 #ifndef INCLUDED_protocols_loophash_LoopHashMap_hh
16 #define INCLUDED_protocols_loophash_LoopHashMap_hh
17 
18 #include <core/types.hh>
19 #include <core/pose/Pose.fwd.hh>
20 //#include <protocols/match/Hit.fwd.hh>
21 // AUTO-REMOVED #include <protocols/match/Hit.hh>
22 //#include <protocols/match/SixDHasher.hh>
23 #include <boost/unordered_map.hpp>
24 // AUTO-REMOVED #include <boost/cstdint.hpp>
25 // AUTO-REMOVED #include <numeric/HomogeneousTransform.hh>
26 #include <utility/pointer/ReferenceCount.hh>
28 
29 #include <numeric/geometry/hashing/SixDHasher.hh>
30 
31 #include <string>
32 #include <vector>
33 #include <map>
34 
35 #include <utility/exit.hh>
36 #include <utility/vector1.hh>
37 
38 namespace protocols {
39 namespace loophash {
40 
41 /// @brief This takes a pose and two residue positions and determines the rigid body transform of the Leap described by those two residues.
42 /// Returns true is successful or false if something went haywire and one should just ignore this loop (this can happen at the ends)
44 
45 /// @brief This takes a pose and two residue positions and determines the rigid body transform of the Leap described by those two residues
46 /// Returns true is successful or false if something went haywire and one should just ignore this loop (this can happen at the ends)
47 /// THe difference between this and the get_rt_over_leap function is that this version doesnt make a copy of the pose which makes it faster.
48 /// However this means that the pose passed cannot be a const pose, even though the function restores the fold tree afterwards..
50 
51 /// @brief This takes a pose and two residue positions and determines the rigid body transform of the Leap described by those two residues.
52 // sheffler
53 bool
55  core::pose::Pose const & pose,
56  core::Size ir,
57  core::Size jr,
59 );
60 
61 
62 /// @brief The LeapIndex stores information about a particular Leap. It hold the oroiginal high precision rigid body transform
63 /// and an Index to a Backbone Database (BackboneDB) that has the actual phi psi angles. THe storage of the precise RT takes a
64 /// lot of space and may be deprecated at some point, since once it is hashed, it is rarely needed and can be recomputed if it is.
65 /// Note that the length of the loop is not stored either, this is again done for saving memory, as huge lists of Leaps are
66 /// typically created all with the same length. THe length is stored and handled by the owner of LeapIndex list.
67 /// The LeapIndex does not store the actual backbone coordinates of the Leap. It merely contains an index (the BackboneIndex)
68 /// which refers to a serial store of backbone triples (phi,psi, omega) which are stored somewhere else in a BackboneDB.
69 /// THis is improtant to save memory storage since multiple Leaps cna share the same backbone triple and redundant storage
70 /// would be hugely wasteful.
71 struct LeapIndex{
74  boost::uint64_t key;
75 };
77  float vecx;
78  float vecy;
79  float vecz;
80  float rotx;
81  float roty;
82  float rotz;
83  unsigned int ba;
84 };
85 
86 /// @brief the loop hash map stores LeapIndexes and a hashmap to access those LeapIndexes quickly by their 6D coordinates.
87 ///
88 
90  public:
91  /// @brief Constructor - must give loop_size
92  LoopHashMap( core::Size loop_size = 10);
93 
94  private:
95  /// @brief Setup this class give a loop_size
96  void setup( core::Size loop_size);
97 
98  /// @brief Add a given piece of data to the hash
100 public:
101 
102  /// @brief Add a leap/loop to the HashMap
103  void add_leap( const LeapIndex &leap_index, numeric::geometry::hashing::Real6 & transform );
104 
105  /// @brief Add a leap/loop to the HashMap with a key, skipping hashing
106  void add_leap( const LeapIndex &leap_index, boost::uint64_t key );
107 
108  /// @brief Add an legacy leap/loop to the HashMap
109  void add_legacyleap( const LegacyLeapIndex &legacyleap_index );
110 
111  /// @brief Obtain an index to a given peptide saved
112  inline const LeapIndex & get_peptide( core::Size index ){
113  runtime_assert( index < loopdb_.size() );
114  return loopdb_[ index ];
115  }
116 
117  inline core::Size n_loops() const {
118  return loopdb_.size();
119  }
120 
121  /// @brief Return a vector of loops with equal keys given a key
122  // And any keys within a radius around the original key
123  void radial_lookup_withkey( boost::uint64_t key, core::Size radius, std::vector < core::Size > &result );
124 
125  /// @brief Return a vector of loops with equal keys given a key
126  // Identical to radial_lookup_withkey(radius=0), but faster
127  void lookup_withkey( boost::uint64_t key, std::vector < core::Size > &result );
128 
129  /// @brief Append to a bucket of vectors in the appropriate bin, lookup by transform
130  void lookup( numeric::geometry::hashing::Real6 transform, std::vector < core::Size > &result );
131 
132  /// @brief Append to a bucket of vectors in the appropriate bin, radial lookup by transform
133  void radial_lookup( core::Size radius, numeric::geometry::hashing::Real6 transform, std::vector < core::Size > &result );
134 
135  /// @brief count hits in the appropriate bin, radial lookup by transform
137 
138  /// @brief Append to a bucket of vectors in the appropriate bin, lookup by bin index
139  /// Using core::Size instead of boost::uinst64_t
140  void lookup( core::Size index, std::vector < core::Size > &result );
141 
142  /// @brief Returns begin() and end() of backbone_index_map_
143  void bbdb_range( std::pair< BackboneIndexMap::iterator, BackboneIndexMap::iterator > & range );
144 
145  /// @brief Returns a hashmap key given a member of a bucket
146  /// Don't think boost implements this, have to manually look it up
147  boost::uint64_t return_key( core::Size bb_index );
148 
149  /// @brief Query the loopsize of this LoopHashMap
150  inline core::Size get_loop_size() const { return loop_size_; }
151 
152  /// @brief Reads legacy binary dbs
154 
155  /// @brief Basic IO functionality - allows reading and writing text states to/from disk
156  void write_db( std::string filename );
157 
158  /// @brief Basic IO functionality - allows reading and writing text states to/from disk
159  void read_db( std::string filename, std::pair< core::Size, core::Size > loopdb_range,
160  std::map< core::Size, bool > & homolog_index );
161  // hack to set loopdb_range default value
162  inline void read_db( std::string filename ) {
163  std::pair< core::Size, core::Size > range( 0, 0 );
164  std::map< core::Size, bool > homolog_index;
165  read_db( filename, range, homolog_index );
166  }
167 
168  /// @brief Return the memory usage of this class
169  void mem_foot_print();
170 
171  /// @brief Sorts the loopdb_ by leap_index.index
172  void sort();
173 
174  private: // Private data
175 
176  /// @brief A class that will take a 6D rigid body transform and turn it into a serial hashbin
177  /// number for hashing. THis is the actual hash so to speak.
178  numeric::geometry::hashing::SixDCoordinateBinnerOP hash_;
179 
180  /// @brief The actual Boost-based hashmap
182 
183  /// @brief List of LeadIndexes
184  std::vector< LeapIndex> loopdb_;
185 
186  /// @brief The length of the the loops in number of residues
188 
189  /// @brief A functor for sort()
190  struct by_index {
191  bool operator()( LeapIndex const &a, LeapIndex const &b ) const {
192  return a.index < b.index;
193  }
194  };
195 
196 
197 };
198 
199 
200 
201 
202 } // namespace loops
203 } // namespace protocols
204 
205 
206 
207 #endif
208 
209