Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DGBindOptEData.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/optimize_weights/DGBindOptEData.cc
11 ///
12 /// @brief
13 /// @author Ian W. Davis
14 
15 #ifdef USEMPI
16 #include <mpi.h>
17 #endif
18 
20 
21 #include <utility/vector1.hh>
22 
23 
24 namespace protocols {
25 namespace optimize_weights {
26 
27 
29  deltaG_bind_(0),
30  bound_(NULL),
31  unbound_(NULL)
32 {
33 }
34 
35 
37 
38 
41  std::ostream & ostr,
42  Multivec const & component_weights,
43  Multivec const & vars,
44  Multivec & dE_dvars,
45  /// Basically, turn over all the private data from OptEMultiFunc
46  Size const num_energy_dofs,
47  int const ,//num_ref_dofs,
48  int const ,//num_total_dofs,
49  EnergyMap const & fixed_terms,
50  ScoreTypes const & ,//score_list,
51  ScoreTypes const & fixed_score_list,
52  bool const print
53 ) const
54 {
55  Real boundE = 0, unboundE = 0;
56  for ( Size ii = 1; ii <= num_energy_dofs; ++ii ) {
57  boundE += vars[ ii ] * bound_->free_data()[ ii ];
58  unboundE += vars[ ii ] * unbound_->free_data()[ ii ];
59  }
60  for ( Size ii = 1; ii <= fixed_score_list.size(); ++ii ) {
61  boundE += fixed_terms[ fixed_score_list[ ii ] ] * bound_->fixed_data()[ ii ];
62  unboundE += fixed_terms[ fixed_score_list[ ii ] ] * unbound_->fixed_data()[ ii ];
63  }
64 
65  // PdbBind 2007 core set
66  // Linear regression of components of interface_delta gave an intercept between -3 and -4;
67  // including this allows a better overall fit to the real binding energy.
68  Real const TdS = 3.5; // kcal/mol
69  //Real const TdS = 0; // kcal/mol
70  Real const pred_dG = (boundE - unboundE) - TdS;
71  Real const diff_dG = pred_dG - deltaG_bind_;
72  Real const sq_err = diff_dG * diff_dG;
73 
74  for ( Size ii = 1; ii <= num_energy_dofs; ++ii ) {
75  dE_dvars[ ii ] += component_weights[ type() ] * 2 * diff_dG * ( bound_->free_data()[ ii ] - unbound_->free_data()[ ii ] );
76  }
77 
78  if( print ) {
79  ostr << "DGBindOptEData bound[ " << boundE << " ] - unbound[ " << unboundE << " ] = predicted[ " << pred_dG << " ], "
80  << "predicted[ " << pred_dG << " ] - experimental[ " << deltaG_bind_ << " ] = error[ " << diff_dG << " ], "
81  << "error^2[ " << sq_err << " ], weighted error^2[ " << component_weights[ type() ]*sq_err << " ]" << std::endl;
82 
83  }
84 
85  return component_weights[ type() ] * sq_err;
86 }
87 
88 
89 /// @brief Return the upper and lower bound on the unweighted components at this
90 /// position if they are larger (or smaller) than the unweighted values already in
91 /// the two input EnergyMaps.
92 void
94  ScoreTypes const & free_score_list,
95  ScoreTypes const & fixed_score_list,
96  EnergyMap & lower_bound,
97  EnergyMap & upper_bound
98 ) const
99 {
100  update_range( bound_, free_score_list, fixed_score_list, lower_bound, upper_bound );
101  update_range( unbound_, free_score_list, fixed_score_list, lower_bound, upper_bound );
102 }
103 
104 
107 {
108  Size total = sizeof( DGBindOptEData ) +
109  sizeof( SingleStructureData ) * 1 +
110  sizeof( SingleStructureData ) * 1;
111  total += sizeof(Real) * (bound_->free_data().size()+bound_->fixed_data().size()) * 1;
112  total += sizeof(Real) * (unbound_->free_data().size()+unbound_->fixed_data().size()) * 1;
113  return total;
114 }
115 
116 
117 #ifdef USEMPI
118 void
119 DGBindOptEData::send_to_node( int const destination_node, int const tag ) const
120 {
121  /// 1. Experimental dG
122  Real deltaG_bind = deltaG_bind_; // stupid const pointer
123  MPI_Send( & deltaG_bind, 1, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
124 
125  /// 2. n free
126  Size n_free = bound_->free_data().size();
127  //std::cout << "sending n_free to node " << destination_node << " " << n_free << std::endl;
128  MPI_Send( & n_free, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
129 
130  /// 3. n fixed
131  Size n_fixed = bound_->fixed_data().size();
132  //std::cout << "sending n_fixed to node " << destination_node << " " << n_fixed << std::endl;
133  MPI_Send( & n_fixed, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
134 
135  /// Send natives, then send decoys
136  Real * free_data = new Real[ n_free ];
137  Real * fixed_data = new Real[ n_fixed ];
138  for ( Size jj = 1; jj <= n_free; ++jj ) {
139  free_data[ ( jj - 1 ) ] = bound_->free_data()[ jj ];
140  }
141  for ( Size jj = 1; jj <= n_fixed; ++jj ) {
142  fixed_data[ ( jj - 1 ) ] = bound_->fixed_data()[ jj ];
143  }
144 
145  //std::cout << "sending native free_data to node " << destination_node << " " << free_data << std::endl;
146  /// 5. native free data
147  MPI_Send( free_data, n_free, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
148 
149  //std::cout << "sending native fixed_data to node " << destination_node << " " << fixed_data << std::endl;
150  /// 6. fixed data
151  MPI_Send( fixed_data, n_fixed, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
152 
153  //std::cout << "Sent -- about to delete data" << std::endl;
154 
155  /// now send decoys
156  Real * decoy_free_data = new Real[ n_free ];
157  Real * decoy_fixed_data = new Real[ n_fixed ];
158  for ( Size jj = 1; jj <= n_free; ++jj ) {
159  decoy_free_data[ ( jj - 1 ) ] = unbound_->free_data()[ jj ];
160  }
161  for ( Size jj = 1; jj <= n_fixed; ++jj ) {
162  decoy_fixed_data[ ( jj - 1 ) ] = unbound_->fixed_data()[ jj ];
163  }
164  /// 7. decoy free data
165  //std::cout << "sending decoy free_data to node " << destination_node << std::endl;
166  MPI_Send( decoy_free_data, n_free, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
167 
168  /// 8. decoy fixed data
169  //std::cout << "sending decoy fixed_data to node " << destination_node << std::endl;
170  MPI_Send( decoy_fixed_data, n_fixed, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
171 
172  delete [] free_data;
173  delete [] fixed_data;
174 
175  delete [] decoy_free_data;
176  delete [] decoy_fixed_data;
177 
178  OptEPositionData::send_to_node( destination_node, tag );
179 
180 }
181 
182 
183 void
184 DGBindOptEData::receive_from_node( int const source_node, int const tag )
185 {
186  MPI_Status stat;
187  //TR << "PNatStructureOptEData::Recieving data from node... " << source_node << std::endl;
188 
189  /// 1. Experimental dG
190  MPI_Recv( & deltaG_bind_, 1, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
191 
192  /// 2. n free
193  Size n_free( 0 );
194  MPI_Recv( & n_free, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
195 
196  /// 3. n fixed
197  Size n_fixed( 0 );
198  MPI_Recv( & n_fixed, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
199 
200  /// Recieve native data first, then decoys
201  Real * free_data = new Real[ n_free ];
202  Real * fixed_data = new Real[ n_fixed ];
203 
204  /// 5. free data
205  MPI_Recv( free_data, n_free, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
206 
207  /// 6. fixed data
208  MPI_Recv( fixed_data, n_fixed, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
209 
210  utility::vector1< Real > free_data_v( n_free );
211  utility::vector1< Real > fixed_data_v( n_fixed );
212  for ( Size jj = 1; jj <= n_free; ++jj ) {
213  free_data_v[ jj ] = free_data[ ( jj - 1 ) ];
214  }
215  for ( Size jj = 1; jj <= n_fixed; ++jj ) {
216  fixed_data_v[ jj ] = fixed_data[ ( jj - 1 ) ];
217  }
218  bound_ = new SingleStructureData( free_data_v, fixed_data_v );
219 
220 
221  delete [] free_data; free_data = 0;
222  delete [] fixed_data; fixed_data = 0;
223 
224  //// Now receive decoy data
225  free_data = new Real[ n_free ];
226  fixed_data = new Real[ n_fixed ];
227 
228  /// 5. free data
229  MPI_Recv( free_data, n_free, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
230 
231  /// 6. fixed data
232  MPI_Recv( fixed_data, n_fixed, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
233 
234  for ( Size jj = 1; jj <= n_free; ++jj ) {
235  free_data_v[ jj ] = free_data[ ( jj - 1 ) ];
236  }
237  for ( Size jj = 1; jj <= n_fixed; ++jj ) {
238  fixed_data_v[ jj ] = fixed_data[ ( jj - 1 ) ];
239  }
240  unbound_ = new SingleStructureData( free_data_v, fixed_data_v );
241 
242 
243  delete [] free_data;
244  delete [] fixed_data;
245 
246  OptEPositionData::receive_from_node( source_node, tag );
247 
248 }
249 #endif // USEMPI
250 
251 
252 } // namespace optimize_weights
253 } // namespace protocols