21 #include <ObjexxFCL/format.hh>
22 #include <utility/vector1.functions.hh>
23 #include <basic/Tracer.hh>
28 #include <utility/vector1.hh>
29 #include <basic/options/keys/OptionKeys.hh>
34 using namespace core::scoring;
35 using namespace ObjexxFCL::fmt;
38 namespace optimize_weights {
40 static basic::Tracer
TR(
"DDGBindOptEData");
50 DDGBindOptEData::DDGBindOptEData():
51 experimental_ddG_bind_(0.0)
68 Size const num_energy_dofs,
69 int const num_ref_dofs,
70 int const num_total_dofs,
76 return process_score( TR,
false, component_weights, vars, dE_dvars, num_energy_dofs, num_ref_dofs, num_total_dofs, fixed_terms, free_score_list, fixed_score_list );
88 Size const num_energy_dofs,
89 int const num_ref_dofs,
90 int const num_total_dofs,
96 process_score( ostr,
true, component_weights, vars, dE_dvars, num_energy_dofs, num_ref_dofs, num_total_dofs, fixed_terms, free_score_list, fixed_score_list );
116 Size const num_energy_dofs,
117 int const num_ref_dofs,
124 using namespace core;
125 using namespace core::optimization;
126 using namespace basic::options;
127 using namespace basic::options::OptionKeys;
128 using namespace utility;
149 for (
Size ii = 1; ii <= num_energy_dofs; ++ii ) {
156 wt_complexes_energies[ jj ] += vars[ ii ] *
wt_complexes_[ jj ]->free_data()[ ii ];
159 mutant_complexes_energies[ jj ] += vars[ ii ] *
mutant_complexes_[ jj ]->free_data()[ ii ]; }
161 wt_unbounds_energies[ jj ] += vars[ ii ] *
wt_unbounds_[ jj ]->free_data()[ ii ]; }
163 mutant_unbounds_energies[ jj ] += vars[ ii ] *
mutant_unbounds_[ jj ]->free_data()[ ii ]; }
166 for (
Size ii = 1; ii <= fixed_score_list.size(); ++ii ) {
172 wt_complexes_energies[ jj ] += fixed_terms[ fixed_score_list[ ii ] ] *
wt_complexes_[ jj ]->fixed_data()[ ii ];
175 mutant_complexes_energies[ jj ] += fixed_terms[ fixed_score_list[ ii ] ] *
mutant_complexes_[ jj ]->fixed_data()[ ii ]; }
177 wt_unbounds_energies[ jj ] += fixed_terms[ fixed_score_list[ ii ] ] *
wt_unbounds_[ jj ]->fixed_data()[ ii ]; }
179 mutant_unbounds_energies[ jj ] += fixed_terms[ fixed_score_list[ ii ] ] *
mutant_unbounds_[ jj ]->fixed_data()[ ii ]; }
184 if ( num_ref_dofs != 0 ) {
186 for (
Size jj = 1; jj <=
wt_complexes_.size(); ++jj ) { wt_complexes_energies[ jj ] += vars[ num_energy_dofs +
mutations_[ ii ].second.first ]; }
187 for (
Size jj = 1; jj <=
mutant_complexes_.size(); ++jj ) { mutant_complexes_energies[ jj ] += vars[ num_energy_dofs +
mutations_[ ii ].second.second ]; }
188 for (
Size jj = 1; jj <=
wt_unbounds_.size(); ++jj ) { wt_unbounds_energies[ jj ] += vars[ num_energy_dofs +
mutations_[ ii ].second.first ]; }
189 for (
Size jj = 1; jj <=
mutant_unbounds_.size(); ++jj ) { mutant_unbounds_energies[ jj ] += vars[ num_energy_dofs +
mutations_[ ii ].second.second ]; }
206 Size const best_wt_complex_index = arg_min( wt_complexes_energies );
207 Size const best_mutant_complex_index = arg_min( mutant_complexes_energies );
208 Size const best_wt_unbounds_index = arg_min( wt_unbounds_energies );
209 Size const best_mutant_unbounds_index = arg_min( mutant_unbounds_energies );
211 Real const best_wt_complex_energy = wt_complexes_energies[ best_wt_complex_index ];
212 Real const best_mutant_complex_energy = mutant_complexes_energies[ best_mutant_complex_index ];
213 Real const best_wt_unbounds_energy = wt_unbounds_energies[ best_wt_unbounds_index ];
214 Real const best_mutant_unbounds_energy = mutant_unbounds_energies[ best_mutant_unbounds_index ];
216 Real dG_bind_wt = best_wt_complex_energy - best_wt_unbounds_energy;
217 Real dG_bind_mutant = best_mutant_complex_energy - best_mutant_unbounds_energy;
219 Real predicted_ddG_bind = dG_bind_mutant - dG_bind_wt;
221 Real ddG_bind_diff_sq = ddG_bind_diff * ddG_bind_diff;
234 <<
" diff^2: " << F(7,2,ddG_bind_diff_sq )
238 TR <<
"process_score(): "
239 <<
"wt bound[ " << best_wt_complex_energy <<
" ] - wt unbound[ " << best_wt_unbounds_energy <<
" ] = " << dG_bind_wt
240 <<
", mut bound[ " << best_mutant_complex_energy <<
" ] - mut unbound[ " << best_mutant_unbounds_energy <<
" ] = " << dG_bind_mutant
241 <<
", predicted[ " << predicted_ddG_bind <<
" ] - experimental[ " <<
experimental_ddG_bind_ <<
" ] = error[ " << ddG_bind_diff <<
" ], "
242 <<
"error^2[ " << ddG_bind_diff_sq <<
" ], "
243 <<
"weighted error^2[ " << component_weights[
ddG_bind_correlation ] * ddG_bind_diff_sq <<
" ]" <<
", tag: " << this->
tag()
248 for(
core::Size e_dof = 1; e_dof <= num_energy_dofs; ++e_dof ) {
253 (
wt_complexes_[ best_wt_complex_index ]->free_data()[ e_dof ]
254 -
wt_unbounds_[ best_wt_unbounds_index ]->free_data()[ e_dof ] );
256 if ( num_ref_dofs != 0 ) {
259 dE_dvars[ num_energy_dofs + mutations_[ ii ].second.first ] -= 2 * component_weights[
ddG_bind_correlation ] * ddG_bind_diff;
347 DDGBindOptEData::send_to_node(
int const destination_node,
int const tag )
const {
351 MPI_Send( & experimental_ddG_bind, 1, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
354 MPI_Send( & n_mutations, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
358 MPI_Send( & position, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
360 MPI_Send( & wt_aa, 1, MPI_INT, destination_node, tag, MPI_COMM_WORLD );
361 MPI_Send( & mut_aa, 1, MPI_INT, destination_node, tag, MPI_COMM_WORLD );
367 MPI_Send( & n_wt_complexes, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
372 MPI_Send( & n_mut_complexes, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
377 MPI_Send( & n_wt_unbounds, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
382 MPI_Send( & n_mut_unbounds, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
384 if ( n_wt_complexes == 0 || n_mut_complexes == 0 || n_wt_unbounds == 0 || n_mut_unbounds == 0 )
390 MPI_Send( & n_free, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
395 MPI_Send( & n_fixed, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
399 Real * free_data =
new Real[ n_free * n_wt_complexes ];
400 Real * fixed_data =
new Real[ n_fixed * n_wt_complexes ];
401 for (
Size ii = 1; ii <= n_wt_complexes; ++ ii ) {
402 for (
Size jj = 1; jj <= n_free; ++jj ) {
403 free_data[ ( ii - 1 ) * n_free + ( jj - 1 ) ] =
wt_complexes_[ ii ]->free_data()[ jj ];
405 for (
Size jj = 1; jj <= n_fixed; ++jj ) {
406 fixed_data[ ( ii - 1 ) * n_fixed + ( jj - 1 ) ] =
wt_complexes_[ ii ]->fixed_data()[ jj ];
411 MPI_Send( free_data, n_wt_complexes * n_free, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
415 MPI_Send( fixed_data, n_wt_complexes * n_fixed, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
418 delete [] fixed_data;
421 free_data =
new Real[ n_free * n_mut_complexes ];
422 fixed_data =
new Real[ n_fixed * n_mut_complexes ];
423 for (
Size ii = 1; ii <= n_mut_complexes; ++ ii ) {
424 for (
Size jj = 1; jj <= n_free; ++jj ) {
425 free_data[ ( ii - 1 ) * n_free + ( jj - 1 ) ] =
mutant_complexes_[ ii ]->free_data()[ jj ];
427 for (
Size jj = 1; jj <= n_fixed; ++jj ) {
428 fixed_data[ ( ii - 1 ) * n_fixed + ( jj - 1 ) ] =
mutant_complexes_[ ii ]->fixed_data()[ jj ];
433 MPI_Send( free_data, n_mut_complexes * n_free, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
437 MPI_Send( fixed_data, n_mut_complexes * n_fixed, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
440 delete [] fixed_data;
443 free_data =
new Real[ n_free * n_wt_unbounds ];
444 fixed_data =
new Real[ n_fixed * n_wt_unbounds ];
445 for (
Size ii = 1; ii <= n_wt_unbounds; ++ ii ) {
446 for (
Size jj = 1; jj <= n_free; ++jj ) {
447 free_data[ ( ii - 1 ) * n_free + ( jj - 1 ) ] =
wt_unbounds_[ ii ]->free_data()[ jj ];
449 for (
Size jj = 1; jj <= n_fixed; ++jj ) {
450 fixed_data[ ( ii - 1 ) * n_fixed + ( jj - 1 ) ] =
wt_unbounds_[ ii ]->fixed_data()[ jj ];
455 MPI_Send( free_data, n_wt_unbounds * n_free, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
459 MPI_Send( fixed_data, n_wt_unbounds * n_fixed, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
462 delete [] fixed_data;
465 free_data =
new Real[ n_free * n_mut_unbounds ];
466 fixed_data =
new Real[ n_fixed * n_mut_unbounds ];
467 for (
Size ii = 1; ii <= n_mut_unbounds; ++ ii ) {
468 for (
Size jj = 1; jj <= n_free; ++jj ) {
469 free_data[ ( ii - 1 ) * n_free + ( jj - 1 ) ] =
mutant_unbounds_[ ii ]->free_data()[ jj ];
471 for (
Size jj = 1; jj <= n_fixed; ++jj ) {
472 fixed_data[ ( ii - 1 ) * n_fixed + ( jj - 1 ) ] =
mutant_unbounds_[ ii ]->fixed_data()[ jj ];
477 MPI_Send( free_data, n_mut_unbounds * n_free, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
481 MPI_Send( fixed_data, n_mut_unbounds * n_fixed, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
484 delete [] fixed_data;
486 OptEPositionData::send_to_node( destination_node, tag );
495 DDGBindOptEData::receive_from_node(
int const source_node,
int const tag )
505 MPI_Recv( & n_mutations, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
511 MPI_Recv( & position, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
513 int wt_aa(0), mut_aa(0);
514 MPI_Recv( & wt_aa, 1, MPI_INT, source_node, tag, MPI_COMM_WORLD, &stat );
515 MPI_Recv( & mut_aa, 1, MPI_INT, source_node, tag, MPI_COMM_WORLD, &stat );
519 mutations_[ ii ] = std::make_pair( position, std::make_pair( wt_aa_, mut_aa_ ) );
523 Size n_wt_complexes( 0 );
524 MPI_Recv( & n_wt_complexes, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
528 Size n_mut_complexes( 0 );
529 MPI_Recv( & n_mut_complexes, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
533 Size n_wt_unbounds( 0 );
534 MPI_Recv( & n_wt_unbounds, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
538 Size n_mut_unbounds( 0 );
539 MPI_Recv( & n_mut_unbounds, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
542 if ( n_wt_complexes == 0 || n_mut_complexes == 0 || n_wt_unbounds == 0 || n_mut_unbounds == 0 )
return;
550 MPI_Recv( & n_free, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
555 MPI_Recv( & n_fixed, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
560 Real * free_data =
new Real[ n_free * n_wt_complexes ];
561 Real * fixed_data =
new Real[ n_fixed * n_wt_complexes ];
564 MPI_Recv( free_data, n_wt_complexes * n_free, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
567 MPI_Recv( fixed_data, n_wt_complexes * n_fixed, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
571 for (
Size ii = 1; ii <= n_wt_complexes; ++ ii ) {
572 for (
Size jj = 1; jj <= n_free; ++jj ) {
573 free_data_v[ jj ] = free_data[ ( ii - 1 ) * n_free + ( jj - 1 ) ];
575 for (
Size jj = 1; jj <= n_fixed; ++jj ) {
576 fixed_data_v[ jj ] = fixed_data[ ( ii - 1 ) * n_fixed + ( jj - 1 ) ];
578 wt_complexes_.push_back(
new SingleStructureData( free_data_v, fixed_data_v ) );
580 delete [] free_data; free_data = 0; free_data_v.resize(0);
581 delete [] fixed_data; fixed_data = 0; fixed_data_v.resize(0);
584 free_data =
new Real[ n_free * n_mut_complexes ];
585 fixed_data =
new Real[ n_fixed * n_mut_complexes ];
588 MPI_Recv( free_data, n_mut_complexes * n_free, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
591 MPI_Recv( fixed_data, n_mut_complexes * n_fixed, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
593 free_data_v.resize( n_free );
594 fixed_data_v.resize( n_fixed );
595 for (
Size ii = 1; ii <= n_mut_complexes; ++ ii ) {
596 for (
Size jj = 1; jj <= n_free; ++jj ) {
597 free_data_v[ jj ] = free_data[ ( ii - 1 ) * n_free + ( jj - 1 ) ];
599 for (
Size jj = 1; jj <= n_fixed; ++jj ) {
600 fixed_data_v[ jj ] = fixed_data[ ( ii - 1 ) * n_fixed + ( jj - 1 ) ];
602 mutant_complexes_.push_back(
new SingleStructureData( free_data_v, fixed_data_v ) );
604 delete [] free_data; free_data = 0; free_data_v.resize(0);
605 delete [] fixed_data; fixed_data = 0; fixed_data_v.resize(0);
608 free_data =
new Real[ n_free * n_wt_unbounds ];
609 fixed_data =
new Real[ n_fixed * n_wt_unbounds ];
612 MPI_Recv( free_data, n_wt_unbounds * n_free, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
615 MPI_Recv( fixed_data, n_wt_unbounds * n_fixed, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
617 free_data_v.resize( n_free );
618 fixed_data_v.resize( n_fixed );
619 for (
Size ii = 1; ii <= n_wt_unbounds; ++ ii ) {
620 for (
Size jj = 1; jj <= n_free; ++jj ) {
621 free_data_v[ jj ] = free_data[ ( ii - 1 ) * n_free + ( jj - 1 ) ];
623 for (
Size jj = 1; jj <= n_fixed; ++jj ) {
624 fixed_data_v[ jj ] = fixed_data[ ( ii - 1 ) * n_fixed + ( jj - 1 ) ];
626 wt_unbounds_.push_back(
new SingleStructureData( free_data_v, fixed_data_v ) );
628 delete [] free_data; free_data = 0; free_data_v.resize(0);
629 delete [] fixed_data; fixed_data = 0; fixed_data_v.resize(0);
632 free_data =
new Real[ n_free * n_mut_unbounds ];
633 fixed_data =
new Real[ n_fixed * n_mut_unbounds ];
636 MPI_Recv( free_data, n_mut_unbounds * n_free, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
639 MPI_Recv( fixed_data, n_mut_unbounds * n_fixed, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
641 free_data_v.resize( n_free );
642 fixed_data_v.resize( n_fixed );
643 for (
Size ii = 1; ii <= n_mut_unbounds; ++ ii ) {
644 for (
Size jj = 1; jj <= n_free; ++jj ) {
645 free_data_v[ jj ] = free_data[ ( ii - 1 ) * n_free + ( jj - 1 ) ];
647 for (
Size jj = 1; jj <= n_fixed; ++jj ) {
648 fixed_data_v[ jj ] = fixed_data[ ( ii - 1 ) * n_fixed + ( jj - 1 ) ];
650 mutant_unbounds_.push_back(
new SingleStructureData( free_data_v, fixed_data_v ) );
652 delete [] free_data; free_data = 0; free_data_v.resize(0);
653 delete [] fixed_data; fixed_data = 0; fixed_data_v.resize(0);
656 OptEPositionData::receive_from_node( source_node, tag );