Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ResidueSelector.hh
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
11 /// @author Phil Bradley
12 
13 
14 #ifndef INCLUDED_core_chemical_ResidueSelector_hh
15 #define INCLUDED_core_chemical_ResidueSelector_hh
16 
17 
18 // // Unit headers
20 
21 // Package headers
22 // Commented by inclean daemon #include <core/chemical/AA.hh>
24 
25 #include <utility/vector1.hh>
26 
27 
28 // Commented by inclean daemon #include <core/chemical/ResidueTypeSet.fwd.hh>
29 // Commented by inclean daemon #include <core/chemical/VariantType.fwd.hh>
30 
31 // Project headers
32 
33 // Utility headers
34 // Commented by inclean daemon #include <utility/vector1.hh>
35 // Commented by inclean daemon #include <utility/pointer/owning_ptr.hh>
36 // Commented by inclean daemon #include <utility/pointer/ReferenceCount.hh>
37 
38 // C++ headers
39 // Commented by inclean daemon #include <sstream>
40 
41 namespace core {
42 namespace chemical {
43 
44 /**
45 
46  The ResidueSelector is an object the picks out a subset of ResidueTypes, via a
47  bool operator[](ResidueType const &) method. It is implemented as a logical AND of individual constraints,
48  each of which typically has an OR structure. So eg the lines
49 
50  PROPERTY PROTEIN
51  AA PRO GLY
52  NAME3 HPR
53  NOT VARIANT_TYPE PHOSPHO TERMINUS
54 
55  would define a selector that matched residues with property PROTEIN, with aa types
56  pro or gly, with a three-letter code of HPR and not of variant type PHOSPHO or TERMINUS
57 
58  The individual constraints that make up the ResidueSelector object are subclasses of
59  ResidueSelectorSingle; ResidueSelector has a vector1 of ResidueSelectorSingleOP's
60 
61 **/
62 
63 
64 
65 ////////////////////////////////////////////////////////////////////////////////////////
66 /// @brief A base class for defining a ResidueSelector by a single criterion
68 public:
69  ///@brief Automatically generated virtual destructor for class deriving directly from ReferenceCount
70  virtual ~ResidueSelectorSingle();
71 
72  /// constructor
73  ResidueSelectorSingle( bool const result ):
74  desired_result_( result )
75  {}
76 
77  /// select positively or negatively
78  bool
80  {
81  return desired_result_;
82  }
83 
84  virtual
85  bool
86  operator[]( ResidueType const & rsd ) const = 0;
87 
88 private:
90 
91 };
92 
93 // allow NOT at the beginning
94 
95 // AA aa1 aa2 aa3
96 // VARIANT_TYPE type1 type2 type3
97 // PROPERTY property1 property2
98 
99 ////////////////////////////////////////////////////////////////////////////////////////
100 /// @brief Does the residue belong to ANY of these AAs?
102 public:
103 
105  utility::vector1< AA > const & aas_in,
106  bool const result
107  ):
108  ResidueSelectorSingle( result ),
109  aas_( aas_in )
110  {}
111 
112  /// select by AA type
113  bool
114  operator[]( ResidueType const & rsd ) const {
115  // left-hand side will be TRUE if rsd.aa() is present in our list of AA's
116  //std::cout << "Selector_AA: " << rsd.aa() << ' ' << aas_.size() << ' ' << desired_result() << std::endl;
117  return ( ( std::find( aas_.begin(), aas_.end(), rsd.aa() ) != aas_.end() ) == desired_result() );
118  }
119 
120  // data
121 private:
123 };
124 
125 ////////////////////////////////////////////////////////////////////////////////////////
126 /// @brief Is a certain string in the command-line option -chemical:allow_patch present ?
127 /// this selector does actually not depend on the residuetype it is queried for
129 public:
130 
132  std::string const& flags_in,
133  bool const result
134  );
135 
136  /// select by AA type
137  bool
138  operator[]( ResidueType const & ) const {
140  }
141 
142  // data
143 private:
145 };
146 
147 ////////////////////////////////////////////////////////////////////////////////////////
148 /// @brief Does the residue have to ANY of these three-letter codes?
150 public:
151 
153  utility::vector1< std::string > const & name3s_in,
154  bool const result
155  ):
156  ResidueSelectorSingle( result ),
157  name3s_( name3s_in )
158  {}
159 
160  // select by three-letter code
161  bool
162  operator[]( ResidueType const & rsd ) const {
163  return ( ( std::find( name3s_.begin(), name3s_.end(), rsd.name3() ) != name3s_.end() ) == desired_result() );
164  }
165 
166 private:
168 };
169 
170 ////////////////////////////////////////////////////////////////////////////////////////
171 /// @brief Does the residue have ANY of these properties?
172 
174 public:
175 
177  utility::vector1< std::string > const & properties_in,
178  bool const result
179  ):
180  ResidueSelectorSingle( result ),
181  properties_( properties_in )
182  {}
183 
184  /// select by PROPERTY
185  bool
186  operator[]( ResidueType const & rsd ) const {
188  it_end = properties_.end(); it!= it_end; ++it ) {
189  if ( rsd.has_property( *it ) ) return desired_result();
190  }
191  return !desired_result();
192  }
193 
194  // data
195 private:
197 };
198 
199 ////////////////////////////////////////////////////////////////////////////////////////
200 /// @brief Does the residue have ANY of variant types?
201 
203 public:
204 
206  utility::vector1< VariantType > const & variants_in,
207  bool const result
208  ):
209  ResidueSelectorSingle( result ),
210  variants_( variants_in )
211  {}
212 
213  /// select by VARIANT_TYPE
214  bool
215  operator[]( ResidueType const & rsd ) const {
217  it_end = variants_.end(); it!= it_end; ++it ) {
218  if ( rsd.has_variant_type( *it ) ) return desired_result();
219  }
220  return !desired_result();
221  }
222 
223  // data
224 private:
226 };
227 
228 
229 
230 ////////////////////////////////////////////////////////////////////////////////////////
231 /// @brief Does the residue have ALL of the variant types and no more
232 
234 public:
235 
237  utility::vector1< VariantType > const & variants_in,
238  bool const result
239  ):
240  ResidueSelectorSingle( result ),
241  variants_( variants_in )
242  {}
243 
244  /// select by VARIANT_TYPE
245  bool
246  operator[]( ResidueType const & rsd ) const {
248  it_end = variants_.end(); it!= it_end; ++it ) {
249  if ( !rsd.has_variant_type( *it ) ) return !desired_result(); // rsd is missing one of our variants
250  }
251  if ( rsd.variant_types().size() == variants_.size() ) return desired_result();
252  return !desired_result(); // residue has an extra variant
253  }
254 
255  // data
256 private:
258 };
259 
260 
261 
262 ////////////////////////////////////////////////////////////////////////////////////////
263 /// @brief Does the residue have ANY of variant types?
264 
266 public:
267 
269  bool const result
270  ):
271  ResidueSelectorSingle( result )
272  {}
273 
274  /// select by VARIANT_TYPE
275  bool
276  operator[]( ResidueType const & rsd ) const {
277  return ( rsd.variant_types().empty() == desired_result() );
278  }
279 
280  // data
281 private:
282 
283 };
284 
285 
286 
287 ////////////////////////////////////////////////////////////////////////////////////////
288 /// @brief Does the residue belong to ANY of these AAs?
290 public:
291 
293  char const n,
294  bool const result
295  ):
296  ResidueSelectorSingle( result ),
297  name1_( n )
298  {}
299 
300  /// select by name1 type
301  bool
302  operator[]( ResidueType const & rsd ) const {
303  return ( ( rsd.name1() == name1_ ) == desired_result() );
304  }
305 
306  // data
307 private:
308  char const name1_;
309 };
310 
311 
312 ////////////////////////////////////////////////////////////////////////////////////////
313 /// @brief create a singe ResidueSelector from an input line.
316 
317 
318 ////////////////////////////////////////////////////////////////////////////////////////
319 /// @brief A class picking out a subset of ResidueType by multiple criteria
321 public:
322  ///@brief Automatically generated virtual destructor for class deriving directly from ReferenceCount
323  virtual ~ResidueSelector();
324 
325  /// [] operator: selector[ResidueType] => yes or no
326  bool
327  operator[]( ResidueType const & rsd ) const
328  {
329  //std::cout << "ResidueSelector::operator[] " << rsd.name() << ' ' << selectors_.size() << std::endl;
330  for ( uint i=1, i_end = selectors_.size(); i<= i_end; ++i ) {
331  if ( !( ( *selectors_[i] )[ rsd ] ) ) return false;
332  }
333  return true;
334  }
335 
336  /// add a new selector single
337  ResidueSelector & // allow chaining
338  add_line( std::string const & line )
339  {
341  if ( new_selector ) {
342  //std::cout << "add_line: success: " << line << std::endl;
343  selectors_.push_back( new_selector );
344  } else {
345  std::cout << "ResidueSelector::add_line: bad line:" << line << std::endl;
346  }
347  return *this;
348  }
349 
350  /// reset
351  ResidueSelector & // allow chaining
353  {
354  selectors_.clear();
355  return *this;
356  }
357 
358  ///
359  ResidueSelector & // allow chaining
360  set_name1( char const n )
361  {
362  selectors_.push_back( new Selector_NAME1( n, true ) );
363  return *this;
364  }
365 
366  ///
367  ResidueSelector & // allow chaining
368  set_aa( AA const aa )
369  {
370  utility::vector1< AA > aas( 1, aa );
371  selectors_.push_back( new Selector_AA( aas, true ) );
372  return *this;
373  }
374 
375  ///
376  ResidueSelector & // allow chaining
377  set_property( std::string const property )
378  {
379  utility::vector1< std::string > properties( 1, property );
380  selectors_.push_back( new Selector_PROPERTY( properties, true ) );
381  return *this;
382  }
383 
384  ///
385  ResidueSelector & // allow chaining
387  {
388  selectors_.push_back( new Selector_NO_VARIANTS( true ) );
389  return *this;
390  }
391 
392  ///
393  ResidueSelector & // allow chaining
394  match_variants( ResidueType const & rsd_type_to_match )
395  {
396  selectors_.push_back( new Selector_MATCH_VARIANTS( rsd_type_to_match.variant_types(), true ) );
397  return *this;
398  }
399 
400  ///
402  select( ResidueTypeSet const & rsd_set );
403 
404  // data
405 private:
406  /// a vector of single ResidueSelector
408 };
409 
410 
411 } // chemical
412 } // core
413 
414 
415 
416 #endif