Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SecondaryMatcherToUpstreamResidue.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/downstream/SecondaryMatcherToUpstreamResidue.hh
12 /// @brief Class declaration for secondary matcher that generates upstream-only hits
13 /// matching the geometry of one upstream residue with another upstream residue
14 /// generated in a previous round.
15 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
16 /// @author Florian Richter (flosopher@gmail.com)
17 
18 #ifndef INCLUDED_protocols_match_downstream_SecondaryMatcherToUpstreamResidue_hh
19 #define INCLUDED_protocols_match_downstream_SecondaryMatcherToUpstreamResidue_hh
20 
21 // Unit headers
23 
24 // Package headers
27 #include <protocols/match/Hit.hh>
31 
32 // Project headers
33 #include <core/types.hh>
36 
37 // ObjexxFCL headers
38 #include <ObjexxFCL/FArray2D.hh>
39 
40 // Utility headers
41 #include <utility/pointer/ReferenceCount.hh>
42 // AUTO-REMOVED #include <utility/OrderedTuple.hh>
43 
44 // C++ headers
45 #include <list>
46 #include <map>
47 #include <string>
48 
49 #include <core/id/AtomID.hh>
50 #include <utility/OrderedTuple.fwd.hh>
51 #include <utility/vector1.hh>
52 
53 
54 namespace protocols {
55 namespace match {
56 namespace downstream {
57 
58 /// @brief A class for an algorithm. Given a conformation of the upstream partner,
59 /// the algorithm is responsible for producing a set of hits.
61 {
62 public:
64  typedef utility::fixedsizearray1< Size, 2 > Size2;
65  typedef utility::OrderedTuple< Size2 > Size2Tuple;
66  typedef std::pair< SecMatchResiduePairEvaluatorCOP, Size > Evaluator_MCFI_ID_Pair;
67  typedef std::list< Evaluator_MCFI_ID_Pair > EvaluatorSet;
68 
69 public:
71 
73 
74  virtual
76  clone() const;
77 
78  /// @brief Main driver function for hit generation. This DownstreamAlgorithm
79  /// structures it's iteration over the hits from previous rounds as follows:
80  /// for i = 1:n_build_positions
81  /// recover_rotamer_coordinates_from_previous_round( hits_for_build_point_i );
82  /// initialize rotcoord data for all downstream algorithms with the same geom_cst_id
83  /// #omp parallel for /// All class access below this point is const and parallelizable
84  /// for j = 1:n_build_positions
85  /// /// call this function to start k loop: matcher.upstream_builder[ geom_cst_id() ]->build( j )
86  /// for k = 1:n_rotamers_j
87  /// /// call to start l loop: downstream_algorithm->build( j, k, rotamer_k ) )
88  /// for l = 1:n_rotamers_from_build_point_i
89  /// if ( respair_evaluator_->evaluate_residues( rotamer_k, rotamer_l )
90  /// hit_list.append( Hit( j, k, ... ));
91  /// return hit_list
92  /// There are two important consequences to this hit-generation layout.
93  /// 1. The coordinates for rotamer_k are computed n_build_position times.
94  /// 2. Only a single build-position i has it's hit coordinates in memory at any point in time.
95  /// This is a clear trade-off between performance and memory with a few caveats:
96  /// A. It is very easy to bound the volume of space where build-point i's rotamers lie,
97  /// so it should be easy to prune rotamer building, so rotamer k will be build many fewer than
98  /// n_build_position times.
99  /// B. By not trying to store all rotamers in memory at once, we do not impose any undue restrictions
100  /// on the number of rotamers that can be enumerated. This is especially important if we're
101  /// using backbone flexibility to search a wider region of conformation space.
102  virtual
103  std::list< Hit >
105  Matcher & matcher
106  );
107 
108 
109  /// @brief Prune hits away from the target_geomcst's hit list following a change to the
110  /// hits for my geom_cst_id(). Pruning hits from the target_geomcst's hit list will
111  /// trigger a round of peripheral-hitlist-change responses.
112  virtual
113  void
114  respond_to_primary_hitlist_change( Matcher & matcher, Size round_just_completed );
115 
116  /// @brief Remove my hits if my target_geomcst's hit list has been shortened. This
117  /// will not trigger a round of peripheral-hitlist-change responses.
118  virtual
119  void
121 
122 
123  /// @brief Iterate across the hits from a particular upstream build point i
124  /// that were generated in a previous round, and see if the geometry of the
125  /// input upstream_residue has "satisfactory interactions" with the
126  /// hits from upstream-build-point i; if so, it appends a Hit to the hitlist
127  /// returned at the end of the method. (Also, see comments for the
128  /// build_at_all_positions method.)
129  virtual
130  std::list< Hit >
131  build(
132  Size const scaffold_build_point_id,
133  Size const upstream_conf_id,
134  core::conformation::Residue const & upstream_residue
135  ) const;
136 
137  /// @brief returns true; this secondary matcher does not describe the location
138  /// of the downstream partner
139  virtual
140  bool
141  upstream_only() const;
142 
143  /// @brief This method returns 'false' since this matcher does not describe
144  /// the coordinates of the downstream partner at all.
145  virtual
146  bool
147  generates_primary_hits() const;
148 
149 
150  /// @brief Prepare a map between upstream hits of the target-geomcst and
151  /// a list of Hit const *'s of this geom_cst_id(). This map will be used
152  /// in the function hits_to_include_with_partial_match.
153  virtual
154  void
155  prepare_for_match_enumeration( Matcher const & matcher );
156 
157  /// @brief Return the set of hits to be iterated across
158  virtual
161 
162  virtual
163  Size
165 
166  //void
167  //set_match_restype( core::chemical::ResidueTypeCOP match_restype );
168 
169  void
170  set_target_geomcst_id( Size target_geomcst_id );
171 
172  void
174 
175  void
177  core::chemical::ResidueTypeCOP target_restype,
179  Size mcfi_id_for_evaluator
180  );
181 
182  /// @brief Invoked by SecondaryMatchUpstreamResProcessor; avoids multiple inherritance,
183  /// while letting the SecondaryMatcherToUpstreamResidue
184  void
185  process_hit(
186  Hit const & hit,
187  core::conformation::Residue const & upstream_conformation
188  );
189 
190 private:
191 
192  void
194  Matcher & matcher
195  );
196 
197  bool
199  Matcher & matcher,
200  upstream::ScaffoldBuildPoint const & target_build_point
201  );
202 
203  /// @brief Allow another SecondaryMatcherToUpstreamResidue to set my
204  /// TargetRotamerCoords object so that we can share this data.
205  void
206  set_target_rotamer_coords( TargetRotamerCoordsOP target_geomcst_coords );
207 
208  void count_rotamer(
209  core::conformation::Residue const & upstream_conformation
210  );
211 
213  Hit const & hit,
214  core::conformation::Residue const & upstream_conformation
215  );
216 
217  void reorder_restypes(
218  upstream::UpstreamBuilder const & builder
219  );
220 
221 private:
222 
224 
225  /// The id for the geom-cst that this SecondaryMatcher is dependent upon;
226  /// the upstream geometries for residues generated by the target-geometric
227  /// constraint are examined in the build() method.
229 
230  std::map< core::chemical::ResidueTypeCOP, Size > target_restype_index_map_;
233 
234 // std::map < std::string, DownstreamBuilderCOP > dsbuilders_;
235 
243 
246 
247  std::map< Size2Tuple, HitPtrListOP > my_hits_for_target_hit_map_;
248 
250 };
251 
253 {
254 public:
255  typedef core::Size Size;
257 
258 public:
259 
261  virtual ~TargetRotamerCoords();
262 
265  void set_required_atoms( Size restype_index, utility::vector1< bool > const & atom_required );
266 
268  utility::vector1< Size > const & n_rotamers_per_target_restype
269  );
270 
272  Size target_restype_id,
273  Size n_rotamers
274  );
275 
277  Size restype_index,
278  Size rotamer_index,
279  Hit const & hit,
280  core::conformation::Residue const & rescoords
281  );
282 
283  Size
284  n_restypes() const {
285  return target_restypes_.size();
286  }
287 
289  restype( Size restype_index ) const {
290  return target_restypes_[ restype_index ];
291  }
292 
293  Size
294  n_rots_total() const {
295  return n_rots_total_;
296  }
297 
298  Size
299  n_rotamers_for_restype( Size restype_id ) const {
300  return coords_[ restype_id ].size2();
301  }
302 
303  Size
304  n_atoms_for_restype( Size restype_id ) const {
305  return atom_ids_for_coordinates_[ restype_id ].size();
306  }
307 
308  Vector const &
310  Size restype_index,
311  Size rotamer_index,
312  Size which_atom
313  ) const {
314  return coords_[ restype_index ]( which_atom, rotamer_index );
315  }
316 
317  Size
319  Size restype_index,
320  Size which_atom
321  ) const {
322  return atom_ids_for_coordinates_[ restype_index ][ which_atom ];
323  }
324 
325  Hit const &
326  hit (
327  Size restype_index,
328  Size rotamer_index
329  ) const {
330  return hit_data_[ restype_index ][ rotamer_index ];
331  }
332 
333  void
334  set_clash_checking( Size rotamer_index) {
335  build_coords_for_clash_checking_[ rotamer_index ] = true;
336  }
337 
338  bool
339  get_clash_checking( Size rotamer_index) {
340  return build_coords_for_clash_checking_[ rotamer_index ];
341  }
342 
343  void
345  Size rotamer_index,
347  ) {
348  coords_for_clash_checking_[ rotamer_index ].resize( coords.size() );
349  coords_for_clash_checking_[ rotamer_index ] = coords;
350  }
351 
354  Size rotamer_index
355  ) {
356  return coords_for_clash_checking_[ rotamer_index ];
357  }
358 
359  void
361  Size n_rotamers
362  ){
363  build_coords_for_clash_checking_.resize( n_rotamers );
364  coords_for_clash_checking_.resize( n_rotamers );
365  }
366 
367  void
370  ){
371  ds_atom_ids_needed_ = atom_ids;
372  }
373 
376  ){
377  return ds_atom_ids_needed_;
378  }
379 
380 
381 private:
386  // In parallel to the coordinates for each of the target hits, keep the
387  // hit data that we need for later generating hits for the match
388  // first = scaffold_build_id, second = upstream_conf_id;
390 
394 };
395 
396 /// @brief A simple class to respond to the UpstreamBuilder's
397 /// process_hit method and pass on the coordinates to its "owning"
398 /// SecondaryMatcherToUpstreamResidue object.
400 {
401 public:
403 
404 public:
405 
408  );
409 
410  virtual
411  void
412  process_hit(
413  Hit const & hit,
414  core::conformation::Residue const & upstream_conformation
415  );
416 
417 private:
418 
420 
421 };
422 
423 
424 /// @brief A simple struct to use in list.sort() to ensure that the
425 /// hits returned by a secondary matcher which has possibly generated upstream
426 /// hits out-of-order, will return an ordered-hit-list in its
427 /// build_hits_at_all_positions() method.
428 ///
429 /// @details This struct compares the upstream portion of the hits it's returning
430 /// ensuring that the rotamer indices (the upstream_conf_ids()) are in ascending
431 /// order for each scaffold build point.
433 {
434  bool operator () ( Hit const & lhs, Hit const & rhs ) const {
435  if ( lhs.scaffold_build_id() == rhs.scaffold_build_id() ) {
436  return lhs.upstream_conf_id() < rhs.upstream_conf_id();
437  } else {
438  return lhs.scaffold_build_id() < rhs.scaffold_build_id();
439  }
440  }
441 };
442 
443 
444 }
445 }
446 }
447 
448 #endif