31 #include <basic/database/open.hh>
34 #include <basic/datacache/BasicDataCache.hh>
44 #include <basic/options/option.hh>
45 #include <basic/options/keys/membrane.OptionKeys.gen.hh>
46 #include <basic/options/keys/in.OptionKeys.gen.hh>
49 #include <utility/io/izstream.hh>
53 #include <utility/vector1.hh>
54 #include <numeric/xyzVector.hh>
55 #include <numeric/xyz.functions.hh>
56 #include <numeric/random/random.hh>
57 #include <numeric/conversions.hh>
59 #include <basic/Tracer.hh>
60 #include <ObjexxFCL/FArray1D.hh>
61 #include <ObjexxFCL/FArray2D.hh>
62 #include <ObjexxFCL/format.hh>
66 static numeric::random::RandomGenerator
RG(280628);
67 static basic::Tracer
TR(
"core.scoring.MembranePotential");
98 cen_dist7_pad( 0.65 ),
99 cen_dist10_pad( 1.0 ),
100 cen_dist12_pad( 1.2 ),
102 cen_dist5_pad_plus ( cen_dist5_pad + 25.0 ),
103 cen_dist6_pad_plus( cen_dist6_pad + 36.0 ),
104 cen_dist7_pad_plus ( cen_dist7_pad + 56.25 ),
105 cen_dist10_pad_plus( cen_dist10_pad + 100.0 ),
106 cen_dist12_pad_plus( cen_dist12_pad + 144.0 ),
108 cen_dist5_pad_minus ( cen_dist5_pad - 25.0 ),
109 cen_dist7_pad_minus ( cen_dist7_pad - 56.25 ),
110 cen_dist10_pad_minus( cen_dist10_pad - 100.0 ),
111 cen_dist12_pad_minus( cen_dist12_pad - 144.0 ),
113 cen_dist5_pad_hinv ( 0.5 / cen_dist5_pad ),
114 cen_dist6_pad_hinv ( 0.5 / cen_dist6_pad ),
115 cen_dist7_pad_hinv ( 0.5 / cen_dist7_pad ),
116 cen_dist10_pad_hinv( 0.5 / cen_dist10_pad ),
117 cen_dist12_pad_hinv( 0.5 / cen_dist12_pad ),
122 Size const max_aa( 20 );
123 Size const env_log_table_cen6_bins( 15 );
124 Size const env_log_table_cen10_bins( 40 );
125 Size const pair_log_table_size( 5 );
126 Size const cbeta_den_table_size( 45 );
127 Size const max_mem_layers( 3 );
128 Size const min_mem_layers( 2 );
132 membrane_normal_magnitude_=numeric::conversions::radians(basic::options::option[ basic::options::OptionKeys::membrane::normal_mag ]());
134 smooth_move_frac_=basic::options::option[ basic::options::OptionKeys::membrane::smooth_move_frac ]();
135 no_interpolate_Mpair_=basic::options::option[ basic::options::OptionKeys::membrane::no_interpolate_Mpair ]();
136 Menv_penalties_=basic::options::option[ basic::options::OptionKeys::membrane::Menv_penalties ]();
137 Membed_init_=basic::options::option[ basic::options::OptionKeys::membrane::Membed_init ]();
138 memb_center_search_=basic::options::option[ basic::options::OptionKeys::membrane::center_search ]();
139 memb_normal_search_=basic::options::option[ basic::options::OptionKeys::membrane::normal_search ]();
148 mem_env_log6_.dimension( max_aa, max_mem_layers,env_log_table_cen6_bins );
149 utility::io::izstream stream;
150 basic::database::open( stream,
"scoring/score_functions/MembranePotential/CEN6_mem_env_log.txt" );
151 for (
Size i=1; i<= max_aa; ++i ){
152 getline( stream, line );
153 std::istringstream l(line);
155 if ( l.fail() || tag !=
"MEM_ENV_LOG_CEN6:" ) utility_exit_with_message(
"bad format for scoring/score_functions/MembranePotential/CEN6_mem_env_log.txt (cen6)");
156 for(
Size j=1;j<=max_mem_layers;++j) {
157 for(
Size k=1;k<=env_log_table_cen6_bins;++k) {
164 mem_env_log10_.dimension( max_aa, max_mem_layers,env_log_table_cen10_bins );
166 utility::io::izstream stream;
167 basic::database::open( stream,
"scoring/score_functions/MembranePotential/CEN10_mem_env_log.txt" );
168 for (
Size i=1; i<= max_aa; ++i ){
169 getline( stream, line );
170 std::istringstream l(line);
172 if ( l.fail() || tag !=
"MEM_ENV_LOG_CEN10:" ) utility_exit_with_message(
"bad format for scoring/score_functions/MembranePotential/CEN10_mem_env_log.txt (cen10)");
173 for(
Size j=1;j<=max_mem_layers;++j) {
174 for(
Size k=1;k<=env_log_table_cen10_bins;++k) {
189 utility::io::izstream stream;
190 basic::database::open( stream,
"scoring/score_functions/MembranePotential/memcbeta_den.txt" );
193 getline( stream, line );
195 std::istringstream l(line);
197 for (
Size i=1; i<= cbeta_den_table_size; ++i ){
200 if ( l.fail() || tag !=
"MEMCBETA_DEN6:" ) utility_exit_with_message(
"bad format for scoring/score_functions/MembranePotential/memcbeta_den.txt (DEN6)");
202 getline( stream, line );
204 std::istringstream l(line);
206 for (
Size i=1; i<= cbeta_den_table_size; ++i ){
209 if ( l.fail() || tag !=
"MEMCBETA_2TM_DEN6:" ) utility_exit_with_message(
"bad format for scoring/score_functions/MembranePotential/memcbeta_den.txt (2TM_DEN6)");
211 getline( stream, line );
213 std::istringstream l(line);
215 for (
Size i=1; i<= cbeta_den_table_size; ++i ){
218 if ( l.fail() || tag !=
"MEMCBETA_4TM_DEN6:" ) utility_exit_with_message(
"bad format for scoring/score_functions/MembranePotential/memcbeta_den.txt (4TM_DEN6)");
224 getline( stream, line );
225 std::istringstream l(line);
227 for (
Size i=1; i<= cbeta_den_table_size; ++i ){
230 if ( l.fail() || tag !=
"MEMCBETA_DEN12:" ) utility_exit_with_message(
"bad format for scoring/score_functions/MembranePotential/memcbeta_den.txt (DEN12)");
232 getline( stream, line );
234 std::istringstream l(line);
236 for (
Size i=1; i<= cbeta_den_table_size; ++i ){
239 if ( l.fail() || tag !=
"MEMCBETA_2TM_DEN12:" ) utility_exit_with_message(
"bad format for scoring/score_functions/MembranePotential/memcbeta_den.txt (2TM_DEN12)");
241 getline( stream, line );
243 std::istringstream l(line);
245 for (
Size i=1; i<= cbeta_den_table_size; ++i ){
248 if ( l.fail() || tag !=
"MEMCBETA_4TM_DEN12:" ) utility_exit_with_message(
"bad format for scoring/score_functions/MembranePotential/memcbeta_den.txt (4TM_DEN12)");
255 mem_pair_log_.dimension( min_mem_layers,pair_log_table_size,max_aa, max_aa );
257 utility::io::izstream stream;
258 basic::database::open( stream,
"scoring/score_functions/MembranePotential/mem_pair_log.txt" );
259 for (
Size i=1; i<= min_mem_layers;++i) {
260 for (
Size j=1; j<= pair_log_table_size; ++j ) {
261 for (
Size k=1; k<= max_aa; ++k ) {
262 getline( stream, line );
263 std::istringstream l(line);
265 l >> tag >> ii >> jj >> aa;
266 assert(
Size(aa) == k );
267 for (
Size n=1;n<=max_aa;++n)
271 if ( l.fail() || ii != i || jj != j || tag !=
"MEM_PAIR_LOG:" ) utility_exit_with_message(
"scoring/score_functions/MembranePotential/mem_pair_log.txt");
293 Real & membrane_env_score
299 evaluate_env(pose,rsd,MembraneDepth,membrane_env_score);
304 Real depth=dot(
xyz-center,normal)+30;
309 membrane_env_score+=50*termini_pen;
314 membrane_env_score=100;
323 Real const MembraneDepth,
324 Real & membrane_env_score
331 int layer1, layer2, layer;
334 Real const env6_weight=1.0;
335 Real const env10_weight=1.0;
341 if (fcen6 > 15) fcen6 = 15 ;
342 if (fcen10 > 40) fcen10 = 40;
346 if ( ( MembraneDepth < 11.0 ) || ( MembraneDepth > 49.0 ) ) {
352 membrane_env_score = score6 + score10;
355 else if ( ( MembraneDepth >= 11.0 && MembraneDepth <= 13.0 ) || ( MembraneDepth >= 47.0 && MembraneDepth <= 49.0 ) ) {
361 if ( MembraneDepth <= 13.0 ) {
366 z = 2*std::abs( (MembraneDepth - low) ) / t2;
367 zn = std::pow( z, s2 );
370 Real score6_layer2( env6_weight*
mem_env_log6_( rsd.
aa(), layer2,
static_cast< int >( fcen6 ) ) );
371 Real score10_layer2( env10_weight*
mem_env_log10_( rsd.
aa(), layer2,
static_cast< int >( fcen10 ) ) );
372 Real score6_layer1( env6_weight*
mem_env_log6_( rsd.
aa(), layer1,
static_cast< int >( fcen6 ) ) );
373 Real score10_layer1( env10_weight*
mem_env_log10_( rsd.
aa(), layer1,
static_cast< int >( fcen10 ) ) );
375 membrane_env_score = f * ( score6_layer2 + score10_layer2 ) + ( 1 - f ) * ( score6_layer1 + score10_layer1 );
377 if ( MembraneDepth <= 12.0 || MembraneDepth >= 48.0 ) {
384 else if ( ( MembraneDepth > 13.0 && MembraneDepth < 17.0 ) || ( MembraneDepth > 43.0 && MembraneDepth < 47.0 ) ) {
390 membrane_env_score = score6 + score10;
392 else if ( ( MembraneDepth >= 17.0 && MembraneDepth <= 19.0 ) || ( MembraneDepth >= 41.0 && MembraneDepth <= 43.0 ) ) {
397 if ( MembraneDepth <= 19.0 ) {
402 z = 2*std::abs( (MembraneDepth - low) ) / t3;
403 zn = std::pow( z, s3 );
406 Real score6_layer2(env6_weight*
mem_env_log6_( rsd.
aa(), layer2,
static_cast< int >( fcen6 )));
407 Real score10_layer2( env10_weight*
mem_env_log10_( rsd.
aa(), layer2,
static_cast< int >( fcen10 ) ) );
408 Real score6_layer1( env6_weight*
mem_env_log6_( rsd.
aa(), layer1,
static_cast< int >( fcen6 ) ) );
409 Real score10_layer1( env10_weight*
mem_env_log10_( rsd.
aa(), layer1,
static_cast< int >( fcen10 ) ) );
411 membrane_env_score = f * ( score6_layer2 + score10_layer2 ) + ( 1 - f ) * ( score6_layer1 + score10_layer1 );
413 if ( MembraneDepth <= 18.0 || MembraneDepth >= 42.0 ) {
429 membrane_env_score = score6+score10;
432 membrane_env_score*=0.5;
435 membrane_env_score = 0.0;
444 Real & membrane_cb_score
451 Real membrane_cb_score6,membrane_cb_score12;
455 int const interp1 =
static_cast< int >( fcen6 );
456 int const interp3 =
static_cast< int >( fcen12 );
459 Real const interp2 = fcen6-interp1;
466 }
else if ( TMHs <= 4 ) {
476 membrane_cb_score12 =
480 membrane_cb_score = (membrane_cb_score6+membrane_cb_score12);
490 Real & membrane_pair_score
494 membrane_pair_score = 0.0;
525 Real AverageDepth=(MembraneDepth1+MembraneDepth2)/2;
526 if(MembraneDepth1 > 18 &&
527 MembraneDepth1 < 42 &&
528 MembraneDepth2 >18 &&
551 if ( interp2 < 0.0 ) interp2 = 0.0;
555 if ( interp2 > 1.0 ) interp2 = 1.0;
561 if( std::abs(AverageDepth - 18)<4)
563 f=1/(1+std::exp(1.5*(18-AverageDepth)));
564 membrane_pair_score = ( ( 1.0f - interp2 ) * ((1-f)*
mem_pair_log_( 1, icon , aa1, aa2 ) + f*
mem_pair_log_( 2, icon , aa1, aa2 )) +
566 }
else if(std::abs(AverageDepth - 42)<4) {
568 f=1/(1+std::exp(1.5*(AverageDepth-42)));
570 membrane_pair_score = ( ( 1.0f - interp2 ) * ((1-f)*
mem_pair_log_( 1, icon , aa1, aa2 ) + f*
mem_pair_log_( 2, icon , aa1, aa2 )) +
575 membrane_pair_score = ( ( 1.0f - interp2 ) *
mem_pair_log_( hydro_layer, icon , aa1, aa2 ) +
576 ( interp2 ) *
mem_pair_log_( hydro_layer, icon+1, aa1, aa2 ));
579 membrane_pair_score = ( ( 1.0f - interp2 ) *
mem_pair_log_( hydro_layer, icon , aa1, aa2 ) +
580 ( interp2 ) *
mem_pair_log_( hydro_layer, icon+1, aa1, aa2 ));
583 membrane_pair_score = ( 1.0f - interp2 ) *
mem_pair_log_( hydro_layer,icon , aa1, aa2 );
585 membrane_pair_score*=2.019;
593 using namespace basic::options;
594 using namespace basic::options::OptionKeys;
605 if(option[in::file::spanfile].user()) {
606 std::string spanfile(option[OptionKeys::in::file::spanfile]());
607 TR <<
"Reading spanfile " << spanfile << std::endl;
610 std::cerr <<
"spanfile missing ... " << std::endl;
617 Vector init_normal,init_center;
619 Real score(0),best_score(999999),accepted_score(99999);
620 Real temperature=2.0;
621 Vector trial_normal(init_normal);
622 Vector trial_center(init_center);
623 Vector orig_trial_center(init_center);
624 Vector orig_trial_normal(init_normal);
625 Vector best_normal(init_normal);
626 Vector best_center(init_center);
627 Vector accepted_center(init_center);
628 Vector accepted_normal(init_normal);
630 accepted_score=best_score;
632 bool best_spanning(spanning);
643 Size thermally_accepted=0;
645 if ( basic::options::option[basic::options::OptionKeys::membrane::fixed_membrane] ) {
646 for (
Size i = 1; i <= nres; ++i ) {
648 membrane_embed.
depth(i)=dot(
xyz-best_center,best_normal)+30;
664 for (
int delta_center = -max_delta_center; delta_center <= max_delta_center; ++delta_center ) {
668 trial_center=orig_trial_center;
673 TR <<
"delta_center= " << delta_center <<
" not spanning" << std::endl ;
674 trial_center=accepted_center;
675 trial_normal=accepted_normal;
681 if(score<accepted_score)
686 best_center=trial_center;
687 best_normal=trial_normal;
690 accepted_score=score;
691 accepted_center=trial_center;
692 accepted_normal=trial_normal;
696 for (
Size i = 1; i <= nres; ++i ) {
698 membrane_embed.
depth(i)=dot(
xyz-best_center,best_normal)+30;
702 membrane_embed.
spanning()=best_spanning;
707 for(
Size alpha=alpha_start; alpha<= max_alpha; alpha+=delta_alpha ) {
708 for(
Size theta=0; theta<360; theta+=60 ) {
710 trial_normal=orig_trial_normal;
714 TR <<
"alpha = " << alpha <<
" not spanning" << std::endl ;
715 trial_center=accepted_center;
716 trial_normal=accepted_normal;
722 if(score<accepted_score)
727 best_center=trial_center;
728 best_normal=trial_normal;
731 accepted_score=score;
732 accepted_center=trial_center;
733 accepted_normal=trial_normal;
738 for (
Size i = 1; i <= nres; ++i ) {
740 membrane_embed.
depth(i)=dot(
xyz-best_center,best_normal)+30;
744 membrane_embed.
spanning()=best_spanning;
752 temperature = 2.0/cycles;
763 TR <<
"Cycle " << cycles <<
" not spanning" << std::endl ;
764 trial_center=accepted_center;
765 trial_normal=accepted_normal;
769 if(score<accepted_score)
774 best_center=trial_center;
775 best_normal=trial_normal;
778 accepted_score=score;
779 accepted_center=trial_center;
780 accepted_normal=trial_normal;
786 Real const boltz_factor=(accepted_score-score)/temperature;
788 if(
RG.uniform()<probability)
790 accepted_score=score;
791 accepted_center=trial_center;
792 accepted_normal=trial_normal;
793 ++thermally_accepted;
798 trial_center=accepted_center;
799 trial_normal=accepted_normal;
804 for (
Size i = 1; i <= nres; ++i ) {
806 membrane_embed.
depth(i)=dot(
xyz-best_center,best_normal)+30;
810 membrane_embed.
spanning()=best_spanning;
814 using namespace ObjexxFCL::fmt;
815 TR <<
"MembraneCenter " << F(8,3,best_center.x())<< F(8,3,best_center.y())<< F(8,3,best_center.z()) << std::endl;
816 TR <<
"MembraneNormal " << F(8,3,best_normal.x())<< F(8,3,best_normal.y())<< F(8,3,best_normal.z()) << std::endl;
817 TR <<
"ATOM 9999 X MEM A 999 " << F(8,3,best_center.x())<< F(8,3,best_center.y())<< F(8,3,best_center.z()) << std::endl;
818 TR <<
"ATOM 9999 Y MEM A 999 " << F(8,3,best_center.x()+15.*best_normal.x())<< F(8,3,best_center.y()+15.*best_normal.y())<< F(8,3,best_center.z()+15.*best_normal.z()) << std::endl;
819 TR <<
"ATOM 9999 Z MEM A 999 " << F(8,3,best_center.x()-15.*best_normal.x())<< F(8,3,best_center.y()-15.*best_normal.y())<< F(8,3,best_center.z()-15.*best_normal.z()) << std::endl;
830 if ( basic::options::option[basic::options::OptionKeys::membrane::fixed_membrane] ) {
835 if ( basic::options::option[basic::options::OptionKeys::membrane::membrane_center].user() ) {
836 center.x() = basic::options::option[basic::options::OptionKeys::membrane::membrane_center]()[1];
837 center.y() = basic::options::option[basic::options::OptionKeys::membrane::membrane_center]()[2];
838 center.z() = basic::options::option[basic::options::OptionKeys::membrane::membrane_center]()[3];
840 if ( basic::options::option[basic::options::OptionKeys::membrane::membrane_normal].user() ) {
841 normal.x() = basic::options::option[basic::options::OptionKeys::membrane::membrane_normal]()[1];
842 normal.y() = basic::options::option[basic::options::OptionKeys::membrane::membrane_normal]()[2];
843 normal.z() = basic::options::option[basic::options::OptionKeys::membrane::membrane_normal]()[3];
869 normal=outside-inside;
883 Real residue_score(0);
884 Real tm_projection(0);
885 Real non_helix_pen(0);
887 for (
Size i = 1; i <= nres; ++i ) {
890 using namespace core::conformation::symmetry;
892 dynamic_cast< SymmetricConformation const & > ( pose.
conformation() ) );
894 if (!symm_info->bb_is_independent(pose.
residue(i).
seqpos())) {
897 if (symm_info->is_virtual(i)) {
901 if (rsdSeq ==0 )
continue;
910 score+=residue_score;
916 score+=tm_projection+non_helix_pen+termini_pen;
923 Real const & theta)
const
925 Real r_alpha = numeric::conversions::radians(alpha);
926 Real r_theta = numeric::conversions::radians(theta);
927 Vector u(std::sin(r_alpha) * std::cos(r_theta), std::sin(r_alpha) * std::sin(r_theta), std::cos(r_alpha));
928 n=rotation_matrix_degrees(u,alpha)*n;
934 Real const & delta)
const
941 Real const & std_dev)
const
943 Vector u(numeric::random::gaussian(),numeric::random::gaussian(),numeric::random::gaussian());
944 Real alpha(numeric::random::gaussian()*std_dev);
945 v=rotation_matrix(u,alpha)*v;
950 Real const & std_dev)
const
952 Vector u(numeric::random::gaussian(),numeric::random::gaussian(),numeric::random::gaussian());
966 bool start_i_side=(dot(start_i-center,normal) > 0);
967 bool span_check=
false;
973 bool start_j_side=(dot(start_j-center,normal) > 0);
974 bool coord_para=(start_i_side==start_j_side);
1023 Real tm_length=std::abs(dot(
start-center,normal)-dot(
end-center,normal));
1027 if(ratio<1 || ratio > 1.5)
1055 using namespace core::conformation::symmetry;
1057 dynamic_cast< SymmetricConformation const & > ( pose.
conformation() ) );
1059 if (!symm_info->bb_is_independent(pose.
residue(i).
seqpos())) {
1062 if (symm_info->is_virtual(i)) {
1066 if (rsdSeq ==0 )
continue;
1072 Real depth=dot(
xyz-center,normal)+30;
1106 using namespace core::conformation::symmetry;
1108 dynamic_cast< SymmetricConformation const & > ( pose.
conformation() ) );
1110 if (!symm_info->bb_is_independent(pose.
residue(i).
seqpos())) {
1113 if (symm_info->is_virtual(i)) {
1117 if (rsdSeq ==0 )
continue;
1123 Real depth=dot(
xyz-center,normal);
1156 return *membrane_embed;