Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HelixPairing.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/HelixPairing.cc
10 /// @brief class for helix pairings
11 /// @author Nobuyasu Koga ( nobuyasu@u.washington.edu )
12 
13 // unit headers
15 
16 // project headers
18 
19 // utility headers
20 #include <utility/string_util.hh>
21 #include <utility/exit.hh>
22 
23 // C++ headers
24 #include <cassert>
25 #include <iostream>
26 #include <sstream>
27 #include <boost/lexical_cast.hpp>
28 #include <basic/Tracer.hh>
29 
30 #include <ObjexxFCL/format.hh>
31 
32 // numeric headers
33 #include <numeric/xyzVector.hh>
34 #include <numeric/conversions.hh>
35 
36 #include <utility/vector1.hh>
37 
38 
39 static basic::Tracer TR( "protocols.topology.HelixPairing" );
40 
41 using namespace core;
43 
44 namespace protocols {
45 namespace fldsgn {
46 namespace topology {
47 
48 /// @Brief default constructor
49 HelixPairing::HelixPairing():
50  h1_( 0 ),
51  h2_( 0 ),
52  orient_( 'N' ),
53  name_( "" ),
54  dist_( 0.0 ),
55  cross_angle_( 0.0 ),
56  align_angle_( -99.0 ),
57  loop_length_( 6 )
58 {}
59 
60 /// @brief value constructor
62  Size const h1,
63  Size const h2,
64  char const o
65 ):
66  h1_( h1 ),
67  h2_( h2 ),
68  orient_( o ),
69  dist_( 0.0 ),
70  cross_angle_( 0.0 ),
71  align_angle_( -99.0 ),
72  loop_length_( 6 )
73 {
74  runtime_assert( h1 < h2 );
75  initialize();
76 }
77 
78 /// @brief value constructor
80  dist_( 0.0 ),
81  cross_angle_( 0.0 ),
82  align_angle_( -99.0 ),
83  loop_length_( 6 )
84 {
85  utility::vector1< String > parts( utility::string_split( hp, '.' ) );
86  runtime_assert( parts.size() == 2 );
87 
88  utility::vector1< String > helices( utility::string_split( parts[1], '-' ) );
89  h1_ = boost::lexical_cast<Size>( helices[1] );
90  h2_ = boost::lexical_cast<Size>( helices[2] );
91  runtime_assert( h1_ < h2_ );
92 
93  char para = parts[2][0];
94  runtime_assert( para == 'P' || para == 'A' );
95  orient_ = parts[2][0];
96 
97  name_ = hp;
98 }
99 
100 
102 {
103  using namespace boost;
104  name_ = lexical_cast<String>(h1_) + '-' + lexical_cast<String>(h2_) + '.' + orient_ ;
105 }
106 
107 /// @brief copy constructor
109  ReferenceCount(),
110  h1_( hp.h1_ ),
111  h2_( hp.h2_ ),
112  orient_( hp.orient_ ),
113  name_( hp.name_ ),
114  dist_( hp.dist_ ),
118 {}
119 
120 /// @brief default destructor
122 
123 /// @brief clone this object
125 {
126  return new HelixPairing( *this );
127 }
128 
129 /// @brief return name
130 std::ostream & operator<<(std::ostream & out, const HelixPairing &hp )
131 {
132  using ObjexxFCL::fmt::F;
133  using ObjexxFCL::fmt::A;
134  out << A( 7, hp.name() ) << " "
135  << F( 8, 3, hp.dist() ) << F( 8, 3, hp.cross_angle() ) << F( 8, 3, hp.align_angle() );
136  //out << A( 7, hp.name() ) << " "
137  //<< F( 8, 3, hp.dist() ) << F( 8, 3, hp.cross_angle() );
138  return out;
139 }
140 
141 /// @brief
143  if( orient_ == 'P' ) {
144  return true;
145  }else{
146  return false;
147  }
148 }
149 
150 /// @brief
151 void
153 {
154 
158 
159  Real flip( 1.0 );
160  if( orient() == 'A' ) flip = -1.0;
161 
162  Helices const & helices( ss_info->helices() );
163  Strands const & strands( ss_info->strands() );
164 
165  Helix const & hx1 = *helices[ h1() ];
166  Helix const & hx2 = *helices[ h2() ];
167  Vector const midvec = hx2.mid_pos() - hx1.mid_pos();
168 
169  dist_ = midvec.length();
170  cross_angle_ = numeric::conversions::degrees( angle_of( hx1.orient(), flip*hx2.orient() ) );
171 
172  int r1 = int( hx1.begin() ) - int( loop_length_ );
173  int r2 = int( hx2.begin() ) - int( loop_length_ );
174  if( r1 < 1 || r2 < 1 ) return;
175 
176  Size const s1 = ss_info->strand_id( Size( r1 ) );
177  Size const s2 = ss_info->strand_id( Size( r2 ) );
178  if( s1 == 0 || s2 == 0 ) return;
179 
180  // check the strand pairing of s1 and s2 is parallel, otherwise skip this calculation
181  Real dot = ss_info->strand( s1 )->orient().dot( ss_info->strand( s2 )->orient() );
182  Real sign( 1.0 );
183  if( dot < 0 ) sign = -1.0;
184 
185  Vector const v1 = ( strands[ s2 ]->mid_pos() - strands[ s1 ]->mid_pos() ).normalized();
186  Vector const v2 = ( strands[ s1 ]->orient() + sign*strands[ s2 ]->orient() ).normalized();
187  Vector sheet_plane = v1.cross( v2 );
188 
189  Vector const h1 = hx1.Nend_pos() - sheet_plane.dot( hx1.Nend_pos() - strands[ s2 ]->mid_pos() )*sheet_plane;
190  Vector const h2 = hx1.Cend_pos() - sheet_plane.dot( hx1.Cend_pos() - strands[ s2 ]->mid_pos() )*sheet_plane;
191  Vector const h3 = hx2.Nend_pos() - sheet_plane.dot( hx2.Nend_pos() - strands[ s2 ]->mid_pos() )*sheet_plane;
192  Vector const h4 = hx2.Cend_pos() - sheet_plane.dot( hx2.Cend_pos() - strands[ s2 ]->mid_pos() )*sheet_plane;
193 
194  //Vector const v3 = hx1.orient().project_parallel( v1 ) + hx1.orient().project_parallel( v2 );
195  //Vector const v4 = hx2.orient().project_parallel( v1 ) + hx2.orient().project_parallel( v2 );
196  Vector const v3 = h2 - h1;
197  Vector const v4 = h4 - h3;
198 
199  align_angle_ = numeric::conversions::degrees( angle_of( v3, flip*v4 ) );
200 
201  // TR.Debug << h1() << " " << h2() << " " << dist_ << " " << cross_angle_ << " " << align_angle_ << std::endl;
202 }
203 
204 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
205 /// @brief default constructor
207  hpairset_name_( "" ),
208  num_helices_( 0 ),
209  initialize_map_helix_pairings_( false )
210 {}
211 
212 /// @brief value constructor
213 HelixPairingSet::HelixPairingSet( String const & helix_pairings ):
214  hpairset_name_( helix_pairings ),
215  num_helices_( 0 ),
216  initialize_map_helix_pairings_( false )
217 {
218  if( helix_pairings == "" ) {
219  return;
220  }
221 
222  utility::vector1< String > hpairs( utility::string_split( helix_pairings, ';' ) );
223  for( utility::vector1< String >::const_iterator iter = hpairs.begin(); iter != hpairs.end() ; ++iter) {
224  helix_pairings_.push_back( new HelixPairing( *iter ) );
225  }
226 }
227 
228 /// @brief value constructor
230  helix_pairings_( helix_pairings ),
231  hpairset_name_( "" ),
232  num_helices_( 0 ),
233  initialize_map_helix_pairings_( false )
234 {
235  // set hpairset_name_
236  for ( HelixPairings::const_iterator it=helix_pairings_.begin(), ite=helix_pairings_.end(); it != ite; ++it ) {
237  HelixPairing const & hpair( **it );
238  if( hpairset_name_ == "" ){
239  hpairset_name_ = hpair.name();
240  }else{
241  hpairset_name_ += ';' + hpair.name();
242  }
243  }
244 }
245 
246 /// @brief copy constructor
248  ReferenceCount(),
249  helix_pairings_( s.helix_pairings_ ),
250  hpairset_name_( s.hpairset_name_ ),
251  num_helices_( s.num_helices_ ),
252  initialize_map_helix_pairings_( s.initialize_map_helix_pairings_ ),
253  map_helix_pairings_( s.map_helix_pairings_ )
254 {}
255 
256 /// @brief destructor
258 
259 /// @brief clone this object
262 {
263  return new HelixPairingSet( *this );
264 }
265 
266 /// @brief return helix pairing
267 std::ostream & operator<<( std::ostream & out, const HelixPairingSet &s )
268 {
269  out << "#### HelixPairingSet Info " << std::endl;
270  out << "# " << s.name() << std::endl;
271  out << "# name distance cross_angle align_angle " << std::endl;
272  HelixPairings const & hpairs( s.helix_pairings() );
273  for( HelixPairings::const_iterator iter = hpairs.begin(); iter != hpairs.end(); ++iter ) {
274  out << "# " << (**iter) << std::endl;
275  }
276  return out;
277 }
278 
279 /// @brief add HelixPairingOP to StandPairingSet
280 void
282 {
283  helix_pairings_.push_back( hop );
285  if( hpairset_name_ == "" ){
286  hpairset_name_ = hop->name();
287  }else{
288  hpairset_name_ += ';' + hop->name();
289  }
290 }
291 
292 /// @brief clear data of this HelixParingSet
293 void
295 {
296  helix_pairings_.clear();
297  hpairset_name_ = "";
299  map_helix_pairings_.clear();
300 }
301 
302 /// @brief return one of the stand_pairings give a number
305 {
306  runtime_assert( s <= helix_pairings_.size() );
307  return helix_pairings_[ s ];
308 }
309 
310 /// @brief
313 {
316  }
317 
318  if( h1 <= num_helices_ && h2 <= num_helices_ ) {
319  return map_helix_pairings_[ h1 ][ h2 ];
320  } else {
321  return 0;
322  }
323 }
324 
325 /// @brief return all helix pairings
326 HelixPairings const &
328 {
329  return helix_pairings_;
330 }
331 
332 /// @brief return the size of helix_pairings_
333 Size
335 {
336  return helix_pairings_.size();
337 }
338 
339 /// @brief return hpairset_name_
340 String
342 {
343  return hpairset_name_;
344 }
345 
346 /// @brief calculate geomtry of helix parings
347 void
349 {
350  for( HelixPairings::const_iterator iter = helix_pairings_.begin(); iter != helix_pairings_.end(); ++iter ) {
351  HelixPairingOP const hpair(*iter);
352  hpair->calc_geometry( ss_info );
353  }
354 }
355 
356 /// @brief create 2D table of helix pairings
358 {
360  for ( HelixPairings::const_iterator it=helix_pairings_.begin(), ite=helix_pairings_.end(); it != ite; ++it ) {
361  HelixPairing hpair(**it);
362  if( hpair.h2() > num_helices_ ){
363  num_helices_ = hpair.h2();
364  }
365  }
367  for( Size i=1; i<=num_helices_; i++ ){
368  map_helix_pairings_[i].resize( num_helices_ );
369  for( Size j=1; j<=num_helices_; j++ ){
370  map_helix_pairings_[i][j] = 0;
371  }
372  }
373 
374  for ( HelixPairings::const_iterator it=helix_pairings_.begin(), ite=helix_pairings_.end(); it != ite; ++it ) {
375  HelixPairingOP const hpair( *it );
376  map_helix_pairings_[ hpair->h1() ][ hpair->h2() ] = hpair;
377  map_helix_pairings_[ hpair->h2() ][ hpair->h1() ] = hpair;
378  }
379  //TR << "#helices = " << num_helices_ << std::endl;
380 }
381 
382 
383 } // namespace topology
384 } // namespace fldsgn
385 } // namespace protocols