Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Sheet.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 // This file is part of the Rosetta software suite and is made available under license.
5 // The Rosetta software is developed by the contributing members of the Rosetta Commons consortium.
6 // Copyright in the Rosetta software belongs to the developers and their institutions.
7 // For more information, see www.rosettacommons.org.
8 
9 /// @file ./src/protocols/fldsgn/topology/Sheet.cc
10 /// @brief
11 /// @author Nobuyasu Koga ( nobuyasu@u.washington.edu )
12 
13 // unit headers
15 
16 // Project headers
17 #include <basic/Tracer.hh>
21 
22 #include <core/id/AtomID_Map.hh>
23 #include <core/scoring/sasa.hh>
24 #include <core/pose/util.hh>
25 
26 // utility headers
27 #include <utility/exit.hh>
28 
29 // C++ headers
30 #include <iostream>
31 #include <map>
32 // AUTO-REMOVED #include <numeric/conversions.hh>
33 
34 #include <utility/vector1.hh>
35 #include <utility/options/IntegerVectorOption.hh>
36 
37 //Auto Headers
38 #include <core/pose/util.tmpl.hh>
39 
40 #include <numeric/NumericTraits.hh>
41 
42 static basic::Tracer TR( "protocols.topology.Sheet" );
43 
44 using namespace core;
45 
46 namespace protocols {
47 namespace fldsgn {
48 namespace topology {
49 
50 /// @details Auto-generated virtual destructor
51 SheetSet::~SheetSet() {}
52 
53 
54 /// @brief default constructor
55 Sheet::Sheet() :
56  num_strands_( 0 ),
57  is_barrel_( false ),
58  is_geometry_initialized_( false )
59 {
60  initialize();
61 }
62 
63 /// @brief value constructor
64 Sheet::Sheet( VecSize const & order_strands, VecInt const & orient_strands, bool is_barrel ):
65  num_strands_( order_strands.size() ),
66  is_barrel_( is_barrel ),
67  order_strands_( order_strands ),
68  orient_strands_( orient_strands ),
69  is_geometry_initialized_( false )
70 {
71  runtime_assert( order_strands.size() == orient_strands.size() );
72  initialize();
73 }
74 
75 /// @brief copy constructor
76 Sheet::Sheet( Sheet const & s ):
77  ReferenceCount(),
78  num_strands_( s.num_strands_ ),
79  is_barrel_( s.is_barrel_ ),
80  order_strands_( s.order_strands_ ),
81  orient_strands_( s.orient_strands_ ),
82  strand_order_( s.strand_order_ ),
83  sheet_plane_( s.sheet_plane_ ),
84  sheet_center_( s.sheet_center_ ),
85  ca_cb_orients_( s.ca_cb_orients_ ),
86  is_geometry_initialized_( s.is_geometry_initialized_ )
87 {}
88 
89 /// @brief initialize this class
90 void
92 {
94  for( Size i=1; i<=order_strands_.size(); i++ ){
95  strand_order_.insert( std::map< Size, Size >::value_type( order_strands_[i], i ) );
96  }
97 }
98 
99 /// @brief default destructor
101 
102 
103 /// @brief return strand pairing
104 std::ostream & operator<<( std::ostream & out, const Sheet &s )
105 {
107  utility::vector1<Real> const orient( s.orient_strands() );
108 
109  for( Size i=1; i<= order.size(); i++ ){
110  out << "#Strand " << i << ": " << order[ i ] << "," << orient[ i ] << std::endl;;
111  }
112  return out;
113 }
114 
115 /// @brief whether the given strand number belongs to this sheet or not
116 bool
118 {
120  iter_end = order_strands_.end(); iter != iter_end; ++iter ) {
121  if( s == *iter ){
122  return true;
123  }
124  }
125  return false;
126 }
127 
128 /// @brief calc surface areas only with beta-sheet
130 Sheet::calc_sasa_bothsides( Pose const & pose, SS_Info2_COP const ssinfo, Real pore_radius )
131 {
132  runtime_assert( is_geometry_initialized_ );
133 
134  utility::vector1< Real > surfaces( 2, 0.0 );
135 
136  // define atom_map for main-chain and CB
138  core::pose::initialize_atomid_map( atom_map, pose, false );
139  protocols::fldsgn::topology::Strands const strands( ssinfo->strands() );
140  for( Size ii=1; ii<=order_strands_.size(); ++ii ) {
141  Size const st( order_strands_[ ii ] );
142 
143  Size begin( strands[ st ]->begin() );
144  Size end( strands[ st ]->end() );
145 
146  if( begin == 1 ) begin = 2;
147  if( end == pose.total_residue() ) end = pose.total_residue() - 1;
148 
149  for( Size ir=begin-1; ir<=end+1; ir++ ) {
150  for ( Size j = 1; j<=5; ++j ) {
151  core::id::AtomID atom( j, ir );
152  atom_map.set( atom, true );
153  }
154  }
155  }
156 
157  // calc sasa
159  utility::vector1< Real > rsd_sasa;
160  core::scoring::calc_per_atom_sasa( pose, atom_sasa, rsd_sasa, pore_radius, false, atom_map );
161 
162  for ( Size iaa=2; iaa<=pose.total_residue()-1; iaa++ ) {
163 
164  if( ca_cb_orient( iaa ) == 1 ) {
165  surfaces[ 1 ] += rsd_sasa[ iaa ];
166  } else if( ca_cb_orient( iaa ) == -1 ) {
167  surfaces[ 2 ] += rsd_sasa[ iaa ];
168  }
169  // std::cout << iaa << " " << ca_cb_orient(iaa) << " " << rsd_sasa[ iaa ] << std::endl;
170  }
171  // std::cout << surfaces[ 1 ] << " " << surfaces[ 2 ] << std::endl;
172 
173  return surfaces;
174 }
175 
176 /// @brief calc geometry
177 void
179 {
180  runtime_assert( ssinfo->bbpos_is_set() );
181 
182  if( num_strands_ == 0 ) {
183  return;
184  }
185 
186  protocols::fldsgn::topology::Strands const strands( ssinfo->strands() );
187 
188  Vector const v1 = ( strands[ order_strands_[ num_strands_ ] ]->mid_pos() -
189  strands[ order_strands_[ 1 ] ]->mid_pos() ).normalized();
190 
191 
192  Vector v2( strands[ order_strands_[ 1 ] ]->orient() );
193  for( Size ii=2; ii<=num_strands_; ii++ ) {
194  Real sign( 1.0 );
195  if( orient_strands_[ 1 ] != orient_strands_[ ii ] ) {
196  sign = - 1.0;
197  }
198  v2 += sign*strands[ order_strands_[ ii ] ]->orient();
199  }
200 
201  sheet_plane_ = v1.cross( v2.normalized() );
202 
203  sheet_center_.clear();
204  for( Size ii=1; ii<=num_strands_; ii++ ) {
205  sheet_center_ += strands[ ii ]->mid_pos();
206  }
208 
209  protocols::fldsgn::topology::BB_Pos const bb_pos( ssinfo->bb_pos() );
210  ca_cb_orients_.resize( bb_pos.size() );
211  for( Size ii=1; ii<=bb_pos.size(); ii++ ) {
212  ca_cb_orients_[ ii ] = 0;
213  }
214 
215  Real half_pi = numeric::NumericTraits<Real>::pi()/2.0;
217  anchor.resize( strands.size(), 0 );
218  for( Size ii=1; ii<=order_strands_.size(); ii++ ) {
219 
220  Size const st( order_strands_[ ii ] );
221  Size const begin( strands[ st ]->begin() );
222  Size const end( strands[ st ]->end() );
223  anchor[ st ] = begin;
224 
225  Vector cacb = bb_pos.CB( begin ) - bb_pos.CA( begin );
226  Real max_angle = fabs( half_pi - angle_of( sheet_plane_, cacb ) );
227 
228  for( Size jj=begin+1; jj<=end; jj++ ) {
229  cacb = bb_pos.CB( jj ) - bb_pos.CA( jj );
230  Real angle = fabs( half_pi - angle_of( sheet_plane_, cacb ) );
231  if( max_angle < angle ) {
232  anchor[ st ] = jj;
233  max_angle = angle;
234  }
235  }
236  }
237 
238 
239  for( Size ii=1; ii<=order_strands_.size(); ++ii ) {
240 
241  Size const st( order_strands_[ ii ] );
242  Size const begin( strands[ st ]->begin() );
243  Size const end( strands[ st ]->end() );
244 
245  Vector const cacb = bb_pos.CB( anchor[ st ] ) - bb_pos.CA( anchor[ st ] );
246  if( cacb.dot( sheet_plane_ ) > 0 ) {
247  ca_cb_orients_[ anchor[ st ] ] = 1;
248  } else {
249  ca_cb_orients_[ anchor[ st ] ] = -1;
250  }
251 
252  for( Size jj=anchor[ st ]; jj>=begin+1; --jj ) {
253  Real dot = ( bb_pos.CB( jj ) - bb_pos.CA( jj ) ).dot( bb_pos.CB( jj-1 ) - bb_pos.CA( jj-1 ) );
254  if( dot > 0 ) {
255  ca_cb_orients_[ jj-1 ] = ca_cb_orients_[ jj ];
256  } else {
257  ca_cb_orients_[ jj-1 ] = -1 * ca_cb_orients_[ jj ];
258  }
259  }
260 
261  for( Size jj=anchor[ st ]; jj<=end-1; ++jj ) {
262  Real dot = ( bb_pos.CB( jj ) - bb_pos.CA( jj ) ).dot( bb_pos.CB( jj+1 ) - bb_pos.CA( jj+1 ) );
263  if( dot > 0 ) {
264  ca_cb_orients_[ jj+1 ] = ca_cb_orients_[ jj ];
265  } else {
266  ca_cb_orients_[ jj+1 ] = -1 * ca_cb_orients_[ jj ];
267  }
268  }
269 
270  }
271 
272 // for debug
273 // for( Size ii=1; ii<=order_strands_.size(); ++ii ) {
274 // Size const st( order_strands_[ ii ] );
275 // Size const begin( strands[ st ]->begin() );
276 // Size const end( strands[ st ]->end() );
277 // for( Size jj=begin; jj<=end; jj++ ) {
278 // std::cout << jj << " " << ca_cb_orients_[ jj ] << std::endl;
279 // }
280 //}
281 
283 }
284 
285 /// @brief
286 int
287 Sheet::which_side( Vector const vec ) const
288 {
289  Real dot = sheet_plane_.dot( vec - sheet_center_ );
290  if ( dot > 0 ) {
291  return 1;
292  } else {
293  return -1;
294  }
295 }
296 
297 
298 /////////////////////////////////////////////////////////////////////////////////////////////
299 /// @brief default constructor
301 {}
302 
303 /// @brief value constructor
304 SheetSet::SheetSet( Sheets const & sheets ):
305  sheets_( sheets )
306 {}
307 
308 /// @brief value constructor
309 SheetSet::SheetSet( SS_Info2_COP const ssinfo, StrandPairingSetCOP const spairset )
310 {
311  initialize( ssinfo, spairset );
312 }
313 
314 /// @brief copy constructor
316  ReferenceCount(),
317  sheets_( s.sheets_ )
318 {}
319 
320 /// @brief return strand pairing
321 std::ostream & operator<<( std::ostream & out, const SheetSet &s )
322 {
323  out << "#### Sheet Info " << std::endl;
324  for( Size i=1; i<=s.num_sheets() ; i++ ){
325  SheetCOP sop ( s.sheet( i ) );
326  if( sop->is_barrel() ){
327  out << "## Barrel " << i << ":" << std::endl;
328  }else{
329  out << "## Sheet " << i << ":" << std::endl;
330  }
331  out << (*sop);
332  }
333  return out;
334 }
335 
336 /// @brief
337 void
339 {
340  sheets_.push_back( sop );
341 }
342 
343 /// @brief
345 {
346  sheets_.clear();
347 }
348 
349 /// @brief
350 SheetOP
351 SheetSet::sheet( Size const s ) const
352 {
353  runtime_assert( s <= sheets_.size() );
354  return sheets_[ s ];
355 }
356 
357 /// @brief return a sheet number given a strand number
358 Size
359 SheetSet::which_sheet( Size const s ) const
360 {
361 
362  if( s == 0 ) return 0;
363  return sheet_number_[ s ];
364 }
365 
366 /// @brief return strand pairing set
369 {
370  return spairset_;
371 }
372 
373 /// @brief
374 void
376 {
377  for( Size i=1; i<=sheets_.size(); i++ ){
378  SheetCOP const sheet ( sheets_[ i ] );
379  VecSize const & order ( sheet->order_strands() );
380  for( VecSize::const_iterator it=order.begin(), ite=order.end(); it!=ite; ++it ){
381  sheet_number_[ *it ] = i;
382  }
383  }
384 }
385 
386 /// @brief
387 void
389 {
390  for( Size i=1; i<=sheets_.size(); i++ ){
391  sheets_[ i ]->calc_geometry( ssinfo );
392  }
393 }
394 
395 /// @brief
396 void
397 SheetSet::initialize( SS_Info2_COP const ssinfo, StrandPairingSetCOP const spairset_in )
398 {
402 
403  // initialize sheet_number_
404  for( Size i=1; i<=ssinfo->strands().size(); i++ ) {
405  sheet_number_.insert( std::map< Size, Size >::value_type( i, 0 ) );
406  }
407 
408  // do nothing if strand pairs < 2
409  if( spairset_in->num_strands() < 2 ) {
410  return;
411  }
412 
413  spairset_ = *( spairset_in->clone() );
415 
416  runtime_assert( spairset_.finalized() );
417 
418  // strand pairings
420 
421  // number of strands included in spairset
422  // Size num_strands = spairset.num_strands();
423 
424  // set neighbor strands and sheet_set
425  DisjointSets sheet_set( ssinfo->strands().size() );
426  for( StrandPairings::const_iterator iter = spairs.begin(); iter != spairs.end(); ++iter ) {
427  StrandPairing const & sp( **iter );
428  sheet_set.ds_union( sp.s1(), sp.s2() );
429  }
430 
431  // calc order of strands
432  std::map< Size, VecSize > sset = sheet_set.sets();
433  std::map< Size, VecSize >::iterator it = sset.begin();
434  while( it != sset.end() ) {
435 
436  bool ibarrel (true);
437  VecSize order_strands;
438 
439  VecSize list_strands = (*it).second;
440  if( list_strands.size() <= 1 ) {
441  it++;
442  continue;
443  }
444 
445  for( VecSize::const_iterator itt = list_strands.begin(); itt != list_strands.end(); ++itt ) {
446  Size s( *itt );
447  if( spairset_.neighbor_strands( s ).size() == 1 ) {
448  order_strands.push_back( s );
449  ibarrel = false;
450  } else if( spairset_.neighbor_strands( s ).size() > 2 ) {
451  TR.Error << "Error, num of neighbor strands > 2 " << std::endl;
452  runtime_assert( false );
453  }
454  }
455 
456  if( ibarrel ){
457  order_strands.push_back( list_strands.front() );
458  }else{
459  runtime_assert( order_strands.size() == 2 );
460  sort ( order_strands.begin(), order_strands.end() );
461  order_strands.erase( order_strands.end() - 1 );
462  }
463 
464  VecSize const & neighbor ( spairset_.neighbor_strands( order_strands.front() ) );
465  if( ibarrel ) {
466  if( neighbor[1] < neighbor[2] ) {
467  order_strands.insert( order_strands.begin() + 1, neighbor[1] );
468  } else {
469  order_strands.insert( order_strands.begin() + 1, neighbor[2] );
470  }
471  } else {
472  order_strands.insert( order_strands.begin() + 1, neighbor[1] );
473  }
474 
475 
476  for( Size i=2; i<= list_strands.size()-1; i++ ){
477  Size s1 = order_strands[ i ];
478  VecSize const & neighbor( spairset_.neighbor_strands( s1 ) );
479 
480  for( Size j=1; j<=neighbor.size(); j++ ){
481  if( neighbor[ j ] != order_strands[ i-1 ] ){
482  order_strands.insert( order_strands.begin() + i, neighbor[j] );
483  }
484  }
485  }
486 
487  // set orient of strands in sheet
488  VecInt orient_strands; // Sergey: was declared as 'VecReal' seems to be a typo, converting to VecInt to fix wanrning
489  orient_strands.push_back( 1 );
490  for( Size i=1; i<=order_strands.size()-1; i++ ){
491  Size s1( order_strands[ i ] );
492  Size s2( order_strands[ i+1 ] );
493  StrandPairingCOP const spairop( spairset_.strand_pairing( s1, s2 ) );
494 
495  if( spairop->orient() == 'P' ){
496  orient_strands.push_back( orient_strands[ i ] );
497  }else{
498  orient_strands.push_back( orient_strands[ i ]*-1 );
499  }
500  }
501 
502  SheetOP sop = new Sheet( order_strands, orient_strands, ibarrel );
503  sheets_.push_back( sop );
504 
505  ++it;
506 
507  } // while( it !=sset.end() )
508 
510 
511 } // SheetTopology::calc_sheetset
512 
513 
514 
515 } // namespace topology
516 } // namespace fldsgn
517 } // namespace protocols
518