Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fold_tree_functions.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/methods/fold_tree_functions.hh
11 /// @brief methods for manipulating FoldTrees
12 /// @author Yih-En Andrew Ban (yab@u.washington.edu)
13 
14 #ifndef INCLUDED_protocols_forge_methods_fold_tree_functions_hh
15 #define INCLUDED_protocols_forge_methods_fold_tree_functions_hh
16 
17 // type headers
18 #include <core/types.hh>
19 
20 // project headers
21 #include <core/kinematics/Edge.hh>
23 // AUTO-REMOVED #include <protocols/loops/Loops.hh>
25 #include <core/pose/Pose.fwd.hh>
26 
27 // utility headers
28 // AUTO-REMOVED #include <utility/vector1.hh>
29 
30 // C++ headers
31 #include <string>
32 
34 #include <utility/vector1.hh>
35 
36 
37 
38 namespace protocols {
39 namespace forge {
40 namespace methods {
41 
42 
43 /// @brief enforce Edge has start <= stop (swap if necessary)
44 /// @return true if start and stop were swapped
45 bool order( core::kinematics::Edge & e );
46 
47 
48 /// @brief add a set of Edges to a FoldTree
49 /// @param[in] begin iterator pointing to the first edge to add
50 /// @param[in] end iterator pointing just past the last edge to add
51 /// @param[out ft the FoldTree to modify
52 template< typename EdgeIterator >
53 void
55  EdgeIterator begin,
56  EdgeIterator end,
58 )
59 {
60  for ( EdgeIterator e = begin; e != end; ++e ) {
61  ft.add_edge( *e );
62  }
63 }
64 
65 
66 /// @brief find regular facet (non-jump edge sans face vertices) that contains given position
67 /// @param[in] pos position
68 /// @param[in] begin iterator pointing to the first edge to search
69 /// @param[in] end iterator pointing just past the last edge to search
70 /// @return iterator pointing to the Edge defining the facet that contains the
71 /// position; if vertex lies on the face of an edge or vertex not found, returns
72 /// 'end'
73 template< typename EdgeIterator >
74 EdgeIterator
76  core::Size const pos,
77  EdgeIterator const begin,
78  EdgeIterator const end
79 )
80 {
81  using core::Size;
83 
84  for ( EdgeIterator e = begin; e != end; ++e ) {
85  if ( e->label() < 0 ) {
86 
87  if ( ( static_cast< Size >( e->start() ) < pos && pos < static_cast< Size >( e->stop() ) ) ||
88  ( static_cast< Size >( e->start() ) > pos && pos > static_cast< Size >( e->stop() ) ) ) {
89  return e;
90  }
91 
92  }
93  }
94 
95  return end;
96 }
97 
98 
99 /// @brief add a vertex, splitting edges if necessary
100 /// @param[in] v the vertex to add
101 /// @param[in,out] edges the list of edges to modify
102 /// @return true if vertex was added and an edge was split, false otherwise
103 template< typename EdgeList >
104 bool
106  core::Size const v,
107  EdgeList & edges
108 )
109 {
111 
112  // attempt to find the facet
113  typename EdgeList::iterator f = regular_facet_containing_position(
114  v,
115  edges.begin(),
116  edges.end()
117  );
118 
119  // if the facet exists, it needs to be split
120  if ( f != edges.end() ) {
121  Edge left = *f;
122  Edge right = *f;
123 
124  order( left );
125  order( right );
126 
127  left.stop() = v;
128  right.start() = v;
129 
130  edges.erase( f );
131 
132  edges.push_back( left );
133  edges.push_back( right );
134 
135  return true;
136  }
137 
138  return false;
139 }
140 
141 
142 /// @brief find the k'th closest larger peptide vertex of given vertex in fold tree
143 /// @param[in] v the given vertex
144 /// @param[in] ft fold tree to search
145 /// @param[in] k find the k'th closest, must be > 0
146 /// @return 0 if no such vertex
149  core::Size const v,
150  core::kinematics::FoldTree const & ft,
151  core::Size const k = 1
152 );
153 
154 
155 /// @brief find the k'th closest smaller peptide vertex of given vertex in fold tree
156 /// @param[in] v the given vertex
157 /// @param[in] ft fold tree to search
158 /// @param[in] k find the k'th closest, must be > 0
159 /// @return 0 if no such vertex
162  core::Size const v,
163  core::kinematics::FoldTree const & ft,
164  core::Size const k = 1
165 );
166 
167 
168 /// @brief query if vertex already exists in fold tree
169 bool
171  core::Size const v,
172  core::kinematics::FoldTree const & ft
173 );
174 
175 
176 /// @brief find facet (edge sans face vertices) that contains given position
177 /// @param[in] pos position
178 /// @param[in] begin iterator pointing to the first edge to search
179 /// @param[in] end iterator pointing just past the last edge to search
180 /// @param[in] label the types of Edge to search, default PEPTIDE
181 /// @return iterator pointing to the Edge defining the facet that contains the
182 /// position; if vertex lies on the face of an edge or vertex not found, returns
183 /// 'end'
184 template< typename EdgeIterator >
185 EdgeIterator
187  core::Size const pos,
188  EdgeIterator const begin,
189  EdgeIterator const end,
190  int const label = core::kinematics::Edge::PEPTIDE
191 )
192 {
193  using core::Size;
195 
196  for ( EdgeIterator e = begin; e != end; ++e ) {
197  if ( e->label() == label ) {
198 
199  if ( ( static_cast< Size >( e->start() ) < pos && pos < static_cast< Size >( e->stop() ) ) ||
200  ( static_cast< Size >( e->start() ) > pos && pos > static_cast< Size >( e->stop() ) ) ) {
201  return e;
202  }
203 
204  }
205  }
206 
207  return end;
208 }
209 
210 
211 /// @brief find regular (non-jump) edges contained within the interval [left, right]
212 template< typename EdgeIterator >
215  core::Size const left,
216  core::Size const right,
217  EdgeIterator const begin,
218  EdgeIterator const end
219 )
220 {
221  using core::Size;
223 
224  utility::vector1< Edge > regular_edges;
225  for ( EdgeIterator e = begin; e != end; ++e ) {
226  if ( e->label() < 0 ) {
227 
228  Edge tmp( *e );
229  order( tmp );
230 
231  if ( !( right < static_cast< Size >( tmp.start() ) || static_cast< Size >( tmp.stop() ) < left ) ) {
232  regular_edges.push_back( *e );
233  }
234 
235  }
236  }
237 
238  return regular_edges;
239 }
240 
241 
242 /// @brief find specific type of edges contained within the interval [left, right]
243 template< typename EdgeIterator >
246  core::Size const left,
247  core::Size const right,
248  int const edge_type,
249  EdgeIterator const begin,
250  EdgeIterator const end
251 )
252 {
253  using core::Size;
255 
256  utility::vector1< Edge > collected_edges;
257  for ( EdgeIterator e = begin; e != end; ++e ) {
258  if ( e->label() == edge_type ) {
259 
260  Edge tmp( *e );
261  order( tmp );
262 
263  if ( !( right < static_cast< Size >( tmp.start() ) || static_cast< Size >( tmp.stop() ) < left ) ) {
264  collected_edges.push_back( *e );
265  }
266 
267  }
268  }
269 
270  return collected_edges;
271 }
272 
273 
274 /// @brief find all jump edges whose start or stop lands on the given position
275 /// @param[in] pos The position.
276 /// @param[in] ft The fold tree.
277 /// @return a list of jump edges
278 /// @remarks jump edges start/stop will be ordered such that 'pos' will always
279 /// be at 'start'.
281  core::Size const pos,
282  core::kinematics::FoldTree const & ft
283 );
284 
285 
286 /// @brief find the jump connecting two continuous segments of a fold tree
287 /// @param[in] u Any vertex on the first segment.
288 /// @param[in] v Any vertex on the second segment.
289 /// @param[in] ft The fold tree to query.
290 /// @return the jump number connecting the two segments, 0 if no such jump
292  core::Size const u,
293  core::Size const v,
294  core::kinematics::FoldTree const & ft
295 );
296 
297 
298 /// @brief remove a cutpoint, merging the two sections that are adjacent to the cut
299 /// @return true if cutpoint removed, false if not a cutpoint
300 bool remove_cutpoint(
301  core::Size const v,
303 );
304 
305 
306 /// @brief seal a fold tree by removing all specified cutpoints
307 /// @param[in] cutpoints Cutpoints to remove.
308 /// @param[in,out] ft The input tree.
309 /// @return A new tree with cutpoints removed and all other topology kept
310 /// constant.
311 void remove_cutpoints(
312  utility::vector1< core::Size > const & cutpoints,
314 );
315 
316 
317 /// @brief attempt to shift jumps in a fold tree based on fixed positions in a MoveMap
318 /// @param[in] ft FoldTree to alter
319 /// @param[in] movemap MoveMap to try and honor
320 /// @return FoldTree with jumps shifted, if possible
321 /// @remarks Procedure will shift a jump position on a continuous segment to a
322 /// randomly selected fixed position on that segment specified by the MoveMap.
323 /// No changes will be made to a jump point if it is contained within a segment
324 /// lacking valid fixed positions. This procedure has the side effect of
325 /// collapsing all jump points to a single point within segments that have
326 /// fixed positions.
329  core::kinematics::FoldTree const & ft,
330  core::kinematics::MoveMap const & mm
331 );
332 
333 
334 /// @brief construct a fold tree from Pose wrt chain endings and residue types
335 /// @remarks Determines edge types from residues (polymer vs non-polymer).
336 /// Each chain will end up as one edge in the fold tree. Jumps will be made
337 /// from the new root to a random fixed backbone residue as specified by the
338 /// movemap. If all residues in a chain are moveable, will choose any random
339 /// residue.
340 /// @param[in] pose Pose.
341 /// @param[in] ft_root Root of the new fold tree.
342 /// @param[in] mm MoveMap used to select jump positions.
343 /// @return fold tree wrt chain endings and residue types
346  core::pose::Pose const & pose,
347  core::Size const ft_root,
348  core::kinematics::MoveMap const & mm
349 );
350 
351 
352 /// @brief merge two fold trees by jump between their roots
353 /// @param[in] left_tree
354 /// @param[in] right_tree
355 /// @return Merged FoldTree with all vertices of right_tree placed to the
356 /// right of vertices in left_tree. Jump labels in right_tree will be
357 /// renumbered += left_tree.num_jump(). New tree is rooted in the same
358 /// place as left_tree.
360 merge(
361  core::kinematics::FoldTree const & left_tree,
362  core::kinematics::FoldTree const & right_tree
363 );
364 
365 
366 /// @brief merge two fold trees connecting by jump via specified positions
367 /// @param[in] left_tree
368 /// @param[in] left_position position on left_tree to connect
369 /// @param[in] right_tree
370 /// @param[in] right_position position on right_tree to connect
371 /// @return Merged FoldTree with all vertices of right_tree placed to the
372 /// right of vertices in left_tree. Jump labels in right_tree will be
373 /// renumbered += left_tree.num_jump(). New tree is rooted in the same
374 /// place as left_tree.
376 merge(
377  core::kinematics::FoldTree const & left_tree,
378  core::Size const left_position,
379  core::kinematics::FoldTree const & right_tree,
380  core::Size const right_position
381 );
382 
383 
384 /// @brief merge two fold trees connecting by jump via specified positions
385 /// @param[in] left_tree
386 /// @param[in] left_position position on left_tree to connect
387 /// @param[in] left_jump_atom Use this atom for the left side of the jump.
388 /// Use empty string to indicate default setting.
389 /// @param[in] right_tree
390 /// @param[in] right_position position on right_tree to connect
391 /// @param[in] right_jump_atom Use this atom for the right set of the jump.
392 /// Use empty string to indicate default setting.
393 /// @param[in] keep_stub_in_residue Attempt to keep generated stubs of the
394 /// jump within their respective residues. default False
395 /// @return Merged FoldTree with all vertices of right_tree placed to the
396 /// right of vertices in left_tree. Jump labels in right_tree will be
397 /// renumbered += left_tree.num_jump(). New tree is rooted in the same
398 /// place as left_tree.
400 merge(
401  core::kinematics::FoldTree const & left_tree,
402  core::Size const left_position,
403  std::string const & left_jump_atom,
404  core::kinematics::FoldTree const & right_tree,
405  core::Size const right_position,
406  std::string const & right_jump_atom,
407  bool const keep_stub_in_residue = false
408 );
409 
410 
411 /// @brief replace a section of one fold tree with another fold tree, connecting by
412 /// jump between their roots
413 /// @param[in] original_tree
414 /// @param[in] replace_begin residue starting the section of original_tree to replace
415 /// @param[in] replace_end residue ending the section of original_tree to replace
416 /// @param[in] movemap MoveMap whose fixed backbone positions dictates where new jumps
417 /// may be placed.
418 /// @param[in] replacement_tree
419 /// @return FoldTree with section replaced.
420 /// @remarks The procedure will attempt to honor the MoveMap as much as it can. The caveat
421 /// is that sequences of calls to some FoldTree routines may shift the jumps internally in
422 /// a way that is not easily predictable. If the procedure cannot find an allowed
423 /// residue for a jump, it will make a jump to the median residue in the disconnected
424 /// fold tree interval.
426 replace(
427  core::kinematics::FoldTree const & original_tree,
428  int const replace_begin,
429  int const replace_end,
430  core::kinematics::MoveMap const & movemap,
431  core::kinematics::FoldTree const & replacement_tree
432 );
433 
435 
436 void jumps_and_cuts_from_pose( core::pose::Pose & pose, utility::vector1< std::pair< core::Size, core::Size > > & jumps, utility::vector1< core::Size > & cuts);
437 
438 
439 
440 } // methods
441 } // forge
442 } // protocols
443 
444 
445 #endif /* INCLUDED_protocols_forge_methods_fold_tree_functions_HH */