00001
00002
00003 #include <stdio.h>
00004 #include <math.h>
00005 #include <string.h>
00006 #include "open_prospect.h"
00007 #include "sm_matrix.h"
00008
00009
00010 float SasaCalc::CalcSasa( TargetStruct *target_data ) {
00011 float total = 0.0;
00012 if ( target_data->structure == NULL )
00013 return 0;
00014
00015 for ( int i = 0; i < target_data->len; i++ ) {
00016 total += CalcResidueSasa( target_data, i );
00017 }
00018 return total;
00019 }
00020
00021 PopsRSasa::PopsRSasa(ProspectParam *in_parent) : PopsSasa( in_parent, false ) {
00022 char buffer[2000];
00023 params = parent->GetPopsRParam();
00024 }
00025
00026
00027 PopsSasa::PopsSasa(ProspectParam *in_parent, bool load) : SasaCalc(), ParamElement( in_parent ) {
00028 char buffer[2000];
00029 params = NULL;
00030 if (load) {
00031 params = parent->GetPopsParam();
00032 }
00033 }
00034
00035
00036
00037 float PopsSasa::FindRadius( int atom_num ) {
00038 for ( int i = 0; i < params->param_count; i++) {
00039 if ( params->params[i].atom_num == atom_num ) {
00040 return params->params[i].radius;
00041 }
00042 }
00043 return -1;
00044 }
00045
00046 float PopsSasa::FindP( int atom_num ) {
00047 for ( int i = 0; i < params->param_count; i++) {
00048 if ( params->params[i].atom_num == atom_num ) {
00049 return params->params[i].p_i;
00050 }
00051 }
00052 return -1;
00053 }
00054
00055
00056 #define PI 3.141592653589793
00057 #define rSolv 1.6
00058 float PopsSasa::CalcResidueSasa( TargetStruct *target_data, int i ) {
00059 float total = 0.0;
00060 for ( int ia = 0; ia < target_data->structure[i].atom_count; ia++) {
00061 float ia_radius = FindRadius( target_data->structure[i].atom_name[ia] );
00062 if ( ia_radius > 0 ) {
00063 float p_i = FindP( target_data->structure[i].atom_name[ia] );
00064 float si = 4 * PI * pow( ia_radius + rSolv, 2 );
00065 float i_total = 1.0;
00066 for ( int j = 0; j < target_data->len; j++ ) {
00067 if ( i != j ) {
00068 for ( int ja = 0; ja < target_data->structure[j].atom_count; ja++) {
00069 float ja_radius = FindRadius( target_data->structure[j].atom_name[ja] );
00070 if ( ja_radius > 0 ) {
00071 float r_ij = smDistance( target_data->structure[i].atom[ia],
00072 target_data->structure[j].atom[ja] );
00073 float b = 0;
00074 if ( r_ij <= ia_radius + ja_radius + 2 * rSolv ) {
00075 b = PI * ( ia_radius + rSolv ) * ( ia_radius + ja_radius + 2*rSolv - r_ij) *
00076 (1 + ((ja_radius - ia_radius) / (r_ij)) );
00077 }
00078 i_total = i_total * (1 - ( p_i * params->p_14 * b) / si);
00079 }
00080 }
00081
00082 }
00083 }
00084 total += si * i_total;
00085 }
00086 }
00087 return total;
00088 }
00089
00090
00091
00092 float SimpleSasa::CalcResidueSasa( TargetStruct *target_data, int res ) {
00093 return 0;
00094 }
00095
00096 float *ParseDsspAcc( FILE *file, int *count = NULL ) {
00097 char buffer[2000];
00098 char read_state = 0;
00099 int read_count = 0;
00100 float *tmp_acc = new float[2000];
00101 while (fgets(buffer, sizeof(buffer), file)) {
00102 if ( !strncmp(" #", buffer, 3) ) {
00103 read_state = 1;
00104 } else {
00105 if ( read_state ) {
00106 char tmp[ 5 ];
00107 tmp[0] = buffer[35];
00108 tmp[1] = buffer[36];
00109 tmp[2] = buffer[37];
00110 tmp[3] = 0;
00111 tmp_acc[ read_count ] = atoi( tmp );
00112 read_count++;
00113 }
00114 }
00115 }
00116 float *acc_val = new float [ read_count ];
00117 for ( int i = 0; i < read_count; i++ ) {
00118 acc_val[i] = tmp_acc[i];
00119 }
00120 delete tmp_acc;
00121 if ( count != NULL ) {
00122 (*count) = read_count;
00123 }
00124 return acc_val;
00125 }
00126
00127 void DsspSasa::LoadDssp(char *path) {
00128 FILE *file = fopen( path, "r" );
00129 acc_val = ParseDsspAcc( file, &len );
00130 fclose( file );
00131 }
00132
00133 float DsspSasa::CalcResidueSasa( TargetStruct *target_data, int res) {
00134 if ( res >= len )
00135 return 0;
00136 return acc_val[ res ];
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 };
00187
00188