00001
00002 #include "../headers/atom.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 float get_mol_mass(s_atm *latoms, int natoms)
00086 {
00087 float mass = 00.0 ;
00088 if(latoms) {
00089 int i ;
00090 for(i = 0 ; i < natoms ; i++) {
00091 mass += latoms[i].mass ;
00092 }
00093 }
00094 return mass ;
00095 }
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 float get_mol_mass_ptr(s_atm **latoms, int natoms)
00113 {
00114 float mass = 00.0 ;
00115 if(latoms) {
00116 int i ;
00117 for(i = 0 ; i < natoms ; i++) {
00118 mass += latoms[i]->mass ;
00119 }
00120 }
00121 return mass ;
00122 }
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 void set_mol_barycenter_ptr(s_atm **latoms, int natoms, float bary[3])
00142 {
00143 float xsum = 0.0,
00144 ysum = 0.0,
00145 zsum = 0.0 ;
00146
00147 if(latoms) {
00148 int i ;
00149 for(i = 0 ; i < natoms ; i++) {
00150 xsum += latoms[i]->x ;
00151 ysum += latoms[i]->y ;
00152 zsum += latoms[i]->z ;
00153 }
00154 }
00155
00156 bary[0] = xsum / natoms ;
00157 bary[1] = xsum / natoms ;
00158 bary[2] = xsum / natoms ;
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178 float get_mol_volume_ptr(s_atm **atoms, int natoms, int niter)
00179 {
00180 int i = 0, j = 0,
00181 nb_in = 0;
00182
00183 float xmin = 0.0, xmax = 0.0,
00184 ymin = 0.0, ymax = 0.0,
00185 zmin = 0.0, zmax = 0.0,
00186 xtmp = 0.0, ytmp = 0.0, ztmp = 0.0,
00187 xr = 0.0, yr = 0.0, zr = 0.0,
00188 vbox = 0.0 ;
00189
00190 s_atm *acur = NULL ;
00191
00192
00193 for(i = 0 ; i < natoms ; i++) {
00194 acur = atoms[i] ;
00195
00196 if(i == 0) {
00197 xmin = acur->x - acur->radius ; xmax = acur->x + acur->radius ;
00198 ymin = acur->y - acur->radius ; ymax = acur->y + acur->radius ;
00199 zmin = acur->z - acur->radius ; zmax = acur->z + acur->radius ;
00200 }
00201 else {
00202
00203 if(xmin > (xtmp = acur->x - acur->radius)) xmin = xtmp ;
00204 else if(xmax < (xtmp = acur->x + acur->radius)) xmax = xtmp ;
00205
00206 if(ymin > (ytmp = acur->y - acur->radius)) ymin = ytmp ;
00207 else if(ymax < (ytmp = acur->y + acur->radius)) ymax = ytmp ;
00208
00209 if(zmin > (ztmp = acur->z - acur->radius)) zmin = ztmp ;
00210 else if(zmax < (ztmp = acur->z + acur->radius)) zmax = ztmp ;
00211 }
00212 }
00213
00214
00215 vbox = (xmax - xmin)*(ymax - ymin)*(zmax - zmin) ;
00216
00217
00218 for(i = 0 ; i < niter ; i++) {
00219 xr = rand_uniform(xmin, xmax) ;
00220 yr = rand_uniform(ymin, ymax) ;
00221 zr = rand_uniform(zmin, zmax) ;
00222
00223 for(j = 0 ; j < natoms ; j++) {
00224 acur = atoms[j] ;
00225 xtmp = acur->x - xr ;
00226 ytmp = acur->y - yr ;
00227 ztmp = acur->z - zr ;
00228
00229
00230 if((acur->radius*acur->radius) > (xtmp*xtmp + ytmp*ytmp + ztmp*ztmp)) {
00231
00232 nb_in ++ ; break ;
00233 }
00234 }
00235 }
00236
00237
00238 return ((float)nb_in)/((float)niter)*vbox;
00239 }
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257 int is_in_lst_atm(s_atm **lst_atm, int nb_atm, int atm_id)
00258 {
00259 int i ;
00260 for(i = 0 ; i < nb_atm ; i++) {
00261 if(atm_id == lst_atm[i]->id) return 1 ;
00262 }
00263
00264 return 0 ;
00265 }
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286 float atm_corsp(s_atm **al1, int nal1, s_atm **al2, int nal2)
00287 {
00288 int i, j,
00289 nb_atm_found = 0 ;
00290 s_atm *cural = NULL,
00291 *curap ;
00292
00293 if(nal1 <=0 || nal2 <= 0){
00294 return 0.0 ;
00295 }
00296
00297 for(i = 0 ; i < nal1 ; i++) {
00298 for(j = 0 ; j < nal2 ; j++) {
00299 cural = al1[i] ;
00300 curap = al2[j] ;
00301
00302 if(curap->res_id == cural->res_id &&
00303 ( (curap->id == cural->id) || strcmp(cural->name, curap->name) == 0 ) ) {
00304 nb_atm_found++ ;
00305 break ;
00306 }
00307 }
00308 }
00309
00310
00311 return ((float)nb_atm_found)/((float)nal1)*100.0 ;
00312 }
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329 void print_atoms(FILE *f, s_atm *atoms, int natoms)
00330 {
00331 s_atm *atom = NULL ;
00332 int i ;
00333 for(i = 0 ; i < natoms ; i++) {
00334 atom = atoms + i ;
00335 fprintf(f, "======== Atom %s (%d) ========\n", atom->name, atom->id) ;
00336 fprintf(f, "Type: '%s', Residu: '%s' (%d), Chain: '%s'\n",
00337 atom->type, atom->res_name, atom->res_id, atom->chain);
00338 fprintf(f, "x: %f, y: %f, z: %f, occ: %f, bfact: %f\n",
00339 atom->x, atom->y, atom->z, atom->occupancy, atom->bfactor);
00340 fprintf(f, "symbol: '%s', charge: %d, mass: %f, vdw: %f\n",
00341 atom->symbol, atom->charge, atom->mass, atom->radius);
00342 }
00343 }