Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StepWiseRNA_VDW_Bin_Screener.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_VDW_Bin_Screener.cc
11 /// @brief Very fast version of VWD replusion screening
12 /// @detailed
13 /// @author Parin Sripakdeevong
14 
15 
16 //////////////////////////////////
19 #include <protocols/swa/StepWiseUtil.hh> //Dec 23, 2011
24 
26 //////////////////////////////////
27 
28 #include <core/types.hh>
30 #include <core/chemical/util.hh>
36 #include <core/pose/Pose.hh>
39 
40 #include <core/id/AtomID_Map.hh>
41 
43 //#include <core/scoring/ScoreFunction.hh>
44 
45 #include <numeric/conversions.hh>
46 
47 #include <iostream>
48 #include <fstream>
49 #include <sstream>
50 #include <ObjexxFCL/format.hh>
51 #include <set>
52 #include <time.h>
53 
54 
55  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
56 
57 
58 
59 using namespace core;
60 
61 namespace protocols {
62 namespace swa {
63 namespace rna {
64 
65  //constructor!
66  StepWiseRNA_VDW_Bin_Screener::StepWiseRNA_VDW_Bin_Screener():
67 // max_distance_(40.0),
68  max_distance_(55.0), //Nov 7, Nov_1_2r8s_TLR was barely out of range. atom_pos_bin.z= 1003
69 // max_distance_(50.0), //Oct 27, Change from 60.0 to 50.0 after one slave node on Biox clash probably due to memory limit (but 60.0 should use only 200 MB!)
70 // max_distance_(60.0), //Oct 26, Change from 40.0 to 60.0. In rare instances, minimization will move moving_res and reference res very far from initial pos of reference res.
71  atom_bin_size_(0.1),
72  bin_min_( int(-max_distance_/atom_bin_size_) ),
73  bin_max_( int(max_distance_/atom_bin_size_) ), //used to be (max_distance_/atom_bin_size_)-1, change on Nov 7, 2010
74  bin_offset_( std::abs(bin_min_)+1 ),
75  num_clash_atom_cutoff_(3), //num of clash required to be considered a clash
76  write_to_file_(false), //for debugging
77  Is_reference_xyz_setup_(false),
78  Is_VDW_screen_bin_setup_(false),
79  user_inputted_VDW_screen_pose_(false),
80  VDW_rep_alignment_RMSD_CUTOFF_(0.001),
81  tolerate_off_range_atom_bin_(true), //Use to be false before Dec 15, 2010
82  num_atom_pos_bin_out_of_range_message_outputted_(0),
83  VDW_rep_screen_with_physical_pose_verbose_(true),
84  physical_pose_clash_dist_cutoff_(1.2),
85  use_VDW_rep_pose_for_screening_(false), //Use actual VDW_screener_pose instead of bin for screening. This mode is slow but more robust. Feb 20, 2011
86  output_pdb_(false)
87  {
88 
89  //March 23,2011:
90  //For VDW_rep_screen_with_physical_pose: use 1.2 Angstrom Cutoff (In constrast use 0.8 Angstrom in create_VDW_screen_bin). Reasoning is as follow:
91  //Problem is that 0.8 Angstrom is not large enough to account for short hbond dist that it lesser than sum of VDW_radius
92  //For Example the shortest H_bond can be 1.6 Angstrom. If donor is nitrogen then H_radius=1.20, N_radius=1.55, SUM=2.75. So cutoff should be 2.75-1.6=1.15~1.2
93  //In create_VDW_screen_bin, this problem is ameliorate by using VDW_radius=1.0 for all moving_res atoms.
94 
95  //In the VDW_bin, the moving_res atom radius is assumed to be 1.0 Angstrom so this give at least another 0.2 Angstrom
96  //Crap...THIS CODE AUUMSE that residue next to the sampling res (on both 3' and 5' end) need to either be virtualized or not be part of the VDW_rep_screener in the first place.
97  //1.For working_pose VDW_rep ....ok since the bulge res is always virtualized. THIS MEANS THAT RECENT LONG_LOOP RUNS ARE BUGGY!
98  //2. CRAP FOR PREPEND, the PHOSPHATE IS NOT VIRTUALIZED since ignore_res_list is EMPTY!!
99  //3. This mean that main problem is with the APPEND with building nucleotide (1st step and at chain_closure)
100 
101  //Play it safe, use num_clash_atom_cutoff_(3):
102  // ....with num_clash_atom cutoff equals 1...actually got full_atom_rep_count:43540/43622 bin_rep: 55456/682546
103  // ....with num_clash_atom cutoff equals 3...actually got full_atom_rep_count:43622/43622 bin_rep: 73868/682546
104 
105 
106  }
107 
108 //////////////////////Note////////////////////////////
109 //for max_distance=50.0, atom_bin_size=0.1
110 //-->bin_min=-500, bin_max=500, bin_offset=501
111 //x_pos -49.95 -0.05 0.05 49.95
112 //x_pos/atom_bin_size -499 0 0 499
113 //if(x_pos<0) -1 -500 -1 0 499
114 //+bin_offset 1 500 501 1000
115 
116 //////////////////////////////////////////////////////
117 
118  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
119 
120  //destructor
122  {}
123 
124  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
125 
126  void
128 
129  bool const verbose=true;
130 
131  if(verbose) Output_title_text("Enter StepWiseRNA_VDW_Bin_Screener::setup_using_working_pose");
132 
133  Size const reference_res( job_parameters->working_reference_res() ); //the last static_residues that this attach to the moving residues
134 
135  numeric::xyzVector<core::Real> const reference_xyz=core::scoring::rna::get_rna_base_centroid( const_working_pose.residue( reference_res ) , false /*verbose*/);
136 
137 
138  pose::Pose working_pose=const_working_pose; //Feb 20, 2011..just to make sure that the o2star hydrogens are virtualized. Since this hydrogen can vary during sampling.
139  Add_virtual_O2Star_hydrogen( working_pose);
140 
141  create_VDW_screen_bin(working_pose, job_parameters->working_moving_res_list(), job_parameters->Is_prepend(), reference_xyz, verbose);
142 
143  if(verbose) Output_title_text("Exit StepWiseRNA_VDW_Bin_Screener::setup_using_working_pose");
144 
145  }
146 
147  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
148  //June 04, 2011. Instead of deleting the matching_res..just return it!
151  core::pose::Pose const & working_pose,
152  utility::vector1< core::Size > const & VDW_rep_screen_align_res,
153  utility::vector1< core::Size > const & working_align_res,
154  std::map< core::Size, core::Size > & full_to_sub) const {
155 
156  Output_title_text("Enter StepWiseRNA_VDW_Bin_Screener::get_matching_res_in_VDW_rep_screen_pose");
157  clock_t const time_start( clock() );
158 
159  using namespace ObjexxFCL;
160 
161  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
162  //First thing is to parse the VDW_rep_ignore_matching_res_ options. Here are the possibilities:
163  //1. If VDW_rep_ignore_matching_res_ is a single element list with the element="false", then do not delete the matching_res.
164  //2. If not 1), then will perform the matching deletion. To ensure that code is working probably, user need to pass in exact the list of
165  // residues segments then matching DO NOT OCCUR. This is basically the residues being rebuilt.
166  // Example Format: [5-12, 17-21] means that matching will not occur exactly between res 5 to 12 and res 17 to 21.
167  // For SWA, the input residues should be in terms of full_length pose. Will use job_parameters->full_to_sub to convert to working_pose res.
168  //3. If VDW_rep_delete_match_res_ is empty, then the check in 2. is not made.
169 
170  std::cout << "VDW_rep_ignore_matching_res_.size()=" << VDW_rep_ignore_matching_res_.size() << std::endl;
171  for(Size n=1; n<=VDW_rep_ignore_matching_res_.size(); n++){
172  std::cout << "VDW_rep_ignore_matching_res_[" << n << "]= " << VDW_rep_ignore_matching_res_[n] << std::endl;
173  }
174 
175  if(VDW_rep_ignore_matching_res_.size()==1){
176  if(VDW_rep_ignore_matching_res_[1]=="false"){
177  std::cout << "VDW_rep_ignore_matching_res_[1]==\"false\", will NOT delete residues in VDW_rep_pose that exist in the working_pose" << std::endl;
178  if(VDW_rep_ignore_matching_res_.size()!=1) utility_exit_with_message("VDW_rep_ignore_matching_res_.size()!=1");
179  utility::vector1< Size > empty_list;
180  empty_list.clear();
181  Output_title_text("Exit StepWiseRNA_VDW_Bin_Screener::delete_matching_res_in_VDW_rep_screen_pose");
182  return empty_list;
183  }
184  }
185 
186  bool const check_VDW_rep_no_match_res= (VDW_rep_ignore_matching_res_.size()==0) ? false: true;
187  Output_boolean("check_VDW_rep_no_match_res=", check_VDW_rep_no_match_res ); std::cout << std::endl;
188 
189  core::Real const dist_cutoff=VDW_rep_alignment_RMSD_CUTOFF_;
190  std::cout << "atom_atom_dist_cutoff= " << dist_cutoff << std::endl;
191 
192 
193  utility::vector1< Size > no_match_res_list;
194 
195  for(Size n=1; n<=VDW_rep_ignore_matching_res_.size(); n++){
196  utility::vector1< std::string > no_match_res_segment_pair=Tokenize(VDW_rep_ignore_matching_res_[n], "-");
197  if(no_match_res_segment_pair.size()!=2) utility_exit_with_message("no_match_res_segment_pair.size()!=2");
198 
199  Size const start_res= string_to_int(no_match_res_segment_pair[1]);
200  Size const end_res = string_to_int(no_match_res_segment_pair[2]);
201 
202  if(start_res>=end_res) utility_exit_with_message("start_res=" + string_of(start_res) + ">=" + string_of(end_res) + "end_res");
203 
204  for(Size full_seq_num=start_res; full_seq_num<=end_res; full_seq_num++){
205  Size const working_seq_num= full_to_sub[full_seq_num];
206  if(working_seq_num==0) continue;
207 
208  if( Contain_seq_num( working_seq_num , no_match_res_list ) ) utility_exit_with_message("seq_num " + string_of(working_seq_num) + " is already in the no_match_res_list!");
209  no_match_res_list.push_back( working_seq_num );
210  }
211  }
212 
213  Output_seq_num_list("working_no_match_res_list= ", no_match_res_list);
214  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
215 
216  //OK, now we match the residues in working_pose and VDW_rep_screener_pose.
217  utility::vector1< Size > working_matching_res_list, VDW_rep_matching_res_list;
218 
219  for(Size working_seq=1; working_seq<=working_pose.total_residue(); working_seq++){
220 
221  Size num_match_res=0;
222 
223  for(Size VDW_rep_seq=1; VDW_rep_seq<=VDW_rep_screen_pose.total_residue(); VDW_rep_seq++){
224 
225  conformation::Residue const & working_rsd=working_pose.residue(working_seq); //static_pose
226  conformation::Residue const & VDW_rep_rsd=VDW_rep_screen_pose.residue(VDW_rep_seq); //moving_pose
227 
228  if( VDW_rep_rsd.aa()!=working_rsd.aa() ) continue;
229 
230  Size const working_first_sc_at=working_rsd.first_sidechain_atom()+1;
231  Size const VDW_rep_first_sc_at=VDW_rep_rsd.first_sidechain_atom()+1;
232 
233  std::string const working_first_sc_name=working_rsd.type().atom_name(working_first_sc_at);
234  std::string const VDW_rep_first_sc_name=VDW_rep_rsd.type().atom_name(VDW_rep_first_sc_at);
235 
236  if( working_first_sc_name!=VDW_rep_first_sc_name){
237  utility_exit_with_message( "working_first_sc_name=" + working_first_sc_name + "!="+ VDW_rep_first_sc_name +"=VDW_rep_first_sc_name");
238  }
239 
240 
241  //fast screen. (O(n^2))
242  if( (working_rsd.xyz(working_first_sc_at)-VDW_rep_rsd.xyz(VDW_rep_first_sc_at)).length_squared() > dist_cutoff*dist_cutoff ) continue;
243 
244  //Consistency TEST: through screen ensure that every atoms is at the same position. (O(n)*O(m))///////////////////
245  bool found_O1P=false; bool found_O2P=false; bool found_O5=false; bool found_P=false;
246 
247  for(Size working_at=1; working_at<=working_rsd.natoms(); working_at++){ //I wonder if we should just consider heavy atom? (rsd_1.nheavyatoms())
248 
249  std::string const working_atom_name=working_rsd.type().atom_name(working_at);
250 
251  //if(working_rsd.atom_type(working_at).element()=="H") continue; #This doesn't work since if Hydrogen is virtual, the type is "X" not "H"
252 
253  //std::cout << "atom=" << working_at << "|name=" << working_rsd.type().atom_name(working_at) << "|type=" << working_rsd.atom_type(working_at).name();
254  //std::cout << "|element()=" << working_rsd.atom_type(working_at).element() << "|" << std::endl;
255 
256  if(working_atom_name==" O1P"){ found_O1P=true; continue; }
257  if(working_atom_name==" O2P"){ found_O2P=true; continue; }
258  if(working_atom_name==" O5*"){ found_O5=true; continue; }
259  if(working_atom_name==" P "){ found_P=true; continue; }
260 
261  if(working_atom_name=="1H5*"){ continue; }
262  if(working_atom_name=="2H5*"){ continue; }
263  if(working_atom_name=="2HO*"){ continue; }
264 
265  if(working_rsd.atom_type(working_at).name()=="VIRT") continue; //mainly to deal with "OVU1", "OVL1", "OVL2"
266 
267  if ( VDW_rep_rsd.has( working_atom_name ) ==false ) utility_exit_with_message("VDW_rep_rsd does not have atom= " + working_atom_name + "!");
268 
269  Size const VDW_rep_at = VDW_rep_rsd.atom_index( working_atom_name );
270 
271  std::string const VDW_rep_atom_name=VDW_rep_rsd.type().atom_name(VDW_rep_at);
272  if(working_atom_name!=VDW_rep_atom_name){ //Check
273  utility_exit_with_message( "working_atom_name!=VDW_rep_atom_name, working_atom_name= " + working_atom_name + " VDW_rep_atom_name= " + VDW_rep_atom_name);
274  }
275 
276  if( ( working_rsd.xyz(working_at)-VDW_rep_rsd.xyz(VDW_rep_at) ).length_squared() > (dist_cutoff*dist_cutoff) ){
277  std::cout << "dist_cutoff= " << dist_cutoff << "| working_seq= " << working_seq << "| VDW_rep_seq= " << VDW_rep_seq << " |";
278  std::cout <<"(working_rsd.xyz(working_at)-VDW_rep_rsd.xyz(VDW_rep_at)).length()=" << (working_rsd.xyz(working_at)-VDW_rep_rsd.xyz(VDW_rep_at)).length() << std::endl;
279  utility_exit_with_message( working_atom_name + " of working_rsd and " + VDW_rep_atom_name + " of VDW_rep_rsd are not within dist_cutoff" );
280  }
281  }
282 
283  if(found_O1P==false) utility_exit_with_message("found_O1P==false");
284  if(found_O2P==false) utility_exit_with_message("found_O2P==false");
285  if(found_O5==false) utility_exit_with_message("found_O5==false");
286  if(found_P==false) utility_exit_with_message("found_P==false");
287  ///////////////////////////////////////////////////////////////////////////////////////////////////
288  if( Contain_seq_num(working_seq, working_matching_res_list )){
289  utility_exit_with_message("working_seq " + string_of(working_seq) + " is already in the delete_res_list! working_seq=" +string_of(working_seq)+ " VDW_rep_seq= " + string_of(VDW_rep_seq) + ".");
290  }
291  if( Contain_seq_num(VDW_rep_seq, VDW_rep_matching_res_list )){
292  utility_exit_with_message("VDW_rep_seq " + string_of(VDW_rep_seq) + " is already in the delete_res_list! working_seq=" +string_of(working_seq)+ " VDW_rep_seq= " + string_of(VDW_rep_seq) + ".");
293  }
294 
295 
296  working_matching_res_list.push_back(working_seq);
297  VDW_rep_matching_res_list.push_back(VDW_rep_seq);
298 
299  num_match_res++;
300 
301  if(Contain_seq_num(working_seq, no_match_res_list)){
302  utility_exit_with_message(" working_seq= " + string_of(working_seq) + " is in both no_match_res_list and delete_res_list!" );
303  }
304 
305  for(Size ii=1; ii<=working_align_res.size(); ii++){
306  if(working_seq==working_align_res[ii]){
307  if(VDW_rep_seq!=VDW_rep_screen_align_res[ii]){
308  utility_exit_with_message("working_seq==working_align_res[ii] but VDW_rep_seq!=VDW_rep_screen_align_res[ii]" );
309  }
310  }
311  }
312 
313  } //VDW_rep_seq
314 
315  if(num_match_res>1) utility_exit_with_message("num_match_res>1 for working_seq=" + working_seq );
316 
317  } //working_seq
318 
319  Output_seq_num_list("working_matching_res_list= ", working_matching_res_list);
320  Output_seq_num_list("VDW_rep_matching_res_list= ", VDW_rep_matching_res_list);
321 
322  ////////////////////////////////////////////More consistency check!///////////////////////////////////////////////////////////////
323  for(Size working_seq=1; working_seq<=working_pose.total_residue(); working_seq++){
324 
325  if( Contain_seq_num(working_seq, working_matching_res_list )==false){
326 
327  //check that all working_alignment_res are properly removed.
328  if( Contain_seq_num(working_seq, working_align_res) ) utility_exit_with_message("working_seq= " + string_of(working_seq) + " is a working_align_res!" );
329 
330  if( check_VDW_rep_no_match_res ){
331  if(Contain_seq_num(working_seq, no_match_res_list)==false) utility_exit_with_message("working_seq= "+ string_of(working_seq)+" is NOT in both no_match_res_list and matching_res_list!");
332  }
333  }
334  }
335 
336 
337  for(Size VDW_rep_seq=1; VDW_rep_seq<= VDW_rep_screen_pose.total_residue(); VDW_rep_seq++){
338 
339  if( Contain_seq_num(VDW_rep_seq, VDW_rep_matching_res_list )==false){
340  //check that all working_alignment_res are properly removed.
341  if( Contain_seq_num(VDW_rep_seq, VDW_rep_screen_align_res) ){
342  utility_exit_with_message("VDW_rep_seq= " + string_of(VDW_rep_seq) + " is a VDW_rep_screen_align_res but is not in VDW_rep_matching_res_list!" );
343  }
344  }
345  }
346  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
347 
348 
349  ////////////////////OK, now we delete the matching residues in working_pose//////////////////////////////////////////////////////
350  /*
351  for(Size VDW_rep_seq=VDW_rep_screen_pose.total_residue(); VDW_rep_seq>= 1; VDW_rep_seq--){
352  if( Contain_seq_num(VDW_rep_seq, VDW_rep_delete_res_list) ){
353  VDW_rep_screen_pose.conformation().delete_residue_slow( VDW_rep_seq );
354  }
355  }
356 
357  if(output_pdb_) VDW_rep_screen_pose.dump_pdb("VDW_rep_screen_bin_AFTER_DELETE_MATCHING_VDW_rep_screen_pose.pdb" );
358 
359  */
360 
361 
362  std::cout << "Total time get_matching_res_in_VDW_rep_screen_pose: " << static_cast<Real>( clock() - time_start ) / CLOCKS_PER_SEC << " SECONDS" << std::endl;
363 
364  Output_title_text("Exit StepWiseRNA_VDW_Bin_Screener::delete_matching_res_in_VDW_rep_screen_pose");
365 
366 
367  return VDW_rep_matching_res_list;
368  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
369 
370 
371  }
372 
373 
374 
375 
376  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
377 
378 
379  void
381  core::pose::Pose const & working_pose,
382  utility::vector1< core::Size > const & VDW_rep_screen_align_res,
383  utility::vector1< core::Size > const & working_align_res,
384  bool const verbose) const {
385 
386  using namespace core::pose;
387  using namespace ObjexxFCL;
388  using namespace core::scoring;
389 
390 
391  ////////////////////////////////////Align VDW_rep_screen_pose to working_pose/////////////////////////////////////////////////////////////////////
392  if(verbose) Output_title_text("Enter StepWiseRNA_VDW_Bin_Screener::align_VDW_rep_screen_pose()");
393 
394  if(verbose) std::cout << "VDW_rep_alignment_RMSD_CUTOFF_= " << VDW_rep_alignment_RMSD_CUTOFF_ << std::endl;
395 
396  if(VDW_rep_screen_align_res.size()!=working_align_res.size()){
397  utility_exit_with_message( "Size of VDW_rep_screen_align_res ( " + string_of(VDW_rep_screen_align_res.size()) + ") != working_align_res (" + string_of(working_align_res.size()) + ")" );
398  }
399 
400  if(output_pdb_){
401  working_pose.dump_pdb("VDW_rep_screen_bin_BEFORE_ALIGN_working_pose.pdb" );
402  VDW_rep_screen_pose.dump_pdb("VDW_rep_screen_bin_BEFORE_ALIGN_VDW_rep_screen_pose.pdb" );
403  }
404 
405 
406  std::map< core::Size, core::Size > res_map;
407 
408  //debug
409  if(verbose) std::cout << "VDW_rep_screen_align_res--->working_align_res" << std::endl;
410 
411  for(Size ii=1; ii<=working_align_res.size(); ii++){
412 
413  Size const res_num_1=VDW_rep_screen_align_res[ii]; //moving_pose
414  Size const res_num_2=working_align_res[ii]; //static_pose
415 
416  if(res_num_1> VDW_rep_screen_pose.total_residue()){
417  utility_exit_with_message( "res_num_1 (" + string_of(res_num_1)+") > VDW_rep_screen_pose.total_residue() (" + string_of(VDW_rep_screen_pose.total_residue())+")!");
418  }
419 
420  if(res_num_2> working_pose.total_residue()){
421  utility_exit_with_message( "res_num_2 (" + string_of(res_num_2)+") > working_pose.total_residue() (" + string_of(working_pose.total_residue())+")!");
422  }
423 
424  if(verbose) std::cout << res_num_1 << " ---> " << res_num_2 << std::endl;
425 
426  res_map[ res_num_1 ] = res_num_2;
427 
428  }
429 
430  id::AtomID_Map< id::AtomID > alignment_atom_id_map=protocols::swa::create_alignment_id_map( VDW_rep_screen_pose, working_pose, res_map );
431 
432 
433  if(verbose) std::cout << "before superimpose_pose" << std::endl;
434 
435  /*Real const alignment_rmsd= // Unused variable causes warning.*/
436  core::scoring::superimpose_pose( VDW_rep_screen_pose, working_pose, alignment_atom_id_map);
437 
438  if(verbose) std::cout << "after superimpose_pose" << std::endl;
439 
440  if(output_pdb_){
441  working_pose.dump_pdb("VDW_rep_screen_bin_AFTER_ALIGN_working_pose.pdb" );
442  VDW_rep_screen_pose.dump_pdb("VDW_rep_screen_bin_AFTER_ALIGN_VDW_rep_screen_pose.pdb" );
443  }
444 
445  //////////////////////////////////Check that VDW_rep_screen pose is perfectly align to working_pose...////////////////////////////////
446 
447  for(Size n=1; n<=working_align_res.size(); n++){
448 
449  Size const res_num_1=VDW_rep_screen_align_res[n]; //moving_pose
450  Size const res_num_2=working_align_res[n]; //static_pose
451 
452 
453  Size atom_count=0;
454  Real sum_sd=0.0;
455 
456  base_atoms_square_deviation(VDW_rep_screen_pose, working_pose, res_num_1, res_num_2, atom_count, sum_sd, false /*verbose*/, false /*ignore_virtual_atom*/);
457 
458  sum_sd=sum_sd/(atom_count);
459  Real rmsd=sqrt(sum_sd);
460 
461  if(atom_count==0) rmsd=99.99; //This is different from suite_rmsd function..!!
462 
463  if(verbose){
464  std::cout << "rmsd= " << rmsd << " Angstrom between res " << res_num_1 << " of VDW_rep_screen_align_res and res " << res_num_2 << " of working_pose" << std::endl;
465  }
466 
467 
468  if(rmsd>VDW_rep_alignment_RMSD_CUTOFF_ ){ //change on Sept 26, 2010..problem arise when use this in non-long-loop mode...
469  std::cout << "rmsd= " << rmsd << " >(" << VDW_rep_alignment_RMSD_CUTOFF_ << ") Angstrom between res " << res_num_1 << " of VDW_rep_screen_align_res and res " << res_num_2 << " of working_pose" << std::endl;
470  utility_exit_with_message( "rmsd>VDW_rep_alignment_RMSD_CUTOFF!");
471  }
472 
473  }
474  if(verbose) Output_title_text("Exit StepWiseRNA_VDW_Bin_Screener::align_VDW_rep_screen_pose()");
475 
476 
477  }
478 
479  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
480  /*
481  void
482  StepWiseRNA_VDW_Bin_Screener::align_to_first_working_pose(core::pose::Pose & pose, std::string const & tag) const {
483 
484  using namespace core::pose;
485  using namespace protocols::swa::rna;
486 
487  if(first_working_align_res_.size()==0) utility_exit_with_message("first_working_align_res_.size()==0");
488 
489  align_poses(pose, tag, first_working_pose_, "first_working_pose (for VDW_rep_screener setup)" , first_working_align_res_);
490 
491  }
492  */
493 
494  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
495 
496  void
497  StepWiseRNA_VDW_Bin_Screener::create_VDW_rep_screen_pose(VDW_RepScreeninfo & VDW_rep_screen_info, //This function update this class!
498  core::pose::Pose const & working_pose,
499  std::map< core::Size, core::Size > & full_to_sub,
500  bool const verbose) const {
501 
502  using namespace core::pose;
503  using namespace ObjexxFCL;
504  using namespace core::chemical;
505 
506 
507  ResidueTypeSetCAP rsd_set;
509 
510  std::cout << "importing VDW_rep_screen_pose: " << VDW_rep_screen_info.pose_name << std::endl;
511  if(VDW_rep_screen_info.pose_name=="") utility_exit_with_message(VDW_rep_screen_info.pose_name=="");
512 
513  ////////import VDW_rep_screen_pose.////////////////////////////////////////
514  pose::Pose VDW_rep_screen_pose;
515  import_pose::pose_from_pdb( VDW_rep_screen_pose, *rsd_set, VDW_rep_screen_info.pose_name );
517  ///////////////////////////////////////////////////////////////////////////
518 
519  //Virtualize O2star...o2star hydrogen position can change ..particularly important for long loop mode.
520  //Important since by virtualizing...the o2star hydrogen will be ignored when creating the VDW_screen_bin.
521  Add_virtual_O2Star_hydrogen( VDW_rep_screen_pose);
522 
523  utility::vector1< core::Size > const & VDW_rep_screen_align_res=VDW_rep_screen_info.VDW_align_res;
524  utility::vector1< core::Size > const & working_align_res=VDW_rep_screen_info.working_align_res;
525 
526  align_VDW_rep_screen_pose(VDW_rep_screen_pose, working_pose, VDW_rep_screen_align_res, working_align_res, verbose);
527 
528  VDW_rep_screen_info.VDW_ignore_res=get_matching_res_in_VDW_rep_screen_pose( VDW_rep_screen_pose, working_pose, VDW_rep_screen_align_res, working_align_res, full_to_sub);
529 
530  VDW_rep_screen_info.VDW_pose=VDW_rep_screen_pose;
531 
532  }
533 
534  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
535  void
537  core::pose::Pose const & const_working_pose){
538 
539  using namespace core::pose;
540  using namespace ObjexxFCL;
541 
543  bool const verbose=true;
544 
545  Output_title_text("Enter StepWiseRNA_VDW_Bin_Screener::FARFAR_setup_using_user_input_VDW_pose");
546 
547  if( ( All_VDW_rep_screen_pose_info.size() % 3 ) != 0 ){
548  utility_exit_with_message( "( All_VDW_rep_screen_pose_info.size() % 3 ) != 0. Example: VWC_rep_screen_pose.pdb 6-44(align_res of VWD_rep_screen_pose) 1-33(align_res of working_pose)" );
549  }
550 
552  Size import_ID=0;
553 
554  ///////////////////////////////////////////////////////////////////////////
555  for(Size n=1; n<=All_VDW_rep_screen_pose_info.size(); n+=3){
556  import_ID++;
557 
558  VDW_RepScreeninfo VDW_rep_screen_info=VDW_RepScreeninfo();
559 
560  VDW_rep_screen_info.import_ID=import_ID;
561  VDW_rep_screen_info.input_string="";
562  VDW_rep_screen_info.input_string+="pose_name= " + All_VDW_rep_screen_pose_info[n];
563  VDW_rep_screen_info.input_string+=" VDW_align_res_string= " + All_VDW_rep_screen_pose_info[n+1];
564  VDW_rep_screen_info.input_string+=" full_align_res_string= " + All_VDW_rep_screen_pose_info[n+2];
565 
566  std::cout << "Adding VDW_screen_rep_pose_info #" << VDW_rep_screen_info.import_ID << ": " << VDW_rep_screen_info.input_string << std::endl;
567 
568  VDW_rep_screen_info.pose_name=All_VDW_rep_screen_pose_info[n];
569  utility::vector1< std::string > const VDW_rep_screen_align_res_string=Tokenize(All_VDW_rep_screen_pose_info[n+1], "-");
570  utility::vector1< std::string > const full_align_res_string=Tokenize(All_VDW_rep_screen_pose_info[n+2], "-");
571 
572  for(Size ii=1; ii<=VDW_rep_screen_align_res_string.size(); ii++){
573  VDW_rep_screen_info.VDW_align_res.push_back( string_to_int( VDW_rep_screen_align_res_string[ii] ) );
574  }
575 
576  for(Size ii=1; ii<=full_align_res_string.size(); ii++){
577  VDW_rep_screen_info.full_align_res.push_back( string_to_int( full_align_res_string[ii] ) );
578  }
579 
580  if(VDW_rep_screen_info.VDW_align_res.size()==0) utility_exit_with_message( "VDW_align_ress.size()==0" );
581  if(VDW_rep_screen_info.full_align_res.size()==0) utility_exit_with_message("full_align_res.size()==0!");
582 
583  if(VDW_rep_screen_info.VDW_align_res.size()!=VDW_rep_screen_info.full_align_res.size()){
584  utility_exit_with_message( "Size of VDW_align_res ( " + string_of(VDW_rep_screen_info.VDW_align_res.size()) + ") != working_align_res (" + string_of(VDW_rep_screen_info.working_align_res.size()) + ")" );
585  }
586 
587  //Assume the FARFAR working_pose is the full_length pose.
588  VDW_rep_screen_info.working_align_res=VDW_rep_screen_info.full_align_res;
589  ///////////////////////////////////////////////////////////////////////////
590  pose::Pose working_pose=const_working_pose;
591  Add_virtual_O2Star_hydrogen( working_pose);
592  //Virtualize O2star...o2star hydrogen position can change ..particularly important for long loop mode.
593  //Important since by virtualizing...the o2star hydrogen will be ignored when creating the VDW_screen_bin.
594 
595  std::map< core::Size, core::Size > full_to_sub;
596  full_to_sub.clear();
597 
598  for(Size n=1; n<=working_pose.total_residue(); n++){
599  full_to_sub[n]=n;
600  }
601 
602  use_VDW_rep_pose_for_screening_=true; ///Allow use of full pose for VDW rep screen instead of the bin.
603  create_VDW_rep_screen_pose(VDW_rep_screen_info, working_pose, full_to_sub, verbose);
604 
605  VDW_rep_screen_info_list_.push_back(VDW_rep_screen_info);
606 
607  }
608 
609  if(verbose) Output_title_text("Exit StepWiseRNA_VDW_Bin_Screener::FARFAR_setup_using_user_input_VDW_pose");
610 
611 
612  }
613 
614  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
615 
616  void
618  core::pose::Pose const & const_working_pose,
619  StepWiseRNA_JobParametersCOP const & job_parameters ){
620 
621  using namespace core::pose;
622  using namespace ObjexxFCL;
623  using namespace core::chemical;
624  using namespace core::scoring;
625 
626 
628  bool const verbose=true;
629 
630 
631  Output_title_text("Enter StepWiseRNA_VDW_Bin_Screener::setup_using_user_input_VDW_pose");
632 
633  if(( All_VDW_rep_screen_pose_info.size() % 3 ) != 0){
634  utility_exit_with_message( "All_VDW_rep_screen_pose_info.size() % 3 ) != 0. Example: VWC_rep_screen_pose.pdb 6-44(align_res of VWD_rep_screen_pose) 1-33(align_res of working_pose)" );
635  }
636 
637  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
639  Size import_ID=0;
640 
641  for(Size n=1; n<=All_VDW_rep_screen_pose_info.size(); n+=3){
642  import_ID++;
643 
644  VDW_RepScreeninfo VDW_rep_screen_info=VDW_RepScreeninfo();
645 
646  VDW_rep_screen_info.import_ID=import_ID;
647  VDW_rep_screen_info.input_string="";
648  VDW_rep_screen_info.input_string+="pose_name= " + All_VDW_rep_screen_pose_info[n];
649  VDW_rep_screen_info.input_string+=" VDW_align_res_string= " + All_VDW_rep_screen_pose_info[n+1];
650  VDW_rep_screen_info.input_string+=" full_align_res_string= " + All_VDW_rep_screen_pose_info[n+2];
651 
652  std::cout << "Checking VDW_screen_rep_pose_info #" << VDW_rep_screen_info.import_ID << ": " << VDW_rep_screen_info.input_string << std::endl;
653 
654  VDW_rep_screen_info.pose_name=All_VDW_rep_screen_pose_info[n];
655  utility::vector1< std::string > const VDW_rep_screen_align_res_string=Tokenize(All_VDW_rep_screen_pose_info[n+1], "-");
656  utility::vector1< std::string > const full_align_res_string=Tokenize(All_VDW_rep_screen_pose_info[n+2], "-");
657 
658 
659  for(Size ii=1; ii<=VDW_rep_screen_align_res_string.size(); ii++){
660  VDW_rep_screen_info.VDW_align_res.push_back( string_to_int( VDW_rep_screen_align_res_string[ii] ) );
661  }
662 
663  for(Size ii=1; ii<=full_align_res_string.size(); ii++){
664  VDW_rep_screen_info.full_align_res.push_back( string_to_int( full_align_res_string[ii] ) );
665  }
666 
667  if(VDW_rep_screen_info.VDW_align_res.size()==0) utility_exit_with_message( "Size of VDW_align_res.size()==0" );
668  if(VDW_rep_screen_info.full_align_res.size()==0) utility_exit_with_message("full_align_res.size()==0!");
669 
670  if(VDW_rep_screen_info.VDW_align_res.size()!=VDW_rep_screen_info.full_align_res.size()){
671  utility_exit_with_message( "Size of VDW_align_res ( " + string_of(VDW_rep_screen_info.VDW_align_res.size()) + ") != working_align_res (" + string_of(VDW_rep_screen_info.working_align_res.size()) + ")" );
672  }
673 
674  VDW_rep_screen_info.working_align_res=apply_full_to_sub_mapping( VDW_rep_screen_info.full_align_res , job_parameters);
675 
676  if(VDW_rep_screen_info.full_align_res.size()!=VDW_rep_screen_info.working_align_res.size()){
677  std::cout << "Ignoring VDW_screen_rep_pose_info #" << VDW_rep_screen_info.import_ID << " since full_align_res.size()!=working_align_res.size()!";
678  std::cout << " full_align_res.size()= " << VDW_rep_screen_info.full_align_res.size();
679  std::cout << " working_align_res.size()= " << VDW_rep_screen_info.working_align_res.size();
680  std::cout << std::endl;
681  continue;
682  }
683 
684  utility::vector1< core::Size > const working_fixed_res( job_parameters->working_fixed_res() );
685  //Ok check that the working_align_res are working_fixed_res...
686  //This is important for VDW_screening in the minimizer!
687  for(Size ii=1; ii<=VDW_rep_screen_info.working_align_res.size(); ii++){
688  if( Contain_seq_num(VDW_rep_screen_info.working_align_res[ii], working_fixed_res )==false){
689  Output_seq_num_list("working_align_res= ", VDW_rep_screen_info.working_align_res, 40);
690  Output_seq_num_list("working_fixed_res= ", working_fixed_res, 40);
691  utility_exit_with_message( "A residue in working_align_res is not a working_fixed_res!" );
692  }
693  }
694  //////////////////////////////////////////////////////////////////
695  pose::Pose working_pose=const_working_pose;
696  Add_virtual_O2Star_hydrogen( working_pose);
697  //Virtualize O2star...o2star hydrogen position can change ..particularly important for long loop mode.
698  //Important since by virtualizing...the o2star hydrogen will be ignored when creating the VDW_screen_bin.
699 
700  std::map< core::Size, core::Size > const const_full_to_sub=job_parameters->const_full_to_sub();
701  std::map< core::Size, core::Size > full_to_sub=const_full_to_sub;
702 
703  use_VDW_rep_pose_for_screening_=true; ///Allow use of full pose for VDW rep screen instead of the bin.
704  create_VDW_rep_screen_pose(VDW_rep_screen_info, working_pose, full_to_sub, verbose);
705 
706  VDW_rep_screen_info_list_.push_back(VDW_rep_screen_info);
707 
708  }
709 
710 
711  ////////////////Find the VDW_rep_screen_pose_infos that are in the root partition!/////////////////////////////////////////////
712  std::cout << "--------------------------------------------------------" << std::endl;
713 
714  ObjexxFCL::FArray1D< bool > const & partition_definition = job_parameters->partition_definition();
715  bool const root_partition = partition_definition( const_working_pose.fold_tree().root() );
716  Size num_rep_screen_pose_info_in_root_partition=0;
717 
718  for(Size n=1; n<=VDW_rep_screen_info_list_.size(); n++){
719 
720  VDW_RepScreeninfo const & VDW_rep_screen_info=VDW_rep_screen_info_list_[n];
721 
722  std::cout << "Check if VDW screen_rep_pose_info #" << VDW_rep_screen_info.import_ID << ": " << VDW_rep_screen_info.input_string << " is in root partition." << std::endl;
723 
724  if(VDW_rep_screen_info.working_align_res.size()!=VDW_rep_screen_info.full_align_res.size()) utility_exit_with_message("ERROR!");
725 
726  bool contain_moving_partition_res=false;
727  for(Size ii=1; ii<=VDW_rep_screen_info.working_align_res.size(); ii++){
728  Size const seq_num=VDW_rep_screen_info.working_align_res[ii];
729  if ( partition_definition( seq_num ) != root_partition ) {
730  contain_moving_partition_res=true;
731  break;
732  }
733  }
734 
735  if(contain_moving_partition_res==false){
736  std::cout << "VDW_screen_rep_pose_info #" << VDW_rep_screen_info.import_ID << " is in root partition! " << std::endl;
737  VDW_rep_screen_info_list_[n].in_root_partition=true;
738  num_rep_screen_pose_info_in_root_partition++;
739  }else{
740  VDW_rep_screen_info_list_[n].in_root_partition=false;
741  }
742 
743  }
744 
745  if(num_rep_screen_pose_info_in_root_partition==0){
746 
747  //consistency check!//////////////////////////////////////////////
748  utility::vector1< core::Size > const working_fixed_res=job_parameters->working_fixed_res();
749  utility::vector1< core::Size > working_fixed_res_in_root_partition;
750 
751  for (Size n=1; n <= working_fixed_res.size(); n++){
752  Size seq_num=working_fixed_res[n];
753  if ( partition_definition( seq_num ) == root_partition ) {
754  working_fixed_res_in_root_partition.push_back(seq_num);
755  }
756  }
757  //////////////////////////////////////////////////////////////////
758 
759  if(working_fixed_res_in_root_partition.size()==0) {
760  std::cout << "No VDW_screener_pose since working_fixed_res_in_root_partition.size()==0, probably build inward " << std::endl;
762  return;
763  }else{
764  utility_exit_with_message("num_rep_screen_pose_info_in_root_partition==0!");
765  }
766  }
767 
768  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
769 
770  Size const reference_res=job_parameters->working_reference_res();
771  std::cout << "--------------------------------------------------------" << std::endl;
772  std::cout << "Get reference xyz: " << std::endl;
773  std::cout << "working_reference_res = " << reference_res << std::endl;
774 
775  numeric::xyzVector<core::Real> const reference_xyz=core::scoring::rna::get_rna_base_centroid( const_working_pose.residue( reference_res ) , true);
776  std::cout << "--------------------------------------------------------" << std::endl;
777 
778  create_VDW_screen_bin(VDW_rep_screen_info_list_, reference_xyz, false /*verbose*/);
779 
780  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
781 
782 
783  if(verbose) Output_title_text("Exit StepWiseRNA_VDW_Bin_Screener::setup_using_user_input_VDW_pose");
784 
785  }
786 
787  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
788  void
790  utility::vector1< core::Size > const & ignore_res_list,
791  bool const Is_prepend, //associated with ignore_res_list
792  std::ofstream & outfile_act){
793 
794  bool output_once=false;
795 
796  std::cout << "pose.total_residue()= " << pose.total_residue()<< std::endl;
797 
798  // if(output_pdb_) pose.dump_pdb( "create_VDW_screen_bin_pose.pdb" );
799 
801  utility::vector1< std::pair <Size,std::string> > moving_phosphate_atom_list;
802 
803 
804  for(Size n=1; n<=pose.total_residue(); n++){
805  core::conformation::Residue const & rsd = pose.residue(n);
806 
807  if(Contain_seq_num(n, ignore_res_list)) {
808  continue;
809  }
810 
811  for(Size at=1; at<= rsd.natoms(); at++){ //include hydrogen atoms.
812 
813  if(rsd.atom_type(at).name()=="VIRT"){
814  virtual_atom_list.push_back( std::make_pair( n, rsd.type().atom_name(at) ) );
815  continue;
816  }
817 
818  if(Is_prepend && Contain_seq_num(n-1, ignore_res_list)) {
819  bool Is_moving_phosphate=false;
820 
821  if(rsd.type().atom_name(at)==" P ") Is_moving_phosphate=true;
822  if(rsd.type().atom_name(at)==" O1P") Is_moving_phosphate=true;
823  if(rsd.type().atom_name(at)==" O2P") Is_moving_phosphate=true;
824  if(rsd.type().atom_name(at)==" O5*") Is_moving_phosphate=true;
825  if(rsd.type().atom_name(at)=="1H5*") Is_moving_phosphate=true;
826  if(rsd.type().atom_name(at)=="2H5*") Is_moving_phosphate=true;
827 
828  if(Is_moving_phosphate){
829  moving_phosphate_atom_list.push_back( std::make_pair( n, rsd.type().atom_name(at) ) );
830  continue;
831  }
832  }
833 
834  Atom_Bin const atom_pos_bin=get_atom_bin(rsd.xyz(at));
835 
836 
837  if(write_to_file_){
838  outfile_act << rsd.xyz(at)[0] << " ";
839  outfile_act << rsd.xyz(at)[1] << " ";
840  outfile_act << rsd.xyz(at)[2] << " ";
841  outfile_act << "\n";
842  }
843  //////////////Purpose of three_dim_VDW_bin is for van der Waals replusion screening///////
844  Real const VDW_radius=rsd.atom_type(at).lj_radius();
845  Real const moving_atom_radius=1.0; //Play it safe...could optimize by having a VWD_bin for each moving_atom tyep but don't think will significantly speed out code Apr 17, 2010
846  Real const clash_dist_cutoff=0.8; //Fail van der Waals replusion screen if two atoms radius within 0.5 Angstrom of each other
847 
848  Real const max_binning_error=2*(atom_bin_size_/2)*sqrt(3.0); //Feb 09, 2012: FIXED. Used to be "3" instead of "3.0"
849 
850  //Basically distance from center of box to the edge of box...2x since this is Lennard Jones distance between two atoms.
851 
852  Real const sum_radius=moving_atom_radius+VDW_radius-clash_dist_cutoff-max_binning_error;
853 
854  int const max_bin_offset=int((sum_radius+atom_bin_size_)/atom_bin_size_);
855  int const min_bin_offset=int(-((sum_radius+atom_bin_size_)/atom_bin_size_));
856 
857  if(output_once==false){
858  output_once=true;
859  std::cout << "seq_num= " << n << " atom_name= " << rsd.type().atom_name(at) << " VDW_radius= " << VDW_radius;
860  std::cout << " moving_atom_radius= " << moving_atom_radius << " clash_dist_cutoff= " << clash_dist_cutoff;
861  std::cout << " max_binning_error= " << max_binning_error << " sum_radius " << sum_radius << std::endl;
862  std::cout << "max_bin_offset= " << max_bin_offset << " min_bin_offset= " <<min_bin_offset << std::endl;
863  //Note that VDW_radius of virtual atom is 0.0...this doesn't really matter since there is a screen virtual atom before this point anyways.
864  }
865 
866  for(int x_bin_offset=min_bin_offset; x_bin_offset<=max_bin_offset; x_bin_offset++){
867  for(int y_bin_offset=min_bin_offset; y_bin_offset<=max_bin_offset; y_bin_offset++){
868  for(int z_bin_offset=min_bin_offset; z_bin_offset<=max_bin_offset; z_bin_offset++){
869 
870  Atom_Bin xyz_bin=atom_pos_bin;
871  xyz_bin.x+=x_bin_offset;
872  xyz_bin.y+=y_bin_offset;
873  xyz_bin.z+=z_bin_offset;
874 
875  if( !Is_atom_bin_in_range(xyz_bin) ) continue;
876 
877  numeric::xyzVector<core::Real> const xyz_pos=get_atom_pos(xyz_bin);
878 
879  if( (xyz_pos-rsd.xyz(at)).length_squared() < sum_radius*sum_radius){
880  VDW_screen_bin_[xyz_bin.x][xyz_bin.y][xyz_bin.z]=true;
881  }
882 
883  }
884  }
885  }
886  ///////////////////////////////////////////////////////////////////////////
887  }
888  }
889 
890  Output_seq_num_list("ignore_res_list=" ,ignore_res_list);
891 
892  std::cout << "VIRTUAL_ATOM_LIST: " << std::endl;
893  for(Size ii=1; ii<=virtual_atom_list.size(); ii++){
894  std::cout << virtual_atom_list[ii].first << "-" << virtual_atom_list[ii].second << " ";
895  }
896  std::cout << std::endl;
897 
898  std::cout << "MOVING_PHOSPHATE_ATOM_LIST: " << std::endl;
899  for(Size ii=1; ii<=moving_phosphate_atom_list.size(); ii++){
900  std::cout << moving_phosphate_atom_list[ii].first << "-" << moving_phosphate_atom_list[ii].second << " ";
901  }
902  std::cout << std::endl;
903  }
904 
905  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
906  void
908  utility::vector1< core::Size > const & ignore_res_list,
909  bool const Is_prepend, //associated with ignore_res_list
910  numeric::xyzVector<core::Real> const & reference_xyz,
911  bool const verbose){
912 
914  utility::vector1< utility::vector1< core::Size > > list_of_ignore_res_list;
915  utility::vector1< bool > list_of_Is_prepend;
916 
917  pose_list.push_back(pose);
918  list_of_ignore_res_list.push_back(ignore_res_list);
919  list_of_Is_prepend.push_back(Is_prepend);
920 
921  create_VDW_screen_bin(pose_list, list_of_ignore_res_list, list_of_Is_prepend, reference_xyz, verbose);
922 
923  }
924 
925  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
926  void
928  numeric::xyzVector<core::Real> const & reference_xyz,
929  bool const verbose){
930 
931 
933  utility::vector1< utility::vector1< core::Size > > list_of_ignore_res_list;
934  utility::vector1< bool > list_of_Is_prepend;
935 
936  for(Size n=1; n<=VDW_rep_screen_info_list.size(); n++){
937  if(VDW_rep_screen_info_list[n].in_root_partition==true){
938  pose_list.push_back(VDW_rep_screen_info_list[n].VDW_pose);
939  list_of_ignore_res_list.push_back(VDW_rep_screen_info_list[n].VDW_ignore_res);
940  list_of_Is_prepend.push_back( false ); /*Backward consistency with prior code that delete the matching res in VDW_rep_pose */
941  }
942  }
943 
944  create_VDW_screen_bin(pose_list, list_of_ignore_res_list, list_of_Is_prepend, reference_xyz, verbose);
945 
946  }
947  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
948  //Update on June 03, 2011 to allow multiple input. Users still need to make sure that all the poses are in the root partition!
949  void
951  utility::vector1< utility::vector1< core::Size > > const & list_of_ignore_res_list,
952  utility::vector1< bool > const list_of_Is_prepend,
953  numeric::xyzVector<core::Real> const & reference_xyz,
954  bool const verbose){
955 
956  std::cout << "------------------Enter create_pose_bin function------------------ " << std::endl;
957  std::cout << "max_distance_= " << max_distance_ << std::endl;
958  std::cout << "atom_bin_size_= " << atom_bin_size_ << std::endl;
959  std::cout << "bin_min_= " << bin_min_ << std::endl;
960  std::cout << "bin_max_= " << bin_max_ << std::endl;
961  std::cout << "bin_offset_= " << bin_offset_ << std::endl;
962  std::cout << "num_clash_atom_cutoff_= " << num_clash_atom_cutoff_ << std::endl;
963  std::cout << "pose_list.size()= " << pose_list.size() << std::endl;
964  Output_boolean("verbose=", verbose); std::cout << std::endl;
965  Output_boolean("write_to_file_=", write_to_file_ ); std::cout << std::endl;
966  Output_boolean("user_inputted_VDW_screen_pose_=", user_inputted_VDW_screen_pose_ ); std::cout << std::endl;
967  Output_boolean("tolerate_off_range_atom_bin_=", tolerate_off_range_atom_bin_ ); std::cout << std::endl;
968  /////////////////////////////////////////////
969 
970  ///Some consistency_checks////////
971  if(pose_list.size()!=list_of_ignore_res_list.size()){
972  utility_exit_with_message("pose_list.size(){" + ObjexxFCL::string_of(pose_list.size()) + "}!={" + ObjexxFCL::string_of(list_of_ignore_res_list.size()) + "}list_of_ignore_res_list.size()");
973  }
974 
975  if(pose_list.size()!=list_of_Is_prepend.size()){
976  utility_exit_with_message("pose_list.size(){" + ObjexxFCL::string_of(pose_list.size()) + "}!={" + ObjexxFCL::string_of(list_of_Is_prepend.size()) + "}list_of_ignore_res_list.size()");
977  }
978  //////////////////////////////////
979 
981  set_reference_xyz(reference_xyz);
982 
983  //Use a vector as the storage object...memory expensive but fast lookup time..
984  utility::vector1< bool > one_dim_bin(bin_max_*2, false);
985  utility::vector1< utility::vector1< bool > > two_dim_bin(bin_max_*2, one_dim_bin);
986  if(VDW_screen_bin_.size()!=0) utility_exit_with_message("VDW_screen_bin_.size()!=0 before setup!");
987  VDW_screen_bin_.assign(bin_max_*2, two_dim_bin);
988 
989  std::ofstream outfile_act;
990  if(write_to_file_) outfile_act.open("atom_pos_bin_act.txt");
991 
992  for(Size n=1; n<=pose_list.size(); n++){
993  std::cout << "--------------Enter update_VDW_screen_bin() for pose #" << n << " (count only include VDW_poses in root partition!)--------------" << std::endl;
994  update_VDW_screen_bin(pose_list[n], list_of_ignore_res_list[n], list_of_Is_prepend[n], outfile_act);
995  std::cout << "--------------Exit update_VDW_screen_bin() for pose #" << n << " (count only include VDW_poses in root partition!)--------------" << std::endl;
996  }
997 
998  if(write_to_file_) outfile_act.close();
999  if(write_to_file_) output_atom_bin("atom_VDW_bin.txt");
1000  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1001  //Check the size
1002  Size occupied_bin_count=0;
1003  Size total_bin_count=0;
1004  for(int x_bin=1; x_bin<=bin_max_*2; x_bin++){
1005  for(int y_bin=1; y_bin<=bin_max_*2; y_bin++){
1006  for(int z_bin=1; z_bin<=bin_max_*2; z_bin++){
1007  if(VDW_screen_bin_[x_bin][y_bin][z_bin]==true) occupied_bin_count++;
1008  total_bin_count++;
1009  }
1010  }
1011  }
1012 
1013  if(total_bin_count==0) utility_exit_with_message("total_bin_count of thre_dim_VDW_bin==0!");
1014 
1015  std::cout << "VDW_screen_bin_: occupied_bin_count = " << occupied_bin_count << " out of total_bin_count = " << total_bin_count << std::endl;
1016  std::cout << "------------------Exit create_pose_bin function------------------ " << std::endl;
1017 
1018  }
1019 
1020  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1021  ////////////////June 04, 2011 Becareful...even nucleotides in the root partition CAN move during minimization, so VDW_screen_bin_ can be OFF!////////////////////////////////
1022  ////////////////SO USE VDW_rep_screen() only during sampling. For minimization use VDW_rep_screen_with_act_pose()!
1023  //fast version
1024  bool
1025  StepWiseRNA_VDW_Bin_Screener::VDW_rep_screen(core::pose::Pose const & screening_pose, //Warning..this pose coordinate is not update...use here for VIRTUAL atom screening.
1026  Size const & moving_res,
1027  core::conformation::Residue const & rsd_at_origin,
1028  core::kinematics::Stub const & moving_res_base_stub){
1029 
1031 
1032  core::conformation::Residue const & moving_rsd = screening_pose.residue(moving_res);
1033 
1035  get_atom_coordinates(xyz_list, moving_res, rsd_at_origin, moving_res_base_stub);
1036 
1037  Size num_clash_atom=0;
1038  for( Size n = 1; n <= xyz_list.size(); n++){
1039 
1040 
1041  //check
1042  if(xyz_list[n].first.rsd()!=moving_res){
1043  std::cout << "xyz_list[n].first.rsd()= " << xyz_list[n].first.rsd() << " moving_res= " << moving_res << std::endl;
1044  utility_exit_with_message("xyz_list[n].first.rsd()!=moving_res");
1045  }
1046 
1047  //Virtual atom screen
1048  Size const at=xyz_list[n].first.atomno();
1049  if(moving_rsd.atom_type(at).name()=="VIRT") continue; //Is this slow???
1050 
1051 
1052  Atom_Bin const atom_pos_bin=get_atom_bin(xyz_list[n].second);
1053 
1054  if(check_atom_bin_in_range(atom_pos_bin)==false) continue;
1055 
1056  //VDW Replusion screening...
1057  if(VDW_screen_bin_[atom_pos_bin.x][atom_pos_bin.y][atom_pos_bin.z]==true){ //CLASH!
1058  num_clash_atom++;
1059  }
1060 
1061  if(num_clash_atom>=num_clash_atom_cutoff_) return false; //before this use to be at the beginning of the for loop, move this down on Sept 29, 2010
1062 
1063  }
1064 
1065  return true;
1066  }
1067  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1068 
1069  //Slow version (in the sense that position of screening_pose had to be updated before this function is called)..
1070  bool
1071  StepWiseRNA_VDW_Bin_Screener::VDW_rep_screen( core::pose::Pose const & screening_pose, core::Size const & moving_res){
1072 
1074 
1075  core::conformation::Residue const & moving_rsd = screening_pose.residue(moving_res);
1076 
1077  Size num_clash_atom=0;
1078  for( Size at = 1; at <= moving_rsd.natoms(); at++){
1079 
1080  //Virtual atom screen
1081  if(moving_rsd.atom_type(at).name()=="VIRT") continue; //Is this slow???
1082 
1083  Atom_Bin const atom_pos_bin=get_atom_bin(moving_rsd.xyz(at));
1084 
1085  if(check_atom_bin_in_range(atom_pos_bin)==false) continue;
1086 
1087  //VDW Replusion screening...
1088  if(VDW_screen_bin_[atom_pos_bin.x][atom_pos_bin.y][atom_pos_bin.z]==true){ //CLASH!
1089  num_clash_atom++;
1090  }
1091 
1092  if(num_clash_atom>=num_clash_atom_cutoff_) return false; //before this use to be at the beginning of the for loop, move this down on Sept 29, 2010
1093 
1094  }
1095 
1096 
1097  return true;
1098  }
1099 
1100  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1101  ///Warning, this version is very SLOW!
1102  bool
1104  utility::vector1< core::Size > const & moving_res_list,
1105  bool const local_verbose){
1106 
1107  if(use_VDW_rep_pose_for_screening_==false) utility_exit_with_message("use_VDW_rep_pose_for_screening_==false");
1108 
1109  if(moving_res_list.size()==0) utility_exit_with_message("moving_res_list.size()==0!");
1110 
1112  std::cout << "------------VDW_rep_screen_with_physical_pose_INFO------------" << std::endl;
1114  std::cout << "physical_pose_clash_dist_cutoff_= " << physical_pose_clash_dist_cutoff_ << std::endl;
1115  std::cout << "num_clash_atom_cutoff_= " << num_clash_atom_cutoff_ << std::endl;
1116  std::cout << "VDW_rep_screen_info_list_.size()= " << VDW_rep_screen_info_list_.size() << std::endl;
1117  Output_seq_num_list("moving_res_list= ", moving_res_list);
1118  std::cout << "--------------------------------------------------------------" << std::endl;
1119  }
1120 
1121  for(Size n=1; n<=VDW_rep_screen_info_list_.size(); n++){
1122 
1123  VDW_RepScreeninfo const & VDW_rep_screen_info=VDW_rep_screen_info_list_[n];
1124 
1125  core::pose::Pose VDW_rep_screen_pose=VDW_rep_screen_info.VDW_pose; //Hard copy!
1126  utility::vector1< core::Size > const & VDW_rep_screen_align_res=VDW_rep_screen_info.VDW_align_res;
1127  utility::vector1< core::Size > const & working_align_res=VDW_rep_screen_info.working_align_res;
1128 
1129  //Align VDW_rep_screen_pose to screening_pose
1130  align_VDW_rep_screen_pose(VDW_rep_screen_pose, screening_pose, VDW_rep_screen_align_res, working_align_res, false /*verbose*/);
1131 
1132  for(Size seq_num=1; seq_num<=VDW_rep_screen_pose.total_residue(); seq_num++){
1133 
1134  if( Contain_seq_num( seq_num , VDW_rep_screen_info.VDW_ignore_res ) ) continue;
1135 
1136  for(Size ii=1; ii<=moving_res_list.size(); ii++){
1137 
1138  Size const moving_res=moving_res_list[ii];
1139 
1140  bool const residues_in_contact=Is_residues_in_contact(moving_res,screening_pose, seq_num, VDW_rep_screen_pose, physical_pose_clash_dist_cutoff_, num_clash_atom_cutoff_, local_verbose /*verbose*/);
1141 
1142  if(residues_in_contact) return false;
1143  }
1144  }
1145  }
1146 
1147  return true;
1148  }
1149  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1150 
1151  bool
1153  //Output_boolean("user_inputted_VDW_screen_pose_= " , user_inputted_VDW_screen_pose_);
1155  }
1156 
1157  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1158 
1159 
1160  void
1162 
1163  if(Is_reference_xyz_setup_==false) return;
1164 
1165  for(int n=0; n<=2; n++){
1166  if( ( (inputted_reference_xyz[n]-0.00001) > reference_xyz_[n] ) || ( (inputted_reference_xyz[n]+0.00001) < reference_xyz_[n]) ) {
1167  utility_exit_with_message("( ( (inputted_reference_xyz[n]-0.00001) > reference_xyz_[n] ) || ( (inputted_reference_xyz[n]+0.00001) < reference_xyz_[n]) )");
1168  std::cout << "inputted_reference_xyz= " << inputted_reference_xyz[0] << " " << inputted_reference_xyz[1] << " " << inputted_reference_xyz[2] << std::endl;
1169  std::cout << "reference_xyz_= " << reference_xyz_[0] << " " << reference_xyz_[1] << " " << reference_xyz_[2] << std::endl;
1170  }
1171  }
1172  }
1173 
1174  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1175  void
1177 
1178  if(Is_VDW_screen_bin_setup_==false) utility_exit_with_message("Is_VDW_screen_bin_setup_==false!");
1179 
1180  if(VDW_screen_bin_.size()==0) utility_exit_with_message("Is_VDW_screen_bin_setup_==true but VDW_screen_bin_==0!");
1181 
1182  }
1183 
1184 
1185 
1186  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1187  bool
1189 
1190 
1191  if(atom_pos_bin.x<1 || (atom_pos_bin.x > (bin_max_*2)) ||
1192  atom_pos_bin.y<1 || (atom_pos_bin.y > (bin_max_*2)) ||
1193  atom_pos_bin.z<1 || (atom_pos_bin.z > (bin_max_*2)) ){
1194 
1195  return false;
1196 
1197  }else{
1198  return true;
1199  }
1200 
1201  }
1202 
1203  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1204 
1205 
1206  bool
1208 
1209  if( !Is_atom_bin_in_range(atom_pos_bin) ){
1210 
1212  std::cout << "bin_max_*2= " << bin_max_*2 << std::endl;
1213  std::cout << " atom_pos_bin.x= " << atom_pos_bin.x << " atom_pos_bin.y= " << atom_pos_bin.y << " atom_pos_bin.z= " << atom_pos_bin.z << std::endl;
1214  std::cout << "atom_pos_bin out of range!" << std::endl;
1216  std::cout << "num_atom_pos_bin_out_of_range_message_outputted_so_far= " << num_atom_pos_bin_out_of_range_message_outputted_ << std::endl;
1217  }
1218 
1219  if(tolerate_off_range_atom_bin_) return false;
1220 
1221  utility_exit_with_message("atom_pos_bin out of range!");
1222 
1223  }
1224 
1225  return true;
1226 
1227  }
1228 
1229  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1230 
1231  void
1233 
1234  if(Is_reference_xyz_setup_==true) utility_exit_with_message("Is_reference_xyz is already setup!");
1235 
1236  reference_xyz_=reference_xyz;
1237 
1239 
1240  }
1241 
1242 
1243  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1244 
1245 
1246  Atom_Bin
1248 
1249  if(Is_reference_xyz_setup_==false) utility_exit_with_message("Is_reference_xyz is not setup yet!");
1250 
1251 
1252  numeric::xyzVector<core::Real> const atom_pos_ref_frame=atom_pos-reference_xyz_;
1253 
1254  Atom_Bin atom_bin;
1255  atom_bin.x=int(atom_pos_ref_frame[0]/atom_bin_size_);
1256  atom_bin.y=int(atom_pos_ref_frame[1]/atom_bin_size_);
1257  atom_bin.z=int(atom_pos_ref_frame[2]/atom_bin_size_);
1258 
1259 
1260  if(atom_pos_ref_frame[0]<0) atom_bin.x--;
1261  if(atom_pos_ref_frame[1]<0) atom_bin.y--;
1262  if(atom_pos_ref_frame[2]<0) atom_bin.z--;
1263 
1264  //////////////////////////////////////////////////////////
1265  atom_bin.x+=bin_offset_; //Want min bin to be at one.
1266  atom_bin.y+=bin_offset_; //Want min bin to be at one.
1267  atom_bin.z+=bin_offset_; //Want min bin to be at one.
1268 
1269 
1270  //////////////////////////////////////////////////////////
1271  return atom_bin;
1272  }
1273 
1274  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1275 
1278 
1279  if(Is_reference_xyz_setup_==false) utility_exit_with_message("Is_reference_xyz is not setup yet!");
1280 
1282 
1283  atom_pos[0]=(atom_bin.x+0.5-bin_offset_)*atom_bin_size_;
1284  atom_pos[1]=(atom_bin.y+0.5-bin_offset_)*atom_bin_size_;
1285  atom_pos[2]=(atom_bin.z+0.5-bin_offset_)*atom_bin_size_;
1286 
1287  atom_pos= atom_pos+reference_xyz_;
1288 
1289  return atom_pos;
1290  }
1291 
1292  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
1293 
1294  void
1296 
1297  if(Is_reference_xyz_setup_==false) utility_exit_with_message("Is_reference_xyz is not setup yet!");
1299 
1300  std::ofstream outfile;
1301 
1302  outfile.open(filename.c_str());
1303 
1304  Atom_Bin atom_bin;
1305 
1306  for(atom_bin.x=1; atom_bin.x<=int(bin_max_*2); atom_bin.x++){
1307  for(atom_bin.y=1; atom_bin.y<=int(bin_max_*2); atom_bin.y++){
1308  for(atom_bin.z=1; atom_bin.z<=int(bin_max_*2); atom_bin.z++){
1309 
1310  if(VDW_screen_bin_[atom_bin.x][atom_bin.y][atom_bin.z]==true){
1311  numeric::xyzVector<core::Real> const atom_pos = get_atom_pos(atom_bin);
1312  outfile << atom_pos[0] << " ";
1313  outfile << atom_pos[1] << " ";
1314  outfile << atom_pos[2] << " ";
1315  outfile << "\n";
1316  }
1317  }
1318  }
1319  }
1320 
1321  outfile.close();
1322  }
1323 
1324 
1325 
1326 
1327 }
1328 }
1329 }