Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RigidBodySampler.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 RigidBodySampler
11 /// @brief Not particularly fancy, just filters a list of poses.
12 /// @detailed
13 /// @author Rhiju Das
14 
15 
16 //////////////////////////////////
20 
21 //////////////////////////////////
22 // AUTO-REMOVED #include <core/chemical/util.hh>
23 #include <core/types.hh>
24 #include <core/pose/Pose.hh>
25 #include <core/pose/util.hh>
26 // AUTO-REMOVED #include <core/scoring/Energies.hh>
30 // AUTO-REMOVED #include <core/chemical/ChemicalManager.hh>
34 #include <core/kinematics/Stub.hh>
36 #include <core/scoring/rms_util.hh>
37 // AUTO-REMOVED #include <core/scoring/rms_util.tmpl.hh>
41 #include <basic/Tracer.hh>
42 #include <utility/vector1.hh>
43 #include <utility/io/ozstream.hh>
44 #include <utility/io/izstream.hh>
45 #include <numeric/xyzVector.hh>
46 #include <numeric/xyzMatrix.hh>
47 #include <numeric/conversions.hh>
49 
50 // AUTO-REMOVED #include <ObjexxFCL/format.hh>
51 #include <ObjexxFCL/string.functions.hh>
52 
53 #include <list>
54 #include <iostream>
55 
56 //Auto Headers
57 #include <core/id/AtomID.hh>
58 
59 using namespace core;
60 using core::Real;
61 
62 static basic::Tracer TR( "protocols.swa.rigid_body_sampler" ) ;
63 using numeric::conversions::radians;
64 using numeric::conversions::degrees;
65 
66 namespace protocols {
67 namespace swa {
68 
69  ////////////////////////////////////////////////////////////////////////////////////////////
70  // Rigid body sample. Keep track of total number of states so that we can extract a Kd
71  // Use input parameters to define fineness of sampling -- will look for convergence.
72  // Save lowest energy states.
73  //
74  // This only really works if we start with both the "reference residue" and the "moving residue" at the origin,
75  // with axes pointing along x, y, and z. That's pretty artificial. Another option might be to
76  // specify stubs of these fixed and moving residues?
77  //
78  ////////////////////////////////////////////////////////////////////////////////////////////
79 
80  //////////////////////////////////////////////////////////////
81  //constructor!
82  RigidBodySampler::RigidBodySampler( utility::vector1< Size > const & fixed_res,
83  utility::vector1< Size > const & moving_res ):
84  fixed_res_( fixed_res ),
85  moving_res_( moving_res ),
86  reference_axes_( Matrix::identity() ),
87  reference_centroid_( Vector( 0.0, 0.0, 0.0 ) ),
88  scorefxn_( core::scoring::getScoreFunction() ),
89  o2star_trials_( false ),
90  ignore_o2star_hbonds_in_filter_( false ),
91  assign_WC_edges_( false ),
92  reference_energy_( 0.0 ),
93  min_hbonds_( 0 ),
94  fa_rep_cutoff_( 0.0 ),
95  CONTACT_CUTOFF_squared_( 4.5 * 4.5 ),
96  STERIC_DIST_CUTOFF_squared_( 2.5 * 2.5 ),
97  MIN_NUM_CONTACTS_( 1 ),
98  rmsd_cutoff_( -1.0 )
99  {
101  }
102 
104 
105  ////////////////////////////////////////////////////////////
106  void
108 
110 
112 
113  count_total_ = 0;
114  count_good_ = 0;
115  count_no_contact_ = 0;
116  count_clash_ = 0;
117  }
118 
119  ////////////////////////////////////////////////////////////
120  // This is the only RNA centric thing, I think...
121  // also this basically doesn't work for what I want anyway.
122  ////////////////////////////////////////////////////////////
123  void
125  using namespace scoring::rna;
126  using namespace kinematics;
127  static RNA_CentroidInfo rna_centroid_info;
128 
129  reference_centroid_ = rna_centroid_info.get_base_centroid( rsd );
130  Stub s = rna_centroid_info.get_base_coordinate_system( rsd, reference_centroid_ );
131  reference_axes_ = s.M;
132 
133  //std::cout << "REFERENCE_CENTROID" << reference_centroid_(1) << ' ' << reference_centroid_(1) << ' ' << reference_centroid_(3) << std::endl;
134  }
135 
136  ////////////////////////////////////////////////////////////
137  void
139 
140  //clock_t const time_start( clock() );
141 
142  pose::Pose pose_start = pose;
143 
145 
147 
148  }
149 
150  /////////////////////////////////////////////////////////////
151  // Sample Euler angles.
152  ////////////////////////////////////////////////////////////
153  void
155 
156  pose::Pose pose_start = pose;
157  Matrix M;
158  Vector const & axis1 = reference_axes_.col_x();
159  Vector const & axis2 = reference_axes_.col_y();
160  Vector const & axis3 = reference_axes_.col_z();
161 
162  Size const N_SAMPLE_ALPHA( static_cast<Size>( ( alpha_max_ - alpha_min_) / alpha_increment_ + 1 ) );
163  Size i( 1 );
164 
166 
167  std::cout << i++ << " out of " << N_SAMPLE_ALPHA << ". Current count: " << count_total_ <<
168  ". num poses that pass cuts: " << count_good_ << std::endl;
169 
170  for ( Real cosbeta = cosbeta_min_; cosbeta <= cosbeta_max_; cosbeta += cosbeta_increment_ ){
171  if ( cosbeta < -1.0 ){
172  beta_ = -1.0 * degrees( std::acos( -2.0 - cosbeta ) );
173  } else if ( cosbeta > 1.0 ){
174  beta_ = -1.0 * degrees( std::acos( 2.0 - cosbeta ) );
175  } else {
176  beta_ = degrees( std::acos( cosbeta ) );
177  }
178 
179  std::cout << "BETA: " << beta_ << std::endl;
180 
181  // Try to avoid singularity at pole.
182  Real gamma_min_local = gamma_min_;
183  Real gamma_max_local = gamma_max_;
184  Real gamma_increment_local = gamma_increment_;
185  if ( (beta_<-179.999 || beta_>179.999) ){
186  gamma_min_local = 0.0;
187  gamma_max_local = 0.0;
188  gamma_increment_local = 1.0;
189  }
190 
191  for ( gamma_ = gamma_min_local; gamma_ <= gamma_max_local; gamma_ += gamma_increment_local ){
192 
193  create_euler_rotation( M, alpha_, beta_, gamma_, axis1, axis2, axis3 );
194 
195  rotate( pose, M, pose_start, moving_res_, reference_centroid_ );
196 
197  pose::Pose pose_to_translate = pose;
198 
199  search_translations( pose,
200  pose_to_translate );
201 
202  } // gamma
203  } // beta
204  }// alpha
205 
206  }
207 
208  /////////////////////////////////////////////////////////////
209  void
211  using namespace core::chemical;
212  for( Size i = 1; i <= pose.total_residue(); i++ ){
213  pose::add_variant_type_to_pose_residue( pose, "VIRTUAL_O2STAR_HYDROGEN", i );
214  }
215  }
216 
217  /////////////////////////////////////////////////////////////
218  // xyz
219  ////////////////////////////////////////////////////////////
220  void
222  pose::Pose const & pose_to_translate )
223  {
224  using namespace core::io::silent;
225  using namespace core::scoring;
226  using namespace protocols::swa;
227  using namespace pose;
228 
229  //Size const N_SAMPLE_TRANSLATE = 2 * static_cast< Size >( (box_size_ / xyz_increment_) + 0.5 ) + 1;
230  //Real const beta = 1.0/ temperature_;
231  // bool const positive_Z = option[ only_positive_Z ]();
232 
233  utility::vector1< Vector > moving_atoms, fixed_atoms;
234 
235  setup_heavy_atoms( pose_to_translate, moving_atoms, moving_res_ );
236  setup_heavy_atoms( pose_to_translate, fixed_atoms, fixed_res_ );
237 
238  // virual o2star pose -- needed for fa_rep checks.
239  Pose pose_to_translate_virtual_o2star = pose_to_translate;
240  Pose pose_virtual_o2star = pose;
241  virtualize_o2star( pose_to_translate_virtual_o2star );
242  virtualize_o2star( pose_virtual_o2star );
243 
244  // std::cout << "X " << x_min_ << ' ' << x_max_ << ' ' << x_increment_ << std::endl;
245  // std::cout << "Y " << y_min_ << ' ' << y_max_ << ' ' << y_increment_ << std::endl;
246  // std::cout << "Z " << z_min_ << ' ' << z_max_ << ' ' << z_increment_ << std::endl;
247 
248  for ( delx_ = x_min_; delx_ <= x_max_; delx_ += x_increment_ ){
249  for ( dely_ = y_min_; dely_ <= y_max_; dely_ += y_increment_ ){
250  for ( delz_ = z_min_; delz_ <= z_max_; delz_ += z_increment_ ){
251 
252  Vector translation( delx_, dely_, delz_ );
253 
254  count_total_++;
255  std::string const tag = "S_" + ObjexxFCL::lead_zero_string_of( count_total_, 6 );
256  // These could be sped up using grid indexing.
257  if ( !check_contact( translation, moving_atoms, fixed_atoms ) ) {
259  continue;
260  }
261 
262  if ( !check_steric_overlap( translation, moving_atoms, fixed_atoms ) ) {
263  count_clash_++;
264  continue;
265  }
266 
267  ////////////////////////////////////////////////////////////////////
268 
269  if ( fa_rep_cutoff_ > 0.0 ){
270  translate( pose_virtual_o2star, translation, pose_to_translate_virtual_o2star, moving_res_ );
271  if ( !check_fa_rep( pose_virtual_o2star ) ) continue;
272  }
273 
274  translate( pose, translation, pose_to_translate, moving_res_ );
275 
276  if ( ignore_o2star_hbonds_in_filter_ && min_hbonds_ > 0 && !check_num_hbonds( pose ) ) continue;
278  if ( min_hbonds_ > 0 && !check_num_hbonds( pose ) ) continue;
279 
280  count_good_++;
281 
282  Real const energy = (*scorefxn_)( pose );
283  save_rigid_body_settings( energy );
284 
285  ////////////////////////////////////////////////////////////////////
286  if ( energy < (best_energy_ + score_cutoff_) && sfd_ ){
287  save_silent_struct( pose, tag );
288  }
289  if ( energy < best_energy_ ) best_energy_ = energy;
290 
291 
292  }
293  }
294  }
295 
296  }
297 
298  ///////////////////////////////////////////////////////////////////////
299  void
301  using namespace core::io::silent;
302  using namespace core::scoring;
303 
304  (*scorefxn_)( pose );
305 
306  BinaryRNASilentStruct s( pose, tag ); // this is RNA-centric -- could make it OK for proteins.
307 
309 
310  s.add_energy( "alphaRB", alpha_ );
311  s.add_energy( "betaRB" , beta_ );
312  s.add_energy( "gammaRB", gamma_ );
313  s.add_energy( "x", delx_ );
314  s.add_energy( "y", dely_ );
315  s.add_energy( "z", delz_ );
316  s.add_energy( "log_vol", log( x_increment_ * y_increment_ * z_increment_ * radians(alpha_increment_) * cosbeta_increment_ * radians(gamma_increment_) ) );
317 
318  if (native_pose_) {
319  Real const rmsd = all_atom_rmsd( pose, *native_pose_ );
320  if ( (rmsd_cutoff_ > 0.0) && (rmsd > rmsd_cutoff_) ) return;
321  s.add_energy( "all_rms", rmsd );
322  }
323 
324  sfd_->add_structure( s );
325  }
326 
327  ///////////////////////////////////////////////////////////////////////
328  void
330 
331  using namespace core::io::silent;
332  using namespace core::scoring;
333  using namespace protocols::rna;
334 
336  utility::vector1< bool > is_bulged;
337 
338  classify_base_pairs( pose, base_pair_list, is_bulged );
339 
340  Size edge1( 0 ), edge2( 0 );
341  for ( Size n = 1; n <= base_pair_list.size(); n++ ) {
342  core::scoring::rna::Base_pair const base_pair = base_pair_list[ n ];
343 
344  if( base_pair.res1 == 1 && base_pair.res2 == 2 ){
345  edge1 = base_pair.edge1; edge2 = base_pair.edge2;
346  }
347  if( base_pair.res2 == 1 && base_pair.res1 == 2 ){
348  edge1 = base_pair.edge2; edge2 = base_pair.edge1;
349  }
350  }
351 
352  s.add_energy( "edge1", edge1 );
353  s.add_energy( "edge2", edge2 );
354 
355  }
356 
357  ///////////////////////////////////////////////////////////////////////
358  void
360  pose::Pose & pose,
361  std::string const rigid_body_sample_file ){
362 
363  using namespace core::io::silent;
364  using namespace utility::io;
365  izstream input( rigid_body_sample_file );
366 
367  if ( !input ) {
368  std::cerr << "No file: " << rigid_body_sample_file << std::endl;
369  utility_exit_with_message( "No file" );
370  }
371 
372  pose::Pose pose_start = pose;
373 
374  Real alpha, beta, gamma, x, y, z;
375  count_total_ = 0;
376  while ( input >> alpha ) {
377 
378  input >> beta >> gamma >> x >> y >> z >> skip;
379  apply_rigid_body_settings( pose, pose_start,
380  alpha, beta, gamma, x, y, z );
381 
382  // Real const energy = // Unused variable causes warning.
383  (*scorefxn_)( pose );
384 
385  count_total_++;
386  std::string const tag = "S_" + ObjexxFCL::lead_zero_string_of( count_total_, 6 );
387 
388  BinaryRNASilentStruct s( pose, tag ); // this is RNA-centric -- could make it OK for proteins.
389  sfd_->add_structure( s );
390 
391  }
392 
393  pose = pose_start;
394  }
395 
396  ///////////////////////////////////////////////////////////////////////
397  void
399  Real const alpha,
400  Real const beta,
401  Real const gamma,
402  Real const x,
403  Real const y,
404  Real const z ){
405 
406  static Matrix M;
407  Vector const & axis1 = reference_axes_.col_x();
408  Vector const & axis2 = reference_axes_.col_y();
409  Vector const & axis3 = reference_axes_.col_z();
410 
411  create_euler_rotation( M, alpha, beta, gamma, axis1, axis2, axis3 );
412  rotate( pose, M, pose_start, moving_res_, reference_centroid_ );
413  translate( pose, Vector( x,y,z), pose, moving_res_ );
414 
415  // This is useful for saving silent structures...
416  alpha_ = alpha;
417  beta_ = beta;
418  gamma_ = gamma;
419  delx_ = x;
420  dely_ = y;
421  delz_ = z;
422  }
423 
424  ///////////////////////////////////////////////////////////////////////
425  void
427  utility::vector1< Vector > & pose_atoms,
428  utility::vector1< Size > const & subset_res ){
429 
430  pose_atoms.clear();
431 
432  for ( Size n = 1; n <= subset_res.size(); n++ ) {
433  Size const i = subset_res[ n ];
434 
435  for ( Size j = 1; j <= pose.residue_type( i ).nheavyatoms(); j++ ){
436  if ( pose.residue(i).is_virtual( j ) ) continue;
437  pose_atoms.push_back( pose.xyz( core::id::AtomID(j,i) ) );
438  }
439 
440  }
441 
442  }
443 
444 
445  ///////////////////////////////////////////////////////////////////////
446  void
448  Real const CONTACT_CUTOFF_ = setting;
449  CONTACT_CUTOFF_squared_ = CONTACT_CUTOFF_ * CONTACT_CUTOFF_;
450  }
451 
452  ///////////////////////////////////////////////////////////////////////
453  void
455  MIN_NUM_CONTACTS_ = setting;
456  }
457 
458  ///////////////////////////////////////////////////////////////////////
459  void
461  sfd_ = sfd;
462  }
463 
464  ///////////////////////////////////////////////////////////////////////
465  void
466  RigidBodySampler::set_o2star_trials( bool const setting ){
467 
468  using namespace core::scoring;
469 
470  o2star_trials_ = setting;
471 
472  if ( o2star_trials_ ){
474  o2star_pack_scorefxn_->set_weight( fa_atr, scorefxn_->get_weight( fa_atr ) );
475  o2star_pack_scorefxn_->set_weight( fa_rep, scorefxn_->get_weight( fa_rep ) );
476  o2star_pack_scorefxn_->set_weight( hbond_lr_bb_sc, scorefxn_->get_weight( hbond_lr_bb_sc ) );
477  o2star_pack_scorefxn_->set_weight( hbond_sr_bb_sc, scorefxn_->get_weight( hbond_sr_bb_sc ) );
478  o2star_pack_scorefxn_->set_weight( hbond_sc, scorefxn_->get_weight( hbond_sc ) );
479  o2star_pack_scorefxn_->set_energy_method_options( scorefxn_->energy_method_options() );
480  // note that geom_sol is not optimized well --> replace with lk_sol for now.
481  o2star_pack_scorefxn_->set_weight( fa_sol, scorefxn_->get_weight( lk_nonpolar ) );
482  }
483  }
484 
485  ///////////////////////////////////////////////////////////////////////
486  bool
488  utility::vector1< Vector > const & moving_atoms,
489  utility::vector1< Vector > const & partner_atoms
490  ){
491 
492  Size num_contacts( 0 );
493 
494  for ( Size i = 1; i <= moving_atoms.size(); i++ ) {
495  Vector const test_cbeta = moving_atoms[ i ] + translation;
496 
497  for ( Size j = 1; j <= partner_atoms.size(); j++ ) {
498  Vector const & partner_cbeta = partner_atoms[ j ];
499 
500  if ( ( test_cbeta - partner_cbeta ).length_squared() < CONTACT_CUTOFF_squared_ ) {
501  num_contacts ++;
502  if ( num_contacts >= MIN_NUM_CONTACTS_ ) return true;
503  }
504 
505  }
506  }
507 
508  return false;
509 
510  }
511 
512  ///////////////////////////////////////////////////////////////////////
513  void
515  Real const STERIC_DIST_CUTOFF_ = setting;
516  STERIC_DIST_CUTOFF_squared_ = STERIC_DIST_CUTOFF_ * STERIC_DIST_CUTOFF_;
517  }
518 
519  ///////////////////////////////////////////////////////////////////////
520  bool
522  utility::vector1< Vector > const & moving_atoms,
523  utility::vector1< Vector > const & partner_atoms
524  ){
525 
526  for ( Size i = 1; i <= moving_atoms.size(); i++ ) {
527  Vector const test_atom = moving_atoms[ i ] + translation;
528 
529  for ( Size j = 1; j <= partner_atoms.size(); j++ ) {
530  Vector const & partner_atom = partner_atoms[ j ];
531  if ( ( test_atom - partner_atom ).length_squared() < STERIC_DIST_CUTOFF_squared_ ) return false;
532  }
533  }
534 
535  return true;
536 
537  }
538 
539  /////////////////////////////////////////////////////////////
540  bool in_vector( Size const & i, utility::vector1< Size > const & vec ){
541  for ( Size n = 1; n <= vec.size(); n++ ) {
542  if ( i == vec[n] ) return true;
543  }
544  return false;
545  }
546 
547  /////////////////////////////////////////////////////////////
548  bool
550 
551  using namespace core::scoring;
552 
553  // figure out H-bonds.
554  hbonds::HBondOptionsOP hbond_options( new hbonds::HBondOptions() );
555  hbond_options->use_hb_env_dep( false );
556  hbonds::HBondSetOP hbond_set( new hbonds::HBondSet( hbond_options ) );
557  hbonds::fill_hbond_set( pose, false /*calc deriv*/, *hbond_set );
558 
559  Size num_cross_hbonds( 0 );
560  Real const HBOND_ENERGY_CUTOFF( -0.5 );
561 
562  for (Size i = 1; i <= hbond_set->nhbonds(); i++ ) {
563  hbonds::HBond const & hbond( hbond_set->hbond( i ) );
564 
565  Size const don_res_num = hbond.don_res();
566  Size const don_hatm = hbond.don_hatm();
567  Size const acc_res_num = hbond.acc_res();
568  Size const acc_atm = hbond.acc_atm();
569 
570  if ( hbond.energy() > HBOND_ENERGY_CUTOFF ) continue;
571 
572  // could be sped up by indexing 'in_moving_res' and 'in_fixed_res'
573  if ( !( ( in_vector( don_res_num, moving_res_ ) && in_vector( acc_res_num, fixed_res_ ) ) ||
574  ( in_vector( acc_res_num, moving_res_ ) && in_vector( don_res_num, fixed_res_ ) ) ) ) continue;
575 
576  if ( ignore_o2star_hbonds_in_filter_ && ( pose.residue_type( don_res_num ).atom_name( don_hatm ) == "2HO*" ) ) continue;
577  if ( ignore_o2star_hbonds_in_filter_ && ( pose.residue_type( acc_res_num ).atom_name( acc_atm ) == " O2*" ) ) continue;
578 
579  num_cross_hbonds++;
580 
581  if ( num_cross_hbonds >= min_hbonds_ ) return true;
582 
583  }
584 
585  return false;
586 
587  }
588 
589  /////////////////////////////////////////////////////////////
590  bool
592  Real const DIST_CUTOFF = 4.0;
593 
594  for ( Size n = 1; n <= moving_res_.size(); n++ ){
595  Vector const & o2star_xyz = pose.residue( moving_res_[n] ).xyz( " O2*" );
596  for ( Size m = 1; m <= fixed_res_.size(); m++ ){
597  for ( Size k = 1; k <= pose.residue_type( fixed_res_[m] ).nheavyatoms(); k++ ) {
598  if ( ( o2star_xyz - pose.residue( fixed_res_[m] ).xyz( k ) ).length() < DIST_CUTOFF ) return true;
599  }
600  }
601  }
602 
603  for ( Size n = 1; n <= fixed_res_.size(); n++ ){
604  Vector const & o2star_xyz = pose.residue( fixed_res_[n] ).xyz( " O2*" );
605  for ( Size m = 1; m <= moving_res_.size(); m++ ){
606  for ( Size k = 1; k <= pose.residue_type( moving_res_[m] ).nheavyatoms(); k++ ) {
607  if ( ( o2star_xyz - pose.residue( moving_res_[m]).xyz( k ) ).length() < DIST_CUTOFF ) return true;
608  }
609  }
610  }
611 
612  return false;
613  }
614 
615  /////////////////////////////////////////////////////////////
616  bool
618 
619  using namespace core::scoring;
620 
621  static bool init( false );
622  static ScoreFunctionOP rep_scorefxn( new ScoreFunction);
623  if (!init ){
624  rep_scorefxn->set_weight( fa_rep, 1.0 );
625  init = true;
626  }
627 
628  Real const fa_rep_score = (*rep_scorefxn)( pose );
629  return ( fa_rep_score <= fa_rep_cutoff_ );
630 
631  }
632 
633 
634  /////////////////////////////////////////////////////////////
635  void
637 
638  utility::vector1< Real > rigid_body_settings;
639  rigid_body_settings.push_back( alpha_ );
640  rigid_body_settings.push_back( beta_ );
641  rigid_body_settings.push_back( gamma_ );
642  rigid_body_settings.push_back( delx_ );
643  rigid_body_settings.push_back( dely_ );
644  rigid_body_settings.push_back( delz_ );
645  rigid_body_settings.push_back( energy );
646 
647  all_rigid_body_settings_save_.push_back( rigid_body_settings );
648 
649  }
650 
651  /////////////////////////////////////////////////////////////
652  void
654  alpha_increment_ = ( 360.0 / static_cast< Real >( n_sample ) );
656  alpha_max_ = n_sample * alpha_increment_;
657  }
658 
659  /////////////////////////////////////////////////////////////
660  void
662  gamma_increment_ = ( 360.0 / static_cast< Real >( n_sample ) );
664  gamma_max_ = n_sample * gamma_increment_;
665  }
666 
667  /////////////////////////////////////////////////////////////
668  void
670  cosbeta_increment_ = 2.0 / n_sample;
671 
672  //cosbeta_min_ = -1.0 + 0.5 * cosbeta_increment_;
673  //cosbeta_max_ = -1.0 + ( n_sample - 0.5 ) * cosbeta_increment_;
674 
675  // Put in a condition to not sample gamma if we're at north or south pole
676  cosbeta_min_ = -1.0;
677  cosbeta_max_ = 1.0;
678 
679  }
680 
681  /////////////////////////////////////////////////////////////
682  void
683  RigidBodySampler::set_translation_sample( Real const box_size, Real const xyz_increment ){
684 
685  x_increment_ = xyz_increment;
686  y_increment_ = xyz_increment;
687  z_increment_ = xyz_increment;
688 
689  x_min_ = -box_size;
690  x_max_ = box_size;
691 
692  y_min_ = -box_size;
693  y_max_ = box_size;
694 
695  z_min_ = -box_size;
696  z_max_ = box_size;
697 
698  }
699 
700  /////////////////////////////////////////////////////////////
701  void
703  z_min_ = 0.0;
704  z_max_ = 0.0;
705  z_increment_ = 0.1; //will only sample z = 0.0.
706  }
707 
708  /////////////////////////////////////////////////////////////
709  void
711  cosbeta_min_ = -1.0;
712  cosbeta_max_ = -1.0;
713  cosbeta_increment_ = 0.1;
714  }
715 
716  /////////////////////////////////////////////////////////////
717  void
719  cosbeta_min_ = 1.0;
720  cosbeta_max_ = 1.0;
721  cosbeta_increment_ = 0.1;
722  }
723 
724  /////////////////////////////////////////////////////////////
725  void
727 
728  pose::Pose pose_perturb = pose;
729  translate( pose_perturb, Vector( 1000.0, 1000.0, 1000.0 ), pose, moving_res_ );
730  reference_energy_ = (*scorefxn_)( pose );
731 
732  }
733 
734  /////////////////////////////////////////////////////////////
735  void
736  RigidBodySampler::output_results( utility::io::ozstream & out ){
737 
738  Real const volume_element = x_increment_ * y_increment_ * z_increment_ * radians(alpha_increment_) * cosbeta_increment_ * radians(gamma_increment_);
739 
740  out << "0.0 0.0 0.0 0.0 0.0 0.0 " << ' ' << 0.0 << ' ' << count_no_contact_ * volume_element << std::endl;
741  out << "0.0 0.0 0.0 0.0 0.0 0.0 " << ' ' << 999.99 << ' ' << count_clash_ * volume_element << std::endl;
742 
743  for ( Size i = 1; i <= all_rigid_body_settings_save_.size(); i++ ) {
744 
745  for ( Size n = 1; n <= all_rigid_body_settings_save_[ i ].size(); n++ ){
746  out << ' ' << all_rigid_body_settings_save_[ i ][ n ];
747  }
748  out << ' ' << volume_element << std::endl;
749 
750  }
751 
752  }
753 
754  /////////////////////////////////////////////////////////////////////////////////////////////
755  void
756  RigidBodySampler::output_silent_file( std::string const silent_file, bool const write_score_only ){
757 
758  using namespace core::io::silent;
759 
760  SilentFileData sfd;
761 
762  SilentFileData::iterator iter = sfd_->begin();
763  SilentStructOP s = *iter;
764  sfd.write_silent_struct( *s, silent_file, write_score_only );
765 
766  utility::io::ozstream out;
767  out.open_append( silent_file );
768 
769 
770  for ( ++iter; iter != sfd_->end(); ++iter ){
771  SilentStructOP s = *iter;
772  sfd.write_silent_struct( *s, out, write_score_only );
773  }
774 
775  }
776 
777 
778  /////////////////////////////////////////////////////////////////////////////////////////////
779  void
780  RigidBodySampler::output_histogram( utility::io::ozstream & out ){
781 
782  Real const volume_element = x_increment_ * y_increment_ * z_increment_ * radians(alpha_increment_) * cosbeta_increment_ * radians(gamma_increment_);
783 
784  // need to define histogram bins and energies.
785  Real const energy_hist_min_ = -5.0;
786  Real const energy_hist_max_ = 10.0;
787  Real const energy_increment_ = 0.01;
788  utility::vector1< Real > histogram_energy, volumes;
789  for ( Real energy = energy_hist_min_; energy < energy_hist_max_; energy += energy_increment_ ){
790  histogram_energy.push_back( energy );
791  volumes.push_back( 0.0 );
792  }
793 
794  /// Go through data. assign as either clash, special low energy, or in the histogram
795  std::map< Size, utility::vector1< Real > > histogram_rigid_body_settings;
796  utility::vector1< utility::vector1< Real > > good_energy_rigid_body_settings;
797  Size count_clash_local = count_clash_;
798  for ( Size i = 1; i <= all_rigid_body_settings_save_.size(); i++ ) {
799 
800  utility::vector1< Real > const & rigid_body_setting = all_rigid_body_settings_save_[ i ];
801 
802  Real const energy = rigid_body_setting[ 7 ];
803 
804  if ( energy < energy_hist_min_ ) {
805  good_energy_rigid_body_settings.push_back( rigid_body_setting );
806  } else if ( energy > energy_hist_max_ ){
807  count_clash_local += 1;
808  } else {
809  Size const bin = static_cast< Size >( ( energy - energy_hist_min_) / energy_increment_ ) + 1;
810  volumes[ bin ] += volume_element;
811  histogram_rigid_body_settings[ bin ] = rigid_body_setting;
812  }
813 
814  }
815 
816  ////////////////////////////////////////////////////////
817  // output
818  ////////////////////////////////////////////////////////
819  out << "0.0 0.0 0.0 0.0 0.0 0.0 " << ' ' << 0.00 << ' ' << count_no_contact_ * volume_element << std::endl;
820  out << "0.0 0.0 0.0 0.0 0.0 0.0 " << ' ' << 999.99 << ' ' << count_clash_local * volume_element << std::endl;
821 
822  for ( Size i = 1; i <= histogram_energy.size(); i++ ){
823  if ( volumes[ i ] > 0.0 ){
824  utility::vector1< Real > const & rigid_body_setting = histogram_rigid_body_settings[ i ];
825 
826  for ( Size n = 1; n <= 6; n++ ){
827  out << ' ' << rigid_body_setting[ n ];
828  }
829  out << ' ' << histogram_energy[ i ];
830  out << ' ' << volumes[ i ] << std::endl;
831  }
832  }
833 
834 
835  for ( Size i = 1; i <= good_energy_rigid_body_settings.size(); i++ ){
836  utility::vector1< Real > const & rigid_body_setting = good_energy_rigid_body_settings[ i ];
837 
838  for ( Size n = 1; n <= rigid_body_setting.size(); n++ ){
839  out << ' ' << rigid_body_setting[ n ];
840  }
841  out << ' ' << volume_element << std::endl;
842  }
843 
844  }
845 
846  ////////////////////////////////////////////////////////
848 
849 
850 
851 }
852 }