Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NMerRefEnergy.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 core/scoring/methods/NMerRefEnergy.hh
11 /// @brief Reference energy method implementation
12 /// @author Chris King (dr.chris.king@gmail.com)
13 
14 // Unit headers
17 
18 // Package headers
20 // AUTO-REMOVED #include <core/scoring/methods/EnergyMethodOptions.hh>
21 
22 // Project headers
23 #include <core/pose/Pose.hh>
24 #include <core/chemical/AA.hh>
26 
27 // C++ Headers
28 #include <string>
29 #include <vector>
30 
31 // Utility Headers
32 #include <utility/io/izstream.hh>
33 #include <utility/string_util.hh>
34 
35 #include <basic/options/option.hh>
36 #include <basic/options/keys/score.OptionKeys.gen.hh>
37 
38 #include <utility/vector1.hh>
39 
40 static basic::Tracer TR( "core.scoring.methods.NMerRefEnergy" );
41 
42 namespace core {
43 namespace scoring {
44 namespace methods {
45 
46 
47 /// @details This must return a fresh instance of the NMerRefEnergy class,
48 /// never an instance already in use
52 ) const {
53  return new NMerRefEnergy;
54 }
55 
58  ScoreTypes sts;
59  sts.push_back( nmer_ref );
60  return sts;
61 }
62 
63 void
64 NMerRefEnergy::nmer_length( Size const nmer_length ){
66  //nmer residue energy is attributed to position 1
68 }
69 
70 void
72 {
73  using namespace basic::options;
74  NMerRefEnergy::nmer_length( option[ OptionKeys::score::nmer_ref_seq_length ]() );
75 }
76 
79 {
82 }
83 
84 NMerRefEnergy::NMerRefEnergy( std::map< std::string, core::Real > const & nmer_ref_energies_in ):
86 {
88 
89  nmer_ref_energies_.clear();
90  for ( std::map< std::string, Real >::const_iterator it = nmer_ref_energies_in.begin(); it != nmer_ref_energies_in.end(); ++it ) {
91  nmer_ref_energies_.insert( *it );
92  }
93 }
94 
96 
98 
99  using namespace basic::options;
100 
101  TR << "checking for NMerRefEnergy Ref list" << std::endl;
102 
103  //check for ref list file
104  if ( option[ OptionKeys::score::nmer_ref_energies_list ].user() ) {
105  std::string const ref_list_fname( option[ OptionKeys::score::nmer_ref_energies_list ] );
106  NMerRefEnergy::read_nmer_table_list( ref_list_fname );
107  }
108  //use single ref file
109  if( option[ OptionKeys::score::nmer_ref_energies ].user() ){
110  std::string const ref_fname( option[ OptionKeys::score::nmer_ref_energies ] );
111  NMerRefEnergy::read_nmer_table( ref_fname );
112  }
113 }
114 
115 //read energy table list
116 //entries from all lists just get added to the same map
117 void NMerRefEnergy::read_nmer_table_list( std::string const ref_list_fname ) {
118  TR << "reading NMerRefEnergy list from " << ref_list_fname << std::endl;
119  utility::io::izstream in_stream( ref_list_fname );
120  if (!in_stream.good()) {
121  utility_exit_with_message( "[ERROR] Error opening NMerRefEnergy list file" );
122  }
123  //now loop over all names in list
124  std::string ref_fname;
125  while( getline( in_stream, ref_fname ) ){
126  utility::vector1< std::string > const tokens( utility::split( ref_fname ) );
127  //skip comments
128  if( tokens[ 1 ][ 0 ] == '#' ) continue;
129  NMerRefEnergy::read_nmer_table( ref_fname );
130  }
131 }
132 
134 
135  TR << "checking for NMerRefEnergy scores" << std::endl;
136 
137  TR << "reading NMerRefEnergy scores from " << ref_fname << std::endl;
138  utility::io::izstream in_stream( ref_fname );
139  if (!in_stream.good()) {
140  utility_exit_with_message( "[ERROR] Error opening NMerRefEnergy file" );
141  }
142  std::string line;
143  while( getline( in_stream, line) ) {
144  utility::vector1< std::string > const tokens ( utility::split( line ) );
145  //skip comments
146  if( tokens[ 1 ][ 0 ] == '#' ) continue;
147  if( tokens.size() != 2 ) utility_exit_with_message( "[ERROR] NMer ref energy database file "
148  + ref_fname + " does not have 2 entries at line " + line );
149  std::string const sequence( tokens[ 1 ] );
150  if( sequence.size() != nmer_length_ ) utility_exit_with_message( "[ERROR] NMer ref energy database file "
151  + ref_fname + " has wrong length nmer at line " + line
152  + "\n\texpected: " + utility::to_string( nmer_length_ ) + " found: " + utility::to_string( sequence.size() ) );
153  //everything is cool! nothing is fucked!
154  Real const energy( atof( tokens[ 2 ].c_str() ) );
155  //Hmmmm... if we have duplicate entries, say in multiple tables, what should we do? error, replace, or sum?
156  //I think we should sum them; that is, all lists are correct, even if they say diff things about diff nmers
157 // if( nmer_ref_energies_.count( sequence ) ) utility_exit_with_message( "[ERROR] NMer ref energy database file "
158 // + ref_fname + " has double entry for sequence " + sequence );
159  if( nmer_ref_energies_.count( sequence ) ){
160  TR << "[WARNING]: NMer ref energy database file "
161  + ref_fname + " has double entry for sequence " + sequence + " Summing with prev value..." << std::endl ;
162  nmer_ref_energies_[ sequence ] += energy;
163  }
164  else nmer_ref_energies_[ sequence ] = energy;
165  }
166 
167 }
168 
169 
172 {
173  return new NMerRefEnergy( nmer_ref_energies_ );
174 }
175 
176 
177 //retrieves ref energy of NMer centered on seqpos
178 void
180  conformation::Residue const & rsd,
181  pose::Pose const & pose,
182  EnergyMap & emap
183 ) const
184 {
185  using namespace chemical;
186 
187  if( nmer_ref_energies_.empty() ) return;
188  Size const seqpos( rsd.seqpos() );
189  //skip if not a NMer center
190  if( seqpos < 1 || seqpos > pose.total_residue() - nmer_cterm_ ) return;
191  //get the NMer centered on seqpos
192  std::string sequence;
193  for( Size iseq = seqpos; iseq <= seqpos + nmer_cterm_; ++iseq ){
194  sequence += pose.residue( iseq ).name1();
195  }
196  //bail if seq not in table
197  if( !nmer_ref_energies_.count( sequence ) ) return;
198  //must use find because this is a const function!
199  //the [] operator will add the element to the map if key not found, which changes the state of this function
200  Real const energy( nmer_ref_energies_.find( sequence )->second );
201  emap[ nmer_ref ] += energy;
202 
203  return;
204 
205 }
206 
207 
208 Real
210  id::DOF_ID const &,
211  id::TorsionID const &,
212  pose::Pose const &,
213  ScoreFunction const &,
214  EnergyMap const &
215 ) const
216 {
217  return 0.0;
218 }
219 
220 /// @brief NMerRefEnergy is context independent; indicates that no
221 /// context graphs are required
222 void
224 {}
227 {
228  return 1; // Initial versioning
229 }
230 } // methods
231 } // scoring
232 } // core
233