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