Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InputStreamWithResidueInfo.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 StepWisePoseSetup
11 /// @brief Sets up pose and job parameters for protein or RNA stepwise building.
12 /// @detailed
13 /// @author Rhiju Das
14 /// @author Parin Sripakdeevong
15 
16 
17 //////////////////////////////////
19 
20 //////////////////////////////////
21 // AUTO-REMOVED #include <core/chemical/util.hh>
23 #include <core/types.hh>
24 #include <core/pose/Pose.hh>
25 #include <core/pose/util.hh>
31 #include <core/scoring/rms_util.hh>
33 
34 #include <basic/options/option.hh>
35 // AUTO-REMOVED #include <basic/options/after_opts.hh>
36 // AUTO-REMOVED #include <basic/options/util.hh>
37 #include <basic/options/keys/in.OptionKeys.gen.hh>
38 #include <basic/options/keys/swa.OptionKeys.gen.hh>
39 
40 
41 // RNA stuff
43 
44 #include <utility/exit.hh>
45 #include <string>
46 
47 //Auto Headers
48 #include <utility/vector1.hh>
49 
50 using namespace core;
51 using core::Real;
52 
53 namespace protocols {
54 namespace swa {
55 
56  //////////////////////////////////////////////////////////////////////
57  // This is for file readin.
58  //////////////////////////////////////////////////////////////////////
61  utility::options::StringVectorOption const & option_s1,
62  utility::options::StringVectorOption const & option_silent1,
63  utility::options::StringVectorOption const & option_tags1
64  //utility::vector1< std::string > const & option_s1,
65  //utility::vector1< std::string > const & option_silent1,
66  //utility::vector1< std::string > const & option_tags1
67  ){
68  using namespace core::import_pose::pose_stream;
69 
70  PoseInputStreamOP input1;
71 
72  if( option_s1.user() ) {
73  // pdb input(s).
74  input1 = new PDBPoseInputStream( option_s1() );
75 
76  } else if ( option_silent1.size() > 0 ){
77 
78  if ( option_tags1.user() > 0) {
79  input1 = new SilentFilePoseInputStream( option_silent1() ,
80  option_tags1() );
81  } else {
82  input1 = new SilentFilePoseInputStream( option_silent1() );
83  }
84  } else {
85  // create a pose stream with a single blank pose...
86  input1 = new ExtendedPoseInputStream( "", 1 ); // hmm...
87  }
88 
89  return input1;
90 
91  }
92 
93  ////////////////////////////////////////////////////////////////////////////////
94  void
96 
97  using namespace protocols::swa;
98  using namespace basic::options;
99  using namespace basic::options::OptionKeys;
100  using namespace basic::options::OptionKeys::swa;
101  using namespace core::import_pose::pose_stream;
102 
103  // my options.
104  utility::vector1< Size > blank_size_vector;
105  utility::vector1< std::string > blank_string_vector;
106 
107 
108  if ( option[ s1 ].user() || option[ silent1 ].user() ) { // assume new style of input.
109  utility::vector1< Size > slice_res_1 = blank_size_vector;
110  if ( option[ slice_res1 ].user() ) slice_res_1 = option[ slice_res1]();
112  setup_pose_input_stream( option[ s1 ], option[ silent1 ], option[ tags1 ] ),
113  option[ input_res1 ](),
114  slice_res_1 );
115  if ( option[ backbone_only1 ]() ) stream1->set_backbone_only( true );
116  input_streams.push_back( stream1 );
117 
118  if ( option[ input_res2 ].user() ) {
119  utility::vector1< Size > slice_res_2 = blank_size_vector;
120  if ( option[ slice_res2 ].user() ) slice_res_2 = option[ slice_res2]();
122  setup_pose_input_stream( option[ s2 ], option[ silent2 ], option[ tags2 ] ),
123  option[ input_res2 ](),
124  slice_res_2 );
125  if ( option[ backbone_only2 ]() ) stream2->set_backbone_only( true );
126  input_streams.push_back( stream2 );
127  }
128  } else if ( option[ in::file::input_res ].user() ) { //old style
129  utility::vector1< std::string > silent_files_in, pdb_tags;
130 
131  // First read in any information on pdb read in from silent files.
132  if ( option[ in::file::silent ].user() ) {
133  silent_files_in = option[ in::file::silent ]();
134 
135  if ( option[ in::file::tags ].user() ) {
136  pdb_tags = option[ in::file::tags ]();
137  }
138  if ( pdb_tags.size() < 1) return; //early finish!! no combo!
139  }
140  if ( option[ in::file::s ].user() ) {
141  // Then any pdbs that need to be read in from disk.
142  utility::vector1< std::string > const pdb_tags_from_disk( option[ in::file::s ]() );
143  for ( Size n = 1; n <= pdb_tags_from_disk.size(); n++ ) pdb_tags.push_back( pdb_tags_from_disk[ n ] );
144  }
145  assert( pdb_tags.size() > 0 );
147  pdb_tags, silent_files_in,
148  option[ in::file::input_res ](), option[ input_res2 ]() );
149  }
150 
151  }
152 
153 
154  //////////////////////////////////////////////////////////////////////////
155  //////////////////////////////////////////////////////////////////////////
156  InputStreamWithResidueInfo::InputStreamWithResidueInfo( core::import_pose::pose_stream::PoseInputStreamOP pose_input_stream,
157  utility::vector1< Size > const & input_res,
158  utility::vector1< Size > const & slice_res ):
159  pose_input_stream_( pose_input_stream ),
160  input_res_( input_res ),
161  slice_res_( slice_res ),
162  backbone_only_( false )
163  {
165  }
166 
167  //////////////////////////////////////////////////////////////////////////
169  utility::vector1< Size > const & input_res ):
170  pose_input_stream_( pose_input_stream ),
171  input_res_( input_res ),
172  backbone_only_( false )
173  {
175  }
176 
177 
178  //////////////////////////////////////////////////////////////////////////
179  void
181  if ( slice_res_.size() == 0 ) {
182  for ( Size i = 1; i <= input_res_.size(); i++ ) slice_res_.push_back( i );
183  }
184  for ( Size i = 1; i <= input_res_.size(); i++ ) full_to_sub_[ input_res_[i] ] = input_res_[i];
185  }
186 
187 
188  //////////////////////////////////////////////////////////////////////////
190  //////////////////////////////////////////////////////////////////////////
193  //////////////////////////////////////////////////////////////////////////
196  //////////////////////////////////////////////////////////////////////////
199  //////////////////////////////////////////////////////////////////////////
200  std::map< Size, Size > &
202  //////////////////////////////////////////////////////////////////////////
203  void
205  //////////////////////////////////////////////////////////////////////////
206  void
207  InputStreamWithResidueInfo::set_full_to_sub( std::map< Size, Size > const & full_to_sub ){ full_to_sub_ = full_to_sub; }
208  //////////////////////////////////////////////////////////////////////////
209  void
211  rsd_set_ = rsd_set;
212  }
213 
214  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
215  void
217  pose_input_stream_->reset();
218  }
219 
220  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
221  bool
223  return ( pose_input_stream_->has_another_pose() );
224  }
225 
226 
227  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
228  void
230  pose::Pose import_pose;
231  copy_next_pose_segment( pose, import_pose, false /*check_sequence_matches*/);
232  }
233 
234  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
235  void
237  pose::Pose & import_pose,
238  bool const check_sequence_matches,
239  bool const align_pose_to_import_pose ){
240 
241  using namespace core::conformation;
242 
243  if ( rsd_set_ == 0 ) utility_exit_with_message( "Hey, need to define rsd_set for pose input stream" );
244 
245  // Read in pose.
246  pose_input_stream_->fill_pose( import_pose, *rsd_set_ );
247 
248  if ( check_sequence_matches && !backbone_only_ ) check_sequence( pose, import_pose );
249 
250  // Dec 2010 -- why do we need this? copy is based on atom names not indexes.
251  //cleanup_pose( import_pose );
252 
253  std::map< core::Size, core::Size > res_map; //This is map from sub numbering to input_res numbering..
254 
255  for ( Size n = 1; n <= input_res_.size(); n++ ) {
256  res_map[ full_to_sub_[ input_res_[n] ] ] = slice_res_[ n ];
257  // std::cout << n << ' ' << input_res_[ n ] << ' ' << full_to_sub_[ input_res_[ n ] ] << " " << slice_res_[ n ] << std::endl;
258 
259  // silly, disulfides
260  // if ( import_pose.residue_type(n).is_protein() && import_pose.residue_type(n).has_variant_type( DISULFIDE ) ){
261  // //add_variant_type_to_pose_residue( pose, DISULFIDE, full_to_sub[ input_res[ n ] ] );
262  // change_cys_state( n, "CYD", pose.conformation() );
263  // }
264 
265  }
266 
267  //Does this work for the "overlap residue" case?? If there is a overlap residue, then order of input_res will manner...Parin Jan 2, 2010.
268  //Is it possible to copy only backbone torsions?? Parin Jan 2, 2010.
269 
270  std::cout << "IMPORT_POSE DURING COPY_NEXT_SEGMENT: " << import_pose.annotated_sequence( true ) << std::endl;
271  // std::cout << "FOLD TREE OF POSE: " << pose.fold_tree() << std::endl;
272 
273  //copy_dofs_match_atom_names( pose, import_pose, res_map, backbone_only_, false /*ignore_virtual*/ );
274  // Dec 2010 -- why do we copy_dofs for virtual?
275  copy_dofs_match_atom_names( pose, import_pose, res_map, backbone_only_, true /*ignore_virtual*/ );
276 
277  //can do an alignment too. Note that this does *not* happen by default. Need to set align_pose_to_import_pose = true.
278  if ( align_pose_to_import_pose ) {
279  id::AtomID_Map< id::AtomID > atom_ID_map = create_alignment_id_map( pose, import_pose, res_map );
280  scoring::superimpose_pose( pose, import_pose, atom_ID_map );
281  }
282 
283 
284  //can do an alignment too. Note that this does *not* happen by default. Need to set align_pose_to_import_pose = true.
285  if ( align_pose_to_import_pose ) {
286  id::AtomID_Map< id::AtomID > atom_ID_map = create_alignment_id_map( pose, import_pose, res_map );
287  scoring::superimpose_pose( pose, import_pose, atom_ID_map );
288  }
289 
290 
291  }
292 
293 
294  ////////////////////////////////////////////////////////////////////////////////////////
295  void
297 
298  using namespace core::chemical;
299 
301 
302  // No virtual anything!
303  utility::vector1< std::string > remove_variants;
304  remove_variants.push_back( "VIRTUAL_PHOSPHATE" );
305  remove_variants.push_back( "VIRTUAL_O2STAR_HYDROGEN" );
306  remove_variants.push_back( "CUTPOINT_LOWER" );
307  remove_variants.push_back( "CUTPOINT_UPPER" );
308  // Also remove VIRTUAL_RESIDUE variant?
309 
310  for ( Size n = 1; n <= import_pose.total_residue(); n++ ) {
311  for ( Size i = 1; i <= remove_variants.size(); i++ ){
312  if ( import_pose.residue_type( n ).has_variant_type( remove_variants[ i ] ) ) {
313  pose::remove_variant_type_from_pose_residue( import_pose, remove_variants[ i ] , n );
314  }
315  }
316  }
317 
318  }
319 
320  ////////////////////////////////////////////////////////////////////////////////////////
321  void
323 
324  std::cout << pose.annotated_sequence( true ) << std::endl;
325  std::cout << import_pose.annotated_sequence( true ) << std::endl;
326 
327  bool match( true );
328  for( Size n = 1; n <= slice_res_.size(); n++ ) {
329  if ( ( slice_res_[ n ] > import_pose.total_residue() ) ||
330  ( full_to_sub_[ input_res_[ n ] ] > pose.total_residue() ) ||
331  ( import_pose.sequence()[ slice_res_[n] - 1 ] !=
332  pose.sequence()[ full_to_sub_[ input_res_[n] ] - 1 ] ) ) {
333  std::cout << " N " << n << std::endl;
334  std::cout << " SLICE_RES " << slice_res_[ n ] << std::endl;
335  std::cout << " INPUT_RES " << input_res_[ n ] << std::endl;
336  std::cout << " FULLTOSUB " << full_to_sub_[ input_res_[ n ] ] << std::endl;
337  std::cout << " IMPORT TOTRES "<< import_pose.total_residue() << std::endl;
338  std::cout << " DESIRED TOTRES "<< pose.total_residue() << std::endl;
339  match = false;
340  break;
341  }
342  }
343  if (!match) utility_exit_with_message( "mismatch in sequence between input pose and desired sequence, given input_res " );
344 
345  }
346 
347  //////////////////////////////////////////////////////////////////////////
348  void
350  utility::vector1< std::string > const & pdb_tags,
351  utility::vector1< std::string > const & silent_files_in,
353  utility::vector1< core::Size > const & input_res2
354  ){
355 
356  using namespace core::import_pose::pose_stream;
357 
359  input_res_vectors.push_back( input_res );
360  input_res_vectors.push_back( input_res2 );
361 
362  utility::vector1< Size > blank_vector;
363 
364  // This was a silly convention (I shouldn't have used it.)
365  // First set up silent file input
366  for ( Size i = 1; i <= silent_files_in.size(); i++ ){
367  utility::vector1< std::string > silent_files1, pdb_tags1;
368  silent_files1.push_back( silent_files_in[ i ] );
369  pdb_tags1.push_back( pdb_tags[ i ] );
371  new SilentFilePoseInputStream( silent_files1, pdb_tags1 ),
372  input_res_vectors[ i ] );
373  input_streams_with_residue_info.push_back( input_stream );
374  }
375  // Then PDBs.
376  for ( Size i = silent_files_in.size()+1; i <= pdb_tags.size(); i++ ){
377  std::string pose_name = pdb_tags[ i ];
378  std::size_t found=pose_name.find(".pdb");
379  if (found==std::string::npos) {
380  pose_name.append(".pdb");
381  }
383  pose_names.push_back( pose_name );
384  InputStreamWithResidueInfoOP input_stream = new InputStreamWithResidueInfo( new PDBPoseInputStream( pose_names ),
385  input_res_vectors[ i ] );
386  input_streams_with_residue_info.push_back( input_stream );
387  }
388 
389  }
390 
391  //////////////////////////////////////////////////////////////////////////
392  void
394  backbone_only_ = setting;
395  }
396 
397 
398 
399 }
400 }