Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SameStrand.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
11 /// @brief secondary structure will hold statistics about secondary structure predictions
12 /// sources can be from
13 /// - fragments
14 /// - psipred files ? other stuff
15 ///
16 /// @detailed
17 /// from converting jumping_pairings.cc of rosetta++ into mini
18 ///
19 ///
20 ///
21 /// @author Oliver Lange
22 
23 
24 // Unit Headers
26 
27 // Package Headers
29 
30 // Project Headers
31 #include <core/types.hh>
32 
33 // AUTO-REMOVED #include <core/fragment/FragSet.hh>
34 // AUTO-REMOVED #include <core/fragment/FragID_Iterator.hh>
35 // AUTO-REMOVED #include <core/fragment/Frame.hh>
36 
37 // Utility headers
38 #include <basic/Tracer.hh>
39 // AUTO-REMOVED #include <utility/io/izstream.hh>
40 
41 // ObjexxFCL Headers
42 #include <ObjexxFCL/FArray1D.hh>
43 #include <ObjexxFCL/FArray2D.hh>
44 #include <ObjexxFCL/StaticIndexRange.hh>
45 
46 // AUTO-REMOVED #include <ObjexxFCL/format.hh>
47 
48 // numeric headers
49 #include <numeric/random/random.hh>
50 #include <utility/exit.hh>
51 
52 #include <utility/vector1.hh>
53 
54 
55 //Auto using namespaces
56 namespace ObjexxFCL { namespace fmt { } } using namespace ObjexxFCL::fmt; // AUTO USING NS
57 //Auto using namespaces end
58 
59 
60 
61 //// C++ headers
62 //#include <cstdlib>
63 //#include <string>
64 //#include <vector>
65 static basic::Tracer tr("protocols.jumping");
66 static numeric::random::RandomGenerator RG(92384); // <- Magic number, do not change
67 
68 namespace protocols {
69 namespace jumping {
70 
71 using namespace ObjexxFCL;
72 
73 SameStrand::SameStrand( core::fragment::SecondaryStructureOP ss ) :
74  secondary_structure_( ss )
75 {
76  runtime_assert( ss );
77 
78  // set total_residue
79  total_residue_ = ss->total_residue();
80 
81  compute( *ss );
82 }
83 
84 //SameStrand::SameStrand() : total_residue_( 0 )
85 //{}
86 
87 // copy c'stor --
89  : ReferenceCount( other )
90 {
93  same_strand_ = other.same_strand_;
94  strand_sum_ = other.strand_sum_;
95 }
96 
97 // nothing to be done in d'stor
99 }
100 
101 
102 bool SameStrand::eval( Size i, Size j ) const {
103  runtime_assert ( i >= 1 && i <= total_residue_ );
104  runtime_assert ( j >= 1 && j <= total_residue_ );
105  return same_strand_( i, j );
106 }
107 
108 void
110  runtime_assert( secondary_structure_ );
111 
112  do_same_strand( );
113  // compute( *secondary_structure_ );
114 }
115 
116 void
118  // do strand_sum
119  do_strand_sum( ss );
120 
121  // and use that to do
122  do_same_strand( );
123 }
124 
125 void
127  // do same_strand
129 
130  float strand1,strand2,strand_ceiling,k_strand;
131  //FArray1D_float strand_sum_( StaticIndexRange( 0, total_residue_ ) );
132  float loop, r;
133 
134  for ( Size pos1 = 1; pos1 <= total_residue_; ++pos1 ) {
135  for ( Size pos2 = 1; pos2 <= total_residue_; ++pos2 ) {
136  strand1 = strand_sum_(pos1)-strand_sum_(pos1-1);
137  strand2 = strand_sum_(pos2)-strand_sum_(pos2-1);
138  strand_ceiling = std::max(0.2f, std::min(strand1,strand2));
139  // std::cout << "same_strand: "<< SS(pos1) << SS(pos2) << SS(strand_ceiling) << std::endl;
140  int const i = std::min(pos1,pos2);
141  int const j = std::max(pos1,pos2);
142 
143  if ( j-i > 5 ) {
144  same_strand_(pos1,pos2) = false;
145  } else if ( j-i < 2 ) {
146  same_strand_(pos1,pos2) = true;
147  } else {
148  same_strand_(pos1,pos2) = true;
149  for ( int k = i+1, ke = j-1; k <= ke; ++k ) {
150  k_strand = ( strand_sum_(k) - strand_sum_(k-1) ) / strand_ceiling;
151  loop = 1.0 - k_strand;
152  if ( loop < 0.3 ) loop = 0.0;
153  r = RG.uniform();
154  if ( r < loop ) {
155  same_strand_(pos1,pos2) = false;
156  }
157  // std::cout << "loop cut:" << SS( i ) << SS( k ) << SS( j ) <<
158  // SS( loop ) << std::endl;
159 
160  } // for k
161  } // if sep>5
162  } // for pos2
163  } // for pos1
164 }
165 
166 void
168  runtime_assert( total_residue_ == ss.total_residue() );
169  strand_sum_.dimension( StaticIndexRange( 0, total_residue_ ) );
170  strand_sum_(0) = 0.0;
171  for ( Size i = 1; i <= total_residue_; ++i ) {
172  strand_sum_(i) = strand_sum_(i-1) + ss.strand_fraction(i);
173  // std::cout << "strandsum: " << SS(i) << SS(strand_sum_(i) ) << std::endl;
174  }
175 }
176 
177 #if 0
178 ///@detail read from file
179 void
180 SameStrand::read_from_file( std::string fn ) {
181 
182  utility::io::izstream data( fn );
183  if ( !data ) {
184  tr.Fatal << "can't secondary structure file!!!" << fn << std::endl;
185  data.close();
186  utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
187  }
188 
189  std::string line;
190  getline( data, line); //ignore header
191  std::istringstream line_stream( line );
192  std::string dummy;
193 
194  //read number of residues
195  line_stream >> dummy >> dummy >> dummy >> dummy >> total_residue_;
196 
197  //dimension arrays
198  loop_fraction_.dimension( total_residue_, 0.0 );
199  strand_fraction_.dimension( total_residue_, 0.0 );
200 
201  while ( getline( data, line ) ) {
202  std::istringstream line_stream( line );
203  // a=i, b=j, c=orientation(1 or 2), d=pleating(1 or 2)
204  int pos;
205  core::Real ef,hf,lf;
206  line_stream >> pos >> ef >> hf >> lf;
207 
208  if ( line_stream.fail() ) {
209  std::cout << "parse error: " << line << std::endl;
210  continue;
211  }
212 
213  loop_fraction_( pos ) = lf;
214  strand_fraction_( pos ) = ef;
215  if ( std::abs( helix_fraction( pos ) - hf ) > 0.01 ) {
216  tr.Warning << "inconsistency in secondary structure file at position "
217  << pos << " H ( read ) = " << hf << " 1.0-L-E ( expected ) " << helix_fraction( pos ) << std::endl;
218  }
219  }
220 
221 }
222  #endif
223 ///@detail write to stream ( opposite from read_from_file )
224 void SameStrand::show( std::ostream& out ) const {
225  using namespace fmt;
226  for ( Size i = 1; i<=total_residue_; i++ ) {
227  for ( Size j = 1; j<=total_residue_; j++ ) {
228  out << ( eval(i,j) ? "E" : "." );
229  }
230  out << std::endl;
231  }
232 }
233 
234 
235 } //protocols
236 } //jumping