Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BuildManager.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/forge/build/BuildManager.hh
11 /// @brief a container for managing BuildInstructions
12 /// @author Yih-En Andrew Ban (yab@u.washington.edu)
13 
14 #ifndef INCLUDED_protocols_forge_build_BuildManager_hh
15 #define INCLUDED_protocols_forge_build_BuildManager_hh
16 
17 // unit headers
19 
20 // package headers
21 #include <core/types.hh>
24 
25 #if defined(WIN_PYROSETTA) || defined(WIN32)
27 #endif
28 
29 // project headers
31 #include <core/pose/Pose.fwd.hh>
33 
34 // utility headers
35 // AUTO-REMOVED #include <utility/vector1.hh>
36 #include <utility/pointer/ReferenceCount.hh>
37 
38 // C++ headers
39 #include <map>
40 #include <set>
41 // AUTO-REMOVED #include <string>
42 
43 #include <utility/vector1.hh>
44 
45 
46 
47 namespace protocols {
48 namespace forge {
49 namespace build {
50 
51 
52 /// @brief a container for managing BuildInstructions
53 /// @note Compatibility checks wrt dependencies currently do not exist.
54 /// It remains to be seen how to handle this.
56 
57 
58 private: // typedefs
59 
60 
62 
63 
64 public: // typedefs
65 
66 
67  typedef core::Size Size;
71 
75 
77  typedef BuildInstructionOPs::iterator BIOPIterator;
78  typedef BuildInstructionOPs::const_iterator BIOPConstIterator;
79  typedef std::pair< Size, Size > DependencyEdge;
81  typedef std::set< Size > Positions;
82  typedef std::map< Size, Size > Original2Modified;
83  typedef std::map< Size, Size > Modified2Original;
84  typedef std::map< Interval, Positions > Interval2Positions;
85  typedef std::map< Interval, Interval > Interval2Interval;
86  typedef std::map< Interval, MoveMap > Interval2MoveMap;
87 
89 
90 
91 public: // construct/destruct
92 
93 
94  /// @brief default constructor
95  BuildManager();
96 
97 
98  /// @brief copy constructor
99  BuildManager( BuildManager const & rval );
100 
101 
102  /// @brief default destructor
103  virtual
104  ~BuildManager();
105 
106 
107 public: // assignment
108 
109 
110  /// @brief copy assignment
111  BuildManager & operator =( BuildManager const & rval );
112 
113 
114 public: // virtual constructors
115 
116 
117  /// @brief clone this object
118  virtual
119  BuildManagerOP clone() const;
120 
121 
122  /// @brief create a new instance of this type of object
123  virtual
124  BuildManagerOP create() const;
125 
126 
127 public: // mutators
128 
129 
130  /// @brief reset all accounting info (intervals, positions, etc) to initial
131  /// state
132  void reset_accounting();
133 
134 
135 public: // instruction interface
136 
137 
138  /// @brief add an instruction directly (no copy)
139  void add( BuildInstructionOP bi );
140 
141 
142  /// @brief clear all instructions
143  void clear();
144 
145 
146  /// @brief current number of instructions
147  inline
148  Size size() const {
149  return instructions_.size();
150  }
151 
152 
153  /// @brief no instructions?
154  inline
155  bool empty() const {
156  return instructions_.empty();
157  }
158 
159 
160  /// @brief const iterator pointing to the first instruction
161  inline
163  return instructions_.begin();
164  }
165 
166 
167  /// @brief const iterator pointing just beyond the last instruction
168  inline
170  return instructions_.end();
171  }
172 
173 
174 public: // instruction dependency interface
175 
176 
177  /// @brief create a directed dependency: instruction 'u' must complete
178  /// before instruction 'v' can complete, i.e. 'v' depends on 'u'
180 
181 
182  /// @brief the number of dependencies currently defined (i.e. # of edges in
183  /// the dependency graph)
184  inline
186  return instruction_dependencies_.size();
187  }
188 
189 
190  /// @brief have dependencies been defined?
191  inline
192  bool dependencies_exist() const {
193  return !instruction_dependencies_.empty();
194  }
195 
196 
197  /// @brief clear all dependencies
198  /// @return number of dependencies dropped
200 
201 
202 public: // pose modification interface
203 
204 
205  /// @brief modify the pose using the instructions in this container
206  /// @param[in,out] pose the Pose to modify
207  /// @return a map translating original residue -> modified residue for
208  /// positions that existed within both the original Pose and modified Pose
209  Original2Modified modify( Pose & pose );
210 
211 
212  /// @brief a dry run of modify() with an all-ala helical Pose of the given
213  /// length
214  /// @param[in] nres The length of the dummy structure to use.
215  /// @return The final length of the modified Pose.
216  /// @remarks Use this to do a fake run of modify() if you need any
217  /// position or mapping information prior to actually calling modify().
218  Size dummy_modify( Size const nres );
219 
220 
221  /// @brief check if instruction regions are compatible with each other
222  /// @return true if regions compatible, false if regions incompatible
223  bool compatibility_check() const;
224 
225 
226 public: // movemap
227 
228 
229  /// @brief return the combined movemap from all instructions in this manager
230  /// @return If modify() has not been called will return an empty MoveMap.
231  MoveMap movemap() const;
232 
233  MoveMapOP movemap_as_OP() const;
234 
235 
236 public: // mapping
237 
238 
239  /// @brief SequenceMapping consistent with the original -> modified mapping from the
240  /// most recent modify() call
241  /// @return valid Sequence mapping if modify() was called; otherwise returns
242  /// NULL
243  /// @remarks This mapping contains the same information as original2modified()
244  /// combined with original2modified_interval_endpoints().
246 
247 
248  /// @brief return a map translating original residue -> modified residue for
249  /// positions that existed within both the original Pose and modified Pose
250  /// @return map; empty if modify() has not yet been called
251  Original2Modified const & original2modified() const;
252 
253 
254  /// @brief return a map translating original intervals to modified intervals
255  /// @remarks modified intervals with no equivalent original interval (e.g. cases
256  /// such as insertions) will not appear in this map
257  /// @return map; empty if modify() has not yet been called
259 
260 
261  /// @brief return a map translating original interval endpoints to modified
262  /// interval endpoints
263  /// @remarks modified intervals with no equivalent original interval (e.g. cases
264  /// such as insertions) will not appear in this map
265  /// @return map; empty if modify() has not yet been called
267 
268 
269  /// @brief return a map translating modified intervals to original intervals
270  /// @remarks modified intervals with no equivalent original interval (e.g. cases
271  /// such as insertions) will not appear in this map
272  /// @return map; empty if modify() has not yet been called
274 
275 
276  /// @brief return a map translating modified interval endpoints to original
277  /// interval endpoints
278  /// @remarks modified intervals with no equivalent original interval (e.g. cases
279  /// such as insertions) will not appear in this map
280  /// @return map; empty if modify() has not yet been called
282 
283 
284 public: // intervals in the newly modified Pose
285 
286 
287  /// @brief return all modified intervals
288  /// @remarks Since this encompasses everything this is typically not useful
289  /// except for overall tracking purposes.
290  /// @return If modify() has not been called will return an empty set.
291  std::set< Interval > intervals() const;
292 
293 
294  /// @brief return modified intervals that have no equivalent original interval
295  /// in their BuildInstructions (original_interval_valid() = false)
296  /// @remarks This is for cases such as insertions where there
297  /// is no equivalent original region.
298  /// @return If modify() has not been called will return an empty set.
299  std::set< Interval > intervals_without_valid_original_equivalents() const;
300 
301 
302  /// @brief return all intervals containing positions that were pre-existing
303  /// in the original Pose prior to calling modify()
304  /// @return If modify() has not been called will return an empty set.
305  std::set< Interval > intervals_containing_preexisting_positions() const;
306 
307 
308  /// @brief return all intervals containing positions that are "new" and did
309  /// not exist in the original Pose
310  /// @return If modify() has not been called will return an empty set.
311  std::set< Interval > intervals_containing_new_positions() const;
312 
313 
314  /// @brief return all intervals containing positions with defined conformation
315  /// @return If modify() has not been called will return an empty set.
316  std::set< Interval > intervals_containing_defined_positions() const;
317 
318 
319  /// @brief return all intervals containing positions with undefined conformation
320  /// @remarks typically used to define intervals appropriate for loop modeling
321  /// @return If modify() has not been called will return an empty set.
322  std::set< Interval > intervals_containing_undefined_positions() const;
323 
324 
325 public: // original intervals in the original Pose
326 
327 
328  /// @brief return all original intervals containing positions that will
329  /// be kept by the BuildInstructions
330  /// @remarks returns valid data even without calling modify()
331  std::set< Interval > original_intervals_containing_kept_positions() const;
332 
333 
334  /// @brief return all original intervals containing positions that will
335  /// be deleted by the BuildInstructions
336  /// @remarks returns valid data even without calling modify()
337  std::set< Interval > original_intervals_containing_deleted_positions() const;
338 
339 
340 public: // positions in the newly modified Pose
341 
342 
343  /// @brief return all positions within the modified intervals
344  /// @remarks Since this encompasses everything this is typically not useful
345  /// except for overall tracking purposes.
346  /// @return If modify() has not been called will return an empty set.
347  Positions positions() const;
348 
349 
350  /// @brief return the set of positions within the new regions that were
351  /// pre-existing in the original Pose prior to calling modify()
352  /// @return If modify() has not been called will return an empty set.
354 
355 
356  /// @brief return a copy of the set of positions that are "new" and did
357  /// not exist in the original Pose.
358  /// @return If modify() has not been called will return an empty set.
359  Positions new_positions() const;
360 
361 
362  /// @brief return a copy of the set of positions within the newly modified
363  /// regions that have a defined conformation. E.g. existing or copied residues.
364  /// @return If modify() has not been called will return an empty set.
366 
367 
368  /// @brief return a copy of the set of positions within the newly modified
369  /// regions that have an undefined conformation. E.g. newly created residues.
370  /// @return If modify() has not been called will return an empty set.
372 
373 
374  /// @brief the positions representing the union of all intervals containing
375  /// positions with undefined conformation
376  /// @remarks Useful as a reference for defining neighborhoods around
377  /// loop modeled regions.
378  /// @return If modify() has not been called will return an empty set.
380 
381 
382 public: // positions in the original unmodified Pose
383 
384 
385  /// @brief return the set of positions within the original intervals that
386  /// will be kept by the BuildInstructions
387  /// @remarks returns valid data even without calling modify()
389 
390 
391  /// @brief return set of positions within the original intervals that will
392  /// be deleted by the BuildInstructions
393  /// @remarks returns valid data even without calling modify()
395 
396 
397 public: // map modified intervals to position information
398 
399 
400  /// @brief return a map from modified intervals to the set of pre-existing
401  /// positions inside them
402  /// @return If modify() has not been called will return an empty map.
404 
405 
406  /// @brief return a map from modified intervals to the set of "new"
407  /// positions inside them that were not present in the original Pose
408  /// @return If modify() has not been called will return an empty map.
410 
411 
412  /// @brief return a map from modified intervals to the set of
413  /// positions inside them that have defined conformation
414  /// @return If modify() has not been called will return an empty map.
416 
417 
418  /// @brief return a map from modified intervals to the set of
419  /// positions inside them that have undefined conformation
420  /// @return If modify() has not been called will return an empty map.
422 
423 
424  /// @brief return a map from modified intervals to their individual movemaps
425  /// @return If modify() has not been called will return an empty map.
427 
428 
429 public: // map original intervals to original position information
430 
431 
432  /// @brief return a map from original intervals to the set of positions
433  /// inside them that will be kept by the BuildInstructions
434  /// @remarks returns valid data even without calling modify()
436 
437 
438  /// @brief return a map from original intervals to the set of positions
439  /// inside them that will be deleted by the BuildInstructions
440  /// @remarks returns valid data even without calling modify()
442 
443 
444 private: // instruction handling
445 
446 
447  /// @brief find the given instruction
448  /// @return iterator pointing to the BuildInstructionOP if found, otherwise
449  /// the 'end' iterator
451 
452 
453  /// @brief find the given instruction
454  /// @return iterator pointing to the BuildInstructionCOP if found, otherwise
455  /// the 'end' iterator
457 
458 
459 private: // dependency handling
460 
461 
462  /// @brief find the given dependency
463  /// @return iterator pointing to the DependencyEdge if found, otherwise the
464  /// 'end' iterator
465  DependencyEdges::iterator find_dependency( BuildInstructionCOP u, BuildInstructionCOP v );
466 
467 
468  /// @brief find the given dependency
469  /// @return const iterator pointing to the DependencyEdge if found, otherwise the
470  /// 'end' const iterator
471  DependencyEdges::const_iterator find_dependency( BuildInstructionCOP u, BuildInstructionCOP v ) const;
472 
473 
474  /// @brief clear the current dependency list and reconstruct the dependencies
475  /// using the given list
476  void reconstruct_dependencies( DependencyEdges const & dependency_list );
477 
478 
479 private: // data
480 
481 
482  /// @brief the list of BuildInstructions to apply
484 
485 
486  /// @brief list recording BuildInstruction inter-dependencies by index into
487  /// instructions_ array
488  /// @remarks For each pair "first,second" in the list, the instruction with
489  /// index "first" must complete before the instruction with index "second"
490  /// I.e. "second" depends on "first".
492 
493 
494  /// @brief map translation old residue -> new residue for
495  /// non-modified regions only
496  /// @remarks only filled in after modify() called
498 
499 
500  /// @brief SequenceMapping consistent with the old -> new mapping from the
501  /// most recent modify() call
503 
504 
505  /// @brief indicates modify() has been called and succeeded
507 
508 
509 };
510 
511 
512 } // namespace build
513 } // namespace forge
514 } // namespace protocols
515 
516 
517 #endif /* INCLUDED_protocols_forge_build_BuildManager_HH */