Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HotspotHasherMover.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/HotspotHasherMover.cc
12 /// @brief
13 /// @author Sarel Fleishman (sarelf@u.washington.edu), Jacob Corn (jecorn@u.washington.edu)
14 
15 // Unit headers
18 
19 // Package headers
20 
21 // Project headers
23 #include <basic/options/keys/out.OptionKeys.gen.hh>
24 #include <utility/file/file_sys_util.hh>
25 #include <basic/options/option.hh>
26 #include <basic/Tracer.hh>
27 #include <utility/tag/Tag.hh>
33 #include <core/pose/selection.hh>
34 
35 #include <utility/vector0.hh>
36 #include <utility/vector1.hh>
37 
38 
39 namespace protocols {
40 namespace protein_interface_design {
41 namespace movers {
42 
43 using namespace core;
44 using namespace std;
45 using namespace core::scoring;
46 using namespace protocols::moves;
47 
48 static basic::Tracer TR( "protocols.protein_interface_design.movers.HotspotHasherMover" );
49 
52 {
54 }
55 
58  return new HotspotHasherMover;
59 }
60 
63 {
64  return "HotspotHasher";
65 }
66 
69  std::vector<std::string> const resnames,
71  core::Size const n_stubs,
72  core::Size const target_resnum,
73  protocols::filters::FilterOP hotspot_filter,
74  core::Real const target_distance,
75  std::string const hashin_fname,
76  std::string const hashout_fname
77 ) :
78  protocols::moves::Mover( HotspotHasherMoverCreator::mover_name() ),
79  scorefxn_(scorefxn),
80  resnames_(resnames),
81  n_stubs_(n_stubs),
82  target_resnum_(target_resnum),
83  target_distance_(target_distance),
84  hashin_fname_(hashin_fname),
85  hashout_fname_(hashout_fname)
86 {
87  hotspot_filter_ = hotspot_filter;
88 }
89 
91 
94  return( protocols::moves::MoverOP( new HotspotHasherMover( *this ) ) );
95 }
96 
98 
99  // finding a request for ALL adds the main 18 aa's to
100  if( std::find( resnames_.begin(), resnames_.end(), "ALL" ) != resnames_.end() ) {
101  resnames_.push_back( "ALA" );
102  resnames_.push_back( "ARG" );
103  resnames_.push_back( "ASN" );
104  resnames_.push_back( "ASP" );
105  resnames_.push_back( "GLU" );
106  resnames_.push_back( "GLN" );
107  resnames_.push_back( "HIS" );
108  resnames_.push_back( "ILE" );
109  resnames_.push_back( "LEU" );
110  resnames_.push_back( "LYS" );
111  resnames_.push_back( "MET" );
112  resnames_.push_back( "PHE" );
113  resnames_.push_back( "PRO" );
114  resnames_.push_back( "SER" );
115  resnames_.push_back( "THR" );
116  resnames_.push_back( "TRP" );
117  resnames_.push_back( "TYR" );
118  resnames_.push_back( "VAL" );
119  }
120 
122 
123  // read existing hashes
125  stubset.read_data( hashin_fname_ );
126  TR << "Found hash file " << hashin_fname_ << std::endl;
127  }
128  if ( utility::file::file_exists( hashout_fname_ ) ) { // useful for interrupted runs
129  stubset.read_data( hashout_fname_ );
130  TR << "Found hash file " << hashout_fname_ << std::endl;
131  }
132 
133 
134  // for each residue requested
135  for( std::vector< std::string >::const_iterator it=resnames_.begin() ; it!=resnames_.end(); ++it ) {
136  std::string resname = *it;
137 
138  TR << "Hash contains " << stubset.size(resname) << " " << resname << " stubs." << std::endl;
139 
140  // check to see if we've already finished our hash
141  core::Size stubs_left = n_stubs_;
142  stubs_left -= stubset.size( resname );
143  if( stubs_left <= 0 )
144  {
145  // perform a scorecut
146  if ( basic::options::option[ basic::options::OptionKeys::out::scorecut ].user() )
147  {
148  Real score_cutoff = basic::options::option[ basic::options::OptionKeys::out::scorecut ]();
149  std::stringstream i;
150  i.str("");
151  i << score_cutoff;
152  stubset.clear();
153  stubset.read_data( hashout_fname_ );
154  protocols::hotspot_hashing::HotspotStubSetOP cut_stubs = stubset.subset( score_cutoff );
155  std::string newfname = i.str() + "cut_" + hashout_fname_;
156  cut_stubs->write_all( newfname );
157  }
158  return;
159  }
160 
161  // do hashing in 10-stub cycles to minimize file i/o
162  Size n_per(10);
163 
164  Size n_cycles = n_stubs_ / n_per;
165  // make sure we do at least one cycle
166  if( n_cycles <= 0 ) n_cycles = 1;
167  // PERFORM HASHING
168  for( Size i = 1; i <= n_cycles; ++i )
169  {
170  stubset.clear();
172  TR << "Finding " << n_per*i << "/" << n_stubs_ << " " << resname << " stubs" ;
173  if( target_resnum_ ) {
174  TR << " " << target_distance_ << "A from " << target_resnum_ << std::endl;
175  stubset.fill( pose, scorefxn_, target_resnum_, target_distance_, resname, n_per );
176  }
177  else {
178  TR << "." << std::endl;
179  stubset.fill( pose, scorefxn_, resname, n_per );
180  }
181  stubset.write_all( hashout_fname_ );
182  }
183  } // for each residue
184 
185  // perform a scorecut
186  if ( basic::options::option[ basic::options::OptionKeys::out::scorecut ].user() )
187  {
188  Real score_cutoff = basic::options::option[ basic::options::OptionKeys::out::scorecut ]();
189  std::stringstream i;
190  i.str("");
191  i << score_cutoff;
192  stubset.clear();
193  stubset.read_data( hashout_fname_ );
194  protocols::hotspot_hashing::HotspotStubSetOP cut_stubs = stubset.subset( score_cutoff );
195  std::string newfname = i.str() + "cut_" + hashout_fname_;
196  cut_stubs->write_all( newfname );
197  }
198 } // HotspotHasherMover::apply
199 
203 }
204 
205 
206 void
208 {
209 
210  std::string const scorefxn( tag->getOption<string>( "scorefxn", "score12" ));
211  scorefxn_ = new ScoreFunction( *(data.get< ScoreFunction * >( "scorefxns", scorefxn)) );
212 
213  n_stubs_ = tag->getOption<core::Size>( "nstubs", 1000 );
214 
215  // target residue
216  // target_resnum gets set below with residues
217  target_resnum_ = 0;
218  if( tag->hasOption( "target_residue_pdb_num" ) || tag->hasOption( "target_residue_res_num" ) ) {
219  target_resnum_ = core::pose::get_resnum( tag, pose, "target_residue_" );
220  }
221 
222  target_distance_ = tag->getOption<core::Real>( "target_distance", 15.0 );
223 
224  score_threshold_ = tag->getOption<core::Real>( "threshold", -1.0 );
225 
226  // hash in/out
227  hashin_fname_ = tag->getOption<std::string>( "in", "");
228  hashout_fname_ = tag->getOption<std::string>( "out", "hash.stubs");
229 
230  // filter
231  std::string const hotspot_filter_name( tag->getOption<std::string>( "hotspot_filter", "true_filter" ) );
232  protocols::filters::Filters_map::const_iterator find_filter( filters.find( hotspot_filter_name ));
233  bool const filter_found( find_filter != filters.end() );
234  if( filter_found )
235  hotspot_filter_ = find_filter->second->clone();
236  else {
237  if( hotspot_filter_name != "true_filter" ){
238  TR<<"***WARNING WARNING! Filter defined for HotspotHasher not found in filter_list!!!! Defaulting to truefilter***"<<std::endl;
239  runtime_assert( filter_found );
240  }
241  else
243  }
244 
245  // residues
246  utility::vector0< TagPtr > const hasher_tags( tag->getTags() );
247  for( utility::vector0< TagPtr >::const_iterator hash_it=hasher_tags.begin(); hash_it!=hasher_tags.end(); ++hash_it ) {
248  TagPtr const hash_tag_ptr = *hash_it;
249  std::string tag_name = hash_tag_ptr->getName();
250  if( tag_name == "residue" ) {
251  std::string resname( hash_tag_ptr->getOption< std::string >( "type", "" ) );
252  resnames_.push_back( resname );
253  }
254  }
255  runtime_assert( resnames_.size() > 0 );
256 
257  TR<<"hashing mover finding residues: ";
258  for( std::vector< std::string >::const_iterator it=resnames_.begin() ; it!=resnames_.end(); ++it ) TR<<*it<<" ";
259  if( target_resnum_ ) TR << target_distance_ << "A away from residue " << target_resnum_ << std::endl;
260  TR<<std::endl;
261 } // HotspotHasherMover::parse_my_tag
262 
263 } //movers
264 } //protein_interface_design
265 } //protocols