00001 #include "../headers/asa.h"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 int atom_in_list(s_atm *a, s_atm **atoms, int natoms){
00075 int i;
00076 if(atoms){
00077 for(i = 0 ; i < natoms ; i++){
00078 if(atoms[i]==a) {
00079 if(atoms[i]->id != a->id) {
00080 fprintf(stdout,"WARNING asa.c: atom in the list but with different ID!") ;
00081 }
00082 return 1;
00083 }
00084 }
00085 }
00086 return 0;
00087 }
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 int *get_surrounding_atoms_idx(s_vvertice **tvert,int nvert,s_pdb *pdb, int *n_sa){
00108 s_atm *a=NULL;
00109 int *sa=NULL;
00110 int i,z,flag=0;
00111 *n_sa=0;
00112 for(i=0;i<pdb->natoms;i++){
00113 a=pdb->latoms_p[i];
00114
00115 if(strncmp(a->symbol,"H",1)){
00116 flag=0;
00117 for(z=0;z<nvert && !flag;z++){
00118
00119 flag=in_tab(sa,*n_sa,i);
00120 if(!flag && ddist(a->x,a->y,a->z,tvert[z]->x,tvert[z]->y,tvert[z]->z)<(tvert[z]->ray+M_PADDING)*(tvert[z]->ray+M_PADDING)){
00121 *n_sa=*n_sa+1;
00122 if(sa==NULL){
00123 sa=(int *)malloc(sizeof(int));
00124 sa[*n_sa-1]=i;
00125 }
00126 else {
00127 sa=(int *)realloc(sa,sizeof(int)*(*n_sa));
00128 sa[*n_sa-1]=i;
00129 }
00130 }
00131 }
00132 }
00133 }
00134 return sa;
00135 }
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 int *get_unique_atoms(s_vvertice **tvert,int nvert, int *n_ua, s_atm **atoms,int na){
00158 s_atm *a=NULL;
00159 int *ua=NULL;
00160 int z,j;
00161 int ca_idx;
00162 *n_ua=0;
00163 int flag=0;
00164
00165 s_vvertice *vcur = NULL ;
00166 s_atm **neighs = NULL ;
00167
00168
00169
00170 for(z=0;z<nvert;z++){
00171 vcur = tvert[z] ;
00172 neighs = tvert[z]->neigh ;
00173 for(j=0;j<4;j++){
00174 a=neighs[j];
00175 flag=in_tab(ua,*n_ua,a->id);
00176 if(!flag) {
00177 *n_ua=*n_ua+1;
00178 if(ua==NULL) ua=(int *)malloc(sizeof(int));
00179 else ua=(int *)realloc(ua,sizeof(int)*(*n_ua));
00180
00181 if(a->id-1 < na && a==atoms[a->id-1]) {
00182 ua[*n_ua-1]=a->id-1;
00183
00184
00185
00186 }
00187 else {
00188 for(ca_idx=0;ca_idx<na;ca_idx++){
00189 if(a==atoms[ca_idx]) {
00190 ua[*n_ua-1]=ca_idx;
00191
00192
00193
00194
00195
00196 break;
00197 }
00198 }
00199 }
00200 }
00201 }
00202 }
00203
00204 return ua;
00205 }
00206
00207
00208 s_atm **get_unique_atoms_DEPRECATED(s_vvertice **tvert,int nvert, int *n_ua)
00209 {
00210 s_vvertice *vcur = NULL ;
00211 s_atm **neighs = NULL ;
00212
00213 s_atm *a=NULL;
00214 s_atm **ua=(s_atm **) malloc(sizeof(s_atm*)*10);
00215
00216 int tab_size = 10 ;
00217 int nb_ua = 0;
00218 int z = 0, j = 0;
00219
00220
00221 for(z = 0 ; z < nvert ; z++){
00222 vcur = tvert[z] ;
00223 neighs = tvert[z]->neigh ;
00224
00225
00226 for(j = 0 ; j < 4 ; j++) {
00227 a = neighs[j];
00228 if(atom_in_list(a, ua, nb_ua) == 0) {
00229 ua[nb_ua] = a;
00230
00231 nb_ua = nb_ua + 1;
00232 if(nb_ua >= tab_size){
00233 ua = (s_atm **) realloc(ua,sizeof(s_atm*)*(nb_ua+10));
00234 tab_size += 10 ;
00235 }
00236 }
00237 }
00238 }
00239
00240 *n_ua = nb_ua ;
00241
00242 return ua;
00243 }
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267 void set_ASA(s_desc *desc,s_pdb *pdb, s_vvertice **tvert,int nvert)
00268 {
00269 desc->surf_pol_vdw14=0.0;
00270 desc->surf_apol_vdw14=0.0;
00271 desc->surf_vdw14=0.0;
00272 desc->surf_vdw22=0.0;
00273 desc->surf_pol_vdw22=0.0;
00274 desc->surf_apol_vdw22=0.0;
00275 desc->n_abpa=0;
00276 int *sa=NULL;
00277
00278 s_atm ** ua = NULL ;
00279
00280 int n_sa = 0;
00281 int n_ua = 0;
00282 int i;
00283 sa=get_surrounding_atoms_idx(tvert,nvert,pdb, &n_sa);
00284
00285
00286 ua=get_unique_atoms_DEPRECATED(tvert,nvert, &n_ua);
00287 float *abpatmp=NULL;
00288 abpatmp=(float *)my_malloc(sizeof(float)*n_ua);
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302 s_atm *a,*cura;
00303 float *curpts=NULL,tz,tx,ty,dsq,area;
00304 int j=0,iv,k,burried,nnburried,vidx,vrefburried;
00305 curpts=get_points_on_sphere(M_NSPIRAL);
00306 for(i=0;i<n_ua;i++){
00307 abpatmp[i]=0.0;
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 cura = ua[i] ;
00320 nnburried=0;
00321
00322 for(k=0;k<M_NSPIRAL;k++){
00323 burried=0;
00324 j=0;
00325 tx=cura->x+curpts[3*k]*(cura->radius+M_PROBE_SIZE);
00326 ty=cura->y+curpts[3*k+1]*(cura->radius+M_PROBE_SIZE);
00327 tz=cura->z+curpts[3*k+2]*(cura->radius+M_PROBE_SIZE);
00328 vrefburried=1;
00329 for(iv=0;iv<nvert;iv++){
00330 for(vidx=0;vidx<4;vidx++){
00331 if(cura==tvert[iv]->neigh[vidx]){
00332 if(ddist(tx,ty,tz,tvert[iv]->x,tvert[iv]->y,tvert[iv]->z)<=tvert[iv]->ray*tvert[iv]->ray) vrefburried=0;
00333 }
00334 }
00335 }
00336 while(!burried && j< n_sa && !vrefburried){
00337 a=pdb->latoms_p[sa[j]];
00338 if(a!=cura){
00339 dsq=ddist(tx,ty,tz,a->x,a->y,a->z);
00340 if(dsq<(a->radius+M_PROBE_SIZE)*(a->radius+M_PROBE_SIZE)) burried=1;
00341 }
00342 j++;
00343 }
00344 if(!burried && !vrefburried) {
00345 nnburried++;
00346 }
00347 }
00348 area=(4*PI*(cura->radius+M_PROBE_SIZE)*(cura->radius+M_PROBE_SIZE)/(float)M_NSPIRAL)*nnburried;
00349 abpatmp[i]=area;
00350 if(cura->electroneg<2.8) desc->surf_apol_vdw14=desc->surf_apol_vdw14+area;
00351 else desc->surf_pol_vdw14=desc->surf_pol_vdw14+area;
00352 desc->surf_vdw14=desc->surf_vdw14+area;
00353
00354 }
00355
00356
00357
00358 for(i=0;i<n_ua;i++){
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370 cura = ua[i] ;
00371 nnburried=0;
00372
00373 for(k=0;k<M_NSPIRAL;k++){
00374 burried=0;
00375 j=0;
00376 tx=cura->x+curpts[3*k]*(cura->radius+M_PROBE_SIZE2);
00377 ty=cura->y+curpts[3*k+1]*(cura->radius+M_PROBE_SIZE2);
00378 tz=cura->z+curpts[3*k+2]*(cura->radius+M_PROBE_SIZE2);
00379 vrefburried=1;
00380 for(iv=0;iv<nvert;iv++){
00381 for(vidx=0;vidx<4;vidx++){
00382 if(cura==tvert[iv]->neigh[vidx]){
00383 if(ddist(tx,ty,tz,tvert[iv]->x,tvert[iv]->y,tvert[iv]->z)<=tvert[iv]->ray*tvert[iv]->ray) vrefburried=0;
00384 }
00385 }
00386 }
00387 while(!burried && j< n_sa && !vrefburried){
00388 a=pdb->latoms_p[sa[j]];
00389 if(a!=cura){
00390 dsq=ddist(tx,ty,tz,a->x,a->y,a->z);
00391 if(dsq<(a->radius+M_PROBE_SIZE2)*(a->radius+M_PROBE_SIZE2)) burried=1;
00392 }
00393 j++;
00394 }
00395 if(!burried && !vrefburried) {
00396 nnburried++;
00397 }
00398 }
00399 area=(4*PI*(cura->radius+M_PROBE_SIZE2)*(cura->radius+M_PROBE_SIZE2)/(float)M_NSPIRAL)*nnburried;
00400 if(cura->electroneg<2.8) {
00401 if(area<=abpatmp[i] && abpatmp[i] <=10.0 && area > 0.0){
00402 desc->n_abpa+=1;
00403 }
00404 desc->surf_apol_vdw22=desc->surf_apol_vdw22+area;
00405 }
00406 else desc->surf_pol_vdw22=desc->surf_pol_vdw22+area;
00407 desc->surf_vdw22=desc->surf_vdw22+area;
00408
00409 }
00410 free(curpts);
00411
00412
00413
00414 curpts=NULL;
00415
00416
00417
00418
00419 free(ua);
00420 free(sa);
00421
00422 sa=NULL;
00423 ua=NULL;
00424 }
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443 float *get_points_on_sphere(int nop) {
00444 float *pts =NULL;
00445 pts=(float *) malloc(sizeof (float) * nop * 3);
00446 float inc = PI * (3.0 - sqrt(5.0));
00447 float off = 2.0 / (float) nop;
00448 float y, r, phi;
00449 int k;
00450 for (k = 0; k < nop; k++) {
00451 y = ((float) k) * off - 1.0 + (off / 2.0);
00452 r = sqrt(1.0 - y * y);
00453 phi = k * inc;
00454 pts[3 * k] = cos(phi) * r;
00455 pts[3 * k + 1] = y;
00456 pts[3 * k + 2] = sin(phi) * r;
00457 }
00458 return pts;
00459 }
00460
00461