Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CPDataCorrespondence.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/scoring/trie/trie.functions.hh
11 /// @brief
12 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
13 
14 // Unit Headers
16 
17 // Project Headers
21 
22 #include <utility/vector1.hh>
23 
24 
25 namespace core {
26 namespace scoring {
27 namespace trie {
28 
30 :
31  n_entries_( 0 ),
32  max_connpoints_for_residue_( 0 ),
33  has_pseudobonds_( false )
34 {}
35 
37 {
38  n_entries_ = nentries;
39  entry_2_resid_.resize( n_entries_ );
41  std::fill( entry_2_resid_.begin(), entry_2_resid_.end(), 0 );
43  std::fill( nconnections_for_entry_.begin(), nconnections_for_entry_.end(), 0 );
45 }
46 
48 {
49  assert( entry > 0 && entry <= n_entries_ );
50  entry_2_resid_[ entry ] = resid;
51 }
52 
54 {
55  assert( entry > 0 && entry <= n_entries_ );
56  assert( nconnections_for_entry_[ entry ] == 0 );// call this function at most once for input value of entry
57  nconnections_for_entry_[ entry ] = nconnections;
58  residue_connid_for_entry_connid_[ entry ].resize( nconnections );
59  std::fill(
60  residue_connid_for_entry_connid_[ entry ].begin(),
62  0
63  );
64  if ( max_connpoints_for_residue_ < nconnections ) {
65  max_connpoints_for_residue_ = nconnections;
66  }
67 }
68 
69 void CPDataCorrespondence::connid_for_entry_connpoint( Size entry, Size connpoint, Size residue_connid )
70 {
71  assert( entry > 0 && entry <= n_entries_ );
72  assert( connpoint > 0 && connpoint <= nconnections_for_entry_[ entry ] );
73  residue_connid_for_entry_connid_[ entry ][ connpoint ] = residue_connid;
74 }
75 
76 
78 {
79  return n_entries_;
80 }
81 
83 {
84  assert( entry > 0 && entry <= n_entries_ );
85  assert( entry_2_resid_[ entry ] != 0 );
86  return entry_2_resid_[ entry ];
87 }
88 
90 {
91  assert( entry > 0 && entry <= n_entries_ );
92  assert( nconnections_for_entry_[ entry ] != 0 );
93  return nconnections_for_entry_[ entry ];
94 }
95 
97 {
98  assert( entry > 0 && entry <= n_entries_ );
99  assert( connpoint > 0 && connpoint <= nconnections_for_entry_[ entry ] );
100  return residue_connid_for_entry_connid_[ entry ][ connpoint ];
101 }
102 
103 /// ASSUMPTION: Connection topology is consistent across all rotamers. Any bond found
104 /// on rotamer 1 is present on rotamer i. Any pseudobond on rotamer 1 is found on rotamer i.
107  conformation::RotamerSetBase const & rotset
108 )
109 {
110 
111  if ( rotset.num_rotamers() == 0 ) { CPDataCorrespondence cpdat; return cpdat; }
112  return create_cpdata_correspondence_for_rotamer( *rotset.rotamer( 1 ) );
113 }
114 
115 CPDataCorrespondence
117  conformation::Residue const & example_rotamer
118 )
119 {
120  using namespace conformation;
121 
122  Size n_connection_partners( 0 );
123  std::map< Size, Size > resid_2_connection_partner_id;
124  utility::vector1< Size > connection_partner_id_2_resid;
125  std::map< Size, std::map< Size, Size > > bonds_to_residues;
126  //// < other-resid < lr-conn-id, this-connid > >
127 
128  /// NOTE: the psuedobond collection on pseudobonded residues i and j are
129  /// the same objects; its safe to take pseudobonds in the order they appear
130  std::map< Size, utility::vector1< Size > > pseudobonds_to_residues;
131  /// < other-resid < this-connid > >
132 
133 
134  Size seqpos = example_rotamer.seqpos();
135  for ( Size ii = 1; ii <= example_rotamer.n_residue_connections(); ++ii ) {
136  if ( example_rotamer.connection_incomplete( ii ) ) continue;
137 
138  Size other_resid = example_rotamer.connected_residue_at_resconn( ii );
139  if ( resid_2_connection_partner_id.find( other_resid ) == resid_2_connection_partner_id.end() ) {
140  ++n_connection_partners;
141  resid_2_connection_partner_id[ other_resid ] = n_connection_partners;
142  connection_partner_id_2_resid.push_back( other_resid );
143  std::map< Size, Size > ii_connmap;
144 
145  /// CONVENTION sort residue connections by their order in the lower residue.
146  for ( Size jj = ii; jj <= example_rotamer.n_residue_connections(); ++jj ) {
147  if ( other_resid != example_rotamer.connected_residue_at_resconn( jj ) ) continue;
148  Size lower_res_connid = seqpos < other_resid ? jj : example_rotamer.connect_map( jj ).connid();
149  ii_connmap[ lower_res_connid ] = jj;
150  }
151  bonds_to_residues[ other_resid ] = ii_connmap;
152  }
153  }
154 
155  std::map< Size, PseudoBondCollectionCOP > const & pb_map( example_rotamer.pseudobonds());
156  for ( std::map< Size, PseudoBondCollectionCOP >::const_iterator
157  pbc_iter = pb_map.begin(), pbc_iter_end = pb_map.end();
158  pbc_iter != pbc_iter_end; ++pbc_iter ) {
159 
160  Size const other_resid = pbc_iter->first;
161  PseudoBondCollectionCOP pbs = pbc_iter->second;
162 
163  if ( resid_2_connection_partner_id.find( other_resid ) == resid_2_connection_partner_id.end() ) {
164  ++n_connection_partners;
165  resid_2_connection_partner_id[ other_resid ] = n_connection_partners;
166  connection_partner_id_2_resid.push_back( other_resid );
167  }
168 
169  utility::vector1< Size > pseudobond_connection_points( pbs->size(), 0 );
170  Size count = 0;
171  for ( PseudoBondCollection::PBIter pbiter = pbs->iter_begin(), pbiter_end = pbs->iter_end();
172  pbiter != pbiter_end; ++pbiter ) {
173  ++count;
174  PseudoBond pb = *pbiter;
175  /// leaving the comparison below as "<=" in case intra-residue pseudobonds are detected!
176  /// generally inappropriate for a trie but what-the-hey?
177  pseudobond_connection_points[ count ] = seqpos <= other_resid ? pb.lr_conn_id() : pb.ur_conn_id();
178  }
179  pseudobonds_to_residues[ other_resid ] = pseudobond_connection_points;
180  }
181 
182 /*
183  CPDataCorrespondence cpdata_map;
184  cpdata_map.n_entries( connections_to_residues_.size() );
185  for ( Size ii = 1; ii <= n_connection_partners; ++ii ) {
186  cpdata_map.resid_for_entry( ii, found_connections_other_resid[ ii ] );
187  cpdata_map.n_connpoints_for_entry( ii, n_connections_for_resid[ ii ] );
188 
189  utility::vector1< Size > const & ii_conns(
190  rotset.rotamer( found_connections_examplerots[ ii ] )->
191  connections_to_residue( found_connections_other_resid[ ii ] ) );
192 
193  for ( Size jj = 1; jj <= n_connections_for_resid[ ii ]; ++jj ) {
194  cpdata_map.connid_for_entry_connpoint( ii, jj, ii_conns[ jj ] );
195  }
196  }
197  return cpdata_map;
198  */
199 
200  CPDataCorrespondence cpdata_map;
201  cpdata_map.n_entries( n_connection_partners );
202  for ( Size ii = 1; ii <= n_connection_partners; ++ii ) {
203  Size const other_resid = connection_partner_id_2_resid[ ii ];
204  cpdata_map.resid_for_entry( ii, other_resid );
205 
206  Size ii_n_connpoints( 0 );
207  if ( bonds_to_residues.find( other_resid ) != bonds_to_residues.end() ) {
208  ii_n_connpoints = bonds_to_residues[ other_resid ].size();
209  }
210  if ( pseudobonds_to_residues.find( other_resid ) != pseudobonds_to_residues.end() ) {
211  ii_n_connpoints += pseudobonds_to_residues[ other_resid ].size();
212  }
213 
214  cpdata_map.n_connpoints_for_entry( ii, ii_n_connpoints );
215  Size count_connpoints( 0 );
216  /// First bonds
217  if ( bonds_to_residues.find( other_resid ) != bonds_to_residues.end() ) {
218  std::map< Size, Size > const & ii_connmap = bonds_to_residues[ other_resid ];
219  for ( std::map< Size, Size >::const_iterator
220  iter = ii_connmap.begin(), iter_end = ii_connmap.end();
221  iter != iter_end; ++iter ) {
222  cpdata_map.connid_for_entry_connpoint( ii, ++count_connpoints, iter->second );
223  }
224  }
225  /// Second pseudobonds.
226  if ( pseudobonds_to_residues.find( other_resid ) != pseudobonds_to_residues.end() ) {
227  utility::vector1< Size > const & ii_pbmap = pseudobonds_to_residues[ other_resid ];
229  iter = ii_pbmap.begin(), iter_end = ii_pbmap.end();
230  iter != iter_end; ++iter ) {
231  cpdata_map.connid_for_entry_connpoint( ii, ++count_connpoints, *iter );
232  }
233  cpdata_map.note_has_pseudobonds();
234  }
235 
236  }
237  return cpdata_map;
238 }
239 
240 } // namespace trie
241 } // namespace scoring
242 } // namespace core
243