src/common/sasa.cc

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         char *text = target_data->WritePDBText( );
00141         
00142         char buffer[ 5000 ];
00143         
00144         sprintf(buffer, "dsspcmbi ");
00145         
00146         int pipe_to_dssp[2], dssp_from_dssp[2] ;
00147         pipe( pipe_to_dssp );
00148         pipe( pipe_from_dssp );
00149 
00150         if ( !(child_pid = fork()) ) {
00151                 //this is the child, 
00152                 
00153                 //setup the pipe into dssp
00154                 close(pipe_to_dssp[0]); //close the read end of the pipe
00155                 close( stdin );
00156                 dup2(pipe_to_dssp[1], stdin );
00157                 
00158                 char dssp_cmd[] = 
00159                 dsspcmbi --
00160                 
00161                 
00162                 write(pipe_files[1], xmltext, strlen(xmltext) );
00163                 close(pipe_files[1]);
00164                 exit(0);
00165         } else {
00166                 close(pipe_files[1]); //close the write end of the pipe
00167                 do {
00168                         read_file_and_append(pipe_files[0], &xmltext, &xmlsize);
00169                         status = wait4(child_pid, NULL, WNOHANG | WUNTRACED , NULL);
00170                         if (status == -1) {
00171                                 fprintf(stderr, "Error while forking\n");
00172                                 return NULL;
00173                         }
00174                         if (!status) 
00175                                 usleep(300);
00176                         
00177                 } while (status == 0 );
00178                 read_file_and_append(pipe_files[0], &xmltext, &xmlsize);
00179                 close(pipe_files[0]);
00180         }
00181         
00182         
00183         return acc_val[res];
00184          */
00185         
00186 };
00187 
00188 

Generated on Wed Apr 11 16:50:50 2007 for open_prospect by  doxygen 1.4.6