Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TorsionBinSimilarity.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 && 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 protocols/frag_picker/scores/TorsionBinSimilarity.cc
11 /// @brief
12 /// @author James Thompson
13 
15 
16 #include <core/types.hh>
21 
22 #include <basic/options/option.hh>
23 #include <basic/options/keys/in.OptionKeys.gen.hh>
24 
25 #include <basic/Tracer.hh>
26 
27 #include <utility/vector1.hh>
28 #include <utility/io/izstream.hh>
29 
30 namespace protocols {
31 namespace frag_picker {
32 namespace scores {
33 
34 static basic::Tracer tr(
35  "protocols.frag_picker.scores.TorsionBinSimilarity"
36 );
37 
39 
40  std::string tmp = chunk()->chunk_key();
41  if ( tmp.compare(cached_scores_id_) == 0 )
42  return;
43  cached_scores_id_ = tmp;
44 
45  tr.Debug << "caching score for " << chunk->get_pdb_id()
46  << " of size " << chunk->size() << std::endl;
47 
48  for (Size i = 1; i <= query_len_; ++i) {
49  for (Size j = 1; j <= chunk->size(); ++j) {
50  Real const phi ( chunk->at(j)->phi() );
51  Real const psi ( chunk->at(j)->psi() );
52  Real const omega( chunk->at(j)->omega() );
53  char const torsion_bin( torsion2big_bin_( phi, psi, omega ) );
54  //scores_[i][j] = std::log( query_bin_probs_[i][bin_index_(torsion_bin)] );
55  scores_[i][j] = 1 - query_bin_probs_[i][bin_index_(torsion_bin)];
56  }
57  }
58 
59  tr.Debug << "precomputed matrix of scores " << scores_.size()
60  << "x" << chunk->size() << std::endl;
61 }
62 
65  FragmentScoreMapOP empty_map
66 ) {
67 
68 
69  std::string tmp = f->get_chunk()->chunk_key();
70  if (tmp.compare(cached_scores_id_) != 0)
71  do_caching(f->get_chunk());
72 
73  Real total_score = 0;
74  for (Size i = 1; i <= f->get_length(); ++i) {
75  assert( f->get_first_index_in_query() + i - 1 <= scores_.size() );
76  assert( f->get_first_index_in_vall() + i - 1 <= scores_[1].size() );
77  total_score += scores_[f->get_first_index_in_query() + i - 1][f->get_first_index_in_vall() + i - 1];
78  }
79  //std::cout << "total_score = " << total_score << std::endl;
80 
81  total_score /= (Real) f->get_length();
82 
83  empty_map->set_score_component(total_score, id_);
84  if ((total_score > lowest_acceptable_value_) && (use_lowest_ == true))
85  return false;
86  return true;
87 }
88 
89 char
91  core::Real const phi,
92  core::Real const psi,
93  core::Real const omega
94 ) const {
95  if ( std::abs( omega ) < 90 ) {
96  return 'O'; // cis-omega
97  } else if ( phi >= 0.0 ) {
98  if ( -100 < psi && psi <= 100 ) {
99  return 'G'; // alpha-L
100  } else {
101  return 'E'; // E
102  }
103  } else {
104  if ( -125 < psi && psi <= 50 ) {
105  return 'A'; // helical
106  } else {
107  return 'B'; // extended
108  }
109  }
110  return 'X';
111 }
112 
113 core::Size TorsionBinSimilarity::bin_index_( char const bin_name ) const {
114  switch( bin_name ) {
115  case 'A': return 1; break;
116  case 'B': return 2; break;
117  case 'E': return 3; break;
118  case 'G': return 4; break;
119  case 'O': return 5; break;
120  default:
121  std::string const msg( "Error: don't recognize bin" + bin_name );
122  utility_exit_with_message(msg);
123  break;
124  }
125 
126  return 'X'; // satisfy compiler
127 }
128 
130  Size priority,
131  Real lowest_acceptable_value,
132  bool use_lowest,
133  FragmentPickerOP picker,
134  std::string /* prediction_id */
135 ) {
136  using core::Size;
137  using core::Real;
138  using utility::vector1;
139  using utility::io::izstream;
140  using namespace basic::options;
141  using namespace basic::options::OptionKeys;
142 
144  if ( !option[ in::file::torsion_bin_probs ].user() ) {
145  utility_exit_with_message("Error: no file specified");
146  }
147  reader.read( izstream( option[ in::file::torsion_bin_probs ]() ) );
148  if ( reader.nrows() == 0 ) {
149  utility_exit_with_message( "Error: didn't read any torsions!" );
150  }
151  Size const sequence_length( reader.nrows() );
152  Size const vall_max_len( picker->get_vall()->get_largest_chunk_size() );
153 
154  utility::vector1< utility::vector1< core::Real > > probs = reader.matrix();
155 
156  return (
158  priority,
159  lowest_acceptable_value,
160  use_lowest,
161  probs,
162  sequence_length,
163  vall_max_len
164  )
165  );
166 }
167 
168 } // scores
169 } // frag_picker
170 } // protocols
171 
172