Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FlxbbDesign.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/flxbb/FlxbbDesign.cc
11 /// @brief perform cycles of design and relax with filter
12 /// @author Nobuyasu Koga ( nobuyasu@uw.edu )
13 
14 // Unit headers
17 
18 // Package Headers
24 
25 // Project headers
26 
29 #include <core/pose/Pose.hh>
30 #include <core/pose/util.hh>
37 #include <basic/options/option.hh>
38 #include <basic/Tracer.hh>
39 #include <protocols/moves/Mover.hh>
40 
41 // option key includes
42 #include <basic/options/keys/flxbb.OptionKeys.gen.hh>
43 // AUTO-REMOVED #include <basic/options/keys/relax.OptionKeys.gen.hh>
44 
45 // Utility headers
46 #include <utility/vector1.hh>
47 #include <utility/string_util.hh>
48 
49 // Parser headers
51 #include <utility/tag/Tag.hh>
52 
58 #include <utility/vector0.hh>
59 
60 static basic::Tracer TR("protocols.flxbb.FlxbbDesign");
61 
62 using namespace core;
63 using namespace protocols::flxbb;
64 using namespace basic::options;
65 using namespace basic::options::OptionKeys;
66 
67 
68 namespace protocols{
69 namespace flxbb{
70 
71 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
73 FlxbbDesignCreator::keyname() const
74 {
75  return FlxbbDesignCreator::mover_name();
76 }
77 
79 FlxbbDesignCreator::create_mover() const {
80  return new FlxbbDesign;
81 }
82 
84 FlxbbDesignCreator::mover_name()
85 {
86  return "FlxbbDesign";
87 }
88 
89 /// @brief default constructor
90 FlxbbDesignPack::FlxbbDesignPack() :
91  protocols::simple_moves::PackRotamersMover("FlxbbDesignPack")
92 {}
93 
95  ScoreFunctionCOP scorefxn,
96  PackerTaskCOP task,
97  FilterStructsOP filter ):
98  protocols::simple_moves::PackRotamersMover( scorefxn, task ),
99  filter_( filter )
100 {}
101 
102 /// @brief destructor
104 
105 /// @brief main operation
106 void
108 {
110  this->setup( pose );
111 
112  if( ! filter_ ){
113  this->run( pose );
114  }else{
115  filter_->reset( pose );
116  while( filter_->filter_on() ){
117  this->run( pose );
118  filter_->apply( pose );
119  }
120  pose = *filter_->get_bestpose();
121  }
122 }
123 
126  return "FlxbbDesignPack";
127 }
128 
129 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
131  Mover( "FlxbbDesign" ),
132  scorefxn_design_( scoring::ScoreFunctionFactory::create_score_function( scoring::STANDARD_WTS, scoring::SCORE12_PATCH ) ),
133  scorefxn_relax_ ( scoring::ScoreFunctionFactory::create_score_function( scoring::STANDARD_WTS, scoring::SCORE12_PATCH ) ),
134  nflxbb_cycles_( 3 ),
135  layer_mode_( "" ),
136  use_origseq_for_not_dsgned_layer_( true ),
137  no_relax_( false ),
138  no_design_( false ),
139  filter_during_design_( NULL ),
140  blueprint_( NULL ),
141  resfile_( "" ),
142  constraints_sheet_( -1.0 ),
143  constraints_NtoC_( -1.0 ),
144  movemap_from_blueprint_( false ),
145  movemap_( NULL ),
146  use_fast_relax_( true ),
147  clear_all_residues_( false ),
148  relax_constraint_to_design_( false ),
149  limit_aroma_chi2_( true )
150 {
151  design_taskset_.clear();
152  task_operations_.clear();
153  read_options();
154 }
155 
156 /// @brief value constructor
158  ScoreFunctionOP const sfxnd,
159  ScoreFunctionOP const sfxnr,
160  Size const ncycle,
161  String const layer_mode,
162  bool const use_origseq_for_not_dsgned_layer,
163  bool const no_relax
164 ) :
165  Mover( "FlxbbDesign" ),
166  scorefxn_design_ ( sfxnd ),
167  scorefxn_relax_ ( sfxnr ),
168  nflxbb_cycles_( ncycle ),
169  layer_mode_( layer_mode ),
170  use_origseq_for_not_dsgned_layer_( use_origseq_for_not_dsgned_layer ),
171  no_relax_( no_relax ),
172  no_design_( false ),
173  filter_during_design_( NULL ),
174  blueprint_( NULL ),
175  resfile_( "" ),
176  constraints_sheet_( -1.0 ),
177  constraints_NtoC_( -1.0 ),
178  movemap_from_blueprint_( false ),
179  movemap_( NULL ),
180  use_fast_relax_( true ),
181  clear_all_residues_( false ),
182  relax_constraint_to_design_( false ),
183  limit_aroma_chi2_( true )
184 {
185  design_taskset_.clear();
186  task_operations_.clear();
187  read_options();
188 }
189 
190 /// @brief copy constructor
192  //utility::pointer::ReferenceCount(),
193  Super( rval ),
194  scorefxn_design_( rval.scorefxn_design_ ),
195  scorefxn_relax_( rval.scorefxn_relax_ ),
196  nflxbb_cycles_( rval.nflxbb_cycles_ ),
197  layer_mode_( rval.layer_mode_ ),
198  use_origseq_for_not_dsgned_layer_( rval.use_origseq_for_not_dsgned_layer_ ),
199  no_relax_( rval.no_relax_ ),
200  no_design_( rval.no_design_ ),
201  design_taskset_( rval.design_taskset_ ),
202  filter_during_design_( rval.filter_during_design_ ),
203  blueprint_ ( rval.blueprint_ ),
204  resfile_( rval.resfile_ ),
205  constraints_sheet_( rval.constraints_sheet_ ),
206  constraints_NtoC_( rval.constraints_NtoC_ ),
207  movemap_from_blueprint_( rval.movemap_from_blueprint_ ),
208  movemap_( rval.movemap_ ),
209  task_operations_( rval.task_operations_ ),
210  use_fast_relax_( rval.use_fast_relax_ ),
211  clear_all_residues_( rval.clear_all_residues_ ),
212  relax_constraint_to_design_( rval.relax_constraint_to_design_ ),
213  limit_aroma_chi2_( rval.limit_aroma_chi2_ )
214 {}
215 
216 /// @brief destructor
218 
219 /// @brief clone this object
221 {
222  return new FlxbbDesign( *this );
223 }
224 
225 /// @brief create this type of object
227 {
228  return new FlxbbDesign();
229 }
230 
231 /// @brief initialize setups
233 {
234  if( option[ OptionKeys::flxbb::ncycle ].user() ) nflxbb_cycles_ = option[ OptionKeys::flxbb::ncycle ]();
235  if( option[ OptionKeys::flxbb::blueprint ].user() ) blueprint_ = new BluePrint( option[ OptionKeys::flxbb::blueprint ]().name() );
236  if( option[ OptionKeys::flxbb::layer::layer ].user() ) layer_mode_ = option[ OptionKeys::flxbb::layer::layer ]();
239  if( option[ OptionKeys::flxbb::movemap_from_blueprint ] ) movemap_from_blueprint_ = true;
240 
241  Size filter_trial( 0 );
242  String filter_type( "" );
243  if( option[ OptionKeys::flxbb::filter_trial ].user() ) filter_trial = option[ OptionKeys::flxbb::filter_trial ]();
244  if( option[ OptionKeys::flxbb::filter_type ].user() ) filter_type = option[ OptionKeys::flxbb::filter_type ]();
245  if( filter_trial > 0 && filter_type != "" ){
246  initialize_filter( filter_trial, filter_type );
247  }
248 }
249 
250 /// @brief
251 void FlxbbDesign::initialize_filter( Size const filter_trial, String const & filter_type ){
252  if( filter_type != "" ){
253  if( filter_type == "packstat" ){
254  filter_during_design_ = new FilterStructs_Packstat( filter_trial );
255  }else{
256  TR.Error << filter_type << " does not exists as filter name " << std::endl;
257  runtime_assert( false );
258  }
259  }
260 }
261 
262 ///@details registering of options that are relevant for FlxbbDesign
264 {
265  option.add_relevant( OptionKeys::flxbb::view );
266  option.add_relevant( OptionKeys::flxbb::ncycle );
267  option.add_relevant( OptionKeys::flxbb::constraints_sheet );
268  option.add_relevant( OptionKeys::flxbb::constraints_NtoC );
269  option.add_relevant( OptionKeys::flxbb::blueprint );
270  option.add_relevant( OptionKeys::flxbb::filter_trial );
271  option.add_relevant( OptionKeys::flxbb::filter_type );
272  option.add_relevant( OptionKeys::flxbb::layer::layer );
273 }
274 
275 /// @brief set scorefxn for fixbb design
277 {
278  scorefxn_design_ = scorefxn;
279 }
280 
281 /// @brief set scorefxn for relax
283 {
284  scorefxn_relax_ = scorefxn;
285 }
286 
287 /// @brief the number of cycles of fixbb and relax
288 void FlxbbDesign::set_ncycles( Size const ncycles )
289 {
290  nflxbb_cycles_ = ncycles;
291 }
292 
293 /// @brief set layer mode
294 void FlxbbDesign::set_layer_mode( String const & layer_mode )
295 {
296  layer_mode_ = layer_mode;
297 }
298 
299 /// @brief use original sequence for not designed region in layer_mode,
300 /// otherwise the residues of the region turned into Ala ( default true )
302 {
304 }
305 
306 /// @brief relax is not performed after design (default false)
307 void FlxbbDesign::no_relax( bool const no_relax )
308 {
310 }
311 
312 /// @brief design protocol will not be performed (default false)
313 void FlxbbDesign::no_design( bool const no_design )
314 {
316 }
317 
318 /// @brief set BlueprintOP
320 {
321  blueprint_ = blueprint;
322 }
323 
324 /// @brief set weight of constraints_sheet which constrains between Ca atoms in beta-sheets
325 /// if this weight > 0.0, the constraints is applied ( default = -1.0 )
327 {
328  constraints_sheet_ = value;
329 }
330 
331 /// @brief set weight of constraints_NtoC which constrain between Ca atoms of C- and N-terminal
332 /// if this weight > 0.0, the constraints is applied ( default = -1.0 )
334 {
335  constraints_NtoC_ = value;
336 }
337 
338 /// @brief
339 void FlxbbDesign::movemap_from_blueprint( bool const value )
340 {
341  movemap_from_blueprint_ = value;
342 }
343 
344 /// @brief set movemap for relax
345 void FlxbbDesign::set_movemap( MoveMapOP const movemap )
346 {
347  movemap_ = movemap;
348 }
349 
350 /// @brief clear DesignTaskSet
351 void FlxbbDesign::set_design_taskset( DesignTaskSet const & design_taskset )
352 {
353  design_taskset_ = design_taskset;
354 }
355 
356 /// @brief set DesignTask
358 {
359  design_taskset_.push_back( design_task );
360 }
361 
362 /// @brief filtering during design
363 void FlxbbDesign::set_filter_during_design( FilterStructsOP const filter_during_design )
364 {
365  filter_during_design_ = filter_during_design;
366 }
367 
368 /// @brief clear DesignTaskSet
370 {
371  design_taskset_.clear();
372 }
373 
374 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
375 /// @brief build design_task_set
378 {
379  using core::pose::PoseOP;
392 
393  DesignTaskSet dts;
394 
395  // create relax mover
396  RelaxProtocolBaseOP rlx_mover;
397  if ( use_fast_relax_ ) {
398  rlx_mover = new FastRelax( scorefxn_relax_ );
399  } else{
400  rlx_mover = new ClassicRelax( scorefxn_relax_ );
401  }
402  if( movemap_ ) rlx_mover->set_movemap( movemap_ ); // movemap can be controled by blueprint
403  if( relax_constraint_to_design_ ) rlx_mover->constrain_relax_to_start_coords( true );
404  if( limit_aroma_chi2_ ) { // default true
405  TaskFactoryOP tf = new TaskFactory;
406  tf->push_back( new LimitAromaChi2Operation );
407  rlx_mover->set_task_factory( tf );
408  }
409 
410  if( layer_mode_ == "" ){
411  dts.push_back( new DesignTask_Normal( nflxbb_cycles_, scorefxn_design_, rlx_mover, filter_during_design_ ) );
412  }else{
413 
414  utility::vector1< String > layers( utility::string_split( layer_mode_, '_' ) );
415  if( layers.size() == 1 && layer_mode_ == "normal" ){
416 
417  rlx_mover = new FastRelax( scorefxn_relax_ );
418  FilterStructs_PackstatOP filter1 = new FilterStructs_Packstat( pose, 10 );
420 
421  // 1st stage: 2 cycles of the fixbb designinig only core and boundary and relax
422  dts.push_back( new DesignTask_Layer( true, true, false, false,
423  2, scorefxn_design_, rlx_mover, filter1 ));
424  // 2nd stage: 2 cycles of design all and relax
425  dts.push_back( new DesignTask_Layer( true, true, true, false,
426  2, scorefxn_design_, rlx_mover, filter1 ));
427  // 3rd stage: design only surface without relax and filter sequence of which totalcharge is non-zero
428  dts.push_back( new DesignTask_Layer( false, false, true, true,
429  1, scorefxn_design_, 0, filter2 ));
430 
431  }else if( layers.size() == 1 && layer_mode_ == "all" ){
432  dts.push_back( new DesignTask_Layer( true, true, true, false,
434  }else if( layers.size() >= 1 ){
435  bool dcore( false );
436  bool boundary( false );
437  bool surface( false );
438  for( utility::vector1< String >::const_iterator iter = layers.begin(); iter != layers.end() ; ++iter) {
439  String layer(*iter);
440  if( layer == "core" ){
441  dcore = true;
442  }else if( layer == "surface" ){
443  surface = true;
444  }else if( layer == "boundary" ){
445  boundary = true;
446  }else{
447  TR << "Error!, wrong specification of layer_mode " << layer << std::endl;
448  TR << "Every layers are designed. " << std::endl;
449  dcore = true;
450  surface = true;
451  boundary = true;
452  }
453  } // utility::vector1
454  dts.push_back( new DesignTask_Layer( dcore, boundary, surface,
457  }
458  } // if ( layer_mode_ == "" )
459 
460  // set the filename of resfile, which is given in parser, to all the DesignTask
461  if( resfile_ != "" ){
462  for( DesignTaskSet::const_iterator it=dts.begin(); it!=dts.end(); ++it ) {
463  (*it)->set_resfile( resfile_ );
464  }
465  }
466 
467  // set additional task operations
468  if( ! task_operations_.empty() ){
469  for( DesignTaskSet::const_iterator it=dts.begin(); it!=dts.end(); ++it ) {
470  (*it)->add_task_operations( task_operations_ );
471  }
472  }
473 
474  // Exclude aromatic chi2 rotamers, of which angles are around 0
475  if( limit_aroma_chi2_ ) { // default true
476  for( DesignTaskSet::const_iterator it=dts.begin(); it!=dts.end(); ++it ) {
477  (*it)->add_task_operation( new LimitAromaChi2Operation );
478  }
479  }
480 
481  return dts;
482 }
483 
484 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
485 /// @brief mover apply
487 {
499 
500  // set pose to fullatom
501  if( ! pose.is_fullatom() ){
503  }
504 
505  // set movemap from blueprint for relax
507  if( movemap_ ){
508  TR << "Movemap will be overrided by the definition of movemap in blueprint " << std::endl;
509  }
510  runtime_assert( blueprint_ );
511  runtime_assert( pose.total_residue() == blueprint_->total_residue() );
513  blueprint_->set_movemap( movemap_ );
514  }
515 
516  // set constraints
517  ConstraintSetOP cstset = new ConstraintSet;
518 
519  // set weight of constraints
520  if( constraints_NtoC_ > 0.0 || constraints_sheet_ > 0.0 ){
521  Real cst_weight( scorefxn_relax_->get_weight( core::scoring::atom_pair_constraint ) );
522  runtime_assert( cst_weight > 0.0 );
523  }
524 
525  // constraints in beta-sheet
526  if( constraints_sheet_ > 0.0 ){
527  if( blueprint_ ){
528  cstset->add_constraints( constraints_sheet( pose, blueprint_, constraints_sheet_ ) );
529  }else{
530  cstset->add_constraints( constraints_sheet( pose, constraints_sheet_ ) );
531  }
532  }
533  // constraints between N and C
534  if( constraints_NtoC_ > 0.0 ){
535  cstset->add_constraints( constraints_NtoC( pose, constraints_NtoC_ ) );
536  }
537  // attach constraints to pose
538  pose.add_constraints( cstset->get_all_constraints() );
539 
540  // setup design_taskset
541  if( design_taskset_.empty() ){
543  }
544 
545  // make pose to all ala
546  // alert !! we might want to have the functionality to keep_disulfide or not
547  if( clear_all_residues_ ) {
548  MakePolyXMover bap( "ALA", false/*kee_pro*/, true /*keep_gly*/, false /*keep_disulfide_cys*/ );
549  bap.apply( pose );
550  }
551 
552  // run
553  Size num_task( 0 );
554  for ( DesignTaskSet::iterator it= design_taskset_.begin(), ite= design_taskset_.end(); it != ite; ++it ) {
555 
556  num_task ++;
557  DesignTaskOP design_task( *it );
558  for( Size i=1 ; i<=design_task->ncycle() ; i++ ){
559 
560  TR << "current_cycle/total_cycle: " << i << "/" << design_task->ncycle() << " in DesignTask: " << num_task << std::endl;
561 
562  if( ! no_design_ ) {
563  // set packertask
564  PackerTaskOP task( TaskFactory::create_packer_task( pose ));
565  design_task->setup( pose, task );
566  design_task->dump_packertask( TR );
567 
568  // run design
569  runtime_assert( design_task->scorefxn() != 0 );
570  FlxbbDesignPack pack( design_task->scorefxn(), design_task->packertask(), design_task->filter_structs() );
571  pack.apply( pose );
572 
573  TR << "Designed sequence: " << pose.sequence() << std::endl;
574  TR << "Score after design by fixbb " << std::endl;
575  scorefxn_design_->show( TR, pose );
576  TR.flush();
577  } else {
578  TR << "Design step was skipped. ";
579  }
580 
581  // run mover
582  if( design_task->mover() && !no_relax_ ){
583  design_task->mover()->apply( pose );
584  TR << "Score after mover, " << design_task->mover()->type() << std::endl;
585  scorefxn_relax_->show( TR, pose );
586  TR.flush();
587  }
588 
589  } // iteration of i: design_task->ncycle()
590  } // iteration of it: DesignTaskSet
591 
592 
593  // detach constraints from pose
594  pose.remove_constraints( cstset->get_all_constraints() );
595 
596  // calc packstat
597  core::Real packscore;
599  setPoseExtraScores( pose, "pack_stat", packscore );
600 
601 } // FlxbbDesign::apply
602 
606 }
607 
608 /// @brief parse xml
609 void
611  TagPtr const tag,
612  DataMap & data,
613  Filters_map const &,
614  Movers_map const &,
615  Pose const & pose )
616 {
617  String const sfxn_design ( tag->getOption<String>( "sfxn_design", "score12" ));
618  String const sfxn_relax ( tag->getOption<String>( "sfxn_relax", "score12" ) );
619  scorefxn_design_ = data.get< ScoreFunction * >( "scorefxns", sfxn_design );
620  scorefxn_relax_ = data.get< ScoreFunction * >( "scorefxns", sfxn_relax );
621 
622  std::string const blueprint( tag->getOption<std::string>( "blueprint", "" ) );
623  if( blueprint != "" ){
624  blueprint_ = new BluePrint( blueprint );
625  }
626 
627  // the number of cycles of fixbb and relax
628  nflxbb_cycles_ = tag->getOption<Size>( "ncycles", 3 );
629 
630  // perform fixbb in layer mode: core, boundary, and surfacee
631  layer_mode_ = tag->getOption<String>( "layer_mode", "" );
632 
633  // use original sequence for not designed region in layer_mode
634  use_origseq_for_not_dsgned_layer_ = tag->getOption<bool>( "use_original_seq", 1 );
635 
636  // set filter
637  Size filter_trial = tag->getOption<Size>( "filter_trial", 10 );
638  String filter_type = tag->getOption<String>( "filter_type", "packstat" );
639  if( filter_trial > 0 && filter_type != "" ){
640  initialize_filter( filter_trial, filter_type );
641  }
642 
643  // do not perform relax after design
644  no_relax_ = tag->getOption<bool>( "no_relax", 0 );
645  bool movemap_defined( false );
646  utility::vector1< TagPtr > const branch_tags( tag->getTags() );
648  for( tag_it = branch_tags.begin(); tag_it!=branch_tags.end(); ++tag_it ){
649  if( (*tag_it)->getName() == "MoveMap" ){
650  movemap_defined = true;
651  break;
652  }
653  }
654  if( movemap_defined ){
657  }
658  // do not perform design
659  no_design_ = tag->getOption<bool>( "no_design", 0 );
660 
661  /// clear amino acid sequence at the very beginning of FlxbbDesign
662  clear_all_residues_ = tag->getOption<bool>( "clear_all_residues", 0 );
663 
664  // resfile for fixbb
665  resfile_ = tag->getOption<String>( "resfile", "" );
666 
667  // constraint N- and C- terminal
668  constraints_NtoC_ = tag->getOption<Real>( "constraints_NtoC", -1.0 );
669 
670  // constraint N- and C- terminal
671  constraints_sheet_ = tag->getOption<Real>( "constraints_sheet", -1.0 );
672 
673  // constraint of backbone to fixbb-designed structure during relax
674  relax_constraint_to_design_ = tag->getOption<bool>( "constraints_to_backbone", 0 );
675 
676  // movemap for relax
677  movemap_from_blueprint_ = tag->getOption<bool>( "movemap_from_blueprint", 0 );
678  if( movemap_from_blueprint_ ){
679  TR << "Movemap is defined based on blueprint " << std::endl;
680  runtime_assert( blueprint != "" );
681  }
682 
683  // read task operations
685 
686  /// use fast relax
687  use_fast_relax_ = tag->getOption<bool>( "fast_relax", 1 );
688 
689  // Exclude aromatic chi2 rotamers, of which angles are around 0
690  limit_aroma_chi2_ = tag->getOption<bool>( "limit_aroma_chi2", 1 );
691 
692  /// read options Alert!! if there are options, settings of parser will be overrided.
693  read_options();
694 
695 }
696 
697 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
698 
699 
700 } // namespace of flxbb
701 } // namespace of protocols