Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TryRotamers.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 
11 /// @file protocols/protein_interface_design/movers/TryRotamers.cc
12 /// @brief
13 /// @author Sarel Fleishman (sarelf@u.washington.edu), Jacob Corn (jecorn@u.washington.edu)
14 
15 // Unit headers
18 
19 // Project headers
20 #include <core/pose/Pose.hh>
21 #include <utility/tag/Tag.hh>
25 #include <core/kinematics/Jump.hh>
30 #include <utility/string_util.hh>
31 
32 #include <core/graph/Graph.hh>
34 #include <core/pose/selection.hh>
35 #include <boost/foreach.hpp>
36 #define foreach BOOST_FOREACH
37 #include <basic/Tracer.hh>
39 
40 #include <core/pose/util.hh>
41 #include <utility/vector0.hh>
42 #include <utility/vector1.hh>
43 
44 
45 namespace protocols {
46 namespace protein_interface_design {
47 namespace movers {
48 
49 using namespace core;
50 using namespace std;
51 using namespace core::scoring;
52 using namespace protocols::moves;
53 
54 static basic::Tracer TR( "protocols.protein_interface_design.movers.TryRotamers" );
55 
58 {
60 }
61 
64  return new TryRotamers;
65 }
66 
69 {
70  return "TryRotamers";
71 }
72 
73 
75  protocols::moves::Mover( TryRotamersCreator::mover_name() )
76 { }
77 
79  ScoreFunction const & scorefxn,
80  protocols::filters::Filter const & final_filter,
81  Size explosion, // rotamer explosion
82  Size jump_num,
83  bool clash_check
84 ) :
85  protocols::moves::Mover( TryRotamersCreator::mover_name() ),
86  scorefxn_(new ScoreFunction(scorefxn)),
87  resnum_(resnum),
88  jump_num_(jump_num),
89  clash_check_(clash_check),
90  explosion_(explosion),
91  final_filter_(final_filter.clone())
92 {}
93 
94  /// @note Pass everything through the final filter (True Filter)
96  core::scoring::ScoreFunction const& scorefxn,
97  Size explosion, // rotamer explosion
98  Size jump_num,
99  bool clash_check
100  ) :
101  protocols::moves::Mover(),
102  scorefxn_(new ScoreFunction(scorefxn)),
103  resnum_(resnum),
104  jump_num_(jump_num),
105  clash_check_(clash_check),
106  explosion_(explosion),
107  final_filter_(new protocols::filters::TrueFilter)
108 {}
109 
111 
112 void
114 {
115  //using namespace rotamer_set;
116  using namespace core::scoring;
117  using namespace core::pack::task;
118  using namespace core::pack::rotamer_set;
119 
120  core::kinematics::FoldTree const saved_ft( pose.fold_tree() );
121 
122  //SEGFAULT REMOVED: OL 3/6/12:
123  //using here a const reference causes segfaults, probably due to subsequent fold-tree manipulation which
124  //would invalidate residue objects.
125  Residue res_ = pose.residue( resnum_ );
126 
127  TR << "current fold-tree:\n" << pose.fold_tree() << std::endl;
128  if( automatic_connection_ ){
129  core::kinematics::FoldTree const new_ft( make_hotspot_foldtree( pose ) );
130  TR<<"New foldtree:\n"<<new_ft<<std::endl;
131  pose.fold_tree( new_ft );
132  }
133 
134  foreach( core::Size const resid, shove_residues_ )
135  core::pose::add_variant_type_to_pose_residue( pose, "SHOVE_BB", resid );
136 
138 
139  if ( !rotset_ || rotset_->num_rotamers() == 0 ) {
141  ptask->set_bump_check( clash_check_ );
142 
143  ResidueLevelTask & restask( ptask->nonconst_residue_task( resnum_ ) );
144  graph::GraphOP packer_graph = new graph::Graph( pose.total_residue() );
145  restask.or_ex1( true );
146  restask.or_ex2( true );
147  restask.or_ex3( true );
148  restask.or_ex4( true );
149  if( explosion_ > 0 ) restask.or_ex1_sample_level(core::pack::task::EX_FOUR_HALF_STEP_STDDEVS);
150  if( explosion_ > 1 ) restask.or_ex2_sample_level(core::pack::task::EX_FOUR_HALF_STEP_STDDEVS);
151  if( explosion_ > 2 ) restask.or_ex3_sample_level(core::pack::task::EX_FOUR_HALF_STEP_STDDEVS);
152  if( explosion_ > 3 ) restask.or_ex4_sample_level(core::pack::task::EX_FOUR_HALF_STEP_STDDEVS);
153  restask.or_include_current( true );
154 
155  restask.restrict_to_repacking();
156  RotamerSetFactory rsf;
157  rotset_ = rsf.create_rotamer_set( res_ );
158 
159  rotset_->set_resid( resnum_ );
160  rotset_->build_rotamers( pose, *scorefxn_, *ptask, packer_graph, false );
161  rotamer_it_ = rotset_->begin();
162  TR<<"building rotamer set of " <<rotset_->num_rotamers()<< " different rotamers ...\n";
163 
164  }//end building rotamer set
165 
166  // job distributor iterates ...
167  if ( rotamer_it_ == rotset_->end() )
168  {
170  TR<<"reached the end of the rotamer ensemble " <<std::endl;
171  pose.fold_tree( saved_ft );
172  return;
173  }
174 
175  if ( final_filter_->apply( pose ) )
176  {
177  if( jump_num_ > 0 ) { // Let 0 indicate no jumps
178  core::kinematics::Jump const saved_jump( pose.jump( jump_num_ ) );
179  pose.replace_residue ( resnum_, **rotamer_it_, false/*orient bb*/ );
180  pose.set_jump_now( jump_num_, saved_jump );
181  }
182  else { // no jumps to save
183  pose.replace_residue ( resnum_, **rotamer_it_, false/*orient bb*/ );
184  }
185  TR << "TryRotamers passed the final_filter" <<std::endl;
187  ++rotamer_it_;
188  pose.fold_tree( saved_ft );
189  return;
190  }
191  else
192  {
194  ++rotamer_it_;
195  TR << std::endl;
196  }
197  pose.fold_tree( saved_ft );
198 }
199 
203 }
204 
205 void
207  DataMap & data,
208  protocols::filters::Filters_map const &filters,
209  Movers_map const &,
210  Pose const & pose)
211 {
212  resnum_ = core::pose::get_resnum( tag, pose );
213  automatic_connection_ = tag->getOption< bool >( "automatic_connection", 1 );
214  string const scorefxn_name( tag->getOption<string>( "scorefxn", "score12" ) );
215  scorefxn_ = new ScoreFunction( *(data.get< ScoreFunction * >( "scorefxns", scorefxn_name) ));
216  jump_num_ = tag->getOption<core::Size>( "jump_num", 1);
217  std::string const final_filter_name( tag->getOption<std::string>( "final_filter", "true_filter" ) );
218  protocols::filters::Filters_map::const_iterator find_filter( filters.find( final_filter_name ));
219  clash_check_ = tag->getOption<bool>("clash_check", 0 );
220  explosion_ = tag->getOption<core::Size>( "explosion", 0);
221  bool const filter_found( find_filter != filters.end() );
222  if( filter_found )
223  final_filter_ = find_filter->second->clone();
224  else {
225  if( final_filter_name != "true_filter" ){
226  TR<<"***WARNING WARNING! Filter defined for TryRotamers not found in filter_list!!!! Defaulting to truefilter***"<<std::endl;
227  runtime_assert( filter_found );
228  }
229  else
231  }
232 
233  if( tag->hasOption( "shove" ) ){
234  std::string const shove_val( tag->getOption< std::string >( "shove" ) );
235  utility::vector1< std::string > const shove_keys( utility::string_split( shove_val, ',' ) );
236  foreach( std::string const key, shove_keys ){
237  core::Size const resnum( core::pose::parse_resnum( key, pose ) );
238  shove_residues_.push_back( resnum );
239  TR<<"Using shove atomtype for "<< key <<'\n';
240  }
241  }
242 
243  TR<<"TryRotamers was instantiated using scorefxn="<<scorefxn_name<<", jump_number="<<jump_num_<< ", clash_check=" << clash_check_ << ", and explosion=" << explosion_ << std::endl;
244 
245 }
246 
247 } //movers
248 } //protein_interface_design
249 } //protocols
250