Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RelativePoseFilter.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)
16 #include <core/pose/PDBInfo.hh>
21 #include <core/chemical/AA.hh>
24 #include <core/pose/Pose.hh>
26 #include <utility/tag/Tag.hh>
28 // AUTO-REMOVED #include <protocols/moves/DataMap.hh>
29 #include <basic/Tracer.hh>
31 #include <core/pose/selection.hh>
32 #include <boost/foreach.hpp>
33 #define foreach BOOST_FOREACH
34 #include <utility/string_util.hh>
42 #include <basic/options/option.hh>
43 #include <basic/options/keys/in.OptionKeys.gen.hh>
44 
45 #include <utility/vector0.hh>
46 #include <utility/vector1.hh>
47 
48 
49 namespace protocols {
50 namespace simple_filters {
51 
52 static basic::Tracer TR( "protocols.simple_filters.RelativePoseFilter" );
53 
54 ///@brief default ctor
56  parent( "RelativePose" ),
57  filter_( NULL ),
58  relax_mover_( NULL ),
59  dump_pose_fname_( "" ),
60  pose_( NULL ),
61  scorefxn_( NULL ),
62  packing_shell_( 8.0 ),
63  thread_( true ),
64  baseline_( true ),
65  baseline_val_( -9999 ),
66  unbound_( false ),
67  copy_stretch_( false ),
68  symmetry_definition_(""),
69  rtmin_( false )
70 {
71  alignment_.clear();
72 }
73 
74 void
76  thread_ = t;
77 }
78 
79 bool
81  return thread_;
82 }
83 
84 void
86  packing_shell_ = s;
87 }
88 
91  return packing_shell_;
92 }
93 
96  return dump_pose_fname_;
97 }
98 
99 void
101  dump_pose_fname_ = s;
102 }
103 
106  return pose_;
107 }
108 
109 void
111  pose_= pose;
112 }
113 
114 void
116  filter_ = filter;
117 }
118 
121  return filter_;
122 }
123 
124 bool
126 {
127  core::pose::PoseCOP threaded_pose( thread_seq( p ) );
128  return( filter()->apply( *threaded_pose ) );
129 }
130 
133  using namespace core::chemical;
134  using namespace protocols::toolbox::task_operations;
135 
136  core::pose::PoseOP copy_pose( new core::pose::Pose( *pose() ) ); // don't let the pose drift
137  // if(symmetry_definition()!=""){
138  // if(core::pose::symmetry::is_symmetric(*copy_pose)) {
139  // core::pose::symmetry::extract_asymmetric_unit(*copy_pose,*copy_pose);
140  // }
141  // core::pose::symmetry::make_symmetric_pose(*pose_,*symmdata_);
142  // }
143  if( unbound() ){
144  protocols::rigid::RigidBodyTransMover rbtm( *copy_pose, 1 );
145  rbtm.step_size( 10000.0 );
146  rbtm.apply( *copy_pose );
147  }
148  if( copy_stretch() ){ // just copy the aligned stretch, and then go straight to relax. No repacking
149  copy_pose->copy_segment( alignment_.size()/*how many residues*/, p/*src*/, alignment_.begin()->first/*start on target*/, alignment_.begin()->second/*start on src*/ );
150  copy_pose->conformation().detect_disulfides();
151  }
152  else{ // no copy_stretch. Repack etc. carefully
154  dao->design_shell( packing_shell() );
155  std::vector< core::Size > diffs;
156  diffs.clear();
157  TR<<"differences at positions: ";
158  for( std::map< core::Size, core::Size >::const_iterator aln=alignment_.begin(); aln!=alignment_.end(); ++aln ){
159  char const res1_name(pose()->conformation().residue( aln->first ).name1());
160  char const res2_name(p.conformation().residue( aln->second ).name1());
161  if( res1_name != res2_name ) {
162  diffs.push_back( aln->first );
163  TR<<res1_name<<aln->first<<res2_name<<", ";
164  }
165  }
166  TR<<std::endl;
167  if( baseline() )
168  TR<<"baseline: "<<baseline_val()<<std::endl;
169  foreach( core::Size const d, diffs )
170  dao->include_residue( d );
171  using namespace core::pack::task;
172  using namespace core::pack::task::operation;
173  TaskFactoryOP tf = new TaskFactory;
174  tf->push_back( dao );
175  tf->push_back( new IncludeCurrent );
176  tf->push_back( new InitializeFromCommandline );
177  core::pack::task::PackerTaskOP pack = tf->create_task_and_apply_taskoperations( *pose() );
178  for( core::Size i = 1; i<=pose()->total_residue(); ++i ){
179  if( !pack->nonconst_residue_task( i ).being_designed() ){ // prevent repacking on all non-designable residues
180  pack->nonconst_residue_task( i ).prevent_repacking();
181  TR<<"prevent repacking: "<<i<<std::endl;
182  }
183  else if( std::find( diffs.begin(), diffs.end(), i ) == diffs.end() ){
184  pack->nonconst_residue_task( i ).restrict_to_repacking();
185  TR<<"restrict to repacking: "<<i<<std::endl;
186  }
187  else{//design!
188  utility::vector1< bool > allowed_aas( num_canonical_aas, false );
189  if( thread() ){
190  //allow the aa at the corresonding position in the alignment with the disk pose p
191  //we can't use the alignment_ map's [] operator because it can add new elements and this is a const function!
192  allowed_aas[ p.residue( alignment_.find( i )->second ).aa() ] = true;
193  } else
194  //or allow the original aa in the current pose
195  allowed_aas[ pose()->residue( i ).aa() ] = true;
196  pack->nonconst_residue_task( i ).restrict_absent_canonical_aas( allowed_aas );
197  TR<<"design: "<<i<<std::endl;
198  }
199  }//for i=1->total_residue
200  using namespace protocols::simple_moves;
203  if( core::pose::symmetry::is_symmetric( *copy_pose ) )
204  prm = new symmetry::SymPackRotamersMover( scorefxn(), pack );
205  else
206  prm = new PackRotamersMover( scorefxn(), pack );
207  prm->apply( *copy_pose );
208  if( rtmin() ){
209  rtmin = new RotamerTrialsMinMover( scorefxn(), *pack );
210  rtmin->apply( *copy_pose );
211  TR<<"finished rtmin"<<std::endl;
212  }
213  }/// end else no copy_stretch
214  relax_mover()->apply( *copy_pose );
215  return( copy_pose );
216 }
217 
218 
221  core::pose::PoseOP threaded_pose( thread_seq( p ) );
222  core::Real const filter_val( filter()->report_sm( *threaded_pose ) );
223  if( dump_pose_fname() != "" ){
225  dump.set_scorefxn( scorefxn() );
226  dump.apply( *threaded_pose );
227  }
228  TR<<"filter "<<filter_name()<<" reports value pos: "<<filter_val<<", "<<std::endl;
229  if( baseline() ){
230  TR<<"filter "<<filter_name()<<" reports value, baseline: "<<filter_val<<", "<<baseline_val()<<std::endl;
231  return( filter_val - baseline_val() );
232  }
233  else{
234  TR<<"filter "<<filter_name()<<" val: "<<filter_val<<std::endl;
235  return( filter_val );
236  }
237 }
238 
241 {
242  return compute( pose );
243 }
244 
245 void
246 RelativePoseFilter::report( std::ostream & out, core::pose::Pose const & ) const
247 {
248  out<<"Dummy: All reports are dummy for this filter. Only report_sm is defined"<<std::endl;
249 }
250 
251 void
253  pose( core::import_pose::pose_from_pdb( pdb_name, false /*read foldtree*/ ) );
254 }
255 
256 
257 /// alignment is expecting X1:Y1,X2:Y2,X3:Y3... where X is the protein on disk (target) and Y is the active structure (starting structure). When no alignment is given it is implied that the poses are trivially aligned 1..nres
258 /// Feb2012 added option to align entire chains: A:B,D:C. Notice that no testing is made to ensure correct lengths etc., simply aligns from the start to end of the chains sequentially.
259 void
262  protocols::filters::Filters_map const & filters,
263  protocols::moves::Movers_map const & movers,
264  core::pose::Pose const & p )
265 {
266  using namespace protocols::rosetta_scripts;
267 
268  TR << "RelativePoseFilter"<<std::endl;
269  std::string pose_fname ("");
270  bool use_native ( tag->getOption< bool >( "use_native_pdb", false ));
271  if (use_native) pose( core::import_pose::pose_from_pdb(basic::options::option[ basic::options::OptionKeys::in::file::native ], false));
272 
273  if ( tag->hasOption( "pdb_name" ) ) {
274  pose_fname = tag->getOption< std::string >( "pdb_name" );
275  pdb_name( pose_fname );
276  }
277  if( tag->hasOption( "symmetry_definition" ) ){
278  symmetry_definition_ = tag->getOption< std::string >( "symmetry_definition", "" );
281  }
282  symmdata_ = new core::conformation::symmetry::SymmData( pose_->n_residue(), pose_->num_jump() );
283  symmdata_->read_symmetry_data_from_file(symmetry_definition_);
285  }
286  relax_mover( parse_mover( tag->getOption< std::string >( "relax_mover", "null" ), movers ) );
287  filter( parse_filter( tag->getOption< std::string >( "filter" ), filters ) );
288  filter_name( tag->getOption< std::string> ( "name" ) );
289  baseline( tag->getOption< bool >( "baseline", 1 ));
290  if( baseline() ){
291  relax_mover()->apply( *pose() );
292  baseline_val( filter()->report_sm( *pose() ) );
293  TR<<"The baseline value for the pose read from disk is: "<<baseline_val()<<std::endl;
294  }
295  else
296  TR<<"Baseline turned off. Is that intended?"<<std::endl;
297  dump_pose_fname( tag->getOption< std::string >( "dump_pose", "" ) );
298  if( tag->hasOption( "alignment" ) ){
299  utility::vector1< std::string > const residue_pairs( utility::string_split( tag->getOption< std::string >( "alignment", "" ), ',' ) );
300  foreach( std::string const residue_pair, residue_pairs ){
301  utility::vector1< std::string > const residues( utility::string_split( residue_pair, ':' ) );
302  runtime_assert( residues.size() == 2 );
303  char const residues1_cstr( residues[ 1 ].c_str()[ 0 ] ), residues2_cstr( residues[ 2 ].c_str()[ 0 ] ); // these may hold the chain designators
304  if( residues[ 1 ].length() == 1 &&
305  ( residues1_cstr <= 'Z' && residues2_cstr >= 'A' ) &&
306  ( residues[ 2 ].length() == 1 &&
307  ( residues2_cstr <= 'Z' && residues2_cstr >= 'A' ) ) ){ // are we aligning two chains to one another?
308  core::pose::PDBInfoCOP pdbinfo1( pose()->pdb_info() ), pdbinfo2( p.pdb_info() );
309  core::Size pose_res( 1 ), p_res( 1 );
310  for(; pose_res <= pose()->total_residue(); ++pose_res )// find chain1 start
311  if( pdbinfo1->chain( pose_res ) == residues1_cstr ) break;
312  for(; p_res <= p.total_residue(); ++p_res ) // find chain2 start
313  if( pdbinfo2->chain( p_res ) == residues2_cstr ) break;
314  for( core::Size index = 0; ; ++index ){/// push aligned residues
315  alignment_[ pose_res ] = p_res;
316  if( pose_res == pose()->total_residue() || p_res == p.total_residue() )//end of chains -> stop aligning
317  break;
318  pose_res++; p_res++;
319  if( pdbinfo1->chain( pose_res ) != residues1_cstr ||
320  pdbinfo2->chain( p_res ) != residues2_cstr ) /// end of aligned chains
321  break;
322  }
323  }//fi aligning two chains
324  else /// aligning individual residues
325  alignment_[ core::pose::parse_resnum( residues[ 1 ], *pose() ) ] = core::pose::parse_resnum( residues[ 2 ], p );
326  }
327  }
328  else{
329 // runtime_assert( pose()->total_residue() == p.total_residue() || core::pose::symmetry::is_symmetric( p ) );
330  for( core::Size i=1; i<=p.total_residue(); ++i )
331  alignment_[ i ] = i;
332  }
333  scorefxn( parse_score_function( tag, data ) );
334  packing_shell( tag->getOption( "packing_shell", packing_shell() ));
335  rtmin( tag->getOption< bool >("rtmin", 0 ) );
336  runtime_assert( packing_shell() >= 0 );
337  thread( tag->getOption< bool >( "thread", thread() ) );
338  unbound( tag->getOption< bool >( "unbound", false ) );
339  copy_stretch( tag->getOption< bool >( "copy_stretch", false ) );
340  TR<<"with pdb: "<<pose_fname<<" dumping fname "<<dump_pose_fname()<<" thread: "<<thread()<<" unbound "<<unbound()<<" copy_stretch: "<<copy_stretch()<<" rtmin "<<rtmin()<<" and packing_shell: "<<packing_shell();
341  if(symmetry_definition_!="") TR<<" symmetry: "<<symmetry_definition_<<std::endl;
342  TR<<std::endl;
343 }
344 
347  return new RelativePoseFilter();
348 }
349 
351 
354  return new RelativePoseFilter( *this );
355 }
356 
359 
361 RelativePoseFilterCreator::keyname() const { return "RelativePose"; }
362 
365  return relax_mover_;
366 }
367 
368 void
370  relax_mover_ = m;
371 }
372 
373 void
376 }
377 
380  return( scorefxn_ );
381 }
382 
383 bool
385  return baseline_;
386 }
387 
388 void
390  baseline_ = b;
391 }
392 
395  runtime_assert( baseline() );
396  return baseline_val_;
397 }
398 
399 void
401  runtime_assert( baseline() );
402  baseline_val_ = b;
403 }
404 
405 void
408 }
409 
412  return symmetry_definition_;
413 }
414 
415 void
417  filter_name_ = s;
418 }
419 
422 
423 bool
425 
426 void
427 RelativePoseFilter::rtmin( bool const b ){ rtmin_ = b; }
428 
429 } // simple_filters
430 } // protocols