Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MapHotspot.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)
14 
15 // Unit headers
18 
19 // Package headers
20 
21 // Project headers
22 #include <core/kinematics/Edge.hh>
25 #include <protocols/moves/Mover.hh>
27 #include <core/chemical/AA.hh>
28 #include <boost/foreach.hpp>
29 #include <algorithm>
32 #include <core/pose/Pose.hh>
34 #include <utility/tag/Tag.hh>
38 
44 
45 #include <core/graph/Graph.hh>
46 #define foreach BOOST_FOREACH
48 #include <basic/Tracer.hh>
51 
52 #include <core/pose/util.hh>
53 #include <utility/vector0.hh>
54 #include <utility/vector1.hh>
55 
56 //Auto Headers
58 
59 
60 
61 namespace protocols {
62 namespace protein_interface_design {
63 namespace movers {
64 
65 using namespace core;
66 using namespace std;
67 using namespace protocols::moves;
68 
69 static basic::Tracer TR( "protocols.protein_interface_design.movers.MapHotspot" );
70 
73 {
75 }
76 
79  return new MapHotspot;
80 }
81 
84 {
85  return "MapHotspot";
86 }
87 
88 MapHotspot::MapHotspot() : protocols::moves::Mover( MapHotspotCreator::mover_name() ) {}
89 
91 
92 /// @details function for minimizing the interface
93 void
95  using namespace core::scoring;
96  using namespace utility;
97 
98  core::Size const num_jump( pose.num_jump() );
99  ScoreFunctionCOP scorefxn( minimization_scorefxns_[ num_jump ] );
100  if( scorefxn == 0 ){
101  TR<<"skipping minimization b/c no scorefxn was defined"<<std::endl;
102  return;
103  }
104  core::kinematics::FoldTree const hotspot_ft( make_hotspot_foldtree( pose ) );
105  TR<<"imposing hotspot foldtree "<<hotspot_ft;
106  pose.fold_tree( hotspot_ft );
107  vector1< bool > const nomin( pose.total_residue(), false );
108  vector1< bool > minsc( pose.total_residue(), false );
109  minsc[ pose.total_residue() ] = true;
110  vector1< core::Size > const empty;
111  vector1< bool > minrb_last( num_jump, false );
112  minrb_last[ num_jump ] = true;
113  MinimizeInterface( pose, scorefxn, nomin/*minbb*/, minsc, minrb_last, false/*optimize foldtree*/, empty/*target res*/ );
114  if( num_jump == 1 ) return;
115  vector1< bool > minrb_all( num_jump, true );
116  minrb_all[ num_jump ] = true;
117  MinimizeInterface( pose, scorefxn, nomin/*minbb*/, minsc, minrb_all, false/*optimize foldtree*/, empty/*target res*/ );
118 
119 }
120 
121 /// @details utility function for dumping out a pose from GenerateMap
122 void
124  std::string residues("");
125  for( core::Size chain=2; chain<=pose.num_jump()+1; ++chain ){
126  core::Size const residue_num( pose.conformation().chain_begin( chain ) );
127  char const residue_type( pose.residue( residue_num ).name1() );
128  residues += residue_type;
129  }
131  std::ostringstream strm;
132  strm<<file_name_prefix_<<"_"<<residues<<".pdb";
133  pose.dump_pdb( strm.str() );
134 }
135 
136 /// @details Utility function to deal with all of the ugliness of copying a single residue from one pose to another while conserving the jump
137 void
138 copy_hotspot_to_pose( core::pose::Pose const & src, core::pose::Pose & dest, core::Size const src_resi, core::chemical::ResidueType const restype, core::Size const jump )
139 {
140  using namespace core::kinematics;
141  using namespace core::conformation;
142  using namespace core::chemical;
143  Jump const saved_jump( src.jump( jump ) );
144  FoldTree const saved_ft( src.fold_tree() );
145  FoldTree new_ft;
146  new_ft.clear();
147 
148  foreach( Edge const edge, saved_ft ){
149  if( (core::Size) edge.start() <= src_resi && ( core::Size )edge.stop() <= src_resi )
150  new_ft.add_edge( edge );
151  }//foreach edge
152 
153  ResidueOP new_res = ResidueFactory::create_residue( restype );
154 
155  dest.append_residue_by_jump( *new_res, dest.total_residue(),"","",true/*new chain*/ );
157  dest.fold_tree( new_ft );
158  using namespace core::chemical;
161 // core::pose::add_lower_terminus_type_to_pose_residue( dest, src_resi-1 );
162  dest.conformation().update_polymeric_connection( src_resi );
163 // dest.conformation().update_polymeric_connection( src_resi-1 );
164  dest.set_jump_now( jump, saved_jump );
166 }
167 
168 /// @details utility function for creating a rotamer set an managing all of the rotamer options
170 MapHotspot::create_rotamer_set( core::pose::Pose const & pose, core::Size const hotspot_resnum, core::Size const explosion ) const
171 {
172  using namespace core::pack::task;
173  using namespace core::pack::rotamer_set;
174  using namespace core::pack::task::operation;
175  using namespace core::scoring;
176  TaskFactory tf;
178  RotamerExplosionOP rotamer_exp_operation = new RotamerExplosion( hotspot_resnum, EX_THREE_THIRD_STEP_STDDEVS, explosion );
179  InitializeFromCommandlineOP init_from_commandline = new InitializeFromCommandline;
180  RestrictResidueToRepackingOP restrict_to_rep_operation = new RestrictResidueToRepacking;
181  restrict_to_rep_operation->include_residue( hotspot_resnum );
182  tf.push_back( rotamer_exp_operation );
183  tf.push_back( restrict_to_rep_operation );
184  tf.push_back( init_from_commandline );
185  PackerTaskCOP ptask( tf.create_task_and_apply_taskoperations( pose ) );
186  RotamerSetFactory rsf;
187  RotamerSetOP rotset = rsf.create_rotamer_set( pose.residue( hotspot_resnum ) );
188  rotset->set_resid( hotspot_resnum );
189  graph::GraphOP packer_graph = new graph::Graph( pose.total_residue() );
190  rotset->build_rotamers( pose, *score12, *ptask, packer_graph, false );
191  TR<<"Created rotamer set for residue "<<hotspot_resnum<<"with explosion="<<explosion<<std::endl;
192  return( rotset );
193 }
194 
195 /// @details A function that recursively goes over all jumps. Within each function, the residue-identities
196 /// related to that jump are cycled, and for each of those, it iterates over the rotamer set.
197 /// for each residue type, the best-energy (score12) rotamer, that fulfills all of the user-defined filters
198 /// is chosen and then we move deeper into the recursion with the next jump. Stopping condition is the
199 /// final iteration over the final jump at which point a decoy is output, or if no rotamer for the
200 /// particular residue identity meets all filters (exit with no decoy generation).
201 void
202 MapHotspot::GenerateMap( core::pose::Pose const & start_pose, core::pose::Pose & curr_pose, core::Size const jump_number )
203 {
204  core::Size const hotspot_resnum( start_pose.conformation().chain_begin( jump_number+1 ) );
205  core::pose::Pose const saved_pose_1( curr_pose );
206  TR<<"Allowed residues: "<< allowed_aas_per_jump_[ jump_number ]<<std::endl;
207  foreach( char const residue_type1, allowed_aas_per_jump_[ jump_number ] ){//iterate over residue types
208  using namespace core::pack::task;
209  using namespace core::pack::rotamer_set;
210  using namespace core::chemical;
211  using namespace core::scoring;
212  ResidueTypeSet const & residue_set( start_pose.residue( hotspot_resnum ).residue_type_set() ); //residue_type_set is noncopyable, so we have to use the &
213  ResidueType const & restype( residue_set.name_map(name_from_aa( aa_from_oneletter_code( residue_type1 ) ) ) );
214 
215  copy_hotspot_to_pose( start_pose, curr_pose, hotspot_resnum, restype, jump_number );
216  core::pack::rotamer_set::RotamerSetCOP rotset( create_rotamer_set( curr_pose, hotspot_resnum, explosion_[ jump_number ]) );
217 
218  core::pose::Pose const saved_pose_2( curr_pose );
219  core::Size rotset_size( 0 ); //ugly but I don't know how to find the size of cacheable data in rotset
220  for( Rotamers::const_iterator rot_it = rotset->begin(); rot_it!=rotset->end(); ++rot_it, ++rotset_size ) {};
221  TR<<"Iterating over "<<rotset_size<<" rotamers for residue "<<residue_type1<<" in jump #"<<jump_number<<std::endl;
222  core::Size curr_rotamer_num( 1 );
223  core::pose::Pose best_pose;
224  core::Real lowest_energy( 100000 );
226  simple_filters::ScoreTypeFilter const pose_total_score( score12, total_score, 100/*threshold*/ );
227  for( Rotamers::const_iterator rot_it = rotset->begin(); rot_it!=rotset->end(); ++rot_it ){
228  TR<<"Current rotamer: "<<curr_rotamer_num++<<'\n';
230  curr_pose.replace_residue( hotspot_resnum, *rot, false );
231  jump_movers_[ jump_number ]->apply( curr_pose );
232  MinimizeHotspots( curr_pose );
233  bool pass_filter( true );
234  for( SizeFilter_map::const_iterator jump_filter_it( jump_filters_.begin() ); jump_filter_it!=jump_filters_.end(); ++jump_filter_it ){ // all filters must be satisfied
235  if( jump_filter_it->first <= jump_number ){
236  pass_filter = jump_filter_it->second->apply( curr_pose );
237  if( !pass_filter ) break;
238  }//fi
239  }//for jump filter
240  if( pass_filter ){
241  core::Real const total_score( pose_total_score.compute( curr_pose ) );
242  if( total_score <= lowest_energy ){
243  TR.Debug << "Current lowE=" << total_score << " Prev lowE=" << lowest_energy << std::endl;
244  best_pose = curr_pose;
245  lowest_energy = total_score;
246  }//fi total_score
247  }//fi pass_filter
248  curr_pose = saved_pose_2;
249  }//foreach rotamer
250  if( lowest_energy >= 10000 )
251  TR<<"No optimal pose found in jump "<<jump_number<<". Consider relaxing filters."<<std::endl;
252  else{
253  curr_pose = best_pose;
254  if( jump_number == start_pose.num_jump() ) // stopping condition
255  output_pose( curr_pose );
256  else
257  GenerateMap( start_pose, curr_pose, jump_number + 1 );
258  }// esle
259  curr_pose = saved_pose_1;
260  }//foreach residue type
261 }
262 
263 void
265  core::pose::Pose chainA = pose.split_by_chain( 1 );
266  core::pose::Pose const start_pose( pose );
267  pose = chainA; // this will make the viewer shows the working pose
268  GenerateMap( start_pose, pose, 1 );
270 }
271 
275 }
276 
277 void
280  protocols::filters::Filters_map const &filters,
281  protocols::moves::Movers_map const &movers,
282  core::pose::Pose const & pose)
283 {
284  using namespace utility::tag;
285 
286  clash_check_ = tag->getOption<bool>("clash_check", 0 );
287  file_name_prefix_ = tag->getOption< std::string >( "file_name_prefix", "map_hs" );
288 
289  utility::vector0< TagPtr > const branch_tags( tag->getTags() );
290  foreach( TagPtr const btag, branch_tags ){
291  std::string const btag_name( btag->getName() );
292  if( btag_name == "Jumps" ){
293  utility::vector0< TagPtr > const jump_tags( btag->getTags() );
294  runtime_assert( jump_tags.size() == pose.num_jump() );
295  foreach( TagPtr j_tag, jump_tags ){
296  core::Size const jump( j_tag->getOption< core::Size >( "jump" ) );
297  bool const jump_fine( jump <= pose.num_jump() );
298  if( !jump_fine ) TR.Error<<"Jump "<<jump<<" is larger than the number of jumps in pose="<<pose.num_jump()<<std::endl;
299  runtime_assert( jump_fine );
300  explosion_[ jump ] = j_tag->getOption<core::Size>( "explosion", 0 );
301  std::string const filter_name( j_tag->getOption<std::string>( "filter_name", "true_filter" ));
302  protocols::filters::Filters_map::const_iterator find_filter( filters.find( filter_name ));
303  bool const filter_found( find_filter != filters.end() );
304  if( !filter_found ) TR.Error<<"Filter "<<filter_name<<" not found in MapHotspot parsing"<<std::endl;
305  runtime_assert( filter_found );
306  jump_filters_[ jump ] = find_filter->second;
307  std::string const mover_name( j_tag->getOption< std::string >( "mover_name", "null" ) );
308  protocols::moves::Movers_map::const_iterator find_mover( movers.find( mover_name ) );
309  bool const mover_found( find_mover != movers.end() );
310  if( !mover_found ) TR.Error<<"Mover "<<mover_name<<" not found in MapHotspot parsing"<<std::endl;
311  runtime_assert( mover_found );
312  jump_movers_[ jump ] = find_mover->second;
313  std::string const allowed_aas( j_tag->getOption< std::string >( "allowed_aas", "ADEFIKLMNQRSTVWY" ) );
314  allowed_aas_per_jump_[ jump ] = allowed_aas;
315  std::string const scorefxn_name( j_tag->getOption< std::string >( "scorefxn_minimize", "score12" ) );
316  if( !data.has( "scorefxns", scorefxn_name ) ){
317  TR<<"Scorefxn "<<scorefxn_name<<" not found. Will not minimize sidechain.";
318  minimization_scorefxns_[ jump ] = 0;
319  }
320  else
321  minimization_scorefxns_[ jump ] = new core::scoring::ScoreFunction( *(data.get< core::scoring::ScoreFunction * >( "scorefxns", scorefxn_name ) ) );
322  }//foreach j_tag
323  }//fi btag_name=="Jumps"
324  else
325  TR.Warning<<"Unrecognized branch tag from MapHotspot: "<<btag_name<<std::endl;
326  }//foreach branch_tag
327 }
328 
329 } //movers
330 } //protein_interface_design
331 } //protocols
332