Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SS_Info2.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 ./src/protocols/fldsgn/topology/SS_Info2.cc
11 /// @brief
12 /// @author Nobuyasu Koga ( nobuyasu@u.washington.edu )
13 
14 /// Unit headers
16 
17 /// Project headers
18 #include <core/pose/Pose.hh>
20 #include <basic/datacache/CacheableData.hh>
21 
22 /// C++ Headers
23 #include <iostream>
24 #include <cassert>
25 
26 // Numeric
27 #include <numeric/xyzVector.hh>
28 #include <numeric/conversions.hh>
29 
30 #include <utility/vector1.hh>
31 
32 
33 using namespace core;
34 
35 namespace protocols {
36 namespace fldsgn {
37 namespace topology {
38 
39 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
40 // SS_Base
41 /// @brief default constructor
42 SS_Base::SS_Base():
43  begin_( 0 ),end_( 0 ),
44  is_geometry_initialized_( false )
45 {
46  Vector v;
47  v.zero();
48  orient_ = v;
49  Nend_orient_ = v;
50  Cend_orient_ = v;
51  Nend_pos_ = v;
52  Cend_pos_ = v;
53  mid_pos_ = v;
54 }
55 
56 
57 /// @brief value constructor
58 SS_Base::SS_Base( Size const & begin, Size const & end ):
59  begin_( begin ), end_( end ),
60  is_geometry_initialized_( false )
61 {
62  Vector v;
63  v.zero();
64  orient_ = v;
65  Nend_orient_ = v;
66  Cend_orient_ = v;
67  Nend_pos_ = v;
68  Cend_pos_ = v;
69  mid_pos_ = v;
70 }
71 
72 
73 /// @brief copy constructor
75  ReferenceCount(),
76  begin_ ( s.begin_ ),
77  end_ ( s.end_ ),
78  is_geometry_initialized_( s.is_geometry_initialized_ ),
79  orient_ ( s.orient_ ),
80  Nend_orient_( s.Nend_orient_ ),
81  Cend_orient_( s.Cend_orient_ ),
82  Nend_pos_( s.Nend_pos_ ),
83  Cend_pos_( s.Cend_pos_ ),
84  mid_pos_( s.mid_pos_ )
85 {}
86 
87 
88 /// @brief destructor
90 
91 
92 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
93 /// @brief default constructor
95  SS_Base()
96 {}
97 
98 
99 /// @brief value constructor
100 Strand::Strand( Size const & begin, Size const & end ):
101  SS_Base( begin, end )
102 {}
103 
104 
105 /// @brief copy constructor
106 Strand::Strand( Strand const & s ):
107  SS_Base( s )
108 {}
109 
110 
111 /// @brief destructor
113 
114 
115 /// @brief
116 std::ostream & operator<<(std::ostream & out, const Strand & st )
117 {
118  out << st.begin() << "-" << st.end() ;
119  return out;
120 }
121 
122 
123 /// @brief set vector between Calpha atoms of edge residues
124 void
126 {
127  is_geometry_initialized( true );
128 
129  // orient is defined by begin and end Ca atoms of strand
130  Nend_pos( bbpos.N( begin() ) );
131  Cend_pos( bbpos.C( end() ) );
132  Vector v = Cend_pos() - Nend_pos();
133  orient( v.normalized() );
134 
135  Size pos = ( end() - begin() )/2 + begin();
136  if( ( end() - begin() )%2 == 0 ) {
137  mid_pos( ( bbpos.N( pos ) + bbpos.C( pos ) )/2.0 );
138  } else {
139  mid_pos( ( bbpos.N( pos ) + bbpos.C( pos+1 ) )/2.0 );
140  }
141 
142  Nend_orient( ( mid_pos() - Nend_pos() ).normalized() );
143  Cend_orient( ( Cend_pos() - mid_pos() ).normalized() );
144 }
145 
146 
147 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
148 /// @brief default constructor
150  SS_Base(),
151  bend_( 0 )
152 {}
153 
154 
155 /// @brief value constructor
156 Helix::Helix( Size const & begin, Size const & end ):
157  SS_Base( begin, end ),
158  bend_( 0 )
159 {}
160 
161 
162 /// @brief copy constructor
163 Helix::Helix( Helix const & s ):
164  SS_Base( s ),
165  bend_( s.bend_ )
166 {}
167 
168 
169 /// @brief destructor
171 
172 
173 /// @brief
174 std::ostream & operator<<(std::ostream & out, const Helix & hx )
175 {
176  out << hx.begin() << "-" << hx.end() ;
177  return out;
178 }
179 
180 /// @brief
181 void
182 Helix::calc_geometry( BB_Pos const & bbpos )
183 {
184  is_geometry_initialized( true );
185 
186  Size begin( (*this).begin() );
187  Size end( (*this).end() );
188 
189  static Real const eleven_inv = 1.0 / 11.0;
190 
191  Size const s1 = int ( begin );
192  Size const s2 = s1 + 1;
193  Size const s3 = s2 + 1;
194  Size const s4 = s3 + 1;
195 
196  Vector const p1 = ( bbpos.CA( s1 ) + bbpos.C( s1 ) ) +
197  ( bbpos.N( s2 ) + bbpos.CA( s2 ) + bbpos.C( s2 ) ) +
198  ( bbpos.N( s3 ) + bbpos.CA( s3 ) + bbpos.C( s3 ) ) +
199  ( bbpos.N( s4 ) + bbpos.CA( s4 ) ) ;
200 
201  Vector const Nend_pos1 = ( p1 + bbpos.N( s1 ) ) * eleven_inv;
202  Vector const Nend_pos2 = ( p1 + bbpos.C( s4 ) ) * eleven_inv;
203  Nend_orient( ( Nend_pos2 - Nend_pos1 ).normalized() );
204 
205  Size const n1 = int ( end - 3 );
206  Size const n2 = n1 + 1;
207  Size const n3 = n2 + 1;
208  Size const n4 = n3 + 1;
209 
210  Vector const p2 = ( bbpos.CA( n1 ) + bbpos.C( n1 ) ) +
211  ( bbpos.N( n2 ) + bbpos.CA( n2 ) + bbpos.C( n2 ) ) +
212  ( bbpos.N( n3 ) + bbpos.CA( n3 ) + bbpos.C( n3 ) ) +
213  ( bbpos.N( n4 ) + bbpos.CA( n4 ) ) ;
214 
215  Vector const Cend_pos1 = ( p2 + bbpos.N( n1 ) ) * eleven_inv;
216  Vector const Cend_pos2 = ( p2 + bbpos.C( n4 ) ) * eleven_inv;
217  Cend_orient( ( Cend_pos2 - Cend_pos1 ).normalized() );
218 
219  // set vector of helix
220  Vector v = Cend_pos2 - Nend_pos1;
221  orient( v.normalized() );
222  // set positonal vector of C- and N-terminal
223  Nend_pos( Nend_pos1 );
224  Cend_pos( Cend_pos2 );
225  // set mid point
226  mid_pos( ( Nend_pos1 + Cend_pos2 )/2.0 );
227  // set bend of the helix
228  bend_ = numeric::conversions::degrees( angle_of( Nend_orient(), Cend_orient() ) );
229 
230 }
231 
232 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
233 /// @brief default constructor
235  SS_Base(),
236  type_("")
237 {}
238 
239 
240 /// @brief value constructor
241 Loop::Loop( Size const & begin, Size const & end, String const & type ):
242  SS_Base( begin, end ),
243  type_( type )
244 {}
245 
246 
247 /// @brief copy constructor
248 Loop::Loop( Loop const & s ):
249  SS_Base( s ),
250  type_( s.type_ )
251 {}
252 
253 
254 /// @brief destructor
256 
257 
258 /// @brief
259 std::ostream & operator<<(std::ostream & out, const Loop & lp )
260 {
261  out << lp.begin() << "-" << lp.end() << lp.type();
262  return out;
263 }
264 
265 
266 //////////////////////////////////////////////////////////////////////////////////////////////////////
267 /// @brief default constructor
269  CacheableData(),
270  secstruct_( "" )
271 {}
272 
273 
274 /// @brief value constructor
275 SS_Info2::SS_Info2( String const & secstruct ):
276  CacheableData()
277 {
278  initialize( secstruct );
279 }
280 
281 
282 /// @brief value constructor
283 SS_Info2::SS_Info2( Pose const & pose, String const & secstruct ):
284  CacheableData()
285 {
286  initialize( pose, secstruct );
287 }
288 
289 
290 /// @brief copy constructor
292  CacheableData(),
293  secstruct_( s.secstruct_ ),
294  bb_pos_( s.bb_pos_ ),
295  strands_( s.strands_ ),
296  strand_id_( s.strand_id_ ),
297  helices_( s.helices_ ),
298  helix_id_( s.helix_id_ ),
299  loop_id_( s.loop_id_ ),
300  ss_element_id_( s.ss_element_id_ )
301 {}
302 
303 
304 /// @brief destructor
306 
307 
308 /// @brief make clone
309 basic::datacache::CacheableDataOP
311 {
312  return new SS_Info2( *this );
313 }
314 
315 
316 /// @brief
317 void
319 {
320  secstruct_ = "";
321  bb_pos_.clear();
322  strands_.clear();
323  helices_.clear();
324  strand_id_.clear();
325  helix_id_.clear();
326  loop_id_.clear();
327  ss_element_id_.clear();
328 }
329 
330 
331 /// @brief resize vectors
332 void
333 SS_Info2::resize( Size const nres )
334 {
335  bb_pos_.resize( int(nres) );
336  helix_id_.resize( nres );
337  strand_id_.resize( nres );
338  loop_id_.resize( nres );
339  ss_element_id_.resize( nres );
340 }
341 
342 
343 /// @brief initialize parameters of this class
344 void
345 SS_Info2::initialize( Pose const & pose, String const & secstruct )
346 {
347  bbpos_is_set_ = true;
348 
349  //flo sep'12
350  //not clear what to do if the pose has ligands
351  //ideally the class should be initalized with the ligand positions,
352  //but obviously the ligands don't have any secondary structure
353  //attempt at getting desired behavior: initialize with pose length,
354  //but make sure that secondary structure is according to number
355  //of protein res
356  core::Size num_protein_res( pose.total_residue() );
357  for( core::Size i = pose.total_residue(); i != 0; i--){
358  if( !pose.residue_type( i ).is_protein() ) num_protein_res--;
359  }
360 
361  // data all clear
362  clear_data();
363  // set strands and helices
364  if( secstruct == "" ){
365  secstruct_ = pose.secstruct();
366  }else{
368  runtime_assert( num_protein_res == secstruct_.length() ); //flo sep'12 changed from pose.total_residue() to num_protein_res
369  }
370  resize( pose.total_residue() );
372  // set bb_pos
374  // set orient of strands and helices
375  set_SSorient();
376 }
377 
378 
379 /// @brief initialize parameters of this class
380 void
381 SS_Info2::initialize( String const & secstruct )
382 {
383  clear_data(); // data all clear
384  Size nres( secstruct.size() );
385  runtime_assert( nres > 0 );
387  resize( nres );
389 }
390 
391 
392 /// @brief
393 std::ostream & operator<<(std::ostream & out, const SS_Info2 & ssinfo )
394 {
395  Size count( 0 );
396  out << "#### SS_Info " << std::endl;
397  for ( Helices::const_iterator it=ssinfo.helices_.begin(), ite=ssinfo.helices_.end(); it != ite; ++it ) {
398  count ++;
399  Helix const & hx( **it );
400  out << "# Helix " << count << ": " << hx << std::endl;
401  }
402  count = 0;
403  for ( Strands::const_iterator it=ssinfo.strands_.begin(), ite=ssinfo.strands_.end(); it != ite; ++it ) {
404  count ++;
405  Strand const & st( **it );
406  out << "# Strand " << count << ": " << st << std::endl;
407  }
408  return out;
409 }
410 
411 
412 /// @brief set orientation vector of secondary structures given a pose
413 void
415 {
416  runtime_assert( pose.total_residue() == bb_pos_.size() );
418  bbpos_is_set_ = true;
419  set_SSorient();
420 }
421 
422 
423 /// @brief set orientation vector of secondary structures given a pose which is defined in the constructor
424 void
426 {
427  for( Strands::iterator iter = strands_.begin(),
428  iter_end = strands_.end(); iter != iter_end; ++iter ) {
429  StrandOP & st( *iter );
430  if( st->length() >= 2 ){
431  st->calc_geometry( bb_pos_ );
432  }
433  } // Strands
434  for( Helices::iterator iter = helices_.begin(),
435  iter_end = helices_.end(); iter != iter_end; ++iter ) {
436  HelixOP & hx( *iter );
437  if( hx->length() >= 4 ){
438  hx->calc_geometry( bb_pos_ );
439  }
440  } // Helices
441 }
442 
443 
444 /// @brief identify the region of each secondary structure element
445 void
446 SS_Info2::identify_ss( String const & secstruct )
447 {
448  bool flag_L( false );
449  bool flag_E( false );
450  bool flag_H( false );
451  Size beginE, beginH, beginL;
452  Size istrand( 0 ), ihelix( 0 ), iloop( 0 ), iss( 0 );
453 
454  String prev( "" );
455  for( Size i=1; i<= secstruct.length(); ++i ) {
456  String const & ss( secstruct.substr( i-1, 1 ) );
457 
458  strand_id_[ i ] = 0;
459  helix_id_ [ i ] = 0;
460  loop_id_ [ i ] = 0;
461 
462  if( ss =="E" ) {
463 
464  if ( flag_E == false ) {
465  istrand ++;
466  beginE = i;
467  }
468  flag_E = true;
469  strand_id_[ i ] = istrand;
470 
471  } else if( ss == "H" ) {
472 
473  if ( flag_H == false ) {
474  ihelix++;
475  beginH = i;
476  }
477  flag_H = true;
478  helix_id_[ i ] = ihelix;
479 
480  } else {
481 
482  if( flag_L == false ) {
483  iloop++;
484  beginL = i;
485  }
486  flag_L = true;
487  loop_id_[ i ] = iloop;
488 
489  }
490 
491  if ( ss !="E" && flag_E == true ) {
492  flag_E = false;
493  if( ( i - beginE ) >= 2 ) {
494  strands_.push_back( new Strand( beginE, i-1 ) );
495  } else {
496  strands_.push_back( new Strand( beginE, beginE ) );
497  }
498  }
499 
500  if ( ss !="H" && flag_H == true ) {
501  flag_H = false;
502  if( ( i-beginH ) >= 2 ) {
503  helices_.push_back( new Helix( beginH, i-1 ) );
504  } else {
505  helices_.push_back( new Helix( beginH, beginH ) );
506  }
507  }
508 
509  if( ss !="L" && flag_L == true ) {
510  flag_L = false;
511  if( ( i-beginL ) >= 2 ) {
512  loops_.push_back( new Loop( beginL, i-1 ) );
513  } else {
514  loops_.push_back( new Loop( beginL, beginL ) );
515  }
516  }
517 
518  if( prev != ss ){
519  iss ++;
520  prev = ss;
521  }
522  ss_element_id_[ i ] = iss;
523 
524  } // for( Size i )
525 
526  if( flag_E == true ) {
527  if( ( secstruct.length() - beginE + 1 ) >= 2 ) {
528  strands_.push_back( new Strand( beginE, secstruct.length() ) );
529  } else {
530  strands_.push_back( new Strand( beginE, beginE ) );
531  }
532  }
533  if( flag_H == true ) {
534  if( ( secstruct.length() - beginH + 1 ) >= 2 ) {
535  helices_.push_back( new Helix( beginH, secstruct.length() ) );
536  } else {
537  helices_.push_back( new Helix( beginH, beginH ) );
538  }
539  }
540  if( flag_L == true ) {
541  if( ( secstruct.length() - beginL + 1 ) >= 2 ) {
542  loops_.push_back( new Loop( beginL, secstruct.length() ) );
543  } else {
544  loops_.push_back( new Loop( beginL, beginL ) );
545  }
546  }
547 
548 } // SS_Info2::identify_ss()
549 
550 } // namespace topology
551 } // namespace fldsgn
552 } // namespace protocols