00001
00002 #include "../headers/neighbor.h"
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
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 s_atm** get_mol_atm_neigh(s_atm **atoms, int natoms, s_atm **all, int nall,
00091 float dcrit, int *nneigh)
00092 {
00093
00094 s_vsort *lsort = get_sorted_list(all, nall, NULL, 0) ;
00095 s_vect_elem *xsort = lsort->xsort ;
00096
00097 int ip, im,
00098 stopm, stopp,
00099 nb_neigh,
00100 sort_x,
00101 ntest_x,
00102 dim = lsort->nelem ;
00103
00104 float vvalx, vvaly, vvalz;
00105
00106 int real_size = 10,
00107 i, seen ;
00108
00109 s_atm *curap = NULL, *curam = NULL ;
00110 s_atm **neigh = (s_atm**)my_malloc(sizeof(s_atm*)*real_size) ;
00111
00112 nb_neigh = 0 ;
00113 for(i = 0 ; i < natoms ; i++) {
00114 s_atm *cur = atoms[i] ;
00115
00116
00117 stopm = 0; stopp = 0;
00118 sort_x = cur->sort_x ;
00119 ntest_x = 1 ;
00120 vvalx = cur->x ; vvaly = cur->y ; vvalz = cur->z ;
00121
00122
00123 while(!stopm || !stopp) {
00124
00125
00126 ip = ntest_x + sort_x ;
00127 if(ip >= dim) stopp = 1 ;
00128
00129 if(stopp == 0) {
00130 curap = (s_atm*) xsort[ip].data ;
00131
00132 if(curap->x - vvalx > dcrit) stopp = 1 ;
00133 else {
00134
00135
00136 if(dist(curap->x, curap->y, curap->z, vvalx, vvaly, vvalz) < dcrit) {
00137
00138
00139 seen = is_in_lst_atm(atoms, natoms, curap->id)
00140 + is_in_lst_atm(neigh, nb_neigh, curap->id) ;
00141 if(!seen) {
00142 if(nb_neigh >= real_size-1) {
00143 real_size *= 2 ;
00144 neigh =(s_atm**) my_realloc(neigh, sizeof(s_atm)*real_size) ;
00145 }
00146 neigh[nb_neigh] = curap ;
00147 nb_neigh ++ ;
00148 }
00149 }
00150 }
00151 }
00152
00153 im = sort_x - ntest_x ;
00154 if(im < 0) stopm = 1 ;
00155
00156 if(stopm == 0) {
00157 curam = (s_atm*) xsort[im].data ;
00158
00159 if(vvalx - curam->x > dcrit) stopm = 1 ;
00160 else {
00161
00162
00163 if(dist(curam->x, curam->y, curam->z, vvalx, vvaly, vvalz) < dcrit){
00164
00165
00166 seen = is_in_lst_atm(atoms, natoms, curam->id)
00167 + is_in_lst_atm(neigh, nb_neigh, curam->id) ;
00168 if(!seen) {
00169 if(nb_neigh >= real_size-1) {
00170 real_size *= 2 ;
00171 neigh = (s_atm**)my_realloc(neigh, sizeof(s_atm)*real_size) ;
00172 }
00173 neigh[nb_neigh] = curam ;
00174 nb_neigh ++ ;
00175 }
00176 }
00177 }
00178 }
00179
00180 ntest_x += 1 ;
00181 }
00182 }
00183
00184 *nneigh = nb_neigh ;
00185 free_s_vsort(lsort) ;
00186
00187 return neigh ;
00188 }
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 s_vvertice** get_mol_vert_neigh(s_atm **atoms, int natoms,
00214 s_vvertice **pvert, int nvert,
00215 float dcrit, int *nneigh)
00216 {
00217 s_vsort *lsort = get_sorted_list(atoms, natoms, pvert, nvert) ;
00218 s_vect_elem *xsort = lsort->xsort ;
00219
00220 int ip, im,
00221 stopm, stopp,
00222 nb_neigh,
00223 sort_x,
00224 ntest_x,
00225 dim = lsort->nelem ;
00226
00227 float vvalx, vvaly, vvalz;
00228
00229 int real_size = 10,
00230 i, seen ;
00231
00232 s_vvertice *curvp = NULL, *curvm = NULL ;
00233 s_vvertice **neigh = (s_vvertice**)my_malloc(sizeof(s_vvertice*)*real_size) ;
00234
00235 nb_neigh = 0 ;
00236 for(i = 0 ; i < natoms ; i++) {
00237 s_atm *cur = atoms[i] ;
00238
00239
00240 stopm = 0; stopp = 0;
00241 sort_x = cur->sort_x ;
00242 ntest_x = 1 ;
00243 vvalx = cur->x ; vvaly = cur->y ; vvalz = cur->z ;
00244
00245
00246 while(!stopm || !stopp) {
00247
00248
00249 ip = ntest_x + sort_x ;
00250 if(ip >= dim) stopp = 1 ;
00251
00252 if(stopp == 0 && xsort[ip].type == M_VERTICE_TYPE) {
00253 curvp = (s_vvertice*) xsort[ip].data ;
00254
00255 if(curvp->x - vvalx > dcrit) stopp = 1 ;
00256 else {
00257
00258
00259 if(dist(curvp->x, curvp->y, curvp->z, vvalx, vvaly, vvalz) < dcrit) {
00260
00261 seen = is_in_lst_vert(neigh, nb_neigh, curvp->id) ;
00262 if(!seen) {
00263 if(nb_neigh >= real_size-1) {
00264 real_size *= 2 ;
00265 neigh = (s_vvertice **)my_realloc(neigh,
00266 sizeof(s_vvertice)*real_size) ;
00267 }
00268 neigh[nb_neigh] = curvp ;
00269 nb_neigh ++ ;
00270 }
00271 }
00272 }
00273 }
00274
00275 im = sort_x - ntest_x ;
00276 if(im < 0) stopm = 1 ;
00277
00278 if(stopm == 0 && xsort[im].type == M_VERTICE_TYPE) {
00279 curvm = (s_vvertice*) xsort[im].data ;
00280
00281 if(vvalx - curvm->x > dcrit) stopm = 1 ;
00282 else {
00283
00284
00285 if(dist(curvm->x, curvm->y, curvm->z, vvalx, vvaly, vvalz) < dcrit){
00286
00287
00288 seen = is_in_lst_vert(neigh, nb_neigh, curvm->id) ;
00289 if(!seen) {
00290 if(nb_neigh >= real_size-1) {
00291 real_size *= 2 ;
00292 neigh = (s_vvertice**)my_realloc(neigh, sizeof(s_vvertice)*real_size) ;
00293 }
00294 neigh[nb_neigh] = curvm ;
00295 nb_neigh ++ ;
00296 }
00297 }
00298 }
00299 }
00300
00301 ntest_x += 1 ;
00302 }
00303 }
00304
00305 *nneigh = nb_neigh ;
00306 free_s_vsort(lsort) ;
00307
00308 return neigh ;
00309 }
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 s_atm** get_mol_ctd_atm_neigh(s_atm **atoms, int natoms,
00333 s_vvertice **pvert, int nvert,
00334 float vdcrit, int interface_search, int *nneigh)
00335 {
00336 s_vsort *lsort = get_sorted_list(atoms, natoms, pvert, nvert) ;
00337 s_vect_elem *xsort = lsort->xsort ;
00338
00339 int ip, im,
00340
00341 stopm, stopp,
00342
00343 nb_neigh = 0,
00344 sort_x = 0,
00345 ntest_x = 0,
00346 dim = lsort->nelem,
00347 real_size = 10,
00348 i, j ;
00349
00350 float lx, ly, lz;
00351
00352 s_vvertice *curvp = NULL, *curvm = NULL ;
00353 s_atm *curatm = NULL ;
00354 s_atm **neigh = (s_atm**)my_malloc(sizeof(s_atm*)*real_size) ;
00355
00356 for(i = 0 ; i < nvert ; i++) {
00357 for(j = 0 ; j < 4 ; j++) {
00358 pvert[i]->neigh[j]->seen = 0 ;
00359 }
00360 }
00361
00362 for(i = 0 ; i < natoms ; i++) {
00363 s_atm *cur = atoms[i] ;
00364
00365
00366 stopm = 0; stopp = 0;
00367 sort_x = cur->sort_x ;
00368
00369 ntest_x = 1 ;
00370
00371
00372 lx = cur->x ; ly = cur->y ; lz = cur->z ;
00373
00374
00375 while(!stopm || !stopp) {
00376
00377
00378 ip = ntest_x + sort_x ;
00379
00380
00381 if(ip >= dim) stopp = 1 ;
00382
00383 if(stopp == 0 && xsort[ip].type == M_VERTICE_TYPE) {
00384 curvp = (s_vvertice*) xsort[ip].data ;
00385
00386
00387 if(curvp->x - lx > vdcrit) stopp = 1 ;
00388 else {
00389
00390
00391 if(dist(curvp->x, curvp->y, curvp->z, lx, ly, lz) < vdcrit) {
00392
00393 for(j = 0 ; j < 4 ; j++) {
00394 curatm = curvp->neigh[j] ;
00395 if(! curatm->seen) {
00396 if(interface_search &&
00397 dist(curatm->x, curatm->y, curatm->z, lx, ly, lz)
00398 < M_INTERFACE_SEARCH_DIST) {
00399
00400
00401 if(nb_neigh >= real_size-1) {
00402 real_size *= 2 ;
00403 neigh = (s_atm**)my_realloc(neigh, sizeof(s_atm)*real_size) ;
00404 }
00405 neigh[nb_neigh] = curatm ;
00406 curatm->seen = 1 ;
00407 nb_neigh ++ ;
00408 }
00409 else if(!interface_search) {
00410
00411
00412 if(nb_neigh >= real_size-1) {
00413 real_size *= 2 ;
00414 neigh = (s_atm**)my_realloc(neigh, sizeof(s_atm)*real_size) ;
00415 }
00416 curatm->seen = 1 ;
00417 neigh[nb_neigh] = curatm ;
00418 nb_neigh ++ ;
00419 }
00420 }
00421 }
00422 }
00423 }
00424 }
00425
00426 im = sort_x - ntest_x ;
00427
00428 if(im < 0) stopm = 1 ;
00429
00430 if(stopm == 0 && xsort[im].type == M_VERTICE_TYPE) {
00431 curvm = (s_vvertice*) xsort[im].data ;
00432
00433 if(lx - curvm->x > vdcrit) stopm = 1 ;
00434 else {
00435
00436
00437 if(dist(curvm->x, curvm->y, curvm->z, lx, ly, lz) < vdcrit) {
00438
00439 for(j = 0 ; j < 4 ; j++) {
00440 curatm = curvm->neigh[j] ;
00441 if(! curatm->seen) {
00442 if(interface_search &&
00443 dist(curatm->x, curatm->y, curatm->z, lx, ly, lz)
00444 < M_INTERFACE_SEARCH_DIST) {
00445
00446
00447 if(nb_neigh >= real_size-1) {
00448 real_size *= 2 ;
00449 neigh = (s_atm**)
00450 my_realloc(neigh, sizeof(s_atm)*real_size) ;
00451 }
00452 curatm->seen = 1 ;
00453 neigh[nb_neigh] = curatm ;
00454 nb_neigh ++ ;
00455 }
00456 else if(!interface_search) {
00457
00458
00459 if(nb_neigh >= real_size-1) {
00460 real_size *= 2 ;
00461 neigh = (s_atm**)my_realloc(neigh, sizeof(s_atm)*real_size) ;
00462 }
00463 curatm->seen = 1 ;
00464 neigh[nb_neigh] = curatm ;
00465 nb_neigh ++ ;
00466 }
00467 }
00468 }
00469 }
00470 }
00471 }
00472
00473 ntest_x += 1 ;
00474 }
00475 }
00476
00477 *nneigh = nb_neigh ;
00478 free_s_vsort(lsort) ;
00479
00480 return neigh ;
00481 }
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503 float count_pocket_lig_vert_ovlp(s_atm **lig, int nlig,
00504 s_vvertice **pvert, int nvert,
00505 float dcrit)
00506 {
00507 s_vsort *lsort = get_sorted_list(lig, nlig, pvert, nvert) ;
00508 s_vect_elem *xsort = lsort->xsort ;
00509
00510 int ip, im, i,
00511 stopm, stopp,
00512 nb_neigh,
00513 sort_x,
00514 ntest_x,
00515 dim = lsort->nelem ;
00516
00517 float vvalx, vvaly, vvalz ;
00518
00519 s_vvertice *ids[nvert] ;
00520 for(i = 0 ; i < nvert ; i++) {
00521 pvert[i]->seen = 0 ;
00522 ids[i] = NULL ;
00523 }
00524
00525 s_vvertice *curvp = NULL, *curvm = NULL ;
00526
00527 nb_neigh = 0 ;
00528 for(i = 0 ; i < nlig ; i++) {
00529 s_atm *cur = lig[i] ;
00530
00531
00532 stopm = 0; stopp = 0;
00533 sort_x = cur->sort_x ;
00534 ntest_x = 1 ;
00535 vvalx = cur->x ; vvaly = cur->y ; vvalz = cur->z ;
00536
00537
00538 while(!stopm || !stopp) {
00539
00540
00541 ip = ntest_x + sort_x ;
00542 if(ip >= dim) stopp = 1 ;
00543
00544 if(stopp == 0 && xsort[ip].type == M_VERTICE_TYPE) {
00545 curvp = (s_vvertice*) xsort[ip].data ;
00546
00547 if(curvp->x - vvalx > dcrit) stopp = 1 ;
00548 else {
00549
00550
00551 if(dist(curvp->x, curvp->y, curvp->z, vvalx, vvaly, vvalz) < dcrit) {
00552
00553 if(! curvp->seen) {
00554 ids[nb_neigh] = curvp ;
00555 curvp->seen = 1 ;
00556 nb_neigh ++ ;
00557 }
00558 }
00559 }
00560 }
00561
00562 im = sort_x - ntest_x ;
00563 if(im < 0) stopm = 1 ;
00564
00565 if(stopm == 0 && xsort[im].type == M_VERTICE_TYPE) {
00566 curvm = (s_vvertice*) xsort[im].data ;
00567
00568 if(vvalx - curvm->x > dcrit) stopm = 1 ;
00569 else {
00570
00571
00572 if(dist(curvm->x, curvm->y, curvm->z, vvalx, vvaly, vvalz) < dcrit){
00573
00574
00575 if(!curvm->seen) {
00576 ids[nb_neigh] = curvm ;
00577 curvm->seen = 1 ;
00578 nb_neigh ++ ;
00579 }
00580 }
00581 }
00582 }
00583
00584 ntest_x += 1 ;
00585 }
00586 }
00587
00588 free_s_vsort(lsort) ;
00589 return (float)nb_neigh/(float)nvert ;
00590 }
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610 float count_atm_prop_vert_neigh (s_atm **lig, int nlig,s_vvertice **pvert, int nvert,
00611 float dcrit, int n_lig_molecules)
00612 {
00613 s_vsort *lsort = get_sorted_list(lig, nlig, pvert, nvert) ;
00614 s_vect_elem *xsort = lsort->xsort ;
00615
00616 int ip, im, i,
00617 stopm, stopp,
00618 nb_neigh,
00619 sort_x,
00620 ntest_x,
00621 dim = lsort->nelem ;
00622
00623 float vvalx, vvaly, vvalz ;
00624 int multi_nb_neigh[n_lig_molecules];
00625 int multi_nb_lig_atoms[n_lig_molecules];
00626
00627 int c_lig_mol=0;
00628 float max_prop=0.0;
00629 float tmp=0.0;
00630 char chain_tmp[2];
00631 int resnumber_tmp;
00632 strcpy(chain_tmp,lig[0]->chain);
00633 resnumber_tmp = lig[0]->res_id;
00634
00635 s_vvertice *curvp = NULL, *curvm = NULL ;
00636
00637 nb_neigh = 0 ;
00638 multi_nb_neigh[0]=0;
00639 multi_nb_lig_atoms[0]=0;
00640 for(i = 0 ; i < nlig ; i++) {
00641
00642 if(strcmp(chain_tmp,lig[i]->chain) !=0 || resnumber_tmp!=lig[i]->res_id){
00643 c_lig_mol++;
00644 strcpy(chain_tmp,lig[i]->chain);
00645 resnumber_tmp =lig[i]->res_id;
00646 multi_nb_neigh[c_lig_mol]=0;
00647 multi_nb_lig_atoms[c_lig_mol]=0;
00648 }
00649 multi_nb_lig_atoms[c_lig_mol]++;
00650 s_atm *cur = lig[i] ;
00651
00652
00653 stopm = 0; stopp = 0;
00654 sort_x = cur->sort_x ;
00655 ntest_x = 1 ;
00656 vvalx = cur->x ; vvaly = cur->y ; vvalz = cur->z ;
00657
00658
00659 while(!stopm || !stopp) {
00660
00661
00662 ip = ntest_x + sort_x ;
00663 if(ip >= dim) stopp = 1 ;
00664
00665 if(stopp == 0 && xsort[ip].type == M_VERTICE_TYPE) {
00666 curvp = (s_vvertice*) xsort[ip].data ;
00667
00668 if(curvp->x - vvalx > dcrit) stopp = 1 ;
00669 else {
00670
00671
00672 if(dist(curvp->x, curvp->y, curvp->z, vvalx, vvaly, vvalz) < dcrit) {
00673
00674 multi_nb_neigh[c_lig_mol]++;
00675 nb_neigh ++ ; break ;
00676 }
00677 }
00678 }
00679
00680 im = sort_x - ntest_x ;
00681 if(im < 0) stopm = 1 ;
00682
00683 if(stopm == 0 && xsort[im].type == M_VERTICE_TYPE) {
00684 curvm = (s_vvertice*) xsort[im].data ;
00685
00686 if(vvalx - curvm->x > dcrit) stopm = 1 ;
00687 else {
00688
00689
00690 if(dist(curvm->x, curvm->y, curvm->z, vvalx, vvaly, vvalz) < dcrit){
00691
00692
00693 multi_nb_neigh[c_lig_mol]++;
00694 nb_neigh++ ; break ;
00695 }
00696 }
00697 }
00698
00699 ntest_x += 1 ;
00700 }
00701 }
00702
00703 for(i=0;i<n_lig_molecules;i++){
00704 tmp=(float)multi_nb_neigh[i]/(float)multi_nb_lig_atoms[i];
00705 if(tmp>max_prop) max_prop=tmp;
00706 }
00707 free_s_vsort(lsort);
00708 return max_prop;
00709 }
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733 int count_vert_neigh_P(s_vvertice **pvert, int nvert,
00734 s_vvertice **pvert_all, int nvert_all,
00735 float dcrit)
00736 {
00737 s_vsort *lsort = get_sorted_list(NULL, 0, pvert_all, nvert_all) ;
00738 int res = count_vert_neigh(lsort, pvert, nvert, dcrit) ;
00739
00740 free_s_vsort(lsort) ;
00741
00742 return res ;
00743 }
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770 int count_vert_neigh(s_vsort *lsort, s_vvertice **pvert, int nvert, float dcrit)
00771 {
00772 s_vect_elem *xsort = lsort->xsort ;
00773
00774 s_vvertice *vcur = NULL ;
00775
00776 int ip, im, i,
00777 stopm, stopp,
00778 nb_neigh,
00779 sort_x,
00780 ntest_x,
00781 dim = lsort->nelem ;
00782
00783 float vvalx, vvaly, vvalz;
00784
00785
00786 for(i = 0 ; i < dim ; i++) ((s_vvertice*) lsort->xsort[i].data)->seen = 0 ;
00787 for(i = 0 ; i < nvert ; i++) pvert[i]->seen = 2 ;
00788
00789 s_vvertice *curvp = NULL, *curvm = NULL ;
00790 nb_neigh = 0 ;
00791 for(i = 0 ; i < nvert ; i++) {
00792 vcur = pvert[i] ;
00793
00794
00795 stopm = 0; stopp = 0;
00796 sort_x = vcur->sort_x ;
00797 ntest_x = 1 ;
00798 vvalx = vcur->x ; vvaly = vcur->y ; vvalz = vcur->z ;
00799
00800
00801 while(!stopm || !stopp) {
00802
00803
00804 ip = ntest_x + sort_x ;
00805
00806
00807 if(ip >= dim) stopp = 1 ;
00808
00809 if(stopp == 0) {
00810 curvp = (s_vvertice*) xsort[ip].data ;
00811
00812
00813 if(curvp->x - vvalx > dcrit) stopp = 1 ;
00814
00815 else if(curvp->seen == 0) {
00816 if(dist(curvp->x, curvp->y, curvp->z, vvalx, vvaly, vvalz) < dcrit) {
00817
00818 curvp->seen = 1 ;
00819 nb_neigh ++ ;
00820 }
00821 }
00822 }
00823
00824 im = sort_x - ntest_x ;
00825 if(im < 0) stopm = 1 ;
00826
00827 if(stopm == 0) {
00828 curvm = (s_vvertice*) xsort[im].data ;
00829
00830
00831 if(vvalx - curvm->x > dcrit) stopm = 1 ;
00832
00833 else if(curvp->seen == 0) {
00834
00835
00836 if(dist(curvm->x, curvm->y, curvm->z, vvalx, vvaly, vvalz) < dcrit){
00837
00838 curvm->seen = 1 ;
00839 nb_neigh ++ ;
00840 }
00841 }
00842 }
00843
00844 ntest_x += 1 ;
00845 }
00846 }
00847
00848 return nb_neigh ;
00849 }