Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DefineMovableLoops.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 /// @brief specific to seeded abinitio protocol
11 /// this class finds loops after seeded abinitio that should be closed
12 /// @author Eva-Maria Strauch (evas01@u.washington.edu)
13 
17 
18 #include <core/types.hh>
19 #include <core/pose/Pose.hh>
20 #include <core/pose/Pose.fwd.hh>
21 #include <core/pose/util.hh>
25 
26 //protocols
27 #include <protocols/loops/Loop.hh>
28 #include <protocols/loops/Loops.hh>
31 #include <protocols/loops/util.hh>
32 #include <protocols/loops/Loops.hh>
33 #include <core/scoring/dssp/Dssp.hh>
35 
36 // C++ headers
37 #include <string>
38 #include <utility/string_util.hh>
39 #include <basic/Tracer.hh>
40 
41 //parser
42 #include <utility/tag/Tag.hh>
43 #include <utility/tag/Tag.fwd.hh>
46 
47 //util
48 #include <utility/vector1.hh>
49 #include <set>
50 #include <boost/foreach.hpp>
51 
52 #define foreach BOOST_FOREACH
53 
54 using namespace core;
55 using namespace protocols::seeded_abinitio;
56 static basic::Tracer TR( "protocols.seeded_abinitio.DefineMovableLoops" );
57 
58 
59 namespace protocols {
60  namespace seeded_abinitio {
61 
62  using namespace protocols::moves;
63  using namespace core;
64 
66  DefineMovableLoopsCreator::keyname() const
67  {
68  return DefineMovableLoopsCreator::mover_name();
69  }
70 
72  DefineMovableLoopsCreator::create_mover() const {
73  return new DefineMovableLoops();
74  }
75 
77  DefineMovableLoopsCreator::mover_name()
78  {
79  return "DefineMovableLoops";
80  }
81 
82  DefineMovableLoops::~DefineMovableLoops() {}
83 
84  DefineMovableLoops::DefineMovableLoops() :
85  protocols::moves::Mover( DefineMovableLoopsCreator::mover_name() )
86  {
87  use_cutpoints_ = true;
88  secstructure_ = "";
89  chains_.clear();
90  chainbreakweights_ = true;
91  secstructure_ = "";
92  chains_.clear();
93  seed_vector_.clear();
94  }
95 
96 bool
98  return chainbreakweights_;
99 }
100 
101 void
103  chainbreakweights_ = acbw;
104 }
105 
106 void
108  use_cutpoints_ = uc;
109 }
110 
111 bool
113  return use_cutpoints_;
114 }
115 
116 
119  std::string secstruct,
120  core::Size offset,//first position to start from
121  protocols::loops::Loops seeds // change back to OP eventually...
122  ){
123 
124  //bool use_seeds( seeds );
125  bool use_seeds = seeds.size() > 0;
126  Size end = offset + secstruct.length() - 1;//double check....
127  utility::vector1< Size > adjusted_cutpoints;
128 
129  //curate the cutpoint list from the cutpoints between the chain ends
130  if( use_cutpoints() ){
132  utility::vector1< Size > cutpoints = ft->cutpoints();
134  //adding last chains' end too, since it isnt included in chain_endings( and to avoid seg fault beloew)
135  chain_ends.push_back( pose.total_residue() );
136 
137  //debug
138  for (Size i = 1; i <= chain_ends.size(); ++i )
139  TR.Debug<<"chain endings: " << chain_ends[i] <<std::endl;
140 
141  //adding together relevant cutpoints
142  for( Size cut_it = 1; cut_it <= cutpoints.size(); ++ cut_it ){
143  TR.Debug <<"cutpoints of current foldtree: "<< cutpoints[cut_it] <<std::endl;
144 
145  for( Size ends_it = 1; ends_it <= chain_ends.size(); ++ends_it ){
146  if( (cutpoints[cut_it] != chain_ends[ends_it]) && (cutpoints[cut_it] <= end ) && ( cutpoints[cut_it] >= offset) ){
147  adjusted_cutpoints.push_back( cutpoints[cut_it] );
148  TR <<"adjusted cutpoint "<< cutpoints[cut_it] << std::endl;
149  }
150  }
151  }
152  }
153 
154  //put loop regions together then pull the ones out that contain a cutpoint if use_cutpoints is specified
155  protocols::loops::Loops found_loops;
156 
157  TR.Debug <<"sec. strc: "<< secstruct <<std::endl;
158  char ss;
159  utility::vector1 < Size > individual_loop;
160  Size cut = 0;
161 
162  for( Size ss_i = 0; ss_i < secstruct.length() ; ++ss_i ){
163  ss = secstruct[ss_i];
164 
165  if ( ss == 'L' ){
166 
167  //is there a seed and if so, only add to loop if the current indx is not part of it
168  if( use_seeds && !seeds.is_loop_residue( ss_i + offset ) ) {
169  individual_loop.push_back( ss_i + offset );
170  }
171 
172  if( !use_seeds ){
173  individual_loop.push_back( ss_i + offset );
174  }
175  TR.Debug <<"use cutpoint " << use_cutpoints_ << " cut: " << cut <<" iterator with offset: " << ss_i + offset <<std::endl;
176  if( use_cutpoints_ && is_cut( adjusted_cutpoints, ss_i + offset ) ){
177  cut = ss_i + offset;
178  TR <<"cut: " << cut << std::endl;
179  }
180  }//end if statemnt is loop
181 
182 
183  if( ss != 'L' ){
184 
185  //for chainbreak weights ///// this is only added if use cutpoints is set to true!!!!
186  if(chainbreakweights() && cut > 0 ){
187  TR <<"adding chainbreak type"<< std::endl;
190  }
191  //take loop container and add as loop, reset temporariy vector with loop positions
192  if( individual_loop.size() > 0 ){
193  if( use_cutpoints_ && cut > 0 ){
194  TR.Debug <<"selecting loop with cutpoint only" << std::endl;
195  found_loops.add_loop( individual_loop[1], individual_loop[individual_loop.size()], cut , 0, false );
196  }
197  if ( !use_cutpoints_ ){
198  TR.Debug << "not using cutpoint " << std::endl;
199  found_loops.add_loop( individual_loop[1], individual_loop[individual_loop.size()], cut , 0, false );
200  }
201  }
202  individual_loop.clear();
203  cut = 0;
204  }//if statement loop stopped
205  }//end for loop through sec strct
206 
207  TR <<"loop return: " << found_loops << std::endl;
208  protocols::loops::LoopsOP newloops = new protocols::loops::Loops( found_loops );
209  return newloops;
210 }
211 
212 
213 bool
215  bool res_cut = false;
216  for ( utility::vector1<Size>::iterator it = cut_points.begin(); it != cut_points.end(); ++it ){
217  if (*it == residue)
218  res_cut = true;
219  }
220  return res_cut;
221 }
222 
223 void
226 
227  Size residues = 0;
228  //ensure that the residues specified are covered by the secondary structure input
229  for( Size it = 1; it <= chains_.size(); ++it ){
230  residues += pose.split_by_chain( chains_[it] ).total_residue();
231  TR.Debug <<"residues to compare: "<<residues <<std::endl;
232  }
233  TR << pose.fold_tree() <<std::endl;
234  TR.Debug <<"residues " <<residues <<" ss assignment: "<< secstructure_.length();
235 
236  if( residues != secstructure_.length() ) {
237  TR <<"residues vs " <<residues <<" ss assignment: "<< secstructure_.size() << std::endl;;
238  utility_exit_with_message("input residues under considerations do not agree with the number of secondary strcutres assignments");
239  }
240 
241  //define offset points, as in which residue to start searching loops
242  Size start_res = pose.conformation().chain_begin( chains_[1] );
243  //end point, at the last chain
244  Size stop_res = pose.conformation().chain_end( chains_[chains_.size()] );
245 
246  //for debugging
247  if( secstructure_.length() != stop_res - start_res + 1 ){
248  TR.Debug << "secstr lenght: " << secstructure_.length() << " stop: " << stop_res << " start: " << start_res << std::endl;
249  utility_exit_with_message("secondary structure length does not equal the start and stop of the chain!!!" );
250  //allow blueprint incorporation above.... todo
251  }
252 
253  Loops seeds( parse_seeds(pose, seed_vector_ ) );
254  TR.Debug <<"start searching: "<<start_res <<" stop searching: " << stop_res <<std::endl;
255  loops_ = find_loops( pose, secstructure_ , start_res , seeds );///make accessor for seeds
256  TR <<"loops " << *loops_ <<std::endl;
257 
258 }
259 
263 }
264 
265 void
267  utility::tag::TagPtr const tag,
271  core::pose::Pose const & pose )
272 {
273  TR<<"DefineMovableLoops has been instantiated"<<std::endl;
274 
275  //adding the LoopOP to the data map
277  data.add( "loops", "found_loops", loops_ );
278 
279  chainbreakweights_ = tag->getOption< bool >("add_chainbreakterm" , 1 );
280 
281  //get secondary structure either from input template, a string in the xml or through the
282  use_cutpoints_ = tag->getOption< bool >( "cutpoint_based" , 1 );
283 
284  if( tag->hasOption("secstrct") ){
285  secstructure_ = tag->getOption< std::string > ( "secstrct" );
286  TR<<"getting secstructure from a string" <<std::endl;
287  if( secstructure_ == "self" ){
288  secstructure_ = pose.secstruct();
289  TR<<"extracting secondary structure from input pose" <<std::endl;
290  }
291  }
292 
293  if( tag->hasOption( "template_pdb" ) ){
294  std::string const template_pdb_fname( tag->getOption< std::string >( "template_pdb" ));
296  core::import_pose::pose_from_pdb( *template_pdb_, template_pdb_fname );
297  TR<<"read in a template pdb with " <<template_pdb_->total_residue() <<"residues"<<std::endl;
300  for( core::Size res = 1 ; res <= template_pdb_->total_residue(); ++res ) secstructure_ += template_pdb_->secstruct( res );
301  secstructure_ = template_pdb_->secstruct();
302  TR << secstructure_ << std::endl;
303  }
304 
305  //command line option overwrites parser input for secondary structure string
306  /*
307  if (option[ OptionKeys::in::file::psipred_ss2 ].user() ) {
308  std::string filename( option[ OptionKeys::in::file::psipred_ss2 ]().name() );
309  utility::vector1< char > secstructs;
310  utility::io::izstream data( filename );
311  //core::pose::util.cc has a method to parse it best
312  }*/
313 
314  if( tag->hasOption( "chain_num" ) ){
315  TR<<"NOTE: chains have to be consecutive" << std::endl;
316  std::string chain_val( tag->getOption< std::string >( "chain_num" ) );
317  utility::vector1< std::string > const chain_keys( utility::string_split( chain_val, ',' ) );
318  foreach( std::string const key, chain_keys ){
319  Size n;
320  std::istringstream ss( key );
321  ss >> n;
322  chains_.push_back( n );
323  TR<<"adding chain "<<key<<std::endl;
324  }
325  }
326 
327  if( chains_.size() <= 0 ){
328  for(Size chain = 1; chain <= pose.conformation().num_chains(); ++chain ){
329  chains_.push_back( chain );
330  TR<<"no chains specified, defaulting to use the last chain: "<< chain << std::endl;
331  }
332  }
333 
334  /// read input seeds
335  utility::vector0< TagPtr > const branch_tags( tag->getTags() );
336  foreach( TagPtr const btag, branch_tags ){
337 
338  if( btag->getName() == "Seeds" ) { //need an assertion for the presence of these or at least for the option file
339  std::string const beginS( btag->getOption<std::string>( "begin" ) );
340  std::string const endS( btag->getOption<std::string>( "end" ) );
341  std::pair <std::string,std::string> seedpair;
342  seedpair.first = beginS;
343  TR.Debug <<"parsing seeds: " << beginS << " " <<endS <<std::endl;
344  seedpair.second = endS;
345  seed_vector_.push_back( seedpair );
346  }//end seeds
347  }//end b-tags
348 }//end parse_my_tag
349 }
350 }