Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RotamerSubset.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/rotamer_set/RotamerSubset.cc
11 /// @brief
12 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
13 
14 // Unit Headers
16 
17 // Project Headers
21 #include <basic/Tracer.hh>
22 
23 // C++ headers
24 #include <string>
25 #include <iostream>
26 
28 #include <utility/vector1.hh>
29 
30 
31 namespace core {
32 namespace pack {
33 namespace rotamer_set {
34 
35 static basic::Tracer tt("core.pack.rotamer_set.RotamerSubset",basic::t_info );
36 
38  RotamerSet & src_rotset,
39  utility::vector1< Size > const & rotamer_subset
40 ) :
41  n_residue_types_( 0 ),
42  cached_tries_( scoring::methods::n_energy_methods, 0 ),
43  id_for_current_rotamer_( 0 ),
44  rotamer_offsets_require_update_( false )
45 {
46  rotamers_.reserve( rotamer_subset.size() );
47  Size const src_curr_rot_index = src_rotset.id_for_current_rotamer();
48  for ( Size ii = 1; ii <= rotamer_subset.size(); ++ii ) {
49  steal_rotamer( src_rotset.nonconst_rotamer( rotamer_subset[ ii ] ) );
50  if ( rotamer_subset[ ii ] == src_curr_rot_index ) {
52  }
53  }
54 
55 }
56 
58 
59 void
61  conformation::Residue const & rotamer
62 )
63 {
65  push_back_rotamer( rotamer.clone() );
66 }
67 
68 
69 
70 Size
72 {
74  return n_residue_types_;
75 }
76 
77 Size
79 {
81  return n_residue_groups_;
82 }
83 
84 
85 Size
87 {
89  assert( which_restype <= n_residue_types_ );
90  return residue_type_rotamers_begin_[ which_restype ];
91 }
92 
93 Size
95 {
97  assert( which_resgroup <= n_residue_groups_ );
98  return residue_group_rotamers_begin_[ which_resgroup ];
99 }
100 
101 
102 Size
104 {
106 
107  assert( which_restype <= n_residue_types_ );
108  return n_rotamers_for_restype_[ which_restype ];
109 }
110 
111 Size
113 {
115 
116  assert( which_resgroup <= n_residue_groups_ );
117  return n_rotamers_for_resgroup_[ which_resgroup ];
118 }
119 
120 /// @brief given a rotamer id, return an int which represents a type for this rotamer.
121 /// INCOMPLETELY IMPLEMENTED. ANDREW: FIX THIS.
122 Size
124 {
125  //return residue_type_for_rotamers_[ which_rotamer ];
126  return 1;
127 }
128 
129 /// @brief given a rotamer id, return an int which represents a type for this rotamer.
130 /// INCOMPLETELY IMPLEMENTED. ANDREW: FIX THIS.
131 Size
133 {
134  //return residue_type_for_rotamers_[ which_rotamer ];
135  return 1;
136 }
137 
138 
139 Size
141 {
142  return rotamers_.size();
143 }
144 
145 Size
147 {
149 }
150 
153 {
154  return rotamers_[ rot_id ];
155 }
156 
157 
158 /// @details In handing out non-const data, the guarantee of rotamer-type contiguity
159 /// within the rotamers_ array, and the correspondence of the rotamer offset
160 /// data is lost. Future access to rotamer offset data first requires an update
161 /// of the rotamer offset arrays.
164 {
166 
167  return rotamers_[ rot_id ];
168 }
169 
170 void
172  Size method_enum_id,
174 )
175 {
176  cached_tries_[ method_enum_id ] = trie;
177 }
178 
179 
181 RotamerSubset::get_trie( Size method_enum_id ) const
182 {
183  return cached_tries_[ method_enum_id ];
184 }
185 
186 /// @details O(n) operation; if you have a lot of rotamers you want to remove, use
187 /// drop_rotamers() instead.
188 void
190 {
191  assert( rot_id <= rotamers_.size() );
192  utility::vector1< conformation::ResidueOP > copy_rotamers( rotamers_.size() - 1, 0 );
193  Size count_copy( 1 );
194  for ( Size ii = 1; ii <= rotamers_.size(); ++ii ) {
195  if ( ii != rot_id ) {
196  copy_rotamers[ count_copy ] = rotamers_[ ii ];
197  if ( ii == id_for_current_rotamer_ ) {
198  id_for_current_rotamer_ = count_copy;
199  }
200  ++count_copy;
201  } else {
202  if ( ii == id_for_current_rotamer_ ) {
204  }
205  }
206  }
207  copy_rotamers.swap( rotamers_ );
210 
211 }
212 
213 /// @brief rotamers_to_delete must be of size nrotmaers -- each position
214 /// in the array that's "true" is removed from the set of rotamers
215 void
217 {
218  assert( rotamers_to_delete.size() == rotamers_.size() );
219 
220  Size n_dropped = 0;
221  for ( Size ii = 1; ii <= rotamers_.size(); ++ii ) {
222  if ( rotamers_to_delete[ ii ] ) {
223  /// if all rotamers end up dropped, then preserve the input rotamer.
224  if ( ii == id_for_current_rotamer_ ) {
226  }
227  rotamers_[ ii ] = 0;
228  ++n_dropped;
229  }
230  }
231  if ( n_dropped == 0 ) return;
232 
233  if ( n_dropped == rotamers_.size() ) {
234  if ( id_for_current_rotamer_ == 0 ) {
235  utility_exit_with_message( "ERROR:: RotamerSubset::drop_rotamers attempted to remove all rotamers without available input_rotamer." );
236  }
237  // keep the input rotamer.
238  rotamers_.resize( 1 );
242  } else {
243  utility::vector1< conformation::ResidueOP > new_rotamers( rotamers_to_delete.size() - n_dropped, 0 );
244  Size count_new = 1;
245  for ( Size ii = 1; ii <= rotamers_.size(); ++ii ) {
246  if ( rotamers_[ ii ] != 0 ) {
247  new_rotamers[ count_new ] = rotamers_[ ii ];
248  if ( ii == id_for_current_rotamer_ ) {
249  id_for_current_rotamer_ = count_new;
250  }
251  ++count_new;
252  }
253  }
254  new_rotamers.swap( rotamers_ );
255  }
258 }
259 
260 /// @brief deletes the rotamers in the list with the given indices.
261 /// The indices of these rotamers is presumed to be those before any delete operation.
262 /// e.g. if there are four rotamers, and rotamer_indices_to_delete includes 1 & 3,
263 /// then the rotamers that will remain are the rotamers originally indexed as 2 and 4,
264 /// even though their new indices will be 1 & 2.
265 void
267  utility::vector1< Size > const & rotamer_indices_to_delete
268 )
269 {
270  utility::vector1< bool > rotamers_to_delete( rotamers_.size(), false );
271  for ( Size ii = 1; ii <= rotamer_indices_to_delete.size(); ++ii ) {
272  rotamers_to_delete[ rotamer_indices_to_delete[ ii ] ] = true;
273  }
274  drop_rotamers( rotamers_to_delete );
275 }
276 
277 void
279 {
280  if ( n_residue_types_ == 0 ) {
283  return;
284  }
285 
286  if ( different_restype( rotamers_[ num_rotamers() ]->type(), restype )) {
288  }
289  if ( different_resgroup( rotamers_[ num_rotamers() ]->type(), restype )) {
291  }
292 }
293 
294 bool
296 {
297  return & rt1 != & rt2;
298 }
299 
300 /// @details The logic to determine if two residue types should be classified as part of the same group.
301 /// The thinking is as follows. Two residue types are in the same group if they have the same residue type.
302 /// They're in the same group if their residue types differ, but they have the same name3 (HIS vs HIS_D have
303 /// the same name3) and they have the same neighbor radius (SER and PhosphoSER should have different groups).
304 /// The goal is to organize residue types together which will be packed together (as happens in multistate design
305 /// with HIS and HISD) and that have the same reach (as is needed for the AANeighborSparseMatrix).
306 bool
308 {
309  return & rt1 != & rt2 && ( rt1.name3() != rt2.name3() || rt1.nbr_radius() != rt2.nbr_radius() );
310 }
311 
312 void
314 {
316  residue_type_rotamers_begin_.push_back( num_rotamers() + 1);
317  n_rotamers_for_restype_.push_back( 0 );
318 }
319 
320 void
322 {
324  residue_group_rotamers_begin_.push_back( num_rotamers() + 1 );
325  n_rotamers_for_resgroup_.push_back( 0 );
326 }
327 
328 void
330 {
331  rotamers_.push_back( rotamer );
334 }
335 
336 void
338 {
339  if ( ! rotamer_offsets_require_update_ ) return;
340 
341  if ( rotamers_.size() == 0 ) {
342  n_residue_types_ = 0;
343  n_residue_groups_ = 0;
344  residue_type_for_rotamers_.resize( 0 );
345  residue_group_for_rotamers_.resize( 0 );
346  residue_type_rotamers_begin_.resize( 0 );
347  residue_group_rotamers_begin_.resize( 0 );
348  n_rotamers_for_restype_.resize( 0 );
349  n_rotamers_for_resgroup_.resize( 0 );
350  return;
351  }
352 
353  /// From here forward, rotamers_.size() >= 1
354  residue_type_for_rotamers_.resize( rotamers_.size() );
355  residue_group_for_rotamers_.resize( rotamers_.size() );
356  n_residue_types_ = 1;
357  n_residue_groups_ = 1;
360  for ( Size ii = 2; ii <= rotamers_.size(); ++ii ) {
361  // compare addresses of the two types
362  // treat them as different amino acids only if they have different name3's
363  // or if they have different radii
364  //if ( & (rotamers_[ ii ]->type()) != & (rotamers_[ ii ]->type()) ) {
365  if ( different_restype( rotamers_[ ii ]->type(), rotamers_[ ii-1 ]->type() ) ) {
367  }
369 
370  if ( different_resgroup( rotamers_[ ii ]->type(), rotamers_[ ii-1 ]->type() ) ) {
372  }
374  }
375 
378  std::fill( residue_type_rotamers_begin_.begin(), residue_type_rotamers_begin_.end(), 0 );
379  std::fill( n_rotamers_for_restype_.begin(), n_rotamers_for_restype_.end(), 0 );
380 
383  std::fill( residue_group_rotamers_begin_.begin(), residue_group_rotamers_begin_.end(), 0 );
384  std::fill( n_rotamers_for_resgroup_.begin(), n_rotamers_for_resgroup_.end(), 0 );
385 
386  Size count_seen_residue_types( 1 );
387  Size count_seen_residue_groups( 1 );
388  n_rotamers_for_restype_[ count_seen_residue_types ] = 1;
389  n_rotamers_for_resgroup_[ count_seen_residue_groups ] = 1;
390  residue_type_rotamers_begin_[ count_seen_residue_types ] = 1;
391  residue_group_rotamers_begin_[ count_seen_residue_groups ] = 1;
392 
393  for ( Size ii = 2; ii <= rotamers_.size(); ++ii ) {
395  ++count_seen_residue_types;
396  residue_type_rotamers_begin_[ count_seen_residue_types ] = ii;
397  }
398  ++n_rotamers_for_restype_[ count_seen_residue_types ];
400  ++count_seen_residue_groups;
401  residue_group_rotamers_begin_[ count_seen_residue_groups ] = ii;
402  }
403  ++n_rotamers_for_resgroup_[ count_seen_residue_groups ];
404  }
405  //std::cout << "nrestypes " << n_residue_types_ << std::endl;
407 }
408 
409 void
411  pose::Pose const & ,
412  scoring::ScoreFunction const &,
413  task::PackerTask const &,
415  bool
416 )
417 {}
418 
419 void
421  RotamerSets const &,
422  pose::Pose const &,
423  scoring::ScoreFunction const &,
424  task::PackerTask const &,
426 )
427 {}
428 
429 void
431  pose::Pose const &,
432  scoring::ScoreFunction const &,
433  task::PackerTask const &,
436 ) const
437 {}
438 
439 void
441  pose::Pose const &,
442  scoring::ScoreFunction const &,
443  task::PackerTask const &,
446 ) const
447 {}
448 
449 
450 /// @brief declare that a new block of residue types has begun, and that new residues
451 /// are about to be pushed back.
452 //void
453 //RotamerSubset::declare_new_residue_type()
454 //{
455 // ++n_residue_types_;
456 // residue_type_rotamers_begin_.push_back( num_rotamers() + 1);
457 // n_rotamers_for_restype_.push_back( 0 );
458 //}
459 
460 /// @brief appends a rotamer to the list of rotamers, and increments the count
461 /// for the number of rotamers for the current value of n_residue_types.
462 //void
463 //RotamerSubset::push_back_rotamer( conformation::ResidueOP rotamer )
464 //{
465 // rotamers_.push_back( rotamer );
466 // residue_type_for_rotamers_.push_back( n_residue_types_ );
467 // ++n_rotamers_for_restype_[ n_residue_types_ ];
468 //}
469 
470 
473  rotamers_.push_back( rotamer );
474 }
475 
476 
477 } // rotamer_set
478 } // pack
479 } // core