Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StepWiseProteinPoseSetup.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 StepWiseProteinPoseSetup
11 /// @brief Create starting pose for rebuilding, from input pose
12 /// @detailed
13 /// @author Rhiju Das
14 
15 
16 //////////////////////////////////
20 
21 //////////////////////////////////
22 #include <core/types.hh>
23 #include <core/pose/Pose.hh>
24 
26 
28 #include <core/pose/util.hh>
30 // AUTO-REMOVED #include <core/scoring/Energies.hh>
31 // AUTO-REMOVED #include <core/scoring/ScoreFunction.hh>
32 // AUTO-REMOVED #include <core/scoring/ScoreFunctionFactory.hh>
34 // AUTO-REMOVED #include <core/chemical/ResidueSelector.hh>
36 // AUTO-REMOVED #include <core/chemical/VariantType.hh>
37 // AUTO-REMOVED #include <core/chemical/util.hh>
39 // AUTO-REMOVED #include <core/conformation/ResidueFactory.hh>
40 // AUTO-REMOVED #include <core/conformation/Conformation.hh>
41 // AUTO-REMOVED #include <core/io/pdb/pose_io.hh>
42 
43 // AUTO-REMOVED #include <numeric/xyz.functions.hh>
44 // AUTO-REMOVED #include <numeric/conversions.hh>
45 
46 #include <utility/vector1.hh>
47 
48 #include <list>
49 
50 //Auto Headers
51 #include <core/id/AtomID.hh>
52 
53 using namespace core;
54 using core::Real;
55 
56 namespace protocols {
57 namespace swa {
58 namespace protein {
59 
60 
61  //////////////////////////////////////////////////////////////////////////
62  //constructor!
63  StepWiseProteinPoseSetup::StepWiseProteinPoseSetup( std::string const & desired_sequence, utility::vector1< std::string > const & start_tags,
64  utility::vector1< std::string > const & silent_files_in ):
65  Mover(),
66  desired_sequence_( desired_sequence ),
67  start_tags_( start_tags ),
68  silent_files_in_( silent_files_in ),
69  rsd_set_( core::chemical::ChemicalManager::get_instance()->residue_type_set( core::chemical::FA_STANDARD ) ),
70  nres_( desired_sequence_.size() ),
71  input_residue_array_( nres_, false ),
72  junction_residue_array_( nres_, false ),
73  moving_residue_array_( nres_, false ),
74  sample_junction_( true ),
75  n_terminus_( false ),
76  c_terminus_( false ),
77  add_peptide_plane_( false ),
78  verbose_( false )
79  {
80  Mover::type("StepWiseProteinPoseSetup");
81 
82  }
83 
84  //////////////////////////////////////////////////////////////////////////
85  //destructor
87  {}
88 
89  /////////////////////
92  return "StepWiseProteinPoseSetup";
93  }
94 
95 
96  ///////////////////////////////////////////////////////////////////////////////////
97  void
98  fix_end_phi_psi( pose::Pose & pose, pose::Pose & start_pose, Size const & start_res, Size const & end_res ){
99 
100  if ( end_res < pose.total_residue() ){
101  Real const psi_current = get_pretend_psi_explicit( pose, end_res );
102  Real const psi_scratch = get_pretend_psi_explicit( start_pose, start_pose.total_residue() );
103  pose.set_psi( end_res, pose.psi( end_res ) + psi_scratch - psi_current );
104  }
105 
106  if ( start_res > 1 ){
107  Real const phi_current = get_pretend_phi_explicit( pose, start_res );
108  Real const phi_scratch = get_pretend_phi_explicit( start_pose, 1 );
109  pose.set_phi( start_res, pose.phi( start_res ) + phi_scratch - phi_current );
110  }
111 
112  }
113 
114 
115  ////////////////////////////////////////////////////
116  ////////////////////////////////////////////////////
117  // Need to be very careful about TERMINI.
118  // Note, in principle, we could inherit these if the target pose
119  // desires termini variants at end.
120 
121  //////////////////////////////////////////////////////////////////////////
122  void
124  {
125 
126  using namespace core::pose;
127 
128  // if ( start_tags_.size() == 0 ){
129  // initialize_from_scratch( pose );
130  // return;
131  // }
132  make_pose_from_sequence( pose, desired_sequence_, *rsd_set_, false /*auto_termini*/);
133 
134  if ( verbose_ ) pose.dump_pdb( "START1.pdb" );
135  add_end_variants( pose );
136  if ( verbose_ ) pose.dump_pdb( "START2.pdb" );
137 
138  // make extended chain
139  for ( Size pos = 1; pos <= pose.total_residue(); pos++ ) {
140  if ( ! pose.residue(pos).is_protein() ) continue;
141  pose.set_phi( pos, -150 );
142  pose.set_psi( pos, 150);
143  pose.set_omega( pos, 180 );
144  }
145 
146  if ( verbose_ ) pose.dump_pdb( "START2x.pdb" );
147 
148  // Later this will become more sophisticated, allowing for several pose chunks to be read in,
149  // aligned to a sequence alignment, and in-between residues samples (stored in "moving_residues_" ).
150 
151  utility::vector1< Size > start_res_all, end_res_all;
152 
153  if ( verbose_ ) pose.dump_pdb( "START_BEFORE_COPY_DOFS.pdb" );
154 
155  for ( Size i = 1; i <= start_tags_.size(); i++ ) {
156 
157  std::string const & start_tag( start_tags_[ i ] );
158 
159  //std::cout << "--- ABOUT TO READ IN INITIAL POSE" << i << std::endl;
160 
161  Pose start_pose;
162  if ( silent_files_in_.size() > 0 ) {
163  // Read in from silent file
164  core::io::silent::SilentFileData silent_file_data;
165  silent_file_data.read_file( silent_files_in_[ i ] );
166  bool found_tag( false );
167  for ( core::io::silent::SilentFileData::iterator iter = silent_file_data.begin(),
168  end = silent_file_data.end(); iter != end; ++iter ) {
169  if ( iter->decoy_tag() != start_tag ) continue;
170  found_tag = true;
171  iter->fill_pose( start_pose, *rsd_set_ );
172  break;
173  }
174  if ( !found_tag ) utility_exit_with_message( "Could not find specified tag in silent file!" );
175  } else {
176  // Read in from PDB
177  import_pose::pose_from_pdb( start_pose, *rsd_set_, start_tag );
178  }
179 
180  // remove_end_variants( start_pose );
181 
182  Size const start_res = figure_out_nested_positions( start_pose.sequence(), desired_sequence_ );
183  Size const end_res = start_res + start_pose.sequence().size() - 1;
184 
185  for ( Size k = start_res; k <= end_res; k++ ) input_residue_array_( k ) = true;
186  junction_residue_array_( start_res ) = true;
187  junction_residue_array_( end_res ) = true;
188 
189  //Now actually copy into the pose.
190  ResMap res_map;
191  Size count( 0 );
192  for ( Size n = start_res; n <= end_res; n++ ) {
193  count++;
194  res_map[ n ] = count;
195  }
196 
197  if ( verbose_ ) start_pose.dump_pdb( "INPUT.pdb" );
198 
199  match_end_variants( pose, start_pose, start_res, end_res );
200 
201  if ( verbose_ ) start_pose.dump_pdb( "MATCH_END.pdb" );
202 
203  copy_dofs( pose, start_pose, res_map );
204 
205  fix_end_phi_psi( pose, start_pose, start_res, end_res );
206 
207  }
208 
209  junction_residue_array_( 1 ) = false;
210  junction_residue_array_( nres_ ) = false;
211 
212  // List of moving residues -- useful for outside routines.
213  moving_residues_.clear();
214  moving_residue_array_ = false;
215  for (Size n = 1; n <= nres_; n++ ) {
216  if ( ! input_residue_array_( n ) ) moving_residue_array_( n ) = true;
218  if ( moving_residue_array_( n ) ) {
219  moving_residues_.push_back( n );
220  //std::cout << "MOVING: " << n << std::endl;
221  }
222  }
223 
224  if ( verbose_ ) pose.dump_pdb( "START3.pdb" );
225 
226  // prepend_residues( pose );
227  // append_residues ( pose, start_pose );
228 
229  }
230 
231  ////////////////////////////////////////////////////////////////////////////////////////////////////
232  void
234 
235  if ( n_terminus_ ) {
236  pose::add_variant_type_to_pose_residue( pose, "LOWER_TERMINUS", 1 );
237  } else {
238  if (add_peptide_plane_) pose::add_variant_type_to_pose_residue( pose, "N_ACETYLATION", 1 );
239  }
240 
241  if ( c_terminus_ ) {
242  pose::add_variant_type_to_pose_residue( pose, "UPPER_TERMINUS", pose.total_residue() );
243  } else {
244  if (add_peptide_plane_) pose::add_variant_type_to_pose_residue( pose, "C_METHYLAMIDATION", pose.total_residue() );
245  }
246 
247  }
248 
249  //////////////////////////////////////////////////////////////////////////////////////////
250  void
252  pose::Pose & scratch_pose, Size const & scratch_pose_res,
253  utility::vector1< chemical::VariantType > const & variant_types ) const
254  {
255 
256  using namespace core::chemical;
257  utility::vector1< VariantType > variant_types_to_add, variant_types_to_remove;
258 
259  for (Size n = 1; n <= variant_types.size(); n++ ) {
260 
261  VariantType const & variant_type = variant_types[ n ];
262  if ( pose.residue( pose_res ).has_variant_type( variant_type ) &&
263  !scratch_pose.residue( scratch_pose_res ).has_variant_type( variant_type ) ){
264  variant_types_to_add.push_back( variant_type );
265  }
266 
267  if ( !pose.residue( pose_res ).has_variant_type( variant_type ) &&
268  scratch_pose.residue( scratch_pose_res ).has_variant_type( variant_type ) ){
269  variant_types_to_remove.push_back( variant_type );
270  }
271 
272  }
273 
274  core::pose::Pose scratch_pose_save = scratch_pose;
275 
276  // Not exactly sure if I need to do this -- all the removes, then all the adds...
277  for ( Size n = 1; n <= variant_types_to_remove.size(); n++ ) {
278  pose::remove_variant_type_from_pose_residue( scratch_pose, variant_types_to_remove[n], scratch_pose_res );
279 
280  // This is really silly.
281  if ( variant_types_to_remove[n] == "LOWER_TERMINUS" ) {
282  scratch_pose.set_xyz( core::id::AtomID( scratch_pose.residue( scratch_pose_res).atom_index("H"),
283  scratch_pose_res ),
284  scratch_pose_save.xyz( core::id::AtomID( scratch_pose_save.residue( scratch_pose_res).atom_index( "1H" ), scratch_pose_res ) ) );
285  }
286 
287  }
288 
289 
290  for ( Size n = 1; n <= variant_types_to_add.size(); n++ ) {
291  pose::add_variant_type_to_pose_residue( scratch_pose, variant_types_to_add[n], scratch_pose_res );
292  }
293 
294  }
295 
296  ///////////////////////////////////////////////////////////////////////////////////////////
297  void
298  StepWiseProteinPoseSetup::match_end_variants( pose::Pose const & pose, pose::Pose & scratch_pose, Size const & start_res, Size const & end_res ) const
299  {
300  using namespace core::chemical;
301 
303  N_variants.push_back( "LOWER_TERMINUS" );
304  N_variants.push_back( "N_ACETYLATION" );
305 
306  match_specific_variants( pose, start_res, scratch_pose, 1, N_variants );
307 
309  C_variants.push_back( "UPPER_TERMINUS" );
310  C_variants.push_back( "C_METHYLAMIDATION" );
311 
312  match_specific_variants( pose, end_res, scratch_pose, scratch_pose.total_residue(), C_variants );
313 
314  }
315 
316 
317  ////////////////////////////////////////////////////////////////////////////////////////////////////
318  Size
320  std::string const & inside_sequence,
321  std::string const & desired_sequence ) const
322  {
323 
324  Size const max_start_res = desired_sequence.size() - inside_sequence.size()+1;
325 
326  for (Size potential_start_res = 1; potential_start_res <= max_start_res; potential_start_res++ ) {
327  bool found_match = true;
328 
329  //Position may already be "called for" by a previous assignment.
330  if ( input_residue_array_( potential_start_res ) ) continue;
331 
332  //Look for exact sequence match.
333  for ( Size i = 0; i < inside_sequence.size(); i++ ) {
334  if ( inside_sequence[i] != desired_sequence[i - 1 + potential_start_res] ) {
335  found_match = false;
336  break;
337  }
338  }
339  if ( found_match ) {
340  return potential_start_res;
341  }
342  }
343 
344  return 0;
345 
346  }
347 
348  //////////////////////////////////////////////////////////////////////////////
351  {
352  return moving_residues_;
353  }
354 
355 // //////////////////////////////////////////////////////////////////////////////
356 // void
357 // StepWiseProteinPoseSetup::prepend_residues( pose::Pose & pose ) {
358 
359 // using namespace core::chemical;
360 // using namespace core::conformation;
361 
362 // if ( start_res_ <= 1 ) return;
363 
364 // pose::remove_lower_terminus_type_from_pose_residue( pose, 1 );
365 // for ( Size i = start_res_ - 1; i > 0; i-- ) {
366 // ResidueTypeCOP new_rsd_type( ResidueSelector().set_name1( desired_sequence_[i-1] ).exclude_variants().select( *rsd_set_ )[1] );
367 // // ResidueTypeCOP new_rsd_type( rsd_set_->aa_map( aa_from_oneletter_code( desired_sequence[i-1] ) )[1] );
368 // ResidueOP new_rsd( ResidueFactory::create_residue( *new_rsd_type ) );
369 // pose.conformation().safely_prepend_polymer_residue_before_seqpos( *new_rsd, 1, true );
370 // pose.set_omega( 1, 180.0 ); //NOTE SIDE CHAINS ARE MESSED UP!
371 // }
372 // for (Size i = 1; i < start_res_ ; i++ ) {
373 // moving_residues_.push_back( i );
374 // }
375 // }
376 
377 
378 // //////////////////////////////////////////////////////////////////////////////
379 // void
380 // StepWiseProteinPoseSetup::append_residues( pose::Pose & pose, pose::Pose const & start_pose ) {
381 
382 // using namespace core::chemical;
383 // using namespace core::conformation;
384 
385 // if ( end_res_ >= desired_sequence_.size() ) return;
386 
387 // pose::remove_upper_terminus_type_from_pose_residue( pose, pose.total_residue() );
388 // for ( Size i = end_res_ + 1; i <= desired_sequence_.size(); i++ ) {
389 // ResidueTypeCOP new_rsd_type( ResidueSelector().set_name1( desired_sequence_[i-1] ).exclude_variants().select( *rsd_set_ )[1] );
390 // ResidueOP new_rsd( ResidueFactory::create_residue( *new_rsd_type ) );
391 // pose.conformation().append_polymer_residue_after_seqpos( *new_rsd, pose.total_residue(), true );
392 // pose.set_omega( pose.total_residue(), 180.0 );
393 // moving_residues_.push_back( i );
394 // }
395 // // pose::add_variant_type_to_pose_residue( pose, "VIRTUAL_CTERM_O", pose.total_residue() );
396 // pose.set_psi( end_res_, start_pose.psi( start_pose.total_residue() ) );
397 // }
398 
399 // //////////////////////////////////////////////////////////////////////////////
400 // void
401 // StepWiseProteinPoseSetup::initialize_from_scratch( pose::Pose & pose )
402 // {
403 // make_pose_from_sequence( pose, desired_sequence_, *rsd_set_, false /*auto_termini*/);
404 
405 // for ( Size n = 1; n <= pose.total_residue(); n++ ) {
406 // moving_residues_.push_back( n );
407 // }
408 // }
409 
410 /////////////////////////////////////////////////////////////////
411 
412  void
414  add_peptide_plane_ = setting;
415  }
416 
417 }
418 }
419 }