Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SwapSegment.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 
10 /// @file protocols/seeded_abinitio/SwapSegment.cc
11 /// @brief
12 /// @author Eva-Maria Strauch (evas01@u.washington.edu)
13 
16 
17 #include <core/types.hh>
18 #include <core/pose/Pose.hh>
19 #include <core/pose/Pose.fwd.hh>
20 #include <core/pose/util.hh>
22 
25 
26 //other
28 #include <core/pose/selection.hh>
29 
30 // C++ headers
31 #include <string>
32 
33 #include <basic/Tracer.hh>
36 
37 //parser
38 #include <utility/tag/Tag.hh>
39 #include <utility/tag/Tag.fwd.hh>
41 
42 //loops
43 #include <protocols/loops/Loop.hh>
45 
46 //util
47 #include <utility/vector1.hh>
48 #include <boost/foreach.hpp>
49 #include <utility/vector0.hh>
50 
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.SwapSegment" );
57 
58 
59 namespace protocols {
60  namespace seeded_abinitio {
61 
62  using namespace protocols::moves;
63  using namespace core;
64 
66  SwapSegmentCreator::keyname() const
67  {
68  return SwapSegmentCreator::mover_name();
69  }
70 
72  SwapSegmentCreator::create_mover() const {
73  return new SwapSegment();
74  }
75 
77  SwapSegmentCreator::mover_name(){
78  return "SwapSegment";
79  }
80 
81 
82  SwapSegment::~SwapSegment() {}
83 
84  SwapSegment::SwapSegment():
85  protocols::moves::Mover( SwapSegmentCreator::mover_name() ){
86  previously_grown_ = false;
87  }
88 
91  return( protocols::moves::MoverOP( new SwapSegment( *this ) ) );
92 }
93 
97 }
98 
99 void
101  core::pose::Pose & pose,
102  core::pose::PoseOP & swap_segment,
104  ){
105 
106  //counter for seeds
107  Size offsetres = 0;
108 
109  for ( Size pos = 1; pos <= pose.total_residue(); ++pos ) {
110  TR.Debug<<"iterating through pose: " <<pos << std::endl;
111  if ( seeds.is_loop_residue( pos ) ) {
112  TR.Debug<<"pos "<< pos <<std::endl;
113  ++offsetres;
114  TR.Debug<<"offsetres " << offsetres <<std::endl;
115  pose.replace_residue(pos, swap_segment->residue( offsetres ), true);
116  }
117  }
118 
119 }
120 
121 //for this method, use only the actual fragments that are supposed to be swapped under the swap_segment
122 void
124  core::pose::Pose & pose,
125  core::pose::PoseOP & swap_segment,
127  ){
128 
129  using namespace core::conformation;
130  Size offsetres = 0;
131 
132  // preparing the segments for swap
134  core::pose::remove_upper_terminus_type_from_pose_residue(*swap_segment, swap_segment->total_residue());
135 
136  for ( Size pos = 1; pos <= pose.total_residue(); ++pos ) {
137  TR.Debug<<"iterating through pose: " <<pos << std::endl;
138  if ( seeds.is_loop_residue( pos ) ) {
139  TR.Debug <<"pos "<< pos <<std::endl;
140  ++offsetres ;
141  TR.Debug <<"offsetres " << offsetres <<std::endl;
142 
143  pose.replace_residue( pos, swap_segment->residue( offsetres ), true);
144  TR.Debug << "After Swap loop Residue " << offsetres << std::endl;
145 
146  }
147  }
148 
149 }
150 void
152  core::pose::Pose & pose,
153  core::pose::PoseOP & target_chain,
154  core::Size chain_to_swap
155  ){
156 
157  TR<<"replacing residues from chain " <<chain_to_swap << " with appropriate rotamers" <<std::endl;
158  for ( core::Size pos = pose.conformation().chain_begin( chain_to_swap ); pos <= pose.conformation().chain_end( chain_to_swap ); ++pos )
159  pose.replace_residue( pos, target_chain->residue( pos ), true);
160 }
161 
162 
163 void
165 {
166 
167  core::pose::PoseOP segment = new core::pose::Pose( seeds_pdb_->split_by_chain( from_chain_ ) );
168  core::pose::PoseOP target_c = new core::pose::Pose( seeds_pdb_->split_by_chain( swap_chain_ ) );
169  //assert sizes of target chain and input pose chain
170 
171  TR.Debug<<"chains: "<< pose.conformation().num_chains() <<" total residues: " <<pose.total_residue() <<std::endl;
172  //need to put in some assertions for stupid things like number bigger than there are chains and
173  //something that automatically adjusts the residue number and hook in the to_chain option
174  //for now hardcoding for first chain
175  //if( pose.conformation().num_chains() > 1
176 
177  //core::Size adjust_numbering = 0;
178 
179  //if( to_chain > 1)
180  core::Size adjust_numbering = pose.conformation().chain_begin( to_chain_ ) - 1;
181 
182  //if( pose.conformation().num_chains() > 1 )
183  // adjust_numbering = pose.conformation().chain_end( 1 );
184 
185  //need to assert that the seed elements are the same residue numbers as in the input pdb!!
186  TR.Debug<<"all_seeds_.loop_size() " << all_seeds_.loop_size() <<" total residues in seeds pdb: " << segment->total_residue() <<std::endl;
187  TR<<"adjusting for chain numbering by: " <<adjust_numbering <<std::endl;
188 
189  all_seeds_.make_sequence_shift( adjust_numbering );
190  TR.Debug <<"new loops: " <<all_seeds_ <<std::endl;
191 
192  if( swap_chain_ > 0){
193  TR<<"swapping chain: " << swap_chain_ << std::endl;
194  swap_chain( pose, target_c , swap_chain_ );
195  }
196 
197  if( all_seeds_.loop_size() != segment->total_residue() )
198  utility_exit_with_message("residues specified under the seeds does not agree with the number of residues provided as segment");
199 
200  if( copy_sidechains_ ){
201  copying_side_chains( pose, segment, all_seeds_);
202  (*scorefxn_)(pose);
203  TR<<"adopting side chains" << std::endl;
204  }
205 
206  if( swap_segment_ ){
207  swap_segment( pose, segment, all_seeds_);
208  TR<<"swapping segment" <<std::endl;
209  (*scorefxn_)(pose);
210  }
211 
212  TR.flush();
213 }
214 
215 
219 }
220 
221 void
223  utility::tag::TagPtr const tag,
227  core::pose::Pose const & pose ){
228 
229  all_seeds_.clear();//just in case
230 
231  //need scorefxn to score after swapping
232  std::string const scorefxn_name( tag->getOption<std::string>( "scorefxn", "score12" ) );
233  scorefxn_ = new core::scoring::ScoreFunction( *(data.get< core::scoring::ScoreFunction * >( "scorefxns", scorefxn_name) ));
234  TR<<"scoring with following scorefunction: " << *scorefxn_ <<std::endl;
235 
236  TR<<"SwapSegment mover has been instantiated" <<std::endl;
237 
238  copy_sidechains_ = tag->getOption< bool > ("copy_sidechains", 1 );
239  swap_segment_ = tag->getOption< bool > ("swap_segment", 0 );
240  swap_chain_ = tag->getOption< core::Size > ("swap_chain", 0 );
241  from_chain_ = tag->getOption< core::Size > ("from_chain", 1 );
242  to_chain_ = tag->getOption< core::Size > ("to_chain", 1 );
243 
244  TR<<"swap sidechains: " << copy_sidechains_ << ", swapping segment: "<< swap_segment_ <<", taking segments from chain: " << from_chain_ << std::endl;
245 
246  if( copy_sidechains_ && swap_segment_ )
247  TR<<"not necessary to swap segments AND to copy side chains" << std::endl;
248 
249  if( tag->hasOption( "seeds_pdb" ) || tag->hasOption( "template_pdb" ) ){
250  std::string const template_pdb_fname( tag->getOption< std::string >( "seeds_pdb" ));
252  core::import_pose::pose_from_pdb( *seeds_pdb_, template_pdb_fname );
253  TR<<"read in a template pdb with " <<seeds_pdb_->total_residue() <<"residues"<<std::endl;
254  seeds_presence_ = true;
255  }
256 
257  if( !seeds_presence_ )
258  utility_exit_with_message("need to specify a template to swap from!!!!");
259  //use the input pdb too ( todo )
260 
261  if( tag->hasOption( "previously_grown") ){
262  previously_grown_ = tag->getOption< bool > ("previously_grown", 0 );
263  TR<<"decoy was previously changed in its length, aka was \"grown\" "<<std::endl;
264  }
265 
266  //parsing branch tags
267  utility::vector0< TagPtr > const branch_tags( tag->getTags() );
268  foreach( TagPtr const btag, branch_tags ){
269 
270  //there is a problem with the parsing of the seeds if the pose was previously grown. This is due to
271  //the difference between parse time and computing time. Since the seeds are parsed before the pose has been
272  //grown to its full length, a different numbering needs to be used
273 
274  if( btag->getName() == "Seeds" ) { //need an assertion for the presence of these or at least for the option file
275 
276  core::Size begin;
277  core::Size end;
278 
279  if( !previously_grown_ ){
280  std::string const beginS( btag->getOption<std::string>( "begin" ) );
281  std::string const endS( btag->getOption<std::string>( "end" ) );
282  begin =( core::pose::parse_resnum( beginS, pose ) );
283  end =( core::pose::parse_resnum( endS, pose ) );
284  TR.Debug<<"string seeds: \n"<< beginS <<" and " << endS <<std::endl;
285  }
286 
287  else {
288  begin = ( btag->getOption< core::Size >( "begin" ) );
289  end = ( btag->getOption< core::Size >( "end" ) );
290  }
291 
292  all_seeds_.add_loop( begin , end , 0, 0, false );
293 
294  TR.Debug<<"parsing seeds: \n"<< begin <<" and " << end <<std::endl;
295  TR.Debug<<"seeds: "<< all_seeds_ <<std::endl;
296  }//end seed tags
297  }//end branch tags
298 
299  if( all_seeds_.size() == 0)
300  utility_exit_with_message("NEED TO SPECIFY A SEGMENT TO REPLACE!!!, whole pose swap currently not supported");
301 
302  }
303 }
304 }