Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BuildManager.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/BuildManager.hh
11 /// @brief a container for managing BuildInstructions
12 /// @author Yih-En Andrew Ban (yab@u.washington.edu)
13 
14 // unit headers
16 
17 // package headers
22 
23 // project headers
24 
26 //testing
32 // AUTO-REMOVED #include <core/conformation/Conformation.hh>
34 
35 #include <basic/options/keys/remodel.OptionKeys.gen.hh>
36 #include <basic/options/option.hh>
37 
38 
39 #include <core/pose/Pose.hh>
40 #include <core/pose/util.hh>
42 #include <basic/Tracer.hh>
43 #ifdef WIN32
44 // apparently this is required for a Visual Studio build.
46 #endif
47 
48 // utility headers
49 #include <utility/exit.hh>
50 
51 // C++ headers
52 #include <algorithm>
53 
55 #include <utility/vector1.hh>
56 
57 
58 
59 
60 namespace protocols {
61 namespace forge {
62 namespace build {
63 
64 
65 // Tracer instance for this file
66 // Named after the original location of this code
67 static basic::Tracer TR( "protocols.forge.build.BuildManager" );
68 
69 
70 /// @brief default constructor
72  Super(),
73  modify_was_successful_( false )
74 {}
75 
76 
77 /// @brief copy constructor
79  Super( rval ),
80  original2modified_( rval.original2modified_ ),
81  seqmap_( rval.seqmap_.get() ? new SequenceMapping( *rval.seqmap_ ) : 0 ),
82  modify_was_successful_( rval.modify_was_successful_ )
83 {
84  // add instructions in the exact same order
85  for ( BIOPConstIterator i = rval.begin(), ie = rval.end(); i != ie; ++i ) {
86  add( *i );
87  }
88 
89  // rebuild the dependencies
91 }
92 
93 
94 /// @brief default destructor
96 
97 
98 /// @brief copy assignment
100  if ( this != &rval ) {
101  Super::operator =( rval );
102 
103  clear(); // clear all instructions
104 
105  // add the instructions in the same order
106  for ( BIOPConstIterator i = rval.begin(), ie = rval.end(); i != ie; ++i ) {
107  add( *i );
108  }
109 
110  // rebuild the dependencies
112 
114  seqmap_ = rval.seqmap_.get() ? new SequenceMapping( *rval.seqmap_ ) : 0;
116  }
117  return *this;
118 }
119 
120 
121 /// @brief clone this object
123  return new BuildManager( *this );
124 }
125 
126 
127 /// @brief create a new instance of this type of object
129  return new BuildManager();
130 }
131 
132 
133 /// @brief reset all accounting info (intervals, positions, etc) to initial
134 /// state
136  for ( BIOPIterator i = instructions_.begin(), ie = instructions_.end(); i != ie; ++i ) {
137  (**i).reset_accounting();
138  }
139  original2modified_.clear();
140  seqmap_.reset_to_null();
141  modify_was_successful_ = false;
142 }
143 
144 
145 /// @brief add an instruction directly (no copy)
147  // A different option is to clone the instruction, which is how it was
148  // originally done prior to the advent of the dependency tracking. Storing
149  // the pointer directly made the initial code for letting the user
150  // construct the dependency graph (BuildManager::create_directed_dependency)
151  // somewhat easier. Consider changing this and how the graph is
152  // tracked/constructed if need be.
153  instructions_.push_back( bi );
154 }
155 
156 
157 /// @brief clear all instructions
159  instructions_.clear();
161 }
162 
163 
164 /// @brief create a directed dependency: instruction 'u' must complete
165 /// before instruction 'v' can complete, i.e. 'v' depends on 'u'
167  // find the index of the instructions in the instructions_ array
168  BIOPIterator u_iter = find_instruction( u );
169  BIOPIterator v_iter = find_instruction( v );
170  runtime_assert( u_iter != instructions_.end() );
171  runtime_assert( v_iter != instructions_.end() );
172 
173  // link the two instructions, safe even if two instructions already linked
174  v->add_dependency_to( u.get() );
175 
176  // add to the edge list
177  instruction_dependencies_.push_back(
178  std::make_pair(
179  std::distance( instructions_.begin(), u_iter ) + 1,
180  std::distance( instructions_.begin(), v_iter ) + 1
181  )
182  );
183 }
184 
185 
186 /// @brief clear all dependencies
187 /// @return number of dependencies dropped
189  Size const n = instruction_dependencies_.size();
190 
191  // clear for each instruction
192  for ( BIOPIterator i = instructions_.begin(), ie = instructions_.end(); i != ie; ++i ) {
193  (**i).clear_dependencies();
194  }
195 
196  // clear the list
198 
199  return n;
200 }
201 
202 
203 /// @brief modify the pose using the instructions in this container
204 /// @param[in,out] pose the Pose to modify
205 /// @return a map translating original residue -> modified residue for
206 /// positions that existed within both the original Pose and modified Pose
208  using namespace protocols::forge::build::BuildInstructionState;
210 
211 //testing
215 using namespace core::conformation;
217 
218  // sanity check
219  if ( !compatibility_check() ) {
220  // full stop
221  utility_exit_with_message( "ERROR: BuildManager::modify() : BuildInstructions incompatible!" );
222  }
223  //special case for two chain build -- danger, primitive at the moment, only
224  //works with non-N,C term extension. Try placing in SegRebuld
225  if (basic::options::option[basic::options::OptionKeys::remodel::two_chain_tree].user()){
226  Size second_start = basic::options::option[basic::options::OptionKeys::remodel::two_chain_tree];
227  Size nres( pose.total_residue());
228 
229  //FoldTree f(pose.fold_tree());
230  FoldTree f;
231  //make cutpoint
232  f.add_edge(1, second_start-1, Edge::PEPTIDE);
233  f.add_edge(second_start, nres, Edge::PEPTIDE);
234  f.add_edge(second_start-1,second_start,1);//jump across the cut
235  //make cutpoint
236  //f.cut_edge(second_start-1);
237  f.reorder(nres);
238  pose.fold_tree(f);
239  //using add_variant_type_to_pose_residue;
242 
243 
244  protocols::loops::Loops chain_def_loops;
245  chain_def_loops.add_loop(protocols::loops::Loop(second_start-1,second_start, second_start-1));
246  //chain_def_loops.add_loop(protocols::loops::Loop(second_start,pose.total_residue()));
247 
248  //add virtual residue, as star foldtree requires it
249  if (pose.residue( pose.total_residue()).aa() != core::chemical::aa_vrt){
251  }
252 
253  //update foldtree to new foldtree
254  f = pose.fold_tree();
255  TR << "before star" << f << std::endl;
256 
257  //update nres to include the new residue
258  nres = pose.total_residue();
259 
260  f.reorder(nres);
261  pose.fold_tree(f);
262  protocols::forge::methods::make_star_foldtree(pose, chain_def_loops);
263  TR << "after star" << pose.fold_tree() << std::endl;
264  }
265 
266 
267 
268 
269  // each call to the Manager's modify() is for a fresh Pose, so reset
270  // the accounting information
272 
273  // store old nres for constructing SequenceMapping
274  Size const old_nres = pose.n_residue();
275 
276  // gather residues of original Pose for mapping purposes
277  Positions old_r = closed_range( Size( 1 ), pose.n_residue() ); // old residues
278 
279  // attach all instructions as length observers and set flag
280  // so detach does not occur after modify
281  for ( BIOPIterator i = instructions_.begin(), ie = instructions_.end(); i != ie; ++i ) {
282  (**i).attach_to( pose );
283  (**i).detach_after_modify( false );
284  }
285 
286  // Now perform all instructions; note that modify() will automatically
287  // re-attach here but that's fine.
288  Size instructions_remaining = instructions_.size();
289  Size instructions_remaining_prior_loop = instructions_remaining; // safeguard against cycles in the dependency topology
290  BIOPIterator iii = instructions_.begin(), iiie = instructions_.end();
291 
292  while ( instructions_remaining > 0 ) {
293 
294  // reset iterator if at the end
295  if ( iii == iiie ) {
296  iii = instructions_.begin();
297 
298  // For now we do the following loop counter check in lieu of actually
299  // checking the topology of the dependency graph for cycles. If the
300  // number of instructions remaining in the current loop is equal to the
301  // number of instructions remaining in the prior loop, there is a problem.
302  if ( instructions_remaining == instructions_remaining_prior_loop ) {
303  TR.Fatal << "FATAL: Infinite loop will occur -- check the topology of the dependency graph and make sure there are no cycles." << std::endl;
304  utility_exit();
305  }
306 
307  instructions_remaining_prior_loop = instructions_remaining;
308  }
309 
310  BuildInstruction & instruction = (**iii);
311 
312  // if instruction has not run yet, call modify()
313  if ( !instruction.modify_was_successful() ) {
314  instruction.modify( pose );
315  TR << pose.fold_tree() << std::endl;
316 
317  // if modify finished successfully, decrement the counter
318  if ( instruction.modify_was_successful() ) {
319  --instructions_remaining;
320  }
321  }
322 
323  // increment iterator
324  ++iii;
325  }
326 
327  // Manually unhook length observers. Also reset detach_after_modify flag
328  // to true as a safety, since we are not necessarily storing clones of the
329  // instructions and we don't want to be inadvertantly causing weird behavior
330  // downstream if the instructions are somehow reused.
331  for ( BIOPIterator i = instructions_.begin(), ie = instructions_.end(); i != ie; ++i ) {
332  (**i).detach_from();
333  (**i).detach_after_modify( true ); // safety
334  }
335 
336  // gather residues of newly modified Pose for mapping purposes
337  Positions new_r = closed_range( Size( 1 ), pose.n_residue() ); // new residues
338 
339  // remove original deleted positions from original residues
340  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
341  BuildInstruction const & bi = **i;
342  Positions const odp = bi.original_deleted_positions();
343 
344  for ( Positions::const_iterator j = odp.begin(), je = odp.end(); j != je; ++j ) {
345  old_r.erase( *j );
346  }
347  }
348 
349  // remove newly created positions from modified residues
350  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
351  BuildInstruction const & bi = **i;
352  Positions const np = bi.new_positions();
353 
354  for ( Positions::const_iterator j = np.begin(), je = np.end(); j != je; ++j ) {
355  new_r.erase( *j );
356  }
357  }
358 
359  runtime_assert( old_r.size() == new_r.size() );
360 
361  // create old -> new map for unmodified regions
362  original2modified_.clear();
363  for ( Positions::const_iterator o = old_r.begin(), n = new_r.begin(), oe = old_r.end(), ne = new_r.end();
364  o != oe && n != ne; ++o, ++n ) {
365  original2modified_[ *o ] = *n;
366  }
367  runtime_assert( original2modified_.size() == old_r.size() && original2modified_.size() == new_r.size() ); // paranoia
368 
369  // flip switch so position mapping functions are turned on
370  modify_was_successful_ = true;
371 
372  /* ALL CODE AFTER THIS POINT MUST OCCUR AFTER modify_was_successful_ IS SET TRUE */
373 
374  // create the new SequenceMapping consisting of oldnew() plus
375  // old2new_region_endpoints() information
376  seqmap_ = new SequenceMapping();
377  for ( Size r = 1; r <= old_nres; ++r ) {
378  Original2Modified::const_iterator i = original2modified_.find( r );
379  if ( i != original2modified_.end() ) {
380  seqmap_->push_back( i->second );
381  } else {
382  seqmap_->push_back( 0 );
383  }
384  }
385 
387  for ( Original2Modified::const_iterator i = o2n_re.begin(), ie = o2n_re.end(); i != ie; ++i ) {
388  (*seqmap_)[ i->first ] = i->second;
389  }
390 
391  return original2modified_;
392 }
393 
394 
395 /// @brief a dry run of modify() with an all-ala helical Pose of the given length
396 /// @param[in] nres The length of the dummy structure to use.
397 /// @return The final length of the modified Pose.
398 /// @remarks Use this to do a fake run of modify() if you need any
399 /// position or mapping information prior to actually calling modify().
402 
403  runtime_assert( !instructions_.empty() );
404 
405  // fake a poly-ala helical dummy pose
406  Pose dummy_pose;
408  dummy_pose,
409  String( nres, 'A' ),
410  ( **instructions_.begin() ).residue_type_set()
411  );
412 
413  for ( core::Size i = 1, ie = dummy_pose.n_residue(); i <= ie; ++i ) {
414  dummy_pose.set_secstruct( i, 'H' );
415  }
416 
417  for ( Size i = 1, ie = dummy_pose.n_residue(); i <= ie; ++i ) {
418  dummy_pose.set_phi( i, -60.0 );
419  dummy_pose.set_psi( i, -45.0 );
420  dummy_pose.set_omega( i, 180.0 );
421  }
422 
423  modify( dummy_pose );
424 
425  return dummy_pose.n_residue();
426 }
427 
428 
429 /// @brief check if instruction regions are compatible with each other
430 /// @return true if regions compatible, false if regions incompatible
432  for ( BIOPConstIterator i = begin(), ie = --end(); i != ie; ++i ) {
433  for ( BIOPConstIterator j = i + 1, je = end(); j != je; ++j ) {
434  if ( !(**i).compatible_with( **j ) ) {
435  return false;
436  }
437  } // foreach j
438  } // foreach i
439 
440  return true;
441 }
442 
443 
444 /// @brief return the combined movemap from all instructions in this manager
446  return *movemap_as_OP();
447 }
448 
450  MoveMapOP combined_mm = new MoveMap();
451 
452  if ( !modify_was_successful_ ) {
453  return combined_mm;
454  }
455 
456  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
457  combined_mm->import( (**i).movemap() );
458  }
459 
460  return combined_mm;
461 }
462 
463 
464 /// @brief SequenceMapping consistent with the original -> modified mapping from the
465 /// most recent modify() call
466 /// @return valid Sequence mapping if modify() was called; otherwise returns
467 /// NULL
468 /// @remarks This mapping contains the same information as original2modified()
469 /// combined with original2modified_interval_endpoints().
471  return seqmap_;
472 }
473 
474 
475 /// @brief return a map translating original residue -> modified residue for
476 /// positions that existed within both the original Pose and modified Pose
477 /// @return map; empty if modify() has not yet been called
479  return original2modified_;
480 }
481 
482 
483 /// @brief return a map translating original intervals to modified intervals
484 /// @remarks modified intervals with no equivalent original intervals (e.g. cases
485 /// such as insertions) will not appear in this map
486 /// @return map; empty if modify() has not yet been called
488  Interval2Interval o2m;
489 
490  // if modify() not called, the mapping is unknown
491  if ( !modify_was_successful_ ) {
492  return o2m;
493  }
494 
495  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
496  BuildInstruction const & bi = **i;
497 
498  if ( bi.original_interval_valid() ) {
499  o2m[ bi.original_interval() ] = bi.interval();
500  }
501  }
502 
503  return o2m;
504 }
505 
506 
507 /// @brief return a map translating original interval endpoints to modified
508 /// interval endpoints
509 /// @remarks modified intervals with no equivalent original interval (e.g. cases
510 /// such as insertions) will not appear in this map
511 /// @return map; empty if modify() has not yet been called
513  Original2Modified o2m;
514 
515  // if modify() not called, the mapping is unknown
516  if ( !modify_was_successful_ ) {
517  return o2m;
518  }
519 
520  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
521  BuildInstruction const & bi = **i;
522 
523  if ( bi.original_interval_valid() ) {
524  o2m[ bi.original_interval().left ] = bi.interval().left;
525  o2m[ bi.original_interval().right ] = bi.interval().right;
526  }
527  }
528 
529  return o2m;
530 }
531 
532 
533 /// @brief return a map translating modified intervals to original intervals
534 /// @remarks modified intervals with no equivalent original interval (e.g. cases
535 /// such as insertions) will not appear in this map
536 /// @return map; empty if modify() has not yet been called
538  Interval2Interval m2o;
539 
540  // if modify() not called, the mapping is unknown
541  if ( !modify_was_successful_ ) {
542  return m2o;
543  }
544 
545  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
546  BuildInstruction const & bi = **i;
547 
548  if ( bi.original_interval_valid() ) {
549  m2o[ bi.interval() ] = bi.original_interval();
550  }
551  }
552 
553  return m2o;
554 }
555 
556 
557 /// @brief return a map translating modified interval endpoints to original
558 /// interval endpoints
559 /// @remarks modified intervals with no equivalent original interval (e.g. cases
560 /// such as insertions) will not appear in this map
562  Modified2Original m2o;
563 
564  // if modify() not called, the mapping is unknown
565  if ( !modify_was_successful_ ) {
566  return m2o;
567  }
568 
569  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
570  BuildInstruction const & bi = **i;
571 
572  if ( bi.original_interval_valid() ) {
573  m2o[ bi.interval().left ] = bi.original_interval().left;
574  m2o[ bi.interval().right ] = bi.original_interval().right;
575  }
576  }
577 
578  return m2o;
579 }
580 
581 
582 /// @brief return all modified intervals
583 /// @remarks Since this encompasses everything this is typically not useful
584 /// except for overall tracking purposes.
585 /// @return If modify() has not been called will return an empty set.
586 std::set< Interval > BuildManager::intervals() const {
587  std::set< Interval > intervals;
588 
589  if ( !modify_was_successful_ ) {
590  return intervals;
591  }
592 
593  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
594  BuildInstruction const & bi = (**i);
595  intervals.insert( bi.interval() );
596  }
597 
598  return intervals;
599 }
600 
601 
602 /// @brief return modified intervals that have no equivalent original interval
603 /// in their BuildInstructions (original_interval_valid() = false)
604 /// @remarks This is for cases such as insertions where there
605 /// is no equivalent original region.
606 /// @return If modify() has not been called will return an empty set.
608  std::set< Interval > intervals;
609 
610  if ( !modify_was_successful_ ) {
611  return intervals;
612  }
613 
614  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
615  BuildInstruction const & bi = (**i);
616 
617  // only return those modified intervals whose original interval is
618  // invalid
619  if ( !bi.original_interval_valid() ) {
620  intervals.insert( bi.interval() );
621  }
622  }
623 
624  return intervals;
625 }
626 
627 
628 /// @brief return all intervals containing positions that were pre-existing
629 /// in the original Pose prior to calling modify()
630 /// @return If modify() has not been called will return an empty set.
632  std::set< Interval > intervals;
633 
634  if ( !modify_was_successful_ ) {
635  return intervals;
636  }
637 
638  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
639  BuildInstruction const & bi = (**i);
640  if ( !bi.preexisting_positions().empty() ) {
641  intervals.insert( bi.interval() );
642  }
643  }
644 
645  return intervals;
646 }
647 
648 
649 /// @brief return all intervals containing positions that are "new" and did
650 /// not exist in the original Pose
651 /// @return If modify() has not been called will return an empty set.
653  std::set< Interval > intervals;
654 
655  if ( !modify_was_successful_ ) {
656  return intervals;
657  }
658 
659  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
660  BuildInstruction const & bi = (**i);
661  if ( !bi.new_positions().empty() ) {
662  intervals.insert( bi.interval() );
663  }
664  }
665 
666  return intervals;
667 }
668 
669 
670 /// @brief return all intervals containing positions with defined conformation
671 /// @return If modify() has not been called will return an empty set.
673  std::set< Interval > intervals;
674 
675  if ( !modify_was_successful_ ) {
676  return intervals;
677  }
678 
679  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
680  BuildInstruction const & bi = (**i);
681  if ( !bi.defined_positions().empty() ) {
682  intervals.insert( bi.interval() );
683  }
684  }
685 
686  return intervals;
687 }
688 
689 
690 /// @brief return all intervals containing positions with undefined conformation
691 /// @remarks typically used to define intervals appropriate for loop modeling
692 /// @return If modify() has not been called will return an empty set.
694  std::set< Interval > intervals;
695 
696  if ( !modify_was_successful_ ) {
697  return intervals;
698  }
699 
700  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
701  BuildInstruction const & bi = (**i);
702  if ( !bi.undefined_positions().empty() ) {
703  intervals.insert( bi.interval() );
704  }
705  }
706 
707  return intervals;
708 }
709 
710 
711 /// @brief return all original intervals containing positions that will
712 /// be kept by the BuildInstructions
713 /// @remarks returns valid data even without calling modify()
715  std::set< Interval > intervals;
716 
717  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
718  BuildInstruction const & bi = (**i);
719  if ( !bi.original_kept_positions().empty() ) {
720  intervals.insert( bi.original_interval() );
721  }
722  }
723 
724  return intervals;
725 }
726 
727 
728 /// @brief return all original intervals containing positions that will
729 /// be deleted by the BuildInstructions
730 /// @remarks returns valid data even without calling modify()
732  std::set< Interval > intervals;
733 
734  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
735  BuildInstruction const & bi = (**i);
736  if ( !bi.original_deleted_positions().empty() ) {
737  intervals.insert( bi.original_interval() );
738  }
739  }
740 
741  return intervals;
742 }
743 
744 
745 /// @brief return all positions within the modified intervals
746 /// @remarks Since this encompasses everything this is typically not useful
747 /// except for overall tracking purposes.
748 /// @return If modify() has not been called will return an empty set.
751 
752  Positions p;
753 
754  if ( !modify_was_successful_ ) {
755  return p;
756  }
757 
758  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
759  Interval const ival = (**i).interval();
760  insert_closed_range( ival.left, ival.right, p );
761  }
762 
763  return p;
764 }
765 
766 
767 /// @brief return the set of positions within the new regions that were
768 /// pre-existing in the original Pose prior to calling modify()
769 /// @return If modify() has not been called will return an empty set.
771  Positions preexisting;
772 
773  if ( !modify_was_successful_ ) {
774  return preexisting;
775  }
776 
777  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
778  Positions const bi_pp = (**i).preexisting_positions();
779  preexisting.insert( bi_pp.begin(), bi_pp.end() );
780  }
781 
782  return preexisting;
783 }
784 
785 
786 /// @brief return a copy of the set of positions that are "new" and did
787 /// not exist in the original Pose.
788 /// @return If modify() has not been called will return an empty set.
790  Positions newp;
791 
792  if ( !modify_was_successful_ ) {
793  return newp;
794  }
795 
796  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
797  Positions const bi_np = (**i).new_positions();
798  newp.insert( bi_np.begin(), bi_np.end() );
799  }
800 
801  return newp;
802 }
803 
804 
805 /// @brief return a copy of the set of positions within the newly modified
806 /// regions that have a defined conformation. E.g. existing or copied residues.
807 /// @return If modify() has not been called will return an empty set.
809  Positions defined;
810 
811  if ( !modify_was_successful_ ) {
812  return defined;
813  }
814 
815  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
816  Positions const bi_dp = (**i).defined_positions();
817  defined.insert( bi_dp.begin(), bi_dp.end() );
818  }
819 
820  return defined;
821 }
822 
823 
824 /// @brief return a copy of the set of positions within the newly modified
825 /// regions that have an undefined conformation. E.g. newly created residues.
826 /// @return If modify() has not been called will return an empty set.
828  Positions undefined;
829 
830  if ( !modify_was_successful_ ) {
831  return undefined;
832  }
833 
834  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
835  Positions const bi_up = (**i).undefined_positions();
836  undefined.insert( bi_up.begin(), bi_up.end() );
837  }
838 
839  return undefined;
840 }
841 
842 
843 /// @brief the positions representing the union of all intervals containing
844 /// positions with undefined conformation
845 /// @remarks Useful as a reference for defining neighborhoods around
846 /// loop modeled regions.
847 /// @return If modify() has not been called will return an empty set.
850 
851  Positions p;
852 
853  if ( !modify_was_successful_ ) {
854  return p;
855  }
856 
857  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
858  BuildInstruction const & bi = (**i);
859  Interval const ival = bi.interval();
860 
861  if ( !bi.undefined_positions().empty() ) {
862  insert_closed_range( ival.left, ival.right, p );
863  }
864  }
865 
866  return p;
867 }
868 
869 
870 /// @brief return the set of positions within the original intervals that
871 /// will be kept by the BuildInstructions
872 /// @remarks returns valid data even without calling modify()
874  Positions kept;
875 
876  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
877  Positions const bi_kp = (**i).original_kept_positions();
878  kept.insert( bi_kp.begin(), bi_kp.end() );
879  }
880 
881  return kept;
882 }
883 
884 
885 /// @brief return set of positions within the original intervals that will
886 /// be deleted by the BuildInstructions
887 /// @remarks returns valid data even without calling modify()
889  Positions deleted;
890 
891  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
892  Positions const bi_dp = (**i).original_deleted_positions();
893  deleted.insert( bi_dp.begin(), bi_dp.end() );
894  }
895 
896  return deleted;
897 }
898 
899 
900 /// @brief return a map from modified intervals to the set of pre-existing
901 /// positions inside them
902 /// @return If modify() has not been called will return an empty map.
904  Interval2Positions i2p;
905 
906  if ( !modify_was_successful_ ) {
907  return i2p;
908  }
909 
910  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
911  BuildInstruction const & bi = **i;
912  i2p.insert( std::make_pair( bi.interval(), bi.preexisting_positions() ) );
913  }
914 
915  return i2p;
916 }
917 
918 
919 /// @brief return a map from modified intervals to the set of "new"
920 /// positions inside them that were not present in the original Pose
921 /// @return If modify() has not been called will return an empty map.
923  Interval2Positions i2p;
924 
925  if ( !modify_was_successful_ ) {
926  return i2p;
927  }
928 
929  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
930  BuildInstruction const & bi = **i;
931  i2p.insert( std::make_pair( bi.interval(), bi.new_positions() ) );
932  }
933 
934  return i2p;
935 }
936 
937 
938 /// @brief return a map from modified intervals to the set of
939 /// positions inside them that have defined conformation
940 /// @return If modify() has not been called will return an empty map.
942  Interval2Positions i2p;
943 
944  if ( !modify_was_successful_ ) {
945  return i2p;
946  }
947 
948  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
949  BuildInstruction const & bi = **i;
950  i2p.insert( std::make_pair( bi.interval(), bi.defined_positions() ) );
951  }
952 
953  return i2p;
954 }
955 
956 
957 /// @brief return a map from modified intervals to the set of
958 /// positions inside them that have undefined conformation
959 /// @return If modify() has not been called will return an empty map.
961  Interval2Positions i2p;
962 
963  if ( !modify_was_successful_ ) {
964  return i2p;
965  }
966 
967  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
968  BuildInstruction const & bi = **i;
969  i2p.insert( std::make_pair( bi.interval(), bi.undefined_positions() ) );
970  }
971 
972  return i2p;
973 }
974 
975 
976 /// @brief return a map from modified intervals to their individual movemaps
977 /// @return If modify() has not been called will return an empty map.
979  Interval2MoveMap i2m;
980 
981  if ( !modify_was_successful_ ) {
982  return i2m;
983  }
984 
985  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
986  BuildInstruction const & bi = **i;
987  i2m.insert( std::make_pair( bi.interval(), bi.movemap() ) );
988  }
989 
990  return i2m;
991 }
992 
993 
994 /// @brief return a map from original intervals to the set of positions
995 /// inside them that will be kept by the BuildInstructions
996 /// @remarks returns valid data even without calling modify()
998  Interval2Positions i2p;
999 
1000  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
1001  BuildInstruction const & bi = **i;
1002  i2p.insert( std::make_pair( bi.original_interval(), bi.original_kept_positions() ) );
1003  }
1004 
1005  return i2p;
1006 }
1007 
1008 
1009 /// @brief return a map from original intervals to the set of positions
1010 /// inside them that will be deleted by the BuildInstructions
1011 /// @remarks returns valid data even without calling modify()
1013  Interval2Positions i2p;
1014 
1015  for ( BIOPConstIterator i = begin(), ie = end(); i != ie; ++i ) {
1016  BuildInstruction const & bi = **i;
1017  i2p.insert( std::make_pair( bi.original_interval(), bi.original_deleted_positions() ) );
1018  }
1019 
1020  return i2p;
1021 }
1022 
1023 
1024 /// @brief find the given instruction
1025 /// @return iterator pointing to the BuildInstructionOP if found, otherwise
1026 /// the 'end' iterator
1028  return std::find( instructions_.begin(), instructions_.end(), u );
1029 }
1030 
1031 
1032 /// @brief find the given instruction
1033 /// @return iterator pointing to the BuildInstructionCOP if found, otherwise
1034 /// the 'end' iterator
1036  return std::find( instructions_.begin(), instructions_.end(), u );
1037 }
1038 
1039 
1040 /// @brief find the edge specifying the given dependency
1041 /// @return iterator pointing to the DependencyEdge if found, otherwise the
1042 /// 'end' iterator
1043 BuildManager::DependencyEdges::iterator BuildManager::find_dependency( BuildInstructionCOP u, BuildInstructionCOP v ) {
1044  for ( DependencyEdges::iterator i = instruction_dependencies_.begin(), ie = instruction_dependencies_.end(); i != ie; ++i ) {
1045  if ( instructions_[ i->first ] == u && instructions_[ i->second ] == v ) {
1046  return i;
1047  }
1048  }
1049 
1050  return instruction_dependencies_.end();
1051 }
1052 
1053 
1054 /// @brief find the given dependency
1055 /// @return const iterator pointing to the DependencyEdge if found, otherwise the
1056 /// 'end' const iterator
1057 BuildManager::DependencyEdges::const_iterator BuildManager::find_dependency( BuildInstructionCOP u, BuildInstructionCOP v ) const {
1058  for ( DependencyEdges::const_iterator i = instruction_dependencies_.begin(), ie = instruction_dependencies_.end(); i != ie; ++i ) {
1059  if ( instructions_[ i->first ] == u && instructions_[ i->second ] == v ) {
1060  return i;
1061  }
1062  }
1063 
1064  return instruction_dependencies_.end();
1065 }
1066 
1067 
1068 /// @brief clear the current dependency list and reconstruct the dependencies
1069 /// using the given list
1072 
1073  // add the new dependencies
1074  for ( DependencyEdges::const_iterator i = dependency_list.begin(), ie = dependency_list.end(); i != ie; ++i ) {
1075  create_directed_dependency( instructions_[ i->first ], instructions_[ i->second ] );
1076  }
1077 }
1078 
1079 
1080 } // namespace build
1081 } // namespace forge
1082 } // namespace protocols