26 #include <basic/database/open.hh>
27 #include <basic/options/option.hh>
28 #include <basic/Tracer.hh>
31 #include <numeric/angle.functions.hh>
32 #include <numeric/interpolation/periodic_range/half/interpolation.hh>
33 #include <numeric/random/random.hh>
36 #include <utility/io/izstream.hh>
38 #if defined(WIN32) || defined(__CYGWIN__)
47 #include <basic/options/keys/score.OptionKeys.gen.hh>
48 #include <basic/options/keys/corrections.OptionKeys.gen.hh>
49 #include <basic/options/keys/in.OptionKeys.gen.hh>
50 #include <basic/options/keys/OptionKeys.hh>
53 #include <utility/vector1.hh>
54 #include <ObjexxFCL/FArray2A.hh>
58 using namespace ObjexxFCL;
64 Ramachandran2B::~Ramachandran2B() {}
66 basic::Tracer
T(
"core.scoring.Ramachandran2B");
68 Real const Ramachandran2B::binw_( 10.0 );
70 Real const Ramachandran2B::rama_sampling_thold_(0.00075 );
71 Real const Ramachandran2B::rama_sampling_factor_( 10.0 );
72 ObjexxFCL::FArray4D< Real > Ramachandran2B::left_ram_probabil_( Ramachandran2B::n_phi_, Ramachandran2B::n_psi_, Ramachandran2B::n_aa_, Ramachandran2B::n_aa_ );
73 ObjexxFCL::FArray4D< Real > Ramachandran2B::right_ram_probabil_( Ramachandran2B::n_phi_, Ramachandran2B::n_psi_, Ramachandran2B::n_aa_, Ramachandran2B::n_aa_ );
75 Ramachandran2B::Ramachandran2B() :
76 ram_energ_( n_phi_, n_psi_, n_aa_, 0.0 ),
77 ram_entropy_( n_aa_, 0.0 ),
78 ram_energ_left_( n_phi_, n_psi_, n_aa_, n_aa_, 0.0 ),
79 ram_entropy_left_( n_aa_, n_aa_, 0.0 ),
80 ram_energ_right_( n_phi_, n_psi_, n_aa_, n_aa_, 0.0 ),
81 ram_entropy_right_( n_aa_, n_aa_, 0.0 ),
82 rama_score_limit_( 20 )
136 for (
int ii = 1; ii <= total_residue; ++ii )
140 Real rama_score,dphi,dpsi;
142 T <<
"Rama:eval_all: residue " << ii <<
" " << pose.
residue(ii).
name() <<
143 " " << ii-1 <<
" " << pose.
residue(ii-1).
name() <<
" " << ii+1 <<
" " <<
144 pose.
residue(ii+1).
name() <<
" = " << rama_score << std::endl;
145 pose_energies.onebody_energies( ii )[
rama] = rama_score;
166 using namespace numeric;
176 if ( phi == 0.0 || psi == 0.0 || rsd.
is_terminus() ) {
198 using namespace numeric;
207 if ( phi == 0.0 || psi == 0.0 ) {
214 if( ! basic::options::option[ basic::options::OptionKeys::score::ramaneighbors ] ) {
222 Real rama_L(0.0), drama_dphi_L(0.0), drama_dpsi_L(0.0);
223 Real rama_R(0.0), drama_dphi_R(0.0), drama_dpsi_R(0.0);
224 Real rama_0(0.0), drama_dphi_0(0.0), drama_dpsi_0(0.0);
225 rama_L =
RamaE_Lower(center, left_aa, drama_dphi_L, drama_dpsi_L);
226 rama_R =
RamaE_Upper(center, right_aa, drama_dphi_R, drama_dpsi_R);
227 rama_0 =
RamaE(center, drama_dphi_0, drama_dpsi_0);
229 rama = rama_L + rama_R - rama_0;
230 drama_dphi = drama_dphi_L + drama_dphi_R - drama_dphi_0;
231 drama_dpsi = drama_dpsi_L + drama_dpsi_R - drama_dpsi_0;
244 FArray2A< Real >
const & rama_for_res
247 using namespace numeric::interpolation::periodic_range::half;
248 Real interp_E = bilinearly_interpolated( phi, psi,
binw_,
n_phi_, rama_for_res, drama_dphi, drama_dpsi );
250 rama = entropy + interp_E;
253 if ( ! basic::options::option[basic::options::OptionKeys::corrections::score::rama_not_squared] ) {
261 drama_dphi *= 2.0 *
rama;
262 drama_dpsi *= 2.0 *
rama;
281 Real drama_dphi, drama_dpsi;
282 return RamaE_Lower( rsd, neighbor, drama_dphi, drama_dpsi );
293 using namespace numeric;
294 using namespace basic::options;
295 using namespace basic::options::OptionKeys;
304 if ( phi == 0.0 || psi == 0.0 ) {
309 if( ! option[ score::ramaneighbors ] ) {
313 FArray2A< Real >::IR
const zero_index( 0,
n_phi_ - 1);
314 FArray2A< Real >
const rama_for_res(
ram_energ_left_(1, 1, rsd.
aa(), neighbor), zero_index, zero_index );
327 Real drama_dphi, drama_dpsi;
328 return RamaE_Upper( rsd, neighbor, drama_dphi, drama_dpsi );
339 using namespace numeric;
348 if ( phi == 0.0 || psi == 0.0 ) {
353 if( ! basic::options::option[ basic::options::OptionKeys::score::ramaneighbors ] )
358 FArray2A< Real >::IR
const zero_index( 0,
n_phi_ - 1);
359 FArray2A< Real >
const rama_for_res(
ram_energ_right_(1, 1, rsd.
aa(), neighbor), zero_index, zero_index );
372 Real drama_dphi(0.0), drama_dpsi(0.0);
373 return RamaE( rsd, drama_dphi, drama_dpsi );
384 using namespace numeric;
393 if ( phi == 0.0 || psi == 0.0 ) {
429 using namespace numeric;
431 FArray2A< Real >::IR
const zero_index( 0,
n_phi_ - 1);
432 FArray2A< Real >
const rama_for_res(
ram_energ_(1, 1, res_aa ), zero_index, zero_index );
443 using namespace basic::options;
445 using namespace basic::options::OptionKeys;
447 int aa_num( 0 ), aa_num_left( 0 ), aa_num_right( 0 );
448 int phi_bin( 0 ), psi_bin( 0 ), ss_type( 0 );
450 Real tProb( 0.0 ), tEnergy( 0.0 );
452 Size line_count( 0 );
458 clock_t starttime = clock();
461 std::string energyFileName = basic::options::option[ in::file::rama2b_map ]().name() ;
462 T <<
"Read in ramachandran map: " << energyFileName << std::endl;
463 utility::io::izstream iRamaEnergy;
464 basic::database::open( iRamaEnergy, energyFileName );
465 while( ! iRamaEnergy.eof() ) {
467 iRamaEnergy >> aa_num >> aa_num_left >> aa_num_right >> ss_type >> phi_bin >> psi_bin >> tCounts >> tProb >> tEnergy;
470 if(aa_num >
n_aa_)
continue;
472 int phiIndex = phi_bin / 10 + 1;
473 int psiIndex = psi_bin / 10 + 1;
474 Real entropy = -1.0 * tProb * tEnergy;
477 ram_energ_( phiIndex, psiIndex, aa_num ) = tEnergy;
479 }
else if( aa_num_left !=
nullaa ) {
483 }
else if( aa_num_right !=
nullaa ) {
494 clock_t stoptime = clock();
495 T <<
"Reading Rama from database took " << ((double) stoptime - starttime)/CLOCKS_PER_SEC <<
" seconds" << std::endl;
510 current_rama_sampling_table.resize(
n_aa_);
512 FArray2A< Real >::IR
const zero_index( 0,
n_phi_ - 1);
513 for (
int left_aa=1; left_aa<=
n_aa_; left_aa++) {
514 current_rama_sampling_table[left_aa].resize(
n_aa_);
515 for (
int aa=1; aa<=
n_aa_; aa++) {
516 current_rama_sampling_table[left_aa][aa].resize(
n_aa_);
517 FArray2A< Real >
const rama_for_res(
left_ram_probabil_(1, 1, left_aa, aa), zero_index, zero_index );
519 Size actual_allowed = 0;
525 for (
int i=0; i<
n_phi_; i++) {
526 for (
int j=0; j<
n_psi_; j++) {
527 Real res_prob = rama_for_res(i,j);
533 if (res_prob < min_val) min_val = res_prob;
534 else if (res_prob > max_val) max_val = res_prob;
539 Real cur_phi, cur_psi;
540 if (i <= n_phi_ / 2) {
544 cur_phi = 0 - (n_phi_ - i);
546 if (j <= n_psi_ / 2) {
550 cur_psi = 0 - (n_psi_ - j);
555 if (torsion_bin !=
'X')
557 if (torsion_bin ==
'X' || cur_tb == torsion_bin) {
559 res_probs[actual_allowed] = res_prob;
560 torsion[1] = static_cast <
Real> ( cur_phi *
binw_);
561 torsion[2] = static_cast <
Real> ( cur_psi *
binw_);
562 res_torsions[actual_allowed] = torsion;
584 for (
Size tor = 1; tor <= actual_allowed; tor++) {
585 Size n_indices =
Size(( res_probs[tor] / min_val ) * rama_sampling_factor_);
587 for (
Size ind=1; ind<=n_indices; ind++) {
589 if( (
int(index) < 1) || (
int(index) > (
int)current_rama_sampling_table[left_aa][aa].
size()) ){
590 std::cerr <<
"index exceeded size of rama_sampling_table_[aa] index=" +
591 ObjexxFCL::string_of( (index) ) +
592 " rama_sampling_table_[aa].size()=" +
593 ObjexxFCL::string_of( current_rama_sampling_table[left_aa][aa].
size() ) +
594 " AA=" + ObjexxFCL::string_of( aa );
598 if( ((
int)tor < 1) || ((
int)tor > (
int)res_torsions.size()) ){
599 std::cerr <<
"tor exceeded size of rama_sampling_table_[aa] index=" +
600 ObjexxFCL::string_of( tor ) +
601 " res_torsions.size()=" + ObjexxFCL::string_of( res_torsions.size() ) +
602 " AA=" + ObjexxFCL::string_of( aa );
606 current_rama_sampling_table[left_aa][aa][index] = res_torsions[tor];
609 current_rama_sampling_table[left_aa][aa].resize(index);
615 if (torsion_bin ==
'X') {
650 Size index = numeric::random::random_range(1, n_torsions);
655 (numeric::random::uniform() *
binw_ * 0.5 * (numeric::random::uniform() < 0.5 ? -1 : 1));
657 (numeric::random::uniform() *
binw_ * 0.5 * (numeric::random::uniform() < 0.5 ? -1 : 1));
673 current_rama_sampling_table.resize(
n_aa_);
675 FArray2A< Real >::IR
const zero_index( 0,
n_phi_ - 1);
676 for (
int aa=1; aa<=
n_aa_; aa++) {
677 current_rama_sampling_table[aa].resize(
n_aa_);
678 for (
int right_aa=1; right_aa<=
n_aa_; right_aa++) {
679 FArray2A< Real >
const rama_for_res(
right_ram_probabil_(1, 1, aa, right_aa), zero_index, zero_index );
681 Size actual_allowed = 0;
687 for (
int i=0; i<
n_phi_; i++) {
688 for (
int j=0; j<
n_psi_; j++) {
689 Real res_prob = rama_for_res(i,j);
695 if (res_prob < min_val) min_val = res_prob;
696 else if (res_prob > max_val) max_val = res_prob;
701 Real cur_phi, cur_psi;
702 if (i <= n_phi_ / 2) {
706 cur_phi = 0 - (n_phi_ - i);
708 if (j <= n_psi_ / 2) {
712 cur_psi = 0 - (n_psi_ - j);
716 if (torsion_bin !=
'X')
718 if (torsion_bin ==
'X' || cur_tb == torsion_bin) {
720 res_probs[actual_allowed] = res_prob;
721 torsion[1] = static_cast <
Real> ( cur_phi *
binw_);
722 torsion[2] = static_cast <
Real> ( cur_psi *
binw_);
723 res_torsions[actual_allowed] = torsion;
745 for (
Size tor = 1; tor <= actual_allowed; tor++) {
746 Size n_indices =
Size(( res_probs[tor] / min_val ) * rama_sampling_factor_);
748 for (
Size ind=1; ind<=n_indices; ind++) {
750 if( (
int(index) < 1) || (
int(index) > (
int)current_rama_sampling_table[aa][right_aa].
size()) ){
751 std::cerr <<
"index exceeded size of rama_sampling_table_[aa] index=" +
752 ObjexxFCL::string_of( (index) ) +
753 " rama_sampling_table_[aa].size()=" +
754 ObjexxFCL::string_of( current_rama_sampling_table[aa][right_aa].
size() ) +
755 " AA=" + ObjexxFCL::string_of( aa );
759 if( ((
int)tor < 1) || ((
int)tor > (
int)res_torsions.size()) ){
760 std::cerr <<
"tor exceeded size of rama_sampling_table_[aa] index=" +
761 ObjexxFCL::string_of( tor ) +
762 " res_torsions.size()=" + ObjexxFCL::string_of( res_torsions.size() ) +
763 " AA=" + ObjexxFCL::string_of( aa );
767 current_rama_sampling_table[aa][right_aa][index] = res_torsions[tor];
770 current_rama_sampling_table[aa][right_aa].resize(index);
782 if (torsion_bin ==
'X') {
816 Size index = numeric::random::random_range(1, n_torsions);
821 (numeric::random::uniform() *
binw_ * 0.5 * (numeric::random::uniform() < 0.5 ? -1 : 1));
823 (numeric::random::uniform() *
binw_ * 0.5 * (numeric::random::uniform() < 0.5 ? -1 : 1));
829 return toupper(torsion_bin) - toupper(
'A') + 1;
869 char const torsion_bin
886 Size index = numeric::random::random_range(1, n_torsions);
891 (numeric::random::uniform() *
binw_ * 0.5 * (numeric::random::uniform() < 0.5 ? -1 : 1));
893 (numeric::random::uniform() *
binw_ * 0.5 * (numeric::random::uniform() < 0.5 ? -1 : 1));
903 char const torsion_bin
918 Size index = numeric::random::random_range(1, n_torsions);
923 (numeric::random::uniform() *
binw_ * 0.5 * (numeric::random::uniform() < 0.5 ? -1 : 1));
925 (numeric::random::uniform() *
binw_ * 0.5 * (numeric::random::uniform() < 0.5 ? -1 : 1));
935 std::map< char, core::Size > & tb_frequencies )
const
939 const_cast< Ramachandran2B * > (
this)->init_rama_sampling_tables_by_torsion_bin();
952 std::map< char, core::Size > & tb_frequencies )
const
956 const_cast< Ramachandran2B * > (
this)->init_rama_sampling_tables_by_torsion_bin();