Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ResidueCountFilter.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/ResidueCountFilter.cc
11 /// @brief Filter on the total number of residues in the structure
12 /// @author Matthew O'Meara (mattjomeara@gmail.com)
13 /// @author Tom Linsky (tlinsky@gmail.com) [residue type option]
14 
15 //Unit Headers
18 #include <utility/tag/Tag.hh>
19 #include <core/pose/Pose.hh>
21 //Project Headers
24 #include <basic/Tracer.hh>
25 //Utility Headers
26 #include <utility/string_util.hh>
27 namespace protocols{
28 namespace simple_filters {
29 
30 using namespace core;
31 using namespace core::scoring;
32 
33 static basic::Tracer TR( "protocols.simple_filters.ResidueCountFilter" );
34 
37 
39 ResidueCountFilterCreator::keyname() const { return "ResidueCount"; }
40 
41 //default ctor
43  protocols::filters::Filter( "ResidueCount" ),
44  max_residue_count_(0),
45  enable_max_residue_count_(false),
46  min_residue_count_(0),
47  enable_min_residue_count_(false)
48 {}
49 
51  ResidueCountFilter const & src
52 ) :
53  protocols::filters::Filter( "ResidueCount" ),
54  max_residue_count_(src.max_residue_count_),
55  enable_max_residue_count_(src.enable_max_residue_count_),
56  min_residue_count_(src.min_residue_count_),
57  enable_min_residue_count_(src.enable_min_residue_count_),
58  res_types_( src.res_types_ )
59 {}
60 
62 
65  return new ResidueCountFilter( *this );
66 }
67 
70  return new ResidueCountFilter();
71 }
72 
73 
74 void
76  utility::tag::TagPtr const tag,
78  filters::Filters_map const &,
79  moves::Movers_map const &,
80  core::pose::Pose const & pose
81 ) {
82  if(tag->hasOption("max_residue_count")){
84  max_residue_count(tag->getOption< core::Size >("max_residue_count"));
85  }
86 
87  if(tag->hasOption("min_residue_count")){
89  min_residue_count(tag->getOption< core::Size >("min_residue_count"));
90  }
91 
92  if(tag->hasOption("residue_types")){
93  std::string const res_type_str( tag->getOption< std::string >("residue_types", "") );
94  utility::vector1< std::string > const res_type_vec( utility::string_split( res_type_str, ',' ) );
95  TR << "Residue types specified: " << res_type_vec << std::endl;
96  // get the residue type set from the first residue of the input pose
97  runtime_assert( pose.total_residue() >= 1 );
98  core::chemical::ResidueTypeSet const & res_type_set( pose.residue( 1 ).residue_type_set() );
99  // loop through residue types, check to see if they are valid, and add them if they are valid
100  for ( core::Size i=1; i<=res_type_vec.size(); ++i ) {
101  if ( ! add_residue_type_by_name( res_type_set, res_type_vec[i] ) ) {
102  // try to add the residue type -- if it doesn't exist in the residue type set, inform the user and exit
103  utility_exit_with_message( "An invalid residue type (" + res_type_vec[i] + ") was specified to the ResidueCount filter." );
104  }
105  } // for all res type specified
106  }
107 
108 }
109 
110 bool
112  core::pose::Pose const & pose
113 ) const {
115  return false;
116  }
117 
119  return false;
120  }
121 
122  return true;
123 }
124 
125 void
127  std::ostream & out,
128  core::pose::Pose const & pose
129 ) const {
130  out << "Residue Count: " << compute( pose ) <<std::endl;
131 }
132 
135  core::pose::Pose const & pose
136 ) const {
137  return compute( pose );
138 }
139 
142  core::pose::Pose const & pose
143 ) const {
144  if ( res_types_.size() > 0 ) {
145  core::Size count( 0 );
146  for ( core::Size i=1; i<=pose.total_residue(); ++i ) {
147  for ( core::Size j=1; j<=res_types_.size(); ++j ) {
148  if ( pose.residue( i ).name3() == res_types_[j] || pose.residue( i ).name() == res_types_[j] ) {
149  ++count;
150  } // if
151  } // for all res types specified
152  } // for all residues
153  return count;
154  } else {
155  return pose.total_residue();
156  }
157 }
158 
161  return max_residue_count_;
162 }
163 
164 void
166  core::Size value
167 ) {
168  max_residue_count_ = value;
169 }
170 
173  return res_types_;
174 }
175 
176 void
178  utility::vector1< std::string > const & res_types
179 ) {
180  res_types_.clear();
181  for ( core::Size i=1; i<=res_types.size(); ++i ) {
182  res_types_.push_back( res_types[i] );
183  }
184 }
185 
186 bool
189 }
190 
191 void
193  bool value
194 ) {
196 }
197 
200  return min_residue_count_;
201 }
202 
203 void
205  core::Size value
206 ) {
207  min_residue_count_ = value;
208 }
209 
210 bool
213 }
214 
215 void
217  bool value
218 ) {
220 }
221 
222 
223 ///@brief Checks whether a residue type is present in the provided residue type set, and if so, adds it to res_types_
224 ///@detail given user specified residue type string, look for residue type name and add it to the list of types to count if it is present in the specified ResidueTypeSet.
225 ///@input res_type_set, the residue type set of the input structure
226 ///@input res_type_input, the user specified residue type name
227 ///@return false if res_type_input doesn't match any residue type names, true otherwise
228 bool
230  core::chemical::ResidueTypeSet const & res_type_set,
231  std::string const & res_type_input
232 ) {
233  using namespace core::chemical;
234 
235  // check for the name in the residue type set
236  if ( !res_type_set.has_name( res_type_input ) ) {
237  return false;
238  }
239 
240  res_types_.push_back( res_type_input );
241  return true;
242 }
243 
244 } // namespace
245 } // namespace