Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RigidSearchMover.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 protocols/ligand_docking/RigidSearchMover.cc
11 ///
12 /// @brief
13 /// @author Ian W. Davis
14 
15 // IS THIS DEPRECATED? IS IT USED ANYWHERE?
16 
17 
19 
21 #include <core/kinematics/Jump.hh>
22 #include <core/kinematics/Stub.hh>
23 #include <core/pose/Pose.hh>
25 #include <basic/Tracer.hh>
27 #include <numeric/random/random.hh>
28 
29 #include <cmath>
30 
31 #include <utility/vector1.hh>
32 
33 #if defined(WIN32) || defined(__CYGWIN__)
34  #include <ctime>
35 #endif
36 
37 static basic::Tracer TR("protocols.ligand_docking.RigidSearchMover", basic::t_debug);
38 static numeric::random::RandomGenerator mc_RG(32900); // <- Magic number, do not change it!!!
39 
40 namespace protocols {
41 namespace ligand_docking {
42 
43 
45  Mover(),
46  jump_id_(jump_id),
47  num_trials_(num_trials),
48  scorefxn_(scorefxn),
49  temperature_(2),
50  rotate_deg_(3),
51  translate_Ang_(0.1),
52  rotate_rsd_(0),
53  rotate_atom_(0),
54  recover_low_(true)
55 {
56  Mover::type( "RigidSearch" );
57 }
58 
59 
61  //utility::pointer::ReferenceCount(),
62  Mover(),
63  jump_id_( that.jump_id_ ),
64  num_trials_( that.num_trials_ ),
65  scorefxn_( that.scorefxn_ ),
66  temperature_( that.temperature_ ),
67  rotate_deg_( that.rotate_deg_ ),
68  translate_Ang_( that.translate_Ang_ ),
69  rotate_rsd_( that.rotate_rsd_ ),
70  rotate_atom_( that.rotate_atom_ ),
71  recover_low_( that.recover_low_ )
72 {
73 }
74 
75 
77 {
78 }
79 
80 
82 {
83  clock_t start_time = clock();
84  using namespace core;
85  using kinematics::Jump;
86  using kinematics::Stub;
87  Jump best_jump_so_far( pose.jump(jump_id_) );
88  Jump last_accepted_jump( best_jump_so_far );
89  Real best_score_so_far( (*scorefxn_)( pose ) );
90  Real last_accepted_score( best_score_so_far );
91  int num_accepts(0), num_improves(0);
92  int const report_interval = std::min( 50, num_trials_ / 5 );
93  TR << "Starting score " << best_score_so_far << std::endl;
94  for(int i = 1; i <= num_trials_; ++i) {
95  if( i % report_interval == 0 ) {
96  TR << "Cycle " << i << ", " << num_accepts << " accepts, " << num_improves << " improves, score = " << (*scorefxn_)( pose ) << std::endl;
97  }
98  // Do move (copied from RigidBodyPerturbMover)
99  // Want to update our center of rotation every time we take a step.
100  // Can either rotate around downstream centroid (default) or a specific atom.
101  Vector dummy_up, rot_center;
102  if( rotate_rsd_ <= 0 || rotate_atom_ <= 0 ) protocols::geometry::centroids_by_jump(pose, jump_id_, dummy_up, rot_center);
103  else rot_center = pose.residue(rotate_rsd_).xyz(rotate_atom_);
104  Jump curr_jump = pose.jump( jump_id_ );
105  // comments explain which stub to use when...
106  Stub downstream_stub = pose.conformation().downstream_jump_stub( jump_id_ );
107  curr_jump.set_rb_center( 1 /*n2c*/, downstream_stub, rot_center );
108  curr_jump.gaussian_move( 1 /*n2c*/, translate_Ang_, rotate_deg_ );
109  pose.set_jump_now( jump_id_, curr_jump );
110  // score and do Boltzmann test
111  Real const curr_score = (*scorefxn_)( pose );
112  Real const deltaE = last_accepted_score - curr_score;
113  if( deltaE < 0 ) {
114  // copied from MonteCarlo::boltzmann()
115  Real const boltz = std::max(-40.0, deltaE / temperature_);
116  if( mc_RG.uniform() >= std::exp(boltz) ) { // rejected!
117  pose.set_jump_now( jump_id_, last_accepted_jump );
118  continue;
119  }
120  }
121  // accepted, thermally or otherwise
122  num_accepts += 1;
123  last_accepted_jump = pose.jump( jump_id_ );
124  last_accepted_score = curr_score;
125  if( last_accepted_score < best_score_so_far ) {
126  num_improves += 1;
127  best_jump_so_far = last_accepted_jump;
128  best_score_so_far = last_accepted_score;
129  }
130  }
131  // recover lowest energy pose
132  if( recover_low_ ) pose.set_jump_now( jump_id_, best_jump_so_far );
133  TR << "Best score " << best_score_so_far << ", end score " << (*scorefxn_)( pose ) << std::endl; // should be same!
134  clock_t end_time = clock();
135  TR << "Speed: " << num_trials_ / (double(end_time - start_time) / CLOCKS_PER_SEC) << " cycles per second" << std::endl;
136 }
137 
140  return "RigidSearchMover";
141 }
142 
143 
144 } // namespace ligand_docking
145 } // namespace protocols