Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BackboneDB.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/BackboneDB.hh
11 /// @brief I little in the spirit of fragments but way more memory and speed efficient. Backbones are stored as 16bit fixed comma integers. :)
12 /// @author Mike Tyka
13 /// @author Ken Jung
14 
15 
16 #ifndef INCLUDED_protocols_loophash_BackboneDB_hh
17 #define INCLUDED_protocols_loophash_BackboneDB_hh
18 
19 #include <core/types.hh>
20 #include <core/pose/Pose.fwd.hh>
21 // AUTO-REMOVED #include <boost/cstdint.hpp>
22 #include <boost/unordered_map.hpp>
23 // AUTO-REMOVED #include <protocols/match/Hit.fwd.hh>
24 // AUTO-REMOVED #include <protocols/match/Hit.hh>
25 // AUTO-REMOVED #include <protocols/match/SixDHasher.hh>
26 // AUTO-REMOVED #include <protocols/frag_picker/VallChunk.hh>
27 
28 // AUTO-REMOVED #include <string>
29 #include <vector>
30 #include <map>
31 
33 #include <utility/vector1.hh>
34 #include <numeric/geometry/BoundingBox.fwd.hh>
35 
36 //numeric headers
37 #include <numeric/geometry/hashing/SixDHasher.fwd.hh>
38 
39 
40 namespace protocols {
41 namespace loophash {
42 
43 // surely there's a func like this somewhere ?
44 template <class T>
45 T sqr( T a){ return a*a; }
46 
47 const core::Real MAXIMAL_FLOAT = 100000000.0;
48 
49 typedef boost::unordered_multimap< boost::uint64_t, core::Size , numeric::geometry::hashing::bin_index_hasher > BackboneIndexMap;
50 typedef numeric::geometry::BoundingBox< core::Vector > BoundingBox;
52 
53 short RealAngleToShort( core::Real angle );
54 
55 core::Real ShortToRealAngle( short angle );
56 
57 
58 // Structs for storing data
59 struct BBExtraData{
61  std::vector < int > rotamer_id;
63 };
64 struct BBData {
65  std::vector < short > angles;
67 };
68 
70  public:
72 
74  const std::vector<core::Real> &phi,
75  const std::vector<core::Real> &psi,
76  const std::vector<core::Real> &omega
77  ){
78  phi_ = phi;
79  psi_ = psi;
80  omega_ = omega;
81  }
82 
83  void apply_to_pose( core::pose::Pose &pose, core::Size ir, bool cut = false ) const;
85 
86  void print() const ;
87 
88  core::Size length() const { return phi_.size(); }
89  const std::vector<core::Real> &phi() const { return phi_; }
90  const std::vector<core::Real> &psi() const { return psi_; }
91  const std::vector<core::Real> &omega() const { return omega_; }
92 
93  bool compare(const BackboneSegment &bs1, core::Real tolerance) const;
94 
95  bool operator==( const BackboneSegment &bs1 ) const;
96 
97  bool operator!=(const BackboneSegment &other) const {
98  return !(*this == other);
99  }
100 
101  core::Size get_mem_foot_print(){ return phi_.size() * 3 * sizeof( core::Real ) + sizeof( BackboneSegment ); }
102  private:
103  std::vector<core::Real> phi_;
104  std::vector<core::Real> psi_;
105  std::vector<core::Real> omega_;
106 
107 };
108 
109 core::Real get_rmsd( const BackboneSegment &bs1, const BackboneSegment &bs2 );
110 
111 
112 
113 
115 {
116  public:
117  BackboneDB(){ extra_ = false; }
118 
119  core::Real angle( core::Size index, core::Size offset );
120 
121  // Always grab extra data from Vall
122  void add_pose( const core::pose::Pose &pose, core::Size nres, core::Size &offset, protocols::frag_picker::VallChunkOP chunk = NULL );
123 
124  //obsolete?
125  //void add_backbone_segment( const BackboneSegment &bs, core::Size &offset );
126 
127 
128  void get_protein( core::Size index, BBData & protein ) const;
129  void get_extra_data( core::Size index, BBExtraData & extra ) const;
130  void add_protein( BBData new_protein );
131  void add_extra_data( BBExtraData extra );
132 
134  const core::Size index,
135  const core::Size offset,
136  const core::Size len,
137  BackboneSegment &bs
138  ) const;
139 
140  core::Size size() const { return data_.size(); }
141  core::Size extra_size() const { return extra_data_.size(); }
142 
143  // Only supports writing to text, extra data is mandatory
144  void write_db( std::string filename );
145 
146  // Only supports reading from text, extra data must exist in db, loading is optional
147  // Returns a range of keys of which protein is read
148  // also returns a map of homolog indices
149  void read_db( std::string filename, bool load_extra,
150  core::Size num_partitions, core::Size assigned_num,
151  std::pair< core::Size, core::Size > & loop_range,
152  std::map< core::Size, bool > & homolog_index );
153  // Hack to give a default parameter to loop_range
154  inline void read_db( std::string filename, bool load_extra ) {
155  std::pair< core::Size, core::Size > range;
156  std::map < core::Size, bool > homolog_index;
157  read_db( filename, load_extra, 1, 0, range, homolog_index );
158  }
159 
160  // For backwards compatability
162 
163  // Reads in homologs into homologs_
164  void read_homologs();
165 
166  core::Size get_mem_foot_print(){ return data_.size() * sizeof( BBData ) + data_.size() * sizeof( BBExtraData ) + sizeof(BackboneDB); };
167 
168  private:
169 
170  // Gonna change this to a vector of BBData structs, one for each protein
171  // This obviously introduces overhead, but minimal (~2MB), and it makes it easier to store
172  // other info as well as sort the database
173 
174  // Extra info is stored in a separate struct (BBExtraData) with an index in the BBData struct
175 
176  // std::vector < short > data_;
177  std::vector < BBData > data_;
178  std::vector < BBExtraData > extra_data_;
179 
180  // if this flag is true, extra_data_ is populated
181  bool extra_;
182 
183  /// @brief Homology map, contains all homologs
184  std::map< std::string, bool > homologs_;
185 
186 };
187 
188 
189 }
190 }
191 
192 #endif
193