Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SegmentSwap.cc
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/SegmentSwap.cc
11 /// @brief instruction to swap a segment with an external segment
12 /// @author Yih-En Andrew Ban (yab@u.washington.edu)
13 
14 // unit headers
16 
17 // package headers
20 
21 // project headers
22 
26 #include <core/pose/PDBInfo.hh>
27 
29 #include <utility/vector1.hh>
30 
31 
32 
33 namespace protocols {
34 namespace forge {
35 namespace build {
36 
37 
38 /// @brief default constructor
40  Super( Interval( 0, 0 ) ),
41  interval_( 0, 0 )
42 {}
43 
44 
45 /// @brief constructor
46 /// @param[in] interval swap out this range of residues
47 /// @param[in] move_map fixed backbone residues in this movemap will be used for new jumps
48 /// @param[in] swap_in swap in this pose
49 /// @remarks Procedure will attempt to honor the movemap as much as it can.
50 /// The caveat is that sequences of calls to some FoldTree routines may shift
51 /// the jumps internally in a way that is not easily predictable. If the
52 /// procedure cannot find an allowed residue for a jump, it will make a jump
53 /// to the (lower) median residue in the disconnected fold tree interval.
55  Interval const & i,
56  MoveMap const & swap_in_movemap,
57  Pose const & swap_in
58 ) :
59  Super( i, &swap_in.residue( 1 ).residue_type_set() ),
60  interval_( i ),
61  swap_in_movemap_( swap_in_movemap ),
62  swap_in_( swap_in )
63 {
64  init();
65 }
66 
67 
68 /// @brief copy constructor
70  Super( rval ),
71  interval_( rval.interval_ ),
72  swap_in_movemap_( rval.swap_in_movemap_ ),
73  swap_in_( rval.swap_in_ )
74 {}
75 
76 
77 /// @brief default destructor
79 
80 
81 /// @brief copy assignment
83  if ( this != &rval ) {
84  Super::operator =( rval );
85 
86  interval_ = rval.interval_;
88  swap_in_ = rval.swap_in_;
89  }
90  return *this;
91 }
92 
93 
94 /// @brief clone this object
96  return new SegmentSwap( *this );
97 }
98 
99 
100 /// @brief fixed backbone residues in this movemap will be used for new jumps
101 /// @remarks Procedure will attempt to honor this movemap as much as it can.
102 /// The caveat is that sequences of calls to some FoldTree routines may shift
103 /// the jumps internally in a way that is not easily predictable. If the
104 /// procedure cannot find an allowed residue for a jump, it will make a jump
105 /// to the (lower) median residue in the disconnected fold tree interval.
107  return swap_in_movemap_;
108 }
109 
110 
111 /// @brief the pose to swap in
113  return swap_in_;
114 }
115 
116 
117 /// @brief a copy of the working range of residues specifying the swapped region
118 /// @details This residue range can change wrt length changes in Pose /Conformation
119 /// being watched.
121  return interval_;
122 }
123 
124 
125 /// @brief return a copy of the set of positions within the new region
126 /// that were pre-existing in the original Pose prior to modify()
127 /// @return An empty set -- no positions are pre-existing.
129  return Positions();
130 }
131 
132 
133 /// @brief return a copy of the set of positions that are "new" and did
134 /// not exist in the original Pose.
135 /// @return A set of positions spanning the interval -- all positions are
136 /// are defined.
139 
140  Interval const ival = interval();
141  return closed_range( ival.left, ival.right );
142 }
143 
144 
145 /// @brief return a copy of the set of positions within the newly modified
146 /// region that has a defined conformation. E.g. existing or copied residues.
147 /// @return A set of positions spanning the interval -- all positions are
148 /// are defined.
149 /// @details This set can change wrt length changes in Pose/Conformation being
150 /// watched.
152  // for SegmentSwap this is the same as the new positions
153  return new_positions();
154 }
155 
156 
157 /// @brief return a copy of the set of positions within the newly modified
158 /// region that has an undefined conformation. E.g. newly created residues.
159 /// @return An empty set -- no undefined positions.
160 /// @details This set can change wrt length changes in Pose/Conformation being
161 /// watched.
163  return Positions();
164 }
165 
166 
167 /// @brief return a copy of the MoveMap that defines the moveable/fixed
168 /// positions/dofs for this instruction
169 /// @return a MoveMap with [interval.left, interval.right] bb set to false
170 /// at the MoveMapTorsionID level
171 /// @details This set can change wrt length changes in Pose/Conformation being
172 /// watched.
174  MoveMap mm;
175 
176  Positions const newp = new_positions();
177  for ( Positions::const_iterator i = newp.begin(), ie = newp.end(); i != ie; ++i ) {
178  mm.set_bb( *i, false );
179  }
180 
181  return mm;
182 }
183 
184 
185 /// @brief update indexing on residue append
187  if ( event.position < interval_.left ) {
188  //++interval_.left;
189  interval_.left += event.length_change;
190  }
191 
192  if ( event.position < interval_.right ) {
193  ++interval_.right;
194  //interval_.right += event.length_change;
195  }
196 }
197 
198 
199 /// @brief update indexing on residue prepend
201  if ( event.position <= interval_.left ) {
202  //++interval_.left;
203  interval_.left += event.length_change;
204  }
205 
206  if ( event.position <= interval_.right ) {
207  //++interval_.right;
208  interval_.right += event.length_change;
209  }
210 }
211 
212 
213 /// @brief update indexing on residue delete
215  if ( event.position < interval_.left ) { // left
216  //--interval_.left;
217  if( int(interval_.left) + event.length_change < int(event.position) ) interval_.left = event.position;
218  else interval_.left += event.length_change;
219  }
220 
221  if ( event.position < interval_.right ) { // right
222  //--interval_.right;
223  if( int(interval_.right) + event.length_change < int(event.position) ) interval_.right = event.position;
224  else interval_.right += event.length_change;
225  }
226 }
227 
228 
229 /// @brief return the set of positions within the original interval that
230 /// will be kept in this BuildInstruction
231 /// @return An empty set -- no positions are kept.
233  return Positions();
234 }
235 
236 
237 /// @brief return set of positions within the original interval that will
238 /// be deleted in this BuildInstruction
239 /// @return An empty set -- no positions are deleted.
243  // return Positions();
244 }
245 
246 
247 /// @brief return set of any fixed positions necessary with respect to the original
248 /// interval and original Pose numbering
249 /// @remarks Used for ensuring build regions for instructions do not overlap and
250 /// so that jumps may be placed correctly.
251 /// @return empty set if no fixed positions necessary
253  Positions fixed;
254  return fixed;
255 }
256 
257 
258 /// @brief return set of any mutable positions necessary with respect to the original
259 /// interval and original Pose numbering
260 /// @remarks Used for ensuring build regions for instructions do not overlap and
261 /// so that jumps may be placed correctly.
265 }
266 
267 
268 /// @brief do the actual work of modifying the Pose
271  using core::pose::PDBInfo;
273 
274  // save interim FoldTree for passing into replace() later
275  FoldTree old_ft = pose.fold_tree();
276 
277  // BEGIN INTERVAL SHIFT: after this point, interval_ will begin to shift due to length
278  // changes in the Pose
279 
280  // Blow away the old segment. delete_residue_range_slow() should keep
281  // all coordinates intact, though the bond lengths/angles adjacent to
282  // the deletion might get funky.
284  assert( interval_.left == interval_.right );
285 
286  assert( interval_.left > 1 ); // conformation does not appear to handle certain modifications at 1
287 
288  // set temporary fold tree with cut introduced so we can insert residues
289  // by jump
290  FoldTree tmp_ft = pose.fold_tree();
291  tmp_ft.new_jump( interval_.left - 1, interval_.left, interval_.left - 1 );
292  pose.fold_tree( tmp_ft );
293 
294  // temporarily shift interval_.left back by one so it sits just prior
295  // to modification region and append modifications below won't affect it
296  --interval_.left;
297 
298  // Swap the entire swap_in_ Pose by jump.
299  Size append_pos = interval_.left + 1;
300  for ( Size i = 1, ie = swap_in_.n_residue(); i <= ie; ++i ) {
301  // temporarily add via jump from interval_.left
302  pose.insert_residue_by_jump( swap_in_.residue( i ), append_pos, interval_.left, "", "" );
303  ++append_pos;
304  }
305 
306  assert( append_pos == interval_.right );
307  assert( append_pos == interval_.left + swap_in_.n_residue() + 1 );
308 
309  // correct interval_;
310  ++interval_.left;
311  --interval_.right;
312 
313  // END INTERVAL SHIFT: after this point, interval_ has stabilized and stores
314  // the new endpoints of the rebuilt segment
315 
316  assert( ( interval_.right - interval_.left + 1 ) == swap_in_.n_residue() );
317 
318  // construct fold tree
319  FoldTree new_ft = replace( old_ft, original_interval().left, original_interval().right,
321 
322  // set proper topology
323  pose.fold_tree( new_ft );
324 
325  // copy secstruct
326  for ( Size i = interval_.left, j = 1; i <= interval_.right; ++i, ++j ) {
327  pose.set_secstruct( i, swap_in_.secstruct( j ) );
328  }
329 
330  // copy pdb info if it exists; PDBInfo should always be
331  // obsolete after leaving modify_impl()
332  if ( swap_in_.pdb_info().get() != NULL ) {
333 
334  if ( pose.pdb_info().get() == NULL ) {
335  pose.pdb_info( new PDBInfo( pose ) );
336  }
337 
338  // force obsolete
339  pose.pdb_info()->obsolete( true );
340 
341  // copy
342  pose.pdb_info()->copy( *swap_in_.pdb_info(), 1, swap_in_.n_residue(), interval_.left );
343  }
344 }
345 
346 
347 /// @brief do the actual reset of intervals, positions, etc to initial state
350 }
351 
352 
353 /// @brief init to be called during non-default constructors
357 
358  // remove lower/upper terminus only at 1, nres
359  if ( swap_in_.n_residue() > 0 ) {
360  if ( swap_in_.residue( 1 ).is_lower_terminus() ) {
362  }
363 
364  if ( swap_in_.residue( swap_in_.n_residue() ).is_upper_terminus() ) {
366  }
367  }
368 }
369 
370 
371 
372 } // namespace build
373 } // namespace forge
374 } // namespace protocols