ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/freemol/branches/sync4pymol12/src/mengine/src/read_pcm.c
Revision: 93
Committed: Sat Jan 17 23:24:55 2009 UTC (13 years, 4 months ago) by wdelano
File size: 41391 byte(s)
Log Message:
branch created
Line File contents
1 #define EXTERN extern
2
3 #include "pcwin.h"
4 #include "pcmod.h"
5 #include "energies.h"
6 #include "pdb.h"
7 #include "solv.h"
8 #include "fix.h"
9 #include "atom_k.h"
10 #include "draw.h"
11
12 void rdfile(int, int);
13 void rdpcm(int,int);
14 void pcmfin(int,int);
15 void pcmfout(int);
16 void gettoken(void);
17 void initialize(void);
18 FILE * fopen_path ( char * , char * , char * ) ;
19 int FetchRecord(FILE *, char *);
20 void zero_data(void);
21 void read_datafiles(char *);
22 void read_atomtypes(int);
23 void get_atomname(int,char *);
24 void clean_string(char *);
25 void hdel(int);
26
27 /* COMMON translations */
28 struct t_pcmfile {
29 char string[200];
30 int head;
31 char token[20];
32 int state;
33 unsigned int nocaps;
34 } pcmfile;
35
36 EXTERN struct t_minim_values {
37 int iprint, ndc, nconst;
38 float dielc;
39 } minim_values;
40
41 EXTERN struct t_files {
42 int nfiles, append, batch, icurrent, ibatno;
43 } files;
44
45 int oh2, oh3, oh6;
46 EXTERN int mm3_mmx[];
47 EXTERN int mmff_mmx[];
48 EXTERN int amber_mmx[];
49 EXTERN int opls_mmx[];
50
51 // ========================================================
52 void read_atomtypes(int field)
53 {
54 char string[20];
55
56 if (field == MM3)
57 {
58 strcpy(string,"mm3.prm");
59 zero_data();
60 read_datafiles(string);
61 } else if (field == MMFF94)
62 {
63 strcpy(string,"mmff94.prm");
64 zero_data();
65 read_datafiles(string);
66 } else if (field == AMBER)
67 {
68 strcpy(string,"amber.prm");
69 zero_data();
70 read_datafiles(string);
71 } else if (field == OPLSAA)
72 {
73 strcpy(string,"oplsaa.prm");
74 zero_data();
75 read_datafiles(string);
76 } else if (field == MMX)
77 {
78 strcpy(string,"mmxconst.prm");
79 zero_data();
80 read_datafiles(string);
81 }
82 }
83 // ========================================================
84 void get_atomname(int type,char *name)
85 {
86 int i;
87 strcpy(name,"");
88 for (i=1; i <= MAXATOMTYPE; i++)
89 {
90 if (type == atom_k.type[i])
91 {
92 strcpy(name,atom_k.symbol[i]);
93 return;
94 }
95 }
96 }
97 // ==================================================
98 void pcmfout(int mode)
99 {
100 FILE *wfile;
101 int icoord, imetflag, ispin,lps;
102 int i,j,isub,icount, itype;
103
104 /* Mode = 1 normal packed write operation
105 * Mode = 2 fast no questions asked unpacked write of pcmod.bak
106 * Mode = 3 fast no questions ot file = wfile
107 * mode = 4 start of minim to pcmod.bak but ask questions about pi */
108 if( mode == 1 )
109 {
110 /* assume append is set when we get a filename that exists */
111 /* put up dialog box with current structure title, pi flags
112 and added constants question */
113 if( files.append )
114 wfile = fopen_path(Savebox.path,Savebox.fname,"a");
115 else
116 wfile = fopen_path(Savebox.path,Savebox.fname,"w");
117 }
118 else if( mode == 2 || mode == 4 )
119 {
120 wfile = fopen_path(pcwindir,"pcmod.bak","w");
121 }
122 else if( mode == 3 )
123 {
124 if( files.append )
125 wfile = fopen_path(Savebox.path,Savebox.fname,"a");
126 else
127 wfile = fopen_path(Savebox.path,Savebox.fname,"w");
128 }
129 if (wfile == NULL)
130 {
131 message_alert("Error opening file in PCMFOUT. Cannot create file","PCM File");
132 return;
133 }
134 // remove lone pairs if not writing mmx types
135 lps = FALSE;
136 if (default_outtype != MMX)
137 {
138 for (i=1; i <= natom; i++)
139 {
140 if (atom[i].mmx_type == 20)
141 {
142 lps = TRUE;
143 break;
144 }
145 }
146 }
147 if (lps == TRUE)
148 hdel(1);
149
150 /* start of file writing */
151 fprintf(wfile,"{PCM %s\n",Struct_Title);
152 fprintf(wfile,"NA %d\n",natom);
153
154 /* flags */
155 fprintf(wfile,"FL ");
156 fprintf(wfile,"EINT%d ",minim_values.ndc);
157 if( units.dielec != 1.5 )
158 fprintf(wfile,"DIELC%f ",units.dielec);
159 fprintf(wfile,"\n");
160 // default output filetypes
161 fprintf(wfile,"ATOMTYPES %d\n",default_outtype);
162 /* substructure name information */
163 icount = 0;
164 /* box of solvent information */
165 if (solv.nmols > 0)
166 {
167 fprintf(wfile,"NMOL %d DENSITY %f BOX %f %f %f\n",solv.nmols,solv.density,solv.boxx, solv.boxy,solv.boxz);
168 }
169 /*
170 if( minim_values.nconst && mode > 1 )
171 fprintf(wfile,"CO FILE %s\n",constf.cname);*/
172 /* atoms and bonds lists */
173 for( i = 1; i <= natom; i++ )
174 {
175 if (default_outtype == MMX)
176 {
177 itype = atom[i].mmx_type;
178 } else if (default_outtype == MM3)
179 {
180 itype = atom[i].mm3_type;
181 } else if (default_outtype == MMFF94)
182 {
183 itype = atom[i].mmff_type;
184 }
185 fprintf(wfile,"AT %d %d %8.4f %8.4f %8.4f",i,itype,atom[i].x,
186 atom[i].y, atom[i].z);
187 // bonds
188 fprintf(wfile," B");
189 for( j = 0; j < MAXIAT; j++ )
190 {
191 if( atom[i].iat[j])
192 {
193 fprintf(wfile," %d %d",atom[i].iat[j],atom[i].bo[j]);
194 }
195 }
196 if( atom[i].flags & (1L << HBOND_MASK) )
197 fprintf(wfile," H ");
198 if( atom[i].flags & (1L << PI_MASK) )
199 fprintf(wfile," P ");
200 if( atom[i].mmx_type >= 300 )
201 {
202 icoord = 0;
203 ispin = -1;
204 imetflag = 0;
205 if( atom[i].flags & (1L << SATMET_MASK) )
206 imetflag += 2;
207 if( atom[i].flags & (1L << GT18e_MASK) )
208 imetflag += 1;
209 if( imetflag == 2 )
210 icoord = 0;
211 if( imetflag == 1 )
212 icoord = 2;
213 if( imetflag == 3 )
214 {
215 icoord = 1;
216 imetflag = 0;
217 if( atom[i].flags & (1L << LOWSPIN_MASK) )
218 imetflag += 2;
219 if( atom[i].flags & (1L << SQPLAN_MASK) )
220 imetflag += 1;
221 if( imetflag == 2 )
222 ispin = 0;
223 if( imetflag == 3 )
224 ispin = 2;
225 if( imetflag == 1 )
226 ispin = 1;
227 }
228 if( icoord )
229 {
230 fprintf(wfile," M %d",icoord);
231 if( ispin >= 0 )
232 fprintf(wfile," %d",ispin);
233 }
234 fprintf(wfile," R %g",atom[i].radius);
235 }
236 if( atom[i].charge )
237 {
238 fprintf(wfile," C %g",atom[i].charge);
239 }
240 fprintf(wfile,"\n");
241 }
242
243 fprintf(wfile,"}\n");
244 fclose(wfile);
245 } /* end of function */
246
247 /* ------------------------------- */
248
249 #define NL gettoken(); if (pcmfile.head == 1000) goto L_30;
250 #define ALPHABETIC 2
251 #define NUMERIC 1
252
253 void pcmfin(int nth,int isubred)
254 {
255 int newatom, i, ibondcount, ibonded, ibondorder,
256 icoord, imetcount, ioffset, ispin, iprint,
257 isubmap[MAXSS], j, numbonds, niatom, itemp;
258 int newat, newtype, ifile, isMetal, itype;
259 long int mask;
260 char ianame[3];
261 float ddcount, xtmp, ytmp, ztmp;
262 FILE *pcminfile;
263
264 imetcount = 0;
265 isMetal = FALSE;
266 ddcount = 0;
267 pcmfile.nocaps = False;
268 numbonds = 0;
269 ibondcount = 0;
270 units.dielec = 1.5;
271
272 for (i = 0; i < MAXSS; i++)
273 {
274 isubmap[i] = 0;
275 }
276
277 if( isubred == 1 )
278 {
279 ioffset = natom;
280 }
281 else
282 {
283 ioffset = 0;
284 }
285
286 pcminfile = fopen_path(Openbox.path,Openbox.fname,"r");
287
288 if (pcminfile == NULL)
289 {
290 message_alert("Error Opening PCM file","PCM Setup");
291 fprintf(pcmlogfile,"PCMFIN error opening file %d %s\n",nth,Openbox.fname);
292 return;
293 }
294
295 ifile = 0;
296 if (nth != 1)
297 {
298 while ( FetchRecord(pcminfile,pcmfile.string) )
299 {
300 if (strncasecmp(pcmfile.string,"{PCM",4) == 0)
301 {
302 ifile++;
303 if (ifile == nth)
304 break;
305 }
306 }
307 }else
308 {
309 FetchRecord(pcminfile,pcmfile.string);
310 }
311
312 /* finished scaning to starting structure now read file */
313 if (isubred == 0)
314 {
315 sscanf(pcmfile.string, "{PCM %60c", Struct_Title);
316 clean_string(Struct_Title);
317 } else
318 {
319 if (natom < 1 )
320 {
321 sscanf(pcmfile.string, "{PCM %60c", Struct_Title);
322 clean_string(Struct_Title);
323 }
324 }
325 L_30:
326 FetchRecord(pcminfile,pcmfile.string);
327 *(pcmfile.string + strlen(pcmfile.string) ) = '\0';
328 if (feof(pcminfile))
329 goto L_170;
330 pcmfile.head = 1;
331 NL;
332 L_40:
333 if (strcmp(pcmfile.token, "NA") == 0)
334 {
335 gettoken();
336 if (pcmfile.head == 1000)
337 goto L_30;
338 niatom = atoi(pcmfile.token);
339 if (niatom + ioffset > MAXATOM)
340 {
341 natom = ioffset;
342 fclose(pcminfile);
343 message_alert(" Maximum number of atoms exceeded in PCMFIN","PCM Setup");
344 fprintf(pcmlogfile," unable to continue reading, more than Max atoms %d\n",MAXATOM);
345 return;
346 }
347 niatom += ioffset;
348 NL;
349 goto L_30;
350 } else if (strcmp(pcmfile.token,"ATOMTYPES") == 0)
351 {
352 gettoken();
353 if (pcmfile.head == 1000)
354 goto L_30;
355 itemp = atoi(pcmfile.token);
356 if (itemp != default_intype)
357 {
358 default_intype = itemp;
359 read_atomtypes(default_intype);
360 }
361 NL;
362 goto L_30;
363 } else if (strcmp(pcmfile.token,"SSNAME") == 0 && isubred == 0) // substructure name
364 {
365 gettoken();
366 if (pcmfile.head == 1000) goto L_30;
367 } else if (strcmp(pcmfile.token, "NT") == 0) /* This is for Amino Acids */
368 {
369 NL;
370 i = atoi(pcmfile.token); /* i is atom number of N terminus */
371 mask = 1L << NTERM; /* use bit 0 of substr 1 for N terminus*/
372 atom[i+ioffset].flags |= mask;
373
374 NL;
375 if (strcmp(pcmfile.token, "CT") == 0)
376 {
377 NL;
378 i = atoi(pcmfile.token); /* i is atom number of C terminus */
379 mask = 1L << CNTERM; /* use bit 1 of substr 1 for C terminus */
380 atom[i+ioffset].flags |= mask;
381 }
382 } else if (strcmp(pcmfile.token, "5PRIME") == 0) /* This is for Nucleic Acids */
383 {
384 NL;
385 i = atoi(pcmfile.token); /* i is atom number of 5prime terminus */
386 mask = 1L << P5;
387 atom[i+ioffset].flags |= mask;
388 }else if (strcmp(pcmfile.token, "3PRIME") == 0) /* This is for Nucleic Acids */
389 {
390 NL;
391 i = atoi(pcmfile.token); /* i is atom number of C terminus */
392 mask = 1L << P3; /* use bit 1 of substr 1 for C terminus */
393 atom[i+ioffset].flags |= mask;
394 } else if (strcmp(pcmfile.token, "FG") == 0) /* This is for functional groups */
395 {
396 NL;
397 i = atoi(pcmfile.token); /* i is atom number of connect point */
398 mask = 1L << DUMMY; /* use bit 0 of substr 1 for connect*/
399 atom[i+ioffset].flags |= mask;
400
401 } else if (strcmp(pcmfile.token, "OT") == 0) /* This is for Sugars */
402 {
403 NL;
404 i = atoi(pcmfile.token); /* i is atom number of O terminus */
405 mask = 1L << NTERM; /* use bit 0 of substr 1 for O terminus*/
406 atom[i+ioffset].flags |= mask;
407
408 NL;
409 if (strcmp(pcmfile.token, "CT") == 0)
410 {
411 NL;
412 i = atoi(pcmfile.token); /* i is atom number of H terminus */
413 mask = 1L << CNTERM; /* use bit 1 of substr 1 for H terminus */
414 atom[i+ioffset].flags |= mask;
415 }
416
417 NL;
418 if (strcmp(pcmfile.token, "OTWO") == 0)
419 {
420 NL;
421 i = atoi(pcmfile.token); /* i is atom number of H terminus */
422 oh2 = i+ioffset;
423 }
424
425 NL;
426 if (strcmp(pcmfile.token, "OTHR") == 0)
427 {
428 NL;
429 i = atoi(pcmfile.token); /* i is atom number of H terminus */
430 oh3 = i+ioffset;
431 }
432
433 NL;
434 if (strcmp(pcmfile.token, "OSIX") == 0)
435 {
436 NL;
437 i = atoi(pcmfile.token); /* i is atom number of H terminus */
438 oh6 = i+ioffset;
439 }
440 } else if (strcmp(pcmfile.token,"START") == 0) /* flag for polybuild */
441 {
442 NL;
443 i = atoi(pcmfile.token);
444 mask = 1L << DUMMY;
445 atom[i+ioffset].flags |= mask;
446 NL; // END
447 NL;
448 i = atoi(pcmfile.token);
449 mask = 1L << DUMMY;
450 atom[i+ioffset].flags |= mask;
451 } else if (strcmp(pcmfile.token,"NMOL") == 0)
452 {
453 NL;
454 solv.nmols = atoi(pcmfile.token);
455 NL;
456 NL;
457 solv.density = atof(pcmfile.token);
458 NL;
459 NL;
460 solv.boxx = atof(pcmfile.token);
461 NL;
462 solv.boxy = atof(pcmfile.token);
463 NL;
464 solv.boxz = atof(pcmfile.token);
465 goto L_30;
466 } else if (strcmp(pcmfile.token, "SS") == 0)
467 {
468 goto L_30;
469 } else if (strcmp(pcmfile.token, "AT") == 0)
470 {
471 NL;
472 newat = atoi(pcmfile.token); // atom serial number
473 if (newat + ioffset > MAXATOM)
474 {
475 message_alert(" Maximum number of atoms exceeded in PCMFIN at atom read","PCM Setup");
476 fprintf(pcmlogfile,"atom read %d %d %d\n",newat,ioffset,natom);
477 natom = ioffset + newat - 1;
478 fclose(pcminfile);
479 exit(0);
480 }
481 newat += ioffset;
482 NL;
483 if (isdigit(*pcmfile.token))
484 {
485 newtype = atoi(pcmfile.token);
486 } else // character string for metal atom
487 {
488 strcpy(ianame,pcmfile.token);
489 isMetal = TRUE;
490 i = strlen(ianame);
491 if ( i == 2)
492 ianame[1] = tolower(ianame[1]);
493 }
494 NL;
495 xtmp = atof(pcmfile.token);
496 NL;
497 ytmp = (atof(pcmfile.token));
498 NL;
499 ztmp = atof(pcmfile.token);
500 NL;
501 if (isMetal == FALSE)
502 {
503 itype = newtype;
504 get_atomname(newtype,ianame);
505 if (default_intype == MM3)
506 itype = mm3_mmxtype(newtype);
507 else if (default_intype == MMFF94)
508 itype = mmff_mmxtype(newtype);
509
510 newatom = make_atom(newtype, xtmp, ytmp, ztmp,ianame);
511 if (default_intype == MM3)
512 set_atomtype(newatom, itype,newtype,0,0,0);
513 else if (default_intype == MMFF94)
514 set_atomtype(newatom, itype,0,newtype,0,0);
515 }else if (isMetal == TRUE)
516 {
517 newatom = make_atom(0, xtmp, ytmp, ztmp,ianame);
518 isMetal = FALSE;
519 last_atom = newatom;
520 }
521
522 L_90:
523 if (strcmp(pcmfile.token, "B") == 0)
524 {
525 /* Reading bonds now */
526 NL;
527 j = 0;
528 L_100:
529 j += 1;
530 if (pcmfile.state == NUMERIC)
531 {
532 ibonded = atoi(pcmfile.token);
533 ibonded += ioffset;
534 } else
535 {
536 goto L_90;
537 }
538 NL;
539 if (pcmfile.state == NUMERIC)
540 {
541 ibondorder = atoi(pcmfile.token);
542 } else
543 {
544 fprintf(stdout, "missing a bondorder, assuming 1\n");
545 goto L_40;
546 }
547 if (newatom < ibonded)
548 make_bond(newatom, ibonded, ibondorder);
549 if (ibondorder == 9)
550 {
551 atom[newatom].flags |= (1L << METCOORD_MASK);
552 atom[ibonded].flags |= (1L << METCOORD_MASK);
553 }
554 NL;
555 goto L_100;
556 }else if ( strcmp(pcmfile.token, "P")== 0)
557 {
558 atom[newatom].flags |= (1L << PI_MASK);
559 NL;
560 goto L_90;
561 }else if (strcmp(pcmfile.token, "D") == 0) // biomolecule marking
562 {
563 NL;
564 NL;
565 goto L_90;
566 }else if (strcmp(pcmfile.token, "N") == 0) // residue number
567 {
568 NL;
569 NL;
570 goto L_90;
571 }else if (strcmp(pcmfile.token,"M")==0)
572 {
573 NL;
574 icoord = atoi(pcmfile.token);
575 if (icoord == 0)
576 {
577 atom[newatom].flags |= (1L << SATMET_MASK);
578 } else if (icoord == 2)
579 {
580 atom[newatom].flags |= (1L << GT18e_MASK);
581 } else{
582 atom[newatom].flags |= (1L << GT18e_MASK);
583 atom[newatom].flags |= (1L << SATMET_MASK);
584 }
585 NL;
586 if (pcmfile.state != 1)
587 goto L_90;
588 ispin = atoi(pcmfile.token);
589 if (ispin == 0)
590 {
591 atom[newatom].flags |= (1L << LOWSPIN_MASK);
592 } else if (ispin == 1)
593 {
594 atom[newatom].flags |= (1L << SQPLAN_MASK);
595 } else
596 {
597 atom[newatom].flags |= (1L << LOWSPIN_MASK);
598 atom[newatom].flags |= (1L << SQPLAN_MASK);
599 }
600 NL;
601 goto L_90;
602 }else if (strcmp(pcmfile.token,"S")== 0)
603 {
604 NL;
605 if (pcmfile.state == NUMERIC)
606 {
607 j = atoi(pcmfile.token);
608 mask = (1L << j);
609 NL;
610 goto L_90;
611 } else
612 {
613 goto L_90;
614 }
615 }else if (strcmp(pcmfile.token,"H")== 0)
616 {
617 atom[newatom].flags |= (1L << HBOND_MASK);
618 NL;
619 goto L_90;
620 }else if (strcmp(pcmfile.token,"C")==0)
621 {
622 NL;
623 atom[newatom].charge = atof(pcmfile.token);
624 NL;
625 goto L_90;
626 } else if (strcmp(pcmfile.token,"ML") == 0)
627 {
628 NL;
629 j = atoi(pcmfile.token);
630 goto L_90;
631 }else if (strcmp(pcmfile.token,"R")== 0)
632 {
633 NL;
634 atom[newatom].radius = atof(pcmfile.token);
635 NL;
636 goto L_90;
637 }
638 } else if (strncasecmp(pcmfile.token, "}",1) == 0)
639 {
640 goto L_170; /* end of structure */
641 } else if (strcmp(pcmfile.token, "FL") == 0)
642 {
643 NL;
644 L_120: if (strcmp(pcmfile.token, "PRINT") == 0)
645 {
646 iprint = 1;
647 NL;
648 if (pcmfile.state == ALPHABETIC)
649 goto L_120;
650 iprint = atoi(pcmfile.token);
651 NL;
652 goto L_120;
653 } else if (strcmp(pcmfile.token, "DIELC") == 0)
654 {
655 NL;
656 if (pcmfile.state != 1)
657 goto L_120;
658 units.dielec = atof(pcmfile.token);
659 NL;
660 goto L_120;
661 } else if (strcmp(pcmfile.token, "UV") == 0)
662 {
663 NL;
664 if (pcmfile.state != 1)
665 goto L_120;
666 // pistuf.iuv = atoi(pcmfile.token);
667 NL;
668 goto L_120;
669 } else if (strcmp(pcmfile.token, "PIPR") == 0)
670 {
671 NL;
672 if (pcmfile.state != 1)
673 goto L_120;
674 // pistuf.jprint = atoi(pcmfile.token);
675 NL;
676 goto L_120;
677 } else if (strcmp(pcmfile.token, "PIPL") == 0)
678 {
679 NL;
680 if (pcmfile.state != 1)
681 goto L_120;
682 // pistuf.nplane = atoi(pcmfile.token);
683 NL;
684 goto L_120;
685 } else if (strcmp(pcmfile.token, "EINT") == 0)
686 {
687 NL;
688 if (pcmfile.state != 1)
689 goto L_120;
690 minim_values.ndc = atoi(pcmfile.token);
691 NL;
692 goto L_120;
693 }
694 } else if (strcmp(pcmfile.token, "CO") == 0)
695 {
696 } else if (strcmp(pcmfile.token, "FBND") == 0)
697 {
698 }
699 goto L_30;
700 L_170:
701 fclose(pcminfile);
702 return;
703 }
704 // ==================================
705 void gettoken()
706 {
707 int foundtoken, i;
708
709 pcmfile.state = 0;
710 foundtoken = -1;
711 strcpy(pcmfile.token, "");
712 for (i = pcmfile.head - 1; i <= strlen(pcmfile.string); i++) {
713 if ((*(pcmfile.string + i) != ':') &&
714 (*(pcmfile.string + i) != ' ') &&
715 (*(pcmfile.string + i) != '\0') &&
716 (*(pcmfile.string + i) != ';') &&
717 (*(pcmfile.string + i) != ',') &&
718 (*(pcmfile.string + i) != '\t')) {
719 if (foundtoken == -1) {
720 foundtoken = i;
721 if (isdigit(*(pcmfile.string + i))) {
722 /* beginning to read a number */
723 pcmfile.state = 1;
724 } else if ((*(pcmfile.string + i) == '.') ||
725 (*(pcmfile.string + i) == '-')) {
726 /* period or dash can't yet tell if
727 * word or number */
728 pcmfile.state = 3;
729 } else {
730 /* must be a word */
731 pcmfile.state = 2;
732 }
733 } else {
734 if (
735 (
736 (pcmfile.state == 2) &&
737 (isdigit(*(pcmfile.string + i)))
738 )
739 ||
740 (
741 (pcmfile.state == 1) &&
742 (isalpha(*(pcmfile.string + i)))
743 )
744 ) {
745 foundtoken = i;
746 goto L_30;
747 } else if (pcmfile.state == 3) {
748 if (isdigit(*(pcmfile.string + i)) ||
749 *(pcmfile.string + i) == '.') {
750 pcmfile.state = 1;
751 } else {
752 pcmfile.state = 2;
753 }
754 }
755 }
756 strncat(pcmfile.token, pcmfile.string + i, 1);
757 } else if (foundtoken != -1) {
758 foundtoken = i;
759 goto L_30;
760 }
761 }
762 if (foundtoken == -1) {
763 pcmfile.head = 1000;
764 return;
765 }
766 L_30:
767 pcmfile.head = foundtoken + 1;
768 if (pcmfile.state == 2 && !pcmfile.nocaps)
769 {
770 for (i = 0; i < strlen(pcmfile.token); i++)
771 {
772 if (!isupper(*(pcmfile.token + i)))
773 *(pcmfile.token + i) = toupper(*(pcmfile.token + i));
774 }
775 }
776 return;
777 }
778 /* ============================================================ */
779 FILE *pcminfile;
780 /* ============================================================ */
781 void rdfile(int mode, int isub)
782 {
783 if (mode == -1)
784 fclose(pcminfile);
785 else if (mode == 0)
786 {
787 pcminfile = fopen_path(Openbox.path,Openbox.fname, "r");
788
789 if (pcminfile == NULL)
790 {
791 message_alert("Error Opening PCM file","Error");
792 return;
793 }
794 } else
795 rdpcm(mode,isub);
796 }
797 /* ============================================================ */
798 void rdpcm(int nth,int isubred)
799 {
800 int i, ibondcount, ibonded, ibondorder,imetcount, ioffset,
801 isubmap[MAXSS], j, numbonds, niatom;
802 int newat, newtype, isMetal;
803 long int mask;
804 char ianame[3];
805 float ddcount, xtmp, ytmp, ztmp;
806
807 imetcount = 0;
808 isMetal = FALSE;
809 ddcount = 0;
810 pcmfile.nocaps = False;
811 numbonds = 0;
812 ibondcount = 0;
813 for (i = 0; i < MAXSS; i++)
814 {
815 isubmap[i] = 0;
816 }
817
818 if( isubred == 1 )
819 {
820 ioffset = natom;
821 }
822 else
823 {
824 ioffset = 0;
825 }
826
827
828 FetchRecord(pcminfile,pcmfile.string);
829 L_30:
830 FetchRecord(pcminfile,pcmfile.string);
831 *(pcmfile.string + strlen(pcmfile.string) ) = '\0';
832 if (feof(pcminfile))
833 goto L_170;
834 pcmfile.head = 1;
835 NL;
836 L_40:
837 if (strcmp(pcmfile.token, "NA") == 0)
838 {
839 gettoken();
840 if (pcmfile.head == 1000)
841 goto L_30;
842 niatom = atoi(pcmfile.token);
843 niatom += ioffset;
844 NL;
845 goto L_30;
846 } else if (strcmp(pcmfile.token,"ATOMTYPES") == 0)
847 {
848 gettoken();
849 if (pcmfile.head == 1000)
850 goto L_30;
851 default_intype = atoi(pcmfile.token);
852 NL;
853 goto L_30;
854 } else if (strcmp(pcmfile.token, "NT") == 0) /* This is for Amino Acids */
855 {
856 NL;
857 i = atoi(pcmfile.token); /* i is atom number of N terminus */
858 mask = 1L << NTERM; /* use bit 0 of substr 1 for N terminus*/
859 atom[i+ioffset].flags |= mask;
860
861 NL;
862 if (strcmp(pcmfile.token, "CT") == 0)
863 {
864 NL;
865 i = atoi(pcmfile.token); /* i is atom number of C terminus */
866 mask = 1L << CNTERM; /* use bit 1 of substr 1 for C terminus */
867 atom[i+ioffset].flags |= mask;
868 }
869 } else if (strcmp(pcmfile.token, "OT") == 0) /* This is for Sugars */
870 {
871 NL;
872 i = atoi(pcmfile.token); /* i is atom number of O terminus */
873 mask = 1L << OTERM; /* use bit 0 of substr 1 for O terminus*/
874 atom[i+ioffset].flags |= mask;
875
876 NL;
877 if (strcmp(pcmfile.token, "CT") == 0)
878 {
879 NL;
880 i = atoi(pcmfile.token); /* i is atom number of H terminus */
881 mask = 1L << COTERM; /* use bit 1 of substr 1 for H terminus */
882 atom[i+ioffset].flags |= mask;
883 }
884 } else if (strcmp(pcmfile.token,"START") == 0) /* flag for polybuild */
885 {
886 NL;
887 i = atoi(pcmfile.token);
888 mask = 1L << DUMMY;
889 atom[i+ioffset].flags |= mask;
890 NL; // END
891 NL;
892 i = atoi(pcmfile.token);
893 mask = 1L << DUMMY;
894 atom[i+ioffset].flags |= mask;
895
896 } else if (strcmp(pcmfile.token, "SS") == 0)
897 {
898 goto L_30;
899 } else if (strcmp(pcmfile.token, "AT") == 0)
900 {
901 NL;
902 newat = atoi(pcmfile.token); // atom serial number
903 if (newat + ioffset > MAXATOM)
904 {
905 message_alert(" Maximum number of atoms exceeded in PCMFIN at atom read","Error");
906 fprintf(pcmlogfile,"atom read %d %d %d\n",newat,ioffset,natom);
907 natom = ioffset + newat - 1;
908 fclose(pcminfile);
909 exit(0);
910 }
911 newat += ioffset;
912 NL;
913 if (isdigit(*pcmfile.token))
914 {
915 newtype = atoi(pcmfile.token);
916 } else // character string for metal atom
917 {
918 strcpy(ianame,pcmfile.token);
919 isMetal = TRUE;
920 }
921 NL;
922 xtmp = atof(pcmfile.token);
923 NL;
924 ytmp = (atof(pcmfile.token));
925 NL;
926 ztmp = atof(pcmfile.token);
927 NL;
928 atom[newat].x = xtmp;
929 atom[newat].y = ytmp;
930 atom[newat].z = ztmp;
931
932 L_90:
933 if (strcmp(pcmfile.token, "B") == 0)
934 {
935 /* Reading bonds now */
936 NL;
937 j = 0;
938 L_100:
939 j += 1;
940 if (pcmfile.state == NUMERIC)
941 {
942 ibonded = atoi(pcmfile.token);
943 ibonded += ioffset;
944 } else
945 {
946 goto L_90;
947 }
948 NL;
949 if (pcmfile.state == NUMERIC)
950 {
951 ibondorder = atoi(pcmfile.token);
952 } else
953 {
954 fprintf(stdout, "missing a bondorder, assuming 1\n");
955 goto L_40;
956 }
957 NL;
958 goto L_100;
959 }else if ( strcmp(pcmfile.token, "P")== 0)
960 {
961 NL;
962 goto L_90;
963 }else if (strcmp(pcmfile.token, "D") == 0) // biomolecule marking
964 {
965 NL;
966 NL;
967 goto L_90;
968 }else if (strcmp(pcmfile.token,"M")==0)
969 {
970 NL;
971 NL;
972 if (pcmfile.state != 1)
973 goto L_90;
974 NL;
975 goto L_90;
976 }else if (strcmp(pcmfile.token,"S")== 0)
977 {
978 NL;
979 if (pcmfile.state == NUMERIC)
980 {
981 NL;
982 goto L_90;
983 } else
984 {
985 goto L_90;
986 }
987 }else if (strcmp(pcmfile.token,"H")== 0)
988 {
989 NL;
990 goto L_90;
991 }else if (strcmp(pcmfile.token,"C")==0)
992 {
993 NL;
994 NL;
995 goto L_90;
996 }else if (strcmp(pcmfile.token,"R")== 0)
997 {
998 NL;
999 NL;
1000 goto L_90;
1001 }
1002 } else if (strncmp(pcmfile.token, "}",1) == 0)
1003 {
1004 goto L_170; /* end of structure */
1005 } else if (strcmp(pcmfile.token, "FL") == 0)
1006 {
1007 NL;
1008 L_120: if (strcmp(pcmfile.token, "PRINT") == 0)
1009 {
1010 NL;
1011 if (pcmfile.state == ALPHABETIC)
1012 goto L_120;
1013 NL;
1014 goto L_120;
1015 } else if (strcmp(pcmfile.token, "DIELC") == 0)
1016 {
1017 NL;
1018 if (pcmfile.state != 1)
1019 goto L_120;
1020 NL;
1021 goto L_120;
1022 } else if (strcmp(pcmfile.token, "UV") == 0)
1023 {
1024 NL;
1025 if (pcmfile.state != 1)
1026 goto L_120;
1027 NL;
1028 goto L_120;
1029 } else if (strcmp(pcmfile.token, "PIPR") == 0)
1030 {
1031 NL;
1032 if (pcmfile.state != 1)
1033 goto L_120;
1034 NL;
1035 goto L_120;
1036 } else if (strcmp(pcmfile.token, "PIPL") == 0)
1037 {
1038 NL;
1039 if (pcmfile.state != 1)
1040 goto L_120;
1041 NL;
1042 goto L_120;
1043 } else if (strcmp(pcmfile.token, "EINT") == 0)
1044 {
1045 NL;
1046 if (pcmfile.state != 1)
1047 goto L_120;
1048 NL;
1049 goto L_120;
1050 }
1051 } else if (strcmp(pcmfile.token, "CO") == 0)
1052 {
1053 } else if (strcmp(pcmfile.token, "FBND") == 0)
1054 {
1055 NL;
1056 NL;
1057 NL;
1058 NL;
1059 NL;
1060 NL;
1061 NL;
1062 NL;
1063 NL;
1064 NL;
1065 NL;
1066 NL;
1067 NL;
1068 NL;
1069 NL;
1070 goto L_30; // get another line
1071 } else if (strcmp(pcmfile.token, "FIX") == 0)
1072 {
1073 NL;
1074 if (strcmp(pcmfile.token, "DIS") == 0)
1075 {
1076 NL;
1077 NL;
1078 NL;
1079 L_1223: if (strcmp(pcmfile.token, "R") == 0)
1080 {
1081 NL;
1082 NL;
1083 goto L_1223;
1084 } else if (strcmp(pcmfile.token, "K") == 0)
1085 {
1086 NL;
1087 NL;
1088 goto L_1223;
1089 }
1090 }
1091 } else if (strcmp(pcmfile.token, "DD") == 0)
1092 {
1093 if (isubred == 1)
1094 goto L_30;
1095
1096 NL;
1097
1098 if (pcmfile.state == NUMERIC)
1099 {
1100 NL;
1101 NL;
1102 NL;
1103 NL;
1104 L_150: if (strcmp(pcmfile.token, "FROM") == 0)
1105 {
1106 NL;
1107 NL;
1108 goto L_150;
1109 } else if (strcmp(pcmfile.token, "TO") == 0)
1110 {
1111 NL;
1112 NL;
1113 goto L_150;
1114 } else if (strcmp(pcmfile.token, "BY") == 0)
1115 {
1116 NL;
1117 NL;
1118 goto L_150;
1119 }
1120 }
1121 }
1122 goto L_30;
1123 L_170:
1124 return;
1125 }