Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InterfaceSasaFilter.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 protocols/simple_filters/InterfaceSasaFilter.cc
11 /// @brief
12 /// @author Sarel Fleishman (sarelf@u.washington.edu), Jacob Corn (jecorn@u.washington.edu)
13 
14 #include <algorithm>
15 #include <boost/lexical_cast.hpp>
16 #include <boost/foreach.hpp>
17 #define foreach BOOST_FOREACH
18 
21 #include <core/pose/Pose.hh>
22 #include <core/id/AtomID_Map.hh>
26 #include <basic/MetricValue.hh>
27 #include <utility/tag/Tag.hh>
29 // Jacob
30 #include <utility/string_util.hh>
34 
35 // Project Headers
36 #include <utility/excn/Exceptions.hh>
37 #include <core/types.hh>
38 
39 
40 namespace protocols {
41 namespace simple_filters {
42 
43 static basic::Tracer TR( "protocols.simple_filters.InterfaceSasaFilter" );
44 
47 
49 InterfaceSasaFilterCreator::keyname() const { return "Sasa"; }
50 
51 
53  Filter( "Sasa" ),
54  lower_threshold_( 0.0 ),
55  upper_threshold_(100000000000.0),
56  hydrophobic_( false ),
57  polar_( false ),
58  jumps_(),
59  sym_dof_names_()
60 {
61  jump(1);
62 }
63 
64 InterfaceSasaFilter::InterfaceSasaFilter( core::Real const lower_threshold, bool const hydrophobic/*=false*/, bool const polar/*=false*/, core::Real upper_threshold, std::string sym_dof_names ) :
65  Filter( "Sasa" ),
66  lower_threshold_( lower_threshold ),
67  upper_threshold_(upper_threshold),
68  hydrophobic_( hydrophobic ),
69  polar_( polar ),
70  jumps_(),
71  sym_dof_names_()
72 {
73  if (sym_dof_names != "")
74  {
75  this->sym_dof_names(sym_dof_names);
76  }
77  else
78  {
79  jump(1);
80  }
81 }
82 
84 
87  return new InterfaceSasaFilter( *this );
88 }
89 
92  return new InterfaceSasaFilter;
93 }
94 
95 void
97 {
98  lower_threshold_ = tag->getOption<core::Real>( "threshold", 800 );
99  upper_threshold_ = tag->getOption<core::Real>( "upper_threshold", 1000000);
100 
101  std::string specified_jumps = tag->getOption< std::string >( "jump", "" );
102  std::string specified_sym_dof_names = tag->getOption< std::string >( "sym_dof_names", "" );
103 
104  if(specified_jumps != "" && specified_sym_dof_names != "")
105  {
106  TR.Error << "Can not specify 'jump' and 'sym_dof_names' in InterfaceSasaFilter" << tag << std::endl;
107  throw utility::excn::EXCN_RosettaScriptsOption( "Can not specify 'jump' and 'sym_dof_names' in InterfaceSasaFilter" );
108  }
109  else if(specified_jumps != "")
110  {
111  // Populate jumps_ with str->int converstions of the jump list.
112  TR.Debug << "Reading jump list: " << specified_jumps << std::endl;
113 
114  jumps_.resize(0);
115 
116  utility::vector1<std::string> jump_strings = utility::string_split( specified_jumps, ',' );
117  for(core::Size i = 1; i <= jump_strings.size(); ++i)
118  {
119  jumps_.push_back( boost::lexical_cast<core::Size>(jump_strings[i]));
120  }
121 
122  sym_dof_names_.resize(0);
123  }
124  else if(specified_sym_dof_names != "")
125  {
126  TR.Debug << "Reading sym_dof_name list: " << specified_sym_dof_names << std::endl;
127 
128  jumps_.resize(0);
129  sym_dof_names_ = utility::string_split( specified_sym_dof_names, ',');
130  }
131  else
132  {
133  TR.Debug << "Defaulting to jump 1. " << std::endl;
134 
135  jump(1);
136  }
137 
138  hydrophobic_ = tag->getOption<bool>( "hydrophobic", false );
139  polar_ = tag->getOption<bool>( "polar", false );
140 
141  if( polar_ && hydrophobic_ )
142  {
143  TR.Error << "Polar and hydrophobic flags specified in Sasa filter: " << tag << std::endl;
144  throw utility::excn::EXCN_RosettaScriptsOption( "Polar and hydrophobic flags specified in Sasa filter." );
145  }
146 
147  if( ( polar_ || hydrophobic_ ) && (jumps_.size() != 1 || jumps_[0] != 1))
148  {
149  TR.Error << "Only total sasa is supported across a jump other than 1. Remove polar and hydrophobic flags and try again: " << tag << std::endl;
150  throw utility::excn::EXCN_RosettaScriptsOption( "Only total sasa is supported across a jump other than 1. Remove polar and hydrophobic flags and try again." );
151  }
152 
153  TR.Debug << "Parsed Sasa Filter: <Sasa" <<
154  " threshold=" << lower_threshold_ <<
155  " upper_threshold=" << upper_threshold_ <<
156  " jump=";
157  std::copy(jumps_.begin(), jumps_.end(), std::ostream_iterator<core::Size>(TR.Debug, ","));
158  TR.Debug <<
159  " sym_dof_names=";
160  std::copy(sym_dof_names_.begin(), sym_dof_names_.end(), std::ostream_iterator<std::string>(TR.Debug, ","));
161  TR.Debug <<
162  " hydrophobic=" << hydrophobic_ <<
163  " polar=" << polar_ <<
164  " />" << std::endl;
165 }
167  utility::lua::LuaObject const & def,
168  utility::lua::LuaObject const & /*score_fxns*/,
169  utility::lua::LuaObject const & /*tasks*/
170 )
171 {
172  lower_threshold_ = def["threshold"] ? def["threshold"].to<core::Real>() : 800;
173  upper_threshold_ = def["upper_threshold"] ? def["upper_threshold"].to<core::Real>() : 1000000;
174  jump( def["jump"] ? def["jump"].to<core::Size>() : 1 ); // APL NOTE: this class now supports a vector of jump indices
175  hydrophobic_ = def["hydrophobic"] ? def["hydrophobic"].to<bool>() : false;
176  polar_ = def["polar"] ? def["polar"].to<bool>() : false;
177  runtime_assert( !hydrophobic_ || !polar_ );
178  if( jumps_.size() == 1 && jumps_[1] != 1 && ( polar_ || hydrophobic_ ) ) {
179  // APL this is an unfortunate restriction
180  utility_exit_with_message( "ERROR: presently, only total sasa is supported across a jump other than 1. Remove polar and hydrophobic flags and try again." );
181  }
182 
183  TR << "SasaFilter with lower threshold of "<<lower_threshold_<<" Ang^2 and jump "<<jumps_[1]<<'\n';
184  if( hydrophobic_ ) {
185  TR << "Only reporting hydrophobic sasa\n";
186  }
187  if( polar_ ) {
188  TR << "Only reporting polar sasa\n";
189  }
190  TR.flush();
191 }
192 
193 bool
195  core::Real const sasa( compute( pose ) );
196 
197  TR<<"sasa is "<<sasa<<". ";
198  if( sasa >= lower_threshold_ && sasa <= upper_threshold_ ){
199  TR<<"passing." <<std::endl;
200  return true;
201  }
202  else {
203  TR<<"failing."<<std::endl;
204  return false;
205  }
206 }
207 
208 void
209 InterfaceSasaFilter::report( std::ostream & out, core::pose::Pose const & pose ) const {
210  core::Real const sasa( compute( pose ));
211  out<<"Sasa= "<< sasa<<'\n';
212 }
213 
216  core::Real const sasa( compute( pose ));
217  return( sasa );
218 }
219 
220 void
222 {
223  jumps_.resize(0);
224  jumps_.push_back(jump);
225  sym_dof_names_.resize(0);
226 }
227 
228 void
230 {
231  jumps_.push_back(jump);
232 }
233 
235 {
236  jumps_ = jumps;
237 }
238 
239 void
241 {
242  sym_dof_names_ = utility::string_split(sym_dof_names, ',');
243  jumps_.resize(0);
244 }
245 
246 void
248 {
249  sym_dof_names_.push_back(sym_dof_name);
250 }
251 
252 void
254 {
256 }
257 
260  using namespace core::pose::metrics;
261  using basic::MetricValue;
262  using namespace core;
263  using namespace protocols::moves;
264 
265  core::pose::Pose split_pose( pose );
266  std::set<core::Size> sym_aware_jump_ids;
267 
268  for (Size i = 1; i <= sym_dof_names_.size(); i++)
269  {
270  TR.Debug << "getting sym_aware_jump_id from " << sym_dof_names_[i] << std::endl;
271  sym_aware_jump_ids.insert(core::pose::symmetry::sym_dof_jump_num( split_pose, sym_dof_names_[i] ));
272  }
273 
274  bool symm = core::pose::symmetry::is_symmetric( pose );
275  if (!symm)
276  {
277  for (Size i = 1; i <= jumps_.size(); i++)
278  {
279  TR.Debug << "getting sym_aware_jump_id from " << jumps_[i] << std::endl;
280  sym_aware_jump_ids.insert(jumps_[i]);
281  }
282  }
283  else
284  {
285  // all slidable jumps
286  Size nslidedofs = core::pose::symmetry::symmetry_info(pose)->num_slidablejumps();
287  for (Size j = 1; j <= nslidedofs; j++)
288  sym_aware_jump_ids.insert( core::pose::symmetry::get_sym_aware_jump_num(pose, j ) );
289  }
290 
291  runtime_assert( !sym_aware_jump_ids.empty() );
292 
293  foreach (Size sym_aware_jump_id, sym_aware_jump_ids)
294  {
295  TR.Debug << "Moving jump id: " << sym_aware_jump_id << std::endl;
296 
298  translate->step_size( 1000.0 );
299  translate->apply( split_pose );
300  }
301  //split_pose.dump_pdb("Interface_SASA_split.pdb");
302  runtime_assert( !hydrophobic_ || !polar_ );
303  if( !hydrophobic_ && !polar_ )
304  {
305  MetricValue< core::Real > mv_sasa;
306 
307  pose.metric( "sasa", "total_sasa", mv_sasa);
308  core::Real const bound_sasa( mv_sasa.value() );
309  TR.Debug << "Bound sasa: " << bound_sasa << std::endl;
310 
311  split_pose.metric( "sasa", "total_sasa", mv_sasa );
312  core::Real const unbound_sasa( mv_sasa.value() );
313  TR.Debug << "Unbound sasa: " << unbound_sasa << std::endl;
314 
316  {
317  //fpd this logic is not correct for lattice symmetries
319  core::Real const buried_sasa( (unbound_sasa - bound_sasa) /(sym_info->subunits()));
320 
321  TR.Debug << "Normalizing calculated sasa by subunits: " << sym_info->subunits() << std::endl;
322  TR.Debug << "Buried sasa: " << buried_sasa << std::endl;
323 
324  return( buried_sasa );
325  } else {
326  core::Real const buried_sasa(unbound_sasa - bound_sasa);
327 
328  TR.Debug << "Buried sasa: " << buried_sasa << std::endl;
329  return( buried_sasa );
330  }
331  }
332  else{
333  MetricValue< id::AtomID_Map< core::Real > > atom_sasa;
334  pose.metric( "sasa_interface", "delta_atom_sasa", atom_sasa );
335  core::Real polar_sasa( 0.0 ), hydrophobic_sasa( 0.0 );
336  for( core::Size pos(1); pos<=pose.total_residue(); ++pos ){
337  for( core::Size atomi( 1 ); atomi <= atom_sasa.value().n_atom( pos ); ++atomi ){
338  core::Real const atomi_delta_sasa( atom_sasa.value()( pos, atomi ) );
339  core::conformation::Residue const pos_rsd( pose.residue( pos ) );
340  core::chemical::AtomType const atom_type( pos_rsd.atom_type( atomi ) );
341  bool const is_polar( atom_type.is_donor() || atom_type.is_acceptor() || atom_type.is_polar_hydrogen() );
342  if( is_polar ) polar_sasa += atomi_delta_sasa;
343  else hydrophobic_sasa += atomi_delta_sasa;
344  }
345  }
346  if( hydrophobic_ ) return hydrophobic_sasa;
347  if( polar_ ) return polar_sasa;
348  }
349  utility_exit_with_message( "Execution should never have reached this point." );
350  return( 0 );
351 }
352 
353 }
354 }