Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DesignRepackMover.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 protocols/simple_moves/DesignRepackMover.cc
11 /// @brief
12 /// @author Sarel Fleishman (sarelf@u.washington.edu), Jacob Corn (jecorn@u.washington.edu), Eva-Maria Strauch (evas01@u.washington.edu)
14 
15 // Project Headers
16 #include <core/types.hh>
17 #include <core/pose/Pose.hh>
18 
21 // AUTO-REMOVED #include <core/pose/symmetry/util.hh>
22 // AUTO-REMOVED #include <core/conformation/symmetry/util.hh>
23 
27 
34 
35 #include <protocols/moves/Mover.hh>
37 //#include <protocols/moves/ResidueMover.hh>
39 
40 
41 #include <numeric/random/random.hh>
42 #include <basic/options/option.hh>
43 
44 // AUTO-REMOVED #include <core/scoring/constraints/HarmonicFunc.hh>
45 // AUTO-REMOVED #include <core/pack/rotamer_set/RotamerSet.fwd.hh>
46 #include <utility/tag/Tag.hh>
47 
48 // Utility Headers
49 
50 #include <ObjexxFCL/FArray1D.hh>
51 #include <ObjexxFCL/FArray1D.fwd.hh>
52 
53 // Unit Headers
55 #include <core/pose/selection.hh>
56 
57 
58 // C++ headers
59 #include <map>
60 #include <string>
61 #include <algorithm>
62 using namespace core;
63 
64 // option key includes
65 
66 #include <basic/options/keys/packing.OptionKeys.gen.hh>
67 
69 #include <utility/vector0.hh>
70 #include <utility/vector1.hh>
71 #include <basic/Tracer.hh>
72 
73 //Auto Headers
75 #define foreach BOOST_FOREACH
76 
77 
78 using namespace core::scoring;
79 
80 static basic::Tracer TR( "protocols.simple_moves.DesignRepackMover" );
81 
82 static numeric::random::RandomGenerator RG( 150845 ); // <- Magic number, do not change it!!!
83 
84 namespace protocols {
85 namespace simple_moves {
86 
87 using namespace protocols::moves;
88 
89 DesignRepackMover::DesignRepackMover() : protocols::moves::Mover( "DesignRepackMover" ),
90  repack_partner1_( false ), repack_partner2_( false ), design_partner1_( false ), design_partner2_( false ), min_rb_set_( false ), min_sc_set_( false ), min_bb_set_( false ), interface_distance_cutoff_( 8.0 ), repack_non_ala_( true ), optimize_foldtree_( true ), automatic_repacking_definition_( true ), use_preset_task_( false ), symmetry_( false )
91 {
93  prevent_repacking_.clear();
94  restrict_to_repacking_.clear();
95 }
96 
97 DesignRepackMover::DesignRepackMover( std::string const name ) : protocols::moves::Mover( name ), repack_partner1_( false ), repack_partner2_( false ), design_partner1_( false ), design_partner2_( false ), min_rb_set_( false ), min_sc_set_( false ), min_bb_set_( false ), interface_distance_cutoff_( 8.0 ), repack_non_ala_( true ), optimize_foldtree_( true ), automatic_repacking_definition_( true ), use_preset_task_( false ), symmetry_( false )
98 {
100 }
101 
104  return "DesignRepackMover";
105 }
106 
107 void
109  task_ = NULL;
110 }
111 
112 void
114  task_factory_ = p;
115 }
116 
117 void
119 {
120  core::Size const rb_jump( 1 );
121 
122  core::pose::Pose pose( in_pose ); // to maintain constness of input pose
123  curr_min_bb_.clear(); curr_min_sc_.clear(); curr_min_rb_.clear();
124  curr_min_bb_.resize( pose.total_residue(), false );
125  curr_min_sc_.resize( pose.total_residue(), false );
126  curr_min_rb_.resize( pose.num_jump(), true );
127  if( min_sc_set() ) {
128  runtime_assert( min_sc_.size() == pose.total_residue() );
130  }
131  if( min_bb_set() ) {
132  runtime_assert( min_bb_.size() == pose.total_residue() );
134  }
135  if( min_rb_set() ) curr_min_rb_ = min_rb_;
136 
137  using ObjexxFCL::FArray1D_bool;
138  FArray1D_bool partner1( pose.total_residue() );
139  if ( !symmetry_ ) {
140  pose.fold_tree().partition_by_jump( rb_jump, partner1 ); // partner1 is true for all residues in partner1; false o/w
141  }
142 
143  protocols::scoring::Interface interface_obj(rb_jump);
144  pose.update_residue_neighbors(); // o/w fails assertion `graph_state_ == GOOD`
145  interface_obj.distance( interface_distance_cutoff_ );
146  interface_obj.calculate( pose );
147 
148  if( !task_ || !use_preset_task_ ){
149 /// This allows presetting the task
150 /// note that the operations on desiganble positions are of logical intersection type and only restrict the identities
151 /// allowed at the positions, so if more rotamers and less identities are set before calling this setup, they
152 /// will be respected
153  if( task_factory_ )
154  task_ = task_factory_->create_task_and_apply_taskoperations( pose );
155  else
157  task_->initialize_from_command_line();
158  }
159 
166  pido.apply( pose, *task_ );
167 
168 // Restrict to allowable amino acids
169  for( core::Size i=1; i<=pose.total_residue(); ++i ){
171  racaas.apply( pose, *task_ );
172  }
173 
174  // Packertask defaults to designing all residues, so this paragraph only has to restrict
175  for ( core::Size i = 1; i <= pose.total_residue(); ++i) {
176  if ( !pose.residue(i).is_protein() ) continue;
177  if( interface_obj.is_interface( i ) ) { // in interface
178  if( (partner1( i ) && repack_partner1_ ) || (!partner1( i ) && repack_partner2_) ) { //redesign/repack interface
179  core::Size const restype( pose.residue(i).aa() );
180  // Check for pro, gly, and disulfide bonded cysteines
181  if( ( !repack_non_ala_ && restype != chemical::aa_ala ) || restype == chemical::aa_pro || restype == chemical::aa_gly || pose.residue(i).type().name() == "CYD" ) {
182 // if( automatic_repacking_definition_ ) task_->nonconst_residue_task(i).prevent_repacking();
183  if( !(pose.residue(i).type().name() == "CYD") ) {
184  if( !min_sc_set() ) curr_min_sc_[ i ] = true;
185  }
186  if( !min_bb_set() ) curr_min_bb_[ i ] = true;
187  }
188  else { // non-PRO/GLY/CYD
189  if( target_residues_.size() == 0 ) { // target residues undefined => repack the entire interface
190 // if( design_ && automatic_repacking_definition_ )
191 // task_->nonconst_residue_task(i).restrict_absent_canonical_aas( allowed_aas_ );
192 // else if( !design_ && automatic_repacking_definition_ )
193 // task_->nonconst_residue_task( i ).restrict_to_repacking();
194  if( !min_sc_set() ) curr_min_sc_[ i ] = true;
195  if( !min_bb_set() ) curr_min_bb_[ i ] = true;
196  }
197  else { //target residues defined
198  core::conformation::Residue const resi( pose.residue( i ) );
199 
201  target_it!=target_residues_.end(); ++target_it ) {
202  core::conformation::Residue const res_target( pose.residue( *target_it ) );
203 
204  Real const distance( resi.xyz( resi.nbr_atom() ).distance( res_target.xyz( res_target.nbr_atom() ) ) );
206 // if( design_ && automatic_repacking_definition_ )
207 // task_->nonconst_residue_task( i ).restrict_absent_canonical_aas( allowed_aas_ );
208 // else if( !design_ && automatic_repacking_definition_ )
209 // task_->nonconst_residue_task( i ).restrict_to_repacking();
210  if( !min_sc_set() ) curr_min_sc_[ i ] = true;
211  if( !min_bb_set() ) curr_min_bb_[ i ] = true;
212 
213  break;
214  } //within distance cutoff
215  else {
216 // if( automatic_repacking_definition_ )
217 // task_->nonconst_residue_task(i).prevent_repacking();
218  if( !min_sc_set() ) curr_min_sc_[ i ] = false;
219  if( !min_bb_set() ) curr_min_bb_[ i ] = true;
220  }
221  } // target_res iterator
222  // reach this point only if target residues are defined, and current residue is at the interface, but not close to target
223  // and for some reason was not taken care of before the break statement above
224 // if( automatic_repacking_definition_ )
225 // task_->nonconst_residue_task( i ).prevent_repacking();
226  if( !min_sc_set() ) curr_min_sc_[ i ] = false;
227  if( !min_bb_set() ) curr_min_bb_[ i ] = true;
228  } // target_res defined
229  } // repackable residues
230  } //redesign/repack interface
231  else { // inside the interface but outside repackable/redesignable parts
232  if( pose.residue(i).type().name() == "CYD" ){
233 // task_->nonconst_residue_task(i).prevent_repacking();
234  curr_min_sc_[ i ] = false;
235  curr_min_bb_[ i ] = false;
236  }
238 // task_->nonconst_residue_task( i ).restrict_to_repacking();
239  if( !min_sc_set() ) curr_min_sc_[ i ] = true;
240  if( !min_bb_set() ) curr_min_bb_[ i ] = true;
241  }
242  }
243  } // in interface
244  else { // non-interface residues are held constant
246 // task_->nonconst_residue_task(i).prevent_repacking();
247  if( !min_sc_set() ) curr_min_sc_[ i ] = false;
248  if( !min_bb_set() ) curr_min_bb_[ i ] = true;
249  }
250  }
252  target_it!=target_residues_.end(); ++target_it ) {
253 // minimize also +-1 amino-acid residues around target residues, unless they are CYD
254  if( !min_sc_set() ){
255  curr_min_sc_[ *target_it ] = true;
256  if( *target_it < pose.total_residue() )
257  if( !(pose.residue(*target_it + 1).type().name() == "CYD") ) curr_min_sc_[ *target_it + 1 ] = true;
258  if( *target_it > 1 )
259  if( !(pose.residue(*target_it - 1).type().name() == "CYD") ) curr_min_sc_[ *target_it - 1 ] = true;
260  }
261  if( !min_bb_set() ) {
262  curr_min_bb_[ *target_it ] = true;
263  if( *target_it < pose.total_residue() )
264  curr_min_bb_[ *target_it + 1 ] = true;
265  if( *target_it > 1 )
266  curr_min_bb_[ *target_it - 1 ] = true;
267  }
268  }
270  task_->nonconst_residue_task( *res ).prevent_repacking();
271 
273  task_->nonconst_residue_task( *res ).restrict_to_repacking();
274 
275  if( basic::options::option[basic::options::OptionKeys::packing::resfile].user() )
277 
278  if ( symmetry_ ) {
280  }
281 }
282 
283 void
286 
287  std::string const scorefxn_repack( tag->getOption<std::string>( "scorefxn_repack", "score12" ) );
288  std::string const scorefxn_minimize( tag->getOption<std::string>( "scorefxn_minimize", "score12" ) );
289  if( !tag->hasOption( "repack_partner1" ) && !tag->hasOption( "repack_partner2" ) && tag->hasOption( "repack" ) ){
290  bool const repack( tag->getOption< bool >( "repack" ) );
292  }
293  else{
294  repack_partner1_ = tag->getOption<bool>( "repack_partner1", 1 );
295  repack_partner2_ = tag->getOption<bool>( "repack_partner2", 1 );
296  }
297  if( !tag->hasOption( "design_partner1" ) && !tag->hasOption( "design_partner2" ) && tag->hasOption( "design" ) ){
298  bool const design( tag->getOption< bool >( "design" ) );
300  }
301  else{
302  design_partner1_ = tag->getOption<bool>( "design_partner1", 0 );
303  design_partner2_ = tag->getOption<bool>( "design_partner2", 1 );
304  }
305  TR<<"design partner1: "<<design_partner1_<<'\n';
306  TR<<"design partner2: "<<design_partner2_<<'\n';
307  TR<<"repack partner1: "<<repack_partner1_<<'\n';
308  TR<<"repack partner2: "<<repack_partner2_<<'\n';
309 
310  runtime_assert( !( design_partner1_ && !repack_partner1_ ) );
311  runtime_assert( !( design_partner2_ && !repack_partner2_ ) );
312  optimize_foldtree_ = tag->getOption<bool>( "optimize_fold_tree", 1 );
313  if( tag->hasOption( "minimize_rb" ) )
314  min_rb( tag->getOption<bool>( "minimize_rb", 1 ) );
315 
316  if( tag->hasOption( "minimize_bb" ) ){
317  utility::vector1< bool > minbb( pose.total_residue(), tag->getOption<bool>( "minimize_bb", 1 ) );
318  min_bb( minbb );
319  }
320 
321  if( tag->hasOption( "minimize_bb_ch1" ) || ( tag->hasOption( "minimize_bb_ch2" ) ) ) {
322  utility::vector1< bool > minbb( pose.total_residue(), true );
323  if( tag->hasOption( "minimize_bb_ch1" ) ){
324  for( core::Size res_it=pose.conformation().chain_begin( 1 ); res_it<=pose.conformation().chain_end( 1 ); ++res_it ){
325  minbb[ res_it ]=tag->getOption<bool>( "minimize_bb_ch1", 1 );
326  }
327  }
328  if( tag->hasOption( "minimize_bb_ch2" ) ){
329  for( core::Size res_it=pose.conformation().chain_begin( 2 ); res_it<=pose.conformation().chain_end( 2 ); ++res_it ){
330  minbb[ res_it ]=tag->getOption<bool>( "minimize_bb_ch2", 1 );
331  }
332  }
333  min_bb( minbb );
334  }//end specificatino of bb mininization
335 
336  if( tag->hasOption( "minimize_sc" ) ) {
337  utility::vector1< bool > minsc( pose.total_residue(), tag->getOption< bool >( "minimize_sc", 1 ));
338  min_sc( minsc );
339  }
340  interface_distance_cutoff_ = tag->getOption<core::Real>( "interface_cutoff_distance", 8.0 );
341  utility::vector0< TagPtr > const repack_tags( tag->getTags() );
342  for( utility::vector0< TagPtr >::const_iterator repack_it=repack_tags.begin(); repack_it!=repack_tags.end(); ++repack_it ) {
343  TagPtr const repack_ptr = *repack_it;
344  if( repack_ptr->getName() == "residue" ) {
345  core::Size const resnum( core::pose::get_resnum( repack_ptr, pose ) );
346  target_residues_.push_back( resnum );
347  }
348  }
349  repack_non_ala_ = tag->getOption<bool>( "repack_non_ala", 1 );
350 
351  symmetry_ = tag->getOption< bool >( "symmetry", 0 );
352 
353  if (symmetry_) {
354  using namespace core::scoring::symmetry;
355  scorefxn_repack_ = new SymmetricScoreFunction( *data.get< ScoreFunction * >( "scorefxns", scorefxn_repack ) );
356  scorefxn_minimize_ = new SymmetricScoreFunction( *data.get< ScoreFunction * >( "scorefxns", scorefxn_minimize ) );
357  } else {
358  using namespace core::scoring;
359  scorefxn_repack_ = new ScoreFunction( *data.get< ScoreFunction * >( "scorefxns", scorefxn_repack ) );
360  scorefxn_minimize_ = new ScoreFunction( *data.get< ScoreFunction * >( "scorefxns", scorefxn_minimize ) );
361  }
362  automatic_repacking_definition_ = tag->getOption<bool>( "automatic_repacking_definition", 1 );
363  TR<<"repack scorefxn "<<scorefxn_repack<<" and minimize scorefxn "<<scorefxn_minimize<<" automatic_repacking_definition set to "<<automatic_repacking_definition_<<" optimize fold tree="<<optimize_foldtree_<<" targeting residues ";
364 
365  for( utility::vector1< core::Size >::const_iterator target_res_it=target_residues_.begin(); target_res_it!=target_residues_.end(); ++target_res_it )
366  TR<<*target_res_it<<" ";
367  TR<<std::endl;
368 }
369 
370 void
372  scorefxn_repack_ = scorefxn->clone();
373 }
374 
375 void
377  scorefxn_minimize_ = scorefxn->clone();
378 }
379 
380 void
382  if( task_factory_ )
383  task_factory_->clear();
384 }
385 
388  return task_;
389 }
390 
393  return task_;
394 }
395 
398  return task_factory_;
399 }
400 
403  return task_factory_;
404 }
405 
407 
410  return scorefxn_repack_;
411 }
412 
415  return scorefxn_minimize_;
416 }
417 
418 } //simple_moves
419 } //protocols