Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DisulfideMatchingEnergyContainer.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 sw=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/scoring/disulfides/ConstraintsEnergyContainer.cc
11 /// @brief Constraints Energy Container class implementation
12 /// @author Spencer Bliven <blivens@u.washington.edu>
13 
14 // Unit headers
16 
17 // Package headers
19 
20 // Project headers
26 #include <core/pose/Pose.hh>
27 #include <basic/Tracer.hh>
28 
29 // STL Headers
30 #include <cassert>
31 
33 #include <utility/vector1.hh>
34 
35 
36 namespace core {
37 namespace scoring {
38 namespace disulfides {
39 
40 static basic::Tracer TR("core.scoring.disulfides.DisulfideMatchingEnergyContainer");
41 
42 /// @brief constructor
45  Size focused_residue,
46  Size disulfide_index
47  ) :
48  owner_( owner ),
49  focused_residue_( focused_residue ),
50  disulfide_index_( disulfide_index )
51 {}
52 
53 /// @brief constructor, default to no disulfide bond
56  )
57 :
58  owner_( owner ),
59  focused_residue_( DisulfideMatchingEnergyContainer::NO_DISULFIDE ),
60  disulfide_index_( DisulfideMatchingEnergyContainer::NO_DISULFIDE )
61 {}
62 
64 {}
65 
66 /// @brief Assignment
69 {
70  assert( &(dynamic_cast< DisulfideMatchingNeighborIterator const & > ( rhs )) );
71  DisulfideMatchingNeighborIterator const & drni_rhs = static_cast< DisulfideMatchingNeighborIterator const & > ( rhs );
72 
73  owner_ = drni_rhs.owner_;
76  return *this;
77 }
78 
79 /// @note Incrementing an iterator in a list with exactly one element moves that
80 /// iterator off the end of the list.
83 {
87  return *this;
88 }
89 
90 bool
92 {
93  assert( &( dynamic_cast< DisulfideMatchingNeighborIterator const & > ( rhs )) );
94  DisulfideMatchingNeighborIterator const & drni_rhs = static_cast< DisulfideMatchingNeighborIterator const & > ( rhs );
95 
96  return ( owner_ == drni_rhs.owner_ &&
97  focused_residue_ == drni_rhs.focused_residue_ &&
98  disulfide_index_ == drni_rhs.disulfide_index_ );
99 }
100 
101 bool
103 {
104  assert( &( dynamic_cast< DisulfideMatchingNeighborIterator const & > ( rhs )) );
105  DisulfideMatchingNeighborIterator const & drni_rhs = static_cast< DisulfideMatchingNeighborIterator const & > ( rhs );
106  return ( owner_ != drni_rhs.owner_ ||
107  focused_residue_ != drni_rhs.focused_residue_ ||
108  disulfide_index_ != drni_rhs.disulfide_index_ );
109 }
110 
111 /// @brief Get the higher-numbered residue for this disulfide bond
112 Size
114 {
116  return owner_->upper_neighbor_id( disulfide_index_ );
117 }
118 
119 /// @brief Get the lower-numbered residue for this disulfide bond
120 Size
122 {
124  return owner_->lower_neighbor_id( disulfide_index_ );
125 }
126 
127 /// @brief Which residue are we looking for disulfide bonds to?
128 Size
130 {
131  return focused_residue_;
132 }
133 
134 /// @brief Which residue is disulfide bonded to the current residue?
135 Size
137 {
138  return owner_->other_neighbor_id( disulfide_index_, focused_residue_ );
139 }
140 
141 /// @brief Save the specified energies for this disulfide to the
142 /// DisulfideMatchingEnergyContainer associated with this iterator.
143 void
145 {
147  owner_->save_energy( disulfide_index_, emap );
148 }
149 
150 /// @brief Get the energies for the current disulfide bond from the
151 /// DisulfideMatchingEnergyContainer associated with this iterator.
152 void
154 {
156  owner_->retrieve_energy( disulfide_index_, emap );
157 }
158 
159 /// @brief Add some energies to the totals already in DisulfideMatchingEnergyContainer
160 void
162 {
164  owner_->accumulate_energy( disulfide_index_, emap );
165 }
166 
168 {
170  owner_->mark_energy_computed( disulfide_index_ );
171 }
172 
174 {
176  owner_->mark_energy_uncomputed( disulfide_index_ );
177 }
178 
179 
180 bool
182 {
184  return owner_->energy_computed( disulfide_index_ );
185 }
186 
187 ////////////////////////////////////////////////////////////////////////
188 ///// Disulfide Residue Neighbor Constant Iterator class implementation
189 ////////////////////////////////////////////////////////////////////////
190 
193  Size focused_residue,
194  Size disulfide_index
195  ) :
196  owner_( owner ),
197  focused_residue_( focused_residue ),
198  disulfide_index_( disulfide_index )
199 {}
200 
203  ) :
204  owner_( owner ),
205  focused_residue_( DisulfideMatchingEnergyContainer::NO_DISULFIDE ),
206  disulfide_index_( DisulfideMatchingEnergyContainer::NO_DISULFIDE )
207 {}
208 
210 {}
211 
214 {
215  assert( &(dynamic_cast< DisulfideMatchingNeighborConstIterator const & > ( rhs )) );
216  DisulfideMatchingNeighborConstIterator const & drni_rhs = static_cast< DisulfideMatchingNeighborConstIterator const & > ( rhs );
217 
218  owner_ = drni_rhs.owner_;
221  return *this;
222 
223 }
224 
227 {
231  return *this;
232 }
233 
234 /// @brief returns true if the two edge-list iterators are equal
235 bool
237 {
238  assert( &( dynamic_cast< DisulfideMatchingNeighborConstIterator const & > ( rhs )) );
239  DisulfideMatchingNeighborConstIterator const & drni_rhs = static_cast< DisulfideMatchingNeighborConstIterator const & > ( rhs );
240 
241  return ( owner_ == drni_rhs.owner_ &&
242  focused_residue_ == drni_rhs.focused_residue_ &&
243  disulfide_index_ == drni_rhs.disulfide_index_ );
244 }
245 
246 
247 /// @brief returns true if the two edge-list iterators are not equal
248 bool
250 {
251  assert( &( dynamic_cast< DisulfideMatchingNeighborConstIterator const & > ( rhs )) );
252  DisulfideMatchingNeighborConstIterator const & drni_rhs = static_cast< DisulfideMatchingNeighborConstIterator const & > ( rhs );
253  return ( owner_ != drni_rhs.owner_ ||
254  focused_residue_ != drni_rhs.focused_residue_ ||
255  disulfide_index_ != drni_rhs.disulfide_index_ );
256 }
257 
258 Size
260 {
262  return owner_->upper_neighbor_id( disulfide_index_ );
263 }
264 
265 Size
267 {
269  return owner_->lower_neighbor_id( disulfide_index_ );
270 }
271 
272 
273 Size
275 {
276  return focused_residue_;
277 }
278 
279 Size
281 {
282  return owner_->other_neighbor_id( disulfide_index_, focused_residue_ );
283 }
284 
285 /// @brief overwrites the three constraint-energy positions in the emap with
286 /// the three contraint energies stored on the edge pointed to by the edge iter.
287 /// Does not zero out the other positions in the emap.
288 void
290 {
292  owner_->retrieve_energy( disulfide_index_, emap );
293 }
294 
295 /// @brief accumulates the three constraint-energy positions in the emap with
296 /// the three contraint energies stored on the edge pointed to by the edge iter.
297 /// Does not touch the other positions in the emap.
298 void
300 {
302  owner_->accumulate_energy( disulfide_index_, emap );
303 }
304 
305 bool
307 {
309  return owner_->energy_computed( disulfide_index_ );
310 }
311 
312 
313 /////////////////////////////////////////////////////
314 /// Disulfide Energy Container Class Implementation
315 /////////////////////////////////////////////////////
316 
318 
319 
321 {}
322 
323 bool
325 {
326  return num_disulfides() == 0;
327 }
328 
329 
331 {
332  find_disulfides( pose );
333 }
334 
335 void
337 {
338  if ( disulfides_changed( pose ) ) find_disulfides( pose );
339 }
340 
342 {}
343 
346 {
348  if ( !empty() ) {
349  dec->disulfide_atom_indices_ = disulfide_atom_indices_;
350  dec->disulfide_residue_types_ = disulfide_residue_types_;
351  dec->resid_2_disulfide_index_ = resid_2_disulfide_index_;
352  dec->disulfide_partners_ = disulfide_partners_;
353  dec->disulfide_info_ = disulfide_info_;
354  }
355  return dec;
356 }
357 
360 {
361  assert( !empty() );
362  if ( resid_2_disulfide_index_[ resid ] != NO_DISULFIDE ) {
363  return new DisulfideMatchingNeighborConstIterator( this, resid, resid_2_disulfide_index_[ resid ] );
364  }
365  else {
366  return new DisulfideMatchingNeighborConstIterator( this );
367  }
368 }
369 
372 {
373  assert( !empty() );
374  return new DisulfideMatchingNeighborConstIterator( this );
375 }
376 
379 {
380  assert( !empty() );
381  if ( resid_2_disulfide_index_[ resid ] != NO_DISULFIDE &&
382  (Size) resid < other_neighbor_id( resid_2_disulfide_index_[ resid ], resid ) ) {
383  return new DisulfideMatchingNeighborConstIterator( this, resid, resid_2_disulfide_index_[ resid ] );
384  }
385  else {
386  return new DisulfideMatchingNeighborConstIterator( this );
387  }
388 }
389 
392 {
393  assert( !empty() );
394  return new DisulfideMatchingNeighborConstIterator( this );
395 }
396 
399 {
400  assert( !empty() );
401  if ( resid_2_disulfide_index_[ resid ] != NO_DISULFIDE ) {
402  return new DisulfideMatchingNeighborIterator( this, resid, resid_2_disulfide_index_[ resid ] );
403  }
404  else {
405  return new DisulfideMatchingNeighborIterator( this );
406  }
407 }
408 
411 {
412  assert( !empty() );
413  return new DisulfideMatchingNeighborIterator( this );
414 }
415 
418 {
419  if ( resid_2_disulfide_index_[ resid ] != NO_DISULFIDE &&
420  (Size) resid < other_neighbor_id( resid_2_disulfide_index_[ resid ], resid ) ) {
421  return new DisulfideMatchingNeighborIterator( this, resid, resid_2_disulfide_index_[ resid ] );
422  }
423  else {
424  return new DisulfideMatchingNeighborIterator( this );
425  }
426 }
427 
430 {
431  assert( !empty() );
432  return new DisulfideMatchingNeighborIterator( this );
433 }
434 
435 bool
437 {
438  if ( empty() ) return false;
439  return resid_2_disulfide_index_[ res1id ] != NO_DISULFIDE &&
440  resid_2_disulfide_index_[ res2id ] != NO_DISULFIDE &&
441  resid_2_disulfide_index_[ res1id ] == resid_2_disulfide_index_[ res2id ];
442 }
443 
444 bool
446 {
447  if ( empty() ) return false;
448  return resid_2_disulfide_index_[ resid ] != NO_DISULFIDE;
449 }
450 
451 Size
453 {
454  return other_neighbor_id( resid_2_disulfide_index_[ resid ], resid );
455 }
456 
457 
458 // Mutators
459 void
461 {
462  disulfide_info_[ disulfide_index ].first.dslfc_rot() = emap[ dslfc_rot ];
463  disulfide_info_[ disulfide_index ].first.dslfc_trans() = emap[ dslfc_trans ];
464  disulfide_info_[ disulfide_index ].first.dslfc_RT() = emap[ dslfc_RT ];
465 }
466 
467 void
469 {
470  disulfide_info_[ disulfide_index ].second = true;
471 }
472 
473 void
475 {
476  disulfide_info_[ disulfide_index ].second = false;
477 }
478 
479 // Accessors
481 {
482  return disulfide_partners_[ disulfide_index ].first;
483 }
484 
486 {
487  return disulfide_partners_[ disulfide_index ].second;
488 }
489 
491 {
492  assert( disulfide_partners_[ disulfide_index ].first == resid ||
493  disulfide_partners_[ disulfide_index ].second == resid );
494  return ( resid == disulfide_partners_[ disulfide_index ].first ?
495  disulfide_partners_[ disulfide_index ].second :
496  disulfide_partners_[ disulfide_index ].first );
497 }
498 
499 DisulfideAtomIndices const &
501 {
502  Size const disulfide_index( resid_2_disulfide_index_[ resid ] );
503  assert( disulfide_index != NO_DISULFIDE );
504  assert( disulfide_partners_[ disulfide_index ].first == resid ||
505  disulfide_partners_[ disulfide_index ].second == resid );
506  return ( resid == disulfide_partners_[ disulfide_index ].first ?
507  disulfide_atom_indices_[ disulfide_index ].first :
508  disulfide_atom_indices_[ disulfide_index ].second );
509 }
510 
511 
512 DisulfideAtomIndices const &
514 {
515  Size const disulfide_index( resid_2_disulfide_index_[ resid ] );
516  assert( disulfide_index != NO_DISULFIDE );
517  assert( disulfide_partners_[ disulfide_index ].first == resid ||
518  disulfide_partners_[ disulfide_index ].second == resid );
519  return ( resid == disulfide_partners_[ disulfide_index ].first ?
520  disulfide_atom_indices_[ disulfide_index ].second :
521  disulfide_atom_indices_[ disulfide_index ].first );
522 }
523 
524 
526 {
527  emap[ dslfc_rot ] += disulfide_info_[ disulfide_index ].first.dslfc_rot();
528  emap[ dslfc_trans ] += disulfide_info_[ disulfide_index ].first.dslfc_trans();
529  emap[ dslfc_RT ] += disulfide_info_[ disulfide_index ].first.dslfc_RT();
530 }
531 
533 {
534  emap[ dslfc_rot ] = disulfide_info_[ disulfide_index ].first.dslfc_rot();
535  emap[ dslfc_trans ] = disulfide_info_[ disulfide_index ].first.dslfc_trans();
536  emap[ dslfc_RT ] = disulfide_info_[ disulfide_index ].first.dslfc_RT();
537 }
538 
540 {
541  return disulfide_info_[ disulfide_index ].second;
542 }
543 
544 
545 void
547 {
548  TR.Debug << "In find_disulfides():" << std::endl;
549 
550  disulfide_partners_.clear();
551  disulfide_atom_indices_.clear();
552  disulfide_info_.clear();
553  resid_2_disulfide_index_.resize( pose.total_residue() );
554  disulfide_residue_types_.resize( pose.total_residue() );
557 
558  Size count_disulfides( 0 );
559  for ( Size ii = 1; ii <= pose.total_residue(); ++ii ) {
560  conformation::Residue res = pose.residue( ii );
561  if ( res.aa() == chemical::aa_cys &&
564  ( pose.residue_type( ii ).has_atom_name( "CEN" ) || pose.residue_type( ii ).has_atom_name( "SG" ) )
565  ) {
566  ++count_disulfides;
567 
568  //Centroid models are bonded CEN to CEN, fullatom are bonded SG to SG.
569  //This code originally forgot to put the whole SG bit in so maybe this is a hack. I don't care!
570  // -rv
571  Size ii_connect_atom(0);
572  if ( pose.residue_type( ii ).has_atom_name( "CEN" ) ) {
573  ii_connect_atom = res.atom_index( "CEN" );
574  } else {
575  ii_connect_atom = res.atom_index( "SG" );
576  }
577 
578  Size other_res_ii( 0 );
579  for ( Size jj = 1; jj <= res.type().n_residue_connections(); ++jj ) {
580  if ( (Size) res.type().residue_connection( jj ).atomno() == ii_connect_atom ) {
581  other_res_ii = res.connect_map( jj ).resid();
582  break;
583  }
584  }
585  if ( other_res_ii == 0 ) {
586  TR.Error << "ERROR: Could not find disulfide partner for residue " << ii << std::endl;
587  utility_exit();
588  }
589  assert( other_res_ii > ii );
590  //Can only bond residues of the same residue type set (eg centroid to centroid)
591  assert( pose.residue_type(other_res_ii).residue_type_set().name() ==
592  pose.residue_type(ii).residue_type_set().name() );
593 
594  TR.Debug << "Found disulf between " << ii << " and " << other_res_ii << std::endl;
595 
596  resid_2_disulfide_index_[ ii ] = count_disulfides;
597  resid_2_disulfide_index_[ other_res_ii ] = count_disulfides;
598  disulfide_residue_types_[ ii ] = & ( pose.residue_type( ii ));
599  disulfide_residue_types_[ other_res_ii ] = chemical::ResidueTypeCOP( & ( pose.residue_type( other_res_ii )));
600  disulfide_partners_.push_back( std::pair< Size, Size >( ii, other_res_ii ) );
601  disulfide_atom_indices_.push_back( std::pair< DisulfideAtomIndices, DisulfideAtomIndices > (
602  DisulfideAtomIndices( pose.residue(ii ) ), DisulfideAtomIndices( pose.residue( other_res_ii ) ) ));
604  disulfide_info_.push_back( std::pair< DisulfideMatchingEnergyComponents, bool > ( temp, false ) );
605 
606  assert(! empty());
607  }
608  }
609  TR.Debug << "Found " << num_disulfides() << " DS" << std::endl;
610 }
611 
612 // we could do something like keep a flag for when minimization is occurring and assume that
613 // disulfide connectivity information does not change during the course of minimization...
614 bool
616 {
617  Size const total_residue( pose.total_residue() );
618  if ( resid_2_disulfide_index_.size() != total_residue ) return true;
619 
620  for ( Size ii = 1; ii <= total_residue; ++ii ) {
621  if ( resid_2_disulfide_index_[ ii ] != NO_DISULFIDE ) {
622  conformation::Residue res = pose.residue( ii );
623  if ( res.aa() != chemical::aa_cys ||
624  disulfide_residue_types_[ ii ]() != & (pose.residue_type( ii )) ||
625  /// subsumed by residue type check ! pose.residue( ii ).has_variant_type( chemical::DISULFIDE ) ||
626  ! pose.residue_type( ii ).has_atom_name( "CEN" ) || // not centroid
627  res.connect_map(
629  res.atom_index( "CEN" ) ) ).resid() !=
631  return true;
632  }
633  } else if ( pose.residue( ii ).aa() == chemical::aa_cys &&
635  return true;
636  }
637  }
638  return false;
639 }
640 
642 {
643  return disulfide_partners_.size();
644 }
645 
646 
647 }
648 }
649 }
650