File: atomprops.c

package info (click to toggle)
king-probe 2.13.110909-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 700 kB
  • ctags: 771
  • sloc: ansic: 10,687; makefile: 40; python: 18
file content (393 lines) | stat: -rw-r--r-- 13,741 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
/* name: atomprops.c                                     */
/* author: J. Michael Word     date written: 6/12/97     */
/* purpose: define atom properties                       */

/*****************************************************************/
/* NOTICE: This is free software and the source code is freely   */
/* available. You are free to redistribute or modify under the   */
/* conditions that (1) this notice is not removed or modified    */
/* in any way and (2) any modified versions of the program are   */
/* also available for free.                                      */
/*               ** Absolutely no Warranty **                    */
/* Copyright (C) 1999 J. Michael Word                            */
/*****************************************************************/

#include <stdio.h>
#include <string.h>  /*060902 needs this for strlen() */
#include <ctype.h>
#define INIT_ATOM_TABLE 1
#include "atomprops.h"

static atomProp* AtomTblIndex[NUMATOMTYPES];
static float ExplMaxRad = 0.0;
static float ImplMaxRad = 0.0;

void initalizeAtomTbl() {
   int i;
   atomProp *ap;
   
   ExplMaxRad = 0.0;
   ImplMaxRad = 0.0;
   for(i=0; i < NUMATOMTYPES; i++) { /* default to noAtom */
      AtomTblIndex[i] = &(AtomTbl[0]);
   }

   for(i=0; i < NUMATOMTYPES; i++) {
      ap = &(AtomTbl[i]);
      AtomTblIndex[ap->type] = ap;

      if (ap->iRad > ImplMaxRad){ ImplMaxRad = ap->iRad; }
      if (ap->eRad > ExplMaxRad){ ExplMaxRad = ap->eRad; }
   }
}

int   getAtno(int a)     { return AtomTblIndex[a]->atno;   }
char* getAtomName(int a) { return AtomTblIndex[a]->name;   }
float getExplRad(int a)  { return AtomTblIndex[a]->eRad;   }
float getImplRad(int a)  { return AtomTblIndex[a]->iRad;   }
float getCovRad(int a)   { return AtomTblIndex[a]->covRad; }
char* getColor(int a)    { return AtomTblIndex[a]->color;  }
float getMaxRadius(int isImpl){
   return (isImpl? ImplMaxRad : ExplMaxRad);
}
int   atomHasProp(int a, int f) {
   return AtomTblIndex[a]->flags & f;
}

int fixAtomName(const char* atomname, char resname[], int position) { /* no bool in C */
   char resn[6];
   char name[5] = "    ";
   int i;
   sprintf(resn, ":%-3.3s:", resname);
   for (i = 0; i < 4; i++) { /* uppercase the input */
      if (atomname[i] == '\0') { break; }
      name[i] = toupper(atomname[i]); 
   }
   name[i] = '\0';
        switch(name[position]) {
           case 'E': if (strstr(HE_RESNAMES, resn) != NULL) { return 1; }
           case 'F': if (strstr(HF_RESNAMES, resn) != NULL) { return 1; }
           case 'G': if (strstr(HG_RESNAMES, resn) != NULL) { return 1; }
           case 'O': if (strstr(HO_RESNAMES, resn) != NULL) { return 1; }
           case 'S': if (strstr(HS_RESNAMES, resn) != NULL) { return 1; }
           default: break;
	}
   return 0; 
}

