Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PlacementAuctionMover.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 sw=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/protein_interface_design/movers/PlacementAuctionMover.cc
11 /// @brief
12 /// @author Sarel Fleishman (sarelf@u.washington.edu)
13 
14 // Unit headers
17 
18 #include <core/types.hh>
19 #include <core/pose/Pose.hh>
21 #include <utility/tag/Tag.hh>
23 
27 
28 //#include <protocols/docking/DockingProtocol.hh>
29 #include <protocols/moves/Mover.hh>
32 // Unit Headers
35 
37 #include <core/id/AtomID.hh>
38 #include <core/chemical/AA.hh>
39 #include <numeric/xyzVector.hh>
40 
41 
42 // Unit Headers
43 #include <basic/Tracer.hh>
46 
47 // C++ headers
48 #include <map>
49 #include <boost/foreach.hpp>
50 
51 #include <utility/vector0.hh>
52 #include <utility/vector1.hh>
53 
54 //Auto Headers
57 
58 
59 
60 #define foreach BOOST_FOREACH
61 
62 using namespace protocols::protein_interface_design;
63 
64 static basic::Tracer TR( "protocols.protein_interface_design.movers.PlacementAuctionMover" );
65 
66 namespace protocols {
67 namespace protein_interface_design {
68 namespace movers {
69 
70 using namespace protocols::moves;
71 using namespace core;
72 
74 PlacementAuctionMoverCreator::keyname() const
75 {
76  return PlacementAuctionMoverCreator::mover_name();
77 }
78 
80 PlacementAuctionMoverCreator::create_mover() const {
81  return new PlacementAuctionMover;
82 }
83 
85 PlacementAuctionMoverCreator::mover_name()
86 {
87  return "Auction";
88 }
89 
90 PlacementAuctionMover::PlacementAuctionMover() :
91  simple_moves::DesignRepackMover( PlacementAuctionMoverCreator::mover_name() )
92 {}
93 
95 
98  return( protocols::moves::MoverOP( new PlacementAuctionMover( *this ) ) );
99 }
100 
103  return auction_results_;
104 }
105 
106 void
108 {
109  auction_results_.insert( item );
110 }
111 
114 {
115  return auction_results_.size();
116 }
117 
118 void
120  auction_results_.erase( it );
121 }
122 
123 void
125  auction_results_.clear();
126 }
127 
130  return auction_results_.begin();
131 }
132 
135  return auction_results_.end();
136 }
137 
140  return auction_results_.begin();
141 }
142 
145  return auction_results_.end();
146 }
147 
148 void
150 {
151  core::pose::Pose const saved_pose( pose ); // the pose should not actually be changed within this function
152 
153  using namespace protocols::hotspot_hashing;
154  using namespace core::scoring;
155 
156  core::Size const host_chain_begin( pose.conformation().chain_begin( host_chain_ ) );
157  core::Size const host_chain_end ( pose.conformation().chain_end( host_chain_ ) );
158  using namespace core::scoring;
159  ScoreFunctionOP only_stub_scorefxn = new ScoreFunction;
160  only_stub_scorefxn->reset();
161  only_stub_scorefxn->set_weight( backbone_stub_constraint, 1.0 );
162  simple_filters::ScoreTypeFilter const stf( only_stub_scorefxn, backbone_stub_constraint, 1.0 );
163 
165  core::Size fixed_res(1);
166  if( host_chain_ == 1 ) fixed_res = pose.total_residue();
167  core::id::AtomID const fixed_atom_id = core::id::AtomID( pose.residue(fixed_res).atom_index("CA"), fixed_res );
168 /// ResidueAuction is keyed by energy => we select the residue,stub,stubset combination with the best energy for each stubset,stub combination
169  typedef std::pair< HotspotStubSetOP, HotspotStubOP > StubsetStubPair;
170  typedef std::pair< core::Real, std::pair< core::Size, StubsetStubPair > > ResidueAuctionItem;
171  typedef std::multimap< core::Real, std::pair< core::Size, StubsetStubPair > > ResidueAuction;
172 /// Preventing positions that have already been prevented throught task factory or through the prevent_repacking method
173  using namespace core::pack::task;
175  if( task_factory() )
176  task = task_factory()->create_task_and_apply_taskoperations( pose );
177  else
179  utility::vector1< core::Size > host_positions;
180  for( core::Size host_position( host_chain_begin+1 ); host_position<=host_chain_end-1; ++host_position ){
181  using namespace core::chemical;
182  // exclude gly/pro and don't allow prevented residues
183  if( std::find( prevent_repacking_.begin(), prevent_repacking_.end(), host_position ) == prevent_repacking_.end() && pose.residue( host_position ).aa() != aa_gly && pose.residue( host_position ).aa() != aa_pro ){
184  if( task->nonconst_residue_task( host_position ).being_packed() )
185  host_positions.push_back( host_position );
186  }
187  }// for host_position
188 
189  foreach( StubSetStubPos const hs_set, stub_sets_ ){
190  HotspotStubSetOP stub_set( hs_set.first );
191  foreach( HotspotStubSet::Hs_data const stub_pair, *stub_set ){
192  HotspotStubOP stub( stub_pair.second.second );
193  foreach( core::Size const host_residue, host_positions )
194  {
195  core::Real const distance( pose.residue( host_residue ).xyz( "CB" ).distance( stub->residue()->xyz( "CB" ) ) );
196  if( distance >= max_cb_cb_dist_ ) continue;
197  core::Real const bonus( stub->bonus_value() );
198  // I'm circumventing add_hotspot_constraints to pose and adding the constraint directly
199  // since there's no ambiguity here and no need to switch to ala pose etc. And I don't
200  // want all the quality control machinery to be applied to this stub; I know it's good.
201  using namespace core::scoring::constraints;
202  ConstraintCOPs stub_constraints;
203  core::conformation::Residue const host_res( pose.conformation().residue( host_residue ) );
204  stub_constraints.push_back( new BackboneStubConstraint( pose, host_residue, fixed_atom_id, host_res, bonus, cb_force_ ) );
205  stub_constraints = pose.add_constraints( stub_constraints );
206  core::Real const bb_cst_score( stf.compute( pose ) );
207  if( bb_cst_score <= -0.5 ) // take only residues that make some appreciable contribution
208  insert( std::make_pair( bb_cst_score, std::make_pair( host_residue, std::make_pair( stub_set, stub ) ) ) );
209  pose = saved_pose;
210  }// foreach host_residue
211  }//foreach stub_pair
212  }//foreach hs_set
213  if( size() == 0 ){
214  TR<<"No pairing found. Failing."<<std::endl;
216  return;
217  }
218  ResidueAuction const saved_auction( auction_results() ); /// auction_results_ will be depleted in the following. Then, if successful, I'll reinstate it.
219  while( size() > 0 ){
220  // The auction ensures that each position is paired to the stubset that bids the lowest-energy stub on that
221  /// position, but allows each stubset to bid multiple positions. This allows stubsets that lose on one position
222  // to potentially succeed on another.
223  PlacementAuctionMover::const_iterator lowest_energy( begin() );
224  core::Size const position( lowest_energy->second.first );
225  HotspotStubSetCOP stubset( lowest_energy->second.second.first );
226  HotspotStubOP stub( lowest_energy->second.second.second );
227 
228  foreach( StubSetStubPos & hs_set, stub_sets() ){
229  // This is where the pairing takes place
230  if( hs_set.first == stubset ){
231  hs_set.second.first = stub;
232  hs_set.second.second = position;
233  break;
234  }
235  }
236 
237  for( ResidueAuction::iterator energy_set_pair = begin(); energy_set_pair != end(); /*incrementing done within the loop*/ ){
238  ResidueAuction::iterator next_it = energy_set_pair;
239  core::Size const erased_pos( energy_set_pair->second.first );
240  HotspotStubSetCOP erased_stubset( energy_set_pair->second.second.first );
241 
242  if( position == erased_pos || stubset == erased_stubset ){
243  ++next_it;
244  erase( energy_set_pair );
245  energy_set_pair = next_it;
246  }
247  else ++energy_set_pair;
248  }//for energy_set_pair
249  }//while size()
250 
251  foreach( StubSetStubPos const stubset_pos_pair, stub_sets() ){
252  core::Size const pos( stubset_pos_pair.second.second );
253  if( pos == 0 ){
254  TR<<"Pairing failed"<<std::endl;
256  return;
257  }
258  }//foreach stubset_pos_pair
259  // If all went well then retrieve the saved copy of the auction
260  auction_results_ = saved_auction;
261  TR<<"Pairing successful."<<std::endl;
263  pose=saved_pose;
264  TR.flush();
265 }
266 
270 }
271 
272 void
274  host_chain_ = hc;
275 }
276 
277 void
279  max_cb_cb_dist_ = c;
280 }
281 
282 void
285 }
286 
287 void
289  cb_force_ = cb;
290 }
291 
294  return stub_sets_;
295 }
296 
299  return stub_sets_;
300 }
301 
302 void
304  DataMap &data,
306  Movers_map const &,
307  core::pose::Pose const & pose )
308 {
309  using namespace protocols::hotspot_hashing;
310  using namespace protocols::filters;
311  using namespace core::scoring;
312 
313  host_chain_ = tag->getOption<core::Size>( "chain_to_design", 2 );
314  utility::vector0< TagPtr > const branch_tags( tag->getTags() );
315  max_cb_cb_dist_ = tag->getOption< core::Real >( "max_cb_dist", 3.0 );
316  cb_force_ = tag->getOption< core::Real >( "cb_force", 0.5 );
317  stub_sets_ = parse_stub_sets( tag, pose, host_chain_, data );
318  runtime_assert( stub_sets_.size() );
319  TR<<"max cb cb distance set to "<<max_cb_cb_dist_<<" and cb_force to "<<cb_force_<<'\n';
320  TR<<"PlacementAuction mover on chain "<<host_chain_<<" with repack_non_ala set to "<<std::endl;
321 }
322 
323 } //movers
324 } //protein_interface_design
325 } //protocols
326