Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Translate.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 
24 
26 
27 #include <utility/exit.hh>
28 #include <utility/string_util.hh>
29 #include <basic/Tracer.hh>
30 #include <core/types.hh>
31 #include <utility/tag/Tag.hh>
32 
33 #include <core/pose/util.hh>
34 #include <utility/vector0.hh>
35 #include <utility/vector1.hh>
36 #include <numeric/xyzVector.io.hh>
37 
38 #include <boost/foreach.hpp>
39 #define foreach BOOST_FOREACH
40 
41 //Auto Headers
42 #include <utility/excn/Exceptions.hh>
43 #include <core/pose/Pose.hh>
44 using basic::T;
45 using basic::Error;
46 using basic::Warning;
47 
48 namespace protocols {
49 namespace ligand_docking {
50 
51 static basic::Tracer translate_tracer("protocols.ligand_docking.ligand_options.translate", basic::t_debug);
52 
55 {
57 }
58 
61  return new Translate;
62 }
63 
66 {
67  return "Translate";
68 }
69 
70 ///@brief
72  //utility::pointer::ReferenceCount(),
73  Mover("Translate"),
74  translate_info_(),
75  chain_ids_to_exclude_(),
76  tag_along_jumps_()
77 {}
78 
80  //utility::pointer::ReferenceCount(),
81  Mover("Translate"),
82  translate_info_(translate_info),
83  chain_ids_to_exclude_(),
84  tag_along_jumps_()
85 {}
86 
88  //utility::pointer::ReferenceCount(),
89  protocols::moves::Mover( that ),
90  translate_info_(that.translate_info_),
91  chain_ids_to_exclude_(that.chain_ids_to_exclude_),
92  tag_along_jumps_(that.tag_along_jumps_)
93 {}
94 
96 
98  return new Translate( *this );
99 }
100 
102  return new Translate;
103 }
104 
106  return "Translate";
107 }
108 
109 ///@brief parse XML (specifically in the context of the parser/scripting scheme)
110 void
112  utility::tag::TagPtr const tag,
113  protocols::moves::DataMap & /*data_map*/,
114  protocols::filters::Filters_map const & /*filters*/,
115  protocols::moves::Movers_map const & /*movers*/,
116  core::pose::Pose const & pose
117 )
118 {
119  if ( tag->getName() != "Translate" ){
120  throw utility::excn::EXCN_RosettaScriptsOption("This should be impossible");
121  }
122  if ( ! tag->hasOption("chain") ) throw utility::excn::EXCN_RosettaScriptsOption("'Translate' mover requires chain tag");
123  if ( ! tag->hasOption("distribution") ) throw utility::excn::EXCN_RosettaScriptsOption("'Translate' mover requires distribution tag");
124  if ( ! tag->hasOption("angstroms") ) throw utility::excn::EXCN_RosettaScriptsOption("'Translate' mover requires angstroms tag");
125  if ( ! tag->hasOption("cycles") ) throw utility::excn::EXCN_RosettaScriptsOption("'Translate' mover requires cycles tag");
126  //if ( ! tag->hasOption("force") ) throw utility::excn::EXCN_RosettaScriptsOption("'Translate' mover requires force tag"); optional. default is don't force, meaning ligand stays put if it can't find somewhere to go.
127 
128  std::string chain = tag->getOption<std::string>("chain");
131  std::string distribution_str= tag->getOption<std::string>("distribution");
132  translate_info_.distribution= get_distribution(distribution_str);
133  translate_info_.angstroms = tag->getOption<core::Real>("angstroms");
134  translate_info_.cycles = tag->getOption<core::Size>("cycles");
135 
136  if(tag->hasOption("force")){
137  if(tag->getOption<std::string>("force") == "true")
138  translate_info_.force= true;
139  else if(tag->getOption<std::string>("force") != "false")
140  throw utility::excn::EXCN_RosettaScriptsOption("'force' option is true or false");
141  }
142 
143  if ( tag->hasOption("tag_along_chains") ){
144  std::string const tag_along_chains_str = tag->getOption<std::string>("tag_along_chains");
145  utility::vector1<std::string> tag_along_chain_strs= utility::string_split(tag_along_chains_str, ',');
146  foreach(std::string tag_along_chain_str, tag_along_chain_strs){
147  utility::vector1<core::Size> chain_ids= get_chain_ids_from_chain(tag_along_chain_str, pose);
148  foreach( core::Size chain_id, chain_ids){
149  core::Size jump_id= core::pose::get_jump_id_from_chain_id(chain_id, pose);
150  chain_ids_to_exclude_.push_back(chain_id);
151  tag_along_jumps_.push_back(jump_id);
152  }
153  }
154  }
155 
156 }
157 
160 
161  {// add this Translate's chain conditionally (for use with CompoundTranslate)
164  if( found == chain_ids_to_exclude_.end() )
166  }
168 
170  if(grid_manager->size() == 0)
171  {
173  translate_ligand(grid, translate_info_.jump_id, pose);// move ligand to a random point in binding pocket
174  }else
175  {
176  //TODO refactor qsar map so it works properly
177  /*
178  if(!grid_manager->is_qsar_map_attached())
179  {
180  utility::vector1<std::string> grid_names( grid_manager->get_grid_names() );
181  core::conformation::ResidueOP residue = new core::conformation::Residue(pose.residue(begin));
182  qsar::qsarMapOP qsar_map(new qsar::qsarMap("default",residue));
183  qsar_map->fill_with_value(1,grid_names);
184  grid_manager->set_qsar_map(qsar_map);
185  }
186  */
187  grid_manager->initialize_all_grids(center);
188  grid_manager->update_grids(pose,center);
190  }
191 }
192 
195  const core::Size jump_id,
196  core::pose::Pose & pose
197 ){
198  translate_tracer.Debug<< "making a uniform translator of up to " << translate_info_.angstroms<< " angstroms" << std::endl;
200 
201  core::pose::Pose const orig_pose(pose);
202  core::pose::Pose best_pose;
203  int best_score=100000;
204 
205  translate_tracer.Debug << "time to cycle: " << translate_info_.cycles << std::endl;
206  for (Size cycle = 0; cycle < translate_info_.cycles; ++cycle) {
207  mover.apply(pose);
209  // did our nbr_atom land in an empty space on the grid?
210  // Don't want to insist the nbr_atom is in the attractive region, because it may not be!
211  int grid_value=best_score;
212  if ( grid->is_in_grid(c.x(), c.y(), c.z()) )
213  {
214  grid_value= grid->getValue(c.x(), c.y(), c.z());
215  }
216  if ( grid_value <= 0 ){
217  translate_tracer.Trace << "Accepting ligand position with nbr_atom at " << c << std::endl;
218  mover.freeze();
219  foreach(core::Size tag_along_jump, tag_along_jumps_){
220  translate_tracer.Trace << "moving jump " << tag_along_jump<< " the same amount"<< std::endl;
221  mover.rb_jump(tag_along_jump);
222  mover.apply(pose);
223  }
224  return;
225  }
226  translate_tracer.Trace << "Rejecting ligand position with nbr_atom at " << c << std::endl;
227 
228  if( translate_info_.force && grid_value < best_score){
229  best_score = grid_value;
230  best_pose = pose;
231  }
232  pose = orig_pose; // reset and try again
233  }
234  // The code below only executes if we still haven't found a nonclashing position for the neighbor atom
235  if( translate_info_.force ){
236  translate_tracer.Trace << "Forcing neighbor atom to move (leading to a clash)" << std::endl;
237  pose= best_pose;
238  mover.freeze();
239  foreach(core::Size tag_along_jump, tag_along_jumps_){
240  mover.rb_jump(tag_along_jump);
241  mover.apply(pose);
242  }
243  return;
244  }else{
245  translate_tracer << "WARNING: cannot find placement for this ligand. Keeping original position. Use the force option to force translation"<< std::endl;
246  }
247 
248 }
249 
252  const core::Size jump_id,
253  core::pose::Pose & pose
254 ){
255  translate_tracer.Debug<< "making a Gaussian translator of up to "<< translate_info_.angstroms<<" angstroms";
256  protocols::rigid::RigidBodyPerturbMover mover( jump_id, 0 /*rotation*/, translate_info_.angstroms);
257 
258  core::pose::Pose const orig_pose(pose);
259  core::pose::Pose best_pose;
260  int best_score=100000;
261 
262  translate_tracer.Debug << "time to cycle: " << translate_info_.cycles << std::endl;
263  for (Size cycle = 0; cycle < translate_info_.cycles; ++cycle) {
264  mover.apply(pose);
266  // did our nbr_atom land in an empty space on the grid?
267  // Don't want to insist the nbr_atom is in the attractive region, because it may not be!
268  int grid_value=0;
269  if ( grid->is_in_grid(c.x(), c.y(), c.z()) )
270  {
271  grid_value= grid->getValue(c.x(), c.y(), c.z()) <= 0;
272  }
273  if ( grid_value < 0 ){
274  translate_tracer.Trace << "Accepting ligand position with nbr_atom at " << c << std::endl;
275  return;
276  }
277  translate_tracer.Trace << "Rejecting ligand position with nbr_atom at " << c << std::endl;
278 
279  if( translate_info_.force && grid_value < best_score){
280  best_score = grid_value;
281  best_pose = pose;
282  }
283  pose = orig_pose; // reset and try again
284  }
285  if( translate_info_.force ){
286  pose= best_pose;
287  return;
288  }else{
289  translate_tracer << "WARNING: cannot find placement for this ligand. Keeping original position. Use the force option to force translation"<< std::endl;
290  }
291 }
292 
295  const core::Size jump_id,
296  core::pose::Pose & pose
297 ) {
298  if(translate_info_.angstroms < 0) utility_exit_with_message("cannot have a negative translation value");
299  if(translate_info_.angstroms == 0) return;
300 
301  if(translate_info_.distribution == Uniform) uniform_translate_ligand(grid, jump_id, pose);
302  else if(translate_info_.distribution == Gaussian) gaussian_translate_ligand(grid, jump_id, pose);
303 }
304 
305 void Translate::translate_ligand(core::Size const jump_id,core::pose::Pose & pose, core::Size const & residue_id)
306 {
307  if(translate_info_.angstroms < 0) utility_exit_with_message("cannot have a negative translation value");
308  if(translate_info_.angstroms == 0) return;
309 
310  core::conformation::Residue const & residue(pose.residue(residue_id));
311 
312  protocols::rigid::RigidBodyMoverOP translate_mover;
314  translate_tracer.Debug<< "making a uniform translator of up to "<< translate_info_.angstroms<<" angstroms"<< std::endl;
316  }
318  translate_tracer.Debug<< "making a Gaussian translator of up to "<< translate_info_.angstroms<<" angstroms";
319  translate_mover= new protocols::rigid::RigidBodyPerturbMover ( jump_id, 0 /*rotation*/, translate_info_.angstroms);
320  }
321 
322  RandomConformerMoverOP conformer_mover = new RandomConformerMover(residue_id);
323 
324  core::pose::Pose orig_pose(pose);
325  translate_tracer.Debug << "time to cycle: " << translate_info_.cycles << std::endl;
326  core::Real best_score = 1000000;
327 
329  for (Size cycle = 0; cycle < translate_info_.cycles; ++cycle) {
330 
331  translate_tracer.Trace <<"Doing a translate move" <<std::endl;
332  translate_mover->apply(pose);
333  // }else
334  // {
335  //
336  // translate_tracer.Trace <<"Doing a conformer selection move" <<std::endl;
337  // conformer_mover->apply(pose);
338  // }
339  core::Real score(grid_manager->total_score(residue));
340  if(score <= best_score)
341  {
342  best_score = score;
343  orig_pose = pose;
344  translate_tracer.Trace << "accepted ligand position with score of " <<score <<std::endl;
345  }else
346  {
347  pose = orig_pose;
348  translate_tracer.Trace <<"rejected ligand position with score of "<<score <<std::endl;
349  }
350  }
351 
352 }
353 
356  return translate_info_.chain_id;
357 }
358 
359 void
361  std::set<core::Size>::const_iterator begin,
362  std::set<core::Size>::const_iterator end
363 ){
364  chain_ids_to_exclude_.insert( chain_ids_to_exclude_.end(), begin, end);
365 }
366 
367 
368 } //namespace ligand_docking
369 } //namespace protocols