Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SetupHotspotConstraintsLoopsMover.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 
11 /// @file protocols/protein_interface_design/movers/SetupHotspotConstraintsLoopsMover.cc
12 /// @brief
13 /// @author Jacob Corn (jecorn@u.washington.edu), Sarel Fleishman (sarelf@uw.edu)
16 #include <core/pose/Pose.hh>
17 #include <protocols/moves/Mover.hh>
20 #include <core/types.hh>
23 #include <basic/Tracer.hh>
24 #include <utility/tag/Tag.hh>
26 #include <boost/foreach.hpp>
27 #define foreach BOOST_FOREACH
28 
30 #include <utility/vector0.hh>
31 #include <utility/vector1.hh>
32 #include <complex>
33 
35 #include <core/types.hh>
36 
37 #include <core/kinematics/Jump.hh>
38 #include <core/pose/Pose.hh>
39 #include <basic/Tracer.hh>
40 #include <core/io/pdb/pose_io.hh>
43 #include <core/pose/util.hh>
47 #include <protocols/loops/util.hh>
48 #include <protocols/loops/Loops.hh>
49 
53 
56 
58 
59 
65 
71 // AUTO-REMOVED #include <core/scoring/constraints/XYZ_Func.hh>
72 
75 
77 #include <basic/options/keys/symmetry.OptionKeys.gen.hh>
78 #include <core/fragment/FragSet.hh>
79 #include <utility/exit.hh>
80 
82 
87 // C++ headers
88 //#include <cstdlib>
89 #include <fstream>
90 #include <iostream>
91 #include <string>
92 
93 #if defined(WIN32) || defined(__CYGWIN__)
94  #include <ctime>
95 #endif
96 
97 //silly using/typedef
98 #include <core/id/AtomID_Map.hh>
99 #include <core/io/pdb/pose_io.hh>
100 #include <core/chemical/AA.hh>
101 
107 
108 // option key includes
109 
110 #include <basic/options/keys/out.OptionKeys.gen.hh>
111 #include <basic/options/keys/loops.OptionKeys.gen.hh>
112 // AUTO-REMOVED #include <basic/options/keys/relax.OptionKeys.gen.hh>
113 #include <basic/options/keys/in.OptionKeys.gen.hh>
114 // AUTO-REMOVED #include <basic/options/keys/cm.OptionKeys.gen.hh>
115 #include <basic/options/keys/edensity.OptionKeys.gen.hh>
116 
118 
121 #include <utility/vector1.hh>
122 #include <basic/options/option.hh>
123 // Utility headers
124 #include <basic/options/option_macros.hh>
125 
126 #include <basic/options/keys/run.OptionKeys.gen.hh>
127 #include <basic/options/keys/hotspot.OptionKeys.gen.hh>
128 #include <basic/options/keys/packing.OptionKeys.gen.hh>
129 // AUTO-REMOVED #include <basic/options/keys/score.OptionKeys.gen.hh>
130 #include <boost/foreach.hpp>
131 
132 
133 namespace protocols {
134 namespace protein_interface_design {
135 namespace movers {
136 
137 using namespace protocols::moves;
138 
139 static basic::Tracer tr( "protocols.protein_interface_design.movers.SetupHotspotConstraintsLoopsMover" );
140 
143 {
145 }
146 
150 }
151 
154 {
155  return "SetupHotspotConstraintsLoops";
156 }
157 
159  protocols::moves::Mover( "SetupHotspotConstraintsLoopsMover" ),
160  chain_to_design_( 2 ),
161  CB_force_constant_( 0.5 ),
162  worst_allowed_stub_bonus_( 0.0 ),
163  apply_self_energies_( true ),
164  bump_cutoff_( 4.0 ),
165  apply_ambiguous_constraints_( true ),
166  colonyE_( false ),
167  resfile_( "NONE" )
168  {}
169 
173 }
174 
178 }
179 
182 ) :
183  // core::Size const chain_to_design,
184  // core::Real const & CB_force_constant( 0.5 ),
185  //core::Real const & worst_allowed_stub_bonus,
186  //bool const apply_self_energies,
187  //core::Real const & bump_cutoff,
188  // bool const apply_ambiguous_constraints( true ),
189  //bool const colonyE
190  protocols::moves::Mover( "SetupHotspotConstraintMover" ),
191  chain_to_design_( 2 ),
192  CB_force_constant_( 0.5 ),
193  worst_allowed_stub_bonus_( 0.0 ),
194  apply_self_energies_( true ),
195  bump_cutoff_( 4.0 ),
196  apply_ambiguous_constraints_( true ),
197  colonyE_( false ),
198  resfile_( "NONE" )
199 
200 // chain_to_design_(chain_to_design),
201 // CB_force_constant_(CB_force_constant),
202 // worst_allowed_stub_bonus_(worst_allowed_stub_bonus),
203 // apply_self_energies_(apply_self_energies),
204 // bump_cutoff_(bump_cutoff),
205 // apply_ambiguous_constraints_(apply_ambiguous_constraints),
206 // colonyE_( colonyE)
207 {
208 // packer_task_ = packer_task->clone();
210 }
211 
213  //utility::pointer::ReferenceCount(),
214  protocols::moves::Mover( init ),
215  chain_to_design_( init.chain_to_design_),
216  CB_force_constant_(init.CB_force_constant_),
217  worst_allowed_stub_bonus_(init.worst_allowed_stub_bonus_),
218  apply_self_energies_(init.apply_self_energies_),
219  bump_cutoff_(init.bump_cutoff_),
220  apply_ambiguous_constraints_(init.apply_ambiguous_constraints_),
221  colonyE_( init.colonyE_ ),
222  resfile_( init.resfile_ )
223 {
225 }
226 
229  core::pose::Pose const& pose,
231 ) {
232  if ( colonyE_ ) {
234  hotspot_stub_set_ = colonyE_set;
235  }
236  core::id::AtomID fixed_atom(1, 1);
237  core::Real worst_allowed_stub_bonus = 0;
238  // bool apply_self_energies = false; // Unused variable causes warning.
239 
240  // Take in a scaffold pose (with PackerTask, for its DesignMap), and a set of stubs.
241  // Each repacked residue will get one "AmbiguousConstraint".
242  // This AmbiguousConstraint will contain a series of BackboneStubConstraints (one for each valid stub)
243  runtime_assert( CB_force_constant_ > -1E-6 ); // these can't be negative
244  runtime_assert( worst_allowed_stub_bonus < 1E-6 ); // these can't be positive
245 
247  if ( resfile_ =="NONE" && basic::options::option[basic::options::OptionKeys::packing::resfile].user() ) {
248  core::pack::task::parse_resfile(pose, *task);
249  } else if ( resfile_ != "NONE" ) {
251  }
252  // *****associate the stub set with the unbound pose
253  // *****associate the stub set with the unbound pose
254  // *****hotspot_stub_set_->pair_with_scaffold( pose, partner );
255 
257  for ( core::Size resnum=55; resnum <= 71; ++resnum ) {
258  // if ( task->pack_residue(resnum) ) {
259  hotspot_stub_set_->pair_with_scaffold( pose, pose.chain( resnum ), true_filter );
260  break;
261  //}
262  }
263 
264  tr.Info << "Making hotspot constraints..." << std::endl;
265  //Size scaffold_seqpos(0);
266  Size ct_cst( 0 );
267  for ( core::Size resnum=55; resnum <= 71; ++resnum ) {
268 
269  // Check that this position is allowed to be used for stub constraints
270  // if ( ! task->pack_residue(resnum) ) continue;
271 
272  // sets the index used by the hotspot for its associated scaffold
273  //scaffold_seqpos = resnum - pose.conformation().chain_begin( pose.chain( resnum ) ); // set but never used
274 
275  // Start the vector which will become a single AmbiguousConstraint, if apply_ambiguous_constraints is true
277  // Loop over all allowed AAs at this position
278  std::list< core::chemical::ResidueTypeCOP > allowed_aas = task->residue_task( resnum ).allowed_residue_types();
279  for (std::list< core::chemical::ResidueTypeCOP >::const_iterator restype = allowed_aas.begin();
280  restype != allowed_aas.end(); ++restype) {
281 
282  // Loop over all stubs with this restype
283  hotspot_hashing::HotspotStubSet::Hotspots res_stub_set( hotspot_stub_set_->retrieve( (*restype )->name3() ) );
284  for (std::multimap<core::Real,hotspot_hashing::HotspotStubOP >::iterator hs_stub = res_stub_set.begin();
285  hs_stub != res_stub_set.end(); ++hs_stub) {
286 
287  // prevent Gly/Pro constraints
288  if ( (hs_stub->second->residue()->aa() == core::chemical::aa_gly) || (hs_stub->second->residue()->aa() == core::chemical::aa_pro && !basic::options::option[basic::options::OptionKeys::hotspot::allow_proline] ) ) {
289  tr.Info << "ERROR - Gly/Pro stubs cannot be used for constraints." << std::endl;
290  continue;
291  }
292 
293  // prevent Gly/Pro constraints
294  if ( (pose.residue(resnum).aa() == core::chemical::aa_gly) || (pose.residue(resnum).aa() == core::chemical::aa_pro && !basic::options::option[basic::options::OptionKeys::hotspot::allow_proline]) ) {
295  tr.Debug << "ERROR - Position " << resnum << " is currently Gly/Pro and cannot be used for stub constraints." << std::endl;
296  continue;
297  }
298 
299  core::Real stub_bonus_value = hs_stub->second->bonus_value();
300  if ( stub_bonus_value < worst_allowed_stub_bonus ) {
301  hs_stub->second->set_scaffold_status( resnum, protocols::hotspot_hashing::accept );
302  //tr.Info << " SuccSelfEnergy=" << stub_bonus_value << std::endl;
303  // ****** accept the pairing -- do we really want this? better to just reject, since bb fit doesn't necessarily mean good pair
304  // ****** hs_stub->scaffold_status( resnum, accept );
305 
306  // Build a BackboneStubConstraint from this stub
308  // Push it onto ambig_csts for this residue
309  ct_cst++;
310  ambig_csts.push_back( new core::scoring::constraints::BackboneStubConstraint( pose, resnum, fixed_atom, *(hs_stub->second->residue()), stub_bonus_value, CB_force_constant_ ) );
311  } else {
312  // Apply it directly
313  constraints.push_back( new core::scoring::constraints::BackboneStubConstraint( pose, resnum, fixed_atom, *(hs_stub->second->residue()), stub_bonus_value, CB_force_constant_ ) );
314  }
315  } else hs_stub->second->set_scaffold_status( resnum, protocols::hotspot_hashing::reject );
316  //else tr.Info << " FailSelfEnergy=" << stub_bonus_value << std::endl;
317  // ****** reject the pairing
318  // ******else hs_stub->scaffold_status( resnum, reject );
319  }
320  }
321 
322  // Finally, add the constraint corresponding to this resnum to the main set
323  if ( ( apply_ambiguous_constraints_ ) && ( ambig_csts.size() > 0 ) )
324  constraints.push_back( new core::scoring::constraints::AmbiguousConstraint(ambig_csts) );
325  }
326  return ct_cst;
327 }
328 
329 
330 void
332  if ( std::abs(CB_force_constant_) > 1E-9 ) {
334  Size ct_cst = generate_csts( pose, constraints );
335  constraints = pose.add_constraints( constraints );
336  tr.Info << "Applied " << ct_cst << " hotspots in " << constraints.size() << " constraints to the pose." << std::endl;
337  } else { //CB_force is <1e-19
339  pose.constraint_set( empty_constraint_set );
340  }
341 }
342 
345 return "SetupHotspotConstraintsLoopsMover";
346 }
347 
348 /// This needs to be parsed before all other movers b/c it changes scorefxns
349 void
351 {
352  using core::Real;
353  chain_to_design_ = tag->getOption<Size>( "redesign_chain", 2 );
354  resfile_ = tag->getOption<std::string>("resfile","NONE");
355 
356  CB_force_constant_ = tag->getOption<Real>( "cb_force", 0.5 );
357 
358  worst_allowed_stub_bonus_ = tag->getOption<Real>( "worst_allowed_stub_bonus", 0 );
359  apply_self_energies_ = tag->getOption<bool>( "apply_stub_self_energies", 0 );
360  bump_cutoff_ = tag->getOption<Real>( "apply_stub_bump_cutoff", 10. );
361  apply_ambiguous_constraints_ = tag->getOption<bool>( "pick_best_energy_constraint", 1 );
362  // core::Real const bb_stub_cst_weight( tag->getOption< core::Real >( "backbone_stub_constraint_weight", 1.0 ) ); // Unused variable causes warning.
363 
364  colonyE_ = tag->getOption<bool>( "colonyE", 0 );
365 
367  if( tag->hasOption( "stubfile" ) ){
368  std::string const hotspot_fname( tag->getOption<std::string>( "stubfile", "stubs.pdb" ) );
369  hotspot_stub_set_->read_data( hotspot_fname );
370  }
371  utility::vector1< TagPtr > const branch_tags( tag->getTags() );
372  foreach( TagPtr const curr_tag, branch_tags ){
373  if( curr_tag->getName() == "HotspotFiles" ){
374  utility::vector1< TagPtr > const branch_tags2( curr_tag->getTags() );
375  foreach( TagPtr const curr_tag2, branch_tags2 ){
376  std::string const file_name( curr_tag2->getOption< std::string >( "file_name" ) );
377  std::string const nickname( curr_tag2->getOption< std::string >( "nickname" ) );
378  core::Size const stub_num( curr_tag2->getOption< core::Size >( "stub_num", 100000 ) );
380  temp_stubset->read_data( file_name );
381  temp_stubset->remove_random_stubs_from_set( temp_stubset->size() - stub_num );
382  hotspot_stub_set_->add_stub_set( *temp_stubset );
383  tr.Info<<"Read stubset from file "<<file_name<<" and associating it with name "<<nickname<<'\n';
384  tr.Info<<stub_num<<" stubs kept in memory\n";
385  data.add( "hotspot_library", nickname, temp_stubset );
386  }
387  }
388  else
389  utility_exit_with_message( curr_tag->getName() + " not recognized by SetupHotspotConstraints, did you mean HotspotFiles?" );
390  }
391 
392  tr.Info<<"applying hotspot hashing constraints to pose with " << " cb_force weight of "<<CB_force_constant_<<", apply ambiguous constraints set to "<<apply_ambiguous_constraints_<< " and colonyE set to " << colonyE_ << "\n";
393  data.add( "constraints" , "hotspot_stubset", hotspot_stub_set_ );
394 
395  tr.Info.flush();
396 }
397 
399 
400 } //movers
401 } //protein_interface_design
402 } //protocols