Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StepWiseRNA_PoseSetup.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 StepWiseRNA_PoseSetup
11 /// @brief Sets up pose and job parameters for RNA stepwise building.
12 /// @detailed
13 /// @author Rhiju Das
14 
15 
16 //////////////////////////////////
21 
23 //////////////////////////////////
24 #include <core/chemical/util.hh>
35 #include <core/types.hh>
37 #include <core/pose/Pose.hh>
38 #include <core/pose/util.hh>
39 #include <basic/Tracer.hh>
41 #include <core/id/TorsionID.hh>
44 #include <ObjexxFCL/string.functions.hh>
45 #include <ObjexxFCL/format.hh>
46 
47 #include <ObjexxFCL/FArray1D.hh>
48 #include <ObjexxFCL/FArray2D.hh>
49 
50 
51 #include <core/io/silent/BinaryRNASilentStruct.hh> //Feb 24, 2011, FARFAR start_silent_file.
52 
53 #include <utility/exit.hh>
54 #include <time.h>
55 
56 #include <string>
57 
58 using namespace core;
59 using core::Real;
60 
61 //////////////////////////////////////////////////////////////////////////
62 //////////////////////////////////////////////////////////////////////////
63 // Core routine for stepwise sampling of proteins (and probably other
64 // biopolymers soon). Take a starting pose and a list of residues to sample,
65 // and comprehensively sample all backbone torsion angles by recursion.
66 //////////////////////////////////////////////////////////////////////////
67 //////////////////////////////////////////////////////////////////////////
68 //////////////////////////////////////////////////////////////////////////
69 
70 static basic::Tracer TR( "protocols.swa.rna.stepwise_rna_pose_setup" ) ;
71 
72 namespace protocols {
73 namespace swa {
74 namespace rna {
75 
76  //////////////////////////////////////////////////////////////////////////
77  //constructor!
78  StepWiseRNA_PoseSetup::StepWiseRNA_PoseSetup( StepWiseRNA_JobParametersOP & job_parameters):
79  rsd_set_( core::chemical::ChemicalManager::get_instance()->residue_type_set( core::chemical::RNA ) ),
80  job_parameters_( job_parameters ),
81  copy_DOF_(false),
82  verbose_( true ),
83  rebuild_bulge_mode_(false), //Nov 26, 2010
84  output_pdb_(false), //Sept 24, 2011
85  apply_virtual_res_variant_at_dinucleotide_(true), //Jul 12, 2012
86  align_to_native_( false ) //Jul 12, 2012
87  {
88  }
89 
90  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
91 
92  //destructor
94  {}
95 
96  /////////////////////
99  return "StepWiseRNA_PoseSetup";
100  }
101 
102  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
103 
104  void
106 
107  using namespace ObjexxFCL;
108 
109  if(verbose_) Output_title_text("Enter StepWiseRNA_PoseSetup::apply");
110 
111  // actually make the pose, set fold tree, copy in starting templates from disk.
112 
113  pose::Pose pose_without_cutpoints;
114 
115  if(copy_DOF_){
116 
117  make_pose( pose_without_cutpoints ); //Create pose with random torsions
118  std::cout << "read_input_pose_and_copy_dofs( pose_without_cutpoints )" << std::endl;
119  read_input_pose_and_copy_dofs( pose_without_cutpoints );
120 
121  make_pose( pose ); //Create pose with random torsions
122  pose.fold_tree( job_parameters_->fold_tree());
123  std::cout << "read_input_pose_and_copy_dofs( pose )" << std::endl;
125 
126  }else{
127  pose_without_cutpoints=pose; //Hard copy, slow
128  pose.fold_tree( job_parameters_->fold_tree());
129  }
130 
131  if(output_pdb_) pose.dump_pdb( "test.pdb" );
132 
133  //WARNING STILL NEED TO IMPLEMENT harmonic_chainbreak HERE!
134  apply_cutpoint_variants( pose , pose_without_cutpoints);
137  apply_bulge_variants( pose );
138  apply_virtual_res_variant( pose); //User specified virtaul_res and bulge_res of it being built
141 
142  if( job_parameters_->add_virt_res_as_root() ) add_aa_virt_rsd_as_root(pose); //Fang's electron density code.
143 
144  if(output_pdb_) pose.dump_pdb( "start.pdb" );
145 
146  if(verbose_ ) Output_title_text("Exit StepWiseRNA_PoseSetup::apply");
147  }
148 
149  ////////////////////////////////////////////////////////
150 
151 
152  void
154  using namespace core::conformation;
155  using namespace core::pose;
156  using namespace protocols::rna;
157 
158  if(verbose_) Output_title_text("Enter StepWiseRNA_PoseSetup::setup_native_pose");
159 
160  utility::vector1< core::Size > const & is_working_res( job_parameters_->is_working_res() );
161  std::string const & working_sequence( job_parameters_->working_sequence() );
162  utility::vector1< core::Size > const & working_best_alignment( job_parameters_->working_best_alignment() );
163  utility::vector1< core::Size > const & working_moving_res_list( job_parameters_->working_moving_res_list() );
164 
166 
167  utility::vector1 < core::Size > const & working_moving_partition_pos = job_parameters_->working_moving_partition_pos(); //Sept 14, 2011.
168 
169  if ( !get_native_pose() ) return;
170  // Need a simple fold tree for following to work...
171  Pose native_pose_copy = *get_native_pose();
172  native_pose_copy.fold_tree( core::kinematics::FoldTree( native_pose_copy.total_residue() ) );
173 
174  PoseOP working_native_pose=new Pose;
175 
176  //First option is to pass in the full length native
177  if(native_pose_copy.sequence() == job_parameters_->full_sequence() ){
178  std::cout << "User passed in full length native pose" << std::endl;
179 
180  (*working_native_pose)=native_pose_copy;
181 
182  for( Size seq_num = native_pose_copy.total_residue(); seq_num >= 1 ; seq_num--){
183  if (!is_working_res[ seq_num ] ){
184  working_native_pose->conformation().delete_residue_slow(seq_num );
185  }
186  }
187 
188  }else if( native_pose_copy.sequence() == working_sequence){ //Could also pass in the working_native_pose directly
189  std::cout << "User passed in working native pose" << std::endl;
190  (*working_native_pose)=native_pose_copy;
191  }else{
192  std::cout << std::setw(50) << " native_pose_copy.sequence() = " << native_pose_copy.sequence() << std::endl;
193  std::cout << std::setw(50) << " job_parameters_->full_sequence()= " << job_parameters_->full_sequence() << std::endl;
194  std::cout << std::setw(50) << " working_sequence= " << working_sequence << std::endl;
195  utility_exit_with_message( "The native pose passed in by the User does not match both the full_sequence and the working sequence of the inputted fasta_file" );
196  }
197 
198  if(working_native_pose->sequence() != working_sequence ){
199  std::cout << std::setw(50) << "working_native_pose->sequence()= " << working_native_pose->sequence();
200  std::cout << std::setw(50) << "working_sequence= " << working_sequence << std::endl;
201  utility_exit_with_message( "working_native_pose->sequence() != working_sequence" );
202  }
203 
204 
206 
207 
208  utility::vector1< core::Size > act_working_alignment;
209  act_working_alignment.clear();
210 
211  utility::vector1< core::Size > const & working_native_alignment = job_parameters_->working_native_alignment();
212 
213  if(working_native_alignment.size()!=0){ //User specified the native alignment res.
214  std::cout << "working_native_alignment.size()!=0!, align native_pose with working_native_alignment!" << std::endl;
215 
216  for(Size n=1; n<=working_native_alignment.size(); n++){
217  Size const seq_num=working_native_alignment[n];
218  if( Contain_seq_num(seq_num, working_moving_res_list) ) continue;
219  if( Contain_seq_num(seq_num, working_moving_partition_pos) ) continue; //Sept 14, 2011.
220  act_working_alignment.push_back(seq_num);
221  }
222 
223 
224  }else{ //Use default alignment res.
225  std::cout << "working_native_alignment.size()==0!, align native_pose with working_best_alignment!" << std::endl;
226 
227  for(Size n=1; n<=working_best_alignment.size(); n++){
228  Size const seq_num=working_best_alignment[n];
229  if( Contain_seq_num(seq_num, working_moving_res_list) ) continue;
230  if( Contain_seq_num(seq_num, working_moving_partition_pos) ) continue; //Sept 14, 2011.
231  act_working_alignment.push_back(seq_num);
232  }
233  }
234 
235 
236  Output_seq_num_list("act_working_alignment= ", act_working_alignment, 40);
237  Output_seq_num_list("working_moving_res_list= ", working_moving_res_list, 40);
238  Output_seq_num_list("working_moving_partition_pos= ", working_moving_partition_pos, 40);
239  Output_seq_num_list("working_native_alignment= ", working_native_alignment, 40);
240  Output_seq_num_list("working_best_alignment= ", working_best_alignment, 40);
241 
242  if(act_working_alignment.size()==0) utility_exit_with_message("act_working_alignment.size()==0");
243 
244 
245  if ( job_parameters_ -> add_virt_res_as_root() ) { //Fang's electron density code
246 
247  //Fang why do you need this?////
248  pose::Pose dummy_pose = *working_native_pose;
249  apply_cutpoint_variants( *working_native_pose , dummy_pose);
250  add_protonated_H1_adenosine_variants( *working_native_pose);
251  verify_protonated_H1_adenosine_variants( *working_native_pose );
252  ////////////////////////////////
253 
254  add_aa_virt_rsd_as_root(*working_native_pose);
255  (*working_native_pose).fold_tree( pose.fold_tree() );
256  align_poses( pose, "working_pose", (*working_native_pose), "working_native_pose", act_working_alignment);
257 
258  }else if (align_to_native_ ){
259  // Rhiju -- prefer to align pose to native pose...
260  align_poses( pose, "working_pose", (*working_native_pose), "working_native_pose", act_working_alignment);
261 
262  }else{ //March 17, 2012 Standard. This ensures that adding native_pdb does not change the final output silent_struct coordinates.
263  align_poses( (*working_native_pose), "working_native_pose" , pose, "working_pose", act_working_alignment);
264 
265  }
266 
267 
268 
269 
270  job_parameters_->set_working_native_pose( working_native_pose );
271 
272  //Setup cutpoints, chain_breaks, variant types here!
273 
274  if(output_pdb_) working_native_pose->dump_pdb("working_native_pose.pdb" );
275  if(output_pdb_) pose.dump_pdb("sampling_pose.pdb" );
276 
277 
278  for(Size n=1; n<=working_native_virtual_res_list_.size(); n++){
279 // pose::add_variant_type_to_pose_residue( (*working_native_pose), "VIRTUAL_RNA_RESID#UE", working_native_virtual_res_list_[n]);
280  apply_virtual_rna_residue_variant_type( (*working_native_pose), working_native_virtual_res_list_[n] , false /*apply_check*/) ;
281  }
282 
283 
284  if(output_pdb_) working_native_pose->dump_pdb("working_native_pose_with_virtual_res_variant_type.pdb" );
285 
286 
287 
288  if(verbose_) Output_title_text("Exit StepWiseRNA_PoseSetup::setup_native_pose");
289 
290  }
291 
292 
293  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
294  void
295  StepWiseRNA_PoseSetup::Import_pose( Size const & i, core::pose::Pose & import_pose) const {
296 
297  using namespace core::conformation;
298 
299 
300  if ( i > input_tags_.size()) utility_exit_with_message( "i > input_tags_.size()!" );
301  if ( copy_DOF_==false) utility_exit_with_message( "copy_DOF_==false!" );
302 
303  if ( i > silent_files_in_.size() ) {
304  // not a silent file, read in from pdb text file.
305 
306  std::string pose_name = input_tags_[ i ];
307  std::size_t found=pose_name.find(".pdb");
308  if (found==std::string::npos) {
309  pose_name.append(".pdb");
310  }
311 
312  // if(verbose) std::cout << " The following pose will be imported :" << pose_name << std::endl;
313  import_pose::pose_from_pdb( import_pose, *rsd_set_, pose_name );
315 
316  } else {
317 
319 
320  }
321 
322  ///////////////////////////////
323  // Check for sequence match.
324  utility::vector1< Size > const & input_res = job_parameters_->input_res_vectors()[i];
325  std::string const & full_sequence=job_parameters_->full_sequence();
326 
327  if ( import_pose.total_residue() != input_res.size() ){
328  std::cout << "import_pose.total_residue()= " << import_pose.total_residue() << " input_res.size()= " << input_res.size() << std::endl;
329  utility_exit_with_message( "input pose does not have same # residues as input res" );
330  }
331  bool match( true );
332  for( Size n = 1; n <= import_pose.total_residue(); n++ ) {
333  if ( import_pose.sequence()[ n-1 ] != full_sequence[ input_res[n] - 1 ] ) {
334  match = false; break;
335  }
336  }
337  if (!match) utility_exit_with_message( "mismatch in sequence between input pose and desired sequence, given input_res " );
338  }
339 
340  ////////////////////////////////////////////////////////////////////////////////
341  void
343 
344  using namespace core::conformation;
345 
346  std::string const working_sequence = job_parameters_->working_sequence();
347 
348  //if ( copy_DOF_==false) utility_exit_with_message( "copy_DOF_==false!" );
349 
350 
351  make_pose_from_sequence( pose, working_sequence, *rsd_set_, false /*auto_termini*/);
352 
353  if(output_pdb_){
354  std::cout << "outputting extended_chain.pdb" << std::endl;
355  pose.dump_pdb( "extended_chain.pdb" );
356  }
357 
358  }
359 
360  ///////////////////////////////////////////////////////////////////////////////////
361  void
363  {
364 
365  std::string const working_sequence = job_parameters_->working_sequence();
366  utility::vector1< utility::vector1< Size > > const & input_res_vectors=job_parameters_->input_res_vectors();
367 
368  if ( input_tags_.size() < 1) utility_exit_with_message( "input_tags_.size() < 1" );
369 
370  if ( copy_DOF_==false) utility_exit_with_message( "copy_DOF_==false!" );
371 
372  using namespace core::pose;
373  using namespace ObjexxFCL;
374 
375  std::map< core::Size, core::Size > & full_to_sub( job_parameters_->full_to_sub() );
376 
377  utility::vector1<pose::Pose> start_pose_list;
378 
379  Pose start_pose;
380  Pose start_pose_with_variant;
381  for ( Size i = 1; i <= input_tags_.size(); i++ ){
382 
383  std::cout << "import_pose " << i << std::endl;
384 
385  //Ok account for special case of build loop outward from scratch...
386  if(input_tags_[i]=="build_from_scratch"){
387  if(input_res_vectors[i].size()!=1) utility_exit_with_message( "input_tags_[i]==\"build_from_scratch\" but input_res_vectors[i].size()!=1" );
388  continue;
389  }
390 
391  Import_pose( i, start_pose );
392  start_pose_with_variant=start_pose;
393  start_pose_list.push_back(start_pose);
394 
395  utility::vector1< Size > const & input_res = job_parameters_->input_res_vectors()[i]; //This is from input_pose numbering to full_pose numbering
396 
397  // Remove all variant types
398  // DO TO LIST: Need to remove atom constraint and remove angle constaint as well
399  //NOTES: June 16, 2011
400  //Should LOWER_TERMINUS and UPPER_TERMINUS be removed as well? LOWER_TERMINUS does determine the position of O1P and O2P?
401  //Also should then check that pose.residue_type(i).variant_types() is the empty?
402  //Alternatively could convert to FARFAR way and use the NEW_copy_dof that match atom names (MORE ROBUST!). This way doesn't need to remove any variant type from the chunk_pose?
403 
404  utility::vector1< std::string > variant_type_list;
405  variant_type_list.push_back("VIRTUAL_PHOSPHATE");
406  variant_type_list.push_back("VIRTUAL_O2STAR_HYDROGEN");
407  variant_type_list.push_back("CUTPOINT_LOWER");
408  variant_type_list.push_back("CUTPOINT_UPPER");
409  variant_type_list.push_back("VIRTUAL_RNA_RESIDUE");
410  variant_type_list.push_back("VIRTUAL_RNA_RESIDUE_UPPER");
411  variant_type_list.push_back("BULGE");
412  variant_type_list.push_back("VIRTUAL_RIBOSE");
413  variant_type_list.push_back("PROTONATED_H1_ADENOSINE");
414  variant_type_list.push_back("3PRIME_END_OH"); //Fang's electron density code
415  variant_type_list.push_back("5PRIME_END_PHOSPHATE"); //Fang's electron density code
416  variant_type_list.push_back("5PRIME_END_OH"); //Fang's electron density code
417 
418  for ( Size seq_num = 1; seq_num <= start_pose.total_residue(); seq_num++ ) {
419  for ( Size k = 1; k <= variant_type_list.size(); ++k ) {
420  std::string const & variant_type = variant_type_list[k];
421 
422  if( start_pose.residue(seq_num).has_variant_type(variant_type) ) {
423  remove_variant_type_from_pose_residue( start_pose, variant_type, seq_num );
424  }
425 
426  }
427  }
428 
429  if(output_pdb_) {
430  start_pose.dump_pdb( "import_" + string_of(i) + ".pdb" );
431  start_pose_with_variant.dump_pdb( "import_orig_" + string_of(i) + ".pdb" );
432  }
433 
434  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
435  //Now actually copy into the pose.
436  // Need to know correspondence of residues between imported pose and the working pose...
437  if ( input_res.size() != start_pose.total_residue() ) {
438  utility_exit_with_message( "Need to specify -already_built_residues, and the number of residues needs to match pdb file inputted after -s" );
439  }
440 
441  std::map< core::Size, core::Size > res_map; //This is map from sub numbering to input_res numbering..
442  for ( Size n = 1; n <= input_res.size(); n++ ) {
443  res_map[ full_to_sub[ input_res[n] ] ] = n;
444  //std::cout << full_to_sub_[ input_res_[ n ] ] << " " << n << std::endl;
445  }
446 
447  //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.
448 
449  //Dec 24, 2011 Parin S.:Convert to Rhiju's NEW version
450  //copy_dofs( pose, start_pose, res_map, true /*copy_dofs_for_junction_residues*/ );
451  copy_dofs_match_atom_names( pose, start_pose, res_map, false /*backbone_only*/, false /*ignore_virtual*/);
452 
453  //////////////////////Add virtual_rna_residue, virtual_rna_residue variant_upper and VIRTUAL_RIBOSE variant type back//////////////////////
454  //////////////////////For standard dincleotide move, there should be virtual_rna_residue and virtual_rna_residue variant_upper //////////
455  //////////////////////However if floating base sampling, will contain the virtual_ribose as well..
456 
457 
458  utility::vector1< Size > const & cutpoint_closed_list = job_parameters_->cutpoint_closed_list();
459  utility::vector1< Size > const & working_cutpoint_closed_list=apply_full_to_sub_mapping( cutpoint_closed_list , StepWiseRNA_JobParametersCOP(job_parameters_) );
460 
461  for ( Size n = 1; n <= start_pose_with_variant.total_residue(); n++ ) {
462  if( has_virtual_rna_residue_variant_type(start_pose_with_variant, n) ){
463  apply_virtual_rna_residue_variant_type( pose, full_to_sub[ input_res[n] ], working_cutpoint_closed_list ) ;
464  }
465 
466  if(start_pose_with_variant.residue(n).has_variant_type("VIRTUAL_RIBOSE")){
467  add_variant_type_to_pose_residue( pose, "VIRTUAL_RIBOSE", full_to_sub[ input_res[n] ] );
468  }
469 
470  if ( start_pose_with_variant.residue(n).has_variant_type("3PRIME_END_OH") ) {
471  add_variant_type_to_pose_residue( pose, "3PRIME_END_OH", full_to_sub[ input_res[n] ] );
472  } else if ( start_pose_with_variant.residue(n).has_variant_type("5PRIME_END_PHOSPHATE") ) {
473  add_variant_type_to_pose_residue( pose, "5PRIME_END_PHOSPHATE", full_to_sub[ input_res[n] ] );
474  } else if ( start_pose_with_variant.residue(n).has_variant_type("5PRIME_END_OH") ) {
475  add_variant_type_to_pose_residue( pose, "5PRIME_END_OH", full_to_sub[ input_res[n] ] );
476  }
477 
478  if( i > silent_files_in_.size() ) { // not a silent file, read in from pdb text file. May 04, 2011
479 
480  //start_pose_with_variant does not have PROTONATED_H1_ADENOSINE variant type since the input_pdb does not have the variant type or loses the variant when imported into Rosetta.
481 
482  if ( start_pose_with_variant.residue(n).has_variant_type("PROTONATED_H1_ADENOSINE") ) { //May 03, 2011
483  Output_seq_num_list("protonate_H1_adenosine_list= ", job_parameters_->protonated_H1_adenosine_list());
484  utility_exit_with_message("start_pose have PROTONATED_H1_ADENOSINE variant type at full_seq_num=" + ObjexxFCL::string_of(input_res[n]) + " even though it was read in from PDB file!");
485  }
486 
487  if(Contain_seq_num( input_res[n], job_parameters_->protonated_H1_adenosine_list() )){
488  apply_protonated_H1_adenosine_variant_type( pose, full_to_sub[ input_res[n] ]);
489  }
490 
491  }else{
492 
493  if( start_pose_with_variant.residue(n).has_variant_type("PROTONATED_H1_ADENOSINE") ) { //May 03, 2011
494 
495  if(start_pose.residue(n).aa() != core::chemical::na_rad){
496  utility_exit_with_message("start_pose have PROTONATED_H1_ADENOSINE variant type at full_seq_num=" + ObjexxFCL::string_of(input_res[n]) + " but rsd.aa()!=core::chemical::na_rad!");
497  }
498 
499  if(Contain_seq_num( input_res[n], job_parameters_->protonated_H1_adenosine_list() )==false){
500  Output_seq_num_list("protonate_H1_adenosine_list= ", job_parameters_->protonated_H1_adenosine_list());
501  utility_exit_with_message("full_seq_num=" + ObjexxFCL::string_of(input_res[n]) + " is have a PROTONATED_H1_ADENOSINE variant type in the start_pose but is not in the protonate_H1_adenosine_list");
502  }
503 
504  apply_protonated_H1_adenosine_variant_type( pose, full_to_sub[ input_res[n] ]);
505  }
506  }
507 
508  }
509  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
510 
511  if(output_pdb_) pose.dump_pdb( "copy_dof_" + string_of(i) + ".pdb" );
512  std::cout << pose.fold_tree() << std::endl;
513  }
514 
515  protocols::rna::assert_phosphate_nomenclature_matches_mini( pose );//Just to be safe, Jun 11, 2010
516 
517  correctly_copy_HO2star_positions(pose, start_pose_list);
518 
519 
520  }
521 
522  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
523  void
525 
526  using namespace ObjexxFCL;
527  using namespace core::conformation;
528  using namespace core::id;
529 
530  if(verbose_) Output_title_text("Enter StepWiseRNA_PoseSetup::correctly_copy_HO2star_position");
531 
532  if(output_pdb_) working_pose.dump_pdb( "copy_dof_pose_BEFORE_correctly_copy_HO2star_positions.pdb" );
533 
534  std::map< core::Size, core::Size > & full_to_sub( job_parameters_->full_to_sub() );
535 
536 
537  //Problem aside in the long_loop mode, where we combine two silent_file pose. The two pose both contain the fixed background residues
538  //In current implementation of COPY_DOFS, the positioning of the background residues in SECOND silent file is used.
539  //However, some background HO2star interacts with the first pose and hence need to correctly copys these HO2star position.
540  //When we implemenet protien/RNA interactions, will extend this to include all "packed" side chains.
541 
542  utility::vector1< utility::vector1< Size > > const & input_res_vectors=job_parameters_->input_res_vectors();
543 
544  std::map< core::Size, core::Size > full_to_input_res_map_ONE=create_full_to_input_res_map(input_res_vectors[1]);
545  std::map< core::Size, core::Size > full_to_input_res_map_TWO=create_full_to_input_res_map(input_res_vectors[2]);
546 
547  if(input_res_vectors.size()!=2) return; //This problem occur only when copying two input pose.
548 
549  //first find residues that are common between the two input pose1
550 
551  utility::vector1< Size > common_res_list;
552 
553  for(Size n=1; n<=input_res_vectors[1].size(); n++){
554  Size const seq_num=input_res_vectors[1][n];
555  if(Contain_seq_num(seq_num, input_res_vectors[2])==true){
556  common_res_list.push_back(seq_num);
557  }
558  }
559 
560  if(verbose_){
561  Output_seq_num_list("input_res_vectors[1]= ", input_res_vectors[1], 30);
562  Output_seq_num_list("input_res_vectors[2]= ", input_res_vectors[2], 30);
563  Output_seq_num_list("common_res_list= ", common_res_list, 30);
564  }
565 
566  if(common_res_list.size()==0) {
567  if(verbose_) Output_title_text("Exit StepWiseRNA_PoseSetup::correctly_copy_HO2star_position");
568  return; //No common/background residues...
569  }
570 
571  for(Size n=1; n<=common_res_list.size(); n++){
572  Size const full_seq_num=common_res_list[n];
573  Size const working_seq_num=full_to_sub[full_seq_num];
574 
575  Size const input_ONE_seq_num=full_to_input_res_map_ONE.find(full_seq_num)->second;
576  Real const nearest_dist_ONE= get_nearest_dist_to_O2star(input_ONE_seq_num, start_pose_list[1], input_res_vectors[1], common_res_list);
577 
578 
579  Size const input_TWO_seq_num=full_to_input_res_map_TWO.find(full_seq_num)->second;
580  Real const nearest_dist_TWO= get_nearest_dist_to_O2star(input_TWO_seq_num, start_pose_list[2], input_res_vectors[2], common_res_list);
581 
582 
583 
584  //pose.set_torsion( TorsionID( moving_res, id::CHI, 4 ), 0 ); //This torsion is not sampled. Arbitary set to zero to prevent randomness
585  id::TorsionID const torsion_id(working_seq_num , id::CHI, 4 );
586 
587  if(verbose_) std::cout << "full_seq_num= " << full_seq_num << " nearest_dist_ONE= " << nearest_dist_ONE << " nearest_dist_TWO= " << nearest_dist_TWO;
588 
589  if(nearest_dist_ONE < nearest_dist_TWO){
590  working_pose.set_torsion( torsion_id, start_pose_list[1].torsion(TorsionID( input_ONE_seq_num, id::CHI, 4 )) );
591  std::cout << " NEARER TO INPUT_POSE_ONE " ;
592  }else{
593  working_pose.set_torsion( torsion_id, start_pose_list[2].torsion(TorsionID( input_TWO_seq_num, id::CHI, 4 )) );
594  std::cout << " NEARER TO INPUT_POSE_TWO " ;
595  }
596 
597  std::cout << std::endl;
598 
599  }
600 
601  if(output_pdb_) working_pose.dump_pdb( "copy_dof_pose_AFTER_correctly_copy_HO2star_positions.pdb" );
602  if(verbose_) Output_title_text("Exit StepWiseRNA_PoseSetup::correctly_copy_HO2star_position");
603 
604  }
605  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
606 
607  core::Real
608  StepWiseRNA_PoseSetup::get_nearest_dist_to_O2star( Size const O2star_seq_num, pose::Pose const & input_pose, utility::vector1< Size > const input_res_list , utility::vector1< Size > const & common_res_list){
609 
610  using namespace core::conformation;
611  using namespace ObjexxFCL;
612 
613 
614  //Real nearest_dist_SQ=9999999999999.99; //Feb 12, 2012 This might lead to server-test error at R47200
615  Real nearest_dist_SQ=99999999.9; //Feb 12, 2012
616 
617  conformation::Residue const & input_pose_O2star_rsd=input_pose.residue(O2star_seq_num);
618 
619  if ( !input_pose_O2star_rsd.has( " O2*" ) ) utility_exit_with_message( "rsd at input_seq_num= " + string_of(O2star_seq_num) + " doesn't have O2* atom! " );
620 
621  numeric::xyzVector<core::Real> const O2star_xyz= input_pose_O2star_rsd.xyz( input_pose_O2star_rsd.atom_index( " O2*" ) );
622 
623 
624  for(Size input_pose_seq_num=1; input_pose_seq_num<=input_res_list.size(); input_pose_seq_num++){
625  Size const full_seq_num=input_res_list[input_pose_seq_num];
626 
627  if(Contain_seq_num(full_seq_num, common_res_list)==true) continue; //A common/background res..not a residue built by SWA.
628 
629  conformation::Residue const & input_pose_rsd=input_pose.residue(input_pose_seq_num);
630 
631  for(Size at=1; at<=input_pose_rsd.natoms(); at++){
632 
633  Real const dist_to_o2star_SQ=(input_pose_rsd.xyz(at)-O2star_xyz).length_squared();
634  if(dist_to_o2star_SQ < nearest_dist_SQ ) nearest_dist_SQ=dist_to_o2star_SQ;
635 
636  }
637 
638 
639  }
640 
641  Real const nearest_dist= sqrt(nearest_dist_SQ);
642 
643  return nearest_dist;
644 
645  }
646 
647 
648  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
649  void
651 
652  using namespace core::id;
653 
654 
655  std::map< core::Size, core::Size > & full_to_sub( job_parameters_->full_to_sub() );
656  utility::vector1< Size > const & cutpoint_closed_list = job_parameters_->cutpoint_closed_list();
657 
658  for(Size n=1; n<=cutpoint_closed_list.size(); n++){
659 
660  Size const cutpoint_closed=cutpoint_closed_list[n];
661 
662  if ( cutpoint_closed == 0 ) continue;
663 
664  if ( full_to_sub.find( cutpoint_closed ) != full_to_sub.end() && full_to_sub.find( cutpoint_closed+1 ) != full_to_sub.end() ) {
665 
666  std::cout << "Applying cutpoint variants to " << cutpoint_closed << std::endl;
667 
668  Size const cutpos = full_to_sub[ cutpoint_closed];
669 
670  // Taken from Parin's code. Need to make sure virtual atoms are correctly positioned
671  // next to O1P, O2P.
672  Correctly_position_cutpoint_phosphate_torsions( pose, cutpos, false /*verbose*/ );
673 
676 
677 
678  std::cout << "pose (before copy): " << std::endl;
679  print_backbone_torsions(pose, cutpos);
680  print_backbone_torsions(pose, cutpos+1);
681 
682  for (Size i = cutpos; i <= cutpos + 1; i++ ){
683  for (Size j = 1; j <= scoring::rna::NUM_RNA_MAINCHAIN_TORSIONS; j++ ) {
684  id::TorsionID torsion_id( i, id::BB, j );
685  pose.set_torsion( torsion_id, pose_without_cutpoints.torsion( torsion_id ) ); //This makes sure that the chain_break torsions have the correct value
686  } // j
687  } // i
688 
689  if(verbose_) {
690  std::cout << "pose_without_cutpoints " << std::endl;
691  print_backbone_torsions(pose_without_cutpoints, cutpos);
692  print_backbone_torsions(pose_without_cutpoints, cutpos+1);
693  std::cout << "pose: " << std::endl;
694  print_backbone_torsions(pose, cutpos);
695  print_backbone_torsions(pose, cutpos+1);
696  }
697 
698 /*
699  Size five_prime_res=cutpos;
700  Size three_prime_res=cutpos+1;
701 
702 
703  conformation::Residue const & lower_res=pose_copy.residue(five_prime_res);
704  conformation::Residue const & upper_res=pose_copy.residue(three_prime_res);
705 
706  //Even through there is the chain_break, these torsions should be defined due to the existence of the upper and lower variant type atoms.
707 
708  for(Size n=1; n<=3; n++){ //alpha, beta, gamma of upper residue
709  pose.set_torsion( TorsionID( three_prime_res, id::BB, n ), upper_res.mainchain_torsion(n) );
710  }
711 
712 
713  for(Size n=5; n<=6; n++){ //epsilon and zeta of lower residue
714  pose.set_torsion( TorsionID( five_prime_res, id::BB, n ), lower_res.mainchain_torsion(n) );
715  }
716 */
717 
718 
719  } else {
720  utility_exit_with_message( "User provided cutpoint_closed not in working pose?" );
721  }
722  }
723 
724  }
725 
726  //////////////////////////////////////////////////////////////////////////////
727  // Assume we have done a crappy job of placing 5' phosphates.
728  // this would be true if, for example, the 5' phosphate was built
729  // by prepending in a previous rebuild-from-scratch effort.
730  // The only exception is if the 5'-phosphate is involved in *chain closure*.
731  //(5' phosphate actually refer to the phosphate group of the residue 3' of the chain_break!!! Jan 29, 2010 Parin S.)
732  void
734 
735  using namespace ObjexxFCL;
736 
737  utility::vector1< std::pair< core::Size, core::Size > > const & chain_boundaries( job_parameters_->chain_boundaries() );
738  std::map< core::Size, core::Size > & full_to_sub( job_parameters_->full_to_sub() );
739  utility::vector1< Size > const & cutpoint_closed_list = job_parameters_->cutpoint_closed_list();
740 
741  Size const num_chains = chain_boundaries.size();
742 
743  for ( Size n = 1; n <= num_chains; n++ ) {
744  Size const chain_start = chain_boundaries[ n ].first;
745 
746  bool chain_start_is_cutpoint_closed=false;
747 
748  for(Size i=1; i <= cutpoint_closed_list.size(); i++){
749  Size const cutpoint_closed=cutpoint_closed_list[i];
750 
751  if ( cutpoint_closed > 0 && full_to_sub[ chain_start ] == full_to_sub[ cutpoint_closed ]+1 ) {
752  chain_start_is_cutpoint_closed=true;
753  break;
754  }
755  }
756  if(chain_start_is_cutpoint_closed) continue;
757 
758  if ( pose.residue( full_to_sub[ chain_start ] ).type().has_variant_type( core::chemical::CUTPOINT_UPPER ) ) {
759  utility_exit_with_message( "Should not be trying to virtualize phosphate on close cutpoint residue (chain_start= " + string_of(chain_start) + " )");
760  }
761 
762  pose::add_variant_type_to_pose_residue( pose, "VIRTUAL_PHOSPHATE", full_to_sub[ chain_start ] );
763  }
764  }
765 
766  //////////////////////////////////////////////////////////////////////////
767  void
769  {
770  using namespace core::conformation;
771  using namespace core::id;
772  using namespace core::scoring::constraints;
773  using namespace core::scoring::rna;
774 
775  ConstraintSetOP cst_set( pose.constraint_set()->clone() );
776  assert( cst_set );
777 
778  utility::vector1< core::Size > const & working_terminal_res = job_parameters_->working_terminal_res();
779 
780  if ( working_terminal_res.size() == 0 ) return;
781 
782 
783  /////////////////////////////////////////////////
784  Size const nres( pose.total_residue() );
785 
786  ObjexxFCL::FArray1D<bool> is_moving_res( nres, false );
787  ObjexxFCL::FArray1D<bool> is_fixed_res( nres, false );
788 
789  ObjexxFCL::FArray1D< bool > const & partition_definition = job_parameters_->partition_definition();
790  bool const root_partition = partition_definition( pose.fold_tree().root() );
791 
792  for (Size seq_num=1; seq_num <= nres; seq_num++){
793  if ( partition_definition( seq_num ) == root_partition ) {
794  is_fixed_res( seq_num ) = true;
795  } else {
796  is_moving_res( seq_num ) = true;
797  }
798  }
799 
800  Output_seq_num_list("working_terminal_res_list= ", working_terminal_res, 40);
801  /////////////////////////////////////////////////
802  Distance const DIST_CUTOFF = 8.0;
803  FuncOP const repulsion_func( new FadeFunc( -2.0 /*min*/, DIST_CUTOFF /*max*/, 1.0 /*fade zone width*/, 100.0 /*penalty*/ ) );
804 
805  for ( Size i = 1; i <= working_terminal_res.size(); i++ ) {
806 
807  Size const k = working_terminal_res[ i ];
808  Residue const & rsd1( pose.residue( k ) );
809  if(rsd1.has_variant_type("VIRTUAL_RNA_RESIDUE")){
810  std::cout << "rsd1.has_variant_type(\"VIRTUAL_RNA_RESIDUE\"), seq_num= " << k << " Ignore terminal_res_repulsion distance constraint " << std::endl;
811  continue;
812  }
813  for ( Size m = 1; m <= nres; m++ ) {
814 
815  Residue const & rsd2( pose.residue( m ) );
816  if(rsd2.has_variant_type("VIRTUAL_RNA_RESIDUE")){
817  std::cout << "rsd2.has_variant_type(\"VIRTUAL_RNA_RESIDUE\"), seq_num= " << m << " Ignore terminal_res_repulsion distance constraint " << std::endl;
818  continue;
819  }
820 
821  AtomID const atom_id1( first_base_atom_index( rsd1 ), rsd1.seqpos() );
822  AtomID const atom_id2( first_base_atom_index( rsd2 ), rsd2.seqpos() );
823 
824  // the one exception -- close contacts WITHIN a partition
825  if ( ( ( is_moving_res( k ) && is_moving_res( m ) ) ||
826  ( is_fixed_res( k ) && is_fixed_res( m ) ) ) &&
827  ( pose.xyz( atom_id1 ) - pose.xyz( atom_id2 ) ).length() < DIST_CUTOFF ) {
828  //std::cout << "Not adding repulsive constraint between " << k << " and " << m << " already closeby in same partition" << std::endl;
829  continue;
830  }
831 
832  // distance from O3* to P
833  cst_set->add_constraint( new AtomPairConstraint( atom_id1, atom_id2, repulsion_func ) );
834 
835  }
836  }
837 
838  pose.constraint_set( cst_set );
839 
840  /* For debugging....
841  std::cout << "constraints " << std::endl;
842  core::scoring::constraints::ConstraintSetOP cst_set( pose.constraint_set()->clone() );
843  cst_set->show(std::cout);
844  pose.remove_constraints();
845  */
846  }
847 
848  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
849  void
851 
852  utility::vector1< core::Size > const & working_protonated_H1_adenosine_list = job_parameters_->working_protonated_H1_adenosine_list();
853  Size const working_moving_res = job_parameters_->working_moving_res(); // corresponds to user input.
854 
855  bool apply_check=true;
856 
858  //OK as long as we will definitely remove the virtual variant type from this res before sampling and minimizing!
859  apply_check=false;
860  std::cout << "rebuild_bulge_mode_=true, setting apply_check for apply_protonated_H1_adenosine_variant_type to false" << std::endl;
861  }
862 
863  if( Contain_seq_num(working_moving_res, working_protonated_H1_adenosine_list ) ){
864  apply_protonated_H1_adenosine_variant_type( pose, working_moving_res, apply_check );
865  }
866 
867  }
868 
869  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
870  void
872 
873  using namespace core::conformation;
874  using namespace core::pose;
875  using namespace ObjexxFCL;
876 
877 
878  utility::vector1< core::Size > const & working_protonated_H1_adenosine_list = job_parameters_->working_protonated_H1_adenosine_list();
879 
880  //Check that all protonated_H1_adenosine exist in the pose!
881  for(Size seq_num=1; seq_num<=pose.total_residue(); seq_num++){
882 
883  if( Contain_seq_num(seq_num, working_protonated_H1_adenosine_list ) ){
884 
885  if(pose.residue(seq_num).aa() != core::chemical::na_rad){
887  utility_exit_with_message("Contain_seq_num(seq_num, working_protonated_H1_adenosine_list )==true but pose.residue(seq_num).aa() != core::chemical::na_rad, seq_num= " + string_of(seq_num) );
888  }
889 
890  if(pose.residue(seq_num).has_variant_type("PROTONATED_H1_ADENOSINE")==false && pose.residue(seq_num).has_variant_type("VIRTUAL_RNA_RESIDUE")==false){
892  utility_exit_with_message("Contain_seq_num(seq_num, working_protonated_H1_adenosine_list )==true but residue doesn't either PROTONATED_H1_ADENOSINE or VIRTUAL_RNA_RESIDUE variant type , seq_num=" + string_of(seq_num) );
893  }
894  }else{
895  if(pose.residue(seq_num).has_variant_type("PROTONATED_H1_ADENOSINE") ){
896 
898  std::cout << "ERROR: seq_num=" << seq_num << std::endl;
899  std::cout << "ERROR: start_pose.residue(n).aa()=" << name_from_aa(pose.residue(seq_num).aa()) << std::endl;
900  utility_exit_with_message("Contain_seq_num(seq_num, working_protonated_H1_adenosine_list)==false but pose.residue(seq_num).has_variant_type(\"PROTONATED_H1_ADENOSINE\") )==false");
901  }
902 
903  }
904 
905  }
906 
907  }
908 
909  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
910  void
912 
913  using namespace core::conformation;
914  using namespace core::pose;
915  using namespace ObjexxFCL;
916 
917 
918  std::map< core::Size, core::Size > & full_to_sub( job_parameters_->full_to_sub() );
919  utility::vector1< Size > const & working_terminal_res = job_parameters_->working_terminal_res();
920 
921  utility::vector1< Size > terminal_res=apply_sub_to_full_mapping( working_terminal_res, job_parameters_);
922 
923  for ( Size i = 1; i <= bulge_res_.size(); i++ ) {
924  Size const seq_num=bulge_res_[i];
925 
926  if( Contain_seq_num(seq_num, terminal_res) == true) utility_exit_with_message("seq_num: " + string_of(seq_num) + " cannot be both both a bulge_res and a terminal res!");
927 
928  if(full_to_sub.find( seq_num ) == full_to_sub.end() ) continue;
929 
930  pose::add_variant_type_to_pose_residue( pose, "BULGE", full_to_sub[ seq_num] );
931  }
932 
933 
934  }
935  ////////////////////////////////////////////////////////////////////////////////////////
936  void
938  //Parin Jan 17, 2009
939 
940  using namespace core::id;
941  using namespace ObjexxFCL;
942 
943 
944  std::map< core::Size, core::Size > & full_to_sub( job_parameters_->full_to_sub() );
945  utility::vector1< Size > const & working_terminal_res = job_parameters_->working_terminal_res();
946 
947  utility::vector1< Size > terminal_res=apply_sub_to_full_mapping( working_terminal_res, job_parameters_);
948 
949  ///////////////////////////////////////////////////////////////////////////////////////
950  Size const working_moving_res( job_parameters_->working_moving_res() ); // corresponds to user input.
951  bool const Is_prepend( job_parameters_->Is_prepend() );
952  Size const working_bulge_moving_res= (Is_prepend) ? working_moving_res+1 : working_moving_res-1;
953 
954  bool const Is_dinucleotide=(job_parameters_->working_moving_res_list().size()==2);
955 
956  if( apply_virtual_res_variant_at_dinucleotide_ && Is_dinucleotide){
957  if(working_bulge_moving_res!=job_parameters_->working_moving_res_list()[2]){
958  Output_boolean("Is_prepend= ", job_parameters_->Is_prepend() );
959  std::cout << " working_moving_res= " << working_moving_res << std::endl;
960  std::cout << "working_bulge_moving_res= " << working_bulge_moving_res << " working_moving_res_list()[2]= " << job_parameters_->working_moving_res_list()[2] << std::endl;
961  utility_exit_with_message( "working_bulge_moving_res!=working_moving_res_list[2]" );
962  }
963 
964  if( Contain_seq_num(working_bulge_moving_res, working_terminal_res ) == true){
965  utility_exit_with_message("working_bulge_moving_res cannot be both both a virtual_res and a terminal res!");
966  }
967  apply_virtual_rna_residue_variant_type( pose, working_bulge_moving_res);
968 
969 // pose::add_variant_type_to_pose_residue( pose, "VIRTUAL_RNA_RESID#UE", working_bulge_moving_res);
970  }
971  /////////////////////////////////////////////////////////////////////////////////////////
972 
973  for(Size i=1; i<=virtual_res_list_.size(); i++){
974  Size const seq_num=virtual_res_list_[i];
975 
976  if( Contain_seq_num(seq_num, terminal_res) == true) utility_exit_with_message("seq_num: " + string_of(seq_num) + " cannot be both both a virtual_res and a terminal res!");
977 
978  if(full_to_sub.find( seq_num ) == full_to_sub.end() ) continue;
979 
980  apply_virtual_rna_residue_variant_type( pose, full_to_sub[ seq_num] );
981 
982 // pose::add_variant_type_to_pose_residue( pose, "VIRTUAL_RNA_RESID#UE", full_to_sub[ seq_num] );
983 
984  }
985  }
986 
987  /////////////////////////////////////////////////////////////////////////////////////////////
988  //Adding Virtual res as root
989  void
990  StepWiseRNA_PoseSetup::add_aa_virt_rsd_as_root( core::pose::Pose & pose){ //Fang's electron density code
991 
992  Size const nres = pose.total_residue();
993  Size const working_moving_res( job_parameters_->working_moving_res() );
994  //if already rooted on virtual residue , return
995  if ( pose.residue( pose.fold_tree().root() ).aa() == core::chemical::aa_vrt ) {
996  TR.Warning << "addVirtualResAsRoot() called but pose is already rooted on a VRT residue ... continuing." << std::endl;
997  return;
998  }
999 
1000  core::chemical::ResidueTypeSet const & residue_set = pose.residue_type(1).residue_type_set();
1001  core::chemical::ResidueTypeCOPs const & rsd_type_list( residue_set.name3_map("VRT") );
1003  if (working_moving_res == 1) {
1004  pose.append_residue_by_jump( *new_res , nres );
1005  } else {
1006  pose.append_residue_by_jump( *new_res , 1 );
1007  }
1008 
1009  // make the virt atom the root
1010  kinematics::FoldTree newF( pose.fold_tree() );
1011  newF.reorder( nres+1 );
1012  pose.fold_tree( newF );
1013  }
1014  ////////////////////////////////////////////////////////////////////////////////////////////////////
1015 
1016 
1017 }
1018 }
1019 }