Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CloseFold.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 // This file is part of the Rosetta software suite and is made available under license.
5 // The Rosetta software is developed by the contributing members of the Rosetta Commons consortium.
6 // (C) 199x-2009 Rosetta Commons participating institutions and developers.
7 // For more information, see http://www.rosettacommons.org/.
8 //
9 /// @file protocols/seeded_abinitio/
10 /// @author Eva-Maria Strauch (evas01@u.washington.edu)
11 
15 
16 #include <core/types.hh>
17 #include <core/pose/Pose.hh>
18 #include <core/pose/Pose.fwd.hh>
19 #include <core/pose/util.hh>
24 
25 //protocols
26 #include <protocols/loops/Loop.hh>
27 #include <protocols/loops/Loops.hh>
31 #include <protocols/loops/util.hh>
32 #include <protocols/loops/Loops.hh>
33 //#include <protocols/loops/LoopMover.hh>
35 //#include <protocols/loops/LoopMover_CCD.hh>
36 //#include <protocols/loops/LoopMover_KIC.hh>
37 //#include <protocols/loops/LoopMoverFactory.hh>
39 
43 
44 //fragments
46 #include <core/fragment/FragSet.hh>
47 #include <core/fragment/Frame.hh>
49 #include <core/fragment/util.hh>
50 
51 // C++ headers
52 #include <string>
53 #include <utility/string_util.hh>
54 
55 #include <basic/Tracer.hh>
56 
66 #include <core/chemical/util.hh>
67 
68 //parser
69 #include <utility/tag/Tag.hh>
70 #include <utility/tag/Tag.fwd.hh>
73 
74 //util
75 #include <utility/vector1.hh>
76 #include <set>
77 #include <utility/excn/Exceptions.hh>
78 #include <boost/foreach.hpp>
79 
80 #define foreach BOOST_FOREACH
81 
82 using namespace core;
83 using namespace protocols::seeded_abinitio;
84 static basic::Tracer TR( "protocols.seeded_abinitio.CloseFold" );
85 
86 
87 namespace protocols {
88  namespace seeded_abinitio {
89 
90  using namespace protocols::moves;
91  using namespace core;
92 
94  CloseFoldCreator::keyname() const
95  {
96  return CloseFoldCreator::mover_name();
97  }
98 
100  CloseFoldCreator::create_mover() const {
101  return new CloseFold();
102  }
103 
105  CloseFoldCreator::mover_name()
106  {
107  return "CloseFold";
108  }
109 
110 
111  CloseFold::~CloseFold() {}
112 
113  CloseFold::CloseFold() :
114  protocols::moves::Mover( CloseFoldCreator::mover_name() )
115  {
116  use_cutpoints_ = true;
117  secstructure_ = "";
118  chains_.clear();
119  //cen_scorefxn_,
120  //fa_scorefxn
121  chainbreakweights_ = true;
122  secstructure_ = "";
123  chains_.clear();
124  seed_vector_.clear();
125  trials_ = 3;
126  idealize_ = true;
127  kic_ = false;
128  //frag3_ = new core::fragment::ConstantLengthFragSet( *frag3 );
129  //frag9_ = new core::fragment::ConstantLengthFragSet( *frag9 );
130  }
131 
134  return( protocols::moves::MoverOP( new CloseFold( *this ) ) );
135 }
136 
139  return protocols::moves::MoverOP( new CloseFold );
140 }
141 
142 bool
144  return chainbreakweights_;
145 }
146 
147 void
149  chainbreakweights_ = acbw;
150 }
151 
152 void
154  use_cutpoints_ = uc;
155 }
156 
157 bool
159  return use_cutpoints_;
160 }
161 
164  return trials_;
165 }
166 
167 void
169  trials_ = trials_quick_ccd;
170 }
171 /*
172 core::scoring::ScoreFunctionOP
173 CloseFold::cen_scorefxn(){
174  return cen_scorefxn_;
175 }
176 
177 core::scoring::ScoreFunctionOP
178 CloseFold::fa_scorefxn(){
179  return fa_scorefxn_ ;
180 }
181 */
182 
183 void
186  for (i = fragments_->begin(); i != fragments_->end(); ++i) {
187  Size position = (*i)->start();
188  library_[position] = **i;
189  }
190 }
191 
192 
195  std::string secstruct,
196  core::Size offset,//first position to start from
197  protocols::loops::Loops seeds // change back to OP eventually...
198  ){
199 
200  //bool use_seeds( seeds );
201  bool use_seeds = seeds.size() > 0;
202  Size end = offset + secstruct.length() - 1;//double check....
203  utility::vector1< Size > adjusted_cutpoints;
204 
205  //curate the cutpoint list from the cutpoints between the chain ends
206  if( use_cutpoints() ){
208  utility::vector1< Size > cutpoints = ft->cutpoints();
210  //adding last chains' end too, since it isnt included in chain_endings( and to avoid seg fault beloew)
211  chain_ends.push_back( pose.total_residue() );
212 
213  //debug
214  for (Size i = 1; i <= chain_ends.size(); ++i )
215  TR <<"chain endings: " << chain_ends[i] <<std::endl;
216 
217  //adding together relevant cutpoints
218  for( Size cut_it = 1; cut_it <= cutpoints.size(); ++ cut_it ){
219  TR.Debug <<"cutpoints of current foldtree: "<< cutpoints[cut_it] <<std::endl;
220 
221  for( Size ends_it = 1; ends_it <= chain_ends.size(); ++ends_it ){
222  if( (cutpoints[cut_it] != chain_ends[ends_it]) && (cutpoints[cut_it] <= end ) && ( cutpoints[cut_it] >= offset) ){
223  adjusted_cutpoints.push_back( cutpoints[cut_it] );
224  TR <<"adjusted cutpoint "<< cutpoints[cut_it] << std::endl;
225  }
226  }
227  }
228  }
229 
230  //put loop regions together then pull the ones out that contain a cutpoint if use_cutpoints is specified
231  protocols::loops::Loops found_loops;
232 
233  TR <<"sec. strc: "<< secstruct <<std::endl;
234  char ss;
235  utility::vector1 < Size > individual_loop;
236  Size cut = 0;
237 
238  for( Size ss_i = 0; ss_i < secstruct.length() ; ++ss_i ){
239  ss = secstruct[ss_i];
240 
241  if ( ss == 'L' ){
242 
243  //is there a seed and if so, only add to loop if the current indx is not part of it
244  if( use_seeds && !seeds.is_loop_residue( ss_i + offset ) ) {
245  individual_loop.push_back( ss_i + offset );
246  }
247 
248  if( !use_seeds ){
249  individual_loop.push_back( ss_i + offset );
250  }
251  TR.Debug <<"use cutpoint " << use_cutpoints_ << " cut: " << cut <<" iterator with offset: " << ss_i + offset <<std::endl;
252  if( use_cutpoints_ && is_cut( adjusted_cutpoints, ss_i + offset ) ){
253  cut = ss_i + offset;
254  TR <<"cut: " << cut << std::endl;
255  }
256  }//end if statemnt is loop
257 
258 
259  if( ss != 'L' ){
260 
261  //for chainbreak weights ///// this is only added if use cutpoints is set to true!!!!
262  if(chainbreakweights() && cut > 0 ){
263  TR <<"adding chainbreak type"<< std::endl;
266  }
267  //take loop container and add as loop, reset temporariy vector with loop positions
268  if( individual_loop.size() > 0 ){
269  if( use_cutpoints_ && cut > 0 ){
270  TR.Debug <<"selecting loop with cutpoint only" << std::endl;
271  found_loops.add_loop( individual_loop[1], individual_loop[individual_loop.size()], cut , 0, false );
272  }
273  if ( !use_cutpoints_ ){
274  TR.Debug << "not using cutpoint " << std::endl;
275  found_loops.add_loop( individual_loop[1], individual_loop[individual_loop.size()], cut , 0, false );
276  }
277  }
278  individual_loop.clear();
279  cut = 0;
280  }//if statement loop stopped
281  }//end for loop through sec strct
282 
283  TR <<"loop return: " << found_loops << std::endl;
284  protocols::loops::LoopsOP newloops = new protocols::loops::Loops( found_loops );
285  return newloops;
286 }
287 
288 
289 bool
291  bool res_cut = false;
292  for ( utility::vector1<Size>::iterator it = cut_points.begin(); it != cut_points.end(); ++it ){
293  if (*it == residue)
294  res_cut = true;
295  }
296  return res_cut;
297 }
298 
299 void
301  using namespace protocols::loops;
302 
303  core::kinematics::FoldTree f_orig = pose.fold_tree();
304 
305  //improvisory loop closure protocol from Frank
306  for ( Loops::iterator it=loops->v_begin(), it_end=loops->v_end(); it != it_end; ++it ) {
307  Loop buildloop( *it );
308  set_single_loop_fold_tree( pose, buildloop );
309  set_extended_torsions( pose, buildloop );
310  //bool chainbreak_present = !pose.residue( buildloop.start() ).is_lower_terminus() &&
311  //!pose.residue( buildloop.stop() ).is_upper_terminus();
312  bool chainbreak_present = true;
313  if ( chainbreak_present ) {
314  std::cout<<"start fast ccd closure " << std::endl;
316  set_move_map_for_centroid_loop( buildloop, *mm_one_loop );
317  loops::loop_mover::perturb::fast_ccd_close_loops( pose, buildloop, *mm_one_loop );
318  }
319  // restore foldtree
320  pose.fold_tree( f_orig );
321  }
322 
323  if( kic ){
325  lr_mover->scorefxns( cen_scorefxn_, fa_scorefxn_ ); // should only use the centroid anyway
326  lr_mover->loops( loops );
327  lr_mover->remodel( "perturb_kic" );
328  //lr_mover->cmd_line_csts( true );
329  lr_mover->rebuild_filter( 999 );
330  lr_mover->n_rebuild_tries( trials() );////////////fix
331  lr_mover->copy_sidechains( true );
332  //lr_mover->set_current_tag( get_current_tag() );
333  lr_mover->apply( pose );
334  remove_cutpoint_variants( pose );
335 
336  }
337 }
338 
339 void
341  using namespace protocols::loops;
342 
343  core::kinematics::FoldTree f_orig( pose.fold_tree() );
344 
346  ccd_closure->scorefxns( cen_scorefxn_, fa_scorefxn_ );
347  ccd_closure->remodel("quick_ccd");
348  ccd_closure->intermedrelax("no");
349  ccd_closure->refine("no");
350  ccd_closure->relax("no");
351  ccd_closure->loops( loops );
352  //ccd_closure->rebuild_filter( 999 );
353  ccd_closure->n_rebuild_tries( trials() );
354  ccd_closure->copy_sidechains( true );
355 
356  //apply fragments
358  fragments.push_back(fragments_);
359  ccd_closure->frag_libs(fragments);
360 
361  //set kinematics
363  fold_tree_from_loops( pose, *loops, looptree );
364  pose.fold_tree(looptree);
365  TR << "current loop-based foldtree: " << looptree << std::endl;
366  ccd_closure->apply(pose);
367 
369  //recover old foldtree
370  pose.fold_tree( f_orig );
371  remove_cutpoint_variants( pose );
372 
373 }//end quick_ccd_closure
374 
375 void
378 
379  Size residues = 0;
380  //ensure that the residues specified are covered by the secondary structure input
381  for( Size it = 1; it <= chains_.size(); ++it ){
382  residues += pose.split_by_chain( chains_[it] ).total_residue();
383  TR <<"residues to compare: "<<residues <<std::endl;
384  }
385  TR << pose.fold_tree() <<std::endl;
386  TR <<"residues " <<residues <<" ss assignment: "<< secstructure_.length();
387 
388  if( residues != secstructure_.length() ) {
389  TR.Debug <<"residues vs " <<residues <<" ss assignment: "<< secstructure_.size() << std::endl;;
390  utility_exit_with_message("input residues under considerations do not agree with the number of secondary strcutres assignments");
391  }
392 
393  //define offset points, as in which residue to start searching loops
394  Size start_res = pose.conformation().chain_begin( chains_[1] );
395  //end point, at the last chain
396  Size stop_res = pose.conformation().chain_end( chains_[chains_.size()] );
397 
398  //for debugging
399  if( secstructure_.length() != stop_res - start_res + 1 ){
400  TR.Debug << "secstr lenght: " << secstructure_.length() << " stop: " << stop_res << " start: " << start_res << std::endl;
401  utility_exit_with_message("secondary structure length does not equal the start and stop of the chain!!!" );
402  //allow blueprint incorporation above.... todo
403  }
404 
405  Loops seeds( parse_seeds(pose, seed_vector_ ) );
406  TR.Debug <<"start searching: "<<start_res <<" stop searching: " << stop_res <<std::endl;
407  loops_ = find_loops( pose, secstructure_ , start_res , seeds );///make accessor for seeds
408  TR <<"loops " << *loops_ <<std::endl;
409 
410  if( ccd_ )
411  quick_closure( pose, loops_ );
412 
413  if( kic_ )
414  fast_loopclose( pose, loops_ , kic_ );
415  else
416  TR << "no loop closure protocol specified " << std::endl;
417 
418 }
419 
423 }
424 
425 void
427  utility::tag::TagPtr const tag,
431  core::pose::Pose const & pose )
432 {
433  TR<<"CloseFold has been instantiated"<<std::endl;
434 
437  using std::string;
438 
439  if( tag->hasOption("fragments")){
440  string fragments_file = tag->getOption<string>("fragments");
441  fragments_ = FragmentIO().read_data(fragments_file);
442  }
443 
444  if( !tag->hasOption("fragments"))
445  throw utility::excn::EXCN_RosettaScriptsOption("need to supply fragments...currently still not accessing the general fragment pool" );
446 
447  //adding the LoopOP to the data map
449  data.add( "loops", "found_loops", loops_ );
450 
451  chainbreakweights_ = tag->getOption< bool >("add_chainbreakterm" , 1 );
452 
453  //get secondary structure either from input template, a string in the xml or through the
454  use_cutpoints_ = tag->getOption< bool >( "cutpoint_based" , 1 );
455 
456  std::string const fa_scorefxn_name( tag->getOption<std::string>( "fa_scorefxn", "score12" ) );
457  fa_scorefxn_ = new core::scoring::ScoreFunction( *(data.get< core::scoring::ScoreFunction * >( "scorefxns", fa_scorefxn_name) ));
458 
459  std::string const cen_scorefxn_name( tag->getOption<std::string>( "cen_scorefxn", "score4L" ) );
460  cen_scorefxn_ = new core::scoring::ScoreFunction( *(data.get< core::scoring::ScoreFunction * >( "scorefxns", cen_scorefxn_name) ));
461 
462  //options for fast closure
463  kic_ = tag->getOption< bool > ("use_kic" , 0 );
464  idealize_ = tag->getOption< bool >( "idealize" , 1 );
465 
466  ccd_ = tag->getOption< bool >("use_ccd", 1 );
467 
468  //options for quick closure
469  trials_ = tag->getOption< core::Size >("trials_ccd" , 3 );
470 
471  if( tag->hasOption("secstrct") ){
472  secstructure_ = tag->getOption< std::string > ( "secstrct" );
473  TR<<"getting secstructure from a string" <<std::endl;
474  if( secstructure_ == "self" ){
475  secstructure_ = pose.secstruct();
476  TR<<"extracting secondary structure from input pose" <<std::endl;
477  }
478  }
479 
480  if( tag->hasOption( "template_pdb" ) ){
481  std::string const template_pdb_fname( tag->getOption< std::string >( "template_pdb" ));
483  core::import_pose::pose_from_pdb( *template_pdb_, template_pdb_fname );
484  TR<<"read in a template pdb with " <<template_pdb_->total_residue() <<"residues"<<std::endl;
485  //template_presence_ = true;
488  for( core::Size res = 1 ; res <= template_pdb_->total_residue(); ++res ) secstructure_ += template_pdb_->secstruct( res );
489  secstructure_ = template_pdb_->secstruct();
490  TR << secstructure_ << std::endl;
491  }
492 
493  if( tag->hasOption( "chain_num" ) ){
494  TR<<"NOTE: chains have to be consecutive" << std::endl;
495  std::string chain_val( tag->getOption< std::string >( "chain_num" ) );
496  utility::vector1< std::string > const chain_keys( utility::string_split( chain_val, ',' ) );
497  foreach( std::string const key, chain_keys ){
498  Size n;
499  std::istringstream ss( key );
500  ss >> n;
501  chains_.push_back( n );
502  TR<<"adding chain "<<key<<std::endl;
503  }
504  }
505 
506  //if( !tag->hasOption( "chains_num" ) ){
507  if( chains_.size() <= 0 ){
508  //TR<<"no chains specified, defaulting to last chain only"<<std::endl;
509  for(Size chain = 1; chain <= pose.conformation().num_chains(); ++chain ){
510  chains_.push_back( chain );
511  TR<<"no chains specified, defaulting to use the last chain: "<< chain << std::endl;
512  }
513  }
514 
515  /// read input seeds
516  utility::vector0< TagPtr > const branch_tags( tag->getTags() );
517  foreach( TagPtr const btag, branch_tags ){
518 
519  if( btag->getName() == "Seeds" ) { //need an assertion for the presence of these or at least for the option file
520 
521  std::string const beginS( btag->getOption<std::string>( "begin" ) );
522  std::string const endS( btag->getOption<std::string>( "end" ) );
523  std::pair <std::string,std::string> seedpair;
524  seedpair.first = beginS;
525  TR.Debug <<"parsing seeds: " << beginS << " " <<endS <<std::endl;
526  seedpair.second = endS;
527  seed_vector_.push_back( seedpair );
528  }//end seeds
529  }//end b-tags
530 }//end parse_my_tag
531 
532 }
533 }