Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BluePrintBDR.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/fldsgn/BluePrintBDR.cc
11 /// @brief
12 /// @author Nobuyasu Koga ( nobuyasu@uw.edu ), Yih-En Andrew Ban (yab@u.washington.edu)
13 
14 // unit headers
18 
19 // package headers
24 // AUTO-REMOVED #include <protocols/forge/methods/chainbreak_eval.hh>
26 // AUTO-REMOVED #include <protocols/forge/methods/util.hh>
27 // AUTO-REMOVED #include <protocols/fldsgn/topology/HSSTriplet.hh> // REQUIRED FOR WINDOWS
28 
29 // project headers
30 #include <basic/Tracer.hh>
31 #include <core/chemical/AA.hh>
33 // AUTO-REMOVED #include <core/chemical/util.hh>
36 #include <core/pose/Pose.hh>
37 #include <core/pose/PDBInfo.hh>
42 #include <core/scoring/Energies.hh>
46 
52 // AUTO-REMOVED #include <protocols/forge/remodel/RemodelLoopMover.hh>
58 
61 #include <utility/tag/Tag.hh>
62 
63 // C++ headers
64 #include <utility>
65 
66 // boost
67 // AUTO-REMOVED #include <boost/lexical_cast.hpp>
68 
69 #include <utility/vector0.hh>
70 #include <utility/vector1.hh>
71 
72 namespace protocols {
73 namespace fldsgn {
74 
75 
76 static basic::Tracer TR( "protocols.fldsgn.BluePrintBDR" );
77 
80 {
82 }
83 
86  return new BluePrintBDR;
87 }
88 
91 {
92  return "BluePrintBDR";
93 }
94 
95 
96 /// @brief default constructor
98  Super( "BluePrintBDR" ),
99  blueprint_( NULL ),
100  sfx_( core::scoring::ScoreFunctionFactory::create_score_function( "fldsgn_cen" ) ),
101  loop_mover_str_( "RemodelLoopMover" ),
102  use_fullmer_( false ),
103  num_fragpick_( 200 ),
104  use_sequence_bias_( false ),
105  use_abego_bias_( false ),
106  max_linear_chainbreak_( 0.07 ),
107  initialized_( false ),
108  ss_from_blueprint_( true ),
109  constraints_NtoC_( -1.0 ),
110  constraints_sheet_( -1.0 ),
111  constraint_file_( "" ),
112  dump_pdb_when_fail_( "" ),
113  rmdl_attempts_( 1 ),
114  use_poly_val_( true ),
115  invrot_tree_(NULL),
116  enzcst_io_(NULL)
117 {}
118 
119 /// @brief value constructor
120 BluePrintBDR::BluePrintBDR( String const & filename, bool const ss_from_blueprint ) :
121  Super( "BluePrintBDR" ),
122  sfx_( core::scoring::ScoreFunctionFactory::create_score_function( "fldsgn_cen" ) ),
123  loop_mover_str_( "RemodelLoopMover" ),
124  use_fullmer_( false ),
125  num_fragpick_( 200 ),
126  use_sequence_bias_( false ),
127  use_abego_bias_( false ),
128  max_linear_chainbreak_( 0.07 ),
129  initialized_( false ),
130  ss_from_blueprint_( ss_from_blueprint ),
131  constraints_NtoC_( -1.0 ),
132  constraints_sheet_( -1.0 ),
133  constraint_file_( "" ),
134  dump_pdb_when_fail_( "" ),
135  rmdl_attempts_( 1 ),
136  use_poly_val_( true ),
137  invrot_tree_(NULL),
138  enzcst_io_(NULL)
139 {
140  set_blueprint( filename );
141 }
142 
143 /// @brief value constructor
144 BluePrintBDR::BluePrintBDR( BluePrintOP const & blueprintOP, bool const ss_from_blueprint ) :
145  Super( "BluePrintBDR" ),
146  blueprint_( blueprintOP ),
147  sfx_( core::scoring::ScoreFunctionFactory::create_score_function( "fldsgn_cen" ) ),
148  loop_mover_str_( "RemodelLoopMover" ),
149  use_fullmer_( false ),
150  num_fragpick_( 200 ),
151  use_sequence_bias_( false ),
152  use_abego_bias_( false ),
153  max_linear_chainbreak_( 0.07 ),
154  initialized_( false ),
155  ss_from_blueprint_( ss_from_blueprint ),
156  constraints_NtoC_( -1.0 ),
157  constraints_sheet_( -1.0 ),
158  constraint_file_( "" ),
159  dump_pdb_when_fail_( "" ),
160  rmdl_attempts_( 1 ),
161  use_poly_val_( true ),
162  invrot_tree_(NULL),
163  enzcst_io_(NULL)
164 {}
165 
166 /// @Brief copy constructor
168  //utility::pointer::ReferenceCount(),
169  Super( rval ),
170  blueprint_( rval.blueprint_ ),
171  manager_( rval.manager_ ),
172  sfx_( rval.sfx_ ),
173  loop_mover_str_( rval.loop_mover_str_ ),
174  use_fullmer_( rval.use_fullmer_ ),
175  num_fragpick_( rval.num_fragpick_ ),
176  use_sequence_bias_( rval.use_sequence_bias_ ),
177  use_abego_bias_( rval.use_abego_bias_ ),
178  max_linear_chainbreak_( rval.max_linear_chainbreak_ ),
179  initialized_( rval.initialized_ ),
180  ss_from_blueprint_( rval.ss_from_blueprint_ ),
181  constraints_NtoC_( rval.constraints_NtoC_ ),
182  constraints_sheet_( rval.constraints_sheet_ ),
183  constraint_file_( rval.constraint_file_ ),
184  dump_pdb_when_fail_( rval.dump_pdb_when_fail_ ),
185  rmdl_attempts_( rval.rmdl_attempts_ ),
186  use_poly_val_( rval.use_poly_val_ ),
187  invrot_tree_(rval.invrot_tree_),
188  enzcst_io_(rval.enzcst_io_)
189 {
190  if ( rval.vlb_.get() ) {
191  vlb_ = new VarLengthBuild( *rval.vlb_ );
192  }
193 }
194 
195 /// @brief default destructor
197 
198 /// @brief clone this object
201 {
202  return new BluePrintBDR( *this );
203 }
204 
205 /// @brief create this type of object
208 {
209  return new BluePrintBDR();
210 }
211 
212 /// @brief the centroid level score function, default "remodel_cen"
215 {
216  return *sfx_;
217 }
218 
219 /// @brief add instruction to the manager of this BluePrintBDR (no copy)
220 /// @param[in] bi BuildInstruction
221 void
223 {
224  manager_.add( bi );
225 
226  // additional instruction means we'll need a new re-init the VLB, so
227  // go ahead and drop the existing one
228  vlb_ = 0;
229 }
230 
231 
232 /// @brief create directed dependency between two instructions
233 void
237 )
238 {
240 }
241 
242 
243 /// @brief set the centroid level score function
244 void
246 {
247  sfx_ = sfx.clone();
248 }
249 
250 /// @brief set the centroid level score function
251 void
253 {
254  sfx_ = sfx->clone();
255 }
256 
257 /// @brief use blueprint
258 void
260 {
261  blueprint_ = new BluePrint( filename );
262 }
263 
264 /// @brief use blueprint
265 void
267 {
268  blueprint_ = blp;
269 }
270 
271 /// @brief set constraint between N- and C- terminal residues, need to set the weight
272 void
274 {
275  constraints_NtoC_ = weight;
276 }
277 
278 /// @brief set constraint file
279 void
280 BluePrintBDR::set_constraint_file( String const & constraint_file )
281 {
282  constraint_file_ = constraint_file;
283 }
284 
285 /// @brief dump pdb when this protocol failed
286 void
287 BluePrintBDR::dump_pdb_when_fail( String const & dump_pdb_when_fail )
288 {
290 }
291 
292 /// @brief set instruction by blueprint
293 bool
295 {
299 
300  bool flag( false ), insert( false );
301  String aa, ss, insert_name, ins_sec;
302  Size left( 0 ), right( 0 ), count( 0 ), insnum( 0 );
303  Pose insert_pose;
304  for( Size i=1; i<=blueprint_->total_residue(); i++ ){
305 
306  if( blueprint_->resnum( i ) != 0 ){
307  count++;
308  if( count > pose.total_residue() ){
309  TR.Error << "Residue number in blueprint file is more than that of pose!, pose/blueprint= "
310  << pose.total_residue() << "/" << count << std::endl;
311  return false;
312  }
313  }
314 
315  //if( blueprint_->buildtype( i ) != '.' && !flag ) { // found R or X at first
316  if( blueprint_->buildtype( i ) == 'R' && blueprint_->buildtype( i ) != 'I' && !flag ) { // found R at first
317 
318  if( count == 0 || i==1 ){ // N-terminal extensione
319  left = 1;
320  }else{
321  left = blueprint_->resnum( i-1 )+1; // insert in the middle of sequence
322  if( left > pose.total_residue() ){ // C-terminal extension
323  left = pose.total_residue();
324  }
325  }
326  flag = true;
327 
328  // } else if( blueprint_->buildtype( i ) == '.' && flag ){ // add instruction
329  } else if( blueprint_->buildtype( i ) != 'R' && blueprint_->buildtype( i ) != 'I' && flag ){ // add instruction
330 
331  right = blueprint_->resnum( i )-1;
332  if ( right == 0 ) { // at the N-termianl
333  right = 1;
334  } else if( right < left ){ // insert residues into the successive residue numbers
335  right = left;
336  }
337  runtime_assert( right <= pose.total_residue() );
338 
339  if( insert ) {
340  if( ins_sec.length() == 1 ) {
341  TR << "Secondary structure of insert pose will be given by Dssp" << std::endl;
342  Dssp dssp( pose );
343  dssp.insert_ss_into_pose( insert_pose );
344  } else {
345  runtime_assert( insert_pose.total_residue() == ins_sec.length() );
346  for( Size j=1; j<=insert_pose.total_residue(); j++ ) {
347  insert_pose.set_secstruct( j, ins_sec[ j-1 ] );
348  }
349  }
350  TR << "SegmentInsert left " << left << ", right: " << right
351  << ", ss: " << ss << ", aa:" << aa << ", pdb:" << insert_name << std::endl;
352  add_instruction( new SegmentInsert( Interval( left, right ), ss, aa, insert_pose ) );
353  } else {
354  TR << "SegmentRebuild left: " << left << ", right: " << right << ", ss: " << ss << ", aa:" << aa << std::endl;
355  add_instruction( new SegmentRebuild( Interval( left, right ), ss, aa ) );
356  }
357 
358  flag = false;
359  insert = false;
360  aa = "";
361  ss = "";
362 
363  } //blurprint_->buildtype()
364 
365  if( flag ){
366  if( blueprint_->buildtype( i ) == 'I' && !insert ) {
367  insert = true;
368  insnum ++;
369  ins_sec = blueprint_->secstruct( i );
370  insert_name = blueprint_->insertion( insnum );
371  core::import_pose::pose_from_pdb( insert_pose, insert_name );
372  aa += '^';
373  ss += '^';
374  } else if( blueprint_->buildtype( i ) == 'I' ) {
375  ins_sec += blueprint_->secstruct( i );
376  } else {
377  aa += blueprint_->sequence( i );
378  ss += blueprint_->secstruct( i );
379  }
380  } // flag
381 
382  } // blueprint_->total_residue()
383 
384  if( flag ){
385  if( blueprint_->resnum( blueprint_->total_residue() ) == 0 ) {
386  right = pose.total_residue();
387  }else{
388  right = blueprint_->resnum( blueprint_->total_residue() );
389  runtime_assert( right <= pose.total_residue() );
390  }
391  add_instruction( new SegmentRebuild( Interval( left, right ), ss, aa ) );
392  TR << "SegmentRebuild left: " << left << ", right: " << right << ", ss: " << ss << ", aa:" << aa << std::endl;
393  }
394 
395  if( instruction_size() < 1 ) {
396  TR << "There is no instruction in blueprint. " << std::endl;
397  return false;
398  }
399 
400  return true;
401 } // set_build_instruction
402 
403 void
405 {
406 
408  //stupid: apparently we have to make a copy of the pose on the heap for
409  //the initialization of allowed_seqpos to work
410  core::pose::PoseOP posecopy( new core::pose::Pose( pose ) );
411  allowed_seqpos->initialize_from_command_line( posecopy ); //this could be moved somewhere else to only initialize once, but probably not that important
413  setup_align_pose->set_add_target_to_pose( true );
414  setup_align_pose->set_geomcst_for_superposition_from_enz_io( enzcst_io_);
415 
417  run_align_pose->set_geomcst_for_superposition_from_enz_io( enzcst_io_);
418 
420  vlb.add_rcg( invrot_rcg );
421  vlb.loop_mover_fold_tree_constant( true ); //we're taking care of the fold tree through the above align movers
422  vlb.clear_setup_movers(); //safety
423  vlb.add_setup_mover( setup_align_pose );
424 
426  vlb.add_user_provided_mover( run_align_pose );
427 
428  if( use_abego_bias_ ) {
429  utility::vector1< std::string > abego_to_use( blueprint_->abego() );
430  abego_to_use.push_back("X"); //kinda hacky, assuming we're only adding one ligand to pose. Ideally we'd query InvrotTree for the number of targets
431  vlb_->set_abego( abego_to_use );
432  }
433 }
434 
435 
436 /// @brief apply defined moves to given Pose
437 void
439 {
444 
445  //set instruction by blueprint file and store secondary structure information
446  if( !blueprint_ && !initialized_ ){
447  TR << "You need to set a blueprint file" << std::endl;
449  return;
450  }else if( !initialized_ ){
451  if( ! set_instruction_blueprint( pose ) ){
453  return;
454  }
455  // assign secondary structure ... probably, this is bug, we have to set SS info everytime
456  // if( !ss_from_blueprint_ ){
457  // Dssp dssp( pose );
458  // dssp.insert_ss_into_pose( pose );
459  // }else{
460  // insert_ss_into_pose( pose );
461  // }
462  //initial_pose_ = new Pose( pose );
463  initialized_ = true;
464  }
465 
466  // assign secondary structure
467  if( !ss_from_blueprint_ ){
468  Dssp dssp( pose );
469  dssp.insert_ss_into_pose( pose );
470  }else{
471  blueprint_->insert_ss_into_pose( pose );
472  }
473 
474  // do centroid build
475  if ( !centroid_build( pose ) ) { // build failed
477 
478  // dump pdb when failed
479  if( dump_pdb_when_fail_ != "" ){
481  }
482  return;
483  }
484 
485  // if we've gotten to this point, then the structure has been built properly
487  // output score
488  // sfx_->show( TR, pose );
489 
490  //fpd reinitialize PDBinfo
491  if (!pose.pdb_info() || pose.pdb_info()->obsolete()) {
492  pose.pdb_info( new core::pose::PDBInfo(pose, true) );
493  }
494 }
495 
496 
500 }
501 
502 /// @brief run the centroid level build stage
503 /// @return true if loop closed, false otherwise
505  Pose & pose
506 )
507 {
513 
520  //using protocols::forge::constraints::SheetConstraintsRCG;
521  //using protocols::forge::constraints::SheetConstraintsRCGOP;
522 
524 
525 
526  // safety, clear the energies object
527  pose.energies().clear();
528 
529  // make backup Pose for transferring sidechains
530  Pose archive_pose = pose;
531  Pose modified_archive_pose = archive_pose;
532  manager_.modify( modified_archive_pose );
533 
534  // ensure modified_archive_pose is completely full-atom, otherwise mismatch
535  // will occur when restoring sidechains at the end of the procedure
536  bool mod_ap_is_full_atom = true;
537  for ( Size i = 1, ie = modified_archive_pose.n_residue(); mod_ap_is_full_atom && i != ie; ++i ) {
538  mod_ap_is_full_atom &= ( modified_archive_pose.residue( i ).residue_type_set().name() == core::chemical::FA_STANDARD );
539  }
540 
541  if ( !mod_ap_is_full_atom ) {
543  }
544 
545  if( use_poly_val_ ) {
546  // flip to poly-ala-gly-pro-disulf pose
547  utility::vector1< Size > protein_residues;
548  for ( Size i = 1, ie = pose.n_residue(); i <= ie; ++i ) {
549  if ( pose.residue( i ).is_protein() ) {
550  protein_residues.push_back( i );
551  }
552  }
553  construct_poly_XXX_pose( "VAL", pose, protein_residues, false, true, false );
554  }
555  /////////////////////////////////////////////////////////////////////////////////////
556 
557  // Run VLB to build the new section, if no segments have been added/deleted
558  // we use the same VLB so that fragment caching works properly
559  if ( !vlb_.get() ) {
560  vlb_ = new VarLengthBuild( manager_ );
561  }
562 
563  // set weight of constraints
564  if( constraints_NtoC_ > 0.0 || constraints_sheet_ > 0.0 ){
565  Real cst_weight( sfx_->get_weight( core::scoring::atom_pair_constraint ) );
566  runtime_assert( cst_weight > 0.0 );
567  }
568 
569  if( constraints_NtoC_ > 0.0 ){
570  NtoC_RCGOP rcg = new NtoC_RCG;
571  vlb_->add_rcg( rcg );
572  }
573 
574  if( constraints_sheet_ > 0.0 ){
576  vlb_->add_rcg( rcg );
577  }
578 
579  if( constraint_file_ != "" ){
580  ConstraintFileRCGOP cst = new ConstraintFileRCG( constraint_file_ );
581  vlb_->add_rcg( cst );
582  }
583 
584  vlb_->scorefunction( sfx_ );
586  vlb_->use_fullmer( use_fullmer_ );
587  vlb_->max_linear_chainbreak( max_linear_chainbreak_ );
588  vlb_->loop_mover_str( loop_mover_str_ );
589  vlb_->num_fragpick( num_fragpick_ );
590 
591  if( use_abego_bias_ ) {
592  vlb_->set_abego( blueprint_->abego() );
593  }
594 
595  if( invrot_tree_ ){
596  this->setup_invrot_tree_in_vlb( *vlb_, pose );
597  }
598 
599 
600  if ( use_sequence_bias_ ) {
601  vlb_->original_sequence( archive_pose.sequence() );
602  }
603 
605  cst.show(std::cout);
606 
607  vlb_->apply( pose );
608 
609  vlb_->clear_rcgs();
610 
611  if ( vlb_->get_last_move_status() == MS_SUCCESS ) {
612 
613  // record the used manager w/ all mapping info
614  manager_ = vlb_->manager();
615 
616  // safety, clear all the energies before restoring full-atom residues and
617  // scoring
618  pose.energies().clear();
619 
620  if ( !core::pose::symmetry::is_symmetric( pose ) ) {
621  // Swap back original sidechains. At the moment this is a two step process
622  // in case any sidechains from SegmentInsert and the like that aren't in the
623  // original archive pose need to be transferred.
624  restore_residues( modified_archive_pose, pose );
625  restore_residues( manager_.original2modified(), archive_pose, pose );
626  } else {
627  TR << "Side-chains won't be swapped back to original. " << std::endl;
628  }
629 
630  return true; // loop closed
631 
632  } else {
633 
634  pose = archive_pose;
635 
636  }
637 
638  return false; // false if loop not closed
639 }
640 
641 /// @brief parse xml
642 void
644  TagPtr const tag,
645  DataMap & data,
646  Filters_map const &,
647  Movers_map const &,
648  Pose const & )
649 {
650  String const blueprint( tag->getOption<std::string>( "blueprint", "" ) );
651  if( blueprint == "" ){
652  TR << "No input of blueprint file ! " << std::endl;
653  runtime_assert( false );
654  }
655  set_blueprint( blueprint );
656 
657  // set secondary structure using blueprint
658  ss_from_blueprint_ = tag->getOption<bool>( "ss_from_blueprint", 1 );
659 
660  // set scorefxn
661  String const sfxn ( tag->getOption<String>( "scorefxn", "" ) );
662  if( sfxn != "" ) {
663  sfx_ = data.get< ScoreFunction * >( "scorefxns", sfxn );
664  TR << "score function, " << sfxn << ", is used. " << std::endl;
665  }
666 
667  // pick fragment using sequence information
668  use_sequence_bias_ = tag->getOption<bool>( "use_sequence_bias", 0 );
669 
670  // pick fragment using abego torsion information
671  use_abego_bias_ = tag->getOption<bool>( "use_abego_bias", 0 );
672 
673  // constraint N- and C- terminal
674  constraints_NtoC_ = tag->getOption<Real>( "constraints_NtoC", -1.0 );
675 
676  // constraints between Ca atoms in sheet
677  constraints_sheet_ = tag->getOption<Real>( "constraints_sheet", -1.0 );
678 
679  // set constraint file
680  constraint_file_ = tag->getOption<String>( "constraint_file", "" );
681 
682  // dump pdb when the protocol fail
683  dump_pdb_when_fail_ = tag->getOption<String>( "dump_pdb_when_fail", "" );
684 
685  // loop mover for rebuilding loops
686  loop_mover_str_ = tag->getOption<String>( "loop_mover", "RemodelLoopMover" );
687 
688  // number of allowed_closure_attempts_ of RemodelLoopMover
689  rmdl_attempts_ = tag->getOption<Size>( "rmdl_attempts", 1 );
690 
691  // entire sequence except for rebuilding parts become poly-Val ( default true )
692  use_poly_val_ = tag->getOption<bool>( "use_poly_val", 1 );
693 
694  //in case we'ref folding up around a ligand
695  if( tag->hasOption("invrot_tree")){
696  String cstfilename = tag->getOption<String>( "invrot_tree", "");
698  enzcst_io->read_enzyme_cstfile( cstfilename );
700  invrot_tree_->generate_targets_and_inverse_rotamers();
701  enzcst_io_ = enzcst_io;
702 
703  //this also means that we'd like the constraint score terms turned on
704  if( sfx_->has_zero_weight( core::scoring::coordinate_constraint ) ) sfx_->set_weight( core::scoring::coordinate_constraint, 1.0 );
705  if( sfx_->has_zero_weight( core::scoring::atom_pair_constraint ) ) sfx_->set_weight( core::scoring::atom_pair_constraint, 1.0 );
706  if( sfx_->has_zero_weight( core::scoring::angle_constraint ) ) sfx_->set_weight( core::scoring::angle_constraint, 1.0 );
707  if( sfx_->has_zero_weight( core::scoring::dihedral_constraint ) ) sfx_->set_weight( core::scoring::dihedral_constraint, 1.0 );
709 
710  }
711 }
712 
713 
714 } // namespace fldsgn
715 } // namespace protocols