Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PackerNeighborGraphFilter.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/filters/PackerNeighborGraphFilter.cc
11 /// @brief
12 /// @detailed
13 /// Contains currently:
14 ///
15 ///
16 /// @author Florian Richter (floric@u.washington.edu ), march 2009
17 
18 // Unit Headers
20 
21 // Package Headers
22 
23 // Project Headers
24 #include <core/graph/Graph.hh>
26 //#include <core/pose/Pose.hh>
27 #include <core/types.hh>
28 
29 
30 // ObjexxFCL Headers
31 
32 // Utility headers
33 #include <basic/Tracer.hh>
34 
35 #include <utility/vector1.hh>
36 
37 
38 
39 //// C++ headers
40 static basic::Tracer tr("protocols.filters.PackerNeighborGraphFilter");
41 
42 namespace protocols {
43 namespace simple_filters {
44 
45 
46 void
48  core::Size res1,
49  core::Size res2
50 ) const
51 {
52 
53  bool res1_in_region1( region1_.find( res1 ) != region1_.end() );
54  bool res1_in_region2( region2_.find( res1 ) != region2_.end() );
55 
56  bool res2_in_region1( region1_.find( res2 ) != region1_.end() );
57  bool res2_in_region2( region2_.find( res2 ) != region2_.end() );
58 
59 
60  if( (res1_in_region1 && res2_in_region2) || (res2_in_region1 && res1_in_region2 ) ){
61  num_cons_++;
62  }
63 
64 }
65 
66 
68 : task_( NULL ), sfxn_( NULL ), task_invalidated_( false )
69 {
72 }
73 
75 
76 void
78  core::Size residue,
79  core::Size required_connections
80 ){
81 
82  std::pair< core::Size, core::Size > con_pair( std::make_pair( residue, required_connections ) );
83 
84  required_connections_per_res_.insert( con_pair );
85 }
86 
87 
88 void
90  core::Size residue
91 ){
92 
93  std::map< core::Size, core::Size >::iterator map_it = required_connections_per_res_.find( residue );
94 
95  if( map_it == required_connections_per_res_.end() ) {
96  required_connections_per_res_.insert( std::make_pair( residue, 1 ) );
97  }
98 
99  else map_it->second++;
100 }
101 
102 
103 void
105  std::set< core::Size > const & region1,
106  std::set< core::Size > const & region2,
107  core::Size required_connections
108 ){
109  required_connections_between_regions_.push_back( RegionalConnections( region1, region2, required_connections ) );
110 }
111 
112 bool
114 
115  using namespace core::graph;
116 
117  //if( task_invalidated_ ) utility_exit_with_message("Calling PackerNeighborGraphFilter apply function even though the task has been invalidated");
118 
119  std::map< core::Size, core::Size > connections_for_important_res;
121 
122  //reset all the regions
124  reg_it != regions_end; ++reg_it ){
125  reg_it->reset_num_connections();
126  }
127 
128  //first, we create the packer neighbor graph
130 
131  //well, that was easy!!
132  //now we have to go through the packer neighbor graph and see what kind of connections it has
133  for( Node::EdgeListConstIter edge_it( png->const_edge_list_begin() ), edge_end( png->const_edge_list_end() );
134  edge_it != edge_end; ++edge_it ){
135 
136 
137  core::Size res1 = (*edge_it)->get_first_node_ind();
138  core::Size res2 = (*edge_it)->get_second_node_ind();
139 
140  //check if either of these residues have required connections
142 
143  std::map< core::Size, core::Size >::iterator map_it = connections_for_important_res.find( res1 );
144  if( map_it == connections_for_important_res.end() ){
145 
146  connections_for_important_res.insert( std::pair< core::Size, core::Size >( res1, 1 ) );
147  }
148  else map_it->second++;
149  }
150 
152 
153  std::map< core::Size, core::Size >::iterator map_it = connections_for_important_res.find( res2 );
154  if( map_it == connections_for_important_res.end() ){
155 
156  connections_for_important_res.insert( std::pair< core::Size, core::Size >( res2, 1 ) );
157  }
158  else map_it->second++;
159  }
160 
161  //now check whether these two residues belong to regions that we care about
163  reg_it != regions_end; ++reg_it ){
164  reg_it->check_if_connected_residues_belong_to_regions( res1, res2 );
165  }
166 
167  } //iteration over graph edges
168 
169 
170  //aight. now let's check whether the connections in the png satisfy the requirements
171  //first, let's check if all required residues have a sufficient number of connections
172  for( std::map< core::Size, core::Size >::const_iterator reqmap_it = required_connections_per_res_.begin();
173  reqmap_it != required_connections_per_res_.end(); ++reqmap_it ){
174 
175  std::map< core::Size, core::Size >::const_iterator curmap_it = connections_for_important_res.find( reqmap_it->first );
176 
177  if( curmap_it == connections_for_important_res.end() ) return false; //residue was required to have connections but had 0
178 
179  else if( curmap_it->second < reqmap_it->second ) return false; //residue had too little connections
180 
181  }
182 
183  //second, check whether all the regions have the right number of connections
185  reg_it != regions_end; ++reg_it ){
186  if( ! reg_it->enough_connections() ) return false;
187  }
188 
189  //yay! if we've made it till here, that means all the requirements are met
190  return true;
191 
192 } // apply_filter
193 
194 
195 } // filters
196 } // protocols