Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Rotate.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 core/pack/task/ResfileReader.cc
11 /// @brief implementation of resfile reader and its command classes
12 /// @author Gordon Lemmon (glemmon@gmail.com)
13 
14 // Unit Headers
17 
21 // AUTO-REMOVED #include <protocols/moves/DataMap.hh>
22 #include <core/pose/util.hh>
23 #include <core/pose/Pose.hh>
26 
28 
30 // AUTO-REMOVED #include <protocols/qsar/qsarMap.hh>
31 
32 // Utility Headers
33 #include <numeric/random/random.hh>
34 #include <utility/exit.hh>
35 #include <basic/Tracer.hh>
36 #include <core/types.hh>
37 #include <algorithm>
38 #include <utility/tag/Tag.hh>
39 
40 #include <utility/vector0.hh>
41 #include <utility/excn/Exceptions.hh>
42 #include <utility/vector1.hh>
43 
44 //Auto Headers
45 #define foreach BOOST_FOREACH
46 using basic::T;
47 using basic::Error;
48 using basic::Warning;
49 
50 namespace protocols {
51 namespace ligand_docking {
52 
53 static basic::Tracer rotate_tracer("protocols.ligand_docking.ligand_options.rotate", basic::t_debug);
54 
57 {
59 }
60 
63  return new Rotate;
64 }
65 
68 {
69  return "Rotate";
70 }
71 
72 Ligand_info::Ligand_info():residues(), atr(0), rep(0), jump(){}
73 
75  residues(residues), atr(atr), rep(rep), jump(){}
76 
77 Ligand_info::Ligand_info(core::conformation::ResidueCOPs const residues, std::pair<int,int> scores, core::kinematics::Jump jump):
78  residues(residues), atr(scores.first), rep(scores.second), jump(jump){}
79 
80 
81 bool Ligand_info::operator<(Ligand_info const ligand_info) const{
82  return ( rep < ligand_info.rep || (rep == ligand_info.rep && atr < ligand_info.atr ) );
83 }
84 bool Ligand_info::operator<(std::pair<int,int> const scores) const{
85  return rep < scores.second || (rep == scores.second && atr < scores.first);
86 }
88 const & Ligand_info::get_residues() const{
89  return residues;
90 }
91 
92 ///@brief
93 Rotate::Rotate(): Mover("Rotate")
94 {}
95 
96 Rotate::Rotate(Rotate_info rotate_info): Mover("Rotate"), rotate_info_(rotate_info)
97 {}
98 
99 Rotate::Rotate(Rotate const & that):
100  //utility::pointer::ReferenceCount(),
101  protocols::moves::Mover( that ),
102  rotate_info_(that.rotate_info_)
103 {}
104 
106 
108  return new Rotate( *this );
109 }
110 
112  return new Rotate;
113 }
114 
116  return "Rotate";
117 }
118 
119 ///@brief parse XML (specifically in the context of the parser/scripting scheme)
120 void
122  utility::tag::TagPtr const tag,
123  protocols::moves::DataMap & /*data_map*/,
124  protocols::filters::Filters_map const & /*filters*/,
125  protocols::moves::Movers_map const & /*movers*/,
126  core::pose::Pose const & pose
127 )
128 {
129  if ( tag->getName() != "Rotate" ){
130  throw utility::excn::EXCN_RosettaScriptsOption("This should be impossible");
131  }
132  if ( ! tag->hasOption("chain") ) throw utility::excn::EXCN_RosettaScriptsOption("'Rotate' mover requires 'chain' tag");
133  if ( ! tag->hasOption("distribution") ) throw utility::excn::EXCN_RosettaScriptsOption("'Rotate' mover requires 'distribution' tag");
134  if ( ! tag->hasOption("degrees") ) throw utility::excn::EXCN_RosettaScriptsOption("'Rotate' mover requires 'degrees' tag");
135  if ( ! tag->hasOption("cycles") ) throw utility::excn::EXCN_RosettaScriptsOption("'Rotate' mover requires 'cycles' tag");
136 
137  rotate_info_.chain = tag->getOption<std::string>("chain");
140  std::string distribution_str= tag->getOption<std::string>("distribution");
141  rotate_info_.distribution= get_distribution(distribution_str);
142  rotate_info_.degrees = tag->getOption<core::Size>("degrees");
143  rotate_info_.cycles = tag->getOption<core::Size>("cycles");
144 
145  if ( tag->hasOption("tag_along_chains") ){
146  std::string const tag_along_chains_str = tag->getOption<std::string>("tag_along_chains");
147  utility::vector1<std::string> tag_along_chain_strs= utility::string_split(tag_along_chains_str, ',');
148  foreach(std::string tag_along_chain_str, tag_along_chain_strs){
149  utility::vector1<core::Size> chain_ids= get_chain_ids_from_chain(tag_along_chain_str, pose);
150  foreach( core::Size chain_id, chain_ids){
151  rotate_info_.tag_along_chains.push_back(chain_id);
153  core::Size const chain_begin (pose.conformation().chain_begin(chain_id));
154  assert( chain_begin == pose.conformation().chain_end(chain_id));
155  rotate_info_.tag_along_residues.push_back( chain_begin );
156  }
157  }
158  }
159 }
160 
163 
165  if(grid_manager->size() == 0)
166  {
168  all_chain_ids.push_back(rotate_info_.chain_id);
170  rotate_ligand(grid, pose);// move ligand to a random point in binding pocket
171  }else
172  {
173  // TODO refactor qsar map so it works properly
174  /*
175  if(grid_manager->is_qsar_map_attached())
176  {
177  //core::conformation::ResidueOP residue = new core::conformation::Residue(pose.residue(begin));
178  //qsar::qsarMapOP qsar_map(new qsar::qsarMap("default",residue));
179  //qsar_map->fill_with_value(1);
180  //grid_manager->set_qsar_map(qsar_map);
181  }
182  */
183  //grid_manager->initialize_all_grids(center);
184  //grid_manager->update_grids(pose,center);
185  }
186 }
187 
188 ///@brief for n random rotations, randomly pick one from among the best scoring set of diverse poses
191  core::pose::Pose & pose
192 ) {
193  if(rotate_info_.degrees == 0) return;
194 
198  }
199  else if(rotate_info_.distribution == Gaussian){
201  }
202 
204  utility::vector1< Ligand_info> ligands= create_random_rotations(grid, mover, pose, chain_begin);
205 
206  core::Size const jump_choice= (core::Size) numeric::random::RG.random_range(1, ligands.size());
207  {
208  pose.set_jump(rotate_info_.jump_id, ligands[jump_choice].jump);
209 
210  foreach(core::conformation::ResidueCOP residue, ligands[jump_choice].residues){
211  pose.replace_residue(chain_begin, *residue, false /*orient backbone*/);// assume rotamers are oriented?
212  ++chain_begin;
213  }
214  for(core::Size i=1; i <= rotate_info_.tag_along_residues.size(); ++i){
215  assert(rotate_info_.tag_along_residues.size() == ligands[jump_choice].tag_along_residues[i]);
217  core::conformation::ResidueCOP residue = ligands[jump_choice].tag_along_residues[i];
218  pose.replace_residue(residue_id, *residue, false /*orient backbone*/);// assume rotamers are oriented?
219  }
220  }
221 }
222 
224 {
225  if(rotate_info_.degrees == 0) return;
226 
230  }
231  else if(rotate_info_.distribution == Gaussian){
233  }
234  //core::Size chain_begin = pose.conformation().chain_begin(rotate_info_.chain_id);
235 
236 }
237 
242  core::pose::Pose & pose,
243  core::Size begin
244 )const{
246  core::Size const heavy_atom_number= core::pose::num_heavy_atoms(begin, end, pose);
247  core::pose::Pose local_pose= pose;
248  local_pose.remove_constraints();
250 
251  utility::vector1< Ligand_info> ligands; ///TODO make this a set. The set should check for another pose with a similar RMSD.
252  // "num_chi_angles" code comes from Ian Davis, who knows why. I added the max fxn so that waters can rotate (they have too few chi angles)
253  core::Size const max_diversity= std::max(5, static_cast<int>(5*core::pose::num_chi_angles(begin, end, local_pose)+1) );
254 
255  Ligand_info best=create_random_rotation(grid, mover, center, begin, end, local_pose);// first case;
256  add_ligand_conditionally(best, ligands, heavy_atom_number);
257  for(core::Size i=1; i<= rotate_info_.cycles && ligands.size() <= max_diversity ; ++i){
258  Ligand_info current =create_random_rotation(grid, mover, center, begin, end, local_pose);
259  if (current < best){
260  best= current;
261  }
262  add_ligand_conditionally(current, ligands, heavy_atom_number);
263  }
264  if(ligands.empty()){
265  ligands.push_back(best);
266  }
267  return ligands;
268 }
269 
273  core::Vector const center,
274  core::Size const begin,
275  core::Size const end,
276  core::pose::Pose & local_pose
277 ) const{
278  apply_rotate(mover, local_pose, center, rotate_info_.jump_id, rotate_info_.tag_along_jumps);
279  rb_grid_rotamer_trials_atr_rep(*grid, local_pose, begin, end);
281  std::pair<int, int> const scores= get_rb_atr_and_rep_scores(*grid, local_pose, begin, end);
282  Ligand_info ligand_info;
283  ligand_info.jump= jump;
284  ligand_info.atr= scores.first;
285  ligand_info.rep= scores.second;
286 
288 
289  foreach(core::Size chain_id, rotate_info_.tag_along_chains){
290  core::conformation::ResidueCOPs tag_along_residues = core::pose::get_chain_residues(local_pose, chain_id);
291  assert(tag_along_residues.size() == 1);
292  ligand_info.tag_along_residues.push_back(tag_along_residues[1]);
293  }
294  return ligand_info;
295 }
296 
298  Ligand_info const & ligand_info,
300  core::Size const heavy_atom_number
301 ){
302  if(
303  check_score(ligand_info, heavy_atom_number)
304  && check_RMSD(ligand_info, heavy_atom_number, ligands)
305  ){
306  ligands.push_back(ligand_info);
307  }
308 }
309 
312  core::pose::Pose & pose,
313  core::Vector const & center,
314  core::Size jump_id,
315  utility::vector1<core::Size> const tag_along_jumps
316 ){
317  mover->rb_jump(jump_id);
318  mover->apply(pose);
319  pose.update_actcoords();///TODO Verify necessity
320  mover->rot_center(center); // restore the old center so ligand doesn't walk away (really necessary?)
321 
322  mover->freeze();
323 
324  foreach(core::Size jump_id, tag_along_jumps){
325  mover->rb_jump(jump_id);
326  mover->apply(pose);
327  }
328 
329  mover->unfreeze();
330 
331 }
332 
334  Ligand_info const ligand,
335  core::Size const heavy_atom_number
336 ){
337  int const rep_threshold=0;
338  int const atr_threshold=-(int) (0.85 * heavy_atom_number);
339  return ligand.atr <= atr_threshold && ligand.rep <= rep_threshold;
340 }
341 
343  Ligand_info const ligand,
344  core::Size const heavy_atom_number,
345  utility::vector1< Ligand_info> const & ligands
346 ){
347  assert(heavy_atom_number > 0);
348 
349  // This next parameter is a wild heuristic guesses that seem OK for the Meiler x-dock set.
350  core::Real const diverse_rms = 0.65 * std::sqrt((double) heavy_atom_number);
351 
352  core::conformation::ResidueCOPs const & these_residues= ligand.get_residues();
353 
354  foreach(Ligand_info ligand_info, ligands){ // if ligands is empty we still return true so no need to check for this condition.
355  core::conformation::ResidueCOPs const & compare_residues= ligand_info.get_residues();
356  runtime_assert(these_residues.size() == compare_residues.size());
357 
358  core::Real const rms = (compare_residues.size() == 1) ///TODO write multi_residue automorphic fxn.
359  ? core::scoring::automorphic_rmsd(*these_residues[1], *compare_residues[1], false)
361 
362  if (rms < diverse_rms) return false;
363  }
364  return true;
365 }
366 
367 } //namespace ligand_docking
368 } //namespace protocols