Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UnfoldedStateEnergyCalculatorUtil.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 protocolsoped 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/UnfoldedStateEnergyCalculator/UnfoldedStateEnergyCalculatorUtil.hh
11 /// @brief Utility functions common to both UnfoldedStateEnergyCalculatorjob distributors
12 /// @author P. Douglas Renfrew (renfrew@unc.edu)
13 
14 // Unit headers
16 
17 // Project headers
20 
21 // Utility headers
22 #include <basic/Tracer.hh>
23 // AUTO-REMOVED #include <basic/options/option.hh>
24 // AUTO-REMOVED #include <utility/exit.hh>
25 // AUTO-REMOVED #include <utility/assert.hh>
26 #include <utility/vector1.hh>
27 
28 // C++ headers
29 #include <algorithm>
30 #include <cmath>
31 
32 static basic::Tracer TR("protocols.UnfoldedStateEnergyCalculator.UnfoldedStateEnergyCalculatorUtil");
33 
34 namespace protocols {
35 namespace unfolded_state_energy_calculator {
36 
37 void
39 {
40  using namespace core;
41  using namespace core::scoring;
42  using namespace utility;
43 
44  // calc arithmetic avg, boltzmann weighted avg, or mode of fragment central residue energies
45  EMapVector mean;
46  EMapVector median;
47  EMapVector mode;
48  EMapVector boltzmann;
49 
50  // for each energy term in the EMapVector
51  for ( Size i( 1 ); i <= n_score_types; ++i ) {
52 
53  // if the energy term has a non-zero weight
54  if ( energy_terms[ ScoreType( i ) ] != 0 ) {
55 
56  // create a vector of all the energies for this energy term
57  vector1< Real > temp_energies;
58  temp_energies.resize( unweighted_energies.size() );
59 
60  for ( Size j( 1 ); j <= unweighted_energies.size(); ++j ) {
61  temp_energies[ j ] = unweighted_energies[ j ][ ScoreType( i ) ];
62  }
63 
64  // sort array
65  std::sort( temp_energies.begin(), temp_energies.end() );
66 
67  // add values to correct EMapVectors
68  mean[ ScoreType( i ) ] = calc_vector_mean( temp_energies );
69  median[ ScoreType( i ) ] = calc_vector_median( temp_energies );
70  mode[ ScoreType( i ) ] = calc_vector_mode( temp_energies );
71  boltzmann[ ScoreType( i ) ] = calc_vector_boltzmann( temp_energies );
72  }
73  }
74 
75  // output all the data we have been collecting. despite function name these energies are unweighted
76  // since the non-zero weights were set to 1 in set_energy_terms()
77  TR << "NUM FRAGMENTS: " << unweighted_energies.size() << std::endl;
78  for ( Size i(1); i <= unweighted_energies.size(); ++i ) {
79  TR << "FRAG " << i << ":\t" << unweighted_energies[ i ].weighted_string_of( energy_terms ) << std::endl;
80  }
81 
82  // ouput averaged vectors
83  TR << "MEAN UNFODLED ENERGIES: " << mean.weighted_string_of( energy_terms ) << std::endl;
84  TR << "MEDIAN UNFODLED ENERGIES: " << median.weighted_string_of( energy_terms ) << std::endl;
85  TR << "MODE UNFODLED ENERGIES: " << mode.weighted_string_of( energy_terms ) << std::endl;
86  TR << "BOLZMANN UNFOLDED ENERGIES: " << boltzmann.weighted_string_of( energy_terms ) << std::endl;
87 }
88 
89 
90 ///@brief assumes sorted array
93 {
94  using namespace core;
95 
96  // sum elements of array
97  Real sum( 0 );
98  for ( Size i( 1 ); i <= data.size(); ++i ) {
99  sum += data[ i ];
100  }
101 
102  // return average
103  return sum/data.size();
104 }
105 
106 ///@brief assumes sorted array
109 {
110  using namespace core;
111 
112  return 0.0;
113 }
114 
115 ///@brief assumes sorted array
118 {
119  using namespace core;
120 
121  // calc mode
122 
123  // if no mode try reducing signifigance
124 
125  return 0.0;
126 }
127 
128 ///@brief assumes sorted array
131 {
132  using namespace core;
133  using namespace utility;
134 
135  // hard coded temp (K) and boltzmann constant (kcals mol^-1 K^-1)
136  Real T( 300.00 ), R( 0.0019872 );
137 
138  // calc energy differences
139  Real low_energy( data[ 1 ] );
140  vector1< core::Real> energy_diffs;
141  energy_diffs.resize( data.size() );
142  for ( Size i( 1 ); i <= data.size(); ++i ) {
143  energy_diffs[ i ] = data[ i ] - low_energy;
144  }
145 
146  // calc boltzmann factors
147  vector1< core::Real> bolzmann_factors;
148  bolzmann_factors.resize( energy_diffs.size() );
149  for ( Size i( 1 ); i <= energy_diffs.size(); ++i ) {
150  bolzmann_factors[ i ] = exp( ( -1 * energy_diffs[ i ] ) / ( R * T ) );
151  }
152 
153  // calc average boltzmann factor
154  Real sum( 0 ), avg( 0 );
155  for ( Size i( 1 ); i <= bolzmann_factors.size(); ++i ) {
156  sum += bolzmann_factors[ i ];
157  }
158  avg = sum/bolzmann_factors.size();
159 
160  // return boltzmann weighted average energy
161  return (-1 * R * T * log( avg ) ) + low_energy;
162 }
163 
164 } // UnfoldedStateEnergyCalculator
165 } // protocols