Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ResFilters.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 core/pack/task/operation/ResFilters.hh
11 /// @brief core-level (very general) classes that take a pose and a residue index, and return true or false
12 /// @author ashworth
13 
14 // Unit Headers
18 
19 // Project Headers
22 #include <core/pose/Pose.hh>
23 #include <core/pose/PDBInfo.hh>
24 #include <basic/Tracer.hh>
25 
26 #include <utility/string_util.hh>
27 #include <utility/tag/Tag.hh>
28 
29 #include <utility/vector0.hh>
30 #include <utility/vector1.hh>
31 #include <set>
32 
33 
34 namespace core {
35 namespace pack {
36 namespace task {
37 namespace operation {
38 
39 static basic::Tracer TR("core.pack.task.operation.ResFilters");
40 
42  parent(),
43  sub_filters_()
44 {}
45 
47  parent(),
48  sub_filters_(sub_filters)
49 {}
50 
52 {
54 
55  if (sub_filters_.size() == 0)
56  {
57  TR.Debug << "ResFilterComposition without sub-filters defined: " << *tag << std::endl;
58  }
59 }
60 
62 {
63  utility::vector0< TagPtr > const subtags( tag->getTags() );
64 
65  for (utility::vector0< TagPtr >::const_iterator subtag( subtags.begin() ), end( subtags.end() );
66  subtag != end;
67  ++subtag )
68  {
69  std::string const type( (*subtag)->getName() );
70 
71  ResFilterFactory * res_filter_factory = ResFilterFactory::get_instance();
72  if ( res_filter_factory && res_filter_factory->has_type( type ) ) {
73  ResFilterOP filter = res_filter_factory->newResFilter( type );
74  filter->parse_tag( *subtag );
75  sub_filters_.push_back(filter);
76 
77  continue;
78  }
79  }
80 }
81 
83  parent()
84 {}
85 
87  parent(sub_filters)
88 {}
89 
90 ResFilterOP AnyResFilter::clone() const { return new AnyResFilter( *this ); }
91 
92 bool AnyResFilter::operator() ( Pose const & pose, Size index ) const
93 {
94  for (core::Size i = 1; i <= sub_filters_.size(); ++i)
95  {
96  if((*(sub_filters_[i]))(pose, index))
97  {
98  return true;
99  }
100  }
101 
102  return false;
103 }
104 
106 {
107  return new AnyResFilter();
108 }
109 
111  parent()
112 {}
113 
115  parent(sub_filters)
116 {}
117 
118 ResFilterOP AllResFilter::clone() const { return new AllResFilter( *this ); }
119 
120 bool AllResFilter::operator() ( Pose const & pose, Size index ) const
121 {
122  for (core::Size i = 1; i <= sub_filters_.size(); ++i)
123  {
124  if(!(*(sub_filters_[i]))(pose, index))
125  {
126  return false;
127  }
128  }
129 
130  return true;
131 }
132 
134 {
135  return new AllResFilter();
136 }
137 
139  parent()
140 {}
141 
143  parent(sub_filters)
144 {}
145 
146 ResFilterOP NoResFilter::clone() const { return new NoResFilter( *this ); }
147 
148 bool NoResFilter::operator() ( Pose const & pose, Size index ) const
149 {
150  for (core::Size i = 1; i <= sub_filters_.size(); ++i)
151  {
152  if((*(sub_filters_[i]))(pose, index))
153  {
154  return false;
155  }
156  }
157 
158  return true;
159 }
160 
162  {
163  return new NoResFilter();
164 }
165 
167  parent(),
168  polar_(false), apolar_(false), aromatic_(false), charged_(false)
169 {}
170 
171 ResidueTypeFilter::ResidueTypeFilter(bool polar, bool apolar, bool aromatic, bool charged) :
172  parent(),
173  polar_(polar), apolar_(apolar), aromatic_(aromatic), charged_(charged)
174 {}
175 
177 
178 bool ResidueTypeFilter::operator() ( Pose const & pose, Size index ) const
179 {
180  runtime_assert( index > 0 && index <= pose.total_residue() );
181  core::conformation::Residue const & residue = pose.residue(index);
182 
183  return (polar_ && residue.is_polar()) ||
184  (apolar_ && residue.is_apolar()) ||
185  (aromatic_ && residue.is_aromatic()) ||
186  (charged_ && residue.is_charged());
187 }
188 
190 {
191  if ( tag->hasOption("polar") ) polar_ = tag->getOption<bool>("polar");
192  if ( tag->hasOption("apolar") ) apolar_ = tag->getOption<bool>("apolar");
193  if ( tag->hasOption("aromatic") ) aromatic_ = tag->getOption<bool>("aromatic");
194  if ( tag->hasOption("charged") ) charged_ = tag->getOption<bool>("charged");
195 }
196 
198  {
199  return new ResidueTypeFilter();
200 }
201 
202 ////////////////////////////////////////////////////////////////////////////////////////////////////
203 // begin ResidueHasProperty
205  : parent()
206 {}
207 
209  : parent(),
210  property_( str )
211 {}
212 
213 bool ResidueHasProperty::operator() ( Pose const & pose, Size index ) const
214 {
215  runtime_assert( index > 0 && index <= pose.total_residue() );
216  return pose.residue_type(index).has_property( property_ );
217 }
218 
221  return new ResidueHasProperty;
222 }
223 
225 
227 {
228  if ( tag->hasOption("property") ) property_ = tag->getOption<std::string>("property");
229 }
230 
231 // begin ResidueLacksProperty
233  : parent()
234 {}
235 
237  : parent( str )
238 {}
239 
240 bool ResidueLacksProperty::operator() ( Pose const & pose, Size index ) const
241 {
242  return ( ! parent::operator()( pose, index ) );
243 }
244 
247  return new ResidueLacksProperty;
248 }
249 
251 
252 ////////////////////////////////////////////////////////////////////////////////////////////////////
253 // begin ResidueName3Is
255  : parent(),
256  name3_set()
257 {}
258 
260  : parent(),
261  name3_set()
262 {
263  name3_set.insert(str);
264 }
265 
266 ResidueName3Is::ResidueName3Is( std::set<std::string> const & strs )
267  : parent(),
268  name3_set(strs)
269 {}
270 
271 bool ResidueName3Is::operator() ( Pose const & pose, Size index ) const
272 {
273  runtime_assert( index > 0 && index <= pose.total_residue() );
274  return name3_set.count(pose.residue_type(index).name3()) != 0;
275 }
276 
279  return new ResidueName3Is;
280 }
281 
282 ResFilterOP ResidueName3Is::clone() const { return new ResidueName3Is( *this ); }
283 
285 {
286  if ( tag->hasOption("name3") )
287  {
288  utility::vector1<std::string> names = utility::string_split(tag->getOption<std::string>("name3"), ',');
289  name3_set.insert(names.begin(), names.end());
290  }
291 }
292 
293 // begin ResidueName3Isnt
295  : parent()
296 {}
297 
299  : parent( str )
300 {}
301 
302 ResidueName3Isnt::ResidueName3Isnt( std::set<std::string> const & strs )
303  : parent( strs )
304 {}
305 
306 bool ResidueName3Isnt::operator() ( Pose const & pose, Size index ) const
307 {
308  return ( ! parent::operator()( pose, index ) );
309 }
310 
313  return new ResidueName3Isnt;
314 }
315 
316 ResFilterOP ResidueName3Isnt::clone() const { return new ResidueName3Isnt( *this ); }
317 
318 ////////////////////////////////////////////////////////////////////////////////////////////////////
319 // begin ResidueIndexIs
321  : parent()
322 {}
323 
325  : parent()
326 {
327  indices_.push_back( index );
328 }
329 
331  : parent(),
332  indices_( indices )
333 {}
334 
337 
338 bool ResidueIndexIs::operator() ( Pose const & pose, Size index ) const
339 {
340  runtime_assert( index > 0 && index <= pose.total_residue() );
341  return std::find( indices_.begin(), indices_.end(), index ) != indices_.end();
342 }
343 
346  return new ResidueIndexIs;
347 }
348 
349 ResFilterOP ResidueIndexIs::clone() const { return new ResidueIndexIs( *this ); }
350 
352 {
353  if ( tag->hasOption("indices") ) {
354  indices_.clear();
355  std::string field( tag->getOption<std::string>("indices") );
356  utility::vector1< std::string > values( utility::string_split( field, ',' ) );
357  for ( utility::vector1< std::string >::const_iterator it( values.begin() ),
358  end( values.end() ); it != end; ++it ) {
359  std::istringstream ss( *it );
360  Size index;
361  ss >> index;
362  indices_.push_back( index );
363  }
364  }
365 
366  TR << "ResidueIndex with indices:";
367  for ( utility::vector1< Size >::const_iterator it( indices_.begin() ), end( indices_.end() );
368  it != end; ++it ) {
369  TR << " " << *it;
370  }
371  TR << std::endl;
372 
373 }
374 
375 // begin ResidueIndexIsnt
377  : parent()
378 {}
379 
381  : parent( index )
382 {}
383 
385  : parent( indices )
386 {}
387 
388 bool ResidueIndexIsnt::operator() ( Pose const & pose, Size index ) const
389 {
390  return ( ! parent::operator()( pose, index ) );
391 }
392 
395  return new ResidueIndexIsnt;
396 }
397 
398 ResFilterOP ResidueIndexIsnt::clone() const { return new ResidueIndexIsnt( *this ); }
399 
400 ////////////////////////////////////////////////////////////////////////////////////////////////////
401 // ResiduePDBIndexIs
403  : parent()
404 {}
405 
407  : parent()
408 {
409  indices_.push_back( ChainPos(chain,pos) );
410 }
411 
413  : parent(),
414  indices_( indices )
415 {}
416 
419 
420 bool ResiduePDBIndexIs::operator() ( Pose const & pose, Size index ) const
421 {
422  runtime_assert( index > 0 && index <= pose.total_residue() );
423  if ( ! pose.pdb_info() ) {
424  utility_exit_with_message("can't apply ResiduePDBIndexIs filter on pose without pdb info");
425  }
426  ChainPos cp( pose.pdb_info()->chain(index), pose.pdb_info()->number(index) );
427  return std::find( indices_.begin(), indices_.end(), cp ) != indices_.end();
428 }
429 
432  return new ResiduePDBIndexIs;
433 }
434 
436 
437 ///@brief the expected format for the 'indices' option is: indices=A.2,B.3,Z.-20
439 {
440  if ( tag->hasOption("indices") ) {
441  indices_.clear();
442  std::string field( tag->getOption<std::string>("indices") );
443  // split option value by comma
444  utility::vector1< std::string > values( utility::string_split( field, ',' ) );
445  for ( utility::vector1< std::string >::const_iterator it( values.begin() ),
446  end( values.end() ); it != end; ++it ) {
447  // split pdb chain.pos token by '.'
448  utility::vector1< std::string > chainposstr( utility::string_split( *it, '.' ) );
449  if ( chainposstr.size() != 2 ) utility_exit_with_message("can't parse pdb index " + *it);
450  char chain( *chainposstr.front().begin() );
451  std::istringstream ss( chainposstr.back() );
452  int pdbnum;
453  ss >> pdbnum;
454  indices_.push_back( ChainPos(chain,pdbnum) );
455  }
456  }
457 
458  TR << "ResiduePDBIndex with indices:";
460  it != end; ++it ) {
461  TR << " " << it->chain_ << '.' << it->pos_;
462  }
463  TR << std::endl;
464 
465 }
466 
467 // ResiduePDBIndexIsnt
469  : parent()
470 {}
471 
473  : parent( chain, pos )
474 {}
475 
477  : parent( indices )
478 {}
479 
480 bool ResiduePDBIndexIsnt::operator() ( Pose const & pose, Size index ) const
481 {
482  return ( ! parent::operator()( pose, index ) );
483 }
484 
487  return new ResiduePDBIndexIsnt;
488 }
489 
491 
492 ////////////////////////////////////////////////////////////////////////////////////////////////////
493 // ChainIs
495  : parent()
496 {}
497 
498 ChainIs::ChainIs( char const & chain )
499  : parent(),
500  chain_( chain )
501 {}
502 
503 bool ChainIs::operator() ( Pose const & pose, Size index ) const
504 {
505  runtime_assert( index > 0 && index <= pose.total_residue() );
506  if ( ! pose.pdb_info() ) {
507  utility_exit_with_message("Can't apply ChainIs filter on pose without pdb info");
508  }
509  return( (pose.pdb_info()->chain(index) == chain_) ? true : false );
510 }
511 
514  return new ChainIs;
515 }
516 
517 ResFilterOP ChainIs::clone() const { return new ChainIs( *this ); }
518 
520 {
521  chain_ = tag->getOption<char>("chain", 'A');
522 }
523 
524 // ChainIsnt
526  : parent()
527 {}
528 
529 ChainIsnt::ChainIsnt( char const & chain )
530  : parent( chain )
531 {}
532 
533 bool ChainIsnt::operator() ( Pose const & pose, Size index ) const
534 {
535  return ( ! parent::operator()( pose, index ) );
536 }
537 
540  return new ChainIsnt;
541 }
542 
543 ResFilterOP ChainIsnt::clone() const { return new ChainIsnt( *this ); }
544 
545 } //namespace operation
546 } //namespace task
547 } //namespace pack
548 } //namespace core