Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParallelBetaPairingPreferenceFilter.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 protocols/filters/ParallelBetaPairingPreferenceFilter.cc
11 /// @brief filter structures by parallel beta pairing preference
12 /// @detailed
13 /// @author Nobuyasu Koga ( nobuyasu@uw.edu )
14 
15 // Unit Headers
18 
19 // Project Headers
20 #include <core/types.hh>
21 #include <core/pose/Pose.hh>
26 
27 // Utility headers
28 #include <basic/database/open.hh>
29 #include <basic/Tracer.hh>
30 #include <utility/io/izstream.hh>
31 #include <utility/string_util.hh>
32 
33 // Parser headers
35 #include <utility/tag/Tag.hh>
36 
37 #include <utility/vector0.hh>
38 #include <utility/vector1.hh>
39 #include <boost/lexical_cast.hpp>
40 
41 //// C++ headers
42 static basic::Tracer TR("protocols.fldsgn.filters.ParallelBetaPairingPreferenceFilter");
43 
44 namespace protocols {
45 namespace fldsgn {
46 namespace filters {
47 
48 // @brief default constructor
50  Filter( "ParallelBetaPairingPreference" ),
51  filter_value_( 0.0 ),
52  verbose_( false )
53 {
54  using namespace core::chemical;
55 
56  utility::io::izstream stream;
57  basic::database::open( stream, "parallel_beta_pairing_preference" );
58 
59  score_pairmatrix_.resize( 20 );
60 
61  String line;
62  while( getline( stream, line ) ){
63  utility::vector1< String > tokens ( utility::string_split( line, '\t' ) );
64  runtime_assert( tokens.size() == 21 );
65  AA aa = core::chemical::aa_from_oneletter_code( tokens[ 1 ][ 0 ] );
66  score_pairmatrix_[ Size ( aa ) ].resize( 20 );
67  for( Size ii=1; ii<=20; ii++ ) {
68  Real value;
69  if( aa == core::chemical::aa_pro ) {
70  value = 0.01;
71  } else {
72  value = boost::lexical_cast<Real>( tokens[ ii+1 ] );
73  }
74  score_pairmatrix_[ Size( aa ) ][ ii ] = -std::log( value );
75  // TR << tokens[ 0 ][ 0 ] << " " << ii << " " << tokens[ ii ] << std::endl;
76  }
77  }
78  stream.close();
79 }
80 
81 
82 // @brief copy constructor
84  Super( rval ),
87  verbose_( rval.verbose_ )
88 {}
89 
90 
91 // @brief set filter value ( defalt 0 )
92 void
94 {
95  filter_value_ = value;
96 }
97 
98 
99 /// @brief return filter value
102 {
103  return compute( pose );
104 }
105 
106 
107 /// @brief report filter results
108 void
109 ParallelBetaPairingPreferenceFilter::report( std::ostream & out, Pose const & pose ) const
110 {
111  out << "ParallelBetaPairingPreference: " << compute( pose ) << "\n";
112 }
113 
114 
115 // @brief returns true if the given pose passes the filter, false otherwise.
116 bool
118 {
119  Real score = compute( pose );
120 
121  if( filter_value_ < score ){
122  return true;
123  }else{
124  return false;
125  }
126 } // apply
127 
128 
129 /// @brief refer score of residue pair
132 {
133  return score_pairmatrix_[ Size( aa1 ) ][ Size( aa2 ) ];
134 }
135 
136 
137 // @brief compute filter value give a pose
140 {
148 
149  float dssp_hbond_threshold = -0.5;
150 
151  Dssp dssp( pose );
152  SS_Info2_OP ssinfo = new SS_Info2( pose, dssp.get_dssp_secstruct() );
153  StrandPairingSet spairset = calc_strand_pairing_set( pose, ssinfo );
154 
155  Size num_pair( 0 );
156  Real score( 0.0 );
157  for( StrandPairings::const_iterator it=spairset.begin(), ite=spairset.end(); it != ite; ++it ) {
158  StrandPairing spair( **it );
159 
160  if( spair.orient() == 'A' ) continue;
161 
162  for( Size ires=spair.begin1(); ires<=spair.end1(); ires++ ) {
163 
164  Size jres( spair.residue_pair( ires ) );
165  float score1 = dssp.bb_pair_score( ires, jres );
166  float score2( 0.0 );
167  if( jres <= pose.total_residue() ) {
168  score2 = dssp.bb_pair_score( ires, jres+1 );
169  }
170 
171  bool ires_HB( false );
172  if( score1 >= dssp_hbond_threshold && score2 < dssp_hbond_threshold ) {
173  ires_HB = true;
174  } else if( score1 >= dssp_hbond_threshold && score2 >= dssp_hbond_threshold ) {
175  ires_HB = false;
176  } else {
177  TR << "WARNING: " << ires << ", " << jres << " is making strange hbond. " << std::endl;
178  continue;
179  }
180 
181  Real sc;
182  String ptn("");
183  if( ires_HB ) {
184  ptn = "HB";
185  sc = score_pairmatrix( pose.aa( ires ), pose.aa( jres ) );
186  } else {
187  ptn = "nHB";
188  sc = score_pairmatrix( pose.aa( jres ), pose.aa( ires ) );
189  }
190 
191  if( verbose_ ) {
192  TR << ires << " " << jres << " "
193  << core::chemical::oneletter_code_from_aa( pose.aa( ires ) ) << " "
194  << core::chemical::oneletter_code_from_aa( pose.aa( jres ) ) << " "
195  << ptn << " " << score2 << " " << sc << std::endl;
196  }
197 
198  score += sc;
199  num_pair ++;
200 
201  }
202  }
203 
204  return score/Real( num_pair );
205 
206 } // apply_filter
207 
208 /// @brief parse xml
209 void
211  TagPtr const tag,
212  DataMap &,
213  Filters_map const &,
214  Movers_map const &,
215  Pose const & )
216 {
217  // set threshold
218  filter_value( tag->getOption<Real>( "threshold", 0 ) );
219 
220  // set threshold
221  verbose_ = tag->getOption<bool>( "verbose", 0 );
222 }
223 
226 
228 ParallelBetaPairingPreferenceFilterCreator::keyname() const { return "ParallelBetaPairingPreference"; }
229 
230 
231 } // filters
232 } // fldsgn
233 } // protocols