int identifyAtom(char* name, char resname[], int Verbose) {  /*dcr041007 allow warning choice*/
   int n = -1, emitWarning = 0;

   switch(name[0]) {
   case '*': case '\'': case '"': case '`': case '_':
   case '+': case '-':  case ' ':
   case '0': case '1': case '2': case '3': case '4':
   case '5': case '6': case '7': case '8': case '9':
      switch(name[1]) {
      case 'A':
	 switch(name[3]) {
	 case '1': n = atomO; emitWarning = 1; break;
	 case '2': n = atomN; emitWarning = 1; break;
	 } break;
      case 'B': n = atomB; break;
      case 'C': n = atomC; break;
      case 'D': n = atomH; break;
      case 'F': n = atomF; break;
      case 'H':
        switch(name[2]) {
        case 'E': n = fixAtomName(name,resname,2) ? atomHe : atomH; break; 
        case 'F': n = fixAtomName(name,resname,2) ? atomHf : atomH; break;
        case 'G': n = fixAtomName(name,resname,2) ? atomHg : atomH; break;
        case 'O': n = fixAtomName(name,resname,2) ? atomHo : atomH; break;
/*        case 'S': n = fixAtomName(name,resname,2) ? atomHs : atomH; break; */
        default : n = atomH; break;
        } break;
      case 'I': n = atomI; break;
      case 'K': n = atomK; break;
      case 'N': n = atomN; break;
      case 'O': n = atomO; break;
      case 'P': n = atomP; break;
    /*case 'S': n = atomS; break;*/
      case 'S': 
         if(name[0] == ' ' && name[2] == 'E') 
         {/*_SE likely refmac,cns missplaced Selenium atom name dcr041007*/
                n = atomSe; emitWarning = 1; break;
         }
         else  {n = atomS; break;} /*050121 NO warning for other S*/
      case 'U': n = atomU; break;
      case 'V': n = atomV; break;
      case 'W': n = atomW; break;
      case 'Y': n = atomY; break;
      } break;
   case 'A':
      switch(name[1]) {
      case 'C': n = atomC;  emitWarning = 1;break;/*nonstd!*/
      case 'G': n = atomAg; break;
      case 'H': n = atomH;  emitWarning = 1;break;
      case 'L': n = atomAl; break;
      case 'M': n = atomAm; break;
      case 'N': n = atomN;  emitWarning = 1;break;
      case 'O': n = atomO;  emitWarning = 1;break;
      case 'P': n = atomP;  emitWarning = 1;break;
      case 'R': n = atomAr; break;
      case 'S': n = atomAs; break;
      case 'T': n = atomAt; break;
      case 'U': n = atomAu; break;
      } break;
   case 'B':
      switch(name[1]) {
      case 'A': n = atomBa; break;
      case 'E': n = atomBe; break;
      case 'I': n = atomBi; break;
      case 'K': n = atomBk; break;
      case 'R': n = atomBr; break;
      } break;
   case 'C': 
      switch(name[1]) {
      case 'A': n = atomCa; break;
      case 'C': n = atomC;  emitWarning = 1;break;
      case 'D': n = atomCd; break;
      case 'E': n = atomCe; break;
      case 'F': n = atomCf; break;
      case 'H': n = atomH;  emitWarning = 1;break;
      case 'L': n = atomCl; break;
      case 'M': n = atomCm; break;
      case 'N': n = atomN;  emitWarning = 1;break;
      case 'O': n = atomCo; emitWarning = 1;break;
      case 'P': n = atomP;  emitWarning = 1;break;
      case 'R': n = atomCr; break;
      case 'S': n = atomCs; break;
      case 'U': n = atomCu; break;
      default:  n = atomC;  emitWarning = 1;break;
      } break;
   case 'D':
      switch(name[1]) {
      case 'Y': n = atomDy; break;
      case 'C': n = atomC;  emitWarning = 1;break;
      case 'H': n = atomH;  emitWarning = 1;break;
      case 'N': n = atomN;  emitWarning = 1;break;
      case 'O': n = atomO;  emitWarning = 1;break;
      case 'P': n = atomP;  emitWarning = 1;break;
      default:  n = atomH;  emitWarning = 1;break;
      } break;
   case 'E':
      switch(name[1]) {
      case 'R': n = atomEr; break;
      case 'S': n = atomEs; break;
      case 'U': n = atomEu; break;
      case 'C': n = atomC;  emitWarning = 1;break;
      case 'H': n = atomH;  emitWarning = 1;break;
      case 'N': n = atomN;  emitWarning = 1;break;
      case 'O': n = atomO;  emitWarning = 1;break;
      case 'P': n = atomP;  emitWarning = 1;break;
      } break;
   case 'F':
      switch(name[1]) {
      case 'E': n = atomFe; break;
      case 'M': n = atomFm; break;
      case 'R': n = atomFr; break;
      case 'C': n = atomC;  emitWarning = 1;break;
      case 'H': n = atomH;  emitWarning = 1;break;
      case 'N': n = atomN;  emitWarning = 1;break;
      case 'O': n = atomO;  emitWarning = 1;break;
      case 'P': n = atomP;  emitWarning = 1;break;
      } break;
   case 'G':
      switch(name[1]) {
      case 'A': n = atomGa; break;
      case 'D': n = atomGd; break;
      case 'E': n = atomGe; break;
      case 'C': n = atomC;  emitWarning = 1;break;
      case 'H': n = atomH;  emitWarning = 1;break;
      case 'N': n = atomN;  emitWarning = 1;break;
      case 'O': n = atomO;  emitWarning = 1;break;
      case 'P': n = atomP;  emitWarning = 1;break;
      } break;
   case 'H':
      switch(name[1]) {
      case 'E': n = fixAtomName(name,resname,1) ? atomHe : atomH; break;
      case 'F': n = fixAtomName(name,resname,1) ? atomHf : atomH; break;
      case 'G': n = fixAtomName(name,resname,1) ? atomHg : atomH; break;
      case 'O': n = fixAtomName(name,resname,1) ? atomHo : atomH; break;
/*      case 'S': n = fixAtomName(name,resname,1) ? atomHs : atomH; break; */
      default : n = atomH; break;
      } break;

/*    case 'E': */
/*  if (isdigit(name[2])) { n = atomH; emitWarning = 1;} */ /* Hepsilon?? */
/*  else {n = atomHe; emitWarning = 1;} */
/*  break; */
/*      case 'F': n = atomHf; emitWarning = 1;break; */
/*      case 'G': */
/*  if (isdigit(name[2])) { n = atomH; emitWarning = 1;} */ /* Hgamma?? */
/*  else {n = atomHg; emitWarning = 1;} */
/*  break; */
/*      case 'O': n = atomHo; emitWarning = 1;break; */
/*      default:  n = atomH;  emitWarning = 1;break; */
/*      } break; */

   case 'I':
      switch(name[1]) {
      case 'N': n = atomIn; break;
      case 'R': n = atomIr; break;
      } break;
   case 'K':
      if (name[1] == 'R') n = atomKr; break;
   case 'L':
      switch(name[1]) {
      case 'A': n = atomLa; break;
      case 'I': n = atomLi; break;
      case 'U': n = atomLu; break;
      } break;
   case 'M':
      switch(name[1]) {
      case 'D': n = atomMd; break;
      case 'G': n = atomMg; break;
      case 'N': n = atomMn; break;
      case 'O': n = atomMo; break;
      } break;
   case 'N':
      switch(name[1]) {
      case 'A': n = atomNa; emitWarning = 1;break;
      case 'B': n = atomNb; emitWarning = 1;break;
      case 'C': n = atomC;  emitWarning = 1;break;
      case 'D': n = atomNd; emitWarning = 1;break;
      case 'E': n = atomNe; emitWarning = 1;break;
      case 'H': n = atomH;  emitWarning = 1;break;
      case 'I': n = atomNi; break;
      case 'N': n = atomN;  emitWarning = 1;break;
      case 'O': n = atomO;  emitWarning = 1;break;/*nonstd!*/
      case 'P': n = atomP;  emitWarning = 1;break;/*nonstd!*/
      case 'S': n = atomS;  emitWarning = 1;break;
      default:  n = atomN;  emitWarning = 1;break;
      } break;
   case 'O':
      switch(name[1]) {
      case 'S': n = atomOs; break;
      default:  n = atomO;  emitWarning = 1;break;
      } break;
   case 'P':
      switch(name[1]) {
      case 'A': n = atomPa; emitWarning = 1;break;
      case 'B': n = atomPb; emitWarning = 1;break;
      case 'D': n = atomPd; emitWarning = 1;break;
      case 'M': n = atomPm; break;
      case 'O': n = atomPo; break;
      case 'R': n = atomPr; break;
      case 'T': n = atomPt; break;
      case 'U': n = atomPu; break;
      default:  n = atomP;  emitWarning = 1;break;
      } break;
   case 'R':
      switch(name[1]) {
      case 'A': n = atomRa; break;
      case 'B': n = atomRb; break;
      case 'E': n = atomRe; break;
      case 'H': n = atomRh; break;
      case 'N': n = atomRn; break;
      case 'U': n = atomRu; break;
      } break;
   case 'S':
      switch(name[1]) {
      case 'B': n = atomSb; emitWarning = 1;break;
      case 'C': n = atomSc; break;
      case 'E': n = atomSe; emitWarning = 1;break;
      case 'I': n = atomSi; break;
      case 'M': n = atomSm; break;
      case 'N': n = atomSn; break;
      case 'R': n = atomSr; break;
      default:  n = atomS;  emitWarning = 1;break;
      } break;
   case 'T':
      switch(name[1]) {
      case 'A': n = atomTa; break;
      case 'B': n = atomTb; break;
      case 'C': n = atomTc; break;
      case 'E': n = atomTe; break;
      case 'H': n = atomTh; break;
      case 'I': n = atomTi; break;
      case 'L': n = atomTl; break;
      case 'M': n = atomTm; break;
      } break;
   case 'X':
      if (name[1] == 'E') n = atomXe; break;
   case 'Y':
      if (name[1] == 'B') n = atomYb; break;
   case 'Z':
      switch(name[1]) {
      case 'N': n = atomZn; break;
      case 'R': n = atomZr; break;
      } break;
   default: break;
   }

   if (n < 0) { emitWarning = 1;
      n = atomC;

      switch(name[1]) {
      case 'H': case 'D': n = atomH; break;
      case 'C': n = atomC; break;
      case 'N': n = atomN; break;
      case 'O': n = atomO; break;
      case 'P': n = atomP; break;
      case 'S': n = atomS; break;

      case 'I': n = atomI; break;
      case 'K': n = atomK; break;
      case 'V': n = atomV; break;
      case 'W': n = atomW; break;
      case 'U': n = atomU; break;

      case 'A':
	 switch(name[2]) {
	 case 'G': n = atomAg; break;
	 case 'L': n = atomAl; break;
	 case 'S': n = atomAs; break;
	 case 'U': n = atomAu; break;
	 } break;
      case 'F':
	 if (name[2] == 'E') n = atomFe; break;
      case 'G':
	 if (name[2] == 'D') n = atomGd; break;
      case 'L':
	 if (name[2] == 'I') n = atomLi; break;
      case 'M':
	 switch(name[2]) {
	 case 'G': n = atomMg; break;
	 case 'N': n = atomMn; break;
	 case 'O': n = atomMo; break;
	 } break;
      case 'Z':
	 if (name[2] == 'N') n = atomZn; break;
/* --------- default if we fall through... ---------------------*/
      default: n = atomC; break;
      }
   }
   if (emitWarning && Verbose) {/*Verbose controlled dcr041007*/
      char warnstr[5]={'_','_','_','_','\0'}; /*dcr041007*/
      char warnresn[5]={'_','_','_','_','\0'}; /*rmi070719*/
      char* atstr;
      int j=0;
      while(name[j]!='\0'&&warnstr[j]!='\0')
      {/*explicitly show blanks so can understand atom name problem*/
         if(name[j]==' ') {warnstr[j]='_';}
         else             {warnstr[j]=name[j];}
         j++;
      }
      j=0;
      while(resname[j]!='\0'&&warnresn[j]!='\0')
      {/*explicitly show blanks so can understand residue/atom name problem*/
         if(name[j]==' ') {warnresn[j]='_';}
         else             {warnresn[j]=resname[j];}
         j++;
      }
      atstr = getAtomName(n);
      if(strlen(atstr)==1)
           {fprintf(stderr,"WARNING: atom %s from resn %s will be treated as  %s\n",warnstr,warnresn,atstr);}
      else {fprintf(stderr,"WARNING: atom %s from resn %s will be treated as %s\n",warnstr,warnresn,atstr);}
         /*name, getAtomName(n));*/
   }

   return n;
}