Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HighResDocker.cc
Go to the documentation of this file.
1 // vi: set ts=2 noet:
2 //
3 // (c) Copyright Rosetta Commons Member Institutions.
4 // (c) This file is part of the Rosetta software suite and is made available under license.
5 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
6 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
7 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
8 
9 /// @file core/pack/task/ResfileReader.cc
10 /// @brief implementation of resfile reader and its command classes
11 /// @author Gordon Lemmon (glemmon@gmail.com), adapted from the ResfileReader code
12 /// by Steven Lewis (smlewi@unc.edu) and Andrew Leaver-Fay
13 
14 // Unit Headers
22 #include <core/pose/util.hh>
23 
25 #include <protocols/moves/Mover.hh>
31 
33 // AUTO-REMOVED #include <core/conformation/Conformation.hh>
36 // AUTO-REMOVED #include <core/kinematics/FoldTree.hh>
40 
42 // Package Headers
43 #include <core/pose/Pose.hh>
45 // AUTO-REMOVED #include <core/scoring/constraints/ResidueTypeConstraint.hh>
46 
47 // Project Headers
49 #include <basic/options/option.hh>
50 #include <basic/options/keys/packing.OptionKeys.gen.hh>
51 
52 // Utility Headers
53 // AUTO-REMOVED #include <utility/string_util.hh>
54 #include <core/types.hh>
55 #include <basic/Tracer.hh>
56 // AUTO-REMOVED #include <core/kinematics/Edge.hh>
58 
59 // Scripter Headers
60 #include <utility/tag/Tag.hh>
62 
63 // Boost Headers
64 #include <boost/foreach.hpp>
65 #define foreach BOOST_FOREACH
66 
67 //STL headers
68 #include <string>
69 
70 #include <set>
71 
72 //Auto Headers
74 #include <utility/vector0.hh>
75 #include <utility/excn/Exceptions.hh>
76 #include <utility/vector1.hh>
77 
78 namespace protocols {
79 namespace ligand_docking {
80 
81 static basic::Tracer high_res_docker_tracer("protocols.ligand_docking.ligand_options.Protocol", basic::t_debug);
82 
85 {
87 }
88 
91  return new HighResDocker;
92 }
93 
96 {
97  return "HighResDocker";
98 }
99 
100 ///@brief
102  Mover("HighResDocker"),
103  num_cycles_(0),
104  repack_every_Nth_(0),
105  score_fxn_(NULL),
106  movemap_builder_(NULL),
107  resfile_("")
108 {
109  resfile_.clear();
110  // Now use cycles and repack_every_Nth to replicate these options...
111  //meiler2006: 50, 8;
112  //abbreviated: 5, 4;
113  //abbrev2: 6, 3;
114 }
115 
117  //utility::pointer::ReferenceCount(),
118  protocols::moves::Mover( that ),
119  num_cycles_(that.num_cycles_),
120  repack_every_Nth_(that.repack_every_Nth_),
121  //chains_(that.chains_),
122  score_fxn_(that.score_fxn_),
123  movemap_builder_(that.movemap_builder_)
124 {}
125 
127 
129  return new HighResDocker( *this );
130 }
131 
133  return new HighResDocker;
134 }
135 
137  return "HighResDocker";
138 }
139 
140 ///@brief parse XML (specifically in the context of the parser/scripting scheme)
141 void
143  utility::tag::TagPtr const tag,
144  protocols::moves::DataMap & datamap,
145  protocols::filters::Filters_map const & /*filters*/,
146  protocols::moves::Movers_map const & /*movers*/,
147  core::pose::Pose const & /*pose*/
148 )
149 {
150  if ( tag->getName() != "HighResDocker" ){
151  throw utility::excn::EXCN_RosettaScriptsOption("This should be impossible");
152  }
153 
154  // cycles and repack_every_Nth
155  if ( ! tag->hasOption("cycles") ) throw utility::excn::EXCN_RosettaScriptsOption("'HighResDocker' mover requires cycles tag");
156  if ( ! tag->hasOption("repack_every_Nth") ) throw utility::excn::EXCN_RosettaScriptsOption("'HighResDocker' mover requires repack_every_Nth tag");
157  num_cycles_= tag->getOption<core::Size>("cycles");
158  repack_every_Nth_= tag->getOption<core::Size>("repack_every_Nth");
159 
160  /// Score Function ///
161  if ( ! tag->hasOption("scorefxn") ) throw utility::excn::EXCN_RosettaScriptsOption("'HighResDocker' requires 'scorefxn' tag");
162  std::string scorefxn_name= tag->getOption<std::string>("scorefxn");
163  score_fxn_= datamap.get< core::scoring::ScoreFunction * >( "scorefxns", scorefxn_name);
164 
165  /// MoveMapBuilder///
166  if ( ! tag->hasOption("movemap_builder") ) throw utility::excn::EXCN_RosettaScriptsOption("'HighResDocker' requires 'movemap_builder' tag");
167  std::string movemap_builder_name= tag->getOption<std::string>("movemap_builder");
168  movemap_builder_= datamap.get< MoveMapBuilder * >( "movemap_builders", movemap_builder_name);
169 
170  /// Resfile ///
171  if ( tag->hasOption("resfile") ){
172  resfile_= tag->getOption<std::string>("resfile");
173  }
174 }
175 
178  MinimizeLigandOPs minimize_ligands;
179 
180  LigandAreas const ligand_areas =
181  movemap_builder_->get_sc_interface_builder()->get_ligand_areas();
182  LigandAreas::const_iterator ligand_area_itr= ligand_areas.begin();
183  LigandAreas::const_iterator const ligand_area_end= ligand_areas.end();
184  //TODO Use BOOST_FOREACH
185  for(; ligand_area_itr != ligand_area_end; ++ligand_area_itr){
186  char const & chain= ligand_area_itr->first;
187  LigandAreaOP const ligand_area = ligand_area_itr->second;
188  core::Real const & degrees = ligand_area->minimize_ligand_;
189  if(degrees > 0){
190  MinimizeLigandOP minimize_ligand = new MinimizeLigand(chain, degrees);
191  minimize_ligand->apply(pose);
192  minimize_ligands.push_back(minimize_ligand);
193  }
194  }
195  return minimize_ligands;
196 }
197 
200  TetherLigandOPs ligand_tethers;
201 
202  LigandAreas const ligand_areas =
203  movemap_builder_->get_sc_interface_builder()->get_ligand_areas();
204  LigandAreas::const_iterator ligand_area_itr= ligand_areas.begin();
205  LigandAreas::const_iterator const ligand_area_end= ligand_areas.end();
206 
207  for(; ligand_area_itr != ligand_area_end; ++ligand_area_itr){
208  char const & chain= ligand_area_itr->first;
209  LigandAreaOP const ligand_area = ligand_area_itr->second;
210  core::Real const & tether_size = ligand_area->tether_ligand_;
211  if(tether_size > 0){
212  TetherLigandOP tether_ligand= new TetherLigand(chain, tether_size);
213  tether_ligand->apply(pose);
214  ligand_tethers.push_back(tether_ligand);
215  }
216  }
217  return ligand_tethers;
218 }
219 
220 void
222  // TetherLigandOPs::const_iterator begin= ligand_tethers.begin(); // Unused variable causes warning.
223  // TetherLigandOPs::const_iterator const end= ligand_tethers.end(); // Unused variable causes warning.
224 
225  foreach(TetherLigandOP ligand_tether, ligand_tethers){
226  ligand_tether->release(pose);
227  }
228 }
229 
230 void
232  assert(num_cycles_ > 0);
233 
234  MinimizeLigandOPs minimized_ligands = setup_ligands_to_minimize(pose);
235 
236  TetherLigandOPs ligand_tethers= tether_ligands(pose);
237 
238  assert(movemap_builder_ && score_fxn_ ); // make sure the pointers point
239  core::kinematics::MoveMapOP movemap = movemap_builder_->build(pose);
240 
241  protocols::moves::MonteCarloOP monteCarlo = new protocols::moves::MonteCarlo(pose, *score_fxn_, 2.0);/* temperature, from RosettaLigand paper */
242  score_fxn_->score( pose ); // without this neither of the movers below were working
243  // I believe that this may have been related to adding constraints incorrectly at other places in my code.
244  // Rigid body exploration
246 
247  for( core::Size cycle = 1; cycle <= num_cycles_; ++cycle ) {
248  core::pack::task::PackerTaskOP packer_task = make_packer_task(pose);// has to be in the loop to be updated after each design cycle (w/resfiles)
249 
250  protocols::moves::MoverOP pack_mover;
251 
252  if(cycle % repack_every_Nth_ == 1){
253  high_res_docker_tracer.Debug << "making PackRotamersMover" << std::endl;
255  }
256  else{
257  high_res_docker_tracer.Debug << "making RotamerTrialsMover" << std::endl;
259  }
260 
261  // Wrap it in something to disable the torsion constraints before packing!
262  pack_mover = new protocols::ligand_docking::UnconstrainedTorsionsMover( pack_mover, minimized_ligands );
263 
264  protocols::simple_moves::MinMoverOP min_mover = new protocols::simple_moves::MinMover( movemap, score_fxn_, "dfpmin_armijo_nonmonotone_atol", 1.0, true /*use_nblist*/ );
265  min_mover->min_options()->nblist_auto_update(true); // does this cost us lots of time in practice?
266 
267  core::Real const score1 = (*score_fxn_)( pose );
268  apply_rigid_body_moves(pose, rigid_body_movers);
269  pack_mover->apply(pose);
270 
271  core::Real const score2 = (*score_fxn_)( pose );
272  if(score2 - score1 < 15.0) {
273  min_mover->apply(pose);
274  }
275 
276  monteCarlo->boltzmann( pose );
277 
278  }
279 
280  remove_ligand_tethers(pose, ligand_tethers);
281  // keep the best structure we found, not the current one
282  monteCarlo->show_scores();
283  monteCarlo->recover_low(pose);
284 }
285 
288  core::pose::Pose const & pose,
289  ligand_options::Interface const allow_repack
290 ) const{
291  static bool pose_already_packed= false;
293  pack_task->initialize_from_command_line(); // -ex1 -ex2 etc.
294 
296  unboundrot_->initialize_from_command_line();
297  pack_task->append_rotamerset_operation( unboundrot_ );
298 
299  for(core::Size i = 1; i <= pose.total_residue(); ++i) {
300  /// If several params files have the same name, allow switching among them
301  /// This was previously only enabled with mutate_same_name3. Now default.
302  if( ! pose.residue(i).is_ligand()) continue;
303  high_res_docker_tracer.Debug<< "enabling packing for ligand residue "<< i << std::endl;
304  enable_ligand_rotamer_packing(pose, i, pack_task);
305  }
306 
307  if(resfile_.empty()){
308  bool const use_resfile= basic::options::option[ basic::options::OptionKeys::packing::resfile ].user() ;
309  if (use_resfile){
310  high_res_docker_tracer<< "using OPTIONS resfile"<< std::endl;
311  core::pack::task::parse_resfile(pose, *pack_task);
312  }
313  else{
314  high_res_docker_tracer<< "restricting to repack"<< std::endl;
315  for(core::Size i = 1; i <= pose.total_residue(); ++i) {
316  if( ! pose.residue(i).is_ligand() )
317  {
318  pack_task->nonconst_residue_task( i ).restrict_to_repacking();
319  }
320  }
321  }
322  }
323  else{
324  high_res_docker_tracer<< "using XML resfile"<< std::endl;
325  core::pack::task::parse_resfile(pose, *pack_task);
326  }
327 
328 
329  for(core::Size i = 1; i <= pose.total_residue(); ++i) {
330  if ( allow_repack[i].type == ligand_options::InterfaceInfo::non_interface ){
331  pack_task->nonconst_residue_task( i ).prevent_repacking();
332  }
333  }
334 
335  // We always want the option (after the initial unbiased pack)
336  // of sticking with our current nicely minimized conformation.
337  if( pose_already_packed ){
338  pack_task->or_include_current(true);
339  }else {
340  pose_already_packed=true;
341  }
342 
343  return pack_task;
344 }
345 
348  core::pose::Pose const & pose,
349  bool all_residues
350 ) const{
351  if ( all_residues ){
353  return make_packer_task_from_vector(pose, interface);
354  }else{ // the packer task interface should match the movemap interface
355  InterfaceBuilderOP sc_interface_builder= movemap_builder_->get_sc_interface_builder();
356  ligand_options::Interface side_chain_interface= sc_interface_builder->build(pose);
357  return make_packer_task_from_vector(pose, side_chain_interface);
358  }
359 }
360 
361 void
363  core::pose::Pose const & pose,
364  core::Size const ligand_residue_id,
366 ) const{
367  core::conformation::Residue const & this_residue= pose.residue(ligand_residue_id);
368  core::chemical::ResidueTypeSet const & rsd_type_set = this_residue.residue_type_set();
369  core::chemical::ResidueTypeCOPs allowed_types = rsd_type_set.name3_map( this_residue.name3() ); // a vector1
370 
371  assert(allowed_types.size() > 0);
372  /// TODO consider removing this so resfiles can specify ligand mutations to allow
373  if( allowed_types.size() == 1){
374  pack_task->nonconst_residue_task( ligand_residue_id ).restrict_to_repacking();
375  return;
376  }
377  // else
378  for( core::Size j = 1; j <= allowed_types.size(); ++j ) {
379  if( allowed_types[j]->name() == this_residue.name() ) continue; // already in the task's list
380  ///TODO figure out why this is nonconst. Perhaps it could be const
381  pack_task->nonconst_residue_task( ligand_residue_id ).allow_noncanonical_aa( allowed_types[j]->name() );
382  }
383 }
384 
388 
389  LigandAreas const ligand_areas =
390  movemap_builder_->get_sc_interface_builder()->get_ligand_areas();
391 
392  foreach(LigandAreas::value_type ligand_area_pair, ligand_areas){
393  char const & chain= ligand_area_pair.first;
395  foreach(core::Size jump_id, jump_ids){
396  LigandAreaOP const ligand_area = ligand_area_pair.second;
397  core::Real const & angstroms= ligand_area->high_res_angstroms_;
398  core::Real const & degrees= ligand_area->high_res_degrees_;
399  protocols::moves::MoverOP rigid_body_mover= new protocols::rigid::RigidBodyPerturbMover( jump_id, degrees, angstroms);
400  rigid_body_movers.push_back(rigid_body_mover);
401  }
402 
403  }
404  return rigid_body_movers;
405 }
406 
408  core::pose::Pose & pose,
410 ){
411  // utility::vector1<protocols::moves::MoverOP>::iterator rigid_body_mover= rigid_body_movers.begin(); // Unused variable causes warning.
412  foreach(protocols::moves::MoverOP rigid_body_mover, rigid_body_movers){
413  rigid_body_mover->apply(pose);
414  }
415 }
416 
417 /// Non-member functions
418 
419 // Favor Native is part of the APPLY_TO_POSE section
420 
421 } //namespace ligand_docking
422 } //namespace protocols