Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PackerTask_.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 core/pack/task/PackerTask_.hh
11 /// @brief Implementation class for task class to describe packer's behavior header
12 /// Almost all of rosetta needs to use packer tasks, but very little of rosetta needs
13 /// to see how it behaves internally.
14 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
15 /// @author Steven Lewis (smlewi@unc.edu)
16 
17 
18 //Unit Headers
20 
21 // Package Headers
26 // AUTO-REMOVED #include <core/pack/task/ResfileReader.hh>
28 
29 //Project Headers
31 #include <core/chemical/AA.hh>
36 #include <core/pose/Pose.hh>
37 #include <basic/options/option.hh>
38 #include <core/pose/PDBInfo.hh>
40 
41 // Objexx headers
42 #include <ObjexxFCL/format.hh>
43 
44 //Utility Headers
45 #include <basic/Tracer.hh>
46 
47 #include <iostream>
48 
49 // option key includes
50 
51 // AUTO-REMOVED #include <basic/options/keys/run.OptionKeys.gen.hh>
52 #include <basic/options/keys/packing.OptionKeys.gen.hh>
53 
54 #include <utility/vector1.hh>
55 
56 using namespace ObjexxFCL;
57 using namespace ObjexxFCL::fmt;
58 
59 namespace core {
60 namespace pack {
61 namespace task {
62 
63 basic::Tracer T( "core.pack.task", basic::t_info );
64 
65 ///@details ResidueLevelTask constructor has following defaults:
66 ///all ex set to false with zero sample level
67 ///position is packable and designable to any of the canonical aa's,
68 ///with variant matching (for termini, etc)
69 ///current rotamer is not included for packer.
70 ///bump check is deactivated by default.
71 ResidueLevelTask_::ResidueLevelTask_(
72  conformation::Residue const & original_residue
73 )
74 :
75  include_current_( false ),
76  adducts_( true ),
77  original_residue_type_( original_residue.type() ), // fix this CAP construction from const &
78  target_residue_type_(0),
79  designing_( original_residue.is_protein() ), // default -- design at all protein residues
80  repacking_( true ),
81  optimize_H_mode_( false ),
82  preserve_c_beta_( false ),
83  flip_HNQ_( false ),
84  fix_his_tautomer_( false ),
85  disabled_( false ),
86  design_disabled_( false ),
87  sample_proton_chi_( true ),
88  sample_rna_chi_( false ),
89  ex1_( false ),
90  ex2_( false ),
91  ex3_( false ),
92  ex4_( false ),
93  ex1aro_( false ),
94  ex2aro_( false ),
95  ex1aro_exposed_( false ),
96  ex2aro_exposed_( false ),
97  ex1_sample_level_( NO_EXTRA_CHI_SAMPLES ),
98  ex2_sample_level_( NO_EXTRA_CHI_SAMPLES ),
99  ex3_sample_level_( NO_EXTRA_CHI_SAMPLES ),
100  ex4_sample_level_( NO_EXTRA_CHI_SAMPLES ),
101  ex1aro_sample_level_( NO_EXTRA_CHI_SAMPLES ),
102  ex2aro_sample_level_( NO_EXTRA_CHI_SAMPLES ),
103  ex1aro_exposed_sample_level_( NO_EXTRA_CHI_SAMPLES ),
104  ex2aro_exposed_sample_level_( NO_EXTRA_CHI_SAMPLES ),
105  exdna_sample_level_( NO_EXTRA_CHI_SAMPLES ),
106  extrachi_cutoff_( EXTRACHI_CUTOFF_LIMIT ),
107  operate_on_ex1_( false ),
108  operate_on_ex2_( false ),
109  operate_on_ex3_( false ),
110  operate_on_ex4_( false )
111 {
112  using namespace chemical;
113  // pb -- get the residue_set from the current residue
114  ResidueTypeSet const & residue_set( original_residue.residue_type_set() );
115  if ( original_residue.is_protein() ) {
116  //default: all amino acids at all positions -- additional "and" operations will remove
117  // amino acids from the list of allowed ones
118  //no rule yet to treat chemically modified aa's differently
119  for ( Size ii = 1; ii <= chemical::num_canonical_aas; ++ii ) {
120  ResidueTypeCOPs const & aas( residue_set.aa_map( chemical::AA( ii )));
121  for ( ResidueTypeCOPs::const_iterator
122  aas_iter = aas.begin(),
123  aas_end = aas.end(); aas_iter != aas_end; ++aas_iter ) {
124  if ( original_residue.type().variants_match(**aas_iter )) {
125  allowed_residue_types_.push_back( *aas_iter );
126  }
127  }
128  }
129  // allow noncanonical AAs to be repacked
130  if (original_residue.aa() == aa_unk)
131  allowed_residue_types_.push_back( & (original_residue.type()) );
132  } else if ( original_residue.is_DNA() ) {
133  // default: all canonical DNA types w/ adducts
134  ResidueTypeCOPs dna_types( ResidueSelector().set_property("DNA").select( residue_set ) );
135  for ( ResidueTypeCOPs::const_iterator type( dna_types.begin() ), end( dna_types.end() );
136  type != end; ++type ) {
137  if ( original_residue.type().nonadduct_variants_match( **type ) ) {
138  allowed_residue_types_.push_back( *type );
139  }
140  }
141  } else {
142  // for non-amino acids, default is to include only the existing residuetype
143  allowed_residue_types_.push_back( & (original_residue.type()) ); // fix this: creating CAP from const &
144  }
145  // The intention is for all ResidueTasks to *start off* as repackable.
146  // Some, like protein AAs and DNA, also start off designable.
149  // assert packable by default
150  runtime_assert( being_packed() );
151  // This is the same assertion, really, but coded directly
152  runtime_assert( ! allowed_residue_types_.empty() );
153 }
154 
156 
157 
160  bool buried,
161  int chi,
162  chemical::ResidueTypeCOP concrete_residue
163 ) const
164 {
165 
166  if ( concrete_residue->is_DNA() ) {
167  runtime_assert( chi == 1 );
168  return exdna_sample_level_;
169  }
170  if ( concrete_residue->is_aromatic() && chi <= 2 ) {
171  if ( chi == 1 ) {
172  if ( buried ) {
173  return ex1aro_sample_level_;
174  } else {
176  }
177  } else {
178  if (buried ) {
179  return ex2aro_sample_level_;
180  } else {
182  }
183  }
184  } else {
185  if ( buried && chi <= 4 ) {
186  if ( chi == 1 ) {
187  return ex1_sample_level_;
188  } else if ( chi == 2 ) {
189  return ex2_sample_level_;
190  } else if ( chi == 3 ) {
191  return ex3_sample_level_;
192  } else {
193  return ex4_sample_level_;
194  }
195  }
196  }
197  return NO_EXTRA_CHI_SAMPLES;
198 }
199 
200 void
202 {
203  using namespace basic::options;
204  using namespace OptionKeys::packing;
205 
207 
208  if ( option[ use_input_sc ] ) or_include_current( true );
209  if ( option[ OptionKeys::packing::preserve_c_beta ].user() ) or_preserve_c_beta( true );
210  if ( option[ OptionKeys::packing::prevent_repacking ].value() ) prevent_repacking();
211 
212 }
213 
214 void
216 {
217  using namespace basic::options;
218  using namespace OptionKeys::packing;
219 
220  if ( option[ ex1::ex1 ].user() ) { or_ex1( option[ ex1::ex1 ].value() ); }
221  if ( option[ ex2::ex2 ].user() ) { or_ex2( option[ ex2::ex2 ].value() ); }
222  if ( option[ ex3::ex3 ].user() ) { or_ex3( option[ ex3::ex3 ].value() ); }
223  if ( option[ ex4::ex4 ].user() ) { or_ex4( option[ ex4::ex4 ].value() ); }
224 
225  if ( option[ ex1aro::ex1aro ].user() )
226  { or_ex1aro( option[ ex1aro::ex1aro ].value() ); }
227 
228  if ( option[ ex2aro::ex2aro ].user() )
229  { or_ex2aro( option[ ex2aro::ex2aro ].value() ); }
230 
231  if ( option[ ex1aro_exposed::ex1aro_exposed ].user() )
232  { or_ex1aro_exposed( option[ ex1aro_exposed::ex1aro_exposed ].value() ); }
233 
234  if ( option[ ex2aro_exposed::ex2aro_exposed ].user() )
235  { or_ex2aro_exposed( option[ ex2aro_exposed::ex2aro_exposed ].value() ); }
236 
237  if ( option[ ex1::level ].user() )
238  { or_ex1_sample_level( static_cast<ExtraRotSample>( option[ ex1::level ].value() )); }
239 
240  if ( option[ ex2::level ].user() )
241  { or_ex2_sample_level( static_cast<ExtraRotSample>( option[ ex2::level ].value() )); }
242 
243  if ( option[ ex3::level ].user() )
244  { or_ex3_sample_level( static_cast<ExtraRotSample>( option[ ex3::level ].value() )); }
245 
246  if ( option[ ex4::level ].user() )
247  { or_ex4_sample_level( static_cast<ExtraRotSample>( option[ ex4::level ].value() )); }
248 
249  if ( option[ ex1aro::level ].user() )
250  { or_ex1aro_sample_level( static_cast<ExtraRotSample>( option[ ex1aro::level ].value() )); }
251 
252  if ( option[ ex2aro::level ].user() )
253  { or_ex2aro_sample_level( static_cast<ExtraRotSample>( option[ ex2aro::level ].value() )); }
254 
255  if ( option[ ex1aro_exposed::level ].user() )
256  { or_ex1aro_exposed_sample_level( static_cast<ExtraRotSample>( option[ ex1aro_exposed::level ].value() )); }
257 
258  if ( option[ ex2aro_exposed::level ].user() )
259  { or_ex2aro_exposed_sample_level( static_cast<ExtraRotSample>( option[ ex2aro_exposed::level ].value() )); }
260 
261  if ( option[ ex1::operate ].user() ) { or_operate_on_ex1( option[ ex1::operate ]() ); }
262  if ( option[ ex2::operate ].user() ) { or_operate_on_ex2( option[ ex2::operate ]() ); }
263  if ( option[ ex3::operate ].user() ) { or_operate_on_ex3( option[ ex3::operate ]() ); }
264  if ( option[ ex4::operate ].user() ) { or_operate_on_ex4( option[ ex4::operate ]() ); }
265 
266  // options to control dna rotamer building
267  if ( option[ exdna::exdna ].user() && option[ exdna::level ].user() ) {
268  if ( option[ exdna::exdna ].value() && option[ exdna::level ].value() ) {
269  or_exdna_sample_level( static_cast<ExtraRotSample>( option[ exdna::level ].value() ) );
270  }
271  }
272  else if ( option[ exdna::exdna ].user() && !option[ exdna::level ].user() ) {
273  if ( option[ exdna::exdna ].value() ) {
275  }
276  }
277  else if ( !option[ exdna::exdna ].user() && option[ exdna::level ].user() ) {
278  if ( option[ exdna::level ].value() ) {
279  or_exdna_sample_level( static_cast<ExtraRotSample>( option[ exdna::level ].value() ) );
280  }
281  }
282 
283  // extra chi cutoff
284  if ( option[ OptionKeys::packing::extrachi_cutoff ].user() ) {
285  and_extrachi_cutoff( option[ OptionKeys::packing::extrachi_cutoff ] );
286  }
287 }
288 
290 {
292 }
293 
295 {
296  return include_current_;
297 }
298 
300 {
301  // probably not worth caring about (rare) redundancies
302  behaviors_.push_back( behavior );
303 }
304 bool ResidueLevelTask_::has_behavior( std::string const & behavior ) const
305 {
306  return std::find( behaviors_.begin(), behaviors_.end(), behavior ) != behaviors_.end();
307 }
309 {
310  return behaviors_.empty() ? false : true;
311 }
312 
314  bool allowed( std::find( allowed_residue_types_.begin(), allowed_residue_types_.end(), type ) !=
315  allowed_residue_types_.end() );
316  if ( !allowed ) {
317  T.Error << "Target type " << type->name() << " is not an allowed type!" << std::endl;
318  utility_exit();
319  return;
320  }
321  target_residue_type_ = type; /// non-commutative if multiple target residue types are set.
322 }
324  target_type( original_residue_type_->residue_type_set().aa_map( aa ).front() );
325 }
327  target_type( &original_residue_type_->residue_type_set().name_map( name ) );
328 }
329 
330 void ResidueLevelTask_::or_adducts( bool setting ) {
331  if ( setting ) return;
332  for ( ResidueTypeCOPListIter type_itr( allowed_residue_types_.begin() ),
333  next_itr( allowed_residue_types_.begin() ),
334  end_itr( allowed_residue_types_.end() ); type_itr != end_itr;
335  /* no increment: deletion + iterator incrementing = segfault! */ ) {
336  next_itr = type_itr; ++next_itr;
337  if ( (*type_itr)->has_variant_type( chemical::ADDUCT ) ) {
338  allowed_residue_types_.erase( type_itr );
339  }
340  type_itr = next_itr;
341  }
342  adducts_ = false;
345 }
346 bool ResidueLevelTask_::adducts() const { return adducts_; }
347 
349 {
350  ex1_ |= ex1;
352 }
353 
355 {
356  ex2_ |= ex2;
358 }
359 
361 {
362  ex3_ |= ex3;
364 }
365 
367 {
368  ex4_ |= ex4;
370 }
371 
373 {
374  if ( ex1_sample_level_ < ex1_sample_level ) {
377  }
378 }
379 
381 {
382  if ( exdna_sample_level_ < exdna_sample_level ) {
385  }
386 }
387 
389 {
390  if ( ex2_sample_level_ < ex2_sample_level ) {
393  }
394 }
396 {
397  if ( ex3_sample_level_ < ex3_sample_level ) {
400  }
401 }
403 {
404  if ( ex4_sample_level_ < ex4_sample_level ) {
407  }
408 }
409 
411 {
412  ex1aro_ |= ex1aro;
414 }
415 
417 {
418  ex2aro_ |= ex2aro;
420 }
421 
423 {
426 }
427 
429 {
432 }
433 
435 {
436  if ( ex1aro_sample_level_ < ex1aro_sample_level ) {
439  }
440 }
441 
443 {
444  if ( ex2aro_sample_level_ < ex2aro_sample_level ) {
447  }
448 }
449 
452 )
453 {
454  if ( ex1aro_exposed_sample_level_ < ex1aro_exposed_sample_level ) {
457  }
458 }
459 
462 )
463 {
464  if ( ex2aro_exposed_sample_level_ < ex2aro_exposed_sample_level ) {
467  }
468 }
469 
471  { operate_on_ex1_ |= operate; }
473  { operate_on_ex2_ |= operate; }
475  { operate_on_ex3_ |= operate; }
477  { operate_on_ex4_ |= operate; }
478 
479 
481 {
482  sample_proton_chi_ = setting;
483 }
484 
486 {
487  return sample_proton_chi_;
488 }
489 
491 {
492  sample_rna_chi_ = setting;
493 }
494 
496 {
497  return sample_rna_chi_;
498 }
499 
500 
502 {
503  return ex1_;
504 }
506 {
507  return ex2_;
508 }
510 {
511  return ex3_;
512 }
514 {
515  return ex4_;
516 }
517 
519 {
520  return ex1_sample_level_;
521 }
523 {
524  return ex2_sample_level_;
525 }
527 {
528  return ex3_sample_level_;
529 }
531 {
532  return ex4_sample_level_;
533 }
534 
536 {
537  return ex1aro_;
538 }
540 {
541  return ex2aro_;
542 }
544 {
545  return ex1aro_exposed_;
546 }
548 {
549  return ex2aro_exposed_;
550 }
551 
553 {
554  return ex1aro_sample_level_;
555 }
557 {
558  return ex2aro_sample_level_;
559 }
561 {
563 }
565 {
567 }
568 
570 {
571  return exdna_sample_level_;
572 }
573 
575 {
576  return operate_on_ex1_;
577 }
579 {
580  return operate_on_ex2_;
581 }
583 {
584  return operate_on_ex3_;
585 }
587 {
588  return operate_on_ex4_;
589 }
590 
592 {
593  optimize_H_mode_ |= setting;
594  if ( optimize_H_mode_ ) {
595  // remove all amino acids that do not match the native amino acid
596  // there is no design in optimize_H_mode_
598  }
599 }
600 
602 {
603  return optimize_H_mode_;
604 }
605 
607 {
608  preserve_c_beta_ |= setting;
609 }
610 
612 {
613  return preserve_c_beta_;
614 }
615 
616 void ResidueLevelTask_::or_flip_HNQ( bool setting )
617 {
618  flip_HNQ_ |= setting;
619  or_optimize_h( setting );
620 }
621 
623 {
624  return flip_HNQ_;
625 }
626 
627 ///@details this function forces a fixed histidine tautomer by removing the alternate tautomer from the ResidueTypesCAPList. The fix_his_tautomer_ boolean is maintained for reference that this has been done, but the boolean is not the source of the effect.
629 {
630  if ( !setting || original_residue_type_->aa() != chemical::aa_his ) return;
631  fix_his_tautomer_ |= setting;
632 
633  //logic: iterate through ResidueTypeCOPList. Remove all ResidueTypeCOPs that ARE histidine but are not of the same tautomer as this residue's original_residue_type_.
634  //but how do we decide tautomer? ResidueType offers two options: string comparisons of the names, and checking which atoms are present. We're going with the latter.
635 
636  //which hydrogen atoms are present in the original residue? We'll check both and vainly hope this won't break if somone tries protonation variants.
637  bool HIS(original_residue_type_->has_atom_name(" HE2")); //HIS
638  bool HIS_D(original_residue_type_->has_atom_name(" HD1")); //HIS_D
639 
641  allowed_iter = allowed_residue_types_.begin(),
642  iter_next = allowed_residue_types_.begin(),
643  allowed_end = allowed_residue_types_.end();
644  allowed_iter != allowed_end; /* no increment: deletion + iterator incrementing = segfault! */ ) {
645  iter_next = allowed_iter;
646  ++iter_next;
647 
648  if ((*allowed_iter)->aa() == chemical::aa_his) { //we only want to look at histidines
649  //which hydrogen atoms are present in the residue we're checking?
650  bool comp_HIS((*allowed_iter)->has_atom_name(" HE2")); //HIS
651  bool comp_HIS_D((*allowed_iter)->has_atom_name(" HD1")); //HIS_D
652 
653  if ( (HIS != comp_HIS) || (HIS_D != comp_HIS_D) ) {
654  allowed_residue_types_.erase( allowed_iter );
655  }
656  }
657  allowed_iter = iter_next;
658  }
659 
660 }
661 
663 {
664  return fix_his_tautomer_;
665 }
666 
667 ///@details and operation -- min -- move only toward a lower cutoff for #neighbors w/i 10A that
668 ///qualify a residue to be considered buried.
669 void ResidueLevelTask_::and_extrachi_cutoff( Size num_neighbors_to_be_called_buried )
670 {
671  if ( extrachi_cutoff_ > num_neighbors_to_be_called_buried ) {
672  extrachi_cutoff_ = num_neighbors_to_be_called_buried;
673  }
674 }
675 
677 {
678  return extrachi_cutoff_;
679 }
680 
681 // remove all ResidueTypes from the list of allowed residue types
683 {
684  disabled_ = true;
685  design_disabled_ = true;
686  allowed_residue_types_.clear();
689  mode_tokens_.push_back("NATRO");
690 }
691 
692 
693 ///@details contract (and) the list of available aas for canonical aa's
694 ///if an amino acid is not present (false) in the boolean vector, then do not allow it at this position
695 ///boolean vector is based on the aa enum; see another example with PIKAA.
696 ///The boolean vector is a 20-length vector in alphabetical order by one-letter code.
697 void
699 {
700  Size num_allowed = std::count( allowed_aas.begin(), allowed_aas.end(), true);
701  std::ostringstream aas;
702  if (num_allowed == 0){
703  mode_tokens_.push_back("EMPTY");
704  } else if ( num_allowed == chemical::num_canonical_aas ){
705  // this doesn't constrain anything...
706  } else if (num_allowed < chemical::num_canonical_aas/2){
707  mode_tokens_.push_back("PIKAA");
708  for( Size i = 1; i <= chemical::num_canonical_aas; ++i ){
709  if( allowed_aas[ i ] ){
710  aas << chemical::oneletter_code_from_aa( static_cast<chemical::AA>(i) );
711  }
712  }
713  } else {
714  mode_tokens_.push_back("NOTAA");
715  for( Size i = 1; i <= chemical::num_canonical_aas; ++i ){
716  if( !allowed_aas[ i ] ){
717  aas << chemical::oneletter_code_from_aa( static_cast<chemical::AA>(i) );
718  }
719  }
720  }
721  mode_tokens_.push_back(aas.str() );
722  do_restrict_absent_canonical_aas( allowed_aas );
723 }
724 
725 void
727 {
728  mode_tokens_.push_back( mode );
729  do_restrict_absent_canonical_aas( allowed_aas );
730 }
731 
732 //The boolean vector is a 20-length vector in alphabetical order by one-letter code.
733 void
735 {
736  runtime_assert( allowed_aas.size() == chemical::num_canonical_aas );
738  allowed_iter = allowed_residue_types_.begin(),
739  iter_next = allowed_residue_types_.begin(),
740  allowed_end = allowed_residue_types_.end();
741  allowed_iter != allowed_end; /* no increment: deletion + iterator incrementing = segfault! */ ) {
742  iter_next = allowed_iter;
743  ++iter_next;
744  if ( (*allowed_iter)->aa() <= chemical::num_canonical_aas ) {
745  if ( ! allowed_aas[ (*allowed_iter)->aa() ] ) {
746  allowed_residue_types_.erase( allowed_iter );
747  }
748  }
749  allowed_iter = iter_next;
750  }
753 }
754 
755 //@details Same behavior as restrict_absent_canonical_aas except that it always allows the native aa at a position even if it is not included in the allowed residues
756 void
758  runtime_assert( allowed_aas.size() == chemical::num_canonical_aas );
760  allowed_iter = allowed_residue_types_.begin(),
761  iter_next = allowed_residue_types_.begin(),
762  allowed_end = allowed_residue_types_.end();
763  allowed_iter != allowed_end; /* no increment: deletion + iterator incrementing = segfault! */ ) {
764  iter_next = allowed_iter;
765  ++iter_next;
766  if ( (*allowed_iter)->aa() <= chemical::num_canonical_aas ) {
767  //checks if not in the allowed list and not the original type
768  if ( ! allowed_aas[ (*allowed_iter)->aa() ] && ! is_original_type( *allowed_iter ) ) {
769  allowed_residue_types_.erase( allowed_iter );
770  }
771  }
772  allowed_iter = iter_next;
773  }
776 
777  }
778 
779 
780 ///@details contract (and) the list of available nas for canonical na's
781 ///if a nucleic acid is not present in the vector, then do not allow it at this position
782 void
784  utility::vector1< chemical::AA > const & keep_nas
785 )
786 {
789  type_itr = allowed_residue_types_.begin(), next_itr = allowed_residue_types_.begin(),
790  end_itr = allowed_residue_types_.end(); type_itr != end_itr;
791  /* no increment: deletion + iterator incrementing = segfault! */ ) {
792  next_itr = type_itr;
793  ++next_itr;
794  bool keep(false);
795  for ( AAs::const_iterator na( keep_nas.begin() ); na != keep_nas.end(); ++na ) {
796  if ( (*type_itr)->aa() == *na ) { keep = true; break; }
797  }
798  if ( ! keep ) allowed_residue_types_.erase( type_itr );
799  type_itr = next_itr;
800  }
803 
804 
805  std::ostringstream nas;
806  for( utility::vector1 < chemical::AA >::const_iterator na = keep_nas.begin(); na != keep_nas.end(); ++na ){
807  // illegal for DNA: single-letter codes redundant
808  //nas << chemical::oneletter_code_from_aa( *na );
809  nas << chemical::name_from_aa( *na );
810  }
811  mode_tokens_.push_back( "NA" );
812  mode_tokens_.push_back( nas.str() );
813 
814 }
815 
816 ///@details removes all residues from the allowed residue types list, except the one that matches
817 ///the original residue; this means only rotameric and not sequence changes are allowed
818 ///if the original residue type has been disabled elsewhere, this function will prevent repacking at
819 ///that residue.
820 void
822 {
824  allowed_iter = allowed_residue_types_.begin(),
825  iter_next = allowed_residue_types_.begin(),
826  allowed_end = allowed_residue_types_.end();
827  allowed_iter != allowed_end; /* no increment: deletion + iterator incrementing = segfault! */ ) {
828  iter_next = allowed_iter;
829  ++iter_next;
830  if ( ! is_original_type( *allowed_iter ) ) allowed_residue_types_.erase( allowed_iter );
831  allowed_iter = iter_next;
832  }
833  design_disabled_ = true;
836  mode_tokens_.push_back("NATAA");
837 }
838 
840 {
841  if ( original_residue_type_->aa() == chemical::aa_unk ) {
842  // unknown aa != equivalent type
843  return ( type->name3() == original_residue_type_->name3() );
844  } else if ( fix_his_tautomer_ && (original_residue_type_->aa() == chemical::aa_his) ) {
845  // the only way to distinguish HIS and HIS_D is by their full name
846  // this will still fail for cases where variants mismatch but the tautomer does not
847  return( type->name() == original_residue_type_->name() );
848  } else {
849  return ( type->aa() == original_residue_type_->aa() );
850  }
851 }
852 
854  return original_residue_type_->residue_type_set();
855 }
856 
858  return original_residue_type_->aa();
859 }
860 
861 // expand (or) the list of available aa's for non-cannonicals
863  std::string const & aaname,
864  chemical::ResidueTypeSet const & residue_set
865 )
866 {
867  if ( disabled_ || design_disabled_ ) return;
868 
869  // get ResidueTypeCOPs vector
870  chemical::ResidueTypeCOPs const & aas( residue_set.residue_types() );
871 
872  for ( chemical::ResidueTypeCOPs::const_iterator aas_iter = aas.begin(), aas_end = aas.end(); aas_iter != aas_end; ++aas_iter ) {
873  if ( original_residue_type_->variants_match( **aas_iter ) &&
874  std::find( allowed_residue_types_.begin(), allowed_residue_types_.end(), *aas_iter ) == allowed_residue_types_.end() && /* haven't already added it */
875  aaname == (**aas_iter).name3() )
876  {
877  allowed_residue_types_.push_back( *aas_iter );
878  }
879  }
880 
881  mode_tokens_.push_back("NC");
882  mode_tokens_.push_back(aaname);
883 
886 }
887 
888 ///@details assumes same ResidueTypeSet as original_residue_type_ and calls other overloaded allow_noncanonical_aas
890 {
891  allow_noncanonical_aa( aaname, original_residue_type_->residue_type_set() );
892 }
893 
894 ///@details assumes same ResidueTypeSet as original_residue_type_ and calls overloaded allow_noncanonical_aas
896 {
898 }
899 
900 void
902  chemical::AA const & aa
903 )
904 {
905  if ( disabled_ || design_disabled_ ) return;
906  disabled_ = false;
907  design_disabled_ = false;
908 
909  chemical::ResidueTypeSet const & residue_set( original_residue_type_->residue_type_set() );
910  chemical::ResidueTypeCOPs const & aas( residue_set.aa_map( aa ) );
911 
912  for ( chemical::ResidueTypeCOPs::const_iterator
913  aas_iter = aas.begin(), aas_end = aas.end(); aas_iter != aas_end; ++aas_iter ) {
914  if ( original_residue_type_->variants_match( **aas_iter ) &&
915  ( std::find( allowed_residue_types_.begin(), allowed_residue_types_.end(), *aas_iter ) ==
916  allowed_residue_types_.end() ) /* haven't already added it */ ) {
917  allowed_residue_types_.push_back( *aas_iter );
918  }
919  }
920 
923 }
924 
927 {
928  return allowed_residue_types_;
929 }
930 
933 {
934  return allowed_residue_types_.begin();
935 }
936 
939 {
940  return allowed_residue_types_.end();
941 }
942 
945 
946  bool allowed( std::find( allowed_residue_types_.begin(), allowed_residue_types_.end(),
948  if ( !allowed ) return 0;
949  return target_residue_type_;
950 }
951 
952 void
953 ResidueLevelTask_::print_allowed_types( std::ostream & os ) const
954 {
956  type != allowed_residue_types_end(); ++type ) {
957  os << '\t' << (**type).name() << '\n';
958  }
959 }
960 
961 bool ResidueLevelTask_::being_designed() const { return designing_; } // is this residue up for design?
962 bool ResidueLevelTask_::being_packed() const { return repacking_; } // is this residue being modified at all by the packer
963 
964 ///@details bookkeeping - increases to EX_ONE_STDDEV if boolean is on, but sample level is zero (AS IT SHOULD!)
966 {
967  if ( ex1_ ) {
969  }
970  if ( ex1aro_ ) {
972  }
973  if ( ex1aro_exposed_ ) {
975  }
976 
979  }
981 }
982 
983 ///@details bookkeeping - increases to EX_ONE_STDDEV if boolean is on, but sample level is zero
985 {
986  if ( ex2_ ) {
988  }
989  if ( ex2aro_ ) {
991  }
992  if ( ex2aro_exposed_ ) {
994  }
995 
998 }
999 
1000 ///@details bookkeeping - increases to EX_ONE_STDDEV if boolean is on, but sample level is zero
1002 {
1003  if ( ex3_ ) {
1005  }
1006 }
1007 
1008 ///@details bookkeeping - increases to EX_ONE_STDDEV if boolean is on, but sample level is zero
1010 {
1011  if ( ex4_ ) {
1013  }
1014 }
1015 
1016 
1017 void
1019 {
1020  designing_ = false;
1021  bool found_aa_difference = false;
1023  allowed_iter = allowed_residue_types_.begin(),
1024  allowed_end = allowed_residue_types_.end();
1025  allowed_iter != allowed_end; ++allowed_iter ) {
1026  if ( (*allowed_iter)->aa() != original_residue_type_->aa() ) {
1027  designing_ = true;
1028  found_aa_difference = true;
1029  break;
1030  }
1031  }
1032  if ( design_disabled_ || disabled_ ) {
1033  runtime_assert( ! found_aa_difference );
1034  designing_ = false;
1035  }
1036 }
1037 
1039 {
1040  if ( ! allowed_residue_types_.empty() ) {
1041  repacking_ = true;
1042  } else {
1043  repacking_ = false;
1044  }
1045 }
1046 
1049 {
1050  return rotamer_operations_;
1051 }
1052 
1053 void
1056 )
1057 {
1058  rotamer_operations_.push_back( rotop );
1059 }
1060 
1063 {
1064  return rotsetops_.begin();
1065 }
1066 
1069 {
1070  return rotsetops_.end();
1071 }
1072 
1073 void
1076 )
1077 {
1078  rotsetops_.push_back( rotsetop );
1079 }
1080 
1081 
1082 
1083 
1084 
1085 
1086 void
1088 {
1089  //T << "ResidueLevelTask_::update_union" << std::endl;
1090  ResidueLevelTask_ const & o(dynamic_cast<ResidueLevelTask_ const &>(t));
1091 
1092  for(utility::vector1<std::string>::const_iterator i = o.behaviors_.begin(); i != o.behaviors_.end(); ++i){
1093  if( std::find(behaviors_.begin(),behaviors_.end(),*i) == behaviors_.end() ) {
1094  //std::cout << "behaviors_ add " << *i;
1095  behaviors_.push_back(*i);
1096  }
1097  }
1098  for(rotamer_set::RotamerOperations::const_iterator i = o.rotamer_operations_.begin(); i != o.rotamer_operations_.end(); ++i){
1099  if( std::find(rotamer_operations_.begin(),rotamer_operations_.end(),*i) == rotamer_operations_.end() ) {
1100  //std::cout << "rotamer_operations_ add " << *i;
1101  rotamer_operations_.push_back(*i);
1102  }
1103  }
1104  for(rotamer_set::RotSetOperationList::const_iterator i = o.rotsetops_.begin(); i != o.rotsetops_.end(); ++i){
1105  if( std::find(rotsetops_.begin(),rotsetops_.end(),*i) == rotsetops_.end() ) {
1106  //std::cout << "rotsetops_ add " << *i;
1107  rotsetops_.push_back(*i);
1108  }
1109  }
1110  for(std::vector<std::string>::const_iterator i = o.mode_tokens_.begin(); i != o.mode_tokens_.end(); ++i){
1111  if( std::find(mode_tokens_.begin(),mode_tokens_.end(),*i) == mode_tokens_.end() ) {
1112  //std::cout << "mode_tokens_ add " << *i;
1113  mode_tokens_.push_back(*i);
1114  }
1115  }
1116  for(ResidueTypeCOPList::const_iterator i = o.allowed_residue_types_.begin(); i != o.allowed_residue_types_.end(); ++i){
1117  if( std::find(allowed_residue_types_.begin(),allowed_residue_types_.end(),*i) == allowed_residue_types_.end() ) {
1118  //std::cout << "allowed_residue_types_ add " << (*i)->name();
1119  allowed_residue_types_.push_back(*i);
1120  //std::cout << " set disabled false ";
1121 
1122  }
1123  }
1124 
1128  disabled_ = !repacking_;
1129 
1131  adducts_ |= o.adducts_;
1134  flip_HNQ_ |= o.flip_HNQ_;
1138  ex1_ |= o.ex1_;
1139  ex2_ |= o.ex2_;
1140  ex3_ |= o.ex3_;
1141  ex4_ |= o.ex4_;
1142  ex1aro_ |= o.ex1aro_;
1143  ex2aro_ |= o.ex2aro_;
1160 
1161 }
1162 
1163 
1164 void
1166 {
1167  //T << "ResidueLevelTask_::update_union" << std::endl;
1168  ResidueLevelTask_ const & o(dynamic_cast<ResidueLevelTask_ const &>(t));
1169 
1170  utility::vector1<std::string> new_behaviors;
1171  for(utility::vector1<std::string>::const_iterator i = o.behaviors_.begin(); i != o.behaviors_.end(); ++i){
1172  if( std::find( behaviors_.begin(), behaviors_.end(),*i) != behaviors_.end() &&
1173  std::find(o.behaviors_.begin(),o.behaviors_.end(),*i) != o.behaviors_.end() ){
1174  new_behaviors.push_back(*i);
1175  }
1176  }
1177  behaviors_ = new_behaviors;
1178 
1179  rotamer_set::RotamerOperations new_rotamer_operations;
1180  for(rotamer_set::RotamerOperations::const_iterator i = o.rotamer_operations_.begin(); i != o.rotamer_operations_.end(); ++i){
1181  if( std::find( rotamer_operations_.begin(), rotamer_operations_.end(),*i) != rotamer_operations_.end() &&
1182  std::find(o.rotamer_operations_.begin(),o.rotamer_operations_.end(),*i) != o.rotamer_operations_.end() ){
1183  new_rotamer_operations.push_back(*i);
1184  }
1185  }
1186  rotamer_operations_ = new_rotamer_operations;
1187 
1188 
1189 
1190  rotamer_set::RotSetOperationList new_rotsetops;
1191  for(rotamer_set::RotSetOperationList::const_iterator i = o.rotsetops_.begin(); i != o.rotsetops_.end(); ++i){
1192  if( std::find( rotsetops_.begin(), rotsetops_.end(),*i) != rotsetops_.end() &&
1193  std::find(o.rotsetops_.begin(),o.rotsetops_.end(),*i) != o.rotsetops_.end() ){
1194  new_rotsetops.push_back(*i);
1195  }
1196  }
1197  rotsetops_ = new_rotsetops;
1198 
1199  std::vector<std::string> new_mode_tokens;
1200  for(std::vector<std::string>::const_iterator i = o.mode_tokens_.begin(); i != o.mode_tokens_.end(); ++i){
1201  if( std::find( mode_tokens_.begin(), mode_tokens_.end(),*i) != mode_tokens_.end() &&
1202  std::find(o.mode_tokens_.begin(),o.mode_tokens_.end(),*i) != o.mode_tokens_.end() ){
1203  new_mode_tokens.push_back(*i);
1204  }
1205  }
1206  mode_tokens_ = new_mode_tokens;
1207 
1208  ResidueTypeCOPList new_allowed_residue_types;
1209  for(ResidueTypeCOPList::const_iterator i = o.allowed_residue_types_.begin(); i != o.allowed_residue_types_.end(); ++i){
1210  if( std::find( allowed_residue_types_.begin(), allowed_residue_types_.end(),*i) != allowed_residue_types_.end() &&
1211  std::find(o.allowed_residue_types_.begin(),o.allowed_residue_types_.end(),*i) != o.allowed_residue_types_.end() ){
1212  new_allowed_residue_types.push_back(*i);
1213  }
1214  }
1215  allowed_residue_types_ = new_allowed_residue_types;
1216 
1220  disabled_ = !repacking_;
1221 
1223  adducts_ &= o.adducts_;
1226  flip_HNQ_ &= o.flip_HNQ_;
1230  ex1_ &= o.ex1_;
1231  ex2_ &= o.ex2_;
1232  ex3_ &= o.ex3_;
1233  ex4_ &= o.ex4_;
1234  ex1aro_ &= o.ex1aro_;
1235  ex2aro_ &= o.ex2aro_;
1252 
1253 }
1254 
1255 void
1257  ResidueLevelTask const & t
1258 ){
1259  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1260 
1261  ResidueLevelTask_ const & o(dynamic_cast<ResidueLevelTask_ const &>(t));
1262 
1264  adducts_ |= o.adducts_;
1265  //designing_ = o.designing_; // need to call determine_if_designing
1266  //repacking_ = o.repacking_; // need to call determine_if_repacking
1269  flip_HNQ_ |= o.flip_HNQ_;
1271  disabled_ |= o.disabled_;
1273  sample_proton_chi_ = o.sample_proton_chi_; // <--- apparently sample_proton_chi is not commutatively assigned
1274  sample_rna_chi_ = o.sample_rna_chi_; // <--- apparently sample_rna_chi is not commutatively assigned
1275  ex1_ |= o.ex1_;
1276  ex2_ |= o.ex2_;
1277  ex3_ |= o.ex3_;
1278  ex4_ |= o.ex4_;
1279  ex1aro_ |= o.ex1aro_;
1280  ex2aro_ |= o.ex2aro_;
1297 
1298  target_residue_type_ = o.target_residue_type_; // <-- there can be only one, so, this is obviously a non-commutative member
1299 
1300  // merge the allowed residue types to find the set that overlaps
1301  ResidueTypeCOPList my_allowed_residue_types( allowed_residue_types_ );
1302  ResidueTypeCOPList o_allowed_residue_types( o.allowed_residue_types_ );
1303  my_allowed_residue_types.sort();
1304  o_allowed_residue_types.sort();
1305  ResidueTypeCOPList common;
1307  myiter = my_allowed_residue_types.begin(),
1308  myend = my_allowed_residue_types.end(),
1309  oiter = o_allowed_residue_types.begin(),
1310  oend = o_allowed_residue_types.end();
1311  myiter != myend && oiter != oend; /* no increment */ ) {
1312  //std::cout << " myiter: " << *myiter << " " << (*myiter)->name() << " oiter: " << *oiter << " " << (*oiter)->name() << std::endl;
1313  if ( *myiter == *oiter ) {
1314  common.push_back( *myiter );
1315  //std::cout << "Common! " << (*myiter)->name() << std::endl;
1316  ++myiter;
1317  ++oiter;
1318  } else if ( *myiter < *oiter ) {
1319  ++myiter;
1320  } else {
1321  ++oiter;
1322  }
1323  }
1324  // Now insert the elements of common in their original order into allowed_residue_types_
1325  ResidueTypeCOPList my_allowed_residue_types2;
1326  my_allowed_residue_types2.swap( allowed_residue_types_ );
1328  myiter = my_allowed_residue_types2.begin(),
1329  myend = my_allowed_residue_types2.end();
1330  myiter != myend; ++myiter ) {
1331  if ( std::find( common.begin(), common.end(), *myiter ) != common.end() ) {
1332  allowed_residue_types_.push_back( *myiter );
1333  }
1334  }
1337 
1338  /// Form a union of the following sets
1340  rotsetops_ .insert(rotsetops_ .begin(),o.rotsetops_ .begin(),o.rotsetops_ .end());
1341  behaviors_ .insert(behaviors_ .begin(),o.behaviors_ .begin(),o.behaviors_ .end());
1342  mode_tokens_ .insert(mode_tokens_ .begin(),o.mode_tokens_ .begin(),o.mode_tokens_ .end());
1343 }
1344 
1345 void
1347  Size resid,
1348  ResidueLevelTask const & t
1349 ){
1350  ResidueLevelTask_ const & o(dynamic_cast<ResidueLevelTask_ const &>(t));
1351  residue_tasks_[resid].update_union(o);
1352  pack_residue_[resid] = residue_tasks_[resid].being_packed();
1353 }
1354 
1355 void
1357  Size resid,
1358  ResidueLevelTask const & t
1359 ){
1360  ResidueLevelTask_ const & o(dynamic_cast<ResidueLevelTask_ const &>(t));
1361  residue_tasks_[resid].update_intersection(o);
1362  pack_residue_[resid] = residue_tasks_[resid].being_packed();
1363 }
1364 
1365 void
1367  Size resid,
1368  ResidueLevelTask const & t
1369 ){
1370  ResidueLevelTask_ const & o(dynamic_cast<ResidueLevelTask_ const &>(t));
1371  residue_tasks_[resid].update_commutative(o);
1372  pack_residue_[resid] = residue_tasks_[resid].being_packed();
1373 }
1374 
1375 void
1377  PackerTask const & t
1378 ){
1379 
1380  /*for(int i = 0; i < 9; ++i){
1381  std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
1382  std::cerr << "!!!!!!!!!!!!!! update update_commutative temporarially is copy! !!!!!!!!!!!!!!" << std::endl;
1383  std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
1384  }*/
1385 
1386  PackerTask_ const & o(dynamic_cast<PackerTask_ const &>(t));
1387 
1388  if( nres_ != o.nres_ ) utility_exit_with_message("unmatching nres_");
1389 
1390  /// leave the state of the pack_residue array as true everywhere. This is an array
1391  /// used only inside rotamer_trials and rtmin, so this should be a good idea.
1392  for(Size i = 1; i <= pack_residue_.size(); ++i) pack_residue_[i] = true;
1393 
1394  for(Size i = 1; i <= residue_tasks_.size(); ++i) residue_tasks_[i].update_commutative(o.residue_tasks_[i]);
1395 
1396  n_to_be_packed_ = o.n_to_be_packed_;/// <-- this derived data will need to be updated
1397  n_to_be_packed_up_to_date_ = false; /// <-- signal that n_to_be_packed will need to be updated
1398 
1399  linmem_ig_ |= o.linmem_ig_;
1400  lazy_ig_ |= o.lazy_ig_;
1401 
1402  double_lazy_ig_ |= o.double_lazy_ig_;
1403  dlig_mem_limit_ = std::min( dlig_mem_limit_, o.dlig_mem_limit_ );
1404 
1405  multi_cool_annealer_ |= o.multi_cool_annealer_;
1406  mca_history_size_ = std::max( mca_history_size_, o.mca_history_size_ );
1407 
1408  optimize_H_ |= o.optimize_H_;
1409 
1410  bump_check_ = o.bump_check_; /// <-- apparently bump check setting is not commutative!
1411  max_rotbump_energy_ = std::min( max_rotbump_energy_, o.max_rotbump_energy_ );
1412 
1413  rotamer_couplings_ = o.rotamer_couplings_; /// <--- apparently rotamer couplings assignment is not commutative
1414 
1415  rotamer_links_ = o.rotamer_links_; /// <--- apparently rotamer links assignment is not commutative
1416 
1417  low_temp_ = o.low_temp_;
1418  high_temp_ = o.high_temp_;
1419  disallow_quench_ = o.disallow_quench_;
1420 
1421 
1422  if(o.IG_edge_reweights_) {
1423  IG_edge_reweights_ = new IGEdgeReweightContainer(nres_);
1425  i != o.IG_edge_reweights_->reweighters_end(); ++i) {
1426  IG_edge_reweights_->add_reweighter(*i);
1427  }
1428  } else {
1429  IG_edge_reweights_ = NULL;
1430  }
1431 
1432 }
1433 
1434 void
1436  if( symmetry_status_ == NO_SYMMETRIZATION_REQUEST ){
1437  symmetry_status_ = REQUEST_SYMMETRIZE_BY_INTERSECTION;
1438  }
1439  if( symmetry_status_ != REQUEST_SYMMETRIZE_BY_INTERSECTION ) {
1440  utility_exit_with_message("PackerTask can be symmetrized by union or by intersection but not both.");
1441  }
1442 }
1443 
1444 void
1446  if( symmetry_status_ == NO_SYMMETRIZATION_REQUEST ){
1447  symmetry_status_ = REQUEST_SYMMETRIZE_BY_UNION;
1448  }
1449  if( symmetry_status_ != REQUEST_SYMMETRIZE_BY_UNION ) {
1450  utility_exit_with_message("PackerTask can be symmetrized by union or by intersection but not both.");
1451  }
1452 }
1453 
1454 bool
1456  return symmetry_status_ == REQUEST_SYMMETRIZE_BY_UNION;
1457 }
1458 
1459 bool
1461  return symmetry_status_ == REQUEST_SYMMETRIZE_BY_INTERSECTION;
1462 }
1463 
1465 )
1466 :
1467  nres_(0 ),
1468  pack_residue_( nres_, true ),
1469  n_to_be_packed_( nres_ ),
1470  n_to_be_packed_up_to_date_( true ),
1471  linmem_ig_( false ),
1472  lazy_ig_( false ),
1473  double_lazy_ig_( false ),
1474  dlig_mem_limit_( 0 ),
1475  multi_cool_annealer_( false ),
1476  mca_history_size_( 1 ),
1477  optimize_H_( false ),
1478  bump_check_( true ),
1479  max_rotbump_energy_( 5.0 ),
1480  low_temp_( -1.0 ), //default --> let annealer pick
1481  high_temp_( -1.0 ), //default --> let annealer pick
1482  disallow_quench_( false ),
1483  symmetry_status_(NO_SYMMETRIZATION_REQUEST)
1484 {
1485  IG_edge_reweights_ = NULL; //default stays empty, no reweighting
1486 }
1487 
1488 ///@details constructor requires a pose. most settings are in ResidueLevelTask
1489 ///nres_ is copied from the pose, all residues are set to be packable by default, and bump_check is true
1490 ///the constructor reads NEITHER the command line flags NOR a resfile; this must be done after creation!
1492  pose::Pose const & pose
1493 )
1494 :
1495  nres_( pose.total_residue() ),
1496  pack_residue_( nres_, true ),
1497  n_to_be_packed_( nres_ ),
1498  n_to_be_packed_up_to_date_( true ),
1499  linmem_ig_( false ),
1500  lazy_ig_( false ),
1501  double_lazy_ig_( false ),
1502  dlig_mem_limit_( 0 ),
1503  multi_cool_annealer_( false ),
1504  mca_history_size_( 1 ),
1505  optimize_H_( false ),
1506  bump_check_( true ),
1507  max_rotbump_energy_( 5.0 ),
1508  low_temp_( -1.0 ), //default --> let annealer pick
1509  high_temp_( -1.0 ), //default --> let annealer pick
1510  disallow_quench_( false ),
1511  symmetry_status_(NO_SYMMETRIZATION_REQUEST)
1512 {
1513  //create residue-level tasks
1514  residue_tasks_.reserve( nres_ );
1515  for ( Size ii = 1; ii <= nres_; ++ii ) {
1516  residue_tasks_.push_back( ResidueLevelTask_( pose.residue(ii) ));
1517  }
1518 
1519  IG_edge_reweights_ = NULL; //default stays empty, no reweighting
1520 }
1521 
1523 
1524 ///@details uses compiler-generated copy ctor
1527 {
1528  // rely on compiler-generated copy ctor
1529  PackerTaskOP newtask( new PackerTask_( *this ));
1530  return newtask;
1531 }
1532 
1534 {
1535  return nres_;
1536 }
1537 
1538 void
1539 PackerTask_::clean_residue_task( conformation::Residue const & original_residue, Size const seqpos)
1540 {
1541  if ( !pack_residue_[ seqpos ] ){
1542  --n_to_be_packed_;
1543  pack_residue_[ seqpos ] = true;
1544  }
1545  residue_tasks_[seqpos] = ResidueLevelTask_( original_residue );
1546 }
1547 
1548 ///@details turn off packing at all positions.
1549 ///This does not affect underlying ResidueLevelTasks, but at the moment there is no method for reversing
1551 {
1552  for ( Size ii = 1; ii <= nres_; ++ii )
1553  {
1554  pack_residue_[ ii ] = false;
1555  }
1556  n_to_be_packed_ = 0;
1558 }
1559 
1560 ///@details arbitrarily set the packer mutability for a position
1561 ///reverse with same function, opposite bool input
1562 void PackerTask_::temporarily_set_pack_residue( int resid, bool setting )
1563 {
1564  if ( ! setting && pack_residue_[ resid ]) {
1565  --n_to_be_packed_;
1566  } else if ( setting && ! pack_residue_[ resid ] ) {
1567  ++n_to_be_packed_;
1568  }
1569  pack_residue_[ resid ] = setting;
1571 }
1572 
1574 {
1576  return n_to_be_packed_;
1577 }
1578 
1579 bool PackerTask_::pack_residue( int resid ) const
1580 {
1581  // if ( resid < 0 || resid > pack_residue_.size() || resid > residue_tasks_.size() ){
1582  // T("core.pack.task.PackerTask") << "Resid " << resid << " out of range." << std::endl;
1583  //}
1584  return pack_residue_[ resid ] && residue_tasks_[ resid ].being_packed();
1585 }
1586 
1587 
1588 bool PackerTask_::design_residue( int resid ) const
1589 {
1590  return ( pack_residue_[ resid ] && residue_tasks_[ resid ].being_designed() );
1591 }
1592 
1594 {
1595  for ( Size ii = 1; ii <= nres_; ++ii ) {
1596  if ( pack_residue_[ ii ] && residue_tasks_[ ii ].being_designed() ) {
1597  return true;
1598  }
1599  }
1600  return false;
1601 }
1602 
1603 void PackerTask_::set_bump_check( bool setting ) {
1604  bump_check_ = setting;
1605 }
1606 bool PackerTask_::bump_check() const { return bump_check_; }
1607 
1609 {
1610  if ( setting < 0 ) return;
1611  if ( setting < max_rotbump_energy_ ) {
1612  max_rotbump_energy_ = setting;
1613  }
1614 }
1615 
1617 {
1618  return max_rotbump_energy_;
1619 }
1620 
1621 
1623 {
1624  if ( ! setting ) return; // short circuit
1625  for ( Size ii = 1; ii <= nres_; ++ii ) {
1626  residue_tasks_[ ii ].or_include_current( setting );
1627  }
1628 }
1629 
1630 void PackerTask_::or_include_current( bool setting, Size resid )
1631 {
1632  residue_tasks_[ resid ].or_include_current( setting );
1633 }
1634 
1636 {
1637  return residue_tasks_[ resid ].include_current();
1638 }
1639 
1640 void PackerTask_::add_behavior( std::string const & behavior )
1641 {
1642  for ( Size ii = 1; ii <= nres_; ++ii ) {
1643  residue_tasks_[ ii ].add_behavior( behavior );
1644  }
1645 }
1646 void PackerTask_::add_behavior( std::string const & behavior, Size resid )
1647 {
1648  residue_tasks_[ resid ].add_behavior( behavior );
1649 }
1650 bool PackerTask_::has_behavior( std::string const & behavior, Size resid ) const
1651 {
1652  return residue_tasks_[ resid ].has_behavior( behavior );
1653 }
1654 bool PackerTask_::has_behavior( Size resid ) const
1655 {
1656  return residue_tasks_[ resid ].has_behavior();
1657 }
1658 
1659 
1662  { return residue_tasks_[ resid ].target_type(); }
1663 
1664 // adducts
1665 void PackerTask_::or_adducts( bool setting )
1666 {
1667  if ( ! setting ) return; // short circuit
1668  for ( Size ii = 1; ii <= nres_; ++ii ) {
1669  residue_tasks_[ ii ].or_adducts( setting );
1670  }
1671 }
1672 void PackerTask_::or_adducts( bool setting, Size resid ){
1673  residue_tasks_[ resid ].or_adducts( setting );
1674 }
1675 bool PackerTask_::adducts( Size resid ) const {
1676  return residue_tasks_[ resid ].adducts();
1677 }
1678 
1679 
1681 {
1682  if ( ! setting ) return; // short circuit
1683 
1684  optimize_H_ = setting;
1685  if ( linmem_ig_ ) linmem_ig_ = false; // Don't bother with lmig in optH.
1686 
1687  for ( Size ii = 1; ii <= nres_; ++ii ) {
1688  residue_tasks_[ ii ].or_optimize_h( setting );
1689  }
1690 }
1691 
1693 {
1694  if ( ! setting ) return; // short circuit
1695  for ( Size ii = 1; ii <= nres_; ++ii ) {
1696  residue_tasks_[ ii ].or_preserve_c_beta( setting );
1697  }
1698 }
1699 
1700 void PackerTask_::or_flip_HNQ( bool setting )
1701 {
1702  if ( ! setting ) return; // short circuit
1703  for ( Size ii = 1; ii <= nres_; ++ii ) {
1704  residue_tasks_[ ii ].or_flip_HNQ( setting );
1705  }
1706 
1707 }
1708 
1709 void PackerTask_::or_fix_his_tautomer( utility::vector1<int> const & positions, bool setting )
1710 {
1711  if ( ! setting ) return;
1712  if ( positions.size() == 0 ) { // no positions defined, set for all residue_tasks_
1713  for (Size ii=1; ii<=nres_; ++ii) {
1714  residue_tasks_[ii].or_fix_his_tautomer( setting );
1715  }
1716  } else { // set for specific positions
1717  for ( Size ii=1; ii<=positions.size(); ++ii ) {
1718  residue_tasks_[ positions[ii] ].or_fix_his_tautomer( setting );
1719  }
1720  }
1721 }
1722 
1723 void PackerTask_::or_linmem_ig( bool setting )
1724 {
1725  linmem_ig_ |= setting;
1726 }
1727 
1729 {
1730  return linmem_ig_;
1731 }
1732 
1733 void PackerTask_::or_lazy_ig( bool setting )
1734 {
1735  lazy_ig_ |= setting;
1736 }
1737 
1739 {
1740  return lazy_ig_;
1741 }
1742 
1744 {
1745  double_lazy_ig_ = setting;
1746 }
1747 
1749 {
1750  return double_lazy_ig_;
1751 }
1752 
1754 {
1755  if ( nbytes_for_rpes != 0 ) {
1756  if ( nbytes_for_rpes < dlig_mem_limit_ || dlig_mem_limit_ == 0 ) {
1757  dlig_mem_limit_ = nbytes_for_rpes;
1758  }
1759  }
1760 }
1761 
1763 {
1764  return dlig_mem_limit_;
1765 }
1766 
1767 ///@brief read only the command line options for extra rotamer building;
1768 PackerTask &
1770 {
1771  for ( Size ii = 1; ii <= nres_; ++ii ) {
1772  residue_tasks_[ ii ].initialize_extra_rotamer_flags_from_command_line();
1773  }
1774  return *this;
1775 }
1776 
1778 {
1779  if ( ! (rotamer_couplings_ || rotamer_links_) ) {
1780  multi_cool_annealer_ |= setting;
1781  }
1782 }
1783 
1785 {
1786  return multi_cool_annealer_;
1787 }
1788 
1790 {
1791  if ( setting > mca_history_size_ ) mca_history_size_ = setting;
1792 }
1793 
1795 {
1796  return mca_history_size_;
1797 }
1798 
1799 void
1800 PackerTask_::show( std::ostream & out ) const {
1801 
1802  out << "#Packer_Task" << std::endl;
1803  out << std::endl;
1804 
1805 
1806  out << "resid\tpack?\tdesign?\tallowed_aas" << std::endl;
1807 
1808  for ( Size i=1, it_end = total_residue();
1809  i <= it_end; ++i){
1810 
1811  out << i;
1812  out << "\t" << (pack_residue( i ) ? "TRUE" : "FALSE");
1813  out << "\t" << (design_residue( i ) ? "TRUE" : "FALSE");
1814 
1815  out << "\t";
1817  allowed_iter( residue_task( i ).allowed_residue_types_begin() );
1818  allowed_iter != residue_task( i ).allowed_residue_types_end();
1819  ++allowed_iter ) {
1820  out << ((allowed_iter == residue_task( i ).allowed_residue_types_begin()) ? "" : ",") <<
1821  (*allowed_iter)->name();
1822  }
1823  out << std::endl;
1824  }
1825 
1826  //sml pymol-style selection, great for debugging
1827  if( basic::options::option[ basic::options::OptionKeys::packing::print_pymol_selection ].value() ){
1828  for ( Size i=1, it_end = total_residue(); i != it_end; ++i) if( pack_residue(i) ) out << i << "+";
1829  out << std::endl;
1830  }
1831 }
1832 
1833 void
1835  show(std::cout);
1836 }
1837 
1838 void
1839 PackerTask_::show_residue_task( std::ostream & out, Size resid ) const {
1840  out << "Residue " << resid << ": " << residue_task(resid).get_original_residue() << "\n";
1841  out << " \tpack?\t\t\t\t" << (pack_residue(resid) ? "TRUE" : "FALSE") <<
1842  "\n" << " \tdesign?\t\t\t\t" << (design_residue(resid) ? "TRUE" : "FALSE") <<
1843  "\n" << " \tinclude current rotamer?\t" << (residue_task(resid).include_current() ? "TRUE" : "FALSE") <<
1844  "\n" << " \thas protocol-level behavior?\t" << (residue_task(resid).has_behavior() ? "TRUE" : "FALSE") <<
1845  "\n" << " \tinclude adducts?\t\t" << (residue_task(resid).adducts() ? "TRUE" : "FALSE") <<
1846  "\n" << " \toptimize H placements?\t\t" << (residue_task(resid).optimize_h() ? "TRUE" : "FALSE") <<
1847  "\n" << " \tpreserve C beta?\t\t" << (residue_task(resid).preserve_c_beta() ? "TRUE" : "FALSE") <<
1848  "\n" << " \tflip HIS/ASN/GLN?\t\t" << (residue_task(resid).flip_HNQ() ? "TRUE" : "FALSE")<<
1849  "\n" << " \tfix HIS tautamer?\t\t" << (residue_task(resid).fix_his_tautomer() ? "TRUE" : "FALSE") <<
1850  "\n" << " \tsample proton chi?\t\t" << (residue_task(resid).sample_proton_chi() ? "TRUE" : "FALSE") <<
1851  "\n" << " \tsample RNA chi?\t\t\t" << (residue_task(resid).sample_rna_chi() ? "TRUE" : "FALSE") <<
1852  "\n" << " \textra chi cutoff:\t\t" << residue_task(resid).extrachi_cutoff() <<
1853  "\n" << " \textra rotamer for chi 1\t\t" << (residue_task(resid).ex1() ? "TRUE" : "FALSE") <<
1854  "\n" << " \textra rotamer for chi 2\t\t" << (residue_task(resid).ex2() ? "TRUE" : "FALSE") <<
1855  "\n" << " \textra rotamer for chi 3\t\t" << (residue_task(resid).ex3() ? "TRUE" : "FALSE") <<
1856  "\n" << " \textra rotamer for chi 4\t\t" << (residue_task(resid).ex4() ? "TRUE" : "FALSE") <<
1857  "\n" << " \textra rotamer for chi 1 (aromatics)\t\t" << (residue_task(resid).ex1aro() ? "TRUE" : "FALSE") <<
1858  "\n" << " \textra rotamer for chi 2 (aromatics)\t\t" << (residue_task(resid).ex2aro() ? "TRUE" : "FALSE") <<
1859  "\n" << " \textra rotamer for chi 1 (exposed aromatics)\t" <<
1860  (residue_task(resid).ex1aro_exposed() ? "TRUE" : "FALSE") <<
1861  "\n" << " \textra rotamer for chi 2 (exposed aromatics)\t" <<
1862  (residue_task(resid).ex2aro_exposed() ? "TRUE" : "FALSE") << "\n";
1863 }
1864 
1865 void
1867  show_residue_task(std::cout, resid);
1868 }
1869 
1870 void
1871 PackerTask_::show_all_residue_tasks( std::ostream & out ) const {
1872  for ( Size i=1, it_end = total_residue(); i <= it_end; ++i){
1873  show_residue_task( out, i );
1874  }
1875 }
1876 
1877 void
1879  for ( Size i=1, it_end = total_residue(); i <= it_end; ++i){
1880  show_residue_task( i );
1881  }
1882 }
1883 
1884 PackerTask &
1886 {
1887  using namespace basic::options;
1888  using namespace basic::options::OptionKeys;
1889 
1890  T << "Packer task: initialize from command line() " << std::endl;
1891 
1892  if ( option[ packing::linmem_ig ].user() && ! optimize_H_ ) {
1893  or_linmem_ig( true );
1894  }
1895  if ( option[ packing::lazy_ig ] && ! optimize_H_ ) {
1896  or_lazy_ig( true );
1897  }
1898  if ( option[ packing::double_lazy_ig ] && ! optimize_H_ ) {
1899  or_double_lazy_ig( true );
1900  }
1901  if ( option[ packing::multi_cool_annealer ].user() ) {
1902  or_multi_cool_annealer( true );
1903  increase_multi_cool_annealer_history_size( option[ packing::multi_cool_annealer ] );
1904  }
1905 
1906  for ( Size ii = 1; ii <= nres_; ++ii ) {
1907  residue_tasks_[ ii ].initialize_from_command_line();
1908  }
1909 
1910  if ( option[ packing::fix_his_tautomer ].user() ) {
1911  or_fix_his_tautomer( option[packing::fix_his_tautomer], true );
1912  }
1913 
1914  if ( option[ packing::repack_only ].value() ) {
1916  }
1917 
1918  and_max_rotbump_energy( option[ packing::max_rotbump_energy ] );
1919 
1921  return *this;
1922 }
1923 
1924 ///@details vector boolean is based on residue position, disables packing at false positions
1925 ///does nothing to true positions. Cannot turn on packing.
1926 PackerTask &
1928  utility::vector1< bool > const & residues_allowed_to_be_packed
1929 )
1930 {
1931  for ( Size ii = 1; ii <= nres_; ++ii ) {
1932  if ( ! residues_allowed_to_be_packed[ ii ] ) {
1933  residue_tasks_[ ii ].prevent_repacking(); // permenent disabling of the residue
1934  }
1935  }
1937  return *this;
1938 }
1939 
1940 ///@details vector boolean is based on residue position, disables packing at false positions
1941 ///does nothing to true positions. Cannot turn on packing. Will prevent packing at false positions
1942 ///if the original residue type has been otherwise disallowed.
1943 PackerTask &
1945 {
1946  for ( Size ii = 1; ii <= nres_; ++ii ) {
1947  residue_tasks_[ ii ].restrict_to_repacking();
1948  }
1950  return *this;
1951 }
1952 
1953 ResidueLevelTask const &
1955 {
1956  // packer has no need to read residue-level task for a residue that has been disabled
1957  //This makes the assumption that ONLY the packer is allowed to use this function
1958  //assert( pack_residue_[ resid ] );
1959  return residue_tasks_[ resid ];
1960 }
1961 
1964 {
1966  return residue_tasks_[ resid ];
1967 }
1968 
1971 {
1973  for ( Size ii = 1; ii <= nres_; ++ii ) { being_packed[ ii ] = residue_tasks_[ ii ].being_packed(); }
1974  return being_packed;
1975 }
1976 
1979 {
1981  for ( Size ii = 1; ii <= nres_; ++ii ) { being_designed[ ii ] = residue_tasks_[ ii ].being_designed(); }
1982  return being_designed;
1983 }
1984 
1985 ///@brief is there at RotamerCouplings object to worry about? (for DNA GC AT pairing, etc)
1986 bool
1988 {
1989  return ( rotamer_couplings_() != 0 );
1990 }
1991 
1992 ///@brief const accessor for the RotamerCouplings object
1995 {
1996  return rotamer_couplings_();
1997 }
1998 
1999 ///@brief setter for the RotamerCouplings object
2000 void
2002 {
2003  rotamer_couplings_ = setting;
2004  if ( setting ) {
2005  multi_cool_annealer_ = false;
2006  }
2007 }
2008 
2009 ///@brief is there at RotamerLinks object to worry about? (for repeat linking
2010 //equivalent positions, etc)
2011 bool
2013 {
2014  return ( rotamer_links_() != 0 );
2015 }
2016 
2017 ///@brief const accessor for the RotamerCouplings object
2020 {
2021  return rotamer_links_();
2022 }
2023 
2024 ///@brief setter for the RotamerCouplings object
2025 void
2027 {
2028  rotamer_links_ = setting;
2029  if ( setting ) {
2030  multi_cool_annealer_ = false;
2031  }
2032 }
2033 
2036  return IG_edge_reweights_;
2037 }
2038 
2041 {
2042  if( !IG_edge_reweights_ ){
2044  }
2045  return IG_edge_reweights_;
2046 
2047 }
2048 
2049 void
2052 )
2053 {
2054  for ( Size ii = 1; ii <= nres_; ++ii ) {
2055  residue_tasks_[ ii ].append_rotamer_operation( rotop );
2056  }
2057 }
2058 
2059 void
2062 )
2063 {
2064  for ( Size ii = 1; ii <= nres_; ++ii ) {
2065  residue_tasks_[ ii ].append_rotamerset_operation( rotsetop );
2066  }
2067 }
2068 
2069 void
2071 {
2072  n_to_be_packed_ = 0;
2073  for ( Size ii = 1; ii <= nres_; ++ii ) {
2074  if ( pack_residue_[ ii ] && residue_tasks_[ ii ].being_packed() ) {
2075  ++n_to_be_packed_;
2076  }
2077  }
2079 }
2080 
2081 //some get-set functions for annealer options
2082 void
2084  low_temp_ = low_temp;
2085 }
2086 
2087 void
2090 }
2091 
2092 void
2095 }
2096 
2097 Real
2099 
2100 Real
2102 
2103 bool
2105 
2107  std::ostringstream modes;
2108  for( std::vector<std::string>::const_iterator i = mode_tokens_.begin(); i < mode_tokens_.end(); ++i){
2109  modes << *i << " ";
2110  }
2111  return modes.str();
2112 }
2113 
2115  Size const chiid,
2116  Size const exaro_sample_level,
2117  Size const ex_sample_level
2118 ) const {
2119  std::ostringstream ex_flags;
2120 
2121  if (exaro_sample_level == 1){
2122  ex_flags << "EX ARO " << chiid;
2123  } else if (exaro_sample_level > 1) {
2124  ex_flags << "EX ARO " << chiid << " LEVEL " << exaro_sample_level;
2125  } else if (ex_sample_level == 1){
2126  ex_flags << "EX " << chiid;
2127  } else if (ex_sample_level > 1){
2128  ex_flags << "EX " << chiid << " LEVEL " << ex_sample_level;
2129  } else {
2130  // use the default
2131  }
2132  return ex_flags.str();
2133 }
2134 
2136 
2137  std::ostringstream command_string;
2138  std::string task_name( task_mode() );
2139  if (task_name != "NATRO") command_string << " " << task_name;
2140 
2141  std::string ex1 = get_ex_flags( 1, ex1aro_sample_level_, ex1_sample_level_);
2142  if (ex1 != "") command_string << " " << ex1;
2143 
2144  std::string ex2 = get_ex_flags( 2, ex2aro_sample_level_, ex2_sample_level_);
2145  if (ex2 != "") command_string << " " << ex2;
2146 
2147  std::string ex3 = get_ex_flags( 3, 0, ex3_sample_level_);
2148  if (ex3 != "") command_string << " " << ex3;
2149 
2150  std::string ex4 = get_ex_flags( 4, 0, ex4_sample_level_);
2151  if (ex4 != "") command_string << " " << ex4;
2152 
2153  if( extrachi_cutoff_ != 18) command_string << " EX_CUTOFF " << extrachi_cutoff_;
2154 
2155  if( include_current()) command_string << " USE_INPUT_SC";
2156 
2157  //SCAN, AUTO, TARGET etc
2158  for (utility::vector1<std::string>::const_iterator i = behaviors_.begin(); i < behaviors_.end(); ++i){
2159  if (*i == "TARGET"){
2160  command_string << " TARGET ";
2161  if (target_type() == 0){
2162  command_string << "_";
2163  } else {
2164  command_string << target_type()->name();
2165  }
2166  } else {
2167  command_string << " " << *i;
2168  }
2169  }
2170 
2171  return command_string.str();
2172 }
2173 
2175  std::ostringstream task_string;
2176  task_string << "start" << std::endl;
2177 
2178  for (Size i = 1; i <= total_residue(); ++i){
2179  std::string residue_task_string = residue_tasks_[ i ].command_string( );
2180  if (residue_task_string != "" && residue_task_string != " ") {
2181  //std::cout << "residue_task_string -> '" << residue_task_string << "'." << std::endl;
2182  task_string << pose.pdb_info()->number(i);
2183  task_string << " " << pose.pdb_info()->chain(i);
2184  task_string << " " << residue_task_string << std::endl;
2185  }
2186  }
2187  return task_string.str();
2188 }
2189 
2190 
2191 ///@brief output highlights of the internal data of PackerTask_: for
2192 ///each residue whether it is to be packed, designed and which amino
2193 ///acids are allowed.
2194 
2195 std::ostream &
2196 operator << ( std::ostream & os, PackerTask const & task )
2197 {
2198  // (Matt O'Meara) Note that PackerTask is the BASE pure virtual
2199  // class while PackerTask_ is the DERIVED class.
2200  // I have put [this function] in this file (PackerTask_.cc)
2201  // because it exposed the internal data of a PackerTask_ object.
2202  // Although PackerTask_ is the only derived class of PackerTask, if
2203  // there were others, the << operator would probably have to be
2204  // different too.
2205  //sml If you have a derived child of PackerTask, and this function isn't working for you, create a PackerTask.print() pure virtual, move these contents to PackerTask_.print(), and have this function call PackerTask.print() so it will virtual-lookup the right function. You'd need to write your own print too of course. Google for "virtual friend function idiom".
2206 
2207  task.show( os );
2208  return os;
2209 }
2210 
2213  core::pose::Pose const & pose
2214 ){
2215  utility::vector1< bool > remapped_pack_residue;
2216  utility::vector1< ResidueLevelTask_ > remapped_residue_tasks;
2217 
2218  core::id::SequenceMapping reverse_seqmap = core::id::SequenceMapping( *seqmap );
2219  reverse_seqmap.reverse();
2220 
2221  for( Size ii = 1; ii <= pose.total_residue(); ++ii ){
2222  //core::Size new_pos = (*seqmap)[ii];
2223  core::Size old_pos = reverse_seqmap[ii];
2224 
2225  if( old_pos == 0 ){
2226  //find insertions and remapped residues old res index is 0
2227  remapped_residue_tasks.push_back( ResidueLevelTask_( pose.residue( ii ) ));
2228  remapped_residue_tasks[ii].initialize_from_command_line();
2229  remapped_pack_residue.push_back( true );
2230  }else if( old_pos != 0 ){
2231  // no change
2232  remapped_residue_tasks.push_back( residue_tasks_[ old_pos ]);
2233  remapped_pack_residue.push_back( pack_residue_[ old_pos ] );
2234  }
2235  }
2236 
2237  residue_tasks_ = remapped_residue_tasks;
2238  pack_residue_ = remapped_pack_residue;
2239  nres_ = pose.total_residue();
2241 
2242 }
2243 
2244 PackerTask &
2246  utility_exit_with_message("illegal");
2247  return *this;
2248 }
2249 
2250 
2251 } //namespace task
2252 } //namespace pack
2253 } //namespace core
2254