Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FilterScan.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 sw=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 /// @author Sarel Fleishman (sarelf@uw.edu)
14 #include <core/pose/PDBInfo.hh>
15 #include <fstream>
16 // AUTO-REMOVED #include <utility/file/FileName.hh>
17 #include <iostream>
18 // AUTO-REMOVED #include <basic/options/keys/in.OptionKeys.gen.hh>
19 // AUTO-REMOVED #include <basic/options/option_macros.hh>
21 #include <core/pose/Pose.hh>
24 #include <utility/tag/Tag.hh>
26 // AUTO-REMOVED #include <protocols/moves/DataMap.hh>
27 #include <basic/Tracer.hh>
33 // AUTO-REMOVED #include <core/pack/task/operation/TaskOperations.hh>
35 #include <core/chemical/AA.hh>
36 #include <utility/vector1.hh>
37 #include <protocols/moves/Mover.hh>
38 #include <protocols/jd2/util.hh>
39 #include <boost/foreach.hpp>
40 #define foreach BOOST_FOREACH
47 #include <protocols/jd2/Job.hh>
48 #include <utility/vector0.hh>
52 #include <utility/string_util.hh>
53 #include <ObjexxFCL/format.hh>
54 
55 //Auto Headers
56 #include <utility/excn/Exceptions.hh>
57 #include <basic/options/keys/OptionKeys.hh>
58 
59 namespace protocols {
60 namespace protein_interface_design{
61 namespace filters {
62 
63 static basic::Tracer TR( "protocols.protein_interface_design.filters.FilterScanFilter" );
64 static basic::Tracer TR_residue_scan( "ResidueScan" );
65 
66 ///@brief default ctor
68  parent( "FilterScan" ),
69  task_factory_( NULL ),
70  triage_filter_( NULL ),
71  filter_( NULL ),
72  resfile_general_property_( "nataa" ),
73  relax_mover_( NULL ),
74  scorefxn_( NULL ),
75  delta_( false ),
76  unbound_( false ),
77  report_all_( false ),
78  jump_( 0 ),
79  dump_pdb_( false ),
80  rtmin_( false )
81 {
82  using namespace basic::options;
83  using namespace basic::options::OptionKeys;
84  std::string temp_resfile_name( protocols::jd2::current_output_name() );
85  temp_resfile_name = temp_resfile_name + ".resfile";
86  resfile_name( temp_resfile_name );
87  delta_filters_.clear();
88 }
89 
90 bool
92  return delta_;
93 }
94 
95 void
96 FilterScanFilter::delta( bool const d ){
97  delta_ = d;
98 }
99 
100 bool
102  return unbound_;
103 }
104 
105 void
107  unbound_ = u;
108 }
109 
110 bool
112  return report_all_;
113 }
114 
115 void
117  report_all_ = ra;
118 }
119 
122  return jump_;
123 }
124 
125 void
127  jump_ = j;
128 }
129 
132  return relax_mover_;
133 }
134 
135 void
137  relax_mover_ = mover;
138 }
139 
142  return triage_filter_;
143 }
144 
145 void
148 }
151  return filter_;
152 }
153 
154 void
156  filter_ = filter;
157 }
158 
162 }
163 
164 void
167 }
168 
171  return resfile_name_;
172 }
173 
176  return score_log_file_;
177 }
178 
179 void
182 }
183 
184 void
187 }
188 
191 {
192  return task_factory_;
193 }
194 
195 void
197 {
199 }
200 
201 void
203  if( !unbound() ) return;
205  rbtm.step_size( 10000.0 );
206  rbtm.apply( pose );
207 }
208 
209 ///@brief introduces a single-point subsitution and then performs the repack, rtmin, and relax moves that are requested.
210 void
212  using namespace core::chemical;
213  using namespace core::pack::task;
214  using namespace core::pack::task::operation;
215  using namespace protocols::toolbox::task_operations;
216 
217  utility::vector1< bool > allowed_aas;
218  allowed_aas.clear();
219  allowed_aas.assign( num_canonical_aas, false );
220  allowed_aas[ target_aa ] = true;
221  TaskFactoryOP mut_res = new TaskFactory( *task_factory() );
222  DesignAroundOperationOP dao = new DesignAroundOperation;///restrict repacking to 8.0A around target res to save time
223  dao->design_shell( 6.0 );
224  dao->include_residue( resi );
225  mut_res->push_back( dao );
226  PackerTaskOP mutate_residue = mut_res->create_task_and_apply_taskoperations( pose );
227  mutate_residue->initialize_from_command_line().or_include_current( true );
228  for( core::Size resj = 1; resj <= pose.total_residue(); ++resj ){
229  if( resi != resj )
230  mutate_residue->nonconst_residue_task( resj ).restrict_to_repacking();
231  else
232  mutate_residue->nonconst_residue_task( resj ).restrict_absent_canonical_aas( allowed_aas );
233  }
234  TR<<"Mutating residue "<<pose.residue( resi ).name3()<<resi<<" to ";
236  if( core::pose::symmetry::is_symmetric( pose ) ) {
238  } else{
239  pack = new protocols::simple_moves::PackRotamersMover( scorefxn(), mutate_residue );
240  }
241  pack->apply( pose );
242  if( rtmin() ) {
243  // definition/allocation of RTmin mover must flag dependant, as some scoreterms are incompatable with RTmin initilization
245  if( core::pose::symmetry::is_symmetric( pose ) ) {
246  utility_exit_with_message("Cannot currently use FilterScan with rtmin on a symmetric pose!");
247  } else{
248  rtmin = new protocols::simple_moves::RotamerTrialsMinMover( scorefxn(), *mutate_residue );
249  }
250  rtmin->apply( pose );
251  }
252  TR<<pose.residue( resi ).name3()<<". Now relaxing..."<<std::endl;
253  if ( relax_mover() ) {
254  relax_mover()->apply( pose );
255  }
256 }
257 
260 
261 bool
263 {
264  using namespace core::pack::task;
265  using namespace core::pack::task::operation;
266  using namespace core::chemical;
267 
268  core::pose::Pose pose( p );
269 
270  PackerTaskCOP task = task_factory()->create_task_and_apply_taskoperations( pose );
271  utility::vector1< core::Size > being_designed;
272  being_designed.clear();
273 
274  for( core::Size resi = 1; resi <= pose.total_residue(); ++resi ){
275  if( task->residue_task( resi ).being_designed() && pose.residue(resi).is_protein() )
276  being_designed.push_back( resi );
277  }
278  if( being_designed.empty() ) {
279  TR.Warning << "WARNING: No residues are listed as designable." << std::endl;
280  return true;
281  }
282  std::map< core::Size, utility::vector1< AA > > residue_id_map;
283  std::map< std::pair< core::Size, AA >, std::pair< core::Real, bool > > residue_id_val_map; // position, aa identity : report filter value, triage filter accepted?
284  residue_id_map.clear(); residue_id_val_map.clear();
285  unbind( pose );
286  core::pose::Pose const pose_orig( pose );// const to ensure that nothing silly happens along the way...
287  core::Real baseline( 0.0 );
288  foreach( core::Size const resi, being_designed ){
289  pose = pose_orig;
290  ///compute baseline
291  single_substitution( pose, resi, pose.residue( resi ).aa() ); /// mutates to self. This simply activates packing/rtmin/relax at the site. By doing this on a per residue basis we ensure that the baseline is computed in exactly the same way as the mutations
292 // pose.dump_scored_pdb( "at_baseline.pdb", *scorefxn() );
293  foreach( protocols::simple_filters::DeltaFilterOP const delta_filter, delta_filters_ ){
294  std::string const fname( delta_filter->get_user_defined_name() );
295  core::Real const fbaseline( delta_filter->filter()->report_sm( pose ) );
296  delta_filter->baseline( fbaseline );
297  TR<<"Computed baseline at position "<<resi<<" with filter "<<fname<<" is "<<fbaseline<<std::endl;
298  }
299  if( delta_filters_.size() == 0 )
300  baseline = filter()->report_sm( pose );
301  typedef std::list< ResidueTypeCOP > ResidueTypeCOPList;
302  ResidueTypeCOPList const & allowed( task->residue_task( resi ).allowed_residue_types() );
303  utility::vector1< AA > allow_temp;
304  allow_temp.clear();
305  foreach( ResidueTypeCOP const t, allowed ){
306  allow_temp.push_back( t->aa() );
307  }
308  foreach( AA const target_aa, allow_temp ){
309  pose = pose_orig;
310  single_substitution( pose, resi, target_aa );
311 // pose.dump_scored_pdb( "after_mut.pdb", *scorefxn() );
312  bool triage_filter_pass( false );
313  if( delta_filters_.size() > 0 ){
314  foreach( protocols::simple_filters::DeltaFilterCOP const delta_filter, delta_filters_ ){
315  triage_filter_pass = delta_filter->apply( pose );
316  if( !triage_filter_pass )
317  break;
318  }
319  }
320  else
321  triage_filter_pass = triage_filter()->apply( pose );
322  if( !triage_filter_pass ){
323  TR<<"Triage filter fails"<<std::endl;
324  if(report_all_) {
325  residue_id_val_map[ std::pair< core::Size, AA >( resi, target_aa ) ] = std::pair< core::Real, bool >(filter()->report_sm( pose ), false);
326  }
327  continue;
328  }
329  TR<<"Triage filter succeeds"<<std::endl;
330  residue_id_val_map[ std::pair< core::Size, AA >( resi, target_aa ) ] = std::pair< core::Real, bool >(filter()->report_sm( pose ), true);
331  residue_id_map[ resi ].push_back( target_aa );
332  if( dump_pdb() ){
333  using namespace protocols::jd2;
335  std::stringstream fname;
336  fname << job->input_tag() << pose_orig.residue( resi ).name3() << resi << pose.residue( resi ).name3()<<".pdb";
337  TR<<"Saving pose "<<fname.str();
338  pose.dump_scored_pdb( fname.str(), *scorefxn() );
339  }
340  TR.flush();
341  }//foreach target_aa
342  }//foreach resi
343  if( resfile_name() != "" ){
344  std::ofstream resfile;
345  resfile.open( resfile_name().c_str(), std::ios::out );
346  resfile << resfile_general_property()<<"\nstart\n";
347  for( std::map< core::Size, utility::vector1< AA > >::const_iterator pair = residue_id_map.begin(); pair != residue_id_map.end(); ++pair ){
348  resfile << pose.pdb_info()->number( pair->first )<<'\t'<<pose.pdb_info()->chain( pair->first )<<"\tPIKAA\t";
349  foreach( AA const aa, pair->second )
350  resfile<<oneletter_code_from_aa( aa );
351  resfile<<'\n';
352  }
353  resfile.close();
354  } //fi resfile_name()
355 
356  if ( score_log_file() != "" ) {
357  std::ofstream scorefile;
358  scorefile.open( score_log_file().c_str(), std::ios::out );
359 
360  using namespace ObjexxFCL::fmt;
361  for( std::map< std::pair< core::Size, AA >, std::pair< core::Real, bool > >::const_iterator pair = residue_id_val_map.begin(); pair != residue_id_val_map.end(); ++pair ){
362  core::conformation::Residue const native_res( pose.conformation().residue( pair->first.first ) );
363  scorefile
364  << pair->first.first << '\t'
365  << p.residue( pair->first.first ).name1() <<'\t'
366  << oneletter_code_from_aa( pair->first.second )<<'\t'
367  << F(9,6, pair->second.first) <<std::endl;
368  }
369  scorefile.close();
370  } // fi score_log_file()
371 
372  for( std::map< std::pair< core::Size, AA >, std::pair< core::Real, bool > >::const_iterator pair = residue_id_val_map.begin(); pair != residue_id_val_map.end(); ++pair ){
373  core::conformation::Residue const native_res( pose.conformation().residue( pair->first.first ) );
374  TR_residue_scan<<resfile_name()<<'\t'
375  << pair->first.first<<'\t'
376  << oneletter_code_from_aa( pair->first.second )<<'\t'
377  <<( delta() ? pair->second.first - baseline : pair->second.first )
378  <<(pair->second.second?"":"\tTRIAGED")<<std::endl;
379  }
380  TR.flush();
381  return true;
382 }
383 
386 {
387  return( 1 );
388 }
389 
390 void
391 FilterScanFilter::report( std::ostream &, core::pose::Pose const & ) const
392 {
393 }
394 
395 void
398  protocols::filters::Filters_map const &filters,
399  protocols::moves::Movers_map const & movers,
400  core::pose::Pose const & )
401 {
402  TR << "FilterScanFilter"<<std::endl;
403  runtime_assert( tag->hasOption( "filter" ) || tag->hasOption( "delta_filters" ));
405  std::string const triage_filter_name( tag->getOption< std::string >( "triage_filter", "true_filter" ) );
406  protocols::filters::Filters_map::const_iterator triage_filter_it( filters.find( triage_filter_name ) );
407 
408  //These #ifdefs are a terrible hack to work around a compiler bug in mpicxx. sorry
409 #ifdef USEMPI
410  if( triage_filter_it == filters.end() )
411  utility_exit_with_message( "Triage filter "+triage_filter_name+" not found" );
412 #endif
413 #ifndef USEMPI
414  if( triage_filter_it == filters.end() )
415  throw utility::excn::EXCN_RosettaScriptsOption( "Triage filter "+triage_filter_name+" not found" );
416 #endif
417 
418  triage_filter( triage_filter_it->second );
419 
420  std::string const filter_name( tag->getOption< std::string >( "filter", "true_filter" ) );
421  protocols::filters::Filters_map::const_iterator filter_it( filters.find( filter_name ) );
422 
423 #ifdef USEMPI
424  if( filter_it == filters.end() )
425  utility_exit_with_message( "Filter "+filter_name+" not found" );
426 #endif
427 #ifndef USEMPI
428  if( filter_it == filters.end() )
429  throw utility::excn::EXCN_RosettaScriptsOption( "Filter "+filter_name+" not found" );
430 #endif
431 
432  filter( filter_it->second );
433  std::string const relax_mover_name( tag->getOption< std::string >( "relax_mover", "null" ) );
434  protocols::moves::Movers_map::const_iterator mover_it( movers.find( relax_mover_name ) );
435 
436 #ifdef USEMPI
437  if( mover_it == movers.end() )
438  utility_exit_with_message( "Relax mover "+relax_mover_name+" not found" );
439 #endif
440 #ifndef USEMPI
441  if( mover_it == movers.end() )
442  throw utility::excn::EXCN_RosettaScriptsOption( "Relax mover "+relax_mover_name+" not found" );
443 #endif
444 
445  relax_mover( mover_it->second );
446 
447  delta( tag->getOption< bool >( "delta", false ) );
448  report_all( tag->getOption< bool >( "report_all", false ) );
450  resfile_name( tag->getOption< std::string >( "resfile_name",resfile_name() ) );
451  resfile_general_property( tag->getOption< std::string >( "resfile_general_property", "nataa" ) );
452  rtmin( tag->getOption< bool >( "rtmin", false ) );
453  score_log_file( tag->getOption< std::string >( "score_log_file",score_log_file() ) );
454  dump_pdb( tag->getOption< bool >( "dump_pdb", false ) );
455 
456 
457  utility::vector1< std::string > delta_filter_names;
458  delta_filter_names.clear();
459  if( tag->hasOption( "delta_filters" ) ){
460  delta_filter_names = utility::string_split( tag->getOption< std::string >( "delta_filters" ), ',' );
461  TR<<"Using delta filters: ";
462  foreach( std::string const fname, delta_filter_names ){
463  delta_filters_.push_back( dynamic_cast< protocols::simple_filters::DeltaFilter * >( protocols::rosetta_scripts::parse_filter( fname, filters )() ) );
464  TR<<fname<<",";
465  }
466  TR<<std::endl;
467  }
468  TR<<"with options resfile_name: "<<resfile_name()<<" resfile_general_property "<<resfile_general_property()<<" unbound "<<unbound()<<" jump "<<jump()<<" delta "<<delta()<<" filter "<<filter_name<<" dump_pdb "<<dump_pdb()<<" rtmin "<<rtmin()<<std::endl;
469 }
470 
473  return scorefxn_;
474 }
475 
476 void
479 }
480 
483  return new FilterScanFilter();
484 }
485 
487 
490  return new FilterScanFilter( *this );
491 }
492 
495 
497 FilterScanFilterCreator::keyname() const { return "FilterScan"; }
498 
499 void
501  dump_pdb_ = d;
502 }
503 
504 bool
506  return dump_pdb_;
507 }
508 
509 } // filters
510 } // protein_interface_design
511 } // protocols