Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EnzdesCstCache.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 .cc file for enzdes cacheable observer
11 /// @brief
12 /// @author Florian Richter, floric@u.washington.edu, september 09
13 
14 
15 //unit headers
17 
18 //package headers
21 #include <protocols/toolbox/match_enzdes_util/EnzConstraintParameters.hh> //for CovalentConnectionReplaceInfo
22 
23 //project headers
25 #include <core/pose/Pose.hh>
28 
29 
30 //utility headers
31 #include <utility/string_util.hh>
32 
33 #include <core/id/AtomID.hh>
34 #include <utility/vector1.hh>
35 
36 
37 namespace protocols {
38 namespace toolbox {
39 namespace match_enzdes_util {
40 
42  EnzConstraintIOCOP enzcst_io,
43  core::Size num_cst_blocks
44 ) : enzcst_io_(enzcst_io)
45 {
46  param_cache_.clear();
47  for( core::Size i = 1; i <= num_cst_blocks; ++i){
48  param_cache_.push_back( new EnzdesCstParamCache() );
49  }
50 }
51 
53  : ReferenceCount( other ), enzcst_io_(other.enzcst_io_)
54 {
55  param_cache_.clear();
56  for( utility::vector1< EnzdesCstParamCacheOP >::const_iterator param_it( other.param_cache_.begin()), param_end(other.param_cache_.end()); param_it != param_end; ++param_it ){
57  param_cache_.push_back( new EnzdesCstParamCache( **param_it ) );
58  }
59 }
60 
62 
65 {
66  return enzcst_io_;
67 }
68 
71  core::Size cst_block )
72 {
73  runtime_assert( cst_block <= param_cache_.size() );
74  return param_cache_[ cst_block ];
75 }
76 
79  core::Size cst_block ) const
80 {
81  if (cst_block > param_cache_.size()){
82  std::cerr << "param_cache_.size:" << param_cache_.size() << " cst_block:" << cst_block << std::endl;
83  std::cerr << "cst_block should be smaller or equal to param_cache_.size()" << std::endl;
84  runtime_assert( cst_block <= param_cache_.size() );
85  }
86  return param_cache_[ cst_block ];
87 }
88 
89 void
91  core::Size cst_block,
92  EnzdesCstParamCacheOP param_cache )
93 {
94  runtime_assert( cst_block <= param_cache_.size() );
95  param_cache_[ cst_block ] = param_cache;
96 }
97 
98 bool
100  core::Size seqpos) const
101 {
102  for( core::Size ii = 1; ii <= this->ncsts(); ++ii ) {
103  if( this->param_cache( ii )->contains_position( seqpos ) ) return true;
104  }
105  return false;
106 }
107 
110 {
111 
112  using namespace core;
113  utility::vector1< Size > found_protein_positions;
114  utility::vector1< Size > found_lig_positions;
115 
116  for( Size i =1; i<= param_cache_.size(); ++i ){
117 
118  for(std::map< Size, EnzCstTemplateResAtomsOP >::const_iterator resA_it = param_cache_[i]->template_res_cache( 1 )->seqpos_map_begin(), resA_end = param_cache_[i]->template_res_cache( 1 )->seqpos_map_end(); resA_it != resA_end; ++resA_it ){
119  if( pose.residue_type( resA_it->first ).is_ligand() ) {
120  if( find( found_lig_positions.begin(), found_lig_positions.end(), resA_it->first ) == found_lig_positions.end() ) {
121  found_lig_positions.push_back( resA_it->first );
122  }
123  }
124  else found_protein_positions.push_back( resA_it->first );
125  }
126 
127  for(std::map< Size, EnzCstTemplateResAtomsOP >::const_iterator resB_it = param_cache_[i]->template_res_cache( 2 )->seqpos_map_begin(), resB_end = param_cache_[i]->template_res_cache( 2 )->seqpos_map_end(); resB_it != resB_end; ++resB_it ){
128  if( pose.residue_type( resB_it->first ).is_ligand() ) {
129  if( find( found_lig_positions.begin(), found_lig_positions.end(), resB_it->first ) == found_lig_positions.end() ) {
130  found_lig_positions.push_back( resB_it->first );
131  }
132  }
133  else found_protein_positions.push_back( resB_it->first );
134  }
135  } //loop over params
136 
137  for( utility::vector1< Size >::const_iterator lig_it = found_lig_positions.begin(); lig_it != found_lig_positions.end(); ++lig_it ){
138  found_protein_positions.push_back( *lig_it );
139  }
140  return found_protein_positions;
141 } //ordered constrained positions
142 
143 void
145  core::id::SequenceMapping const & smap )
146 {
147  for( utility::vector1< EnzdesCstParamCacheOP >::iterator param_it = param_cache_.begin(), param_end = param_cache_.end(); param_it != param_end; ++param_it ){
148  (*param_it)->remap_resid( smap );
149  }
150 }
151 
152 /// @brief Default constructor
153 /// right now two instances of cached template res get created
154 /// probably not ideal in general case, but is always the case
155 /// in the current implementation of enzdes, and this is the only
156 /// thing using this at the moment
158 {
159  template_res_cache_.push_back( new EnzCstTemplateResCache() );
160  template_res_cache_.push_back( new EnzCstTemplateResCache() );
161 }
162 
164  : ReferenceCount( other ),
165  active_pose_constraints_( other.active_pose_constraints_ ),
166  covalent_connections_(other.covalent_connections_ )
167 {
168  template_res_cache_.clear();
169  for( core::Size i = 1; i <= other.template_res_cache_.size(); ++i ){
170  template_res_cache_.push_back( new EnzCstTemplateResCache( *(other.template_res_cache_[i] ) ) );
171  }
172 }
173 
174 
176 
177 
178 void
181 ){
182  active_pose_constraints_ = constraints;
183 }
184 
185 void
187 {
188  active_pose_constraints_.clear();
189 }
190 
191 bool
193 {
194  for( utility::vector1< EnzCstTemplateResCacheOP >::const_iterator template_res_it = template_res_cache_.begin(), template_res_end = template_res_cache_.end(); template_res_it != template_res_end; ++template_res_it ){
195  if( (*template_res_it)->not_in_pose() ) return true;
196  }
197  return false;
198 }
199 
200 void
202 
203  core::Size find_count(0);
204  for( utility::vector1< EnzCstTemplateResCacheOP >::iterator template_res_it = template_res_cache_.begin(), template_res_end = template_res_cache_.end(); template_res_it != template_res_end; ++template_res_it ){
205  if( (*template_res_it)->remove_seqpos( seqpos ) ) find_count++;
206  }
207 
208  if( find_count > 1 ){
209  utility_exit_with_message("Error: Several template residues were apparently at pose position "+utility::to_string(seqpos )+". This shouldn't happen...\n");
210  }
211 
212  if( find_count == 0 ){
213  utility_exit_with_message("Error: No template residues were found at pose position "+utility::to_string(seqpos )+". Something's unclean somewhere...\n");
214  }
215 } //remove_seqpos_from_template_res
216 
217 void
219 
220  core::Size find_count(0);
221  for( utility::vector1< EnzCstTemplateResCacheOP >::iterator template_res_it = template_res_cache_.begin(), template_res_end = template_res_cache_.end(); template_res_it != template_res_end; ++template_res_it ){
222 
223  if( (*template_res_it)->not_in_pose() ){
224  (*template_res_it)->set_position_in_pose( seqpos );
225  find_count++;
226  }
227  }
228  if( find_count > 1 ) utility_exit_with_message("Error: Several template residues are missing in the pose. This shouldn't happen...\n");
229  if( find_count == 0 ) utility_exit_with_message("Error: no template residue is missing in the pose, this shouldn't have happened... \n");
230 }
231 
232 
233 bool
235 {
236  for( utility::vector1< EnzCstTemplateResCacheOP >::const_iterator template_res_it = template_res_cache_.begin(), template_res_end = template_res_cache_.end(); template_res_it != template_res_end; ++template_res_it ){
237  if( (*template_res_it)->contains_position( seqpos ) ) return true;
238  }
239  return false;
240 }
241 
242 
243 /// @details have to remap all the data that's cached
244 /// 1. the information about the template res
245 /// 2. the actual constraints
246 /// 3. the information about covalent connections
247 void
249 {
250  // 1.
251  for( utility::vector1< EnzCstTemplateResCacheOP >::iterator template_res_it = template_res_cache_.begin(), template_res_end = template_res_cache_.end(); template_res_it != template_res_end; ++template_res_it ){
252  (*template_res_it)->remap_resid( smap );
253  }
254 
255  //2.
257  cst_it != active_pose_constraints_.end(); ++cst_it ){
258  *cst_it = (*cst_it)->remap_resid( smap );
259  if( ! (*cst_it) ) utility_exit_with_message("Remapping of catalytic constraints failed");
260  }
261 
262  //3.
263  for( utility::vector1< CovalentConnectionReplaceInfoCOP >::iterator con_it = covalent_connections_.begin(), con_end = covalent_connections_.end(); con_it != con_end; ++con_it ){
265  newcov->remap_resid( smap );
266  (*con_it) = newcov;
267  }
268 }
269 
270 
272  ReferenceCount(),
273  not_in_pose_(true), pose_data_uptodate_(false)
274 {
275  seqpos_map_.clear();
276 }
277 
279  ReferenceCount( other ),
280  not_in_pose_(other.not_in_pose_),
281  pose_data_uptodate_(other.pose_data_uptodate_)
282 {
283  seqpos_map_.clear();
284  for( SeqposTemplateAtomsMap::const_iterator map_it(other.seqpos_map_.begin()), map_end(other.seqpos_map_.end()); map_it != map_end; ++map_it ){
285  seqpos_map_.insert( std::pair< core::Size, EnzCstTemplateResAtomsOP >( map_it->first, new EnzCstTemplateResAtoms( *(map_it->second) ) ) );
286  }
287 }
288 
290 
291 void
293  seqpos_map_.clear();
294  seqpos_map_.insert( std::pair<core::Size,EnzCstTemplateResAtomsOP>(seqpos, new EnzCstTemplateResAtoms() ) );
295  not_in_pose_ = false;
296  pose_data_uptodate_ = false;
297 }
298 
299 void
301  seqpos_map_.insert( std::pair<core::Size,EnzCstTemplateResAtomsOP>(seqpos, new EnzCstTemplateResAtoms() ) );
302  not_in_pose_ = false;
303  pose_data_uptodate_ = false;
304 }
305 
306 bool
308 
309  bool return_val = seqpos_map_.erase( seqpos );
310  if( seqpos_map_.size() == 0 ) {
311  not_in_pose_ = true;
312  pose_data_uptodate_ = false;
313  }
314  return return_val;
315 }
316 
317 void
319 
320  // we have to remap the maps, little complicated to change the indexes of a map
322  for( SeqposTemplateAtomsMap::const_iterator map_it(seqpos_map_.begin()), map_end(seqpos_map_.end()); map_it != map_end; ++map_it ){
323  temp_vec.push_back( *map_it );
324  }
325  seqpos_map_.clear();
326 
327  for( utility::vector1< std::pair< Size, EnzCstTemplateResAtomsOP > >::iterator vec_it = temp_vec.begin(), vec_end = temp_vec.end(); vec_it != vec_end; ++vec_it ){
328  vec_it->second->remap_resid( smap );
329  core::Size newpos( smap[ vec_it->first ] );
330  if( newpos == 0 ) utility_exit_with_message("A catalytic residue is apparently missing from the pose");
331  seqpos_map_.insert( std::pair< Size, EnzCstTemplateResAtomsOP >( newpos, vec_it->second ) );
332  }
333 }
334 
335 }
336 } // enzdes
337 } //protocols