35 #include <utility/LexicographicalIterator.hh>
36 #include <utility/string_util.hh>
37 #include <utility/vector1.functions.hh>
38 #include <utility/exit.hh>
40 #include <ObjexxFCL/format.hh>
42 #include <numeric/numeric.functions.hh>
43 #include <numeric/statistics.functions.hh>
51 #include <basic/Tracer.hh>
54 #include <basic/options/keys/optE.OptionKeys.gen.hh>
55 #include <basic/options/keys/corrections.OptionKeys.gen.hh>
58 #include <utility/vector1.hh>
59 #include <basic/options/option.hh>
68 using namespace scoring;
69 using namespace ObjexxFCL::fmt;
72 namespace optimize_weights {
75 OptEData::~OptEData() {}
78 PNatRotOptERotamerData::~PNatRotOptERotamerData() {}
81 PNatAAOptERotamerData::~PNatAAOptERotamerData() {}
83 static basic::Tracer
TR(
"protocols.optimize_weights.OptEData");
89 os << rd->rot_number() <<
"," << rd->this_aa() <<
",";
93 fd != fixed_data.end(); ++fd ) {
94 if ( fd != fixed_data.begin() ) os <<
" ";
101 d != data.end(); ++d ) {
102 if ( d != data.begin() ) os <<
" ";
112 OptEPositionData::OptEPositionData()
115 OptEPositionData::~OptEPositionData()
119 OptEPositionData::update_range(
127 for (
Size ii = 1; ii <= free_score_list.size(); ++ii ) {
128 Real ii_min = lower_bound[ free_score_list[ ii ] ];
129 Real ii_max = upper_bound[ free_score_list[ ii ] ];
130 if ( ii_min > structure->free_data()[ ii ] ) {
131 ii_min = structure->free_data()[ ii ];
133 if ( ii_max < structure->free_data()[ ii ] ) {
134 ii_max = structure->free_data()[ ii ];
136 lower_bound[ free_score_list[ ii ] ] = ii_min;
137 upper_bound[ free_score_list[ ii ] ] = ii_max;
140 for (
Size ii = 1; ii <= fixed_score_list.size(); ++ii ) {
141 Real ii_min = lower_bound[ fixed_score_list[ ii ] ];
142 Real ii_max = upper_bound[ fixed_score_list[ ii ] ];
143 if ( ii_min > structure->fixed_data()[ ii ] ) {
144 ii_min = structure->fixed_data()[ ii ];
146 if ( ii_max < structure->fixed_data()[ ii ] ) {
147 ii_max = structure->fixed_data()[ ii ];
149 lower_bound[ fixed_score_list[ ii ] ] = ii_min;
150 upper_bound[ fixed_score_list[ ii ] ] = ii_max;
161 OptEPositionData::tag()
const
168 OptEPositionData::send_to_node(
169 int const destination_node,
173 int len( tag_.size() );
174 MPI_Send( &len, 1, MPI_INT, destination_node, tag, MPI_COMM_WORLD );
175 MPI_Send( const_cast< char * > (tag_.c_str()), len, MPI_CHAR, destination_node, tag, MPI_COMM_WORLD );
179 OptEPositionData::receive_from_node(
180 int const source_node,
187 MPI_Recv( &len, 1, MPI_INT, source_node, tag, MPI_COMM_WORLD, & stat );
188 char *
str =
new char[ len + 1 ];
190 MPI_Recv( str, len, MPI_CHAR, source_node, tag, MPI_COMM_WORLD, & stat );
193 tag_ = tag_from_node;
202 PNatAAOptEPositionData::PNatAAOptEPositionData()
205 PNatAAOptEPositionData::~PNatAAOptEPositionData()
225 PNatAAOptEPositionData::get_score(
230 Size const num_energy_dofs,
231 int const num_ref_dofs,
238 using namespace core::optimization;
239 using namespace basic::options;
240 using namespace basic::options::OptionKeys;
245 static Real const inv_kT( option[ optE::inv_kT_nataa ] );
251 Multivec ref_deriv_weight( aa_range, 0.0 );
256 vars, num_energy_dofs, fixed_terms, score_list, fixed_score_list, aa_range, dummy_set,
257 best_energy_by_aa, unweighted_E_dof, ref_deriv_weight );
268 Real numerator(0.0), partition(0.0);
269 Multivec dpartition( vars.size(), 0.0 ), dnumerator( vars.size(), 0.0 );
271 for(
Size aa(1); aa <= aa_range; ++aa ) {
273 Real const exp_term( std::exp( -1.0 * inv_kT * best_energy_by_aa[ aa ] ) );
274 partition += exp_term;
275 if ( aa ==
size_t(this_native_aa) )
276 numerator = exp_term;
280 if ( num_ref_dofs != 0 ) {
281 Real const ref_deriv_term( -1.0 * inv_kT * ref_deriv_weight[ aa ] * exp_term );
282 dpartition[ num_energy_dofs + aa ] = ref_deriv_term;
283 if ( aa ==
size_t(this_native_aa) )
284 dnumerator[ num_energy_dofs + aa ] = ref_deriv_term;
289 for(
Size e_dof(1); e_dof <= num_energy_dofs; ++e_dof ) {
290 Real e_dof_deriv( -1.0 * inv_kT * unweighted_E_dof[ aa ][ e_dof ] * exp_term );
291 dpartition[ e_dof ] += e_dof_deriv;
292 if ( aa ==
size_t(this_native_aa) )
293 dnumerator[ e_dof ] = e_dof_deriv;
298 for (
Size dof(1); dof <= vars.size(); ++dof ) {
299 dE_dvars[ dof ] += component_weights[ type() ] * ( dpartition[ dof ] / partition - dnumerator[ dof ] / numerator );
302 return ( -1.0 * component_weights[ type() ] * std::log( numerator / partition ) );
306 PNatAAOptEPositionData::print_score(
312 Size const num_energy_dofs,
313 int const num_ref_dofs,
321 using namespace core::optimization;
322 using namespace basic::options;
323 using namespace basic::options::OptionKeys;
329 static Real const inv_kT( option[ optE::inv_kT_nataa ] );
335 Multivec ref_deriv_weight( aa_range, 0.0 );
340 vars, num_energy_dofs, fixed_terms, score_list, fixed_score_list, aa_range, dummy_set,
341 best_energy_by_aa, unweighted_E_dof, ref_deriv_weight );
346 Real numerator(0.0), partition(0.0);
347 Multivec dpartition( vars.size(), 0.0 ), dnumerator( vars.size(), 0.0 );
349 for(
Size aa(1); aa <= aa_range; ++aa ) {
351 Real const exp_term( std::exp( -1.0 * inv_kT * best_energy_by_aa[ aa ] ) );
352 partition += exp_term;
353 if ( aa ==
size_t(this_native_aa) ) numerator = exp_term;
357 if ( num_ref_dofs != 0 ) {
358 Real const ref_deriv_term( -1.0 * inv_kT * ref_deriv_weight[ aa ] * exp_term );
359 dpartition[ num_energy_dofs + aa ] = ref_deriv_term;
360 if ( aa ==
size_t(this_native_aa) ) dnumerator[ num_energy_dofs + aa ] = ref_deriv_term;
364 for(
Size e_dof(1); e_dof <= num_energy_dofs; ++e_dof ) {
366 Real e_dof_deriv( -1.0 * inv_kT * unweighted_E_dof[ aa ][ e_dof ] * exp_term );
367 dpartition[ e_dof ] += e_dof_deriv;
368 if ( aa ==
size_t(this_native_aa) ) dnumerator[ e_dof ] = e_dof_deriv;
373 for (
Size dof(1); dof <= vars.size(); ++dof ) {
374 dE_dvars[ dof ] += dpartition[ dof ] / partition - dnumerator[ dof ] / numerator;
377 ostr <<
"PNATAA " << tag() <<
X(1) << this_native_aa <<
"," << I(2, (
int)this_native_aa) <<
X(1)
379 <<
" num: " << F(7,3,numerator) <<
" part: " << F(7,3,partition)
380 <<
" p: " << F(7,5,numerator / partition)
381 <<
" -lnp: " << F(6,4,-1.0 * std::log( numerator / partition ))
382 <<
" -compwt_lnp: " << F(6, 4, component_weights[ type() ] * (-1.0 * std::log( numerator / partition )) )
404 for (
Size ii = 1; ii <= free_score_list.size(); ++ii ) {
405 Real ii_min = lower_bound[ free_score_list[ ii ] ];
406 Real ii_max = upper_bound[ free_score_list[ ii ] ];
407 for( PNatAAOptERotamerDataOPs::const_iterator iter = rotamer_data_begin(),
408 e_itr = rotamer_data_end() ; iter != e_itr; ++iter ) {
409 if ( ii_min > (*iter)->data()[ ii ] ) {
410 ii_min = (*iter)->data()[ ii ];
412 if ( ii_max < (*iter)->data()[ ii ] ) {
413 ii_max = (*iter)->data()[ ii ];
416 lower_bound[ free_score_list[ ii ] ] = ii_min;
417 upper_bound[ free_score_list[ ii ] ] = ii_max;
420 for (
Size ii = 1; ii <= fixed_score_list.size(); ++ii ) {
421 Real ii_min = lower_bound[ fixed_score_list[ ii ] ];
422 Real ii_max = upper_bound[ fixed_score_list[ ii ] ];
423 for( PNatAAOptERotamerDataOPs::const_iterator iter = rotamer_data_begin(),
424 e_itr = rotamer_data_end() ; iter != e_itr; ++iter ) {
425 if ( ii_min > (*iter)->fixed_data()[ ii ] ) {
426 ii_min = (*iter)->fixed_data()[ ii ];
428 if ( ii_max < (*iter)->fixed_data()[ ii ] ) {
429 ii_max = (*iter)->fixed_data()[ ii ];
432 lower_bound[ fixed_score_list[ ii ] ] = ii_min;
433 upper_bound[ fixed_score_list[ ii ] ] = ii_max;
438 PNatAAOptEPositionData::process_rotamers(
440 Size const num_energy_dofs,
451 for( PNatAAOptERotamerDataOPs::const_iterator itr = rotamer_data_begin(), e_itr = rotamer_data_end() ; itr != e_itr; ++itr ) {
452 int const this_aa( (*itr)->this_aa() );
454 Real weighted_energy( 0.0 );
456 for(
Size ii = 1; ii <= num_energy_dofs; ++ii ) {
457 weighted_energy += vars[ ii ] * ((**itr)[ ii ]);
460 for(
Size ii = 1; ii <= fixed_score_list.size(); ++ii ) {
461 weighted_energy += fixed_terms[ fixed_score_list[ ii ] ] * (*itr)->fixed_data()[ ii ];
466 if ( vars.size() > num_energy_dofs ) {
467 weighted_energy += vars[ num_energy_dofs + this_aa ];
470 Real const cutoff( 300.0 );
471 if( weighted_energy > cutoff ) weighted_energy = cutoff;
472 if( weighted_energy < -1.0*cutoff ) weighted_energy = -1.0*cutoff;
474 if( weighted_energy < best_energy_by_aa[ this_aa ] ) {
476 best_energy_by_aa[ this_aa ] = weighted_energy;
479 if( std::abs( weighted_energy ) < cutoff ) {
480 unweighted_E_dof[ this_aa ] = (*itr)->data();
481 ref_deriv_weight[ this_aa ] = 1.0;
484 unweighted_E_dof[ this_aa ] = dummy_set;
485 ref_deriv_weight[ this_aa ] = 0.0;
493 PNatAAOptEPositionData::type()
const
500 PNatAAOptEPositionData::write_to_file( std::ofstream & outfile )
const
503 <<
"position " << position() <<
" "
504 <<
"nataa " << native_aa() <<
" "
506 <<
"nrots " << data_.size() <<
"\n";
507 for ( PNatAAOptERotamerDataOPs::const_iterator
rot( rotamer_data_begin() );
508 rot != rotamer_data_end(); ++
rot ) {
509 outfile << *
rot << std::endl;
515 PNatAAOptEPositionData::read_from_file( std::ifstream & infile )
518 using namespace utility;
522 getline( infile, line );
523 Strings words( string_split( line,
' ' ) );
524 runtime_assert( words[ 1 ] ==
"position" );
525 position_ = from_string( words[ 2 ],
Size( 0 ) );
526 runtime_assert( words[ 3 ] ==
"nataa" );
528 runtime_assert( words[ 5 ] ==
"neighbor_count" );
529 neighbor_count_ = from_string( words[ 6 ],
Size( 0 ) );
530 runtime_assert( words[ 7] ==
"nrots" );
531 Size num_rotamers = from_string( words[ 8 ],
Size( 0 ) );
533 for (
Size ii = 1; ii <= num_rotamers; ++ii ) {
534 getline( infile, line );
537 Strings sections( string_split( line,
',' ) );
541 std::istringstream ss( sections[1] );
546 fixed_vals( string_split( sections[3],
' ' ) ),
547 free_vals( string_split( sections[4],
' ' ) );
548 for ( Strings::iterator fixed_val( fixed_vals.begin() ); fixed_val != fixed_vals.end(); ++fixed_val ) {
550 std::istringstream ss( *fixed_val );
552 fixed_energies.push_back( val );
554 for ( Strings::iterator free_val( free_vals.begin() ); free_val != free_vals.end(); ++free_val ) {
556 std::istringstream ss( *free_val );
558 energies.push_back( val );
560 runtime_assert( !energies.empty() );
562 add_rotamer_line_data( new_rot_data );
567 PNatAAOptEPositionData::write_to_binary_file( std::ofstream & outfile )
const
570 typedef Energies::const_iterator Energies_CItr;
577 outfile.write( (
char*) & position_,
sizeof(
Size) );
578 outfile.write( (
char*) & native_aa_,
sizeof(
chemical::AA) );
579 outfile.write( (
char*) & neighbor_count_,
sizeof(
Size) );
581 Size const nrotamers( data().
size() );
582 outfile.write( (
char*) &nrotamers,
sizeof(
Size) );
583 for ( PNatAAOptERotamerDataOPs::const_iterator
rot( data().begin() );
584 rot != data().end(); ++
rot ) {
586 Size rot_number( (*rot)->rot_number() );
587 outfile.write( (
char*) &this_aa,
sizeof(
chemical::AA) );
588 outfile.write( (
char*) &rot_number,
sizeof(
Size) );
590 Size const nfree( (*rot)->data().size() );
591 outfile.write( (
char*) &nfree,
sizeof(
Size) );
592 for ( Energies_CItr energy( (*rot)->data().begin() );
593 energy != (*rot)->data().end(); ++energy ) {
594 outfile.write( (
char*) &(*energy),
sizeof(
Real) );
597 Size const nfixed( (*rot)->fixed_data().size() );
598 outfile.write( (
char*) &nfixed,
sizeof(
Size) );
599 for ( Energies_CItr fixed_energy( (*rot)->fixed_data().begin() );
600 fixed_energy != (*rot)->fixed_data().end(); ++fixed_energy ) {
601 outfile.write( (
char*) &(*fixed_energy),
sizeof(
Real) );
610 PNatAAOptEPositionData::read_from_binary_file( std::ifstream & infile )
613 typedef Energies::const_iterator Energies_CItr;
617 infile.read( (
char*) & position_,
sizeof(
Size) );
618 infile.read( (
char*) & native_aa_,
sizeof(
chemical::AA) );
619 infile.read( (
char*) & neighbor_count_,
sizeof(
Size) );
625 infile.read( (
char*) &nrotamers,
sizeof(
Size) );
626 for (
Size j(1); j <= nrotamers; ++j ) {
631 infile.read( (
char*) &rot_number,
sizeof(
Size) );
633 Energies energies, fixed_energies;
635 infile.read( (
char*) &nfree,
sizeof(
Size) );
636 for (
Size k(1); k <= nfree; ++k ) {
638 infile.read( (
char*) &energy,
sizeof(
Real) );
639 energies.push_back( energy );
643 infile.read( (
char*) &nfixed,
sizeof(
Size) );
644 for (
Size k(1); k <= nfixed; ++k ) {
645 Real fixed_energy(0.0);
646 infile.read( (
char*) &fixed_energy,
sizeof(
Real) );
647 fixed_energies.push_back( fixed_energy );
649 runtime_assert( !energies.empty() );
653 add_rotamer_line_data( rot_data );
658 PNatAAOptEPositionData::memory_use()
const
662 if ( data_.size() > 0 ) {
663 total +=
sizeof(
Real ) * ( data_[ 1 ]->data().size() + data_[ 1 ]->fixed_data().size() ) * data_.size();
673 PNatAAOptEPositionData::send_to_node(
int const destination_node,
int const tag )
const
679 int ii_pos = position();
680 MPI_Send( & ii_pos, 1, MPI_INT, destination_node, tag, MPI_COMM_WORLD );
683 int ii_aa = native_aa();
684 MPI_Send( & ii_aa, 1, MPI_INT, destination_node, tag, MPI_COMM_WORLD );
688 MPI_Send( & ii_neighbor_count, 1, MPI_INT, destination_node, tag, MPI_COMM_WORLD );
692 MPI_Send( & ii_num_rotamers, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
694 if ( ii_num_rotamers == 0 )
return;
696 Size free_count = data_[1]->data().size();
697 Size fixed_count = data_[1]->fixed_data().size();
700 MPI_Send( & free_count, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
701 MPI_Send( & fixed_count, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
703 int * ii_aa_types =
new int[ ii_num_rotamers ];
704 int * ii_rot_nums =
new int[ ii_num_rotamers ];
705 Real * free_data =
new Real[ ii_num_rotamers * free_count ];
706 Real * fixed_data =
new Real[ ii_num_rotamers * fixed_count ];
707 for (
Size jj = 1; jj <= ii_num_rotamers; ++jj ) {
708 ii_aa_types[ jj - 1 ] = data()[ jj ]->this_aa();
709 ii_rot_nums[ jj - 1 ] = data()[ jj ]->rot_number();
710 for (
Size kk = 1; kk <= free_count; ++kk ) {
711 free_data[ ( jj - 1 ) * free_count + kk - 1 ] = data()[ jj ]->data()[ kk ];
713 for (
Size kk = 1; kk <= fixed_count; ++kk ) {
714 fixed_data[ ( jj - 1 ) * fixed_count + kk - 1 ] = data()[ jj ]->fixed_data()[ kk ];
719 MPI_Send( ii_aa_types, ii_num_rotamers, MPI_INT, destination_node, tag, MPI_COMM_WORLD );
722 MPI_Send( ii_rot_nums, ii_num_rotamers, MPI_INT, destination_node, tag, MPI_COMM_WORLD );
725 MPI_Send( free_data, ii_num_rotamers * free_count, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
728 MPI_Send( fixed_data, ii_num_rotamers * fixed_count, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
730 delete [] ii_aa_types; ii_aa_types = 0;
731 delete [] ii_rot_nums; ii_rot_nums = 0;
732 delete [] free_data; free_data = 0;
733 delete [] fixed_data; fixed_data = 0;
736 OptEPositionData::send_to_node( destination_node, tag );
741 PNatAAOptEPositionData::receive_from_node(
int const source_node,
int const tag )
749 MPI_Recv( & ii_pos, 1, MPI_INT, source_node, tag, MPI_COMM_WORLD, &stat );
750 set_position( ii_pos );
754 MPI_Recv( & ii_aa, 1, MPI_INT, source_node, tag, MPI_COMM_WORLD, &stat );
758 int ii_neighbor_count;
759 MPI_Recv( & ii_neighbor_count, 1, MPI_INT, source_node, tag, MPI_COMM_WORLD, &stat );
760 set_neighbor_count( ii_neighbor_count );
763 Size ii_num_rotamers;
764 MPI_Recv( & ii_num_rotamers, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
766 if ( ii_num_rotamers == 0 )
return;
772 MPI_Recv( & free_count, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
773 MPI_Recv( & fixed_count, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
776 int * ii_aa_types =
new int[ ii_num_rotamers ];
777 int * ii_rot_nums =
new int[ ii_num_rotamers ];
778 Real * free_data =
new Real[ ii_num_rotamers * free_count ];
779 Real * fixed_data =
new Real[ ii_num_rotamers * fixed_count ];
782 MPI_Recv( ii_aa_types, ii_num_rotamers, MPI_INT, source_node, tag, MPI_COMM_WORLD, &stat );
785 MPI_Recv( ii_rot_nums, ii_num_rotamers, MPI_INT, source_node, tag, MPI_COMM_WORLD, &stat );
788 MPI_Recv( free_data, ii_num_rotamers * free_count, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
791 MPI_Recv( fixed_data, ii_num_rotamers * fixed_count, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
796 for (
Size jj = 1; jj <= ii_num_rotamers; ++jj ) {
797 for (
Size kk = 1; kk <= free_count; ++kk ) {
798 free_data_vect[ kk ] = free_data[ ( jj - 1 ) * free_count + kk - 1 ];
800 for (
Size kk = 1; kk <= fixed_count; ++kk ) {
801 fixed_data_vect[ kk ] = fixed_data[ ( jj - 1 ) * fixed_count + kk - 1 ];
805 ii_rot_nums[ jj - 1 ],
808 add_rotamer_line_data( jj_rotamer_data );
812 delete [] ii_aa_types; ii_aa_types = 0;
813 delete [] ii_rot_nums; ii_rot_nums = 0;
814 delete [] free_data; free_data = 0;
815 delete [] fixed_data; fixed_data = 0;
817 OptEPositionData::receive_from_node( source_node, tag );
829 PSSMOptEPositionData::PSSMOptEPositionData() {}
831 PSSMOptEPositionData::~PSSMOptEPositionData() {}
835 PSSMOptEPositionData::get_score(
840 Size const num_energy_dofs,
848 using namespace core::optimization;
849 using namespace basic::options;
850 using namespace basic::options::OptionKeys;
852 static Real const inv_kT( option[ optE::inv_kT_nataa ] );
859 Multivec ref_deriv_weight( aa_range, 0.0 );
864 vars, num_energy_dofs, fixed_terms, score_list, fixed_score_list, aa_range, dummy_set,
865 best_energy_by_aa, unweighted_E_dof, ref_deriv_weight );
867 for (
Size ii = 1; ii <= aa_range; ++ii ) {
868 if ( best_energy_by_aa[ ii ] == 1000.0 ) {
882 Real partition( 0.0 ), pssm_partition( 0.0 );
883 if ( option[ optE::sqrt_pssm ].user() ) {
886 for (
Size ii = 1; ii <= aa_range; ++ii ) {
887 Real const exp_term( std::exp( -1.0 * inv_kT * best_energy_by_aa[ ii ] ) );
888 partition += exp_term;
889 boltz_coeff[ ii ] = exp_term;
891 Real const partition2 = partition * partition;
892 Real dot_product = 0;
895 for (
Size ii = 1; ii <= aa_range; ++ii ) {
897 dot_product += pssm_probabilities_[ ii ] * std::sqrt( boltz_coeff[ ii ] / partition );
899 for (
Size jj = 1; jj <= num_energy_dofs; ++jj ) {
900 energy_coeff[ jj ] += unweighted_E_dof[ ii ][ jj ] * boltz_coeff[ ii ];
905 for (
Size ii = 1; ii <= aa_range; ++ii ) {
906 Real const ii_negsqrt_prob = std::pow( boltz_coeff[ ii ] / partition, -0.5 );
908 for (
Size jj = 1; jj <= num_energy_dofs; ++jj ) {
909 dE_dvars[ jj ] += -0.5 * pssm_probabilities_[ ii ] *
910 ( ii_negsqrt_prob ) * component_weights[ type() ] *
911 ( boltz_coeff[ ii ] * energy_coeff[ jj ] -
912 inv_kT * unweighted_E_dof[ ii ][ jj ] * boltz_coeff[ ii ] * partition ) /
915 for (
Size jj = 1; jj <= aa_range; ++jj ) {
917 dE_dvars[ num_energy_dofs + jj ] += -0.5 * pssm_probabilities_[ ii ] *
918 ( ii_negsqrt_prob ) * component_weights[ type() ] *
919 ( boltz_coeff[ ii ] * boltz_coeff[ ii ] -
920 inv_kT * boltz_coeff[ ii ] * partition ) / ( partition2 );
922 dE_dvars[ num_energy_dofs + jj ] += -0.5 * pssm_probabilities_[ ii ] *
923 ( ii_negsqrt_prob ) * component_weights[ type() ] *
924 ( inv_kT * boltz_coeff[ ii ] * boltz_coeff[ jj ] ) / ( partition2 );
928 return -1.0 * component_weights[ type() ] * dot_product;
931 for (
Size ii = 1; ii <= aa_range; ++ii ) {
932 Real const exp_term( std::exp( -1.0 * inv_kT * best_energy_by_aa[ ii ] ) );
933 partition += exp_term;
934 pssm_partition += pssm_probabilities_[ ii ] * exp_term;
936 Real const ref_deriv_term( -1.0 * inv_kT * ref_deriv_weight[ ii ] * exp_term );
937 dpartition[ num_energy_dofs + ii ] = ref_deriv_term;
938 dpssm_partition[ num_energy_dofs + ii ] = pssm_probabilities_[ ii ] * ref_deriv_term;
940 for (
Size jj = 1; jj <= num_energy_dofs; ++jj ) {
941 Real e_dof_deriv( -1.0 * inv_kT * unweighted_E_dof[ ii ][ jj ] * exp_term );
942 dpartition[ jj ] += e_dof_deriv;
943 dpssm_partition[ jj ] += pssm_probabilities_[ ii ] * e_dof_deriv;
946 for (
Size ii = 1; ii <= vars.size(); ++ii ) {
947 dE_dvars[ ii ] += component_weights[
pssm_data ] * ( dpartition[ ii ] / partition - dpssm_partition[ ii ] / pssm_partition );
958 return -1 * component_weights[
pssm_data ] * std::log( pssm_partition / partition );
963 PSSMOptEPositionData::print_score(
969 Size const num_energy_dofs,
977 using namespace core::optimization;
978 using namespace basic::options;
979 using namespace basic::options::OptionKeys;
983 static Real const inv_kT( option[ optE::inv_kT_nataa ] );
990 Multivec ref_deriv_weight( aa_range, 0.0 );
995 vars, num_energy_dofs, fixed_terms, score_list, fixed_score_list, aa_range, dummy_set,
996 best_energy_by_aa, unweighted_E_dof, ref_deriv_weight );
998 for (
Size ii = 1; ii <= aa_range; ++ii ) {
999 if ( best_energy_by_aa[ ii ] == 1000.0 ) {
1007 Real partition( 0.0 ), pssm_partition( 0.0 );
1008 if ( option[ optE::sqrt_pssm ].user() ) {
1011 for (
Size ii = 1; ii <= aa_range; ++ii ) {
1012 Real const exp_term( std::exp( -1.0 * inv_kT * best_energy_by_aa[ ii ] ) );
1013 partition += exp_term;
1014 boltz_coeff[ ii ] = exp_term;
1016 Real const partition2 = partition * partition;
1017 Real dot_product = 0;
1020 for (
Size ii = 1; ii <= aa_range; ++ii ) {
1022 dot_product += pssm_probabilities_[ ii ] * std::sqrt( boltz_coeff[ ii ] / partition );
1024 for (
Size jj = 1; jj <= num_energy_dofs; ++jj ) {
1025 energy_coeff[ jj ] += unweighted_E_dof[ ii ][ jj ] * boltz_coeff[ ii ];
1030 for (
Size ii = 1; ii <= aa_range; ++ii ) {
1031 Real const ii_negsqrt_prob = std::pow( boltz_coeff[ ii ] / partition, -0.5 );
1033 for (
Size jj = 1; jj <= num_energy_dofs; ++jj ) {
1034 dE_dvars[ jj ] += -0.5 * pssm_probabilities_[ ii ] *
1035 ( ii_negsqrt_prob ) *
1036 ( boltz_coeff[ ii ] * energy_coeff[ jj ] -
1037 inv_kT * unweighted_E_dof[ ii ][ jj ] * boltz_coeff[ ii ] * partition ) /
1040 for (
Size jj = 1; jj <= aa_range; ++jj ) {
1042 dE_dvars[ num_energy_dofs + jj ] += -0.5 * pssm_probabilities_[ ii ] *
1043 ( ii_negsqrt_prob ) *
1044 ( boltz_coeff[ ii ] * boltz_coeff[ ii ] -
1045 inv_kT * boltz_coeff[ ii ] * partition ) / ( partition2 );
1047 dE_dvars[ num_energy_dofs + jj ] += -0.5 * pssm_probabilities_[ ii ] *
1048 ( ii_negsqrt_prob ) *
1049 ( inv_kT * boltz_coeff[ ii ] * boltz_coeff[ jj ] ) / ( partition2 );
1054 ostr <<
"PSSM_SQRT " << native_aa() <<
" " << (
int) native_aa();
1055 ostr <<
" nneighb: " <<
neighbor_count() <<
" dotpr: " << dot_product <<
" ";
1056 for (
Size ii = 1; ii <= aa_range; ++ii ) {
1057 ostr <<
"([ " << ii <<
"] " << pssm_probabilities_[ ii ] <<
" , " << std::sqrt( boltz_coeff[ ii ] / partition ) <<
" ) ";
1059 ostr <<
" " << tag() <<
"\n";
1066 for (
Size ii = 1; ii <= aa_range; ++ii ) {
1067 Real const exp_term( std::exp( -1.0 * inv_kT * best_energy_by_aa[ ii ] ) );
1068 partition += exp_term;
1069 pssm_partition += pssm_probabilities_[ ii ] * exp_term;
1071 Real const ref_deriv_term( -1.0 * inv_kT * ref_deriv_weight[ ii ] * exp_term );
1072 dpartition[ num_energy_dofs + ii ] = ref_deriv_term;
1073 dpssm_partition[ num_energy_dofs + ii ] = pssm_probabilities_[ ii ] * ref_deriv_term;
1075 for (
Size jj = 1; jj <= num_energy_dofs; ++jj ) {
1076 Real e_dof_deriv( -1.0 * inv_kT * unweighted_E_dof[ ii ][ jj ] * exp_term );
1077 dpartition[ jj ] += e_dof_deriv;
1078 dpssm_partition[ jj ] += pssm_probabilities_[ ii ] * e_dof_deriv;
1081 for (
Size ii = 1; ii <= vars.size(); ++ii ) {
1082 dE_dvars[ ii ] += dpartition[ ii ] / partition - dpssm_partition[ ii ] / pssm_partition;
1093 ostr <<
"PSSM_PART " << native_aa() <<
" " << (
int) native_aa();
1094 ostr <<
" nneighb: " <<
neighbor_count() <<
" pssmpart: " << pssm_partition / partition <<
" ";
1095 ostr <<
" -lnpssmpart: " << -1.0 * std::log( pssm_partition / partition ) <<
" ";
1096 ostr <<
" -compwt_lnpssm " << -1.0 * component_weights[
pssm_data ] * std::log( pssm_partition / partition );
1097 for (
Size ii = 1; ii <= aa_range; ++ii ) {
1098 ostr <<
"([ " << ii <<
"] " << pssm_probabilities_[ ii ] <<
" , " << std::exp( -1.0 * best_energy_by_aa[ ii ] ) / partition <<
" ) ";
1101 ostr <<
" " << tag() <<
"\n";
1111 PSSMOptEPositionData::set_pssm_probabilities(
1115 using namespace basic::options;
1116 using namespace basic::options::OptionKeys;
1120 pssm_probabilities_ = pssm_probs;
1124 if ( option[ optE::sqrt_pssm ].user() ) {
1125 for (
Size ii = 1; ii <= pssm_probs.size(); ++ii ) {
1126 pssm_probabilities_[ ii ] = std::sqrt( pssm_probs[ ii ] );
1132 PSSMOptEPositionData::type()
const
1139 PSSMOptEPositionData::write_to_file( std::ofstream & outfile )
const
1141 outfile << pssm_probabilities_.size() <<
" ";
1142 for (
Size ii = 1; ii <= pssm_probabilities_.size(); ++ii ) {
1143 outfile << pssm_probabilities_[ ii ] <<
" ";
1146 parent::write_to_file( outfile );
1151 PSSMOptEPositionData::read_from_file( std::ifstream & infile )
1155 pssm_probabilities_.resize( nprobs );
1156 for (
Size ii = 1; ii <= pssm_probabilities_.size(); ++ii ) {
1157 infile >> pssm_probabilities_[ ii ];
1159 parent::read_from_file( infile );
1164 PSSMOptEPositionData::write_to_binary_file( std::ofstream & )
const
1169 PSSMOptEPositionData::read_from_binary_file( std::ifstream & )
1173 PSSMOptEPositionData::memory_use()
const
1175 Size total = pssm_probabilities_.size() *
sizeof(
Real );
1176 return total + parent::memory_use();
1183 PSSMOptEPositionData::send_to_node(
int const destination_node,
int const tag )
const
1187 int n_probabilities = pssm_probabilities_.size();
1188 MPI_Send( & n_probabilities, 1, MPI_INT, destination_node, tag, MPI_COMM_WORLD );
1189 if ( n_probabilities != 0 ) {
1190 Real * pssmprobs =
new Real[ n_probabilities ];
1191 for (
int ii = 1; ii <= n_probabilities; ++ii ) {
1192 pssmprobs[ ii - 1 ] = pssm_probabilities_[ ii ];
1194 MPI_Send( pssmprobs, n_probabilities, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
1195 delete [] pssmprobs;
1197 parent::send_to_node( destination_node, tag );
1202 PSSMOptEPositionData::receive_from_node(
int const source_node,
int const tag )
1205 int n_probabilities;
1206 MPI_Recv( & n_probabilities, 1, MPI_INT, source_node, tag, MPI_COMM_WORLD, &stat );
1207 if ( n_probabilities != 0 ) {
1208 Real * pssmprobs =
new Real[ n_probabilities ];
1209 pssm_probabilities_.resize( n_probabilities );
1210 MPI_Recv( pssmprobs, n_probabilities, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
1211 for (
int ii = 1; ii <= n_probabilities; ++ii ) {
1212 pssm_probabilities_[ ii ] = pssmprobs[ ii - 1 ];
1214 delete [] pssmprobs;
1216 parent::receive_from_node( source_node, tag );
1227 PNatRotOptEPositionData::PNatRotOptEPositionData() : phi_(0.0), psi_(0.0) {}
1237 Size const num_energy_dofs,
1246 TR,
false, component_weights, vars,
1247 dE_dvars, num_energy_dofs, dummy1, dummy2,
1248 fixed_terms, dummy3, fixed_score_list );
1269 //for ( Size ii = 1; ii <= unweighted_E_dof.size(); ++ii ) {
1270 // for ( Size jj = 1; jj <= unweighted_E_dof[ii].size(); ++jj ) {
1271 // unweighted_E_dof[ ii ][ jj ] = 0.0;
1275 Size const natrotwell = rotamer_index_2_well_id( native_rotamer_index_ );
1278 Real best_energy( 0.0 );
1279 bool best_energy_is_native( false ), first_round( true );
1281 for( PNatRotOptERotamerDataOPs::const_iterator itr = rotamer_data_begin(),
1282 e_itr = rotamer_data_end() ; itr != e_itr; ++itr ) {
1283 utility::vector1< Size > const & this_rotindex( (*itr)->rotamer_index() );
1284 Size this_rotwell = rotamer_index_2_well_id( this_rotindex );
1286 if ( this_rotwell != natrotwell && count_rotamer_as_native( *itr ) ) {
1287 this_rotwell = natrotwell;
1290 Real weighted_energy( 0.0 );
1291 // Variable-weighted energy terms
1292 for( Size ii = 1; ii <= num_energy_dofs; ++ii ) {
1293 weighted_energy += vars[ ii ] * ((**itr)[ ii ]);
1295 // Fixed-weight energy terms
1296 for( Size ii = 1; ii <= fixed_score_list.size(); ++ii ) {
1297 weighted_energy += fixed_terms[ fixed_score_list[ ii ] ] * (*itr)->fixed_data()[ ii ];
1300 Real const cutoff( 300.0 );
1301 if( weighted_energy > cutoff ) weighted_energy = cutoff;
1302 if( weighted_energy < -1.0*cutoff ) weighted_energy = -1.0*cutoff;
1304 if ( first_round || weighted_energy < best_energy ) {
1305 best_energy = weighted_energy;
1306 first_round = false;
1307 best_energy_is_native = this_rotwell == natrotwell;
1310 if( weighted_energy < best_energy_by_rotwell[ this_rotwell ] ) {
1312 best_energy_by_rotwell[ this_rotwell ] = weighted_energy;
1313 well_is_represented[ this_rotwell ] = true;
1315 if( std::abs( weighted_energy ) < cutoff ) {
1316 unweighted_E_dof[ this_rotwell ] = (*itr)->free_data();
1318 // derivatives will be zero above and below cutoffs
1319 unweighted_E_dof[ this_rotwell ] = dummy_set;
1322 } // done processing rotamers
1323 // now do the partition function analysis
1325 if ( ! well_is_represented[ rotamer_index_2_well_id( native_rotamer_index_ ) ] ) {
1331 Real numerator(0.0), partition(0.0);
1332 Multivec dpartition( vars.size(), 0.0 ), dnumerator( vars.size(), 0.0 );
1334 for( LexicographicalIterator iter( rotamer_well_counts_ ); ! iter.at_end(); ++iter ) {
1335 Size const iter_rotwell = rotamer_index_2_well_id( iter );
1336 if ( ! well_is_represented[ iter_rotwell ] ) continue;
1338 Real const exp_term( std::exp( -1.0 * inv_kT * best_energy_by_rotwell[ iter_rotwell ] ) );
1339 partition += exp_term;
1340 bool const native_rotamer( is_native_rotamer_well( iter ));
1341 if ( native_rotamer ) numerator = exp_term;
1343 // partitions for energy derivatives
1344 for( Size e_dof(1); e_dof <= num_energy_dofs; ++e_dof ) {
1345 // note for derivatives: d/dw( e^-(E*w+...) ) = -E * e^-(E*w+...)
1346 Real e_dof_deriv( -1.0 * inv_kT * unweighted_E_dof[ iter_rotwell ][ e_dof ] * exp_term );
1347 dpartition[ e_dof ] += e_dof_deriv;
1348 if ( native_rotamer ) dnumerator[ e_dof ] = e_dof_deriv;
1352 // accumulate to passed-in derivative sums
1353 for ( Size dof(1); dof <= vars.size(); ++dof ) {
1354 dE_dvars[ dof ] += component_weights[ prob_native_rotamer ] * ( dpartition[ dof ] / partition - dnumerator[ dof ] / numerator );
1357 //return best_energy_is_native ? 0 : 1;
1358 return ( -1.0 * component_weights[ prob_native_rotamer ] * std::log( numerator / partition ) );
1364 std::ostream & ostr,
1369 Size const num_energy_dofs,
1378 ostr,
true, component_weights, vars,
1379 dE_dvars, num_energy_dofs, dummy1, dummy2,
1380 fixed_terms, dummy3, fixed_score_list );
1387 std::ostream & ostr,
1393 Size const num_energy_dofs,
1401 using namespace core::optimization;
1402 using namespace utility;
1403 using namespace basic::options;
1404 using namespace basic::options::OptionKeys;
1406 static Real const inv_kT( option[ optE::inv_kT_natrot ] );
1408 static bool const dun10active( option[ corrections::score::dun10 ] );
1428 Real best_energyHACK( 0.0 );
1429 bool best_energy_is_native(
false ), first_round(
true );
1432 Size nnearnative( 0 );
1440 bool count_as_native(
false );
1442 this_rotwell = natrotwell;
1443 count_as_native =
true;
1449 Real weighted_energy( 0.0 );
1450 if ( count_as_native && dun10active ) {
1451 using namespace core::chemical;
1455 case aa_asp : weighted_energy = std::log( 3.0f / 6.0f );
break;
1456 case aa_glu : weighted_energy = std::log( 3.0f / 6.0f );
break;
1457 case aa_phe : weighted_energy = std::log( 2.0f / 6.0f );
break;
1458 case aa_his : weighted_energy = std::log( 3.0f / 12.0f );
break;
1459 case aa_asn : weighted_energy = std::log( 6.0f / 12.0f );
break;
1460 case aa_gln : weighted_energy = std::log( 4.0f / 12.0f );
break;
1461 case aa_tyr : weighted_energy = std::log( 2.0f / 6.0f );
break;
1468 for(
Size ii = 1; ii <= num_energy_dofs; ++ii ) {
1469 weighted_energy += vars[ ii ] * ((**itr)[ ii ]);
1472 for(
Size ii = 1; ii <= fixed_score_list.size(); ++ii ) {
1473 weighted_energy += fixed_terms[ fixed_score_list[ ii ] ] * (*itr)->fixed_data()[ ii ];
1476 Real const cutoff( 300.0 );
1477 if( weighted_energy > cutoff ) weighted_energy = cutoff;
1478 if( weighted_energy < -1.0*cutoff ) weighted_energy = -1.0*cutoff;
1480 if ( first_round || weighted_energy < best_energyHACK ) {
1481 best_energyHACK = weighted_energy;
1482 first_round =
false;
1483 best_energy_is_native = this_rotwell == natrotwell;
1486 if( weighted_energy < best_energy_by_rotwell[ this_rotwell ] ) {
1487 best_rotamer_by_rotwell[ this_rotwell ] = *itr;
1488 best_energy_by_rotwell[ this_rotwell ] = weighted_energy;
1489 well_is_represented[ this_rotwell ] =
true;
1491 if( std::abs( weighted_energy ) < cutoff ) {
1492 unweighted_E_dof[ this_rotwell ] = (*itr)->free_data();
1495 unweighted_E_dof[ this_rotwell ] = dummy_set;
1502 Real numerator(0.0), partition(0.0);
1503 Multivec dpartition( vars.size(), 0.0 ), dnumerator( vars.size(), 0.0 );
1504 static Real const SENTINEL = 1234;
1505 Real best_energy( SENTINEL );
Size best_rotind( 0 );
1512 if ( ! well_is_represented[ iter_rotwell ] )
continue;
1514 Real const exp_term( std::exp( -1.0 * inv_kT * best_energy_by_rotwell[ iter_rotwell ] ) );
1515 partition += exp_term;
1517 if ( native_rotamer ) numerator = exp_term;
1519 if ( best_energy == SENTINEL || best_energy > best_energy_by_rotwell[ iter_rotwell ] ) {
1520 best_energy = best_energy_by_rotwell[ iter_rotwell ];
1521 best_rotind = iter_rotwell;
1523 best_rotwell[ ii ] = iter[ ii ];
1527 if ( native_rotamer ) {
1529 native_rotwell[ ii ] = iter[ ii ];
1533 for(
Size e_dof(1); e_dof <= num_energy_dofs; ++e_dof ) {
1535 Real e_dof_deriv( -1.0 * inv_kT * unweighted_E_dof[ iter_rotwell ][ e_dof ] * exp_term );
1536 dpartition[ e_dof ] += e_dof_deriv;
1537 if ( native_rotamer ) dnumerator[ e_dof ] = e_dof_deriv;
1548 ostr <<
"PNATROT-NO-NEAR-NATIVE nnat:" << nnearnative <<
" ndec: " << ndecoys <<
" p: " << 0.0 <<
" -lnp: ";
1550 ostr <<
" compwt_lnp: " << 100;
1554 ostr <<
" phi/psi:" <<
phi_ <<
" " <<
psi_ <<
"\n";
1559 ostr <<
"NON-NATIVE-ROT " <<
tag() <<
" ";
1560 for (
Size ii = 1; ii <= (*itr)->rotamer_index().size(); ++ii ) {
1561 ostr << (*itr)->rotamer_index()[ ii ] <<
" "<< (*itr)->chi()[ ii ] <<
" ";
1573 for (
Size dof(1); dof <= vars.size(); ++dof ) {
1574 dE_dvars[ dof ] += dpartition[ dof ] / partition - dnumerator[ dof ] / numerator;
1578 ostr <<
"PNATROT nnat:" << nnearnative <<
" ndec: " << ndecoys <<
" p: " << numerator / partition <<
" -lnp: ";
1579 ostr << -1.0 * std::log( numerator / partition );
1580 ostr <<
" compwt_lnp: " << -1.0 * component_weights[
prob_native_rotamer ] * std::log( numerator / partition );
1586 ostr <<
" " << best_rotwell[ ii ] <<
" " << best_rotamer_by_rotwell[ best_rotind ]->chi()[ ii ] ;
1588 ostr <<
" phi/psi:" <<
phi_ <<
" " <<
psi_ <<
"\n";
1593 return ( -1.0 * component_weights[
prob_native_rotamer ] * std::log( numerator / partition ) );
1605 for (
Size ii = 1; ii <= free_score_list.size(); ++ii ) {
1606 Real ii_min = lower_bound[ free_score_list[ ii ] ];
1607 Real ii_max = upper_bound[ free_score_list[ ii ] ];
1610 if ( ii_min > (*iter)->free_data()[ ii ] ) {
1611 ii_min = (*iter)->free_data()[ ii ];
1613 if ( ii_max < (*iter)->free_data()[ ii ] ) {
1614 ii_max = (*iter)->free_data()[ ii ];
1617 lower_bound[ free_score_list[ ii ] ] = ii_min;
1618 upper_bound[ free_score_list[ ii ] ] = ii_max;
1621 for (
Size ii = 1; ii <= fixed_score_list.size(); ++ii ) {
1622 Real ii_min = lower_bound[ fixed_score_list[ ii ] ];
1623 Real ii_max = upper_bound[ fixed_score_list[ ii ] ];
1626 if ( ii_min > (*iter)->fixed_data()[ ii ] ) {
1627 ii_min = (*iter)->fixed_data()[ ii ];
1629 if ( ii_max < (*iter)->fixed_data()[ ii ] ) {
1630 ii_max = (*iter)->fixed_data()[ ii ];
1633 lower_bound[ fixed_score_list[ ii ] ] = ii_min;
1634 upper_bound[ fixed_score_list[ ii ] ] = ii_max;
1643 return data_.size();
1680 if (
data_.size() > 0 ) {
1681 total +=
sizeof(
Real ) * (
data_[ 1 ]->free_data().size() +
data_[ 1 ]->fixed_data().size() ) *
data_.size();
1682 total +=
sizeof(
Size ) *
data_[ 1 ]->rotamer_index().size() *
data_.size();
1690 PNatRotOptEPositionData::send_to_node(
int const destination_node,
int const tag )
const
1697 int n_chi(
data_[ 1 ]->rotamer_index().
size() );
1698 MPI_Send( & n_chi, 1, MPI_INT, destination_node, tag, MPI_COMM_WORLD);
1702 int * rotamer_well_counts =
new int[ n_chi ];
1703 for (
int ii = 1; ii <= n_chi; ++ii ) {
1706 MPI_Send( rotamer_well_counts, n_chi, MPI_INT, destination_node, tag, MPI_COMM_WORLD );
1707 delete [] rotamer_well_counts;
1712 int * native_rotamer =
new int[ n_chi ];
1713 for (
int ii = 1; ii <= n_chi; ++ii ) {
1716 MPI_Send( native_rotamer, n_chi, MPI_INT, destination_node, tag, MPI_COMM_WORLD );
1717 delete [] native_rotamer;
1722 MPI_Send( & ii_num_rotamers, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
1724 if ( ii_num_rotamers == 0 )
return;
1730 MPI_Send( & free_count, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
1731 MPI_Send( & fixed_count, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
1734 Size * ii_rot_indices =
new Size[ ii_num_rotamers * n_chi ];
1735 Real * chi =
new Real[ ii_num_rotamers * n_chi ];
1736 Real * free_data =
new Real[ ii_num_rotamers * free_count ];
1737 Real * fixed_data =
new Real[ ii_num_rotamers * fixed_count ];
1739 for (
Size jj = 1; jj <= ii_num_rotamers; ++jj ) {
1745 for (
int kk = 1; kk <= n_chi; ++kk ) {
1746 ii_rot_indices[ ( jj - 1 ) * n_chi + kk - 1 ] = rotamer_index_vect[ kk ];
1747 chi[ ( jj - 1 ) * n_chi + kk - 1 ] = chi_vect[ kk ];
1749 for (
Size kk = 1; kk <= free_count; ++kk ) {
1750 free_data[ ( jj - 1 ) * free_count + kk - 1 ] = free_data_vect[ kk ];
1752 for (
Size kk = 1; kk <= fixed_count; ++kk ) {
1753 fixed_data[ ( jj - 1 ) * fixed_count + kk - 1 ] = fixed_data_vect[ kk ];
1758 MPI_Send( ii_rot_indices, ii_num_rotamers * n_chi, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
1759 MPI_Send( chi, ii_num_rotamers * n_chi, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
1762 MPI_Send( free_data, ii_num_rotamers * free_count, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
1765 MPI_Send( fixed_data, ii_num_rotamers * fixed_count, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
1768 delete [] ii_rot_indices; ii_rot_indices = 0;
1769 delete [] chi; chi = 0;
1770 delete [] free_data; free_data = 0;
1771 delete [] fixed_data; fixed_data = 0;
1775 MPI_Send( & nnative_chi, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
1776 if ( nnative_chi != 0 ) {
1777 Real * native_chi =
new Real[ nnative_chi ];
1778 for (
Size ii = 1; ii <= nnative_chi; ++ii ) native_chi[ ii - 1 ] =
native_chi_[ ii ];
1779 MPI_Send( native_chi, nnative_chi, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
1780 delete [] native_chi;
1785 MPI_Send( & nnative_chi_periodicity, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
1786 if ( nnative_chi_periodicity != 0 ) {
1787 Real * native_chi_periodicity =
new Real[ nnative_chi_periodicity ];
1789 MPI_Send( native_chi_periodicity, nnative_chi_periodicity, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
1790 delete [] native_chi_periodicity;
1795 MPI_Send( &
phi, 1, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
1796 MPI_Send( &
psi, 1, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
1800 MPI_Send( &
aa, 1, MPI_INT, destination_node, tag, MPI_COMM_WORLD );
1804 OptEPositionData::send_to_node( destination_node, tag );
1809 PNatRotOptEPositionData::receive_from_node(
int const source_node,
int const tag )
1817 MPI_Recv( & n_chi, 1, MPI_INT, source_node, tag, MPI_COMM_WORLD, &stat );
1821 runtime_assert( n_chi > 0 );
1825 int * rotamer_well_counts =
new int[ n_chi ];
1826 MPI_Recv( rotamer_well_counts, n_chi, MPI_INT, source_node, tag, MPI_COMM_WORLD, &stat );
1828 for (
int ii = 1; ii <= n_chi; ++ii ) {
1829 rotamer_well_counts_v[ ii ] = rotamer_well_counts[ ii - 1 ];
1832 delete [] rotamer_well_counts;
1838 int * native_rotamer =
new int[ n_chi ];
1839 MPI_Recv( native_rotamer, n_chi, MPI_INT, source_node, tag, MPI_COMM_WORLD, &stat );
1841 for (
int ii = 1; ii <= n_chi; ++ii ) {
1842 native_rotamer_v[ ii ] = native_rotamer[ ii -1 ];
1846 delete [] native_rotamer;
1850 Size ii_num_rotamers;
1851 MPI_Recv( & ii_num_rotamers, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
1854 if ( ii_num_rotamers == 0 )
return;
1857 Size fixed_count(0);
1860 MPI_Recv( & free_count, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
1861 MPI_Recv( & fixed_count, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
1864 Size * ii_rot_indices =
new Size[ ii_num_rotamers * n_chi ];
1865 Real * chi =
new Real[ ii_num_rotamers * n_chi ];
1866 Real * free_data =
new Real[ ii_num_rotamers * free_count ];
1867 Real * fixed_data =
new Real[ ii_num_rotamers * fixed_count ];
1870 MPI_Recv( ii_rot_indices, ii_num_rotamers * n_chi, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
1871 MPI_Recv( chi, ii_num_rotamers * n_chi, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
1874 MPI_Recv( free_data, ii_num_rotamers * free_count, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
1877 MPI_Recv( fixed_data, ii_num_rotamers * fixed_count, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
1884 for (
Size jj = 1; jj <= ii_num_rotamers; ++jj ) {
1885 for (
int kk = 1; kk <= n_chi; ++kk ) {
1886 rotamer_index_vect[ kk ] = ii_rot_indices[ ( jj - 1 ) * n_chi + kk - 1 ];
1887 chi_vect[ kk ] = chi[ ( jj - 1 ) * n_chi + kk - 1 ];
1889 for (
Size kk = 1; kk <= free_count; ++kk ) {
1890 free_data_vect[ kk ] = free_data[ ( jj - 1 ) * free_count + kk - 1 ];
1892 for (
Size kk = 1; kk <= fixed_count; ++kk ) {
1893 fixed_data_vect[ kk ] = fixed_data[ ( jj - 1 ) * fixed_count + kk - 1 ];
1904 delete [] ii_rot_indices; ii_rot_indices = 0;
1905 delete [] chi; chi = 0;
1906 delete [] free_data; free_data = 0;
1907 delete [] fixed_data; fixed_data = 0;
1911 MPI_Recv( & nnative_chi, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
1912 if ( nnative_chi != 0 ) {
1914 Real * native_chi =
new Real[ nnative_chi ];
1915 MPI_Recv( native_chi, nnative_chi, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
1916 for (
Size ii = 1; ii <= nnative_chi; ++ii )
native_chi_[ ii ] = native_chi[ ii - 1 ];
1917 delete [] native_chi;
1922 MPI_Recv( & nnative_chi_periodicity, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
1923 if ( nnative_chi_periodicity != 0 ) {
1924 Real * native_chi_periodicity =
new Real[ nnative_chi_periodicity ];
1925 MPI_Recv( native_chi_periodicity, nnative_chi_periodicity, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
1928 delete [] native_chi_periodicity;
1933 MPI_Recv( & phi, 1, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
1934 MPI_Recv( & psi, 1, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
1940 MPI_Recv( & aa, 1, MPI_INT, source_node, tag, MPI_COMM_WORLD, &stat );
1944 OptEPositionData::receive_from_node( source_node, tag );
1958 runtime_assert( native_rotamer_index_[ ii ] > 0 );
1982 static Real const TOLERANCE = 40.0;
2002 runtime_assert( rotamer_well_counts.size() > 0 );
2005 for (
Size ii = 1; ii <= rotamer_well_counts_.size(); ++ii ) {
2006 n_wells_ *= rotamer_well_counts_[ ii ];
2013 data_.push_back( rot_in );
2028 PNatRotOptERotamerDataOPs::const_iterator
2031 return data_.begin();
2033 PNatRotOptERotamerDataOPs::const_iterator
2054 Size well_id = rotamer_index[ 1 ] - 1;
2057 well_id += rotamer_index[ ii ] - 1;
2064 utility::LexicographicalIterator
const & lexiter
2068 Size well_id = lexiter[ 1 ] - 1;
2071 well_id += lexiter[ ii ] - 1;
2089 utility::LexicographicalIterator
const & lexiter
2110 total_residue_( 0 ),
2111 n_top_natives_to_score_( 1 ),
2112 n_high_entropy_decoys_( 0 ),
2113 normalize_decoy_stddev_( false ),
2114 initial_decoy_stddev_( 1.0 ),
2115 nativeness_sum_( 0.0 )
2128 Size const num_energy_dofs,
2137 TR,
false, component_weights, vars,
2138 dE_dvars, num_energy_dofs, dummy1, dummy2,
2139 fixed_terms, dummy3, fixed_score_list );
2306 std::ostream & ostr,
2311 Size const num_energy_dofs,
2320 ostr,
true, component_weights, vars,
2321 dE_dvars, num_energy_dofs, dummy1, dummy2,
2322 fixed_terms, dummy3, fixed_score_list );
2327 std::ostream & ostr,
2333 Size const num_energy_dofs,
2341 using namespace core::optimization;
2342 using namespace utility;
2343 using namespace basic::options;
2344 using namespace basic::options::OptionKeys;
2346 static Real const inv_kT( option[ optE::inv_kT_natstruct ] );
2347 Real score_factor = option[ optE::approximate_decoy_entropy ].user() ? 1 :
total_residue_;
2361 for (
Size ii = 1; ii <= num_energy_dofs; ++ii ) {
2363 native_energies[ jj ] += vars[ ii ] *
natives_[ jj ]->free_data()[ ii ];
2366 decoy_energies[ jj ] += vars[ ii ] *
decoys_[ jj ]->free_data()[ ii ];
2369 for (
Size ii = 1; ii <= fixed_score_list.size(); ++ii ) {
2371 native_energies[ jj ] += fixed_terms[ fixed_score_list[ ii ] ] *
natives_[ jj ]->fixed_data()[ ii ];
2374 decoy_energies[ jj ] += fixed_terms[ fixed_score_list[ ii ] ] *
decoys_[ jj ]->fixed_data()[ ii ];
2383 noentropy_decoy_energies = decoy_energies;
2384 noentropy_native_energies = native_energies;
2387 Real const noentropy_best_native_energy = min( noentropy_native_energies );
2388 Real const noentropy_best_decoy_energy = min( noentropy_decoy_energies );
2389 bool const noentropy_native_beats_decoys( noentropy_best_native_energy < noentropy_best_decoy_energy );
2390 Real const noentropy_best_energy = noentropy_native_beats_decoys ? noentropy_best_native_energy : noentropy_best_decoy_energy;
2392 for (
Size ii = 1; ii <= native_energies.size(); ++ii ) {
2393 noentropy_native_energies[ ii ] -= noentropy_best_energy;
2396 noentropy_decoy_energies[ ii ] -= noentropy_best_energy;
2403 Real sd = numeric::statistics::std_dev( decoy_energies.begin(), decoy_energies.end(),
Real( 0.0 ));
2407 for (
Size jj = 1; jj <= decoy_energies.size(); ++jj ) {
2408 decoy_energies[ jj ] *= scaling_factor;
2410 for (
Size jj = 1; jj <= native_energies.size(); ++jj ) {
2411 native_energies[ jj ] *= scaling_factor;
2419 if ( option[ optE::approximate_decoy_entropy ].user() ) {
2421 static Real const neg_lnalpha = -std::log( option[ optE::approximate_decoy_entropy ] );
2424 Real const offset = ( energy_offset < 0 ) ? energy_offset : 0;
2427 decoy_energies[ jj ] += offset;
2432 if ( option[ optE::ramp_nativeness ] ) {
2434 for (
Size jj = 1; jj <= native_energies.size(); ++jj ) {
2435 native_energies[ jj ] += native_entropy_penalty;
2441 top_natives[ 1 ] = arg_min( native_energies );
2442 }
else if ( option[ optE::approximate_decoy_entropy ].user() ) {
2445 top_natives[ 1 ] = arg_min( native_energies );
2447 top_natives[ top_natives[ 1 ] ] = 1;
2449 arg_least_several( native_energies, top_natives );
2454 Real best_native_energy = native_energies[ top_natives[ 1 ] ];
2455 Real const best_decoy_energy = min( decoy_energies );
2456 bool const native_beats_decoys( best_native_energy < best_decoy_energy );
2457 Real const best_energy = native_beats_decoys ? best_native_energy : best_decoy_energy;
2459 for (
Size ii = 1; ii <= native_energies.size(); ++ii ) native_energies[ ii ] -= best_energy;
2460 for (
Size ii = 1; ii <=
decoys_.size(); ++ii ) decoy_energies[ ii ] -= best_energy;
2463 Real numerator(0.0), partition(0.0);
2464 Multivec dpartition( vars.size(), 0.0 ), dnumerator( vars.size(), 0.0 );
2466 for (
Size ii = 1; ii <= top_natives.size(); ++ii ) {
2467 Real exp_term( std::exp( -1.0 * inv_kT * native_energies[ top_natives[ ii ] ] ) );
2471 exp_term = std::max( 1e-6, exp_term );
2474 partition += exp_term;
2475 numerator += exp_term * iinativeness;
2477 for(
Size e_dof(1); e_dof <= num_energy_dofs; ++e_dof ) {
2479 Real e_dof_deriv( -1.0 * inv_kT * score_factor *
natives_[ top_natives[ ii ] ]->free_data()[ e_dof ] * exp_term );
2480 dpartition[ e_dof ] += e_dof_deriv;
2481 dnumerator[ e_dof ] += iinativeness * e_dof_deriv ;
2487 Real const exp_term( std::exp( -1.0 * inv_kT * decoy_energies[ ii ] ) );
2488 partition += exp_term;
2491 for(
Size e_dof(1); e_dof <= num_energy_dofs; ++e_dof ) {
2493 Real e_dof_deriv( -1.0 * inv_kT * score_factor *
decoys_[ ii ]->free_data()[ e_dof ] * exp_term );
2494 dpartition[ e_dof ] += e_dof_deriv;
2500 for (
Size dof(1); dof <= num_energy_dofs; ++dof ) {
2501 dE_dvars[ dof ] += dpartition[ dof ] / partition - dnumerator[ dof ] / numerator;
2506 ostr <<
" n<d? " << native_beats_decoys <<
" p: " << numerator / partition;
2507 ostr <<
" -lnp: " << -1 * std::log( numerator / partition ) <<
" -wlnp " << -1.0 * score_factor * std::log( numerator / partition );
2508 ostr <<
" -compwt_lnp " << component_weights[
prob_native_structure ] * -1.0 * score_factor * std::log( numerator / partition );
2509 ostr <<
" " <<
tag() <<
"\n";
2512 ostr <<
"DECDISCRIM NATIVE " <<
tag() <<
" rms: " <<
natives_[ ii ]->rms() <<
" sc(w/o_etropy): " << noentropy_native_energies[ ii ] <<
" sc(w/entropy): " << native_energies[ ii ] <<
" " <<
natives_[ ii ]->tag() <<
"\n";
2515 ostr <<
"DECDISCRIM DECOY " <<
tag() <<
" rms: " <<
decoys_[ ii ]->rms() <<
" sc(w/o_entropy): " << noentropy_decoy_energies[ ii ] <<
" sc(w/entropy): " << decoy_energies[ ii ] <<
" " <<
decoys_[ ii ]->tag() <<
"\n";
2518 return ( -1.0 * component_weights[
prob_native_structure ] * score_factor * std::log( numerator / partition ) );
2534 update_range(
decoys_[ jj ], free_score_list, fixed_score_list, lower_bound, upper_bound );
2591 PNatStructureOptEData::send_to_node(
int const destination_node,
int const tag )
const
2596 MPI_Send( & total_residue, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
2600 MPI_Send( & n_top, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
2605 MPI_Send( & nnatives, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
2610 MPI_Send( & ndecoys, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
2615 MPI_Send( & n_high_entropy_decoys, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
2619 MPI_Send( & normalize_decoy_stddev, 1, MPI_INT, destination_node, tag, MPI_COMM_WORLD );
2623 MPI_Send( & initial_decoy_stddev, 1, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
2627 MPI_Send( & nativeness_sum, 1, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
2630 if ( nnatives == 0 || ndecoys == 0 ) {
2631 OptEPositionData::send_to_node( destination_node, tag );
2638 MPI_Send( & n_free, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
2643 MPI_Send( & n_fixed, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
2647 Real * free_data =
new Real[ n_free * nnatives ];
2648 Real * fixed_data =
new Real[ n_fixed * nnatives ];
2649 for (
Size ii = 1; ii <= nnatives; ++ ii ) {
2651 for (
Size jj = 1; jj <= n_free; ++jj ) {
2652 free_data[ ( ii - 1 ) * n_free + ( jj - 1 ) ] =
natives_[ ii ]->free_data()[ jj ];
2654 for (
Size jj = 1; jj <= n_fixed; ++jj ) {
2655 fixed_data[ ( ii - 1 ) * n_fixed + ( jj - 1 ) ] =
natives_[ ii ]->fixed_data()[ jj ];
2659 MPI_Send( rms, nnatives, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
2663 MPI_Send( free_data, nnatives * n_free, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
2667 MPI_Send( fixed_data, nnatives * n_fixed, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
2672 Real * decoy_rms =
new Real[ ndecoys ];
2673 Real * decoy_free_data =
new Real[ n_free * ndecoys ];
2674 Real * decoy_fixed_data =
new Real[ n_fixed * ndecoys ];
2675 for (
Size ii = 1; ii <= ndecoys; ++ ii ) {
2677 for (
Size jj = 1; jj <= n_free; ++jj ) {
2678 decoy_free_data[ ( ii - 1 ) * n_free + ( jj - 1 ) ] =
decoys_[ ii ]->free_data()[ jj ];
2680 for (
Size jj = 1; jj <= n_fixed; ++jj ) {
2681 decoy_fixed_data[ ( ii - 1 ) * n_fixed + ( jj - 1 ) ] =
decoys_[ ii ]->fixed_data()[ jj ];
2685 MPI_Send( decoy_rms, ndecoys, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
2689 MPI_Send( decoy_free_data, ndecoys * n_free, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
2693 MPI_Send( decoy_fixed_data, ndecoys * n_fixed, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
2696 delete [] free_data;
2697 delete [] fixed_data;
2699 delete [] decoy_rms;
2700 delete [] decoy_free_data;
2701 delete [] decoy_fixed_data;
2706 IterativeOptEDriver::send_string_to_node( destination_node,
natives_[ ii ]->
tag() );
2710 IterativeOptEDriver::send_string_to_node( destination_node,
decoys_[ ii ]->
tag() );
2713 OptEPositionData::send_to_node( destination_node, tag );
2718 PNatStructureOptEData::receive_from_node(
int const source_node,
int const tag )
2724 Size total_residue( 0 );
2725 MPI_Recv( & total_residue, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
2730 MPI_Recv( & n_top, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
2735 MPI_Recv( & nnatives, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
2739 MPI_Recv( & ndecoys, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
2743 Size n_high_entropy_decoys( 0 );
2744 MPI_Recv( & n_high_entropy_decoys, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
2748 int normalize_decoy_stddev( 0 );
2749 MPI_Recv( & normalize_decoy_stddev, 1, MPI_INT, source_node, tag, MPI_COMM_WORLD, &stat );
2753 Real initial_decoy_stddev( 1.0 );
2754 MPI_Recv( & initial_decoy_stddev, 1, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
2758 Real nativeness_sum( 0.0 );
2759 MPI_Recv( & nativeness_sum, 1, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
2762 if ( nnatives == 0 || ndecoys == 0 ) {
2763 OptEPositionData::receive_from_node( source_node, tag );
2771 MPI_Recv( & n_free, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
2775 MPI_Recv( & n_fixed, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
2779 Real * free_data =
new Real[ n_free * nnatives ];
2780 Real * fixed_data =
new Real[ n_fixed * nnatives ];
2782 MPI_Recv( rms, nnatives, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
2785 MPI_Recv( free_data, nnatives * n_free, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
2788 MPI_Recv( fixed_data, nnatives * n_fixed, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
2792 for (
Size ii = 1; ii <= nnatives; ++ ii ) {
2793 for (
Size jj = 1; jj <= n_free; ++jj ) {
2794 free_data_v[ jj ] = free_data[ ( ii - 1 ) * n_free + ( jj - 1 ) ];
2796 for (
Size jj = 1; jj <= n_fixed; ++jj ) {
2797 fixed_data_v[ jj ] = fixed_data[ ( ii - 1 ) * n_fixed + ( jj - 1 ) ];
2799 natives_.push_back(
new SingleStructureData( free_data_v, fixed_data_v ) );
2800 natives_[ ii ]->rms( rms[ ii-1 ] );
2804 delete []
rms; rms = 0;
2805 delete [] free_data; free_data = 0;
2806 delete [] fixed_data; fixed_data = 0;
2809 rms =
new Real[ ndecoys ];
2810 free_data =
new Real[ n_free * ndecoys ];
2811 fixed_data =
new Real[ n_fixed * ndecoys ];
2813 MPI_Recv( rms, ndecoys, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
2816 MPI_Recv( free_data, ndecoys * n_free, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
2819 MPI_Recv( fixed_data, ndecoys * n_fixed, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
2821 for (
Size ii = 1; ii <= ndecoys; ++ ii ) {
2822 for (
Size jj = 1; jj <= n_free; ++jj ) {
2823 free_data_v[ jj ] = free_data[ ( ii - 1 ) * n_free + ( jj - 1 ) ];
2825 for (
Size jj = 1; jj <= n_fixed; ++jj ) {
2826 fixed_data_v[ jj ] = fixed_data[ ( ii - 1 ) * n_fixed + ( jj - 1 ) ];
2828 decoys_.push_back(
new SingleStructureData( free_data_v, fixed_data_v ) );
2829 decoys_[ ii ]->rms( rms[ ii - 1 ] );
2835 delete [] free_data;
2836 delete [] fixed_data;
2841 natives_[ ii ]->tag( IterativeOptEDriver::receive_string_from_node( source_node ));
2845 decoys_[ ii ]->tag( IterativeOptEDriver::receive_string_from_node( source_node ));
2849 OptEPositionData::receive_from_node( source_node, tag );
2859 if ( basic::options::option[ basic::options::OptionKeys::optE::ramp_nativeness ] ) {
2884 std::cerr <<
"ERROR: PNatStructureOptEData will not score fewer than one top native!" << std::endl;
2911 static bool ramp_nativeness( basic::options::option[ basic::options::OptionKeys::optE::ramp_nativeness ] );
2912 return ! ramp_nativeness ? 1.0 :
2953 free_terms_( score_list ),
2954 free_term_constraints_( score_list.
size() )
2975 Real spring_constant;
2980 if ( ! infile )
break;
2982 infile >> term_name;
2986 std::cerr <<
"ERROR reading '" << term_name <<
"' in weight-constraint input file as a ScoreType." << std::endl;
2990 if ( score_types_seen[ term ] ) {
2991 std::cerr <<
"ERROR initializing weight-constraints from file: term '" << term_name <<
"' repeated in input file" << std::endl;
2995 score_types_seen[ term ] =
true;
2996 Size term_index( 0 );
3004 if ( term_index == 0 ) {
3005 std::cerr <<
"Error initializing constraints for term: " << term_name <<
" which does not appear in the free_terms_ list";
3009 if ( on_off ==
"OFF" ) {
3011 }
else if ( on_off ==
"ON" ) {
3012 infile >> min_val >> max_val >> spring_constant;
3018 std::cerr <<
"ERROR: In weight constraint file, expected 'ON' or 'OFF' but read '" << on_off <<
"' instead." << std::endl;
3030 Size const num_energy_dofs,
3038 using namespace core::optimization;
3040 for (
Size ii = 1; ii <= num_energy_dofs; ++ii ) {
3060 std::ostream & ostr,
3065 Size const num_energy_dofs,
3073 using namespace core::optimization;
3076 std::ostringstream sstr;
3077 for (
Size ii = 1; ii <= num_energy_dofs; ++ii ) {
3086 sstr << score_list[ ii ] <<
": " << vars[ ii ] <<
", " << pen <<
"; ";
3090 sstr << score_list[ ii ] <<
" " << vars[ ii ] <<
", " << pen <<
"; ";
3093 ostr <<
" total: " << total <<
" " << sstr.str() <<
"\n";
3153 ConstraintedOptimizationWeightFunc::send_to_node(
int const ,
int const )
const
3177 ConstraintedOptimizationWeightFunc::receive_from_node(
int const ,
int const )
3211 experimental_ddG_( 0 ),
3212 wt_aa_( core::chemical::
aa_ala ),
3213 mut_aa_( core::chemical::
aa_ala )
3225 Size const num_energy_dofs,
3226 int const num_ref_dofs,
3227 int const num_total_dofs,
3234 TR,
false, component_weights, vars,
3235 dE_dvars, num_energy_dofs, num_ref_dofs, num_total_dofs,
3236 fixed_terms, free_score_list, fixed_score_list );
3247 Size const num_energy_dofs,
3248 int const num_ref_dofs,
3250 EnergyMap const & fixed_terms,
3252 ScoreTypes const & fixed_score_list
3255 using namespace core::optimization;
3256 using namespace utility;
3258 // if there are no structures to go through, return immediately
3259 if ( muts_.size() == 0 || wts_.size() == 0 ) return 0.0;
3261 // these vectors are sized to the number of structures there are for a wt name and mutant name;
3262 // they'll be used to determine which structure has the best energy
3263 utility::vector1< Real > wt_energies( wts_.size(), 0.0 );
3264 utility::vector1< Real > mut_energies( muts_.size(), 0.0 );
3266 // go through and come up with a total score for each structure in the wts_ and muts_ list
3267 for ( Size ii = 1; ii <= num_energy_dofs; ++ii ) {
3268 for ( Size jj = 1; jj <= wts_.size(); ++jj ) {
3269 wt_energies[ jj ] += vars[ ii ] * wts_[ jj ]->free_data()[ ii ];
3271 for ( Size jj = 1; jj <= muts_.size(); ++jj ) {
3272 mut_energies[ jj ] += vars[ ii ] * muts_[ jj ]->free_data()[ ii ];
3275 for ( Size ii = 1; ii <= fixed_score_list.size(); ++ii ) {
3276 for ( Size jj = 1; jj <= wts_.size(); ++jj ) {
3277 wt_energies[ jj ] += fixed_terms[ fixed_score_list[ ii ] ] * wts_[ jj ]->fixed_data()[ ii ];
3279 for ( Size jj = 1; jj <= muts_.size(); ++jj ) {
3280 mut_energies[ jj ] += fixed_terms[ fixed_score_list[ ii ] ] * muts_[ jj ]->fixed_data()[ ii ];
3284 // I presume these are the reference energies that are being added in?
3285 // num_energy_dofs is the number of free, non-reference energy parameters in the run -ronj
3286 if ( num_ref_dofs != 0 ) {
3287 for ( Size jj = 1; jj <= wts_.size(); ++jj ) {
3288 wt_energies[ jj ] += vars[ num_energy_dofs + wt_aa_ ];
3290 for ( Size jj = 1; jj <= muts_.size(); ++jj ) {
3291 mut_energies[ jj ] += vars[ num_energy_dofs + mut_aa_ ];
3295 // Identify which wt and mut structure in the lists have the best energy
3296 // arg_min returns the index of the smallest value in a vector
3297 Size const best_wt = arg_min( wt_energies );
3298 Size const best_mut = arg_min( mut_energies );
3300 Real const best_wt_energy = wt_energies[ best_wt ];
3301 Real const best_mut_energy = mut_energies[ best_mut ];
3303 Real const predicted_ddG = best_mut_energy - best_wt_energy;
3304 Real const ddG_diff = predicted_ddG - experimental_ddG_;
3306 for( Size e_dof(1); e_dof <= num_energy_dofs; ++e_dof ) {
3307 dE_dvars[ e_dof ] += 2 * component_weights[ ddG_mutation_correlation ] * ddG_diff * ( muts_[ best_mut ]->free_data()[ e_dof ] - wts_[ best_wt ]->free_data()[ e_dof ] );
3310 if ( num_ref_dofs != 0 ) {
3311 dE_dvars[ num_energy_dofs + mut_aa_ ] += 2 * component_weights[ ddG_mutation_correlation ] * ddG_diff;
3312 dE_dvars[ num_energy_dofs + wt_aa_ ] -= 2 * component_weights[ ddG_mutation_correlation ] * ddG_diff;
3315 //TR << "DDGMutationOptEData::get_score(): predicted: " << ObjexxFCL::fmt::F(4,2,predicted_ddG)
3316 // << ", experimental: " << experimental_ddG_ << ", ddG_diff^2: " << ObjexxFCL::fmt::F(6,3,ddG_diff * ddG_diff)
3317 // << ", tag: " << tag() << std::endl;
3318 return component_weights[ ddG_mutation_correlation ] * ddG_diff * ddG_diff;
3323 std::ostream & ostr,
3328 Size const num_energy_dofs,
3329 int const num_ref_dofs,
3330 int const num_total_dofs,
3337 ostr,
true, component_weights, vars,
3338 dE_dvars, num_energy_dofs, num_ref_dofs, num_total_dofs,
3339 fixed_terms, free_score_list, fixed_score_list );
3344 std::ostream & ostr,
3350 Size const num_energy_dofs,
3351 int const num_ref_dofs,
3358 using namespace core::optimization;
3359 using namespace basic::options;
3360 using namespace basic::options::OptionKeys;
3361 using namespace utility;
3364 if (
muts_.size() == 0 ||
wts_.size() == 0 )
return 0.0;
3374 #define CAP_FA_REP 1
3377 for (
Size ii = 1; ii <= num_energy_dofs; ++ii ) {
3378 for (
Size jj = 1; jj <=
wts_.size(); ++jj ) {
3382 if ( ( score_list[ ii ] ==
fa_rep ) && ( vars[ ii ] *
wts_[ jj ]->free_data()[ ii ] > 10 ) ) { wt_energies[ jj ] += 10; }
3385 wt_energies[ jj ] += vars[ ii ] *
wts_[ jj ]->free_data()[ ii ];
3387 wt_dG_energies[ jj ][ ii ] = vars[ ii ] *
wts_[ jj ]->free_data()[ ii ];
3389 for (
Size jj = 1; jj <=
muts_.size(); ++jj ) {
3392 if ( ( score_list[ ii ] ==
fa_rep ) && ( vars[ ii ] *
muts_[ jj ]->free_data()[ ii ] > 10 ) ) { mut_energies[ jj ] += 10; }
3395 mut_energies[ jj ] += vars[ ii ] *
muts_[ jj ]->free_data()[ ii ];
3397 mut_dG_energies[ jj ][ ii ] = vars[ ii ] *
muts_[ jj ]->free_data()[ ii ];
3400 for (
Size ii = 1; ii <= fixed_score_list.size(); ++ii ) {
3401 for (
Size jj = 1; jj <=
wts_.size(); ++jj ) {
3403 if ( ( fixed_score_list[ ii ] ==
fa_rep ) && ( fixed_terms[ fixed_score_list[ ii ] ] *
wts_[ jj ]->fixed_data()[ ii ] > 10 ) ) { wt_energies[ jj ] += 10; }
3406 wt_energies[ jj ] += fixed_terms[ fixed_score_list[ ii ] ] *
wts_[ jj ]->fixed_data()[ ii ];
3408 wt_dG_energies[ jj ][ num_energy_dofs + ii ] = fixed_terms[ fixed_score_list[ ii ] ] *
wts_[ jj ]->fixed_data()[ ii ];
3410 for (
Size jj = 1; jj <=
muts_.size(); ++jj ) {
3412 if ( ( fixed_score_list[ ii ] ==
fa_rep ) && ( fixed_terms[ fixed_score_list[ ii ] ] *
muts_[ jj ]->fixed_data()[ ii ] > 10 ) ) { mut_energies[ jj ] += 10; }
3415 mut_energies[ jj ] += fixed_terms[ fixed_score_list[ ii ] ] *
muts_[ jj ]->fixed_data()[ ii ];
3417 mut_dG_energies[ jj ][ num_energy_dofs + ii ] = fixed_terms[ fixed_score_list[ ii ] ] *
muts_[ jj ]->fixed_data()[ ii ];
3423 if ( num_ref_dofs != 0 ) {
3424 for (
Size jj = 1; jj <=
wts_.size(); ++jj ) {
3425 wt_energies[ jj ] += vars[ num_energy_dofs +
wt_aa_ ];
3427 for (
Size jj = 1; jj <=
muts_.size(); ++jj ) {
3428 mut_energies[ jj ] += vars[ num_energy_dofs +
mut_aa_ ];
3444 Real predicted_ddG( 0.0 );
3445 Real ddG_diff( 0.0 );
3451 if ( option[ optE::optimize_ddGmutation_straight_mean ] ) {
3453 Real const wt_avg_energy = numeric::statistics::mean( wt_energies.begin(), wt_energies.end(),
Real( 0.0 ) );
3454 Real const mut_avg_energy= numeric::statistics::mean( mut_energies.begin(), mut_energies.end(),
Real( 0.0 ) );
3456 predicted_ddG = mut_avg_energy - wt_avg_energy;
3460 ostr <<
"DDGMutationOptEData pred: " << predicted_ddG <<
" exp: " <<
experimental_ddG_;
3461 ostr <<
" err: " << ddG_diff * ddG_diff <<
" cmptwt_err: ";
3463 ostr <<
" " <<
tag() <<
"\n";
3465 Real const inv_nmuts = 1.0 /
muts_.size();
3466 Real const inv_nwts = 1.0 /
wts_.size();
3467 for(
Size e_dof(1); e_dof <= num_energy_dofs; ++e_dof ) {
3468 for (
Size jj = 1; jj <=
muts_.size(); ++jj ) {
3471 for (
Size jj = 1; jj <=
wts_.size(); ++jj ) {
3476 if ( num_ref_dofs != 0 ) {
3482 }
else if ( option[ optE::optimize_ddGmutation_boltzman_average ] ) {
3484 static Real const inv_kT( option[ optE::inv_kT_nataa ] );
3487 Real best_wt = utility::min( wt_energies );
3488 Real best_mut = utility::min( mut_energies );
3489 Real best_of_best = std::min( best_wt, best_mut );
3490 for (
Size ii = 1; ii <= wt_energies.size(); ++ii ) wt_energies[ ii ] -= best_of_best;
3491 for (
Size ii = 1; ii <= mut_energies.size(); ++ii ) mut_energies[ ii ] -= best_of_best;
3496 Real mut_denom(0.0);
3499 for (
Size ii = 1; ii <= wt_partition.size(); ++ii ) wt_denom += wt_partition[ ii ] = std::exp( -1 * wt_energies[ ii ] * inv_kT );
3500 for (
Size ii = 1; ii <= mut_partition.size(); ++ii ) mut_denom += mut_partition[ ii ] = std::exp( -1 * mut_energies[ ii ] * inv_kT );
3502 Real wt_avg_energy( 0.0 ), mut_avg_energy( 0.0 );
3503 for (
Size ii = 1; ii <= wt_partition.size(); ++ii ) wt_avg_energy += wt_partition[ ii ] * wt_energies[ ii ];
3504 for (
Size ii = 1; ii <= mut_partition.size(); ++ii ) mut_avg_energy += mut_partition[ ii ] * mut_energies[ ii ];
3505 wt_avg_energy /= wt_denom;
3506 mut_avg_energy /= mut_denom;
3508 predicted_ddG = mut_avg_energy - wt_avg_energy;
3512 ostr <<
"DDGMutationOptEData pred: " << predicted_ddG <<
" exp: " <<
experimental_ddG_;
3513 ostr <<
" err: " << ddG_diff * ddG_diff <<
" cmptwt_err: ";
3515 ostr <<
" " <<
tag() <<
"\n";
3518 for(
Size e_dof(1); e_dof <= num_energy_dofs; ++e_dof ) {
3520 Real fmut(0.0), fprimemut(0.0), gmut( mut_denom ), gprimemut(0.0);
3521 for (
Size jj = 1; jj <=
muts_.size(); ++jj ) {
3522 fmut += mut_partition[ jj ] * mut_energies[ jj ];
3523 fprimemut += -1 *
muts_[ jj ]->free_data()[ e_dof ] * inv_kT * mut_partition[ jj ] +
muts_[ jj ]->free_data()[ e_dof ] * mut_partition[ jj ];
3524 gprimemut += -1 *
muts_[ jj ]->free_data()[ e_dof ] * inv_kT * mut_partition[ jj ];
3526 dE_dvars[ e_dof ] += 2 * component_weights[
ddG_mutation_correlation ] * ddG_diff * ( fprimemut * gmut - gprimemut * fmut ) / (gmut*gmut);
3528 Real fwt(0.0), fprimewt(0.0), gwt( wt_denom ), gprimewt(0.0);
3529 for (
Size jj = 1; jj <=
wts_.size(); ++jj ) {
3530 fwt += wt_partition[ jj ] * wt_energies[ jj ];
3531 fprimewt += -1 *
wts_[ jj ]->free_data()[ e_dof ] * inv_kT * wt_partition[ jj ] +
wts_[ jj ]->free_data()[ e_dof ] * wt_partition[ jj ];
3532 gprimewt += -1 *
wts_[ jj ]->free_data()[ e_dof ] * inv_kT * wt_partition[ jj ];
3534 dE_dvars[ e_dof ] -= 2 * component_weights[
ddG_mutation_correlation ] * ddG_diff * ( fprimewt * gwt - gprimewt * fwt ) / (gwt*gwt);
3537 if ( num_ref_dofs != 0 ) {
3545 Size const best_wt = arg_min( wt_energies );
3546 Size const best_mut = arg_min( mut_energies );
3548 Real const best_wt_energy = wt_energies[ best_wt ];
3549 Real const best_mut_energy = mut_energies[ best_mut ];
3551 predicted_ddG = best_mut_energy - best_wt_energy;
3556 ostr <<
"DDGMutationOptEData pred: " << predicted_ddG <<
" exp: " <<
experimental_ddG_;
3557 ostr <<
" err: " << ddG_diff * ddG_diff <<
" cmptwt_err: ";
3559 ostr <<
" " <<
tag() <<
"\n";
3563 for(
Size e_dof(1); e_dof <= num_energy_dofs; ++e_dof ) {
3564 if ( ( score_list[ e_dof ] ==
fa_rep ) && (
muts_[ best_mut ]->free_data()[ e_dof ] -
wts_[ best_wt ]->free_data()[ e_dof ] ) > 10 )
3567 dE_dvars[ e_dof ] += 2 * component_weights[
ddG_mutation_correlation ] * ddG_diff * (
muts_[ best_mut ]->free_data()[ e_dof ] -
wts_[ best_wt ]->free_data()[ e_dof ] );
3570 if ( num_ref_dofs != 0 ) {
3591 Size const num_energy_dofs,
3592 int const num_ref_dofs,
3594 EnergyMap const & fixed_terms,
3596 ScoreTypes const & fixed_score_list
3599 using namespace core::optimization;
3600 using namespace utility;
3602 if ( muts_.size() == 0 || wts_.size() == 0 ) return;
3604 utility::vector1< Real > wt_energies( wts_.size(), 0.0 );
3605 utility::vector1< Real > mut_energies( muts_.size(), 0.0 );
3606 for ( Size ii = 1; ii <= num_energy_dofs; ++ii ) {
3607 for ( Size jj = 1; jj <= wts_.size(); ++jj ) {
3608 wt_energies[ jj ] += vars[ ii ] * wts_[ jj ]->free_data()[ ii ];
3610 for ( Size jj = 1; jj <= muts_.size(); ++jj ) {
3611 mut_energies[ jj ] += vars[ ii ] * muts_[ jj ]->free_data()[ ii ];
3614 for ( Size ii = 1; ii <= fixed_score_list.size(); ++ii ) {
3615 for ( Size jj = 1; jj <= wts_.size(); ++jj ) {
3616 wt_energies[ jj ] += fixed_terms[ fixed_score_list[ ii ] ] * wts_[ jj ]->fixed_data()[ ii ];
3618 for ( Size jj = 1; jj <= muts_.size(); ++jj ) {
3619 mut_energies[ jj ] += fixed_terms[ fixed_score_list[ ii ] ] * muts_[ jj ]->fixed_data()[ ii ];
3623 if ( num_ref_dofs != 0 ) {
3624 for ( Size jj = 1; jj <= wts_.size(); ++jj ) {
3625 wt_energies[ jj ] += vars[ num_energy_dofs + wt_aa_ ];
3627 for ( Size jj = 1; jj <= muts_.size(); ++jj ) {
3628 mut_energies[ jj ] += vars[ num_energy_dofs + mut_aa_ ];
3632 Size const best_wt = arg_min( wt_energies );
3633 Size const best_mut = arg_min( mut_energies );
3635 Real const best_wt_energy = wt_energies[ best_wt ];
3636 Real const best_mut_energy = mut_energies[ best_mut ];
3638 Real const predicted_ddG = best_mut_energy - best_wt_energy;
3639 Real const ddG_diff = predicted_ddG - experimental_ddG_;
3641 TR << "DDGMutationOptEData::print_score(): predicted: " << predicted_ddG << ", experimental: " << experimental_ddG_
3642 << ", ddG_diff^2: " << ddG_diff * ddG_diff << ", tag: " << tag() << std::endl;
3644 ostr << "DDGMutationOptEData pred: " << predicted_ddG << " exp: " << experimental_ddG_;
3645 ostr << " err: " << ddG_diff * ddG_diff << " cmptwt_err: ";
3646 ostr << component_weights[ ddG_mutation_correlation ] * ddG_diff * ddG_diff;
3647 ostr << " " << tag() << "\n";
3649 //ostr << "DDGMutRaw: " << best_wt << " " << best_wt_energy << " " << best_mut << " " << best_mut_energy << " : ";
3650 //for ( Size ii = 1; ii <= wts_[ best_wt ]->free_data().size(); ++ii ) {
3651 // ostr << " ( " << wts_[ best_wt ]->free_data()[ ii ] << " , " << muts_[ best_mut ]->free_data()[ ii ] << " ) ";
3666 for (
Size jj = 1; jj <=
wts_.size(); ++jj ) {
3667 update_range(
wts_[ jj ], free_score_list, fixed_score_list, lower_bound, upper_bound );
3669 for (
Size jj = 1; jj <=
muts_.size(); ++jj ) {
3670 update_range(
muts_[ jj ], free_score_list, fixed_score_list, lower_bound, upper_bound );
3714 if (
wts_.size() > 0 ) {
3715 total +=
sizeof(
Real ) * (
wts_[ 1 ]->free_data().size() +
wts_[ 1 ]->fixed_data().size() ) *
wts_.size();
3717 if (
muts_.size() > 0 ) {
3718 total +=
sizeof(
Real ) * (
muts_[ 1 ]->free_data().size() +
muts_[ 1 ]->fixed_data().size() ) *
muts_.size();
3727 DDGMutationOptEData::send_to_node(
int const destination_node,
int const tag )
const
3732 MPI_Send( & experimental_ddG, 1, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
3733 MPI_Send( & wt_aa, 1, MPI_INT, destination_node, tag, MPI_COMM_WORLD );
3734 MPI_Send( & mut_aa, 1, MPI_INT, destination_node, tag, MPI_COMM_WORLD );
3739 MPI_Send( & nwts, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
3744 MPI_Send( & nmuts, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
3746 if ( nwts == 0 || nmuts == 0 )
return;
3749 Size n_free =
muts_[ 1 ]->free_data().size();
3751 MPI_Send( & n_free, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
3754 Size n_fixed =
muts_[ 1 ]->fixed_data().size();
3756 MPI_Send( & n_fixed, 1, MPI_UNSIGNED_LONG, destination_node, tag, MPI_COMM_WORLD );
3759 Real * free_data =
new Real[ n_free * nwts ];
3760 Real * fixed_data =
new Real[ n_fixed * nwts ];
3761 for (
Size ii = 1; ii <= nwts; ++ ii ) {
3762 for (
Size jj = 1; jj <= n_free; ++jj ) {
3763 free_data[ ( ii - 1 ) * n_free + ( jj - 1 ) ] =
wts_[ ii ]->free_data()[ jj ];
3765 for (
Size jj = 1; jj <= n_fixed; ++jj ) {
3766 fixed_data[ ( ii - 1 ) * n_fixed + ( jj - 1 ) ] =
wts_[ ii ]->fixed_data()[ jj ];
3772 MPI_Send( free_data, nwts * n_free, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
3776 MPI_Send( fixed_data, nwts * n_fixed, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
3781 Real * decoy_free_data =
new Real[ n_free * nmuts ];
3782 Real * decoy_fixed_data =
new Real[ n_fixed * nmuts ];
3783 for (
Size ii = 1; ii <= nmuts; ++ ii ) {
3784 for (
Size jj = 1; jj <= n_free; ++jj ) {
3785 decoy_free_data[ ( ii - 1 ) * n_free + ( jj - 1 ) ] =
muts_[ ii ]->free_data()[ jj ];
3787 for (
Size jj = 1; jj <= n_fixed; ++jj ) {
3788 decoy_fixed_data[ ( ii - 1 ) * n_fixed + ( jj - 1 ) ] =
muts_[ ii ]->fixed_data()[ jj ];
3793 MPI_Send( decoy_free_data, nmuts * n_free, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
3797 MPI_Send( decoy_fixed_data, nmuts * n_fixed, MPI_DOUBLE, destination_node, tag, MPI_COMM_WORLD );
3799 delete [] free_data;
3800 delete [] fixed_data;
3802 delete [] decoy_free_data;
3803 delete [] decoy_fixed_data;
3805 OptEPositionData::send_to_node( destination_node, tag );
3810 DDGMutationOptEData::receive_from_node(
int const source_node,
int const tag )
3816 int wt_aa( 0 ), mut_aa(0);
3817 MPI_Recv( &
experimental_ddG_, 1, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
3818 MPI_Recv( & wt_aa, 1, MPI_INT, source_node, tag, MPI_COMM_WORLD, &stat );
3819 MPI_Recv( & mut_aa, 1, MPI_INT, source_node, tag, MPI_COMM_WORLD, &stat );
3820 wt_aa_ =
static_cast< AA > ( wt_aa );
3825 MPI_Recv( & nwts, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
3829 MPI_Recv( & nmuts, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
3831 if ( nwts == 0 || nmuts == 0 )
return;
3832 wts_.reserve( nwts );
3833 muts_.reserve( nmuts );
3837 MPI_Recv( & n_free, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
3841 MPI_Recv( & n_fixed, 1, MPI_UNSIGNED_LONG, source_node, tag, MPI_COMM_WORLD, &stat );
3844 Real * free_data =
new Real[ n_free * nwts ];
3845 Real * fixed_data =
new Real[ n_fixed * nwts ];
3848 MPI_Recv( free_data, nwts * n_free, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
3851 MPI_Recv( fixed_data, nwts * n_fixed, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
3855 for (
Size ii = 1; ii <= nwts; ++ ii ) {
3856 for (
Size jj = 1; jj <= n_free; ++jj ) {
3857 free_data_v[ jj ] = free_data[ ( ii - 1 ) * n_free + ( jj - 1 ) ];
3859 for (
Size jj = 1; jj <= n_fixed; ++jj ) {
3860 fixed_data_v[ jj ] = fixed_data[ ( ii - 1 ) * n_fixed + ( jj - 1 ) ];
3862 wts_.push_back(
new SingleStructureData( free_data_v, fixed_data_v ) );
3866 delete [] free_data; free_data = 0;
3867 delete [] fixed_data; fixed_data = 0;
3870 free_data =
new Real[ n_free * nmuts ];
3871 fixed_data =
new Real[ n_fixed * nmuts ];
3874 MPI_Recv( free_data, nmuts * n_free, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
3877 MPI_Recv( fixed_data, nmuts * n_fixed, MPI_DOUBLE, source_node, tag, MPI_COMM_WORLD, &stat );
3879 for (
Size ii = 1; ii <= nmuts; ++ ii ) {
3880 for (
Size jj = 1; jj <= n_free; ++jj ) {
3881 free_data_v[ jj ] = free_data[ ( ii - 1 ) * n_free + ( jj - 1 ) ];
3883 for (
Size jj = 1; jj <= n_fixed; ++jj ) {
3884 fixed_data_v[ jj ] = fixed_data[ ( ii - 1 ) * n_fixed + ( jj - 1 ) ];
3886 muts_.push_back(
new SingleStructureData( free_data_v, fixed_data_v ) );
3890 delete [] free_data;
3891 delete [] fixed_data;
3893 OptEPositionData::receive_from_node( source_node, tag );
3921 wts_.push_back( wt );
3927 muts_.push_back( mut );
3939 for ( OptEPositionDataOPs::const_iterator pos( data_.begin() );
3940 pos != data_.end(); ++pos ) {
3941 num_rots += (*pos)->size();
3953 runtime_assert( data_.empty() );
3956 std::ifstream infile( filename.c_str() );
3960 using utility::string_split;
3963 while( getline( infile, line ) ) {
3964 Strings words( string_split( line,
' ' ) );
3965 if ( line.substr(0,12) ==
"fixed terms:" ) {
3966 for ( Strings::iterator term( words.begin()+2 ); term != words.end(); ++term ) {
3969 }
else if ( line.substr(0,11) ==
"free terms:" ) {
3970 for ( Strings::iterator term( words.begin()+2 ); term != words.end(); ++term ) {
3977 runtime_assert( !free_terms.empty() );
3978 runtime_assert( ( fixed_terms == fixed_energy_terms_ ) || fixed_energy_terms_.empty() );
3979 runtime_assert( ( free_terms == energy_terms_ ) || energy_terms_.empty() );
3980 fixed_energy_terms_ = fixed_terms;
3981 energy_terms_ = free_terms;
3983 while ( getline( infile, line ) ) {
3984 Strings words( string_split( line,
' ' ) );
3986 if ( words.size() == 0 ) { utility_exit_with_message(
"Bad line from optE data file"); }
3987 if ( words[ 1 ] !=
"optE_position_data_type" ) { utility_exit_with_message(
"Bad line from optE data file"); }
3991 new_position_data->read_from_file( infile );
3992 add_position_data( new_position_data );
3996 TR <<
"Read in " << num_rotamers() <<
" rotamers at "
3997 << num_positions() <<
" positions from file " << filename << std::endl;
4006 std::ofstream outfile( filename.c_str() );
4008 outfile <<
"# data line format:" << std::endl <<
"# rot_number, this_aa,"
4009 <<
" [ energies for fixed terms ], [ energies for free terms ]"
4012 outfile <<
"fixed terms:";
4013 for ( ScoreTypes::const_iterator et( fixed_energy_terms_.begin() );
4014 et != fixed_energy_terms_.end(); ++et ) {
4019 outfile <<
"free terms:";
4020 for ( ScoreTypes::const_iterator et( energy_terms_.begin() );
4021 et != energy_terms_.end(); ++et ) {
4027 for ( OptEPositionDataOPs::const_iterator pos( position_data_begin() );
4028 pos != position_data_end(); ++pos ) {
4029 outfile <<
"optE_position_data_type " << (*pos)->type() <<
"\n";
4030 (*pos)->write_to_file( outfile );
4033 TR <<
"Wrote " << num_rotamers() <<
" rotamers at "
4034 << num_positions() <<
" positions to file " << filename << std::endl;
4044 std::ofstream outfile( filename.c_str(), std::ios::out | std::ios::binary );
4045 Size const npositions( data_.size() );
4046 outfile.write( (
char*) &npositions,
sizeof(
Size) );
4047 for ( OptEPositionDataOPs::const_iterator pos( data_.begin() ); pos != data_.end(); ++pos ) {
4050 (*pos)->write_to_binary_file( outfile );
4053 TR <<
"Wrote " << num_rotamers() <<
" rotamers at "
4054 << num_positions() <<
" positions to binary file " << filename << std::endl;
4065 std::ifstream infile( filename.c_str(), std::ios::in | std::ios::binary );
4068 while ( infile.read( (
char*) &npositions,
sizeof(
Size) ) ) {
4069 for (
Size i(1); i <= npositions; ++i ) {
4073 pos_data->read_from_binary_file( infile );
4074 add_position_data( pos_data );
4079 TR <<
"Read in " << num_rotamers() <<
" rotamers at "
4080 << num_positions() <<
" positions from binary file " << filename << std::endl;
4091 std::map< std::string, OptEPositionDataType >
4129 initialize_optE_type_name_map();
4131 return optE_type_2_optE_type_name_[
type ];
4137 initialize_optE_type_name_map();
4138 return optE_type_name_map_.find( name ) != optE_type_name_map_.end();
4144 initialize_optE_type_name_map();
4145 runtime_assert( is_optE_type_name( name ));
4146 return optE_type_name_map_[ name ];
4153 if ( optE_type_name_map_initialized_ )
return;
4155 optE_type_name_map_initialized_ =
true;
4160 optE_type_2_optE_type_name_[
pssm_data ] =
"pssm_data";
4171 optE_type_name_map_[ optE_type_2_optE_type_name_[ ii ] ] =
static_cast< OptEPositionDataType > ( ii );