Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LAMBEGO_Similarity.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/LAMBEGO_Similarity.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.LAMBEGO_Similarity"
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 ss ( chunk->at(j)->ss() );
54  char const torsion_bin( torsion2big_bin_( phi, psi, omega, ss ) );
55  //scores_[i][j] = std::log( query_bin_probs_[i][bin_index_(torsion_bin)] );
56  scores_[i][j] = 1 - query_bin_probs_[i][bin_index_(torsion_bin)];
57  }
58  }
59 
60  tr.Debug << "precomputed matrix of scores " << scores_.size()
61  << "x" << chunk->size() << std::endl;
62 }
63 
66  FragmentScoreMapOP empty_map
67 ) {
68 
69 
70  std::string tmp = f->get_chunk()->chunk_key();
71  if (tmp.compare(cached_scores_id_) != 0)
72  do_caching(f->get_chunk());
73 
74  Real total_score = 0;
75  for (Size i = 1; i <= f->get_length(); ++i) {
76  assert( f->get_first_index_in_query() + i - 1 <= scores_.size() );
77  assert( f->get_first_index_in_vall() + i - 1 <= scores_[1].size() );
78  total_score += scores_[f->get_first_index_in_query() + i - 1][f->get_first_index_in_vall() + i - 1];
79  }
80  //std::cout << "total_score = " << total_score << std::endl;
81 
82  total_score /= (Real) f->get_length();
83 
84  empty_map->set_score_component(total_score, id_);
85  if ((total_score > lowest_acceptable_value_) && (use_lowest_ == true))
86  return false;
87  return true;
88 }
89 
90 char
92  core::Real const phi,
93  core::Real const psi,
94  core::Real const omega,
95  char const ss
96 ) const {
97 
98  bool const loop( ss == 'L' );
99 
100  if ( std::abs( omega ) < 90 ) {
101  return 'O'; // cis-omega
102  } else if ( phi >= 0.0 ) {
103  if ( -100 < psi && psi <= 100 ) {
104  return 'G'; // alpha-L
105  } else {
106  return 'E'; // E
107  }
108  } else {
109  if ( -125 < psi && psi <= 50 ) {
110  if ( loop ) return 'L'; // helical loop
111  else return 'A'; // helical non-loop
112  } else {
113  if ( loop ) return 'M';
114  else return 'B'; // extended
115  }
116  }
117  return 'X';
118 }
119 
120 core::Size LAMBEGO_Similarity::bin_index_( char const bin_name ) const {
121  switch( bin_name ) {
122  case 'L': return 1; break;
123  case 'A': return 1; break;
124  case 'M': return 2; break;
125  case 'B': return 2; break;
126  case 'E': return 3; break;
127  case 'G': return 4; break;
128  case 'O': return 5; break;
129  default:
130  std::string const msg( "Error: don't recognize bin" + bin_name );
131  utility_exit_with_message(msg);
132  break;
133  }
134 
135  return 'X'; // satisfy compiler
136 }
137 
139  Size priority,
140  Real lowest_acceptable_value,
141  bool use_lowest,
142  FragmentPickerOP picker,
143  std::string /* prediction_id */
144 ) {
145  using core::Size;
146  using core::Real;
147  using utility::vector1;
148  using utility::io::izstream;
149  using namespace basic::options;
150  using namespace basic::options::OptionKeys;
151 
153  if ( !option[ in::file::torsion_bin_probs ].user() ) {
154  utility_exit_with_message("Error: no file specified");
155  }
156  reader.read( izstream( option[ in::file::torsion_bin_probs ]() ) );
157  if ( reader.nrows() == 0 ) {
158  utility_exit_with_message( "Error: didn't read any torsions!" );
159  }
160  Size const sequence_length( reader.nrows() );
161  Size const vall_max_len( picker->get_vall()->get_largest_chunk_size() );
162 
163  utility::vector1< utility::vector1< core::Real > > probs = reader.matrix();
164 
165  return (
166  new LAMBEGO_Similarity(
167  priority,
168  lowest_acceptable_value,
169  use_lowest,
170  probs,
171  sequence_length,
172  vall_max_len
173  )
174  );
175 }
176 
177 } // scores
178 } // frag_picker
179 } // protocols