Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StepWiseRNA_Util.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_Util
11 /// @brief Util functions for Stepwise Assembly RNA.
12 /// @detailed
13 /// @author Parin Sripakdeevong
14 
15 
16 //////////////////////////////////
20 #include <protocols/swa/rna/StepWiseRNA_JobParameters.hh> //Oct 22, 2011..for some reason Util.cc have JP.hh BUT JP.cc also have Util.hh!!! SHOULD RESOLVE THIS!
21 
22 
26 
27 #include <core/scoring/ScoreType.hh> //Parin Sept 20, 2011.
28 //////////////////////////////////
29 
30 #include <core/types.hh>
32 #include <core/chemical/util.hh>
38 #include <core/pose/Pose.hh>
39 #include <core/pose/util.hh>
40 #include <core/pose/util.tmpl.hh>
59 
60 #include <core/id/AtomID.hh>
61 #include <core/id/AtomID_Map.hh>
62 
63 #include <ObjexxFCL/FArray1D.hh>
64 #include <ObjexxFCL/FArray2D.hh>
65 
66 #include <numeric/conversions.hh>
67 
68 #include <iostream>
69 #include <fstream>
70 #include <sstream>
71 #include <ObjexxFCL/format.hh>
72 #include <set>
73 #include <time.h>
74 #include <map>
75 
76 #include <stdio.h> //Sept 26, 2011
77 
78 //for process_mem_usage:
79 #include <ios>
80 
81 
82 using namespace core;
83 
84 namespace protocols {
85 namespace swa {
86 namespace rna {
87 
88 
89  bool Is_O1P_atom(std::string const & atom_name){ return (atom_name==" O1P"); }
90 
91  bool Is_O2P_atom(std::string const & atom_name){ return (atom_name==" O2P"); }
92 
93  bool Is_P_atom(std::string const & atom_name){ return (atom_name==" P "); }
94 
95  bool Is_O2star_atom(std::string const & atom_name){ return (atom_name==" O2*"); }
96 
97  bool Is_O3star_atom(std::string const & atom_name){ return (atom_name==" O3*"); }
98 
99  bool Is_O4star_atom(std::string const & atom_name){ return (atom_name==" O4*"); }
100 
101  bool Is_O5star_atom(std::string const & atom_name){ return (atom_name==" O5*"); }
102 
103  bool Is_C2star_atom(std::string const & atom_name){ return (atom_name==" C2*"); }
104 
105  bool Is_C3star_atom(std::string const & atom_name){ return (atom_name==" C3*"); }
106 
107  bool Is_C4star_atom(std::string const & atom_name){ return (atom_name==" C4*"); }
108 
109  bool Is_C5star_atom(std::string const & atom_name){ return (atom_name==" C5*"); }
110 
111  bool Is_1H5star_atom(std::string const & atom_name){ return (atom_name=="1H5*"); }
112 
113  bool Is_2H5star_atom(std::string const & atom_name){ return (atom_name=="2H5*"); }
114 
115  bool Is_H3star_atom(std::string const & atom_name){ return (atom_name==" H3*"); }
116 
117  bool Is_H4star_atom(std::string const & atom_name){ return (atom_name==" H4*"); }
118 
119  bool Is_three_prime_phosphate_atom(std::string const & atom_name){ return (Is_O3star_atom(atom_name)); }
120 
121  bool Is_five_prime_phosphate_atom(std::string const & atom_name){ return (Is_O5star_atom(atom_name) || Is_O1P_atom(atom_name) || Is_O2P_atom(atom_name) || Is_P_atom(atom_name)) ; }
122 
123  bool Is_phosphate_atom(std::string const & atom_name){ return ( Is_three_prime_phosphate_atom(atom_name) || Is_five_prime_phosphate_atom(atom_name) ); }
124 
125 
126  void
128 
129  using namespace core::scoring;
130  using namespace core::optimization;
131 
132 
133  AtomTreeMinimizer minimizer;
134 
135  scoring::constraints::ConstraintSetOP save_pose_constraints = pose.constraint_set()->clone();
136 
138 
139  minimizer.run( pose, mm, *(scorefxn), options );
140 
141  pose.constraint_set( save_pose_constraints );
142 
143  }
144 
145  bool
147 
148  for(Size n=1; n<=seq_num_list.size()-1; n++){ //[11, 12, 13]
149  if( (seq_num_list[n]+1)!=seq_num_list[n+1]) return false;
150  }
151  return true;
152  }
153 
154  bool
156 
157  for(Size n=1; n<=seq_num_list.size()-1; n++){ //[14, 13, 12]
158  if( (seq_num_list[n]-1)!= seq_num_list[n+1]) return false;
159  }
160  return true;
161  }
162 
163  ////////////////////////////////////////////////May 04, 2011////////////////////////////////////////////////////
164  void
165  apply_protonated_H1_adenosine_variant_type(core::pose::Pose & pose, core::Size const & seq_num, bool const apply_check){
166 
167  bool verbose=true;
168 
169  if(verbose) std::cout << "Applying PROTONATED_H1_ADENOSINE variant_type to seq_num " << seq_num << std::endl;
170 
171  if(apply_check){
172  //Basically the two variant type are not compatible, VIRTUAL_RNA_RESIDUE variant type currently does not virtualize the protonated H1 atom.
173  if(pose.residue(seq_num).has_variant_type("VIRTUAL_RNA_RESIDUE")){
174  utility_exit_with_message("Cannot apply PROTONATED_H1_ADENOSINE variant_type to seq_num: " + ObjexxFCL::string_of(seq_num) + ". This residue have a incompatible VIRTUAL_RNA_RESIDUE variant type." );
175  }
176  }
177 
178 
179  if(pose.residue(seq_num).has_variant_type("PROTONATED_H1_ADENOSINE")){
180  std::cout << "WARNING pose already have PROTONATED_H1_ADENOSINE variant_type at seq_num= " << seq_num << ", early RETURN!" << std::endl;
181  return;
182  //utility_exit_with_message("pose already have PROTONATED_H1_ADENOSINE variant_type at seq_num= " + ObjexxFCL::string_of(seq_num));
183  }
184 
185  if(pose.total_residue()<seq_num){
186  utility_exit_with_message( "Cannot apply PROTONATED_H1_ADENOSINE variant_type to seq_num: " + ObjexxFCL::string_of(seq_num) + ". pose.total_residue()<seq_num" );
187  }
188 
189  if(pose.residue(seq_num).aa() != core::chemical::na_rad){
190  utility_exit_with_message("working_seq_num=" + ObjexxFCL::string_of(seq_num) + " cannot have PROTONATED_H1_ADENOSINE variant type since it is not a adenosine!");
191  }
192 
193  pose::add_variant_type_to_pose_residue( pose, "PROTONATED_H1_ADENOSINE", seq_num );
194 
195  }
196  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
197 
198  void
199  apply_virtual_rna_residue_variant_type(core::pose::Pose & pose, core::Size const & seq_num, bool const apply_check){
200 
201  utility::vector1< Size > working_cutpoint_closed_list;
202  working_cutpoint_closed_list.clear(); //empty list
203 
204  apply_virtual_rna_residue_variant_type(pose, seq_num, working_cutpoint_closed_list, apply_check);
205  }
206 
207  void
208  apply_virtual_rna_residue_variant_type(core::pose::Pose & pose, core::Size const & seq_num, utility::vector1< core::Size > const & working_cutpoint_closed_list, bool const apply_check){
209 
210  using namespace core::chemical;
211  using namespace ObjexxFCL;
212 
213  if(pose.total_residue()<seq_num){
214  utility_exit_with_message( "Cannot apply VIRTUAL_RNA_RESIDUE VARIANT TYPE to seq_num: " + string_of(seq_num) + ". pose.total_residue()<seq_num" );
215  }
216 
217  //Basically the two variant type are not compatible, VIRTUAL_RNA_RESIDUE variant type currently does not virtualize the protonated H1 atom.
218  if(pose.residue(seq_num).has_variant_type("PROTONATED_H1_ADENOSINE")){
219  std::cout << "Removing PROTONATED_H1_ADENOSINE variant_type from seq_num= " << seq_num << " before adding VIRTUAL_RNA_RESIDUE variant_type since the two variant_types are not compatible!" << std::endl;
220  pose::remove_variant_type_from_pose_residue( pose, "PROTONATED_H1_ADENOSINE", seq_num );
221  }
222  //OK PROTONATED_H1_ADENOSINE variant type should also be removed when adding VIRTUAL_RNA_RESIDUE_EXCLUDE_PHOSPHATE variant type or BULGE variant type.
223  //However these two variant type are not currently used in standard SWA run (May 04, 2011)
224 
225 
226 
227  bool Is_cutpoint_closed=false;
228 
229  if(pose.residue( seq_num ).has_variant_type( chemical::CUTPOINT_LOWER ) ){
230  if( pose.residue( seq_num+1 ).has_variant_type( chemical::CUTPOINT_UPPER )==false ){
231  utility_exit_with_message("seq_num " + string_of(seq_num) + " is a CUTPOINT_LOWER but seq_num " + string_of(seq_num+1) + " is not a cutpoint CUTPOINT_UPPER??" );
232  }
233  Is_cutpoint_closed=true;
234  }
235 
236  //Ok another possibility is that the CUTPOINT_LOWER and CUTPOINT_UPPER variant type had not been applied yet..so check the working_cutpoint_closed_list
237  for(Size n=1; n<=working_cutpoint_closed_list.size(); n++){
238  if(seq_num==working_cutpoint_closed_list[n]) {
239  Is_cutpoint_closed=true;
240  break;
241  }
242  }
243 
244 
245  bool const Is_cutpoint_open=( pose.fold_tree().is_cutpoint( seq_num ) && Is_cutpoint_closed==false);
246 
247  if(apply_check){
248  if (Is_cutpoint_open) {
249  utility_exit_with_message( "Cannot apply VIRTUAL_RNA_RESIDUE VARIANT TYPE to seq_num: " + string_of(seq_num) + ". The residue is 5' of a OPEN cutpoint" );
250  }
251 
252  if ( pose.total_residue()==seq_num ) {
253  utility_exit_with_message( "Cannot apply VIRTUAL_RNA_RESIDUE VARIANT TYPE to seq_num: " + string_of(seq_num) + ". pose.total_residue()==seq_num" );
254  }
255 
256  }
257 
258  pose::add_variant_type_to_pose_residue( pose, "VIRTUAL_RNA_RESIDUE", seq_num );
259 
260  //if( !(pose.total_residue()==seq_num) && (Is_cutpoint_open==false) ) {
261  if( (pose.total_residue()!=seq_num) && (Is_cutpoint_open==false) ) { //April 6, 2011
262  pose::add_variant_type_to_pose_residue( pose, "VIRTUAL_RNA_RESIDUE_UPPER", seq_num+1 );
263  }
264  }
265  //////////////////////////////////////////////////////////////////////////////////////
266  void
268 
269  using namespace core::chemical;
270  using namespace ObjexxFCL;
271 
272  if(pose.total_residue()<seq_num){
273  utility_exit_with_message( "Cannot remove VIRTUAL_RNA_RESIDUE VARIANT TYPE to seq_num: " + string_of(seq_num) + ". pose.total_residue()<seq_num" );
274  }
275 
276  if(pose.total_residue()==seq_num){ //April 6, 2011
277  utility_exit_with_message( "Cannot remove VIRTUAL_RNA_RESIDUE VARIANT TYPE to seq_num: " + string_of(seq_num) + ". pose.total_residue()==seq_num" );
278  }
279 
280  pose::remove_variant_type_from_pose_residue( pose, "VIRTUAL_RNA_RESIDUE", seq_num );
281  pose::remove_variant_type_from_pose_residue( pose, "VIRTUAL_RNA_RESIDUE_UPPER", seq_num+1 );
282 
283  }
284  //////////////////////////////////////////////////////////////////////////////////////
285  bool
287 
288  using namespace ObjexxFCL;
289 
290  if(pose.residue(seq_num).has_variant_type("VIRTUAL_RNA_RESIDUE")==false) return false;
291 
292  if( (seq_num+1)>pose.total_residue()){ //Check in range
293  std::cout << "(seq_num+1)= " << (seq_num+1) << std::endl;
294  utility_exit_with_message( "(seq_num+1)>pose.total_residue()!" );
295  }
296 
297  if(pose.residue(seq_num+1).has_variant_type("VIRTUAL_RNA_RESIDUE_UPPER")==false){
298  std::cout << "Problem seq_num= " << seq_num << std::endl;
299  utility_exit_with_message("res (" + string_of(seq_num) + ") has_variant_type VIRTUAL_RNA_RESIDUE but res seq_num+1 (" + string_of(seq_num+1) + ")does not have variant_type VIRTUAL_RNA_RESIDUE_UPPER");
300  }
301 
302  return true;
303 
304  }
305 
306  //////////////////////////////////////////////////////////////////////////////////////
307  void
309 
310 
311  for(Size seq_num = 1; seq_num <= pose.total_residue(); seq_num++ ) {
312 
313  if (pose.residue(seq_num).aa() == core::chemical::aa_vrt ) continue; //Fang's electron density code
314 
315  utility::vector1< core::chemical::VariantType > target_variants( pose.residue(seq_num).type().variant_types() );
316 
317  if(target_variants.size()!=pose.residue(seq_num).type().variant_types().size()){
318  utility_exit_with_message("target_variants.size()!=pose.residue(seq_num).type().variant_types().size()");
319  }
320 
321  Size skip_variant_count=0;
322 
323  for ( Size i=1; i<= target_variants.size(); i++ ) {
324  //std::cout << "seq_num=" << seq_num << " variant_type[" << i << "]=" << target_variants[i] << std::endl;
325 
326  if ( pose.residue(seq_num).type().has_variant_type( target_variants[i] )==false ) utility_exit_with_message("pose.residue(seq_num).type().has_variant_type( target_variants[i] )==false!");
327 
328  bool skip_this_variant=false;
329 
330  if(target_variants[i]=="LOWER_TERMINUS") skip_this_variant=true;
331 
332  if(target_variants[i]=="UPPER_TERMINUS") skip_this_variant=true;
333 
334  if(skip_this_variant){
335  skip_variant_count++;
336  continue;
337  }
338 
339  pose::remove_variant_type_from_pose_residue( pose, target_variants[i], seq_num );
340 
341  }
342 
343  if(pose.residue(seq_num).type().variant_types().size()!=skip_variant_count){
344  std::cout << "pose.residue(seq_num).type().variant_types().size()=" << pose.residue(seq_num).type().variant_types().size() << std::endl;
345  std::cout << "skip_variant_count=" << skip_variant_count << std::endl;
346  utility_exit_with_message("pose.residue(seq_num).type().variant_types().size()!=skip_variant_count");
347  }
348 
349  }
350 
351  }
352 
353  //////////////////////////////////////////////////////////////////////////////////////
355  apply_full_to_sub_mapping( utility::vector1< Size > const & res_vector, utility::vector1< core::Size > const & is_working_res, std::map< core::Size, core::Size > const & full_to_sub){
356 
357  using namespace ObjexxFCL;
358 
359  if(is_working_res.size()==0){
360  utility_exit_with_message("is_working_res.size()==0");
361  }
362 
363  if(full_to_sub.empty()==true){
364  utility_exit_with_message("full_to_sub.empty()==true");
365  }
366 
367  Size const total_res=is_working_res.size();
368 
369  utility::vector1< core::Size > working_res_vector;
370  for ( Size n = 1; n <= res_vector.size(); n++ ) {
371 
372  if(res_vector[ n ] >total_res) utility_exit_with_message( "res_vector[ n ] (" +string_of(res_vector[ n ]) + ") > total_res (" + string_of(total_res) + ")!");
373 
374  if ( !is_working_res[ res_vector[ n ] ] ) continue;
375  working_res_vector.push_back( full_to_sub.find(res_vector[ n ])->second);
376  }
377 
378  return working_res_vector;
379 
380  }
381 
382  //////////////////////////////////////////////////////////////////////////////////////
383 
386 
387  utility::vector1< core::Size > const & is_working_res = job_parameters->is_working_res();
388  std::map< core::Size, core::Size > const & full_to_sub = job_parameters->const_full_to_sub();
389 
390  return apply_full_to_sub_mapping( res_vector, is_working_res, full_to_sub);
391 
392  }
393 
394 
395  //////////////////////////////////////////////////////////////////////////////////////
396 
399 
400  std::map< core::Size, core::Size > const & sub_to_full( job_parameters->const_sub_to_full() );
401 
402  utility::vector1< core::Size > full_res_vector;
403  for ( Size n = 1; n <= working_res_vector.size(); n++ ){
404 
405  if(sub_to_full.find(working_res_vector[ n ])==sub_to_full.end()){
406  utility_exit_with_message( "sub_to_full.find(working_res_vector[ n ]).end()==sub_to_full.end()!");
407  }
408 
409  full_res_vector.push_back( sub_to_full.find(working_res_vector[ n ])->second);
410  }
411 
412  return full_res_vector;
413  }
414 
415 
416  ///////////////////////////This should be a function of the job_parameters class///////////////////////
417  void
418  ensure_valid_full_seq_num(Size const full_seq_num, StepWiseRNA_JobParametersCOP const & job_parameters){
419 
420  using namespace ObjexxFCL;
421 
422  utility::vector1< core::Size > const & is_working_res = job_parameters->is_working_res();
423 
424  if(full_seq_num<1) utility_exit_with_message("full_seq_num (" + string_of(full_seq_num) + ") is lesser then 1");
425 
426  if(full_seq_num>is_working_res.size()) utility_exit_with_message("full_seq_num (" +string_of(full_seq_num)+ ") is greater than is_working_res.size() (" +string_of(is_working_res.size()) + ")");
427 
428  }
429 
430  //////////////////////////This should be a function of the job_parameters class/////////////////////////
431  bool
432  check_is_working_res(Size const full_seq_num, StepWiseRNA_JobParametersCOP const & job_parameters){
433 
434  using namespace ObjexxFCL;
435 
436  utility::vector1< core::Size > const & is_working_res = job_parameters->is_working_res();
437 
438  ensure_valid_full_seq_num(full_seq_num, job_parameters);
439 
440  return is_working_res[full_seq_num];
441 
442  }
443  //////////////////////////This should be a function of the job_parameters class/////////////////////////
444  core::Size
445  check_validity_and_get_working_res(Size const full_seq_num, StepWiseRNA_JobParametersCOP const & job_parameters){
446 
447  using namespace ObjexxFCL;
448 
449  std::map< core::Size, core::Size > const & full_to_sub = job_parameters->const_full_to_sub();
450 
451  std::string const & working_sequence= job_parameters->working_sequence();
452 
453  if(check_is_working_res(full_seq_num, job_parameters )==false){
454  utility_exit_with_message("full_seq_num (" + string_of(full_seq_num) + ") is NOT working_res" );
455  }
456 
457  Size const working_seq_num= full_to_sub.find(full_seq_num)->second;
458 
459  if(working_seq_num<1) utility_exit_with_message("working_seq_num (" + string_of(working_seq_num) + ") is lesser then 1");
460 
461  if(working_seq_num>working_sequence.size()) utility_exit_with_message("working_seq_num (" + string_of(working_seq_num) + ") is greater than working_sequence.size() ( " +string_of(working_sequence.size()) + ")");
462 
463  return working_seq_num;
464 
465  }
466 
467  //////////////////////////////////////////////////////////////////////////////////////
468 
469  std::map< core::Size, core::Size >
471 
472  std::map< core::Size, core::Size > full_to_input_res_map;
473 
474  for(Size n=1; n<=input_res_vector.size(); n++){
475  full_to_input_res_map[input_res_vector[n]]=n;
476  }
477 
478  return full_to_input_res_map;
479  }
480  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
481  /*
482  core::Size
483  string_to_int(std::string const string){
484  Size int_of_string; //misnomer
485  std::stringstream ss (std::stringstream::in | std::stringstream::out);
486  ss << string;
487  ss >> int_of_string;
488 
489  // std::cout << "The string " << string << " have the corresponding int value " << int_of_string << std::endl;
490 
491  return int_of_string;
492  }*/
493 
494  core::Size
495  string_to_int(std::string const input_string){
496 
497  Size int_of_string; //misnomer
498  std::stringstream ss (std::stringstream::in | std::stringstream::out);
499 
500  ss << input_string;
501 
502  if(ss.fail()) utility_exit_with_message("In string_to_real(): ss.fail() for ss << input_string | string ("+input_string+")");
503 
504  ss >> int_of_string;
505 
506  if(ss.fail()) utility_exit_with_message("In string_to_real(): ss.fail() for ss >> int_of_string | string ("+input_string+")");
507 
508  return int_of_string;
509  }
510 
511  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
512  /*
513  core::Real
514  string_to_real(std::string const string){
515  Real real_of_string;
516  std::stringstream ss (std::stringstream::in | std::stringstream::out);
517  ss << string;
518  ss >> real_of_string;
519  return real_of_string;
520 
521  //std::cout << "The string " << string << " have the corresponding real value " << real_of_string << std::endl;
522  }
523  */
524 
525  core::Real
526  string_to_real(std::string const input_string){
527 
528  Real real_of_string;
529  std::stringstream ss (std::stringstream::in | std::stringstream::out);
530 
531  ss << input_string;
532 
533  if(ss.fail()) utility_exit_with_message("In string_to_real(): ss.fail() for ss << input_string | string ("+input_string+")");
534 
535  ss >> real_of_string;
536 
537  if(ss.fail()) utility_exit_with_message("In string_to_real(): ss.fail() for ss >> real_of_string | string ("+input_string+")");
538 
539  return real_of_string;
540 
541  }
542 
543  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
544 
546  Tokenize(std::string const str, std::string delimiters){
547  using namespace std;
548 
550 
551  // Skip delimiters at beginning.
552  string::size_type lastPos = str.find_first_not_of(delimiters, 0);
553  // Find first "non-delimiter".
554  string::size_type pos = str.find_first_of(delimiters, lastPos);
555 
556  while (string::npos != pos || string::npos != lastPos){
557  // Found a token, add it to the vector.
558  tokens.push_back(str.substr(lastPos, pos - lastPos));
559  // Skip delimiters. Note the "not_of"
560  lastPos = str.find_first_not_of(delimiters, pos);
561  // Find next "non-delimiter"
562  pos = str.find_first_of(delimiters, lastPos);
563  }
564  return tokens;
565  }
566 
567  bool
568  Contain_seq_num(Size const & seq_num, utility::vector1< std::pair< core::Size, core::Size > > const & residue_pair_list){
569  for(Size j=1; j<=residue_pair_list.size(); j++){
570  if(seq_num==residue_pair_list[j].first || seq_num==residue_pair_list[j].second) {
571  return true;
572  }
573  }
574  return false;
575  }
576 
577  bool
578  Contain_seq_num(Size const & seq_num, utility::vector1< core::Size > const & residue_list){
579  for(Size j=1; j<=residue_list.size(); j++){
580  if(seq_num==residue_list[j]) {
581  return true;
582  }
583  }
584  return false;
585  }
586 
587  ////////////////////////////////////////////////////////////////////////////////////////////////////////////
588 
589  bool
591 
592  using namespace chemical;
593 
594  //Cytosine and Uracil contain 8 heavy base atoms. Adenine contains 10 heavy base atoms. Guanine contains 11 heavy base atoms.
595  if((rsd.nheavyatoms()-rsd.first_sidechain_atom()+2)<8){ //plus 2 since need to count both start and end atom.
596  utility_exit_with_message( "The rna base " + name_from_aa(rsd.aa()) + " contain lesser than 8 heavy atoms" );
597  }
598 
599  Size non_virtual_atom_count=0;
600  for ( Size atomno=rsd.first_sidechain_atom()+1; atomno<= rsd.nheavyatoms(); ++atomno) { //iterate over base atoms....+1 to exclude the O2star oxygen
601  if(rsd.atom_type(atomno).name()!="VIRT"){
602  non_virtual_atom_count++;
603  }
604  }
605 
606  bool const method_1= ( non_virtual_atom_count< 8) ? true : false;
607  bool const method_2= ( rsd.has_variant_type("VIRTUAL_RNA_RESIDUE") || rsd.has_variant_type("BULGE") ) ? true : false;
608 
609  if(method_1!=method_2){
610  Output_boolean("Is_virtual_base determination by method_1: ", method_1 );
611  Output_boolean("Is_virtual_base determination by method_2: ", method_2 );
612  std::cout << std::endl;
613  utility_exit_with_message( "Is_virtual_base determination by the two methods are not the same!" );
614  }
615 
616  return method_1;
617 
618  }
619 
620  ////////////////////////////////////////////////////////////////////////////////////////////////////////////
621  //Sept 10, 2010.OK actually don't need to past in the seq_pos...since that info is avialable in the residue object. Left the old version of the code below for backward compatibility.
622  void
623  setup_suite_atom_id_map(conformation::Residue const & rsd_1, conformation::Residue const & rsd_2, id::AtomID_Map< id::AtomID > & atom_ID_map, bool const base_only){
624 
625  //std::cout << "blah blah blah " << std::endl;
626  setup_suite_atom_id_map(rsd_1, rsd_2, rsd_1.seqpos(), rsd_2.seqpos(), atom_ID_map , base_only);
627 
628  }
629 
630  ////////////////////////////////////////////////////////////////////////////////////////////////////////////
631 
632  void
634  conformation::Residue const & rsd_2,
635  Size const res_num_1,
636  Size const res_num_2, //allow for the possibility that two poses have different sizes Jun 9, 2010
637  id::AtomID_Map< id::AtomID > & atom_ID_map,
638  bool const base_only){
639 
640  using namespace ObjexxFCL;
641 
642  if(name_from_aa( rsd_1.aa() )!=name_from_aa( rsd_2.aa())){
643  utility_exit_with_message( "rsd_1.aa()!= rsd_2.aa(). res_num_1= " + string_of(res_num_1) + " name_from_aa(rsd_1.aa())=" + name_from_aa(rsd_1.aa()) + " res_num_2= " + string_of(res_num_2) + " name_from_aa(rsd_2.aa())=" + name_from_aa(rsd_2.aa()) );
644  }
645 
646  Size const first_atom= (base_only) ? rsd_1.first_sidechain_atom()+1 : 1; //+1 to exclude the O2star oxygen
647 
648  for( Size atomno_1=first_atom; atomno_1<= rsd_1.nheavyatoms(); ++atomno_1) {
649 
650  std::string const atom_name_1=rsd_1.type().atom_name(atomno_1);
651 
652  if ( !rsd_2.has( atom_name_1 ) ) continue;
653 
654  Size const atomno_2 = rsd_2.atom_index( atom_name_1 );
655 
656  //Check
657  std::string const atom_name_2=rsd_2.type().atom_name(atomno_2);
658  if(atom_name_1!=atom_name_2){
659  utility_exit_with_message( "atom_name_1 != atom_name_2, atom_name_1= " + atom_name_1 + " atom_name_2= " + atom_name_2);
660  }
661 
662  if(rsd_1.atom_type(atomno_1).name()=="VIRT") continue; //Check for virtual atoms
663  if(rsd_2.atom_type(atomno_2).name()=="VIRT") continue; //Check for virtual atoms
664 
665  id::AtomID const id1( atomno_1, res_num_1);
666  id::AtomID const id2( atomno_2, res_num_2);
667  atom_ID_map.set( id1, id2 );
668 
669  }
670 
671  }
672 
673  ////////////////////////////////////////////////////////////////////////////////////////////////////////////
674 
675  //Easiest if just align over the base atoms
676  //Virtual types mess up numbering...This will make sure that numbering is correct.
677  void
678  setup_suite_atom_id_map(pose::Pose const & pose_1, pose::Pose const & pose_2, Size const base_res, id::AtomID_Map< id::AtomID > & atom_ID_map, bool const base_only){
679 
680  conformation::Residue const & base_rsd_1=pose_1.residue(base_res);
681  conformation::Residue const & base_rsd_2=pose_2.residue(base_res);
682 
683  setup_suite_atom_id_map(base_rsd_1, base_rsd_2, base_res, base_res, atom_ID_map, base_only);
684 
685  }
686 
687 
688  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
689  ////Dec 23, 2011.
690  void
691  setup_suite_atom_id_map(pose::Pose const & pose_1, pose::Pose const & pose_2, Size const base_res_1, Size const base_res_2, id::AtomID_Map< id::AtomID > & atom_ID_map, bool const base_only){
692 
693  conformation::Residue const & base_rsd_1=pose_1.residue(base_res_1);
694  conformation::Residue const & base_rsd_2=pose_2.residue(base_res_2);
695 
696  setup_suite_atom_id_map(base_rsd_1, base_rsd_2, base_res_1, base_res_2, atom_ID_map, base_only);
697 
698  }
699  /////////////////////////////////////////////////////////////////////////////////////////////////////////////
700 
702  create_alignment_id_map( pose::Pose & mod_pose, pose::Pose const & ref_pose, utility::vector1< core::Size > const & rmsd_residue_list, bool const base_only){
703  using namespace chemical;
704 
705  id::AtomID_Map< id::AtomID > atom_ID_map;
706 
707 // Output_boolean("atom_ID_map before initialize Is_empty? ", atom_ID_map.empty()); std::cout << std::endl;
708 
709  pose::initialize_atomid_map( atom_ID_map, mod_pose, id::BOGUS_ATOM_ID );
710 
711  if(ref_pose.sequence()!=mod_pose.sequence()){
712  std::cout << "ref_pose.sequence()= " << ref_pose.sequence() << std::endl;
713  std::cout << "mod_pose.sequence()= " << mod_pose.sequence() << std::endl;
714  utility_exit_with_message( "ref_pose.sequence()!=mod_pose.sequence()");
715  }
716 
717 
718  for ( Size seq_num = 1; seq_num <= mod_pose.total_residue(); ++seq_num ) {
719  if (mod_pose.residue(seq_num).aa() == core::chemical::aa_vrt ) continue; //Fang's electron density code.
720  if(!Contain_seq_num(seq_num, rmsd_residue_list)) continue;
721 
722  setup_suite_atom_id_map(mod_pose, ref_pose, seq_num, atom_ID_map, base_only);
723 
724  }
725 
726  return atom_ID_map;
727 
728  }
729 
730  void
731  align_poses(core::pose::Pose & moving_pose, std::string const moving_tag, core::pose::Pose const & static_pose, std::string const static_tag, utility::vector1< core::Size > const & working_best_alignment, bool const base_only){
732 
733 // using namespace core::conformation;
734 
735  bool found_non_virtual_base=false;
736  for(Size n=1; n<=working_best_alignment.size(); n++){
737  Size const seq_num=working_best_alignment[n];
738  if( Is_virtual_base(moving_pose.residue(seq_num) ) ==true || Is_virtual_base(static_pose.residue(seq_num) ) ==true ) continue;
739 
740  found_non_virtual_base=true; //ok found a non-virtual base nucleotide that can be used for alignment
741  break;
742  }
743 
744  if(found_non_virtual_base==false){
745  for(Size n=1; n<=working_best_alignment.size(); n++){
746  Size const seq_num=working_best_alignment[n];
747  std::cout << "seq_num= " << seq_num;
748  Output_boolean(" Is_virtual_base( " + moving_tag + " ):", Is_virtual_base(moving_pose.residue(seq_num) ) );
749  Output_boolean(" Is_virtual_base( " + static_tag + " ):", Is_virtual_base(static_pose.residue(seq_num) ) );
750  std::cout << std::endl;
751  }
752  std::string error_message= "Error in aligning " + moving_tag + " to " + static_tag + ". No non-virtual_base in working_best_alignment to align the poses!";
753  std::cout << error_message << std::endl;
754  utility_exit_with_message(error_message);
755  }
756 
757  //align current_pose to pose_output_list.
758  id::AtomID_Map< id::AtomID > const & alignment_atom_id_map = create_alignment_id_map(moving_pose , static_pose , working_best_alignment, base_only);
759  core::scoring::superimpose_pose( moving_pose, static_pose, alignment_atom_id_map);
760 
761 // current_pose.dump_pdb( tag+ "_current_pose_after_alignment");
762  if(check_for_messed_up_structure(moving_pose, moving_tag)==true){
763  std::string error_message= "Error in aligning " + moving_tag + " to " + static_tag + "!";
764  std::cout << error_message << std::endl;
765  utility_exit_with_message( moving_tag + " is messed up ...this is probably an alignment problem");
766  };
767  }
768 
769  void
770  output_pair_size(std::pair<Size, Size> const & pair_size){
771  std::cout << "( " << pair_size.first << ", " << pair_size.second << " ) ";
772  }
773 
774  void
775  output_pair_size_vector(utility::vector1 <std::pair<Size, Size> > const & pair_size_vector, std::string const & output_string, core::Size const spacing){
776  std::cout << std::setw(spacing) << std::left << output_string << " :";
777  for(Size n=1; n<=pair_size_vector.size(); n++){
778  output_pair_size(pair_size_vector[n]);
779  }
780  std::cout << std::endl;
781  }
782 
783  //Sort by the first element. Low number on the top of the list
784  bool
785  pair_sort_citeria(std::pair<Size, Size> pair_one, std::pair<Size, Size> pair_two){
786  return (pair_one.first < pair_two.first);
787  }
788 
789  void
790  Sort_pair_list(utility::vector1< std::pair<Size, Size> > pair_list){
791  sort(pair_list.begin(), pair_list.end(), pair_sort_citeria);
792  }
793 
794 
795  bool
797  return (seq_num_1 < seq_num_2);
798  }
799 
800  void
801  sort_seq_num_list(utility::vector1<core::Size> & seq_num_list) { //Low number on the top of the list
802  sort(seq_num_list.begin(), seq_num_list.end(), seq_num_sort_citeria);
803  }
804  void
805  Output_seq_num_list(std::string const tag, utility::vector1<core::Size> const & seq_num_list, core::Size const spacing){
806 
807  using namespace ObjexxFCL;
808  using namespace ObjexxFCL::fmt;
809 
810  std::cout << std::setw(spacing) << tag;
811 
812  utility::vector1<core::Size> sorted_seq_num_list=seq_num_list;
813  sort_seq_num_list(sorted_seq_num_list);
814 
815  Size seq_num=1;
816  for(Size n=1; n<=sorted_seq_num_list.size(); n++){
817 
818  while(seq_num<sorted_seq_num_list[n]){
819  std::cout << A(4," ");
820  seq_num++;
821  }
822  std::cout << I(4, sorted_seq_num_list[n]);
823  seq_num++;
824  }
825 
826  std::cout << std::endl;
827 
828  }
829 
830  bool
831  Is_equivalent_vector(utility::vector1<core::Size> const & seq_num_list_1, utility::vector1<core::Size> const & seq_num_list_2){
832 
833  utility::vector1<core::Size> sorted_seq_num_list_1=seq_num_list_1;
834  utility::vector1<core::Size> sorted_seq_num_list_2=seq_num_list_2;
835 
836  sort_seq_num_list(sorted_seq_num_list_1);
837  sort_seq_num_list(sorted_seq_num_list_2);
838 
839  if( sorted_seq_num_list_1.size() !=sorted_seq_num_list_2.size() ) return false;
840 
841  for(Size n=1; n<=sorted_seq_num_list_1.size(); n++){
842  if( sorted_seq_num_list_1[n]!=sorted_seq_num_list_2[n] ) return false;
843  }
844 
845  return true;
846 
847  }
848 
849  void Output_is_prepend_map(std::string const tag, std::map< core::Size, bool > const & my_map, core::Size const max_seq_num, core::Size const tag_spacing){
850 
851  using namespace ObjexxFCL;
852  using namespace ObjexxFCL::fmt;
853 
854  std::cout << std::setw(tag_spacing) << tag;
855 
856  Size spacing=4;
857 // std::cout << std::setw(30) << "Is_residue_prepend:";
858  for(Size seq_num=1; seq_num<=max_seq_num; seq_num++){
859  char prepend_char;
860  if(my_map.find(seq_num)!=my_map.end()){
861  prepend_char = (my_map.find(seq_num)->second) ? 'P' : 'A';
862  }else{
863  prepend_char = '-';
864  }
865  std::cout << std::setw(spacing) << prepend_char;
866  }
867  std::cout << std::endl;
868 
869  }
870 
871  void
872  Output_bool_list(std::string const tag, utility::vector1<Size > const & size_list, core::Size const spacing){
873  utility::vector1< bool > bool_list;
874 
875  for(Size n=1; n<=size_list.size(); n++){
876  bool_list.push_back(size_list[n]);
877  }
878  Output_bool_list(tag, bool_list, spacing);
879  }
880 
881  void
882  Output_bool_list(std::string const tag, utility::vector1<bool > const & bool_list, core::Size const spacing){
883 
884  using namespace ObjexxFCL;
885  using namespace ObjexxFCL::fmt;
886 
887  std::cout << std::setw(spacing) << tag;
888 
889  for(Size seq_num=1; seq_num <= bool_list.size(); seq_num++){
890  Output_boolean(bool_list[seq_num]);
891  }
892  std::cout << std::endl;
893  }
894 
895  void
896  Output_size_list(std::string const tag, utility::vector1< Size > const & size_list, core::Size const spacing){
897 
898  using namespace ObjexxFCL;
899  using namespace ObjexxFCL::fmt;
900 
901  std::cout << std::setw(spacing) << tag;
902 
903  for(Size seq_num=1; seq_num <= size_list.size(); seq_num++){
904  std::cout << I(4, size_list[seq_num]);
905  }
906  std::cout << std::endl;
907  }
908 
909 
910  bool
912 
913  for(Size seq_num = 1; seq_num <= pose.total_residue(); seq_num++) {
914  if (pose.residue(seq_num).aa() == core::chemical::aa_vrt ) continue; //Fang's electron density code.
915  if ( !pose.residue( seq_num ).has_variant_type( chemical::CUTPOINT_LOWER ) ) continue;
916  if ( !pose.residue( seq_num+1 ).has_variant_type( chemical::CUTPOINT_UPPER ) ) continue;
917 
918  return true;
919  }
920  return false;
921  }
922 
923 /*
924  Size
925  Get_five_prime_chain_break(pose::Pose const & pose){
926 
927  if(!Is_close_chain_break(pose)){
928  std::cout << "In StepWiseRNA_ResidueSampler::Get_five_prime_chain_break, the function should not be called! "<< std::endl;
929  exit(1);
930  };
931 
932  for(Size seq_num = 1; seq_num <= pose.total_residue(); seq_num++){
933 
934  if ( !pose.residue( seq_num ).has_variant_type( chemical::CUTPOINT_LOWER ) ) continue;
935  if ( !pose.residue( seq_num+1 ).has_variant_type( chemical::CUTPOINT_UPPER ) ) continue;
936 
937  return seq_num;
938  }
939 
940  std::cout << "In StepWiseRNA_ResidueSampler::Get_five_prime_chain_break, cannot find five_prime_chain_break" << std::endl;
941  exit(1);
942  }
943 */
944 
945  void
946  Add_harmonic_chainbreak_constraint(pose::Pose & pose, Size const five_prime_res){
947 
948  using namespace core::conformation;
949  using namespace core::scoring;
950  using namespace core::scoring::constraints;
951  using namespace core::id;
952 
953  using numeric::conversions::radians;
954 
955  Size three_prime_res=five_prime_res+1;
956 
957 
958  // From RAD.param file
959  // ICOOR_INTERNAL UPPER -175.907669 60.206192 1.607146 O3* C3* C4* , Upper is P1
960  // ICOOR_INTERNAL LOWER -64.027359 71.027062 1.593103 P O5* C5* , Lower is O3'
961  // Bug that bond distance is not the same. Rhiju suggest using 1.593103
962 
963  //Original (Amber?) parameter 1.608, 119.8, 103.4
964 
965  Real const O3_P_distance( 1.593 ); //amber=1.608
966  Real const O3_angle( 119.8 ); // 180-60.206192
967  Real const P_angle( 108.97 ); // Quite off from original (original==Amber's parameter??) ,180-71.027062
968 
969  Real const distance_stddev( 0.0659 ); // amber is 0.0659
970  Real const angle_stddev_degrees_P( 8.54 ); // amber is 8.54 (P angle), 5.73 (O3 angle) //did I made a mistake with the variable naming or is that a actual error? May 25, 2011.
971  Real const angle_stddev_degrees_O3( 5.73 ); //did I made a mistake with the variable naming or is that a actual error? May 25, 2011.
972 
973  ConstraintSetOP cst_set( pose.constraint_set()->clone() );
974  assert( cst_set ); //if ( !cst_set ) cst_set = new ConstraintSet();
975 
976 
977  FuncOP const distance_func( new HarmonicFunc( O3_P_distance, distance_stddev ) );
978  FuncOP const O3_angle_func( new HarmonicFunc( radians( O3_angle ), radians( angle_stddev_degrees_P ) ) ); //did I made a mistake with the variable naming or is that a actual error? May 25, 2011.
979  FuncOP const P_angle_func( new HarmonicFunc( radians( P_angle ), radians( angle_stddev_degrees_O3 ) ) ); //did I made a mistake with the variable naming or is that a actual error? May 25, 2011.
980 
981 
982 
983  Residue const & rsd1( pose.residue(five_prime_res) );
984  Residue const & rsd2( pose.residue(three_prime_res) );
985 
986  AtomID const C3_id( rsd1.atom_index( "C3*" ), five_prime_res);
987  AtomID const O3_id( rsd1.atom_index( "O3*" ), five_prime_res);
988  AtomID const P_id( rsd2.atom_index( "P" ), three_prime_res);
989  AtomID const O5_id( rsd2.atom_index( "O5*" ), three_prime_res);
990 
991  // distance from O3* to P
992  cst_set->add_constraint( new AtomPairConstraint( O3_id, P_id, distance_func ) );
993 
994  // angle at O3*
995  cst_set->add_constraint( new AngleConstraint( C3_id, O3_id, P_id, O3_angle_func ) );
996 
997  // angle at P
998  cst_set->add_constraint( new AngleConstraint( O3_id, P_id, O5_id, P_angle_func ) );
999 
1000  pose.constraint_set( cst_set );
1001 
1002  //std::cout << "pose_cst_set" << std::endl;
1003  //cst_set->show(std::cout);
1004 
1005  }
1006 
1007 
1008 
1009  void
1011 
1012  std::cout << std::endl;
1013 
1014  Size title_length=title.size();
1015  Size char_per_line=80;
1016  Size dash_length=char_per_line-title_length;
1017 
1018  for(Size i=1; i<=dash_length/2; i++){
1019  std::cout << "-";
1020  }
1021 
1022  std::cout << title;
1023 
1024  for(Size i=1; i<=dash_length/2; i++){
1025  std::cout << "-";
1026  }
1027 
1028  std::cout << std::endl;
1029 
1030  }
1031 
1032 
1033  void
1034  Output_fold_tree_info(kinematics::FoldTree const & fold_tree, std::string const pose_name){
1035 
1036  std::cout << "fold tree of " << pose_name << ": " << std::endl;
1037  for(int i=1; i<=fold_tree.num_cutpoint(); i++){
1038  std::cout << std::setw(30) << "jump_point_num= " << i;
1039  std::cout << " cutpoint= " << fold_tree.cutpoint(i);
1040  std::cout << " 5' jump_point= " << fold_tree.jump_point( 1, i ) << "," << fold_tree.upstream_atom(i);
1041  std::cout << " 3' jump_point= " << fold_tree.jump_point( 2, i ) << "," << fold_tree.downstream_atom(i) << std::endl;
1042  }
1043  }
1044 
1045  void
1047  Output_fold_tree_info(pose.fold_tree(), pose_name);
1048  }
1049 
1050  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1051  //April 15, 2012: Umm should switch to utility::file::file_exists( full_filename )!
1052 
1053  bool
1054  file_exists(std::string const & file_name){
1055 
1056  std::ifstream my_file;
1057 
1058  my_file.open(file_name.c_str());
1059 
1060  bool const file_exist=my_file.is_open();
1061 
1062  my_file.close();
1063 
1064  return file_exist;
1065 
1066  }
1067 
1068  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1069  void
1070  remove_file(std::string const & file_name){
1071 
1072  //Note that remove is part of #include <stdio.h>
1073  //perror: interprets the value of the global variable errno into a string and prints that string to stderr
1074 
1075  using namespace ObjexxFCL;
1076 
1077  if(file_exists(file_name)==false){
1078  utility_exit_with_message("file_name (" + file_name + ") doesn't exist!");
1079  }
1080 
1081  int const retcode=std::remove(file_name.c_str());
1082 
1083  if(retcode!=0){
1084  std::string const error_message="The following error occurs when attempting to remove file_name ("+file_name+")";
1085 
1086  std::perror(error_message.c_str());
1087  utility_exit_with_message( error_message + ", retcode= " + string_of(retcode));
1088  }
1089 
1090  }
1091 
1092  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1093 
1094  void
1096 
1097  Size const spacing=10;
1098 
1099  std::cout << std::setw(18) << "Torsions= ";
1100  std::cout << std::setw(spacing)<< rotamer[1] << " ";
1101  std::cout << std::setw(spacing)<< rotamer[2] << " ";
1102  std::cout << std::setw(spacing)<< rotamer[3] << " ";
1103  std::cout << std::setw(spacing)<< rotamer[4] << " ";
1104  std::cout << std::setw(spacing)<< rotamer[5] << " ";
1105  std::cout << std::setw(spacing)<< rotamer[6] << " ";
1106  std::cout << std::setw(spacing)<< rotamer[7] << " ";
1107  std::cout << std::setw(spacing)<< rotamer[8] << " ";
1108  std::cout << std::setw(spacing)<< rotamer[9] << " ";
1109  std::cout << std::setw(spacing)<< rotamer[10] << " ";
1110  std::cout << std::setw(spacing)<< rotamer[11] << " ";
1111  std::cout << std::setw(spacing)<< rotamer[12] << " ";
1112  std::cout << std::setw(spacing)<< rotamer[13] << " ";
1113  std::cout << std::endl;
1114 
1115  }
1116 
1117 
1118  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1119  void
1121 
1122  for (core::Size i = 1; i <= pose.total_residue(); i++){
1123  if (pose.residue(i).aa() == core::chemical::aa_vrt ) continue; //Fang's electron density code
1124  pose::add_variant_type_to_pose_residue( pose, "VIRTUAL_O2STAR_HYDROGEN", i);
1125  }
1126  }
1127 
1128  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1129  bool
1131 
1132  for(Size i=1; i<=pose.total_residue(); i++){
1133  if (pose.residue(i).aa() == core::chemical::aa_vrt ) continue; //Fang's electron density code
1134  if ( pose.residue_type( i ).has_variant_type( "VIRTUAL_O2STAR_HYDROGEN" ) ){
1135  pose::remove_variant_type_from_pose_residue( pose, "VIRTUAL_O2STAR_HYDROGEN", i);
1136  }
1137  }
1138  return true;
1139  }
1140 
1141  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1142  //This now works for any rebuild residue.
1143  Real
1144  suite_rmsd(pose::Pose const & pose1, pose::Pose const & pose2, Size const & moving_res_num, bool const prepend_res, bool const ignore_virtual_atom){
1145 
1146  Size atom_count=0;
1147  Real sum_sd=0;
1148 
1149  suite_square_deviation(pose1, pose2, prepend_res, moving_res_num, moving_res_num, atom_count, sum_sd, false, ignore_virtual_atom);
1150 
1151  sum_sd=sum_sd/(atom_count);
1152  Real rmsd=sqrt(sum_sd);
1153 
1154  if(atom_count==0) rmsd=0.0; //special case...implement this on June_11, 2010, took me a whole day to debug this since buggy only on Biox compiler!
1155 
1156  return (std::max(0.01, rmsd));
1157 
1158  }
1159 
1160  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1161  //Ok this function should only be called if pose contain full sequence.
1162  //This one include edge phosphates
1163 
1164  core::Real
1165  full_length_rmsd_over_residue_list(pose::Pose const & pose1, pose::Pose const & pose2, utility::vector1 < Size > const & residue_list, std::string const & full_sequence, bool const verbose, bool const ignore_virtual_atom){
1166 
1167  using namespace ObjexxFCL;
1168 
1169 
1170  if( pose1.sequence()!=full_sequence ){
1171  std::cout << "pose1.sequence()= " << pose1.sequence() << std::endl;
1172  std::cout << "pose2.sequence()= " << pose2.sequence() << std::endl;
1173  std::cout << "full_sequence= " << full_sequence << std::endl;
1174  utility_exit_with_message( "pose1.sequence()!=full_sequence" );
1175  }
1176 
1177  if( pose2.sequence()!=full_sequence ){
1178  std::cout << "pose1.sequence()= " << pose1.sequence() << std::endl;
1179  std::cout << "pose2.sequence()= " << pose2.sequence() << std::endl;
1180  std::cout << "full_sequence= " << full_sequence << std::endl;
1181  utility_exit_with_message( "pose2.sequence()!=full_sequence" );
1182  }
1183 
1184  Size const total_res=pose1.total_residue();
1185 
1186 /*
1187  //OK check that input pose is full_length.
1188  if(pose1.total_residue()!=pose2.total_residue()){
1189  std::cout << "pose1.total_residue()= " << pose1.total_residue() << std::endl;
1190  std::cout << "pose2.total_residue()= " << pose2.total_residue() << std::endl;
1191  utility_exit_with_message( "pose1.total_residue()!=pose2.total_residue()");
1192  }
1193 
1194 
1195  //if(full_to_sub.size()!=pose1.total_residue()){
1196  return 99.99; //not full length pose!
1197  //std::cout << "full_to_sub.size()= " << full_to_sub.size() << std::endl;
1198  //std::cout << "pose1.total_residue()= " << pose1.total_residue() << std::endl;
1199  //utility_exit_with_message( "full_to_sub.size()!=pose1.total_residue()");
1200  }
1201 
1202  for(Size full_seq_num=1; full_seq_num<=full_to_sub.size(); full_seq_num++){
1203 
1204 
1205  if(full_to_sub.count(full_seq_num)!=1){
1206  utility_exit_with_message( "full_to_sub.count(" +string_of(full_seq_num) + ")!=1");
1207  }
1208 
1209  Size const map_seq_num=full_to_sub.find(full_seq_num)->second;
1210 
1211  if(full_seq_num!=map_seq_num){
1212  return 88.88; //not full length pose!
1213  //std::cout << "full_seq_num= " << full_seq_num << std::endl;
1214  //std::cout << "map_seq_num= " << map_seq_num << std::endl;
1215  //utility_exit_with_message( "full_seq_num!=map_seq_num)");
1216  }
1217  }
1218 */
1219 
1220  if(verbose){
1221  Output_title_text("Enter full_length_rmsd_over_residue_list function");
1222  Output_boolean("ignore_virtual_atom= ",ignore_virtual_atom); std::cout << std::endl;
1223  Output_seq_num_list("residue_list= ", residue_list, 30);
1224  }
1225 
1226  Size atom_count=0;
1227  Real sum_sd=0;
1228 
1229  for(Size i=1; i<=residue_list.size(); i++){
1230 
1231  Size const full_seq_num= residue_list[i];
1232 
1233  bool Is_prepend=false;
1234  bool both_pose_res_is_virtual=false;
1235 
1236  if(pose1.residue(full_seq_num).has_variant_type("VIRTUAL_RNA_RESIDUE") && pose2.residue(full_seq_num).has_variant_type("VIRTUAL_RNA_RESIDUE")){
1237  both_pose_res_is_virtual=true;
1238  }
1239 
1240  if( (full_seq_num+1)<=total_res){
1241  if(pose1.residue(full_seq_num).has_variant_type("VIRTUAL_RNA_RESIDUE")){
1242  if(pose1.residue(full_seq_num+1).has_variant_type("VIRTUAL_RNA_RESIDUE_UPPER")==false){ //consistency_check
1243  utility_exit_with_message( "pose1's full_seq_num= " + string_of(full_seq_num) + " is a virtual res but seq_num+1 is not a virtual_res_upper!" );
1244  }
1245  }
1246 
1247  if(pose2.residue(full_seq_num).has_variant_type("VIRTUAL_RNA_RESIDUE")){
1248  if(pose2.residue(full_seq_num+1).has_variant_type("VIRTUAL_RNA_RESIDUE_UPPER")==false){ //consistency_check
1249  utility_exit_with_message( "pose2's full_seq_num= " + string_of(full_seq_num) + " is a virtual res but seq_num+1 is not a virtual_res_upper!" );
1250  }
1251  }
1252  }
1253 
1254  if(verbose){
1255  std::cout << "full_seq_num= " << full_seq_num;
1256  Output_boolean(" Is_prepend= ",Is_prepend);
1257  Output_boolean(" both_pose_res_is_virtual= ",both_pose_res_is_virtual); std::cout << std::endl;
1258  }
1259 
1260  if(both_pose_res_is_virtual) continue;
1261 
1262  //add atom in the suites to atom_count
1263  //add sd of each atom to sum_sd
1264  suite_square_deviation(pose1, pose2, Is_prepend, full_seq_num, full_seq_num, atom_count, sum_sd, verbose, ignore_virtual_atom);
1265 
1266  if( ( (full_seq_num+1)<=total_res) && Contain_seq_num(full_seq_num+1, residue_list)==false){
1267 
1268  if(verbose) std::cout << "Phosphate_edge_res_(full_seq_num+1)= " << full_seq_num+1 << std::endl;
1269 
1270  phosphate_square_deviation(pose1, pose2, full_seq_num+1, full_seq_num+1, atom_count, sum_sd, verbose, ignore_virtual_atom);
1271  }
1272 
1273  }
1274 
1275 
1276  sum_sd=sum_sd/(atom_count);
1277  Real rmsd=sqrt(sum_sd);
1278 
1279  if(atom_count==0) rmsd=0.0; //special case...implement this on May 5, 2010
1280 
1281  if(verbose){
1282  std::cout << "sum_sd= " << sum_sd << " atom_count= " << atom_count << " rmsd= " << rmsd << std::endl;
1283  Output_title_text("Exit In full_length_rmsd_over_residue_list function");
1284  }
1285 
1286  return (std::max(0.01, rmsd));
1287 
1288  }
1289  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1290  Real
1291  rmsd_over_residue_list(pose::Pose const & pose1, pose::Pose const & pose2, utility::vector1 < Size > const & residue_list, std::map< core::Size, core::Size > const & full_to_sub, std::map< core::Size, bool > const & Is_prepend_map, bool const verbose, bool const ignore_virtual_atom){
1292 
1293  if(verbose){
1294  Output_title_text("Enter rmsd_over_residue_list function");
1295  Output_boolean("ignore_virtual_atom= ",ignore_virtual_atom); std::cout << std::endl;
1296  Output_seq_num_list("residue_list= ", residue_list, 30);
1297  }
1298 
1299 
1300  Size atom_count=0;
1301  Real sum_sd=0;
1302 
1303  for(Size i=1; i<=residue_list.size(); i++){
1304 
1305  Size const full_seq_num= residue_list[i];
1306  Size const seq_num=full_to_sub.find(full_seq_num)->second;
1307  bool Is_prepend=Is_prepend_map.find(full_seq_num)->second;
1308  bool both_pose_res_is_virtual=false;
1309  if(pose1.residue(seq_num).has_variant_type("VIRTUAL_RNA_RESIDUE") && pose2.residue(seq_num).has_variant_type("VIRTUAL_RNA_RESIDUE")){
1310  both_pose_res_is_virtual=true;
1311  }
1312 
1313 
1314  if(verbose){
1315  std::cout << "Full_seq_num= " << full_seq_num << " partial_seq_num= " << seq_num;
1316  Output_boolean(" Is_prepend= ",Is_prepend); Output_boolean(" both_pose_res_is_virtual= ",both_pose_res_is_virtual); std::cout << std::endl;
1317  }
1318 
1319  if(both_pose_res_is_virtual) continue;
1320 
1321  //add atom in the suites to atom_count
1322  //add sd of each atom to sum_sd
1323  suite_square_deviation(pose1, pose2, Is_prepend, seq_num, seq_num, atom_count, sum_sd, verbose, ignore_virtual_atom);
1324 
1325  }
1326 
1327  sum_sd=sum_sd/(atom_count);
1328  Real rmsd=sqrt(sum_sd);
1329 
1330  if(atom_count==0) rmsd=0.0; //special case...implement this on May 5, 2010
1331 
1332  if(verbose){
1333  std::cout << "sum_sd= " << sum_sd << " atom_count= " << atom_count << " rmsd= " << rmsd << std::endl;
1334  Output_title_text("Exit rmsd_over_residue_list function");
1335  }
1336 
1337  return (std::max(0.01, rmsd));
1338  }
1339 
1340  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1341 
1342 
1343  Real
1344  rmsd_over_residue_list(pose::Pose const & pose1, pose::Pose const & pose2, StepWiseRNA_JobParametersCOP job_parameters_, bool const ignore_virtual_atom){
1345 
1346  utility::vector1 < core::Size > const & rmsd_res_list = job_parameters_->rmsd_res_list();
1347  std::map< core::Size, core::Size > const & full_to_sub = job_parameters_->const_full_to_sub();
1348  std::map< core::Size, bool > const & Is_prepend_map = job_parameters_->Is_prepend_map();
1349 
1350  return rmsd_over_residue_list( pose1, pose2, rmsd_res_list, full_to_sub, Is_prepend_map, false /*verbose*/, ignore_virtual_atom);
1351 
1352  }
1353 
1354  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1355  void
1356  Print_heavy_atoms(Size const & suite_num_1, Size const & suite_num_2, pose::Pose const & pose1, pose::Pose const & pose2){
1357 
1358  using namespace conformation;
1359  Size num_atoms;
1360 
1361  num_atoms=std::max(pose1.residue(suite_num_1).nheavyatoms(), pose2.residue(suite_num_2).nheavyatoms());
1362 
1363  std::cout << "num_atoms: " << num_atoms << std::endl;
1364 
1365  for(Size n=1; n<= num_atoms; n++){
1366 
1367  std::cout << " atom num = " << n;
1368  std::cout << " atom_name of the pose1 " << pose1.residue(suite_num_1).atom_name(n);
1369  std::cout << " atom_name of the pose2 " << pose2.residue(suite_num_2).atom_name(n) << std::endl;
1370 
1371  }
1372  }
1373 //
1374 
1375  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1376  Size
1377  Get_num_side_chain_atom_from_res_name(chemical::AA const & res_aa, bool const verbose){
1378 
1379  Size num_side_chain_atom;
1380 
1381  if(name_from_aa(res_aa)=="RAD") {
1382  if(verbose) std::cout << "name_from_aa: RAD" << std::endl;
1383  num_side_chain_atom=11;
1384  } else if(name_from_aa(res_aa)=="RCY") {
1385  if(verbose) std::cout << "name_from_aa: RCY" << std::endl;
1386  num_side_chain_atom=9;
1387  } else if(name_from_aa(res_aa)=="RGU") {
1388  if(verbose) std::cout << "name_from_aa: RGU" << std::endl;
1389  num_side_chain_atom=12;
1390  } else if(name_from_aa(res_aa)=="URA") {
1391  if(verbose) std::cout << "name_from_aa: URA" << std::endl;
1392  num_side_chain_atom=9;
1393  } else {
1394  std::cout << "Error, cannot identify residue type" << std::endl;
1395  num_side_chain_atom=0;
1396  exit (1);
1397  }
1398 
1399  return num_side_chain_atom;
1400  }
1401 
1402  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1403  Real
1404  atom_square_deviation(conformation::Residue const & rsd_1, conformation::Residue const & rsd_2, Size const & atomno_1, Size const & atomno_2, bool verbose){
1405 
1406 
1407 
1408  //////////////Might take this out later if it significantly slow down the code///////////////
1409  std::string const & atom_name_1=rsd_1.type().atom_name(atomno_1);
1410  std::string const & atom_name_2=rsd_2.type().atom_name(atomno_2);
1411 
1412  //This can be turned on for debugging, but by default is mod out since string comparison might be slow Parin Jan 28, 2009
1413  if(atom_name_1!=atom_name_2){
1414  utility_exit_with_message( "atom_name_1 != atom_name_2, atom_name_1= " + atom_name_1 + " atom_name_2= " + atom_name_2);
1415  }
1416 
1417 // if(rsd_1.atom_type(atomno_1).name()=="VIRT" || rsd_2.atom_type(atomno_2).name()=="VIRT") {
1418 // std::cout << "atom_name_1= " << atom_name_1 << " atom_name_2= " << atom_name_2 << std::endl;
1419 // utility_exit_with_message( "rsd_1.atom_type(n).name()==\"VIRT\" || rsd_2.atom_type(n).name()==\"VIRT\" =TRUE!");
1420 // }
1421  ////////////////////////////////////////////////////////////////////////////////////////////////
1422 
1423  Distance const dist_squared = (rsd_1.xyz( atomno_1) - rsd_2.xyz( atomno_2)).length_squared();
1424 
1425 
1426  if(verbose){
1427  std::cout << " atom_name of the atom1= " << atom_name_1 << " " << rsd_1.seqpos();
1428  std::cout << " atom_name of the atom2= " << atom_name_2 << " " << rsd_2.seqpos();
1429  std::cout << " Dist_squared= " << dist_squared << std::endl;
1430  }
1431 
1432  return dist_squared;
1433 
1434  }
1435 
1436  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1437  //Create on Sept 24, 2010...should really integrate these rmsd square deviation functions....cause now it is just copy and paste copy
1438 
1439  void
1440  base_atoms_square_deviation(pose::Pose const & pose1, pose::Pose const & pose2, Size const & moving_res_1, Size const & moving_res_2, Size& atom_count, Real& sum_sd, bool verbose, bool const ignore_virtual_atom){
1441 
1442 
1443  chemical::AA const & res_aa = pose1.residue(moving_res_1).aa();
1444  chemical::AA const & res_aa2 = pose2.residue(moving_res_2).aa();
1445 
1446  if(res_aa!=res_aa2) utility_exit_with_message( "res_aa (" + name_from_aa(res_aa) + ")!=res_aa2 (" + name_from_aa(res_aa2) + ") " );
1447 
1448  Size const first_sidechain_atom1=pose1.residue(moving_res_1).first_sidechain_atom();
1449  Size const first_sidechain_atom2=pose2.residue(moving_res_2).first_sidechain_atom();
1450 
1451  Size const num_side_chain_atom=Get_num_side_chain_atom_from_res_name(res_aa, verbose);
1452 
1453  if ( verbose ) std::cout << " MOVING_RES_1: " << moving_res_1 << " MOVING_RES_2: " << moving_res_2 << std::endl;
1454 
1455  //Need to use num_side_chain_atom from pose1 since a silly bug in Rosetta miscalculate num_heavy_atom by considering
1456  //the virtaul O2star hydrogen to be heavy_atom when it is set to virtual in the current_pose_screen
1457  for( Size n = 1; n<= num_side_chain_atom; n++){ //This INCLUDE the O2star oxygen
1458 
1459  Size const atomno_1=(n-1)+first_sidechain_atom1;
1460  Size const atomno_2=(n-1)+first_sidechain_atom2;
1461 
1462  conformation::Residue const & rsd_1=pose1.residue(moving_res_1);
1463  conformation::Residue const & rsd_2=pose2.residue(moving_res_2);
1464 
1465  if(rsd_1.type().atom_name(atomno_1) ==" O2*") continue; //Exclude the O2star oxygen
1466  if(rsd_2.type().atom_name(atomno_2) ==" O2*") continue; //Exclude the O2star oxygen
1467 
1468  if(ignore_virtual_atom){
1469  if(rsd_1.atom_type(atomno_1).name()=="VIRT" || rsd_2.atom_type(atomno_2).name()=="VIRT") continue;
1470  }
1471 
1472  if(rsd_1.atom_type(atomno_1).name()=="VIRT" && rsd_2.atom_type(atomno_2).name()=="VIRT") { //Change this to "AND" on Apr 5
1473 // std::cout << "Both atoms are VIRTUAL! moving_res_1= " << moving_res_1 << " moving_res_2= " << moving_res_2 << " atomno_1= " << atomno_1 << " atomno_2= " << atomno_2 << std::endl;
1474  continue;
1475  }
1476 
1477  atom_count++;
1478  sum_sd=sum_sd+atom_square_deviation(rsd_1, rsd_2, atomno_1, atomno_2, verbose);
1479  }
1480  }
1481 
1482  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1483  void
1484  phosphate_square_deviation(pose::Pose const & pose1, pose::Pose const & pose2, Size const & moving_res_1, Size const & moving_res_2, Size& atom_count, Real& sum_sd, bool verbose, bool const ignore_virtual_atom){
1485 
1486 
1487  chemical::AA const & res_aa = pose1.residue(moving_res_1).aa();
1488  chemical::AA const & res_aa2 = pose2.residue(moving_res_2).aa();
1489 
1490  if(res_aa!=res_aa2) utility_exit_with_message( "res_aa (" + name_from_aa(res_aa) + ")!=res_aa2 (" + name_from_aa(res_aa2) + ") " );
1491 
1492  if ( verbose ) std::cout << " MOVING_RES_1: " << moving_res_1 << " MOVING_RES_2: " << moving_res_2 << std::endl;
1493 
1494  for( Size atomno = 1; atomno <= 4; atomno++){
1495 
1496  conformation::Residue const & rsd_1=pose1.residue(moving_res_1);
1497  conformation::Residue const & rsd_2=pose2.residue(moving_res_2);
1498 
1499  if(ignore_virtual_atom){
1500  if(rsd_1.atom_type(atomno).name()=="VIRT" || rsd_2.atom_type(atomno).name()=="VIRT") continue;
1501  }
1502 
1503  if(rsd_1.atom_type(atomno).name()=="VIRT" && rsd_2.atom_type(atomno).name()=="VIRT") continue;
1504 
1505  atom_count++;
1506  sum_sd=sum_sd+atom_square_deviation(rsd_1, rsd_2, atomno, atomno, verbose);
1507 
1508  }
1509 
1510  }
1511 
1512  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1513 
1514  core::Real
1515  phosphate_base_phosphate_rmsd(pose::Pose const & pose1, pose::Pose const & pose2, Size const & moving_res_num, bool const ignore_virtual_atom){
1516 
1517  Size atom_count=0;
1518  Real sum_sd=0;
1519 
1520  phosphate_base_phosphate_square_deviation(pose1, pose2, moving_res_num, moving_res_num, atom_count, sum_sd, false, ignore_virtual_atom);
1521 
1522  sum_sd=sum_sd/(atom_count);
1523  Real rmsd=sqrt(sum_sd);
1524 
1525  if(atom_count==0) rmsd=0.0; //special case...implement this on June_11, 2010, took me a whole day to debug this since buggy only on Biox compiler!
1526 
1527  return (std::max(0.01, rmsd));
1528 
1529  }
1530 
1531  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1532  void
1533  phosphate_base_phosphate_square_deviation(pose::Pose const & pose1, pose::Pose const & pose2, Size const & moving_res_1, Size const & moving_res_2, Size& atom_count, Real& sum_sd, bool verbose, bool const ignore_virtual_atom){
1534 
1535  chemical::AA const & res_aa = pose1.residue(moving_res_1).aa();
1536  chemical::AA const & res_aa2 = pose2.residue(moving_res_2).aa();
1537 
1538  if(res_aa!=res_aa2) utility_exit_with_message( "res_aa (" + name_from_aa(res_aa) + ")!=res_aa2 (" + name_from_aa(res_aa2) + ") " );
1539 
1540  Size const first_sidechain_atom1=pose1.residue(moving_res_1).first_sidechain_atom();
1541  Size const first_sidechain_atom2=pose2.residue(moving_res_2).first_sidechain_atom();
1542 
1543  Size const num_side_chain_atom=Get_num_side_chain_atom_from_res_name(res_aa, verbose);
1544 
1545  if ( verbose ) std::cout << " MOVING_RES_1: " << moving_res_1 << " MOVING_RES_2: " << moving_res_2 << std::endl;
1546 
1547  Size const num_heavy_backbone_atoms=11; //RNA contain 11 heavy backbone atoms.
1548 
1549  for( Size atomno = 1; atomno <= num_heavy_backbone_atoms; atomno++){
1550 
1551  Size const res_count = (atomno <=4) ? 2 : 1; //atom 1-4 are " P ", " O1P", " O2P" and " O5*"
1552 
1553  for(Size ii=1; ii<res_count; ii++){
1554 
1555  Size const res_num_1= moving_res_1 + (ii-1);
1556  Size const res_num_2= moving_res_2 + (ii-1);
1557 
1558  conformation::Residue const & rsd_1=pose1.residue(res_num_1);
1559  conformation::Residue const & rsd_2=pose2.residue(res_num_2);
1560 
1561  if(ignore_virtual_atom){
1562  if(rsd_1.atom_type(atomno).name()=="VIRT" || rsd_2.atom_type(atomno).name()=="VIRT") continue;
1563  }
1564 
1565  if(rsd_1.atom_type(atomno).name()=="VIRT" && rsd_2.atom_type(atomno).name()=="VIRT") continue;
1566 
1567  atom_count++;
1568  sum_sd=sum_sd+atom_square_deviation(rsd_1, rsd_2, atomno, atomno, verbose);
1569  }
1570  }
1571 
1572  //Need to use num_side_chain_atom from pose1 since a silly bug in Rosetta miscalculate num_heavy_atom by considering
1573  //the virtaul O2star hydrogen to be heavy_atom when it is set to virtual in the current_pose_screen
1574  for( Size n = 1; n<= num_side_chain_atom; n++){ //INCLUDE the O2star oxygen
1575 
1576  Size const atomno_1=(n-1)+first_sidechain_atom1;
1577  Size const atomno_2=(n-1)+first_sidechain_atom2;
1578 
1579  conformation::Residue const & rsd_1=pose1.residue(moving_res_1);
1580  conformation::Residue const & rsd_2=pose2.residue(moving_res_2);
1581 
1582  if(ignore_virtual_atom){
1583  if(rsd_1.atom_type(atomno_1).name()=="VIRT" || rsd_2.atom_type(atomno_2).name()=="VIRT") continue;
1584  }
1585 
1586  if(rsd_1.atom_type(atomno_1).name()=="VIRT" && rsd_2.atom_type(atomno_2).name()=="VIRT") { //Change this to "AND" on Apr 5
1587 // std::cout << "Both atoms are VIRTUAL! moving_res_1= " << moving_res_1 << " moving_res_2= " << moving_res_2 << " atomno_1= " << atomno_1 << " atomno_2= " << atomno_2 << std::endl;
1588  continue;
1589  }
1590 
1591  atom_count++;
1592  sum_sd=sum_sd+atom_square_deviation(rsd_1, rsd_2, atomno_1, atomno_2, verbose);
1593  }
1594 
1595  }
1596 
1597  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1598 
1599 
1600  // Could get the atom_num using the atom_name but I don't think this will be fast Size atom_P = rsd.atom_index( " P " ); Jan 28, 2010 Parin S////////////////////////////////////////////
1601 
1602  void
1603  suite_square_deviation(pose::Pose const & pose1, pose::Pose const & pose2, bool const & prepend_res, Size const & moving_res_1, Size const & moving_res_2, Size& atom_count, Real& sum_sd, bool verbose, bool const ignore_virtual_atom){
1604 
1605  chemical::AA const & res_aa = pose1.residue(moving_res_1).aa();
1606  chemical::AA const & res_aa2 = pose2.residue(moving_res_2).aa();
1607 
1608  if(res_aa!=res_aa2) utility_exit_with_message( "res_aa (" + name_from_aa(res_aa) + ")!=res_aa2 (" + name_from_aa(res_aa2) + ") " );
1609 
1610  Size const first_sidechain_atom1=pose1.residue(moving_res_1).first_sidechain_atom();
1611  Size const first_sidechain_atom2=pose2.residue(moving_res_2).first_sidechain_atom();
1612 
1613  Size const num_side_chain_atom=Get_num_side_chain_atom_from_res_name(res_aa, verbose);
1614 
1615  if(false && verbose){
1616  std::cout << " residue type1= " << res_aa << " residue type2= " << res_aa2;
1617  std::cout << " 1st_side_atom1= " << first_sidechain_atom1;
1618  std::cout << " 1st_side_atom2= " << first_sidechain_atom2;
1619  std::cout << " nheavyatoms1= " << pose1.residue(moving_res_1).nheavyatoms();
1620  std::cout << " nheavyatoms2= " << pose2.residue(moving_res_2).nheavyatoms() << std::endl;
1621  std::cout << " num_side_chain_atom = " << num_side_chain_atom << std::endl;
1622  Print_heavy_atoms(moving_res_1, moving_res_2, pose1, pose2);
1623  }
1624 
1625  if ( verbose ) std::cout << " MOVING_RES_1: " << moving_res_1 << " MOVING_RES_2: " << moving_res_2 << " PREPEND? " << prepend_res << std::endl;
1626 
1627  Size const num_heavy_backbone_atoms=11; //RNA contain 11 heavy backbone atoms.
1628 
1629  for( Size atomno = 1; atomno <= num_heavy_backbone_atoms; atomno++){
1630 
1631  //atom 1-4 are " P ", " O1P", " O2P" and " O5*"
1632  Size const res_num_1= (prepend_res && atomno <= 4) ? moving_res_1 + 1: moving_res_1;
1633  Size const res_num_2= (prepend_res && atomno <= 4) ? moving_res_2 + 1: moving_res_2;
1634 
1635 
1636  conformation::Residue const & rsd_1=pose1.residue(res_num_1);
1637  conformation::Residue const & rsd_2=pose2.residue(res_num_2);
1638 
1639  if(ignore_virtual_atom){
1640  if(rsd_1.atom_type(atomno).name()=="VIRT" || rsd_2.atom_type(atomno).name()=="VIRT") continue;
1641  }
1642 
1643  if(rsd_1.atom_type(atomno).name()=="VIRT" && rsd_2.atom_type(atomno).name()=="VIRT") {
1644 // std::cout << "Both atoms are VIRTUAL! res_num_1= " << res_num_1 << " res_num_2= " << res_num_2 << " atomno= " << atomno << std::endl;
1645  continue;
1646  }
1647 
1648  atom_count++;
1649  sum_sd=sum_sd+atom_square_deviation(rsd_1, rsd_2, atomno, atomno, verbose);
1650  }
1651 
1652  //Need to use num_side_chain_atom from pose1 since a silly bug in Rosetta miscalculate num_heavy_atom by considering
1653  //the virtaul O2star hydrogen to be heavy_atom when it is set to virtual in the current_pose_screen
1654  for( Size n = 1; n<= num_side_chain_atom; n++){ //INCLUDE the O2star oxygen
1655 
1656 
1657  Size const atomno_1=(n-1)+first_sidechain_atom1;
1658  Size const atomno_2=(n-1)+first_sidechain_atom2;
1659 
1660  conformation::Residue const & rsd_1=pose1.residue(moving_res_1);
1661  conformation::Residue const & rsd_2=pose2.residue(moving_res_2);
1662 
1663  if(ignore_virtual_atom){
1664  if(rsd_1.atom_type(atomno_1).name()=="VIRT" || rsd_2.atom_type(atomno_2).name()=="VIRT") continue;
1665  }
1666 
1667  if(rsd_1.atom_type(atomno_1).name()=="VIRT" && rsd_2.atom_type(atomno_2).name()=="VIRT") { //Change this to "AND" on Apr 5
1668  // std::cout << "Both atoms are VIRTUAL! moving_res_1= " << moving_res_1 << " moving_res_2= " << moving_res_2 << " atomno_1= " << atomno_1 << " atomno_2= " << atomno_2 << std::endl;
1669  continue;
1670  }
1671 
1672  atom_count++;
1673  sum_sd=sum_sd+atom_square_deviation(rsd_1, rsd_2, atomno_1, atomno_2, verbose);
1674  }
1675 
1676 
1677  // O1P<-->O2P check on phosphate positions closest to fixed side
1678  if(verbose && false){
1679  Size const res_num_1= (prepend_res) ? moving_res_1 + 1: moving_res_1;
1680  Size const res_num_2= (prepend_res) ? moving_res_2 + 1: moving_res_2;
1681  Distance dist_squared = (pose1.residue(res_num_1).xyz( 2 ) - pose2.residue(res_num_2).xyz( 3 ) ).length_squared();
1682  std::cout << " atom_name of the pose1= " << pose1.residue(res_num_1).atom_name(2) << " " << res_num_1;
1683  std::cout << " atom_name of the pose2= " << pose2.residue(res_num_2).atom_name(3) << " " << res_num_2;
1684  std::cout << " Switch Phosphate1= " << " dist_squared= " << dist_squared << std::endl;
1685  dist_squared = (pose1.residue(res_num_1).xyz( 3 ) - pose2.residue(res_num_2).xyz( 2 ) ).length_squared();
1686  std::cout << " atom_name of the pose1= " << pose1.residue(res_num_1).atom_name(3) << " " << res_num_1;
1687  std::cout << " atom_name of the pose2= " << pose2.residue(res_num_2).atom_name(2) << " " << res_num_2;
1688  std::cout << " Switch Phosphate2= " << " dist_squared= " << dist_squared << std::endl;
1689  }
1690 
1691 
1692  }
1693  /////////////////////////////////////////////////////////////////////////////////////////////////
1694 
1695  //WARNING THIS FUNCTION ASSUME THAT THE GAP RESIDUES DOESN'T EXIST!!!COULD LEAD TO SERIOUS ERROR! Sept 17, 2010
1696  //This function is called when the chain_break gap_size = 0 or 1
1697  bool
1698  Check_chain_closable(pose::Pose const & pose, Size const five_prime_chain_break_res, Size const gap_size ){
1699 
1700  if ( gap_size > 1 ) return true;
1701 
1702  //Use to call Calculate_dist_to_close_chain function, but that requires rebuild_unit_struct
1703  Size const three_prime_chain_break_res= five_prime_chain_break_res + 1; //THIS ASSUME THAT GAP RESIDUES DOESN'T EXIST
1704 
1705  return Check_chain_closable(pose.residue(three_prime_chain_break_res).xyz("C5*") , pose.residue(five_prime_chain_break_res).xyz("O3*"), gap_size);
1706 
1707  }
1708 
1709  /////////////////////////////////////////////////////////////////////////////////////////////////
1710  bool
1712 
1713  //Two possibilities
1714  //1. xyz_1-> five_prime_O3_xyz && xyz_2->three_prime_C5_xyz
1715  //2. xyz_2-> five_prime_O3_xyz && xyz_1->three_prime_C5_xyz
1716 
1717  using namespace ObjexxFCL;
1718 
1719  Distance const dist_square=(xyz_1 - xyz_2).length_squared();
1720 
1721  if ( gap_size > 1 ){ //new option Sept 18, 2010, most useful for long loop mode...
1722 
1723  Real const dist_cutoff=O3I_C5IPLUS2_MAX_DIST + ((gap_size-1)*(C5I_C5I_PLUS_ONE_MAX_DIST));
1724 
1725  //C5I_C5I_PLUS_ONE_MAX_DIST is the right choice and NOT O3I_O3I_PLUS_ONE_MAX_DIST, since we want to go from O3I to C5(I+gapsize+1)
1726  //Also C5I_C5I_PLUS_ONE_MAX_DIST is slightly larger than O3I_O3I_PLUS_ONE_MAX_DIST and hence the safe choice
1727 
1728  return( dist_square < (dist_cutoff*dist_cutoff) );
1729 
1730 
1731  }else if ( gap_size == 1 ) {
1732 
1733  //previously used 11.0138 as O3I_C5IPLUS2_MAX_DIS which is slight underestimate...TOO strict;
1734 
1735  return ( dist_square < O3I_C5IPLUS2_MAX_DIST*O3I_C5IPLUS2_MAX_DIST );
1736 
1737  }else if (gap_size ==0){
1738 
1739  static Distance const cutoff_distance_min_square( 2.0*2.0 );
1740  static Distance const cutoff_distance_max_square( 4.627*4.627 );
1741 
1742  //basically cannot close chain if the C5_O3_distance is either too short or too long.
1743  if( ( dist_square > cutoff_distance_max_square) || dist_square < cutoff_distance_min_square ) return false;
1744 
1745  return true;
1746 
1747  }else{
1748  std::string const exit_message="Invalid gap_size= " + string_of(gap_size) + " !!";
1749  utility_exit_with_message( exit_message );
1750  }
1751 
1752  utility_exit_with_message( "Should not reach this point of the function!" );
1753  exit(1); //prevent compiler warning!
1754  }
1755 
1756  //////////////////////////////////////////////////////////////////////////////////////////////////////
1757  //Optimization for floating_base_chain_closure
1758  //Need to integrate this with standard Check_chain_closable()
1759  bool
1760  Check_chain_closable_floating_base(pose::Pose const & five_prime_pose, pose::Pose const & three_prime_pose,
1761  Size const five_prime_chain_break_res, Size const gap_size ){
1762 
1763  if( gap_size != 0 ){
1764  std::cout << "gap_size= " << gap_size;
1765  utility_exit_with_message( "gap_size!=0" );
1766  }
1767 
1768  //This is potentially dangerous since even in the case where gap_size!=0...it assume that there is not residues between 3' and 5' res....
1769  Size const three_prime_chain_break_res= five_prime_chain_break_res + 1;
1770 
1771  Distance C5_O3_dist=(three_prime_pose.residue(three_prime_chain_break_res).xyz("C5*") - five_prime_pose.residue(five_prime_chain_break_res).xyz("O3*") ).length();
1772 
1773 
1774 
1775  static Distance const C5_O3_min( 2.866000 );
1776  static Distance const C5_O3_max( 3.968000 );
1777  static Distance const leniency_dist( 0.0);
1778 
1779 
1780  //basically cannot close chain if the C5_O3_distance is either too short or too long.
1781  if( (C5_O3_dist > (C5_O3_max+leniency_dist )) || (C5_O3_dist < (C5_O3_min-leniency_dist )) ) return false;
1782 
1783  conformation::Residue const & five_prime_rsd =five_prime_pose.residue(five_prime_chain_break_res);
1784  conformation::Residue const & three_prime_rsd=three_prime_pose.residue(three_prime_chain_break_res);
1785 
1786  Distance C4_C3_min=0.0;
1787  Distance C4_C3_max=0.0;
1788 
1789  get_C4_C3_distance_range(five_prime_rsd, three_prime_rsd, C4_C3_min, C4_C3_max);
1790 
1791  Distance C4_C3_dist=(three_prime_pose.residue(three_prime_chain_break_res).xyz(" C4*") - five_prime_pose.residue(five_prime_chain_break_res).xyz(" C3*") ).length();
1792 
1793  if( (C4_C3_dist > (C4_C3_max+leniency_dist )) || (C4_C3_dist < (C4_C3_min-leniency_dist )) ) return false;
1794 
1795  return true;
1796 
1797  }
1798 
1799  void
1801  conformation::Residue const & three_prime_rsd,
1802  Distance & C4_C3_dist_min,
1803  Distance & C4_C3_dist_max){
1804 
1805 
1806  numeric::xyzVector<Real> start_vector=five_prime_rsd.xyz(" O3*")-five_prime_rsd.xyz(" C3*");
1807  numeric::xyzVector<Real> end_vector=three_prime_rsd.xyz(" C4*")-three_prime_rsd.xyz(" C5*");
1808 
1809  start_vector.normalize();
1810  end_vector.normalize();
1811 
1812  Real dot_product=dot( start_vector, end_vector);
1813 
1814 
1815  if(dot_product > -1.00 && dot_product < -0.95 ) {C4_C3_dist_min= 2.428; C4_C3_dist_max= 4.337; }
1816  else if(dot_product > -0.95 && dot_product < -0.90 ) {C4_C3_dist_min= 2.238; C4_C3_dist_max= 4.582; }
1817  else if(dot_product > -0.90 && dot_product < -0.85 ) {C4_C3_dist_min= 2.064; C4_C3_dist_max= 4.743; }
1818  else if(dot_product > -0.85 && dot_product < -0.80 ) {C4_C3_dist_min= 1.979; C4_C3_dist_max= 4.882; }
1819  else if(dot_product > -0.80 && dot_product < -0.75 ) {C4_C3_dist_min= 1.833; C4_C3_dist_max= 4.995; }
1820  else if(dot_product > -0.75 && dot_product < -0.70 ) {C4_C3_dist_min= 1.735; C4_C3_dist_max= 5.099; }
1821  else if(dot_product > -0.70 && dot_product < -0.65 ) {C4_C3_dist_min= 1.659; C4_C3_dist_max= 5.195; }
1822  else if(dot_product > -0.65 && dot_product < -0.60 ) {C4_C3_dist_min= 1.590; C4_C3_dist_max= 5.273; }
1823  else if(dot_product > -0.60 && dot_product < -0.55 ) {C4_C3_dist_min= 1.500; C4_C3_dist_max= 5.347; }
1824  else if(dot_product > -0.55 && dot_product < -0.50 ) {C4_C3_dist_min= 1.418; C4_C3_dist_max= 5.417; }
1825  else if(dot_product > -0.50 && dot_product < -0.45 ) {C4_C3_dist_min= 1.337; C4_C3_dist_max= 5.488; }
1826  else if(dot_product > -0.45 && dot_product < -0.40 ) {C4_C3_dist_min= 1.282; C4_C3_dist_max= 5.552; }
1827  else if(dot_product > -0.40 && dot_product < -0.35 ) {C4_C3_dist_min= 1.223; C4_C3_dist_max= 5.611; }
1828  else if(dot_product > -0.35 && dot_product < -0.30 ) {C4_C3_dist_min= 1.145; C4_C3_dist_max= 5.659; }
1829  else if(dot_product > -0.30 && dot_product < -0.25 ) {C4_C3_dist_min= 1.075; C4_C3_dist_max= 5.713; }
1830  else if(dot_product > -0.25 && dot_product < -0.20 ) {C4_C3_dist_min= 1.022; C4_C3_dist_max= 5.769; }
1831  else if(dot_product > -0.20 && dot_product < -0.15 ) {C4_C3_dist_min= 0.963; C4_C3_dist_max= 5.812; }
1832  else if(dot_product > -0.15 && dot_product < -0.10 ) {C4_C3_dist_min= 1.019; C4_C3_dist_max= 5.861; }
1833  else if(dot_product > -0.10 && dot_product < -0.05 ) {C4_C3_dist_min= 1.331; C4_C3_dist_max= 5.904; }
1834  else if(dot_product > -0.05 && dot_product < 0.00 ) {C4_C3_dist_min= 1.532; C4_C3_dist_max= 5.942; }
1835  else if(dot_product > 0.00 && dot_product < 0.05 ) {C4_C3_dist_min= 1.768; C4_C3_dist_max= 5.979; }
1836  else if(dot_product > 0.05 && dot_product < 0.10 ) {C4_C3_dist_min= 1.953; C4_C3_dist_max= 6.017; }
1837  else if(dot_product > 0.10 && dot_product < 0.15 ) {C4_C3_dist_min= 2.121; C4_C3_dist_max= 6.046; }
1838  else if(dot_product > 0.15 && dot_product < 0.20 ) {C4_C3_dist_min= 2.292; C4_C3_dist_max= 6.083; }
1839  else if(dot_product > 0.20 && dot_product < 0.25 ) {C4_C3_dist_min= 2.424; C4_C3_dist_max= 6.118; }
1840  else if(dot_product > 0.25 && dot_product < 0.30 ) {C4_C3_dist_min= 2.563; C4_C3_dist_max= 6.140; }
1841  else if(dot_product > 0.30 && dot_product < 0.35 ) {C4_C3_dist_min= 2.726; C4_C3_dist_max= 6.171; }
1842  else if(dot_product > 0.35 && dot_product < 0.40 ) {C4_C3_dist_min= 2.849; C4_C3_dist_max= 6.200; }
1843  else if(dot_product > 0.40 && dot_product < 0.45 ) {C4_C3_dist_min= 2.998; C4_C3_dist_max= 6.219; }
1844  else if(dot_product > 0.45 && dot_product < 0.50 ) {C4_C3_dist_min= 3.128; C4_C3_dist_max= 6.245; }
1845  else if(dot_product > 0.50 && dot_product < 0.55 ) {C4_C3_dist_min= 3.261; C4_C3_dist_max= 6.261; }
1846  else if(dot_product > 0.55 && dot_product < 0.60 ) {C4_C3_dist_min= 3.380; C4_C3_dist_max= 6.284; }
1847  else if(dot_product > 0.60 && dot_product < 0.65 ) {C4_C3_dist_min= 3.523; C4_C3_dist_max= 6.298; }
1848  else if(dot_product > 0.65 && dot_product < 0.70 ) {C4_C3_dist_min= 3.658; C4_C3_dist_max= 6.315; }
1849  else if(dot_product > 0.70 && dot_product < 0.75 ) {C4_C3_dist_min= 3.785; C4_C3_dist_max= 6.329; }
1850  else if(dot_product > 0.75 && dot_product < 0.80 ) {C4_C3_dist_min= 3.914; C4_C3_dist_max= 6.340; }
1851  else if(dot_product > 0.80 && dot_product < 0.85 ) {C4_C3_dist_min= 4.065; C4_C3_dist_max= 6.350; }
1852  else if(dot_product > 0.85 && dot_product < 0.90 ) {C4_C3_dist_min= 4.209; C4_C3_dist_max= 6.356; }
1853  else if(dot_product > 0.90 && dot_product < 0.95 ) {C4_C3_dist_min= 4.374; C4_C3_dist_max= 6.357; }
1854  else if(dot_product > 0.95 && dot_product < 1.00 ) {C4_C3_dist_min= 4.570; C4_C3_dist_max= 6.349; }
1855  else{
1856  std::cout << "dot_product= " << dot_product << std::endl;
1857  utility_exit_with_message( "Invalid dot_product!" );
1858  }
1859 
1860  }
1861 
1862 /*
1863 dot_min= -1.000000 dot_max= -0.950000 C4_C3_dist_min= 2.428000 C4_C3_dist_max 4.337000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.881000
1864 dot_min= -0.950000 dot_max= -0.900000 C4_C3_dist_min= 2.238000 C4_C3_dist_max 4.582000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.923000
1865 dot_min= -0.900000 dot_max= -0.850000 C4_C3_dist_min= 2.064000 C4_C3_dist_max 4.743000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.951000
1866 dot_min= -0.850000 dot_max= -0.800000 C4_C3_dist_min= 1.979000 C4_C3_dist_max 4.882000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.966000
1867 dot_min= -0.800000 dot_max= -0.750000 C4_C3_dist_min= 1.833000 C4_C3_dist_max 4.995000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1868 dot_min= -0.750000 dot_max= -0.700000 C4_C3_dist_min= 1.735000 C4_C3_dist_max 5.099000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1869 dot_min= -0.700000 dot_max= -0.650000 C4_C3_dist_min= 1.659000 C4_C3_dist_max 5.195000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1870 dot_min= -0.650000 dot_max= -0.600000 C4_C3_dist_min= 1.590000 C4_C3_dist_max 5.273000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1871 dot_min= -0.600000 dot_max= -0.550000 C4_C3_dist_min= 1.500000 C4_C3_dist_max 5.347000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1872 dot_min= -0.550000 dot_max= -0.500000 C4_C3_dist_min= 1.418000 C4_C3_dist_max 5.417000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1873 dot_min= -0.500000 dot_max= -0.450000 C4_C3_dist_min= 1.337000 C4_C3_dist_max 5.488000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1874 dot_min= -0.450000 dot_max= -0.400000 C4_C3_dist_min= 1.282000 C4_C3_dist_max 5.552000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1875 dot_min= -0.400000 dot_max= -0.350000 C4_C3_dist_min= 1.223000 C4_C3_dist_max 5.611000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1876 dot_min= -0.350000 dot_max= -0.300000 C4_C3_dist_min= 1.145000 C4_C3_dist_max 5.659000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1877 dot_min= -0.300000 dot_max= -0.250000 C4_C3_dist_min= 1.075000 C4_C3_dist_max 5.713000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1878 dot_min= -0.250000 dot_max= -0.200000 C4_C3_dist_min= 1.022000 C4_C3_dist_max 5.769000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1879 dot_min= -0.200000 dot_max= -0.150000 C4_C3_dist_min= 0.963000 C4_C3_dist_max 5.812000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1880 dot_min= -0.150000 dot_max= -0.100000 C4_C3_dist_min= 1.019000 C4_C3_dist_max 5.861000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1881 dot_min= -0.100000 dot_max= -0.050000 C4_C3_dist_min= 1.331000 C4_C3_dist_max 5.904000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1882 dot_min= -0.050000 dot_max= 0.000000 C4_C3_dist_min= 1.532000 C4_C3_dist_max 5.942000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1883 dot_min= 0.000000 dot_max= 0.050000 C4_C3_dist_min= 1.768000 C4_C3_dist_max 5.979000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1884 dot_min= 0.050000 dot_max= 0.100000 C4_C3_dist_min= 1.953000 C4_C3_dist_max 6.017000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1885 dot_min= 0.100000 dot_max= 0.150000 C4_C3_dist_min= 2.121000 C4_C3_dist_max 6.046000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1886 dot_min= 0.150000 dot_max= 0.200000 C4_C3_dist_min= 2.292000 C4_C3_dist_max 6.083000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1887 dot_min= 0.200000 dot_max= 0.250000 C4_C3_dist_min= 2.424000 C4_C3_dist_max 6.118000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1888 dot_min= 0.250000 dot_max= 0.300000 C4_C3_dist_min= 2.563000 C4_C3_dist_max 6.140000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1889 dot_min= 0.300000 dot_max= 0.350000 C4_C3_dist_min= 2.726000 C4_C3_dist_max 6.171000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1890 dot_min= 0.350000 dot_max= 0.400000 C4_C3_dist_min= 2.849000 C4_C3_dist_max 6.200000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1891 dot_min= 0.400000 dot_max= 0.450000 C4_C3_dist_min= 2.998000 C4_C3_dist_max 6.219000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1892 dot_min= 0.450000 dot_max= 0.500000 C4_C3_dist_min= 3.128000 C4_C3_dist_max 6.245000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1893 dot_min= 0.500000 dot_max= 0.550000 C4_C3_dist_min= 3.261000 C4_C3_dist_max 6.261000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1894 dot_min= 0.550000 dot_max= 0.600000 C4_C3_dist_min= 3.380000 C4_C3_dist_max 6.284000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1895 dot_min= 0.600000 dot_max= 0.650000 C4_C3_dist_min= 3.523000 C4_C3_dist_max 6.298000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1896 dot_min= 0.650000 dot_max= 0.700000 C4_C3_dist_min= 3.658000 C4_C3_dist_max 6.315000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1897 dot_min= 0.700000 dot_max= 0.750000 C4_C3_dist_min= 3.785000 C4_C3_dist_max 6.329000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1898 dot_min= 0.750000 dot_max= 0.800000 C4_C3_dist_min= 3.914000 C4_C3_dist_max 6.340000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1899 dot_min= 0.800000 dot_max= 0.850000 C4_C3_dist_min= 4.065000 C4_C3_dist_max 6.350000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1900 dot_min= 0.850000 dot_max= 0.900000 C4_C3_dist_min= 4.209000 C4_C3_dist_max 6.356000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1901 dot_min= 0.900000 dot_max= 0.950000 C4_C3_dist_min= 4.374000 C4_C3_dist_max 6.357000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1902 dot_min= 0.950000 dot_max= 1.000000 C4_C3_dist_min= 4.570000 C4_C3_dist_max 6.349000 C5_O3_dist_min= 2.866000 C5_O3_dist_max 3.968000
1903 
1904 */
1905 
1906  //////////////////////////////////////////////////////////////////////////////////////////////////////
1907  void
1909 
1910  using namespace core::id;
1911 
1912  std::cout << "Freeze pose sugar torsions, total_residue=" << total_residue << std::endl;
1913 
1914  for(Size i=1; i<=total_residue; i++){
1915 
1916  mm.set( TorsionID( i , id::BB, 4 ), false ); //delta_i
1917  mm.set( TorsionID( i , id::CHI, 2 ), false ); //nu2_i
1918  mm.set( TorsionID( i , id::CHI, 3 ), false ); //nu1_i
1919 
1920  }
1921  }
1922 
1923  //////////////////////////////////////////////////////////////////////////////////////////////////////
1924  void
1925  Output_boolean(std::string const & tag, bool boolean){
1926 
1927  using namespace ObjexxFCL;
1928  using namespace ObjexxFCL::fmt;
1929  std::cout << tag;
1930 
1931  if(boolean==true){
1932  std::cout << A(4,"T");
1933  } else {
1934  std::cout << A(4,"F");
1935  }
1936  }
1937 
1938  /////////////////////////////////////////////////////////////////////////////////////
1939  void
1940  Output_boolean(bool boolean){
1941 
1942  using namespace ObjexxFCL;
1943  using namespace ObjexxFCL::fmt;
1944 
1945  if(boolean==true){
1946  std::cout << A(4,"T");
1947  } else {
1948  std::cout << A(4,"F");
1949  }
1950  }
1951 
1952  //////////////////////////////////////////////////////////////////////////////////////////////////////
1953  void
1955 
1956  using namespace ObjexxFCL;
1957  using namespace ObjexxFCL::fmt;
1958  using namespace core::id;
1959  using namespace core::kinematics;
1960 
1961  Size const total_residue =pose.total_residue();
1962 
1963  Size spacing=10;
1964 
1965  std::cout << "--------------------------------------------------------------------------------------" << std::endl;
1966  std::cout << "Movemap (in term of partial_pose seq_num): " << std::endl;
1967  std::cout << A(spacing,"res_num" ) << A(spacing," alpha ") << A(spacing," beta ") << A(spacing," gamma ");
1968  std::cout << A(spacing," delta ") << A(spacing,"eplison ") << A(spacing," zeta ") << A(spacing," chi_1 ");
1969  std::cout << A(spacing," nu_2 ") << A(spacing," nu_1 ") << A(spacing,"chi_O2* ") << std::endl;
1970 
1971  for(Size n=1; n<= total_residue; n++){
1972 
1973  std::cout << I(spacing, 3 , n);
1974  std::cout << A(-1+(spacing-4)/2, ""); Output_boolean(mm.get(TorsionID( n , id::BB, 1 ))); std::cout << A(1+(spacing-4)/2, "");
1975  std::cout << A(-1+(spacing-4)/2, ""); Output_boolean(mm.get(TorsionID( n , id::BB, 2 ))); std::cout << A(1+(spacing-4)/2, "");
1976  std::cout << A(-1+(spacing-4)/2, ""); Output_boolean(mm.get(TorsionID( n , id::BB, 3 ))); std::cout << A(1+(spacing-4)/2, "");
1977  std::cout << A(-1+(spacing-4)/2, ""); Output_boolean(mm.get(TorsionID( n , id::BB, 4 ))); std::cout << A(1+(spacing-4)/2, "");
1978  std::cout << A(-1+(spacing-4)/2, ""); Output_boolean(mm.get(TorsionID( n , id::BB, 5 ))); std::cout << A(1+(spacing-4)/2, "");
1979  std::cout << A(-1+(spacing-4)/2, ""); Output_boolean(mm.get(TorsionID( n , id::BB, 6 ))); std::cout << A(1+(spacing-4)/2, "");
1980  std::cout << A(-1+(spacing-4)/2, ""); Output_boolean(mm.get(TorsionID( n , id::CHI, 1 ))); std::cout << A(1+(spacing-4)/2, "");
1981  std::cout << A(-1+(spacing-4)/2, ""); Output_boolean(mm.get(TorsionID( n , id::CHI, 2 ))); std::cout << A(1+(spacing-4)/2, "");
1982  std::cout << A(-1+(spacing-4)/2, ""); Output_boolean(mm.get(TorsionID( n , id::CHI, 3 ))); std::cout << A(1+(spacing-4)/2, "");
1983  std::cout << A(-1+(spacing-4)/2, ""); Output_boolean(mm.get(TorsionID( n , id::CHI, 4 ))); std::cout << A(1+(spacing-4)/2, "");
1984  std::cout << std::endl;
1985  }
1986  std::cout << "--------------------------------------------------------------------------------------" << std::endl;
1987 
1988 
1989 
1990  std::cout << "print movemap jump_points [explicit method]: " << std::endl;
1991  for (Size n = 1; n <= pose.fold_tree().num_jump(); n++ ){
1992  Size const jump_pos1( pose.fold_tree().upstream_jump_residue( n ) );
1993  Size const jump_pos2( pose.fold_tree().downstream_jump_residue( n ) );
1994 
1995  std::cout << "n=" << n << " | jump_pos1= " << jump_pos1 << " | jump_pos2= " << jump_pos2;
1996  std::cout << " | mm.get_jump(n) = "; Output_boolean( mm.get_jump(n) );
1997  std::cout << std::endl;
1998 
1999  }
2000  std::cout << "--------------------------------------------------------------------------------------" << std::endl;
2001 
2002  //From core/kinematic/MoveMap.hh
2003  //typedef std::map< id::JumpID, bool > JumpID_Map
2004  std::cout << "print movemap jump_points [iterator method]: " << std::endl;
2005  for (std::map< id::JumpID, bool >::const_iterator it=mm.jump_id_begin(); it!=mm.jump_id_end(); it++ ){
2006  std::cout << "movemap jump==true for jump_pos1=" << it->first << " | jump_pos2=" << it->second << std::endl;
2007  }
2008  std::cout << "--------------------------------------------------------------------------------------" << std::endl;
2009 
2010  }
2011 
2012  /////////////////////////////////////////////////////////////////////////////////////
2014  get_surrounding_O2star_hydrogen(pose::Pose const & pose, utility::vector1< core::Size > const & moving_res, bool verbose){
2015 
2016  using namespace core::chemical;
2017  using namespace core::scoring;
2018  using namespace core::kinematics;
2019  using namespace ObjexxFCL;
2020 
2021 
2022 
2023  //Consistency_check
2024  for(Size seq_num=1; seq_num<=pose.total_residue(); seq_num++){
2025 
2026  if (pose.residue(seq_num).aa() == core::chemical::aa_vrt ) continue; //Fang's electron density code
2027 
2028  core::conformation::Residue const & rsd = pose.residue(seq_num);
2029  Size const at= rsd.first_sidechain_atom();
2030 
2031  if(rsd.type().atom_name(at) !=" O2*") {
2032  std::string const exit_message= "seq_num= " + string_of(seq_num) + ", rsd.type().atom_name(at) !=\" O2*\" ";
2033  utility_exit_with_message( exit_message);
2034  }
2035  }
2036 
2037  utility::vector1< bool > Is_O2star_hydrogen_virtual_list;
2038 
2039  for(Size seq_num=1; seq_num<=pose.total_residue(); seq_num++){
2040 
2041  if(pose.residue(seq_num).aa() == core::chemical::aa_vrt ){
2042  if(verbose) std::cout << "res " << seq_num << " is core::chemical::aa_vrt! " << std::endl;
2043  Is_O2star_hydrogen_virtual_list.push_back(false); //false since not virtual O2star_hydrogen
2044  continue;
2045  }
2046 
2047  core::conformation::Residue const & rsd = pose.residue(seq_num);
2048  Size at=rsd.atom_index( "2HO*" );
2049 
2050  if(rsd.atom_type(at).name()=="VIRT"){
2051  if(verbose) std::cout << "res " << seq_num << " has a virtual o2star hydrogen! " << std::endl;
2052  Is_O2star_hydrogen_virtual_list.push_back(true);
2053  }else{
2054  Is_O2star_hydrogen_virtual_list.push_back(false);
2055  }
2056  }
2057 
2058  //March 17, 2012 extra precation.
2059  if(Is_O2star_hydrogen_virtual_list.size()!=pose.total_residue()) utility_exit_with_message("Is_O2star_hydrogen_virtual_list.size()!=pose.total_residue()");
2060 
2061  utility::vector1< core::Size > surrounding_O2star_hydrogen;
2062 
2063  Size num_o2star_moving_res=0;
2064  for(Size n=1; n<=moving_res.size(); n++){
2065  Size const seq_num=moving_res[n];
2066 
2067  if(pose.residue(seq_num).aa() == core::chemical::aa_vrt ) continue; //Fang's electron density code
2068  if(Is_O2star_hydrogen_virtual_list[seq_num]) continue;
2069 
2070  //if(verbose) std::cout << "res " << seq_num << " is a working_moving_res" << std::endl;
2071  surrounding_O2star_hydrogen.push_back(seq_num);
2072  num_o2star_moving_res++;
2073  }
2074 
2075 
2076  //1st layer, interaction between surrounding O2star and moving_res
2077  for(Size seq_num=1; seq_num<= pose.total_residue(); seq_num++){
2078 
2079  if(pose.residue(seq_num).aa() == core::chemical::aa_vrt ) continue; //Fang's electron density code
2080  if(Contain_seq_num(seq_num, surrounding_O2star_hydrogen) ) continue;
2081 
2082  bool Is_surrounding_res=false;
2083 
2084  core::conformation::Residue const & surrounding_rsd = pose.residue(seq_num);
2085  Size const surr_at= surrounding_rsd.first_sidechain_atom();
2086 
2087  if(Is_O2star_hydrogen_virtual_list[seq_num]) continue;
2088 
2089  //3.5 Angstrom for O2star-normal
2090 
2091  for(Size ii=1; ii<=moving_res.size(); ii++){
2092  if(Is_surrounding_res==true) break;
2093 
2094  core::conformation::Residue const & moving_rsd=pose.residue(moving_res[ii]);
2095 
2096  for(Size moving_at=1; moving_at<=moving_rsd.natoms(); moving_at++){
2097 
2098  if( moving_rsd.atom_type(moving_at).name()=="VIRT" ) continue;
2099 
2100  Real const cutoff_dist= (moving_at==moving_rsd.first_sidechain_atom()) ? 4.5: 3.5 ;
2101 
2102  //4.5 Angstrom interaction dist_cutoff for surrounding O2star- moving_res O2star
2103  //3.5 Angstrom interaction dist_cutoff for surround O2star and other atoms of moving_res
2104 
2105  Real const dist_square = (surrounding_rsd.xyz(surr_at)-moving_rsd.xyz(moving_at) ).length_squared();
2106 
2107  if( dist_square < cutoff_dist*cutoff_dist){
2108  if(verbose) std::cout << "res " << seq_num << " is a 1st layer surrounding O2star_hydrogen res, dist_square = " << dist_square << std::endl;
2109  surrounding_O2star_hydrogen.push_back(seq_num);
2110  Is_surrounding_res=true;
2111  break;
2112  }
2113  }
2114  }
2115  }
2116 
2117 
2118  //layer 2+, interaction between surrounding O2star hydrogen themselves
2119  Size layer_num=2;
2120  while(true){
2121  bool add_new_O2star_hydrogen=false;
2122 
2123  for(Size seq_num=1; seq_num<= pose.total_residue(); seq_num++){
2124 
2125  if (pose.residue(seq_num).aa() == core::chemical::aa_vrt ) continue; //Fang's electron density code
2126  if(Contain_seq_num(seq_num, surrounding_O2star_hydrogen) ) continue;
2127 
2128  core::conformation::Residue const & rsd_1 = pose.residue(seq_num);
2129  Size const at_1= rsd_1.first_sidechain_atom();
2130 
2131  if(Is_O2star_hydrogen_virtual_list[seq_num]) continue;
2132 
2133  for(Size ii=1; ii<=surrounding_O2star_hydrogen.size(); ii++){
2134 
2135  core::conformation::Residue const & rsd_2=pose.residue(surrounding_O2star_hydrogen[ii]);
2136  Size const at_2= rsd_2.first_sidechain_atom();
2137 
2138  Real const cutoff_dist=4.5; //4.5 Angstrom interaction dist_cutoff for surrounding O2star themselves.
2139 
2140  Real const dist_square = (rsd_1.xyz(at_1)-rsd_2.xyz(at_2) ).length_squared();
2141 
2142  if( dist_square < cutoff_dist*cutoff_dist){
2143  if(verbose) std::cout << "res " << seq_num << " is layer " << layer_num << " surrounding O2star_hydrogen res, dist_square = " << dist_square << std::endl;
2144  surrounding_O2star_hydrogen.push_back(seq_num);
2145  add_new_O2star_hydrogen=true;
2146  break;
2147  }
2148  }
2149  }
2150 
2151  layer_num++;
2152  if(add_new_O2star_hydrogen==false) break;
2153  }
2154 
2155  //consistency_check..
2156  for(Size ii=1; ii<=surrounding_O2star_hydrogen.size(); ii++){
2157 
2158  Size const seq_num=surrounding_O2star_hydrogen[ii];
2159 
2160  if(Is_O2star_hydrogen_virtual_list[seq_num]){
2161  std::string const exit_message= "surrounding_O2star_hydrogen res " + string_of(seq_num) + " has a virtual o2star hydrogen!! ";
2162  utility_exit_with_message( exit_message);
2163  }
2164  }
2165 
2166  if(verbose){
2167  std::cout << "num_o2star_moving_res= " << num_o2star_moving_res << " surrounding_O2star_hydrogen.size()= " << surrounding_O2star_hydrogen.size() << std::endl;
2168  }
2169 
2170  return surrounding_O2star_hydrogen;
2171 
2172  }
2173 
2174  /////////////////////////////////////////////////////////////////////////////////////
2175  void
2176  o2star_minimize(pose::Pose& pose, core::scoring::ScoreFunctionOP const & packer_scorefxn){ //O2star pack every position..
2177 
2178  utility::vector1< core::Size > O2star_pack_seq_num;
2179 
2180  for(Size seq_num=1; seq_num<=pose.total_residue(); seq_num++){
2181  if (pose.residue(seq_num).aa() == core::chemical::aa_vrt ) continue; //Fang's electron density code
2182  O2star_pack_seq_num.push_back(seq_num);
2183  }
2184 
2185  o2star_minimize(pose, packer_scorefxn, O2star_pack_seq_num);
2186 
2187  }
2188 
2189  /////////////////////////////////////////////////////////////////////////////////////
2190  void
2191  o2star_minimize(pose::Pose& pose, core::scoring::ScoreFunctionOP const & packer_scorefxn, utility::vector1< core::Size > const & O2star_pack_seq_num){
2192 
2193  Output_seq_num_list("O2star_pack_seq_num= " , O2star_pack_seq_num);
2194 
2195  pack::task::PackerTaskOP task = create_standard_o2star_pack_task(pose, O2star_pack_seq_num);
2196  task->initialize_from_command_line();
2197 
2198  pack::rotamer_trials( pose, *packer_scorefxn, task);
2199 
2200  }
2201 
2202  /////////////////////////////////////////////////////////////////////////////////////
2203  //Created on Jan 20, 2012: Meant as the standard function to setup o2star_pack_task to be called by both StepWiseRNA_ResidueSampler and StepWiseRNA_Minimizer...and in the future also FARFAR_minimizer.
2206 
2208 
2209  //Commented out the initialize_from_command_line() call below on Jan 20, 2012: REASONS:
2210  /////1. The line is actually missing in the StepWiseRNA_ResidueSampler version (see below) which now calls this function.
2211  /////2. This is potentially dangerous since behavior can be influence by command_line flags (for example from command_line could turn on ex1 (base sampling) and etc which is not what we want!
2212  //o2star_pack_task->initialize_from_command_line(); //Found only in original version packer_setup in StepWiseRNA_Util.cc BUT not the one in StepWiseRNA_ResidueSampler version.
2213 
2214  for(Size seq_num=1; seq_num<=pose.total_residue(); seq_num++){
2215 
2216  if(pose.residue(seq_num).aa() == core::chemical::aa_vrt ) continue; //Fang's electron density code
2217  if(Contain_seq_num(seq_num, O2star_pack_seq_num) && pose.residue(seq_num).is_RNA() ){ //pack this residue!
2218 
2219  /*
2220  NOTE: the ex4 option allows sampling of extra torsion angles ("ex") at
2221  the 2'-OH (which is torsion "4"). To pack the bases, you would have to
2222  add "ex1"; it should not happen! If you see bases getting repacked,
2223  that is a bug, and please let me know. (From Rhiju email response)
2224 
2225  ex4 (HO2star) is "on" by default | ex1 (base chi) is "off" by default
2226  */
2227 
2228  o2star_pack_task->nonconst_residue_task(seq_num).and_extrachi_cutoff( 0 );
2229  o2star_pack_task->nonconst_residue_task(seq_num).or_ex4( true ); //extra O2star sampling
2230  o2star_pack_task->nonconst_residue_task(seq_num).or_include_current( true ); //Jan 21, 2012: umm this might be set to true inside call to rotamer_trials() BUT even so, doesn't hurt so have it here as well!
2231  // How about bump check?
2232  }else{
2233  o2star_pack_task->nonconst_residue_task(seq_num).prevent_repacking();
2234  }
2235  }
2236 
2237  return o2star_pack_task;
2238 
2239  /* ////Below is the version originally found in StepWiseRNA_ResidueSampler::initialize_o2star_packer_task(). ////
2240  ///////Integrated with this with the StepWsieRNA_Util.cc version on Jan 20, 2012/////////////////////////////////
2241  o2star_pack_task_ = pack::task::TaskFactory::create_packer_task( pose );
2242 
2243  for(Size seq_num=1; seq_num<=pose.total_residue(); seq_num++){
2244 
2245  if(Contain_seq_num(seq_num, O2star_pack_seq_num) && pose.residue(seq_num).is_RNA() ){ //pack this residue!
2246 
2247  o2star_pack_task_->nonconst_residue_task(seq_num).and_extrachi_cutoff( 0 );
2248  o2star_pack_task_->nonconst_residue_task(seq_num).or_ex4( true ); //extra O2star sampling
2249  o2star_pack_task_->nonconst_residue_task(seq_num).or_include_current( true );
2250  // How about bump check?
2251  }else{
2252  o2star_pack_task_->nonconst_residue_task(seq_num).prevent_repacking();
2253  }
2254  }
2255  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
2256  */
2257 
2258  }
2259 
2260  /////////////////////////////////////////////////////////////////////////////////////
2261  void
2262  print_backbone_torsions(pose::Pose const & pose, Size const five_prime_chainbreak){
2263 
2264  using namespace core::id;
2265 
2266  conformation::Residue const & suite_lower_res=pose.residue(five_prime_chainbreak);
2267  std::cout << std::setw(5) << " ep= " << std::setw(15) << suite_lower_res.mainchain_torsion(5);
2268  std::cout << std::setw(5) << " z= " << std::setw(15) << suite_lower_res.mainchain_torsion(6);
2269 
2270 
2271  Size const three_prime_chainbreak=five_prime_chainbreak+1;
2272 
2273  if (three_prime_chainbreak <= pose.total_residue()) {
2274  conformation::Residue const & suite_upper_res=pose.residue(three_prime_chainbreak);
2275  std::cout << std::setw(5) << " a= " << std::setw(15) << suite_upper_res.mainchain_torsion(1);
2276  std::cout << std::setw(5) << " b= " << std::setw(15) << suite_upper_res.mainchain_torsion(2);
2277  std::cout << std::setw(5) << " g= " << std::setw(15) << suite_upper_res.mainchain_torsion(3);
2278  }
2279 
2280  std::cout << std::endl;
2281 
2282  }
2283  /////////////////////////////////////////////////////////////////////////////////////
2284 
2285 
2286  //When a CUTPOINT_UPPER is added to 3' chain_break residue, the EXISTENCE of the CUTPOINT_UPPER atoms means that the alpha torsion which previously DOES NOT exist due to the chain_break now exist. The alpha value is automatically defined to the A-form value by Rosetta. However Rosetta does not automatically adjust the O1P and O2P atom position to account for this fact. So it is important that the O1P and O2P atoms position are correctly set to be consistent with A-form alpha torsion before the CUTPOINT_UPPER IS ADDED Parin Jan 2, 2009
2287  //Uncomment print_backbone_torsion on Dec 26, 2010
2288  void
2289  Correctly_position_cutpoint_phosphate_torsions(pose::Pose & current_pose, Size const five_prime_chainbreak, bool verbose /*=false*/){
2290 
2291  using namespace core::chemical;
2292  using namespace core::conformation;
2293  using namespace core::id;
2294  using namespace core::io::pdb;
2295 
2297  residue_type_set( core::chemical::RNA );
2298 
2299  if(verbose) Output_title_text("ENTER Correctly_position_cutpoint_phosphate_torsions function");
2300 
2301  chemical::AA res_aa = aa_from_name( "RAD" );
2302  ResidueOP new_rsd = conformation::ResidueFactory::create_residue( *(rsd_set->aa_map( res_aa )[1]) ) ;
2303  if(verbose) std::cout << " res_aa: " << res_aa << std::endl;
2304 
2305  Size three_prime_chainbreak=five_prime_chainbreak+1;
2306 
2307  if(verbose){
2308  //dump_pdb(current_pose, "Before_prepending_dummy_nucleotide");
2309  std::cout << std::setw(50) << "Before_prepending_dummy_nucleotide";
2310  print_backbone_torsions(current_pose, five_prime_chainbreak);
2311  }
2312 
2313  current_pose.prepend_polymer_residue_before_seqpos( *new_rsd, three_prime_chainbreak, true);
2314  scoring::rna::RNA_FittedTorsionInfo const rna_fitted_torsion_info;
2315 
2316  if(verbose){
2317  //dump_pdb(current_pose, "Before_setting_torsion_to_A_form.pdb");
2318  std::cout << std::setw(50) << "Before_setting_torsion_to_A_form";
2319  print_backbone_torsions(current_pose, five_prime_chainbreak+1);
2320  }
2321  //Actually just by prepending the residue causes the alpha torsion to automatically be set to -64.0274,
2322  //so the manual setting below is actually not needed, May 24, 2010.. Parin S.
2323  //These are the initial value of virtual upper and lower cutpoint atom.
2324  //Actaully only the alpha (id::BB, 1) is important here since it set the position of O3' (LOWER) atom which in turn determines O1P and O2P atom
2325  current_pose.set_torsion( TorsionID( three_prime_chainbreak+1, id::BB, 1 ), -64.027359 );
2326 
2327  /* BEFORE AUG 24, 2011
2328  //Where the hell did I get these numbers from value...by appending with ideal geometry and look at the initalized value? Oct 13, 2009
2329  current_pose.set_torsion( TorsionID( five_prime_chainbreak+1, id::BB, 5 ), -151.943 ); //Not Important?
2330  current_pose.set_torsion( TorsionID( five_prime_chainbreak+1, id::BB, 6 ), -76.4185 ); //Not Important?
2331  current_pose.set_torsion( TorsionID( three_prime_chainbreak+1, id::BB, 1 ), -64.0274 );
2332  */
2333 
2334  //RAD.params
2335  //ICOOR_INTERNAL LOWER -64.027359 71.027062 1.593103 P O5* C5*
2336  //ICOOR_INTERNAL O1P -111.509000 71.937134 1.485206 P O5* LOWER
2337  //ICOOR_INTERNAL O2P -130.894000 71.712189 1.485010 P O5* O1P
2338 
2339  //RCY.params
2340  //ICOOR_INTERNAL LOWER -64.027359 71.027062 1.593103 P O5* C5*
2341  //ICOOR_INTERNAL O1P -111.509000 71.937134 1.485206 P O5* LOWER
2342  //ICOOR_INTERNAL O2P -130.894000 71.712189 1.485010 P O5* O1P
2343 
2344  //RGU.params
2345  //ICOOR_INTERNAL LOWER -64.027359 71.027062 1.593103 P O5* C5*
2346  //ICOOR_INTERNAL O1P -111.509000 71.937134 1.485206 P O5* LOWER
2347  //ICOOR_INTERNAL O2P -130.894000 71.712189 1.485010 P O5* O1P
2348 
2349  //URA.parms
2350  //ICOOR_INTERNAL LOWER -64.027359 71.027062 1.593103 P O5* C5*
2351  //ICOOR_INTERNAL O1P -111.509000 71.937134 1.485206 P O5* LOWER
2352  //ICOOR_INTERNAL O2P -130.894000 71.712189 1.485010 P O5* O1P
2353 
2354  if(verbose){
2355  //dump_pdb(current_pose, "After_setting_torsion_to_A_form.pdb");
2356  std::cout << std::setw(50) << "After_setting_torsion_to_A_form"; print_backbone_torsions(current_pose, five_prime_chainbreak+1);
2357  }
2358 
2359  current_pose.delete_polymer_residue(five_prime_chainbreak+1);
2360 
2361  if(verbose){
2362  //dump_pdb(current_pose, "After_deleting_dummy_nucleotide");
2363  std::cout << std::setw(50) << "After_deleting_dummy_nucleotide"; print_backbone_torsions(current_pose, five_prime_chainbreak);
2364  }
2365 
2366  if(verbose) Output_title_text("EXIT Correctly_position_cutpoint_phosphate_torsions function");
2367 
2368  }
2369  //////////////////////////////////////////////////////////////////////////
2370 
2371  void
2372  copy_torsions_FROM_TO( core::id::TorsionID const start_torsion_ID, core::id::TorsionID const end_torsion_ID, core::pose::Pose const & template_pose, core::pose::Pose & pose){
2373 
2374  using namespace core::chemical;
2375  using namespace core::conformation;
2376  using namespace core::id;
2377  using namespace core::scoring::rna;
2378  using namespace core::kinematics;
2379 
2380  if(template_pose.total_residue()!=pose.total_residue()){
2381  std::cout << "template_pose.total_residue()= " << template_pose.total_residue() << " pose.total_residue()= " << pose.total_residue() << std::endl;
2382  utility_exit_with_message( "template_pose.total_residue()!=pose.total_residue()" );
2383  }
2384 
2385  if((template_pose.fold_tree()==pose.fold_tree())==false){
2386  Output_fold_tree_info(template_pose.fold_tree(), "template_pose");
2387  Output_fold_tree_info(pose.fold_tree(), "pose");
2388  utility_exit_with_message( "(template_pose.fold_tree()==pose.fold_tree())==false" );
2389  }
2390 
2391  if(start_torsion_ID.type()!=id::BB){
2392  std::cout << "start_torsion_ID: " << start_torsion_ID;
2393  utility_exit_with_message( "start_torsion_ID.type()!=id::BB" );
2394  }
2395 
2396  if(end_torsion_ID.type()!=id::BB){
2397  std::cout << "end_torsion_ID: " << start_torsion_ID;
2398  utility_exit_with_message( "end_torsion_ID.type()!=id::BB" );
2399  }
2400 
2401 
2402  for(Size seq_num=start_torsion_ID.rsd(); seq_num<=end_torsion_ID.rsd(); seq_num++){
2403 
2404  //Backbone
2405  for(Size n=1; n<= NUM_RNA_MAINCHAIN_TORSIONS; n++){
2406 
2407  if(seq_num==start_torsion_ID.rsd() && n<start_torsion_ID.torsion()) continue;
2408 
2409  if(seq_num==end_torsion_ID.rsd() && n>end_torsion_ID.torsion()) continue;
2410 
2411  pose.set_torsion( TorsionID( seq_num, id::BB, n ), template_pose.residue(seq_num).mainchain_torsion(n) );
2412 
2413  }
2414 
2415  //Side_chain
2416  bool copy_side_chain=true;
2417 
2418  if(seq_num==start_torsion_ID.rsd() && start_torsion_ID.torsion()> 4 /*Delta*/) copy_side_chain=false;
2419  if(seq_num==end_torsion_ID.rsd() && end_torsion_ID.torsion()< 4 /*Delta*/) copy_side_chain=false;
2420 
2421  if(copy_side_chain){
2422  pose.set_torsion( TorsionID( seq_num, id::CHI, 1 ), template_pose.residue(seq_num).chi(1) ); /*CHI*/
2423  pose.set_torsion( TorsionID( seq_num, id::CHI, 2 ), template_pose.residue(seq_num).chi(2) ); /*NU2*/
2424  pose.set_torsion( TorsionID( seq_num, id::CHI, 3 ), template_pose.residue(seq_num).chi(3) ); /*NU1*/
2425  pose.set_torsion( TorsionID( seq_num, id::CHI, 4 ), template_pose.residue(seq_num).chi(4) );/*chi_O2star*/
2426 
2427  }
2428 
2429  }
2430  }
2431 
2432 
2433  //////////////////////////////////////////////////////////////////////////
2434  core::Size
2435  setup_chain_break_jump_point( core::pose::Pose & pose, core::Size const jump_point_one, core::Size const jump_point_two , core::Size const five_prime_cutpoint, bool const verbose){
2436 
2437  Size cutpoint=setup_bulge_jump_point( pose, jump_point_one, jump_point_two , verbose);
2438 
2439  Correctly_position_cutpoint_phosphate_torsions( pose, five_prime_cutpoint , false /*verbose*/ );
2440 
2442  pose::add_variant_type_to_pose_residue( pose, chemical::CUTPOINT_UPPER, five_prime_cutpoint+1 );
2443 
2444  return cutpoint;
2445  }
2446 
2447  //////////////////////////////////////////////////////////////////////////
2448 
2449  void
2450  remove_chain_break_jump_point(core::pose::Pose & pose, core::Size const five_prime_cutpoint, core::kinematics::FoldTree const fold_tree_without_cutpoint){
2451 
2452  std::cout << "remove_chain_break_jump_point " << std::endl;
2453 
2456 
2457  pose.fold_tree( fold_tree_without_cutpoint );
2458 
2459 
2460  }
2461 
2462  //////////////////////////////////////////////////////////////////////////
2463 
2464  core::Size
2465  setup_bulge_jump_point( pose::Pose & pose, Size const & moving_base, Size const & reference_base , bool const verbose){
2466 
2467 
2468  using namespace core::conformation;
2469 
2470  if(moving_base==reference_base){
2471  utility_exit_with_message( "moving_base==reference_base!" );
2472  }
2473 
2474  int i,j;
2475 
2476  Size cutpoint;
2477  if(moving_base>reference_base){
2478  i=reference_base;
2479  j=moving_base;
2480  cutpoint=moving_base-1;
2481  }else{
2482  i=moving_base;
2483  j=reference_base;
2484  cutpoint=moving_base;
2485  }
2486 
2487  core::kinematics::FoldTree fold_tree = pose.fold_tree(); //HARD COPY?
2488 
2489  if(verbose) Output_fold_tree_info(fold_tree, "Before add bulge jump point");
2490 
2491  // fold_tree.new_jump( five_prime_seq_num, three_prime_seq_num, cut_point );
2492  fold_tree.new_jump( reference_base , moving_base , cutpoint); //Choose the residue five_prime of the actual cutpoint position
2493 
2494  if(verbose) std::cout << "after add new jump point" << std::endl;
2495 
2496  Residue const & rsd1( pose.residue( i ) );
2497  Residue const & rsd2( pose.residue( j ) );
2498 
2499  Size jump_num=9999;
2500 
2501  for ( Size n = 1; n <= fold_tree.num_jump(); n++ ) {
2502  if (( fold_tree.upstream_jump_residue(n) == i && fold_tree.downstream_jump_residue(n) == j ) ||
2503  ( fold_tree.upstream_jump_residue(n) == j && fold_tree.downstream_jump_residue(n) == i )){
2504  jump_num=n;
2505  break;
2506  }
2507  }
2508 
2509  // fold_tree.set_jump_atoms( n, five_prime_seq_num , five_prime_atom, three_prime_seq_num , three_prime_atom);
2510  fold_tree.set_jump_atoms( jump_num, rsd1.atom_name( rsd1.chi_atoms(1)[4] ), rsd2.atom_name( rsd2.chi_atoms(1)[4] ) ); //Base atoms...
2511 
2512  if(verbose) Output_fold_tree_info(fold_tree, "New fold_tree with bulge jump point");
2513  pose.fold_tree( fold_tree );
2514 
2515  return cutpoint;
2516  }
2517 
2518  //////////////////////////////////////////////////////////////////////////
2519 
2520 
2521  Size
2522  make_cut_at_moving_suite( core::kinematics::FoldTree & fold_tree, Size const & moving_suite ){
2523 
2524  fold_tree.new_jump( moving_suite, moving_suite+1, moving_suite );
2525 
2526  int const i( moving_suite ), j( moving_suite+1 );
2527  for ( Size n = 1; n <= fold_tree.num_jump(); n++ ) {
2528  if ( fold_tree.upstream_jump_residue(n) == i && fold_tree.downstream_jump_residue(n) == j ) return n;
2529  if ( fold_tree.upstream_jump_residue(n) == j && fold_tree.downstream_jump_residue(n) == i ) return n;
2530  }
2531 
2532  utility_exit_with_message( "Problem with jump number" );
2533 
2534  return 0; // we never get here.
2535 
2536  }
2537 
2538  ///////////////////////////////////////////////////////////////////////
2539 
2540  Size
2541  make_cut_at_moving_suite( pose::Pose & pose, Size const & moving_suite ){
2542 
2543  core::kinematics::FoldTree fold_tree = pose.fold_tree();
2544 
2545  Size jump_number=make_cut_at_moving_suite(fold_tree, moving_suite);
2546 
2547  pose.fold_tree( fold_tree );
2548 
2549  return jump_number;
2550 
2551  }
2552 
2553 
2554 
2555  ////////////////////////////////////////////////////////////////////////
2556  void
2558  for ( Size i = 1; i <= rotamer_list.size(); i++ ) {
2559  pose.set_torsion( rotamer_list[ i ].id , rotamer_list[i].value);
2560  }
2561  }
2562 
2563  //////////////////////////////////////////////////////////////////////////////////////
2564 /*
2565 /// @brief Principal value of angle in degrees on ( -180, 180 ]
2566 template< typename T >
2567 inline
2568 T
2569 principal_angle_degrees( T const & angle )
2570 {
2571  return remainder( angle, T( 360.0 ) );
2572 }
2573 */
2574  bool
2576  using namespace core::scoring;
2577  using namespace core::scoring::rna;
2578 
2579  for(Size seq_num=1; seq_num<=pose.total_residue(); seq_num++){
2580  if (pose.residue(seq_num).aa() == core::chemical::aa_vrt ) continue; //Fang's electron density code
2581  conformation::Residue const & rsd(pose.residue(seq_num));
2582  Real delta = numeric::principal_angle_degrees(rsd.mainchain_torsion( DELTA ));
2583  Real chi = numeric::principal_angle_degrees(rsd.chi(1));
2584  Real nu_2 = numeric::principal_angle_degrees(rsd.chi(2));
2585  Real nu_1 = numeric::principal_angle_degrees(rsd.chi(3));
2586 
2587 
2588 // std::cout << " tag= " << tag << " seq_num= " << seq_num << " delta= " << delta << " chi= " << chi << " nu_2= " << nu_2 << " nu_1= " << nu_1 << std::endl;
2589 
2590  if((delta>-0.01 && delta<0.01) || (nu_2>-0.01 && nu_2<0.01) || (nu_1>-0.01 && nu_1<0.01)){ //observation is that messed up structure will have delta value of zero
2591  std::cout << "Warning: " << tag << " is probably a messed up pose, will be ignored" << std::endl;
2592  std::cout << " seq_num= " << seq_num << " delta= " << delta << " chi= " << chi << " nu_2= " << nu_2 << " nu_1= " << nu_1 << std::endl;
2593  if( (rsd.has_variant_type("VIRTUAL_RNA_RESIDUE")==true) || (rsd.has_variant_type("VIRTUAL_RIBOSE")==true) ){ //Implement on Oct 28,2010
2594  std::cout << "OK lets NOT ignore yet since this rsd has virtual_res or virtual_ribose variant type..continue checking.. " << std::endl;
2595  }else{
2596  return true;
2597  }
2598  }
2599  }
2600  return false;
2601  }
2602 
2603  //////////////////////////////////////////////////////////////////////////////////////
2604  BaseState
2605  Get_residue_base_state(core::pose::Pose const & pose, Size const seq_num){
2606 
2607  using namespace core::scoring;
2608  using namespace core::scoring::rna;
2609 
2610  Real const CHI_CUTOFF=15.0; //Kinda RANDOM..ROUGH average between north chi_anti (~79) and north chi_syn (~-50)
2611 
2612  conformation::Residue const & rsd = pose.residue(seq_num);
2613  Real const chi = numeric::principal_angle_degrees(rsd.chi( CHI - NUM_RNA_MAINCHAIN_TORSIONS ));
2614 
2615  if(chi<=CHI_CUTOFF){
2616  return SYN;
2617  }else{
2618  return ANTI;
2619  }
2620 
2621  }
2622 
2623  //////////////////////////////////////////////////////////////////////////////////////
2624 
2625  PuckerState
2626  Get_residue_pucker_state(core::pose::Pose const & pose, Size const seq_num, bool const verbose){
2627 
2628  using namespace core::scoring;
2629  using namespace core::scoring::rna;
2630 
2631  static scoring::rna::RNA_FittedTorsionInfo const rna_fitted_torsion_info;
2632  Real const DELTA_CUTOFF( rna_fitted_torsion_info.delta_cutoff() );
2633 
2634  if(verbose) std::cout << " DELTA_CUTOFF angle=" << DELTA_CUTOFF;
2635 
2636  conformation::Residue const & rsd(pose.residue(seq_num));
2637  Real delta = numeric::principal_angle_degrees(rsd.mainchain_torsion( DELTA ));
2638 
2639  if((delta>1.0 && delta<179.00)==false){
2640  std::cout << " seq_num= " << seq_num << " delta angle= " << delta << std::endl;
2641 
2642 /////////////////////////
2643  if(pose.residue(seq_num).has_variant_type("VIRTUAL_RNA_RESIDUE")){
2644  std::cout << "Warning: delta angle is out of range for virtual_residue at seq_num "<< seq_num<< "!" << std::endl;
2645  }else{
2646  //This part is now obsolete .... Apr 30, 2010...
2647  //A possibility for a out of range delta is for imported pdbs (upper element of 1q93 for example).
2648  Real principal_delta=numeric::principal_angle_degrees(delta);
2649 
2650  //Consistency check
2651  if(delta<-180){
2652  if( ( delta+359<principal_delta )==false || (delta+361>principal_delta)==false){
2653  utility_exit_with_message( "delta<-180 but delta+359<principal_delta )==false || (delta+361>principal_delta)==false!" );
2654  }
2655  }
2656 
2657  if(delta>180){
2658  if(( delta-359>principal_delta )==false || (delta-361<principal_delta)==false){
2659  utility_exit_with_message( "delta>180 but delta-359>principal_delta )==false || (delta-361<principal_delta)==false!" );
2660  }
2661  }
2662 
2663  delta=principal_delta;
2664 
2665  //Check again
2666  if((delta>1.0 && delta<179.00)==false) utility_exit_with_message( "principal delta angle out of range!" );
2667 //////////////////////////
2668  }
2669  }
2670 
2671  if(verbose) std::cout << " delta angle=" << delta << std::endl;
2672 
2673  if (delta <= DELTA_CUTOFF) {
2674  return NORTH;
2675  } else {
2676  return SOUTH;
2677  }
2678  }
2679 
2680  bool
2681  Is_same_ribose_pucker(core::pose::Pose const & current_pose, core::pose::Pose const & cluster_center_pose, Size const seq_num){
2682  if( Get_residue_pucker_state(current_pose, seq_num)==Get_residue_pucker_state(cluster_center_pose, seq_num) ){
2683  return true;
2684  }else{
2685  return false;
2686  }
2687  }
2688 
2689 
2690  void
2691  sleep(core::Size mseconds )
2692  {
2693  clock_t endwait;
2694  endwait = clock () + mseconds * CLOCKS_PER_SEC/1000 ;
2695  while (clock() < endwait) {}
2696  }
2697 
2698  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
2699 
2700  void
2702 
2703 // using namespace core::chemical;
2704 
2705  Size const nres=pose.total_residue();
2706 
2707  kinematics::FoldTree simple_fold_tree(nres); //Create a simple fold tree
2708 
2709  simple_fold_tree.simple_tree(nres); //Just to make sure.
2710 
2711  pose.fold_tree( simple_fold_tree);
2712  }
2713 
2714  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
2715 
2716 
2717  void
2718  get_atom_coordinates(utility::vector1< std::pair< id::AtomID, numeric::xyzVector<core::Real> > > & xyz_list, Size const & seq_num, core::conformation::Residue const & rsd_at_origin, core::kinematics::Stub const & moving_res_base_stub){
2719 
2720  xyz_list.clear();
2721 
2722  numeric::xyzVector<core::Real> const & new_centroid=moving_res_base_stub.v;
2723  numeric::xyzMatrix< core::Real > const & new_coordinate_matrix=moving_res_base_stub.M;
2724 
2725  for( Size at = 1; at <= rsd_at_origin.natoms(); at++){
2726 
2727  id::AtomID const id( at, seq_num);
2728 
2730 
2731  atom_pos= new_coordinate_matrix * rsd_at_origin.xyz(at); //I think the order here does matter.
2732  atom_pos= atom_pos + new_centroid; //I think the order here does matter.
2733 
2734  xyz_list.push_back(std::make_pair(id, atom_pos));
2735  }
2736 
2737  }
2738 
2739  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
2740 
2741  void
2742  import_pose_from_silent_file(core::pose::Pose & import_pose, std::string const & silent_file , std::string const & input_tag){
2743 
2744  using namespace core::chemical;
2745  using namespace core::conformation;
2746 
2748  residue_type_set( core::chemical::RNA );
2749 
2750  core::io::silent::SilentFileData silent_file_data;
2751  silent_file_data.read_file( silent_file );
2752 
2753  Size num_matching_tag=0;
2754 
2755  for ( core::io::silent::SilentFileData::iterator iter = silent_file_data.begin(), end = silent_file_data.end(); iter != end; ++iter ){
2756  if ( iter->decoy_tag() != input_tag ) continue;
2757  num_matching_tag += 1;
2758  iter->fill_pose( import_pose, *rsd_set );
2759  }
2760 
2761  if( num_matching_tag!=1 ){
2762  utility_exit_with_message( "num_matching_tag=(" + ObjexxFCL::string_of(num_matching_tag) + ")!=1 for tag " + input_tag + " in silent file (" + silent_file + ")!" );
2763  }
2764 
2765  if(check_for_messed_up_structure(import_pose, input_tag)==true){
2766  utility_exit_with_message("import_pose " + input_tag + " from silent_file " + silent_file + " is a messed up pose!");
2767  }
2768 
2769  }
2770 
2771  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
2772 
2773  std::string
2774  path_basename(std::string const full_path){
2775 
2776  size_t found=full_path.rfind('/');
2777 
2778  std::string basename;
2779 
2780  if(found!=std::string::npos){
2781  basename=full_path.substr(found+1);
2782  } else {
2783  basename=full_path;
2784  }
2785 
2786  return basename;
2787  }
2788 
2789  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
2790 
2791 
2792  bool
2793  Is_residues_in_contact(core::Size const & res_ONE, core::pose::Pose const & pose_ONE, core::Size const & res_TWO, core::pose::Pose const & pose_TWO, core::Real const atom_atom_overlap_dist_cutoff, core::Size const num_atom_contacts_cutoff, bool const verbose){
2794 
2795  using namespace ObjexxFCL;
2796 
2797  core::conformation::Residue const & rsd_ONE=pose_ONE.residue(res_ONE);
2798  core::conformation::Residue const & rsd_TWO=pose_TWO.residue(res_TWO);
2799 
2800  Size num_atom_contacts_so_far=0;
2801 
2802  if(num_atom_contacts_cutoff<1){
2803  utility_exit_with_message( "num_atom_contacts_cutoff(" + string_of(num_atom_contacts_cutoff) +")<1!" );
2804  }
2805 
2806  for(Size at_ONE=1; at_ONE<= rsd_ONE.natoms(); at_ONE++){ //include hydrogen atoms
2807  for(Size at_TWO=1; at_TWO<= rsd_TWO.natoms(); at_TWO++){ //include hydrogen atoms
2808 
2809  if(rsd_ONE.atom_type(at_ONE).name()=="VIRT") continue;
2810  if(rsd_TWO.atom_type(at_TWO).name()=="VIRT") continue;
2811 
2812  Real const VDW_radius_ONE=rsd_ONE.atom_type(at_ONE).lj_radius();
2813  Real const VDW_radius_TWO=rsd_TWO.atom_type(at_TWO).lj_radius();
2814 
2815  Real const cutoff_sum_VDW_radius=VDW_radius_ONE+VDW_radius_TWO-atom_atom_overlap_dist_cutoff;
2816 
2817  if(cutoff_sum_VDW_radius<0) utility_exit_with_message("(VDW_radius_ONE+VDW_radius_TWO-atom_atom_overlap_dist_cutoff)<0!!" );
2818 
2819  Real const atom_atom_dist_squared=(rsd_ONE.xyz(at_ONE)-rsd_TWO.xyz(at_TWO)).length_squared();
2820 
2821  if(atom_atom_dist_squared<(cutoff_sum_VDW_radius*cutoff_sum_VDW_radius)){
2822  num_atom_contacts_so_far++;
2823  if(verbose){
2824  std::cout << "res_ONE= " << res_ONE << " res_TWO= " << res_TWO << " num_atom_contacts_so_far= " << num_atom_contacts_so_far << "|";
2825  std::cout << " VDW_radius_ONE= " << VDW_radius_ONE << " VDW_radius_TWO= " << VDW_radius_TWO;
2826  std::cout << " atom_atom_overlap_dist_cutoff= " << atom_atom_overlap_dist_cutoff << " cutoff_sum_VDW_radius= " << cutoff_sum_VDW_radius;
2827  std::cout << " atom_atom_dist= " << (rsd_ONE.xyz(at_ONE)-rsd_TWO.xyz(at_TWO)).length();
2828  std::cout << " " << rsd_ONE.atom_name(at_ONE) << " of res_ONE and " << rsd_TWO.atom_name(at_TWO) << " of res_TWO are in contact! " << std::endl;
2829  }
2830  }
2831 
2832  if(num_atom_contacts_so_far==num_atom_contacts_cutoff){
2833  return true;
2834  }
2835 
2836  if(num_atom_contacts_so_far>num_atom_contacts_cutoff){ //consistency_check
2837  utility_exit_with_message( "num_atom_contacts_so_far(" + string_of(num_atom_contacts_so_far) +")>num_atom_contacts_cutoff(" + string_of(num_atom_contacts_cutoff) +")");
2838  }
2839 
2840 
2841  }
2842  }
2843 
2844  return false;
2845 
2846  }
2847 
2848  //////////////This function was originally part of SWA_RNA_Sampler and used for the Richardson code. Move to Util, so that FloatingBase_Sampler_Util will have access to it////////////
2849  void
2850  set_CCD_torsions_to_zero(core::pose::Pose & pose, Size const five_prime_res){
2851 
2852  using namespace core::chemical;
2853  using namespace core::conformation;
2854  using namespace core::id;
2855  //std::cout << "set_CCD_torsions_to_zero" << std::endl;
2856 
2857  //Size const five_prime_res = job_parameters_->five_prime_chain_break_res();
2858  Size const three_prime_res = five_prime_res+1;
2859 
2860  //Even through there is the chain_break, alpha of 3' and epl and gamma of 5' should be defined due to the existence of the upper and lower variant type atoms.
2861 
2862  for(Size n=1; n<=3; n++){ //alpha, beta, gamma of 3' res
2863  pose.set_torsion( TorsionID( three_prime_res, id::BB, n ), 0.0 );
2864  }
2865 
2866  for(Size n=5; n<=6; n++){ //epsilon and zeta of 5' res
2867  pose.set_torsion( TorsionID( five_prime_res, id::BB, n ), 0.0 );
2868  }
2869 
2870  }
2871 
2872  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
2873  void
2875  utility::vector1< core::Size > & allow_bulge_res_list,
2876  core::pose::Pose const & pose,
2877  bool const verbose){
2878 
2879  if(allow_bulge_res_list.size()!=0){
2880  utility_exit_with_message( "allow_bulge_res_list.size()!=0" );
2881  }
2882 
2883  if(verbose){
2884  std::cout << "allow_bulge_res_list.size()==0, ";
2885  std::cout << "Getting default_allowed_bulge_res!" << std::endl;
2886  }
2887 
2888 
2889 
2890  for(Size seq_num=1; seq_num<=pose.total_residue(); seq_num++){
2891 
2892  //exclude edge residues:
2893  if(seq_num == 1) continue;
2894 
2895  if(seq_num == pose.total_residue()) continue;
2896 
2897  bool Is_cutpoint_closed=false;
2898 
2899  bool Is_cutpoint_lower = pose.residue( seq_num ).has_variant_type(
2901 
2902  bool Is_cutpoint_upper = pose.residue( seq_num ).has_variant_type(
2904 
2905  bool near_cutpoint_closed= Is_cutpoint_lower || Is_cutpoint_upper;
2906 
2907  bool near_cutpoint = pose.fold_tree().is_cutpoint( seq_num ) ||
2908  pose.fold_tree().is_cutpoint( seq_num - 1 );
2909 
2910 
2911  bool near_cutpoint_open = near_cutpoint && !near_cutpoint_closed;
2912 
2913  if( near_cutpoint_open ) continue;
2914 
2915  allow_bulge_res_list.push_back(seq_num);
2916 
2917  }
2918 
2919  }
2920  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
2921 
2922 
2923  core::Size
2925  utility::vector1< core::Size > const & in_allow_bulge_res_list,
2926  core::scoring::ScoreFunctionOP const & scorefxn,
2927  std::string const & tag,
2928  bool const allow_pre_virtualize,
2929  bool const allow_consecutive_bulges,
2930  bool const verbose){
2931 
2932  using namespace core::pose;
2933  using namespace core::scoring;
2934  using namespace ObjexxFCL;
2935 
2936 
2937  Size const total_res=input_pose.total_residue();
2938 
2939  Real const rna_bulge_bonus=( scorefxn->get_weight(rna_bulge) )*10;
2940 
2941  utility::vector1< core::Size > allow_bulge_res_list = in_allow_bulge_res_list;
2942 
2943  if(allow_bulge_res_list.size()==0){
2944  get_default_allowed_bulge_res(allow_bulge_res_list, input_pose, verbose);
2945  }
2946 
2947 
2948  if(verbose){
2949  std::cout << "Enter virtualize_bulges() " << std::endl;
2950  std::cout << "rna_bulge_bonus= " << rna_bulge_bonus << std::endl;
2951  Output_boolean("allow_pre_virtualize= ",allow_pre_virtualize); std::cout << std::endl;
2952  Output_boolean("allow_consecutive_bulges= ",allow_consecutive_bulges); std::cout << std::endl;
2953  Output_seq_num_list("allow_bulge_res_list= ", allow_bulge_res_list, 40);
2954 
2955  //Testing to see if checking in apply_virtual_rna_residue_variant_type can be violated!//////////
2956  pose::Pose testing_pose=input_pose;
2957 
2958  for(Size seq_num=1; seq_num<=total_res; seq_num++){
2959  if (testing_pose.residue(seq_num).aa() == core::chemical::aa_vrt ) continue; //Fang's electron density code
2960  if(Contain_seq_num(seq_num, allow_bulge_res_list)==false ) continue;
2961  apply_virtual_rna_residue_variant_type(testing_pose, seq_num, true /*apply_check*/);
2962  }
2963  //////////////////////////////////////////////////////////////////////////////////////////////////
2964  }
2965 
2966  //////////////////////////////////////////////////////////////////////////////////////////////////////
2967  if(allow_pre_virtualize==false){
2968  for(Size seq_num=1; seq_num<=total_res; seq_num++){
2969  if (input_pose.residue(seq_num).aa() == core::chemical::aa_vrt ) continue; //Fang's electron density code
2970  if(input_pose.residue(seq_num).has_variant_type("VIRTUAL_RNA_RESIDUE")){
2971  utility_exit_with_message( "allow_pre_virtualize==false but seq_num= " + string_of(seq_num) + " is already virtualized!!" );
2972  }
2973  }
2974  }
2975  //////////////////////////////////////////////////////////////////////////////////////////////////////
2976  pose::Pose working_pose=input_pose;
2977  Real const start_score=(*scorefxn)(working_pose);
2978 
2979 
2980  Size num_res_virtualized=0;
2981  Size round_num=0;
2982 
2983  while(true){ //Need multiple round, since virtualizing a particular res will reduce the energy score of neighoring res and might effect wether neighoring res should be virtualized.
2984  pose::Pose base_pose=input_pose;
2985  Real const base_score=(*scorefxn)(base_pose);
2986 
2987  round_num++;
2988 
2989  Size num_res_virtualized_in_this_round=0;
2990 
2991  for(Size seq_num=1; seq_num<=total_res; seq_num++){
2992  if (input_pose.residue(seq_num).aa() == core::chemical::aa_vrt ) continue; //Fang's electron density code
2993  if(Contain_seq_num(seq_num, allow_bulge_res_list)==false ) continue;
2994 
2995  if(input_pose.residue(seq_num).has_variant_type("VIRTUAL_RNA_RESIDUE")){
2996  if(input_pose.residue(seq_num+1).has_variant_type("VIRTUAL_RNA_RESIDUE_UPPER")==false){ //consistency_check
2997  utility_exit_with_message( "seq_num= " + string_of(seq_num) + " is a virtual res but seq_num+1 is not a virtual_res_upper!" );
2998  }
2999 
3000  if(base_pose.residue(seq_num).has_variant_type("VIRTUAL_RNA_RESIDUE")==false){ //consistency check
3001  utility_exit_with_message( "input_pose have virtual at seq_num= " + string_of(seq_num) + " but input_pose doesn't!" );
3002  }
3003 
3004  continue;
3005  }
3006 
3007  if(allow_consecutive_bulges==false){
3008  if( (seq_num+1)<=total_res){
3009  if( input_pose.residue(seq_num+1).has_variant_type("VIRTUAL_RNA_RESIDUE") ) continue;
3010  }
3011 
3012  if( (seq_num-1)>=1){
3013  if( input_pose.residue(seq_num-1).has_variant_type("VIRTUAL_RNA_RESIDUE") ) continue;
3014  }
3015  }
3016 
3017 
3018  working_pose=base_pose;//reset working_pose to base_pose
3019  apply_virtual_rna_residue_variant_type(working_pose, seq_num, true) ;
3020  Real const new_score=(*scorefxn)(working_pose);
3021 
3022  if(new_score<base_score){
3023  num_res_virtualized++;
3024  num_res_virtualized_in_this_round++;
3025 
3026  std::cout << "tag= " << tag << " round_num= " << round_num << " seq_num= " << seq_num << ". new_score (" << new_score << ") is lesser than base_score (" << base_score << "). " << std::endl;
3027 
3028  apply_virtual_rna_residue_variant_type(input_pose, seq_num, true) ;
3029 
3030  }
3031  }
3032 
3033  if(num_res_virtualized_in_this_round==0) break;
3034 
3035  }
3036 
3037 
3038  working_pose=input_pose;
3039  Real const final_score=(*scorefxn)(working_pose);
3040 
3041  if(num_res_virtualized>0){
3042  std::cout << "----------------------------------------------------------" << std::endl;
3043  std::cout << "Inside virtualize_bulges() " << std::endl;
3044  std::cout << "TOTAL_NUM_ROUND= " << round_num << std::endl;
3045  std::cout << "tag= " << tag << std::endl;
3046  std::cout << "num_res_virtualized= " << num_res_virtualized << std::endl;
3047  std::cout << "start_score= " << start_score << std::endl;
3048  std::cout << "final_score= " << final_score << std::endl;
3049  std::cout << "----------------------------------------------------------" << std::endl;
3050 
3051  }
3052 
3053  return num_res_virtualized;
3054 
3055  }
3056 
3057  /////////////////New function on Nov 11, 2010///////////////
3058 
3059  std::string
3061 
3062  std::string tag;
3063 
3064  size_t found=pdb_filename.rfind('/');
3065 
3066  if(found!=std::string::npos){
3067  tag = pdb_filename.substr(found+1);
3068  } else {
3069  tag=pdb_filename;
3070  }
3071 
3072  size_t found_2=tag.rfind(".pdb");
3073 
3074  if(found_2!=std::string::npos){
3075  tag = tag.substr(0,tag.size()-4);
3076  }
3077 
3078  return tag;
3079  }
3080 
3081  //DUPLICATE OF CODE IN StepWiseRNA_JobParameters_Setup.cc
3082  void
3083  move_jump_atom_to_base(core::kinematics::FoldTree & fold_tree, std::string const & working_sequence){
3084 
3085  Size const num_cutpoint=fold_tree.num_cutpoint();
3086 
3087  for ( Size i = 1; i <= num_cutpoint; i++ ) {
3088  Size const k = fold_tree.upstream_jump_residue( i );
3089  Size const m = fold_tree.downstream_jump_residue( i );
3090 
3091  char upstream_res=working_sequence[k-1];
3092  char downstream_res= working_sequence[m-1];
3093 
3094  //Base atoms...
3095  //chi_atoms(1)[4] )= C2 if URA or RCY
3096  //chi_atoms(1)[4] )= C4 if RGU or RAD
3097  std::string upstream_jump_atom;
3098  std::string downstream_jump_atom;
3099 
3100  if(upstream_res=='u' || upstream_res=='c'){
3101  upstream_jump_atom=" C2 ";
3102  }else if(upstream_res=='a' || upstream_res=='g'){
3103  upstream_jump_atom=" C4 ";
3104  }else{
3105  utility_exit_with_message( "Invalid upstream_res!!" );
3106  }
3107 
3108  if(downstream_res=='u' || downstream_res=='c'){
3109  downstream_jump_atom=" C2 ";
3110  }else if(downstream_res=='a' || downstream_res=='g'){
3111  downstream_jump_atom=" C4 ";
3112  }else{
3113  utility_exit_with_message( "Invalid downstream_res!!" );
3114  }
3115 
3116  std::cout << "upstream_res= " << k << upstream_res << " upstream_jump_atom= " << upstream_jump_atom;
3117  std::cout << " downstream_res= " << k << downstream_res << " downstream_jump_atom= " << downstream_jump_atom << std::endl;
3118 
3119  fold_tree.set_jump_atoms( i, downstream_jump_atom, upstream_jump_atom);
3120 
3121  }
3122  }
3123 
3124 
3125  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
3126  void
3127  print_JobParameters_info(StepWiseRNA_JobParametersCOP const & const_JP, std::string const JP_name, bool const Is_simple_full_length_JP){
3128 
3130 
3131  (*JP)=(*const_JP);
3132 
3133  print_JobParameters_info(JP, JP_name, Is_simple_full_length_JP);
3134 
3135  }
3136 
3137 
3138  void
3139  print_JobParameters_info(StepWiseRNA_JobParametersOP const & JP, std::string const JP_name, bool const Is_simple_full_length_JP){
3140 
3141  using namespace ObjexxFCL;
3142 
3143  Output_title_text("printing JobParameters Information for " + JP_name );
3144 
3145  utility::vector1< Size > empty_seq_num_list;
3146  empty_seq_num_list.clear();
3147 
3148  std::cout << "full_sequence= " << JP->full_sequence();
3149  std::cout << " working_sequence= " << JP->working_sequence();
3150  std::cout << " moving_res= " << JP->moving_res();
3151  std::cout << " working_moving_res= " << JP->working_moving_res();
3152  std::cout << " working_moving_suite= " << JP->working_moving_suite() << std::endl;
3153 
3154 
3155  std::cout << "gap_size= " << JP->gap_size();
3156  std::cout << " five_prime_chain_break_res= " << JP->five_prime_chain_break_res();
3157  Output_boolean(" Is_prepend= ", JP->Is_prepend() ) ;
3158  Output_boolean(" Is_internal= " , JP->Is_internal() );
3159  Output_boolean(" output_extra_RMSDs= ", JP-> output_extra_RMSDs() ); std::cout << std::endl;
3160 
3161 
3162  //std::map< core::Size, core::Size > full_to_sub_;
3163  //std::map< core::Size, core::Size > sub_to_full_;
3164 
3165  //utility::vector1< std::pair< core::Size, core::Size > > chain_boundaries_;
3166 
3167  // ObjexxFCL::FArray1D< bool > partition_definition_;
3168 
3169  //core::pose::PoseOP working_native_pose_;
3170 
3171  std::cout << "------------full_stuff------------" << std::endl;
3172  Output_bool_list("is_working_res= " , JP->is_working_res() );
3173 
3174  for(Size n=1; n<=JP->input_res_vectors().size(); n++){
3175  Output_seq_num_list("input_res_vectors[" + string_of(n) + "]", JP->input_res_vectors()[n] );
3176  }
3177  Output_seq_num_list("global_sample_res_list= ", JP->global_sample_res_list() );
3178 
3179  if(JP->force_syn_chi_res_list().size()>0) Output_seq_num_list("force_syn_chi_res_list= " , JP->force_syn_chi_res_list() );
3180  if(JP->force_north_ribose_list().size()>0) Output_seq_num_list("force_north_ribose_list= ", JP->force_north_ribose_list() );
3181  if(JP->force_south_ribose_list().size()>0) Output_seq_num_list("force_south_ribose_list= ", JP->force_south_ribose_list() );
3182  if(JP->protonated_H1_adenosine_list().size()>0) Output_seq_num_list("protonated_H1_adenosine_list ", JP->protonated_H1_adenosine_list() );
3183 
3184 
3185 
3186 
3187 
3188  Output_is_prepend_map("Is_prepend_map= ", JP->Is_prepend_map() , JP->full_sequence().size());
3189  Output_seq_num_list("rmsd_res_list= ", JP->rmsd_res_list() );
3190 
3191  Output_seq_num_list("native_alignment=", JP->native_alignment() );
3192  Output_seq_num_list("cutpoint_closed_list=", JP->cutpoint_closed_list() );
3193 
3194 
3195  std::cout << "------------working_stuff------------" << std::endl;
3196 
3197  Output_seq_num_list("working_global_sample_res_list= ", JP->working_global_sample_res_list() );
3198  if(JP->force_syn_chi_res_list().size()>0) Output_seq_num_list("working_force_syn_chi_res_list= ", JP->working_force_syn_chi_res_list() );
3199  if(JP->force_north_ribose_list().size()>0) Output_seq_num_list("working_force_north_ribose_list= ", JP->working_force_north_ribose_list() );
3200  if(JP->force_south_ribose_list().size()>0) Output_seq_num_list("working_force_south_ribose_list= ", JP->working_force_south_ribose_list() );
3201  if(JP->protonated_H1_adenosine_list().size()>0) Output_seq_num_list("working_protonated_H1_adenosine_list= ", JP->working_protonated_H1_adenosine_list() );
3202 
3203 
3204  Output_seq_num_list("working_fixed_res= " , JP->working_fixed_res() );
3205 
3206  if(Is_simple_full_length_JP==false){
3207  Output_seq_num_list("working_moving_res_list= " , JP->working_moving_res_list() );
3208  Output_seq_num_list("working_moving_suite_list= " , JP->working_moving_suite_list() );
3209  }else{
3210  Output_seq_num_list("line_filler " , empty_seq_num_list );
3211  Output_seq_num_list("line_filler " , empty_seq_num_list );
3212  }
3213 
3214  Output_seq_num_list("working_terminal_res= ", JP->working_terminal_res() );
3215  Output_seq_num_list("working_moving_partition_pos= ", JP->working_moving_partition_pos() );
3216 
3217  Output_seq_num_list("working_best_alignment=", JP->working_best_alignment() );
3218  Output_seq_num_list("working_native_alignment=", JP->working_native_alignment() );
3219 
3220  if(Is_simple_full_length_JP==false){
3221  utility::vector1<bool > vector1_partition_definition;
3222 
3223  for(Size n=1; n<=JP->partition_definition().size(); n++){
3224  vector1_partition_definition.push_back(JP->partition_definition()(n) );
3225  }
3226 
3227  Output_bool_list("partition_definition=", vector1_partition_definition );
3228 
3229  std::cout << "root_res= " << JP->fold_tree().root() << std::endl;
3230  Output_fold_tree_info(JP->fold_tree() , "fold_tree");
3231  }
3232 
3233  Output_title_text("");
3234 
3235 
3236  }
3237 
3238 
3239  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
3240 /*
3241  void
3242  process_mem_usage(double& vm_usage, double& resident_set, core::Size count){
3243  using std::ios_base;
3244  using std::ifstream;
3245  using std::string;
3246 
3247  vm_usage = 0.0;
3248  resident_set = 0.0;
3249 
3250  // 'file' stat seems to give the most reliable results
3251  //
3252  ifstream stat_stream("/proc/self/stat",ios_base::in);
3253 
3254  // dummy vars for leading entries in stat that we don't care about
3255  //
3256  string pid, comm, state, ppid, pgrp, session, tty_nr;
3257  string tpgid, flags, minflt, cminflt, majflt, cmajflt;
3258  string utime, stime, cutime, cstime, priority, nice;
3259  string O, itrealvalue, starttime;
3260 
3261  // the two fields we want
3262  //
3263  unsigned long vsize;
3264  long rss;
3265 
3266  stat_stream >> pid >> comm >> state >> ppid >> pgrp >> session >> tty_nr
3267  >> tpgid >> flags >> minflt >> cminflt >> majflt >> cmajflt
3268  >> utime >> stime >> cutime >> cstime >> priority >> nice
3269  >> O >> itrealvalue >> starttime >> vsize >> rss; // don't care about the rest
3270 
3271  long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; // in case x86-64 is configured to use 2MB pages
3272  vm_usage = vsize / 1024.0;
3273  resident_set = rss * page_size_kb;
3274 
3275 
3276  std::cout << "memory_usage= " << count << " " << pid << " " << comm << " " << state << " " << ppid << " " << pgrp << " " << session << " " << tty_nr << " " << tpgid << " " << flags << " " << minflt << " " << cminflt << " " << majflt << " " << cmajflt << " "<< utime << " " << stime << " " << cutime << " " << cstime << " " << priority << " "<< nice << " "<< O << " "<< itrealvalue << " "<< starttime << " "<< vsize << " " << rss << std::endl;
3277 
3278  }
3279 */
3280 
3281 /*
3282  void
3283  add_native_base_pair_stats( core::io::silent::SilentStructOP & s, pose::Pose const & native_pose, utility::vector1 < core::Size > const & input_rmsd_res_list){
3284 
3285  using namespace protocols::rna;
3286  using namespace conformation;
3287  using namespace scoring::rna;
3288  //using namespace core::pose;
3289 
3290  utility::vector1 < core::Size > act_rmsd_res_list;
3291  act_rmsd_res_list.clear();
3292 
3293  for(Size n=1; n<=input_rmsd_res_list.size(); n++){
3294 
3295  Size const seq_num=input_rmsd_res_list[n];
3296 
3297  if(Is_virtual_base(native_pose.residue(seq_num))) continue;
3298 
3299  act_rmsd_res_list.push_back(seq_num);
3300 
3301  }
3302 
3303  utility::vector1< core::scoring::rna::Base_pair> const base_pair_list = classify_base_pairs_parin( native_pose, act_rmsd_res_list);
3304 
3305  Size native_WC( 0 ), native_NWC( 0 );
3306 
3307  for ( Size n = 1; n <= base_pair_list.size(); n++ ) {
3308 
3309  core::scoring::rna::Base_pair const base_pair = base_pair_list[ n ];
3310 
3311  Residue const & rsd_1= native_pose.residue( base_pair.res1 );
3312  Residue const & rsd_2= native_pose.residue( base_pair.res2 );
3313 
3314  if ( ( base_pair.edge1 == WATSON_CRICK && base_pair.edge2 == WATSON_CRICK && base_pair.orientation == 1 ) && core::scoring::rna::possibly_canonical( rsd_1.aa(), rsd_2.aa() ) ){
3315  native_WC++;
3316  } else {
3317  native_NWC++;
3318  }
3319  }
3320  s->add_energy( "NAT_WC", native_WC );
3321  s->add_energy( "NAT_NWC", native_NWC );
3322 
3323  }
3324 */
3325 
3326 /* This requires my version of the RNA_BasePairClassifier.cc which I decide not to commit to trunk (Parin Sripakdeevong 27/12/2011)
3327  void
3328  add_base_pair_stats( core::io::silent::SilentStructOP & s, pose::Pose const & pose, pose::Pose const & native_pose, utility::vector1 < core::Size > const & input_rmsd_res_list){
3329 
3330 
3331  using namespace scoring::rna;
3332  using namespace core::conformation;
3333  using namespace protocols::rna;
3334 
3335  bool verbose=false;
3336 
3337  utility::vector1 < core::Size > act_rmsd_res_list;
3338  act_rmsd_res_list.clear();
3339 
3340  for(Size n=1; n<=input_rmsd_res_list.size(); n++){
3341 
3342  Size const seq_num=input_rmsd_res_list[n];
3343 
3344  if(Is_virtual_base(native_pose.residue(seq_num))) continue;
3345 
3346  act_rmsd_res_list.push_back(seq_num);
3347 
3348  }
3349 
3350  utility::vector1< core::scoring::rna::Base_pair> const model_base_pair_list = classify_base_pairs_strict( pose, act_rmsd_res_list);
3351 
3352  utility::vector1< core::scoring::rna::Base_pair> const native_base_pair_list = classify_base_pairs_strict( native_pose, act_rmsd_res_list);
3353 
3354  //std::cout << "BLAH" << std::endl;
3355 
3356  Size native_WC=0;
3357  Size native_NWC=0;
3358  Size recovered_WC=0;
3359  Size recovered_NWC=0;
3360 
3361 
3362  for ( Size n = 1; n <= native_base_pair_list.size(); n++ ) {
3363 
3364  core::scoring::rna::Base_pair const native_base_pair = native_base_pair_list[ n ];
3365 
3366  Residue const & rsd_1( native_pose.residue( native_base_pair.res1 ) );
3367  Residue const & rsd_2( native_pose.residue( native_base_pair.res2 ) );
3368 
3369  if ( ( native_base_pair.edge1 == WATSON_CRICK && native_base_pair.edge2 == WATSON_CRICK && native_base_pair.orientation == 1 ) && possibly_canonical( rsd_1.aa(), rsd_2.aa() ) ) {
3370  native_WC++;
3371 
3372  if ( check_in_base_pair_list( native_base_pair , model_base_pair_list ) ) recovered_WC++;
3373 
3374  } else {
3375  native_NWC++;
3376 
3377  if ( check_in_base_pair_list( native_base_pair , model_base_pair_list ) ){
3378  recovered_NWC++;
3379  } else {
3380  if(verbose){
3381  std::cout << "Missing native base pair " << pose.residue( native_base_pair.res1 ).name1() << " " << pose.residue( native_base_pair.res2 ).name1() << " ";
3382  native_base_pair.print_info(); std::cout << std::endl;
3383  }
3384  }
3385  }
3386  }
3387 
3388  s->add_energy( "NAT_WC", native_WC );
3389  s->add_energy( "NAT_NWC", native_NWC );
3390 
3391  s->add_energy( "REC_WC" , recovered_WC );
3392  s->add_energy( "REC_NWC", recovered_NWC );
3393 
3394  }
3395 */
3396 
3397  void
3398  set_nucleotide_to_A_form(pose::Pose & pose, Size const seq_num){
3399  //Torsion value extracted from 3DNA (webiste) (A-U BP repeating) idealized A-form helix. Note that bond angle and bond length of idealized Rosetta doesn't exactly match the values in 3DNA
3400 
3401  using namespace core::id;
3402 
3403  pose.set_torsion( TorsionID( seq_num, id::BB, 1 ), -68.9 ); //alpha
3404  pose.set_torsion( TorsionID( seq_num, id::BB, 2 ), 179.5 ); //beta
3405  pose.set_torsion( TorsionID( seq_num, id::BB, 3 ), 54.5 ); //gamma
3406  pose.set_torsion( TorsionID( seq_num, id::BB, 5 ), -154.0 ); //epsilon
3407  pose.set_torsion( TorsionID( seq_num, id::BB, 6 ), -70.8 ); //zeta
3408 
3409  pose.set_torsion( TorsionID( seq_num, id::BB, 4 ), 82.2 ); //delta
3410  pose.set_torsion( TorsionID( seq_num, id::CHI, 1 ), 79.2 );//chi
3411  pose.set_torsion( TorsionID( seq_num, id::CHI, 2 ), 36.9 ); //nu2
3412  pose.set_torsion( TorsionID( seq_num, id::CHI, 3 ), 94.7 ); //nu1
3413 
3414 
3415  }
3416 /////////////////////////////////////////////////////////////////////////////////////////////
3417  void
3418  print_atom_info(pose::Pose const & pose, Size const seq_num, std::string const pose_name){
3419  std::cout << "print_atom_info for pose: " << pose_name << " seq_num= " << seq_num << std::endl;
3420 
3421  conformation::Residue const & rsd=pose.residue(seq_num); //static_pose
3422 
3423  for(Size at=1; at<=rsd.natoms(); at++){ //I wonder if we should just consider heavy atom? (rsd_1.nheavyatoms())
3424 
3425  std::cout << "atom=" << at << "|name=" << rsd.type().atom_name(at) << "|type=" << rsd.atom_type(at).name();
3426  std::cout << "|element()=" << rsd.atom_type(at).element() << "|" << std::endl;
3427 
3428  }
3429 
3430  }
3431 /////////////////////////////////////////////////////////////////////////////////////////////
3432  void
3433  print_individual_atom_info(core::conformation::Residue const & rsd, Size const atomno, std::string const rsd_name){
3434  std::cout << "individual_atom_info: rsd_name " << rsd_name;
3435 
3436  std::cout << " atom=" << atomno << "|name=" << rsd.type().atom_name(atomno) << "|type=" << rsd.atom_type(atomno).name();
3437  std::cout << "|element()=" << rsd.atom_type(atomno).element() << "|" << std::endl;
3438 
3439  }
3440 
3441 /////////////////////////////////////////////////////////////////////////////////////////////
3442 
3443  void
3444  print_base_state(std::string const tag, BaseState const base_state){
3445 
3446  std::string base_state_string="";
3447 
3448  if(base_state==BOTH){
3449  base_state_string="BOTH";
3450  }else if(base_state==ANTI){
3451  base_state_string="ANTI";
3452  }else if(base_state==SYN){
3453  base_state_string="SYN" ;
3454  }else if(base_state==NONE){
3455  base_state_string="NONE";
3456  }else{
3457  std::cout << "Invalid base state=" << base_state << std::endl;
3458  utility_exit_with_message( "Invalid base state!" );
3459  }
3460 
3461  std::cout << tag << std::setw(4) << std::left << base_state_string << " ";
3462  }
3463 
3464 /////////////////////////////////////////////////////////////////////////////////////////////
3465 
3466  void
3467  print_ribose_pucker_state(std::string const tag, PuckerState const pucker_state){
3468 
3469  std::string pucker_state_string="";
3470 
3471  if(pucker_state==NORTH){
3472  pucker_state_string="NORTH";
3473  }else if(pucker_state==SOUTH){
3474  pucker_state_string="SOUTH";
3475  }else if(pucker_state==ALL){
3476  pucker_state_string="ALL";
3477  }else{
3478  std::cout << "Invalid pucker state=" << pucker_state << std::endl;
3479  utility_exit_with_message( "Invalid pucker state!" );
3480  }
3481 
3482  std::cout << tag << std::setw(5) << std::left << pucker_state_string << " ";
3483 
3484  }
3485 
3486  //////////July 20, 2011, common scorefunctions..Used to be part of StepWiseRNA_ResidueSampler.cc
3487  void
3489  core::scoring::ScoreFunctionOP & sampling_scorefxn_,
3490  core::scoring::ScoreFunctionOP & atr_rep_screening_scorefxn_,
3491  core::scoring::ScoreFunctionOP & chainbreak_scorefxn_,
3492  core::scoring::ScoreFunctionOP & o2star_pack_scorefxn_){
3493 
3494 
3495  using namespace core::scoring;
3496 
3497  ///////////////////////////////////////////////////////////////////
3498  // Bare minimum to check for contact (fa_atr) but not clash (fa_rep)
3499  atr_rep_screening_scorefxn_ = new ScoreFunction;
3500  atr_rep_screening_scorefxn_->set_weight( fa_atr , 0.23 );
3501  atr_rep_screening_scorefxn_->set_weight( fa_rep , 0.12 );
3502 
3503  ///////////////////////////////////////////////////////////////////
3504  chainbreak_scorefxn_ = new ScoreFunction;
3505  chainbreak_scorefxn_->set_weight( angle_constraint, 1.0 );
3506  chainbreak_scorefxn_->set_weight( atom_pair_constraint, 1.0 );
3507 
3508  ////////////////////Setup sampling scoring//////////////////////////////////////////////////////////////////////////////
3509  //1. Want to increase fa_rep during the minimization phase but want to keep it at 0.12 during the sample phase
3510  //2. Sugar scoring is always turned off during sampling stage since it screw up pose selection. (TURN IT BACK ON: RD 01/31/2010)
3511  //3. Harmonic and Linear Chain_break scoring is always turned off during sampling stage
3512  sampling_scorefxn_ = scorefxn_->clone();
3513 
3514  // sampling_scorefxn_->set_weight( rna_sugar_close, 0.0 ); (TURN IT BACK ON: RD 01/31/2010)
3515 
3516  sampling_scorefxn_->set_weight( fa_rep, 0.12 );
3517  //Only important only if fa_rep score in weight file is not 0.12..want to make sure that changing fa_rep in weight file doesn't effect sampling process. May 23 2010 Parin S.
3518 
3519  sampling_scorefxn_->set_weight( linear_chainbreak, 0.0);
3520  sampling_scorefxn_->set_weight( chainbreak, 0.0 );
3521  sampling_scorefxn_->set_weight( angle_constraint, 0.0 );
3522  sampling_scorefxn_->set_weight( atom_pair_constraint, 0.0 );
3523  //This makes sure that there are no chain_break score involve in the full_score screening.
3524  //This works since by the time a pose reach full_score screening, it must already pass chain_break screening, May 23, 2010 Parin S.
3525 
3526 
3527 
3528  //////////////////////////////////////////////TESTING/////////////////////////////////////////////////
3529  //////////////////////////////////////////////TESTING/////////////////////////////////////////////////
3530  // Note that: rna_torsion, rna_sugar_close, fa_stack not optimized -- also irrelevant for 2'-OH sampling.
3531  //just a comparison. This is extremely slow. Would need to implement trie
3532  // for geom_sol, lk_nonpolar, and hackelec... Not too hard, but I don't feel like doing it now. (Rhiju)
3533  //o2star_pack_scorefxn_ = sampling_scorefxn_->clone();
3534  /*
3535  //Parin July 21, 2011
3536  o2star_pack_scorefxn_ = new ScoreFunction;
3537  // Each of the following terms have been pretty optimized for the packer (trie, etc.)
3538  o2star_pack_scorefxn_->set_weight( fa_atr, sampling_scorefxn_->get_weight( fa_atr ) );
3539  o2star_pack_scorefxn_->set_weight( fa_rep, sampling_scorefxn_->get_weight( fa_rep ) );
3540  o2star_pack_scorefxn_->set_weight( hbond_lr_bb_sc, sampling_scorefxn_->get_weight( hbond_lr_bb_sc ) );
3541  o2star_pack_scorefxn_->set_weight( hbond_sr_bb_sc, sampling_scorefxn_->get_weight( hbond_sr_bb_sc ) );
3542  o2star_pack_scorefxn_->set_weight( hbond_sc, sampling_scorefxn_->get_weight( hbond_sc ) );
3543  o2star_pack_scorefxn_->set_energy_method_options( sampling_scorefxn_->energy_method_options() );
3544  o2star_pack_scorefxn_->set_weight( lk_nonpolar, sampling_scorefxn_->get_weight( lk_nonpolar ) ); //FIX THIS ON JULY 21, 2011. TOO EXPENSIVE!
3545  o2star_pack_scorefxn_->set_weight( lk_polar, sampling_scorefxn_->get_weight( geom_sol ) ); //FIX THIS ON JULY 21, 2011. TOO EXPENSIVE!
3546  // note that geom_sol is not optimized well --> replace with lk_sol for now.
3547  */
3548  //////////////////////////////////////////////////////////////////////////////////////////////////////
3549  //////////////////////////////////////////////////////////////////////////////////////////////////////
3550 
3551 
3552  o2star_pack_scorefxn_ = new ScoreFunction;
3553  // Each of the following terms have been pretty optimized for the packer (trie, etc.)
3554  o2star_pack_scorefxn_->set_weight( fa_atr, sampling_scorefxn_->get_weight( fa_atr ) );
3555  o2star_pack_scorefxn_->set_weight( fa_rep, sampling_scorefxn_->get_weight( fa_rep ) );
3556  o2star_pack_scorefxn_->set_weight( hbond_lr_bb_sc, sampling_scorefxn_->get_weight( hbond_lr_bb_sc ) );
3557  o2star_pack_scorefxn_->set_weight( hbond_sr_bb_sc, sampling_scorefxn_->get_weight( hbond_sr_bb_sc ) );
3558  o2star_pack_scorefxn_->set_weight( hbond_sc, sampling_scorefxn_->get_weight( hbond_sc ) );
3559  ///Warning, don't include hbond_intra, since hbond_intra HAVE NOT been been optimized for packing!
3560 
3561  o2star_pack_scorefxn_->set_weight( fa_sol, sampling_scorefxn_->get_weight( lk_nonpolar ) ); //// note that geom_sol is not optimized well --> replace with lk_sol for now. //IS THIS A MISTAKE???
3562 
3563  o2star_pack_scorefxn_->set_energy_method_options( sampling_scorefxn_->energy_method_options() ); //This set NO_HB_ENV_DEP, INCLUDE_INTRA_RES_RNA_HB and etcs.
3564 
3565  }
3566 
3567  void
3568  copy_all_o2star_torsions(core::pose::Pose & mod_pose, core::pose::Pose const & template_pose){
3569 
3570  using namespace core::id;
3571  using namespace core::conformation;
3572 
3573  if( template_pose.total_residue()!=mod_pose.total_residue() ){
3574  utility_exit_with_message("template_pose.total_residue()!=mod_pose.total_residue()");
3575  }
3576 
3577  utility::vector1< bool > do_update_list(template_pose.total_residue(), false);
3578 
3579  for(Size seq_num=1; seq_num<=template_pose.total_residue(); seq_num++){
3580  if (template_pose.residue(seq_num).aa() == core::chemical::aa_vrt ) continue; //Fang's electron density code
3581  if(std::abs( template_pose.torsion(TorsionID( seq_num, id::CHI, 4 )) - mod_pose.torsion(TorsionID( seq_num, id::CHI, 4 )) ) > 0.001 ){
3582  //the two o2star torsions are not the same! Basically don't want to trigger refolding if need not to.
3583  do_update_list[seq_num]=true;
3584  }
3585  }
3586 
3587  for(Size seq_num=1; seq_num<=template_pose.total_residue(); seq_num++){
3588  if (mod_pose.residue(seq_num).aa() == core::chemical::aa_vrt ) continue; //Fang's electron density code
3589  if(do_update_list[seq_num]==true){
3590  mod_pose.set_torsion( TorsionID( seq_num, id::CHI, 4 ), template_pose.torsion(TorsionID( seq_num, id::CHI, 4 ) ) );
3591  }
3592  }
3593 
3594  }
3595 
3596 
3597 /////////////////////////////////////////////////////////////////////////////////////////////
3598 ///According to Kyle B., DFPMIN should be start enough to determine what is the ideal step size. However, the exception is the first minimizing step which could lead to "blow up" error!
3599 ///To prevent can create new scorefxn with scaling_factor=0.1 and minimize with this new score function Sept 20, 2011. Parin S.
3600 
3602 rescale_scorefxn(core::scoring::ScoreFunctionOP const & starting_scorefxn, Real const scaling_factor){
3603 
3604  using namespace core::scoring;
3605 
3606  core::scoring::ScoreFunctionOP rescaled_scorefxn = starting_scorefxn->clone();
3607 
3608  core::Size non_zero_weight=0;
3609 
3610  show_scorefxn_weight_lines(rescaled_scorefxn, "BEFORE REWEIGHT");
3611 
3612  for(Size n=1; n<=n_score_types; n++){
3613 
3614  core::Real const old_weight=rescaled_scorefxn->get_weight( ScoreType(n) );
3615 
3616  if ( old_weight != 0.0 ) {
3617  non_zero_weight+=1;
3618  rescaled_scorefxn->set_weight(ScoreType(n), old_weight*scaling_factor);
3619  }
3620  }
3621 
3622  std::cout << std::endl;
3623 
3624 
3625  std::cout << "n_score_types= " << int(n_score_types) << " non_zero_weight= " << non_zero_weight << " scaling_factor= " << scaling_factor << std::endl;
3626 
3627 
3628  show_scorefxn_weight_lines(rescaled_scorefxn, "AFTER REWEIGHT");
3629 
3630  return rescaled_scorefxn;
3631 
3632 }
3633 
3634 /////////////////////////////////////////////////////////////////////////////////////////////
3635 
3636 void
3638 
3639  using namespace core::scoring;
3640  using namespace ObjexxFCL::fmt;
3641 
3642  std::cout << "----------------" << title << "----------------" << std::endl;
3643 
3644  std::cout << "----------------------------------------------\n";
3645  std::cout << " Scores Weight\n";
3646  std::cout << "----------------------------------------------\n";
3647 
3648  pose::Pose empty_pose=*(new pose::Pose);
3649 
3650  for(Size n=1; n<=n_score_types; n++){
3651 
3652  core::Real const weight=scorefxn->get_weight( ScoreType(n) );
3653 
3654  if(weight!= 0.0){
3655  std::cout << ' ' << LJ(30,ScoreType(n)) << ' '<< F(11,5, weight ) << std::endl;
3656  }
3657  }
3658 
3659  std::string dash_string="";
3660  for(Size n=1; n<=title.size(); n++){
3661  dash_string+="-";
3662  }
3663 
3664  std::cout << "----------------" << dash_string << "----------------" << std::endl;
3665 
3666 }
3667 
3668 /////////////////////////////////////////////////////////////////////////////////////////////
3669 
3670 
3671 
3672 
3673 }
3674 }
3675 }