ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/freemol/trunk/smi23d/src/mengine/read_pcm.c
Revision: 3
Committed: Mon Jun 9 21:38:26 2008 UTC (11 years, 11 months ago) by tjod
File size: 51124 byte(s)
Log Message:
test

Line User Rev File contents
1 tjod 3 #define EXTERN extern
2    
3     #include "pcwin.h"
4     #include "pcmod.h"
5     #include "energies.h"
6     #include "substr.h"
7     #include "pdb.h"
8     #include "solv.h"
9     #include "fix.h"
10     #include "atom_k.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     int make_atom(int,float,float,float,char *);
18     void initialize(void);
19     void make_bond(int,int,int);
20     void message_alert(char *, char *);
21     FILE * fopen_path ( char * , char * , char * ) ;
22     int mm3_mmxtype(int);
23     int mmff_mmxtype(int);
24     int amber_mmxtype(int);
25     int opls_mmxtype(int);
26     void set_atomtype(int,int,int,int,int,int);
27     int FetchRecord(FILE *, char *);
28     void zero_data(void);
29     void read_datafiles(char *);
30     void read_atomtypes(int);
31     void get_atomname(int,char *);
32     void clean_string(char *);
33     void hdel(int);
34    
35     /* COMMON translations */
36     struct t_pcmfile {
37     char string[200];
38     int head;
39     char token[20];
40     int state;
41     unsigned int nocaps;
42     } pcmfile;
43    
44     EXTERN struct t_minim_values {
45     int iprint, ndc, nconst;
46     float dielc;
47     } minim_values;
48    
49     EXTERN struct t_ts_bondorder {
50     float fbnd[15];
51     } ts_bondorder;
52    
53     EXTERN struct t_files {
54     int nfiles, append, batch, icurrent, ibatno;
55     } files;
56    
57     EXTERN struct t_pistuf {
58     int iuv, ihuck, mult;
59     int norb, nplane, jprint;
60     int *listpi;
61     int nbpi, ntpi, **pibond, **pitor, **piplane ;
62     } pistuf;
63    
64     EXTERN struct t_units {
65     double bndunit, cbnd, qbnd;
66     double angunit, cang, qang, pang, sang, aaunit;
67     double stbnunit, ureyunit, torsunit, storunit, v14scale;
68     double aterm, bterm, cterm, dielec, chgscale;
69     } units;
70     EXTERN struct t_residues {
71     int nchain, ichainstart[10];
72     int ngroup, iresnum[1000], irestype[1000], istartatom[1000];
73     } residues;
74    
75     EXTERN int oh2, oh3, oh6;
76     EXTERN int mm3_mmx[];
77     EXTERN int mmff_mmx[];
78     EXTERN int amber_mmx[];
79     EXTERN int opls_mmx[];
80    
81     // ========================================================
82     void read_atomtypes(int field)
83     {
84     char string[20];
85    
86     if (field == MM3)
87     {
88     strcpy(string,"mm3.prm");
89     zero_data();
90     read_datafiles(string);
91     } else if (field == MMFF94)
92     {
93     strcpy(string,"mmff94.prm");
94     zero_data();
95     read_datafiles(string);
96     } else if (field == AMBER)
97     {
98     strcpy(string,"amber.prm");
99     zero_data();
100     read_datafiles(string);
101     } else if (field == OPLSAA)
102     {
103     strcpy(string,"oplsaa.prm");
104     zero_data();
105     read_datafiles(string);
106     } else if (field == MMX)
107     {
108     strcpy(string,"mmxconst.prm");
109     zero_data();
110     read_datafiles(string);
111     }
112     }
113     // ========================================================
114     void get_atomname(int type,char *name)
115     {
116     int i;
117     strcpy(name,"");
118     for (i=1; i <= MAXATOMTYPE; i++)
119     {
120     if (type == atom_k.type[i])
121     {
122     strcpy(name,atom_k.symbol[i]);
123     return;
124     }
125     }
126     }
127     // ========================================================
128     int mm3_mmxtype(int mm3type)
129     {
130     int i;
131    
132     if (mm3type < 153)
133     i = mm3_mmx[mm3type-1];
134     else if (mm3type == 200)
135     i = 60;
136     else
137     i = mm3type;
138     return(i);
139     }
140     // ==================================================
141     int mmff_mmxtype(int mmfftype)
142     {
143     int i;
144     if (mmfftype < 100)
145     i = mmff_mmx[mmfftype-1];
146     else
147     i = mmfftype;
148     return(i);
149     }
150     // ==================================================
151     int amber_mmxtype(int ambertype)
152     {
153     int i;
154     if (ambertype < 43)
155     i = amber_mmx[ambertype-1];
156     else
157     i = ambertype;
158     return(i);
159     }
160     // ==================================================
161     int opls_mmxtype(int oplstype)
162     {
163     int i;
164     if (oplstype < 82)
165     i = opls_mmx[oplstype-1];
166     else
167     i = oplstype;
168     return(i);
169     }
170     // ==================================================
171     void pcmfout(int mode)
172     {
173     FILE *wfile;
174     int icoord, imetflag, ispin,lps;
175     int i,j,isub,icount, itype;
176    
177     /* Mode = 1 normal packed write operation
178     * Mode = 2 fast no questions asked unpacked write of pcmod.bak
179     * Mode = 3 fast no questions ot file = wfile
180     * mode = 4 start of minim to pcmod.bak but ask questions about pi */
181     if( mode == 1 )
182     {
183     /* assume append is set when we get a filename that exists */
184     /* put up dialog box with current structure title, pi flags
185     and added constants question */
186     if( files.append )
187     wfile = fopen_path(Savebox.path,Savebox.fname,"a");
188     else
189     wfile = fopen_path(Savebox.path,Savebox.fname,"w");
190     }
191     else if( mode == 2 || mode == 4 )
192     {
193     wfile = fopen_path(pcwindir,"pcmod.bak","w");
194     }
195     else if( mode == 3 )
196     {
197     if( files.append )
198     wfile = fopen_path(Savebox.path,Savebox.fname,"a");
199     else
200     wfile = fopen_path(Savebox.path,Savebox.fname,"w");
201     }
202     if (wfile == NULL)
203     {
204     message_alert("Error opening file in PCMFOUT. Cannot create file","PCM File");
205     return;
206     }
207     // remove lone pairs if not writing mmx types
208     lps = FALSE;
209     if (default_outtype != MMX)
210     {
211     for (i=1; i <= natom; i++)
212     {
213     if (atom[i].mmx_type == 20)
214     {
215     lps = TRUE;
216     break;
217     }
218     }
219     }
220     if (lps == TRUE)
221     hdel(1);
222    
223     /* start of file writing */
224     fprintf(wfile,"{PCM %s\n",Struct_Title);
225     fprintf(wfile,"NA %d\n",natom);
226    
227     /* flags */
228     fprintf(wfile,"FL ");
229     fprintf(wfile,"EINT%d ",minim_values.ndc);
230     if( units.dielec != 1.5 )
231     fprintf(wfile,"DIELC%f ",units.dielec);
232     fprintf(wfile,"\n");
233     // default output filetypes
234     fprintf(wfile,"ATOMTYPES %d\n",default_outtype);
235     /* substructure name information */
236     icount = 0;
237     for (i=0; i < MAXSS; i++)
238     if ( substr.istract[i] != 0)
239     icount++;
240     for (i=0; i < icount; i++)
241     fprintf(wfile,"SSNAME %s\n",substr.strname[i]);
242     /* box of solvent information */
243     if (solv.nmols > 0)
244     {
245     fprintf(wfile,"NMOL %d DENSITY %f BOX %f %f %f\n",solv.nmols,solv.density,solv.boxx, solv.boxy,solv.boxz);
246     }
247     /*
248     if( minim_values.nconst && mode > 1 )
249     fprintf(wfile,"CO FILE %s\n",constf.cname);*/
250     /* atoms and bonds lists */
251     for( i = 1; i <= natom; i++ )
252     {
253     if (default_outtype == MMX)
254     {
255     itype = atom[i].mmx_type;
256     } else if (default_outtype == MM3)
257     {
258     itype = atom[i].mm3_type;
259     } else if (default_outtype == MMFF94)
260     {
261     itype = atom[i].mmff_type;
262     }
263     fprintf(wfile,"AT %d %d %8.4f %8.4f %8.4f",i,itype,atom[i].x,
264     atom[i].y, atom[i].z);
265     // bonds
266     fprintf(wfile," B");
267     for( j = 0; j < MAXIAT; j++ )
268     {
269     if( atom[i].iat[j])
270     {
271     fprintf(wfile," %d %d",atom[i].iat[j],atom[i].bo[j]);
272     }
273     }
274     if (atom[i].biotype > 0 )
275     {
276     fprintf(wfile," D %d",atom[i].biotype);
277     fprintf(wfile," N %d",atom[i].residue);
278     }
279     if( atom[i].substr[0] > 0 )
280     {
281     fprintf(wfile," S ");
282     isub = 0;
283     for( j = 0; j < MAXSS; j++ )
284     {
285     if( (atom[i].substr[0] & (1L << j) ) && (substr.istract[j]) )
286     isub = j;
287     }
288     fprintf(wfile,"%d ",isub);
289     }
290     if( atom[i].flags & (1L << HBOND_MASK) )
291     fprintf(wfile," H ");
292     if( atom[i].flags & (1L << PI_MASK) )
293     fprintf(wfile," P ");
294     if( atom[i].mmx_type >= 300 )
295     {
296     icoord = 0;
297     ispin = -1;
298     imetflag = 0;
299     if( atom[i].flags & (1L << SATMET_MASK) )
300     imetflag += 2;
301     if( atom[i].flags & (1L << GT18e_MASK) )
302     imetflag += 1;
303     if( imetflag == 2 )
304     icoord = 0;
305     if( imetflag == 1 )
306     icoord = 2;
307     if( imetflag == 3 )
308     {
309     icoord = 1;
310     imetflag = 0;
311     if( atom[i].flags & (1L << LOWSPIN_MASK) )
312     imetflag += 2;
313     if( atom[i].flags & (1L << SQPLAN_MASK) )
314     imetflag += 1;
315     if( imetflag == 2 )
316     ispin = 0;
317     if( imetflag == 3 )
318     ispin = 2;
319     if( imetflag == 1 )
320     ispin = 1;
321     }
322     if( icoord )
323     {
324     fprintf(wfile," M %d",icoord);
325     if( ispin >= 0 )
326     fprintf(wfile," %d",ispin);
327     }
328     fprintf(wfile," R %g",atom[i].radius);
329     }
330     if( atom[i].charge )
331     {
332     fprintf(wfile," C %g",atom[i].charge);
333     }
334     if (solv.nmols > 0)
335     fprintf(wfile," ML %d",atom[i].molecule);
336     fprintf(wfile,"\n");
337     }
338     if( fxtor.nfxtor == 1 || fxtor.nfxtor == 2 )
339     {
340     fprintf(wfile,"DD %d %d %d %d FROM %d TO %d BY %d\n",fxtor.iatom[0][0],
341     fxtor.iatom[0][1], fxtor.iatom[0][2], fxtor.iatom[0][3], fxtor.start_ang[0],
342     fxtor.final_ang[0], fxtor.step[0] );
343     if( fxtor.nfxtor == 2 )
344     {
345     fprintf(wfile,"DD %d %d %d %d FROM %d TO %d BY %d\n",fxtor.iatom[1][0],
346     fxtor.iatom[1][1], fxtor.iatom[1][2], fxtor.iatom[1][3], fxtor.start_ang[1],
347     fxtor.final_ang[1], fxtor.step[1] );
348     }
349     }
350     if (fixdis.nfxstr)
351     {
352     for( i = 0; i < fixdis.nfxstr; i++ )
353     {
354     fprintf(wfile,"FIX DIS %d %d R %7.3f K %7.3f\n",fixdis.ifxstr[i][0],
355     fixdis.ifxstr[i][1], fixdis.fxstrd[i], fixdis.fxstrc[i] );
356     }
357     }
358     for (i=0; i < 15; i++)
359     {
360     if (ts_bondorder.fbnd[i] > 0.0F)
361     {
362     fprintf(wfile,"FBND");
363     for (j=0; j<15; j++)
364     {
365     fprintf(wfile," %5.3f",ts_bondorder.fbnd[j]);
366     }
367     fprintf(wfile,"\n");
368     break;
369     }
370     }
371     if (residues.ngroup > 0)
372     {
373     for (i=0; i < residues.ngroup; i++)
374     fprintf(wfile,"Residue %d %d %d\n",residues.iresnum[i],
375     residues.irestype[i],residues.istartatom[i]);
376     }
377    
378     fprintf(wfile,"}\n");
379     fclose(wfile);
380     } /* end of function */
381    
382     /* ------------------------------- */
383    
384     #define NL gettoken(); if (pcmfile.head == 1000) goto L_30;
385     #define ALPHABETIC 2
386     #define NUMERIC 1
387    
388     void pcmfin(int nth,int isubred)
389     {
390     unsigned int substrismin;
391     int newatom, i, ibondcount, ibonded, ibondorder,
392     icoord, imetcount, ioffset, ispin, iprint,
393     isubmap[MAXSS], j, numbonds, niatom, itemp;
394     int newat, newtype, ifile, isMetal, biotype, itype;
395     long int mask;
396     char ianame[3];
397     float ddcount, xtmp, ytmp, ztmp;
398     FILE *pcminfile;
399    
400     imetcount = 0;
401     isMetal = FALSE;
402     ddcount = 0;
403     substrismin = False;
404     fxtor.nfxtor = 0;
405     pcmfile.nocaps = False;
406     numbonds = 0;
407     ibondcount = 0;
408     units.dielec = 1.5;
409    
410     for (i = 0; i < MAXSS; i++)
411     {
412     isubmap[i] = 0;
413     }
414    
415     if( isubred == 1 )
416     {
417     ioffset = natom;
418     substr.istract[substr.icurstr] = TRUE;
419     }
420     else
421     {
422     ioffset = 0;
423     }
424    
425     pcminfile = fopen_path(Openbox.path,Openbox.fname,"r");
426    
427     if (pcminfile == NULL)
428     {
429     message_alert("Error Opening PCM file","PCM Setup");
430     fprintf(pcmoutfile,"PCMFIN error opening file %d %s\n",nth,Openbox.fname);
431     return;
432     }
433    
434     ifile = 0;
435     if (nth != 1)
436     {
437     while ( FetchRecord(pcminfile,pcmfile.string) )
438     {
439     if (strncasecmp(pcmfile.string,"{PCM",4) == 0)
440     {
441     ifile++;
442     if (ifile == nth)
443     break;
444     }
445     }
446     }else
447     {
448     FetchRecord(pcminfile,pcmfile.string);
449     }
450    
451     /* finished scaning to starting structure now read file */
452     if (isubred == 0)
453     {
454     sscanf(pcmfile.string, "{PCM %60c", Struct_Title);
455     clean_string(Struct_Title);
456     strcpy(substr.strname[0]," ");
457     strncpy(substr.strname[0],Struct_Title,20);
458     } else
459     {
460     if (natom < 1 )
461     {
462     sscanf(pcmfile.string, "{PCM %60c", Struct_Title);
463     clean_string(Struct_Title);
464     strcpy(substr.strname[0]," ");
465     strncpy(substr.strname[0],Struct_Title,20);
466     } else
467     {
468     // read substructure name
469     strcpy(substr.strname[substr.icurstr]," ");
470     sscanf(pcmfile.string,"{PCM %s\n", substr.strname[substr.icurstr]);
471     }
472     }
473     L_30:
474     FetchRecord(pcminfile,pcmfile.string);
475     *(pcmfile.string + strlen(pcmfile.string) ) = '\0';
476     if (feof(pcminfile))
477     goto L_170;
478     pcmfile.head = 1;
479     NL;
480     L_40:
481     if (strcmp(pcmfile.token, "NA") == 0)
482     {
483     gettoken();
484     if (pcmfile.head == 1000)
485     goto L_30;
486     niatom = atoi(pcmfile.token);
487     if (niatom + ioffset > MAXATOM)
488     {
489     natom = ioffset;
490     fclose(pcminfile);
491     message_alert(" Maximum number of atoms exceeded in PCMFIN","PCM Setup");
492     fprintf(pcmoutfile," unable to continue reading, more than Max atoms %d\n",MAXATOM);
493     return;
494     }
495     niatom += ioffset;
496     NL;
497     goto L_30;
498     } else if (strcmp(pcmfile.token,"ATOMTYPES") == 0)
499     {
500     gettoken();
501     if (pcmfile.head == 1000)
502     goto L_30;
503     itemp = atoi(pcmfile.token);
504     if (itemp != default_intype)
505     {
506     default_intype = itemp;
507     read_atomtypes(default_intype);
508     }
509     NL;
510     goto L_30;
511     } else if (strcmp(pcmfile.token,"SSNAME") == 0 && isubred == 0) // substructure name
512     {
513     gettoken();
514     if (pcmfile.head == 1000) goto L_30;
515     for (i=0; i < MAXSS; i++)
516     {
517     if (substr.istract[i] == FALSE)
518     {
519     substr.istract[i] = TRUE;
520     strcpy(substr.strname[i],pcmfile.token);
521     break;
522     }
523     }
524     } else if (strcmp(pcmfile.token, "NT") == 0) /* This is for Amino Acids */
525     {
526     NL;
527     i = atoi(pcmfile.token); /* i is atom number of N terminus */
528     mask = 1L << NTERM; /* use bit 0 of substr 1 for N terminus*/
529     atom[i+ioffset].flags |= mask;
530    
531     NL;
532     if (strcmp(pcmfile.token, "CT") == 0)
533     {
534     NL;
535     i = atoi(pcmfile.token); /* i is atom number of C terminus */
536     mask = 1L << CNTERM; /* use bit 1 of substr 1 for C terminus */
537     atom[i+ioffset].flags |= mask;
538     }
539     } else if (strcmp(pcmfile.token, "5PRIME") == 0) /* This is for Nucleic Acids */
540     {
541     NL;
542     i = atoi(pcmfile.token); /* i is atom number of 5prime terminus */
543     mask = 1L << P5;
544     atom[i+ioffset].flags |= mask;
545     }else if (strcmp(pcmfile.token, "3PRIME") == 0) /* This is for Nucleic Acids */
546     {
547     NL;
548     i = atoi(pcmfile.token); /* i is atom number of C terminus */
549     mask = 1L << P3; /* use bit 1 of substr 1 for C terminus */
550     atom[i+ioffset].flags |= mask;
551     } else if (strcmp(pcmfile.token, "FG") == 0) /* This is for functional groups */
552     {
553     NL;
554     i = atoi(pcmfile.token); /* i is atom number of connect point */
555     mask = 1L << DUMMY; /* use bit 0 of substr 1 for connect*/
556     atom[i+ioffset].flags |= mask;
557    
558     } else if (strcmp(pcmfile.token, "OT") == 0) /* This is for Sugars */
559     {
560     NL;
561     i = atoi(pcmfile.token); /* i is atom number of O terminus */
562     mask = 1L << NTERM; /* use bit 0 of substr 1 for O terminus*/
563     atom[i+ioffset].flags |= mask;
564    
565     NL;
566     if (strcmp(pcmfile.token, "CT") == 0)
567     {
568     NL;
569     i = atoi(pcmfile.token); /* i is atom number of H terminus */
570     mask = 1L << CNTERM; /* use bit 1 of substr 1 for H terminus */
571     atom[i+ioffset].flags |= mask;
572     }
573    
574     NL;
575     if (strcmp(pcmfile.token, "OTWO") == 0)
576     {
577     NL;
578     i = atoi(pcmfile.token); /* i is atom number of H terminus */
579     oh2 = i+ioffset;
580     }
581    
582     NL;
583     if (strcmp(pcmfile.token, "OTHR") == 0)
584     {
585     NL;
586     i = atoi(pcmfile.token); /* i is atom number of H terminus */
587     oh3 = i+ioffset;
588     }
589    
590     NL;
591     if (strcmp(pcmfile.token, "OSIX") == 0)
592     {
593     NL;
594     i = atoi(pcmfile.token); /* i is atom number of H terminus */
595     oh6 = i+ioffset;
596     }
597     } else if (strcmp(pcmfile.token,"START") == 0) /* flag for polybuild */
598     {
599     NL;
600     i = atoi(pcmfile.token);
601     mask = 1L << DUMMY;
602     atom[i+ioffset].flags |= mask;
603     NL; // END
604     NL;
605     i = atoi(pcmfile.token);
606     mask = 1L << DUMMY;
607     atom[i+ioffset].flags |= mask;
608     } else if (strcmp(pcmfile.token,"NMOL") == 0)
609     {
610     NL;
611     solv.nmols = atoi(pcmfile.token);
612     NL;
613     NL;
614     solv.density = atof(pcmfile.token);
615     NL;
616     NL;
617     solv.boxx = atof(pcmfile.token);
618     NL;
619     solv.boxy = atof(pcmfile.token);
620     NL;
621     solv.boxz = atof(pcmfile.token);
622     goto L_30;
623     } else if (strcmp(pcmfile.token, "SS") == 0)
624     {
625     goto L_30;
626     } else if (strcmp(pcmfile.token, "AT") == 0)
627     {
628     NL;
629     newat = atoi(pcmfile.token); // atom serial number
630     if (newat + ioffset > MAXATOM)
631     {
632     message_alert(" Maximum number of atoms exceeded in PCMFIN at atom read","PCM Setup");
633     fprintf(pcmoutfile,"atom read %d %d %d\n",newat,ioffset,natom);
634     natom = ioffset + newat - 1;
635     fclose(pcminfile);
636     exit(0);
637     }
638     newat += ioffset;
639     NL;
640     if (isdigit(*pcmfile.token))
641     {
642     newtype = atoi(pcmfile.token);
643     } else // character string for metal atom
644     {
645     strcpy(ianame,pcmfile.token);
646     isMetal = TRUE;
647     i = strlen(ianame);
648     if ( i == 2)
649     ianame[1] = tolower(ianame[1]);
650     }
651     NL;
652     xtmp = atof(pcmfile.token);
653     NL;
654     ytmp = (atof(pcmfile.token));
655     NL;
656     ztmp = atof(pcmfile.token);
657     NL;
658     if (isMetal == FALSE)
659     {
660     itype = newtype;
661     get_atomname(newtype,ianame);
662     if (default_intype == MM3)
663     itype = mm3_mmxtype(newtype);
664     else if (default_intype == MMFF94)
665     itype = mmff_mmxtype(newtype);
666     else if (default_intype == AMBER)
667     itype = amber_mmxtype(newtype);
668     else if (default_intype == OPLSAA)
669     itype = opls_mmxtype(newtype);
670    
671     newatom = make_atom(newtype, xtmp, ytmp, ztmp,ianame);
672     if (default_intype == MM3)
673     set_atomtype(newatom, itype,newtype,0,0,0);
674     else if (default_intype == MMFF94)
675     set_atomtype(newatom, itype,0,newtype,0,0);
676     else if (default_intype == AMBER)
677     set_atomtype(newatom, itype,0,0,newtype,0);
678     else if (default_intype == OPLSAA)
679     set_atomtype(newatom, itype,0,0,0,newtype);
680     }else if (isMetal == TRUE)
681     {
682     newatom = make_atom(0, xtmp, ytmp, ztmp,ianame);
683     isMetal = FALSE;
684     last_atom = newatom;
685     }
686     if (isubred == 1)
687     {
688     atom[newatom].substr[0] = 0;
689     atom[newatom].substr[0] |= (1L << substr.icurstr);
690     }
691    
692     L_90:
693     if (strcmp(pcmfile.token, "B") == 0)
694     {
695     /* Reading bonds now */
696     NL;
697     j = 0;
698     L_100:
699     j += 1;
700     if (pcmfile.state == NUMERIC)
701     {
702     ibonded = atoi(pcmfile.token);
703     ibonded += ioffset;
704     } else
705     {
706     goto L_90;
707     }
708     NL;
709     if (pcmfile.state == NUMERIC)
710     {
711     ibondorder = atoi(pcmfile.token);
712     } else
713     {
714     fprintf(stdout, "missing a bondorder, assuming 1\n");
715     goto L_40;
716     }
717     if (newatom < ibonded)
718     make_bond(newatom, ibonded, ibondorder);
719     if (ibondorder == 9)
720     {
721     atom[newatom].flags |= (1L << METCOORD_MASK);
722     atom[ibonded].flags |= (1L << METCOORD_MASK);
723     }
724     NL;
725     goto L_100;
726     }else if ( strcmp(pcmfile.token, "P")== 0)
727     {
728     atom[newatom].flags |= (1L << PI_MASK);
729     NL;
730     goto L_90;
731     }else if (strcmp(pcmfile.token, "D") == 0) // biomolecule marking
732     {
733     NL;
734     biotype = atoi(pcmfile.token);
735     atom[newatom].biotype = biotype;
736     NL;
737     goto L_90;
738     }else if (strcmp(pcmfile.token, "N") == 0) // residue number
739     {
740     NL;
741     biotype = atoi(pcmfile.token);
742     atom[newatom].residue = biotype;
743     NL;
744     goto L_90;
745     }else if (strcmp(pcmfile.token,"M")==0)
746     {
747     NL;
748     icoord = atoi(pcmfile.token);
749     if (icoord == 0)
750     {
751     atom[newatom].flags |= (1L << SATMET_MASK);
752     } else if (icoord == 2)
753     {
754     atom[newatom].flags |= (1L << GT18e_MASK);
755     } else{
756     atom[newatom].flags |= (1L << GT18e_MASK);
757     atom[newatom].flags |= (1L << SATMET_MASK);
758     }
759     NL;
760     if (pcmfile.state != 1)
761     goto L_90;
762     ispin = atoi(pcmfile.token);
763     if (ispin == 0)
764     {
765     atom[newatom].flags |= (1L << LOWSPIN_MASK);
766     } else if (ispin == 1)
767     {
768     atom[newatom].flags |= (1L << SQPLAN_MASK);
769     } else
770     {
771     atom[newatom].flags |= (1L << LOWSPIN_MASK);
772     atom[newatom].flags |= (1L << SQPLAN_MASK);
773     }
774     NL;
775     goto L_90;
776     }else if (strcmp(pcmfile.token,"S")== 0)
777     {
778     NL;
779     if (pcmfile.state == NUMERIC)
780     {
781     j = atoi(pcmfile.token);
782     mask = (1L << j);
783     if (isubred == 0)
784     {
785     atom[newatom].substr[0] |= mask;
786     substr.istract[j] = TRUE;
787     }
788     NL;
789     goto L_90;
790     } else
791     {
792     goto L_90;
793     }
794     }else if (strcmp(pcmfile.token,"H")== 0)
795     {
796     atom[newatom].flags |= (1L << HBOND_MASK);
797     NL;
798     goto L_90;
799     }else if (strcmp(pcmfile.token,"C")==0)
800     {
801     NL;
802     atom[newatom].charge = atof(pcmfile.token);
803     NL;
804     goto L_90;
805     } else if (strcmp(pcmfile.token,"ML") == 0)
806     {
807     NL;
808     j = atoi(pcmfile.token);
809     atom[newatom].molecule = j;
810     goto L_90;
811     }else if (strcmp(pcmfile.token,"R")== 0)
812     {
813     NL;
814     atom[newatom].radius = atof(pcmfile.token);
815     NL;
816     goto L_90;
817     }
818     } else if (strncasecmp(pcmfile.token, "}",1) == 0)
819     {
820     goto L_170; /* end of structure */
821     } else if (strcmp(pcmfile.token, "FL") == 0)
822     {
823     NL;
824     L_120: if (strcmp(pcmfile.token, "PRINT") == 0)
825     {
826     iprint = 1;
827     NL;
828     if (pcmfile.state == ALPHABETIC)
829     goto L_120;
830     iprint = atoi(pcmfile.token);
831     NL;
832     goto L_120;
833     } else if (strcmp(pcmfile.token, "DIELC") == 0)
834     {
835     NL;
836     if (pcmfile.state != 1)
837     goto L_120;
838     units.dielec = atof(pcmfile.token);
839     NL;
840     goto L_120;
841     } else if (strcmp(pcmfile.token, "UV") == 0)
842     {
843     NL;
844     if (pcmfile.state != 1)
845     goto L_120;
846     NL;
847     goto L_120;
848     } else if (strcmp(pcmfile.token, "PIPR") == 0)
849     {
850     NL;
851     if (pcmfile.state != 1)
852     goto L_120;
853     NL;
854     goto L_120;
855     } else if (strcmp(pcmfile.token, "PIPL") == 0)
856     {
857     NL;
858     if (pcmfile.state != 1)
859     goto L_120;
860     NL;
861     goto L_120;
862     } else if (strcmp(pcmfile.token, "EINT") == 0)
863     {
864     NL;
865     if (pcmfile.state != 1)
866     goto L_120;
867     minim_values.ndc = atoi(pcmfile.token);
868     NL;
869     goto L_120;
870     }
871     } else if (strcmp(pcmfile.token, "CO") == 0)
872     {
873     } else if (strcmp(pcmfile.token, "FBND") == 0)
874     {
875     NL;
876     ts_bondorder.fbnd[0] = atof(pcmfile.token);
877     NL;
878     ts_bondorder.fbnd[1] = atof(pcmfile.token);
879     NL;
880     ts_bondorder.fbnd[2] = atof(pcmfile.token);
881     NL;
882     ts_bondorder.fbnd[3] = atof(pcmfile.token);
883     NL;
884     ts_bondorder.fbnd[4] = atof(pcmfile.token);
885     NL;
886     ts_bondorder.fbnd[5] = atof(pcmfile.token);
887     NL;
888     ts_bondorder.fbnd[6] = atof(pcmfile.token);
889     NL;
890     ts_bondorder.fbnd[7] = atof(pcmfile.token);
891     NL;
892     ts_bondorder.fbnd[8] = atof(pcmfile.token);
893     NL;
894     ts_bondorder.fbnd[9] = atof(pcmfile.token);
895     NL;
896     ts_bondorder.fbnd[10] = atof(pcmfile.token);
897     NL;
898     ts_bondorder.fbnd[11] = atof(pcmfile.token);
899     NL;
900     ts_bondorder.fbnd[12] = atof(pcmfile.token);
901     NL;
902     ts_bondorder.fbnd[13] = atof(pcmfile.token);
903     NL;
904     ts_bondorder.fbnd[14] = atof(pcmfile.token);
905     } else if (strcmp(pcmfile.token, "FIX") == 0)
906     {
907     NL;
908     if (strcmp(pcmfile.token, "DIS") == 0)
909     {
910     NL;
911     fixdis.ifxstr[fixdis.nfxstr][0] = atoi(pcmfile.token);
912     NL;
913     fixdis.ifxstr[fixdis.nfxstr][1] = atoi(pcmfile.token);
914     NL;
915     L_1223: if (strcmp(pcmfile.token, "R") == 0)
916     {
917     NL;
918     fixdis.fxstrd[fixdis.nfxstr] = atof(pcmfile.token);
919     NL;
920     goto L_1223;
921     } else if (strcmp(pcmfile.token, "K") == 0)
922     {
923     NL;
924     fixdis.fxstrc[fixdis.nfxstr] = atof(pcmfile.token);
925     fixdis.nfxstr +=1;
926     NL;
927     goto L_1223;
928     }
929     }
930     } else if (strcmp(pcmfile.token, "RESIDUE") == 0)
931     {
932     NL;
933     residues.iresnum[residues.ngroup] = atoi(pcmfile.token);
934     NL;
935     residues.irestype[residues.ngroup] = atoi(pcmfile.token);
936     NL;
937     residues.istartatom[residues.ngroup] = atoi(pcmfile.token);
938     residues.ngroup++;
939     } else if (strcmp(pcmfile.token, "DD") == 0)
940     {
941     if (isubred == 1)
942     goto L_30;
943    
944     NL;
945    
946     if (pcmfile.state == NUMERIC)
947     {
948     fxtor.iatom[fxtor.nfxtor][0] = atoi(pcmfile.token);
949     NL;
950     fxtor.iatom[fxtor.nfxtor][1] = atoi(pcmfile.token);
951     NL;
952     fxtor.iatom[fxtor.nfxtor][2] = atoi(pcmfile.token);
953     NL;
954     fxtor.iatom[fxtor.nfxtor][3] = atoi(pcmfile.token);
955     NL;
956     L_150: if (strcmp(pcmfile.token, "FROM") == 0)
957     {
958     NL;
959     fxtor.start_ang[fxtor.nfxtor] = atoi(pcmfile.token);
960     fxtor.curr_ang[fxtor.nfxtor] = fxtor.start_ang[fxtor.nfxtor];
961     NL;
962     goto L_150;
963     } else if (strcmp(pcmfile.token, "TO") == 0)
964     {
965     NL;
966     fxtor.final_ang[fxtor.nfxtor] = atoi(pcmfile.token);
967     NL;
968     goto L_150;
969     } else if (strcmp(pcmfile.token, "BY") == 0)
970     {
971     NL;
972     fxtor.step[fxtor.nfxtor] = atoi(pcmfile.token);
973     fxtor.nfxtor++;
974     NL;
975     goto L_150;
976     }
977     }
978     }
979     goto L_30;
980     L_170:
981     fclose(pcminfile);
982     for (i=1; i <= natom; i++)
983     {
984     if (atom[i].mmx_type == 5)
985     {
986     flags.noh = True;
987     break;
988     }
989     }
990     return;
991     }
992    
993     void gettoken()
994     {
995     int foundtoken, i;
996    
997     pcmfile.state = 0;
998     foundtoken = -1;
999     strcpy(pcmfile.token, "");
1000     for (i = pcmfile.head - 1; i <= strlen(pcmfile.string); i++) {
1001     if ((*(pcmfile.string + i) != ':') &&
1002     (*(pcmfile.string + i) != ' ') &&
1003     (*(pcmfile.string + i) != '\0') &&
1004     (*(pcmfile.string + i) != ';') &&
1005     (*(pcmfile.string + i) != ',') &&
1006     (*(pcmfile.string + i) != '\t')) {
1007     if (foundtoken == -1) {
1008     foundtoken = i;
1009     if (isdigit(*(pcmfile.string + i))) {
1010     /* beginning to read a number */
1011     pcmfile.state = 1;
1012     } else if ((*(pcmfile.string + i) == '.') ||
1013     (*(pcmfile.string + i) == '-')) {
1014     /* period or dash can't yet tell if
1015     * word or number */
1016     pcmfile.state = 3;
1017     } else {
1018     /* must be a word */
1019     pcmfile.state = 2;
1020     }
1021     } else {
1022     if (
1023     (
1024     (pcmfile.state == 2) &&
1025     (isdigit(*(pcmfile.string + i)))
1026     )
1027     ||
1028     (
1029     (pcmfile.state == 1) &&
1030     (isalpha(*(pcmfile.string + i)))
1031     )
1032     ) {
1033     foundtoken = i;
1034     goto L_30;
1035     } else if (pcmfile.state == 3) {
1036     if (isdigit(*(pcmfile.string + i)) ||
1037     *(pcmfile.string + i) == '.') {
1038     pcmfile.state = 1;
1039     } else {
1040     pcmfile.state = 2;
1041     }
1042     }
1043     }
1044     strncat(pcmfile.token, pcmfile.string + i, 1);
1045     } else if (foundtoken != -1) {
1046     foundtoken = i;
1047     goto L_30;
1048     }
1049     }
1050     if (foundtoken == -1) {
1051     pcmfile.head = 1000;
1052     return;
1053     }
1054     L_30:
1055     pcmfile.head = foundtoken + 1;
1056     if (pcmfile.state == 2 && !pcmfile.nocaps)
1057     {
1058     for (i = 0; i < strlen(pcmfile.token); i++)
1059     {
1060     if (!isupper(*(pcmfile.token + i)))
1061     *(pcmfile.token + i) = toupper(*(pcmfile.token + i));
1062     }
1063     }
1064     return;
1065     }
1066     /* ============================================================ */
1067     FILE *pcminfile;
1068     /* ============================================================ */
1069     void rdfile(int mode, int isub)
1070     {
1071     if (mode == -1)
1072     fclose(pcminfile);
1073     else if (mode == 0)
1074     {
1075     pcminfile = fopen_path(Openbox.path,Openbox.fname, "r");
1076    
1077     if (pcminfile == NULL)
1078     {
1079     message_alert("Error Opening PCM file","Error");
1080     return;
1081     }
1082     } else
1083     rdpcm(mode,isub);
1084     }
1085     /* ============================================================ */
1086     void rdpcm(int nth,int isubred)
1087     {
1088     unsigned int substrismin;
1089     int i, ibondcount, ibonded, ibondorder,imetcount, ioffset,
1090     isubmap[MAXSS], j, numbonds, niatom;
1091     int newat, newtype, isMetal;
1092     long int mask;
1093     char ianame[3];
1094     float ddcount, xtmp, ytmp, ztmp;
1095    
1096     imetcount = 0;
1097     isMetal = FALSE;
1098     ddcount = 0;
1099     substrismin = False;
1100     pcmfile.nocaps = False;
1101     numbonds = 0;
1102     ibondcount = 0;
1103     for (i = 0; i < MAXSS; i++)
1104     {
1105     isubmap[i] = 0;
1106     }
1107    
1108     if( isubred == 1 )
1109     {
1110     ioffset = natom;
1111     substr.istract[substr.icurstr] = TRUE;
1112     }
1113     else
1114     {
1115     ioffset = 0;
1116     }
1117    
1118    
1119     FetchRecord(pcminfile,pcmfile.string);
1120     L_30:
1121     FetchRecord(pcminfile,pcmfile.string);
1122     *(pcmfile.string + strlen(pcmfile.string) ) = '\0';
1123     if (feof(pcminfile))
1124     goto L_170;
1125     pcmfile.head = 1;
1126     NL;
1127     L_40:
1128     if (strcmp(pcmfile.token, "NA") == 0)
1129     {
1130     gettoken();
1131     if (pcmfile.head == 1000)
1132     goto L_30;
1133     niatom = atoi(pcmfile.token);
1134     niatom += ioffset;
1135     NL;
1136     goto L_30;
1137     } else if (strcmp(pcmfile.token,"ATOMTYPES") == 0)
1138     {
1139     gettoken();
1140     if (pcmfile.head == 1000)
1141     goto L_30;
1142     default_intype = atoi(pcmfile.token);
1143     NL;
1144     goto L_30;
1145     } else if (strcmp(pcmfile.token, "NT") == 0) /* This is for Amino Acids */
1146     {
1147     NL;
1148     i = atoi(pcmfile.token); /* i is atom number of N terminus */
1149     mask = 1L << NTERM; /* use bit 0 of substr 1 for N terminus*/
1150     atom[i+ioffset].flags |= mask;
1151    
1152     NL;
1153     if (strcmp(pcmfile.token, "CT") == 0)
1154     {
1155     NL;
1156     i = atoi(pcmfile.token); /* i is atom number of C terminus */
1157     mask = 1L << CNTERM; /* use bit 1 of substr 1 for C terminus */
1158     atom[i+ioffset].flags |= mask;
1159     }
1160     } else if (strcmp(pcmfile.token, "OT") == 0) /* This is for Sugars */
1161     {
1162     NL;
1163     i = atoi(pcmfile.token); /* i is atom number of O terminus */
1164     mask = 1L << OTERM; /* use bit 0 of substr 1 for O terminus*/
1165     atom[i+ioffset].flags |= mask;
1166    
1167     NL;
1168     if (strcmp(pcmfile.token, "CT") == 0)
1169     {
1170     NL;
1171     i = atoi(pcmfile.token); /* i is atom number of H terminus */
1172     mask = 1L << COTERM; /* use bit 1 of substr 1 for H terminus */
1173     atom[i+ioffset].flags |= mask;
1174     }
1175     } else if (strcmp(pcmfile.token,"START") == 0) /* flag for polybuild */
1176     {
1177     NL;
1178     i = atoi(pcmfile.token);
1179     mask = 1L << DUMMY;
1180     atom[i+ioffset].flags |= mask;
1181     NL; // END
1182     NL;
1183     i = atoi(pcmfile.token);
1184     mask = 1L << DUMMY;
1185     atom[i+ioffset].flags |= mask;
1186    
1187     } else if (strcmp(pcmfile.token, "SS") == 0)
1188     {
1189     goto L_30;
1190     } else if (strcmp(pcmfile.token, "AT") == 0)
1191     {
1192     NL;
1193     newat = atoi(pcmfile.token); // atom serial number
1194     if (newat + ioffset > MAXATOM)
1195     {
1196     message_alert(" Maximum number of atoms exceeded in PCMFIN at atom read","Error");
1197     fprintf(pcmoutfile,"atom read %d %d %d\n",newat,ioffset,natom);
1198     natom = ioffset + newat - 1;
1199     fclose(pcminfile);
1200     exit(0);
1201     }
1202     newat += ioffset;
1203     NL;
1204     if (isdigit(*pcmfile.token))
1205     {
1206     newtype = atoi(pcmfile.token);
1207     } else // character string for metal atom
1208     {
1209     strcpy(ianame,pcmfile.token);
1210     isMetal = TRUE;
1211     }
1212     NL;
1213     xtmp = atof(pcmfile.token);
1214     NL;
1215     ytmp = (atof(pcmfile.token));
1216     NL;
1217     ztmp = atof(pcmfile.token);
1218     NL;
1219     atom[newat].x = xtmp;
1220     atom[newat].y = ytmp;
1221     atom[newat].z = ztmp;
1222    
1223     L_90:
1224     if (strcmp(pcmfile.token, "B") == 0)
1225     {
1226     /* Reading bonds now */
1227     NL;
1228     j = 0;
1229     L_100:
1230     j += 1;
1231     if (pcmfile.state == NUMERIC)
1232     {
1233     ibonded = atoi(pcmfile.token);
1234     ibonded += ioffset;
1235     } else
1236     {
1237     goto L_90;
1238     }
1239     NL;
1240     if (pcmfile.state == NUMERIC)
1241     {
1242     ibondorder = atoi(pcmfile.token);
1243     } else
1244     {
1245     fprintf(stdout, "missing a bondorder, assuming 1\n");
1246     goto L_40;
1247     }
1248     NL;
1249     goto L_100;
1250     }else if ( strcmp(pcmfile.token, "P")== 0)
1251     {
1252     NL;
1253     goto L_90;
1254     }else if (strcmp(pcmfile.token, "D") == 0) // biomolecule marking
1255     {
1256     NL;
1257     NL;
1258     goto L_90;
1259     }else if (strcmp(pcmfile.token,"M")==0)
1260     {
1261     NL;
1262     NL;
1263     if (pcmfile.state != 1)
1264     goto L_90;
1265     NL;
1266     goto L_90;
1267     }else if (strcmp(pcmfile.token,"S")== 0)
1268     {
1269     NL;
1270     if (pcmfile.state == NUMERIC)
1271     {
1272     NL;
1273     goto L_90;
1274     } else
1275     {
1276     goto L_90;
1277     }
1278     }else if (strcmp(pcmfile.token,"H")== 0)
1279     {
1280     NL;
1281     goto L_90;
1282     }else if (strcmp(pcmfile.token,"C")==0)
1283     {
1284     NL;
1285     NL;
1286     goto L_90;
1287     }else if (strcmp(pcmfile.token,"R")== 0)
1288     {
1289     NL;
1290     NL;
1291     goto L_90;
1292     }
1293     } else if (strncmp(pcmfile.token, "}",1) == 0)
1294     {
1295     goto L_170; /* end of structure */
1296     } else if (strcmp(pcmfile.token, "FL") == 0)
1297     {
1298     NL;
1299     L_120: if (strcmp(pcmfile.token, "PRINT") == 0)
1300     {
1301     NL;
1302     if (pcmfile.state == ALPHABETIC)
1303     goto L_120;
1304     NL;
1305     goto L_120;
1306     } else if (strcmp(pcmfile.token, "DIELC") == 0)
1307     {
1308     NL;
1309     if (pcmfile.state != 1)
1310     goto L_120;
1311     NL;
1312     goto L_120;
1313     } else if (strcmp(pcmfile.token, "UV") == 0)
1314     {
1315     NL;
1316     if (pcmfile.state != 1)
1317     goto L_120;
1318     NL;
1319     goto L_120;
1320     } else if (strcmp(pcmfile.token, "PIPR") == 0)
1321     {
1322     NL;
1323     if (pcmfile.state != 1)
1324     goto L_120;
1325     NL;
1326     goto L_120;
1327     } else if (strcmp(pcmfile.token, "PIPL") == 0)
1328     {
1329     NL;
1330     if (pcmfile.state != 1)
1331     goto L_120;
1332     NL;
1333     goto L_120;
1334     } else if (strcmp(pcmfile.token, "EINT") == 0)
1335     {
1336     NL;
1337     if (pcmfile.state != 1)
1338     goto L_120;
1339     NL;
1340     goto L_120;
1341     }
1342     } else if (strcmp(pcmfile.token, "CO") == 0)
1343     {
1344     } else if (strcmp(pcmfile.token, "FBND") == 0)
1345     {
1346     NL;
1347     NL;
1348     NL;
1349     NL;
1350     NL;
1351     NL;
1352     NL;
1353     NL;
1354     NL;
1355     NL;
1356     NL;
1357     NL;
1358     NL;
1359     NL;
1360     NL;
1361     goto L_30; // get another line
1362     } else if (strcmp(pcmfile.token, "FIX") == 0)
1363     {
1364     NL;
1365     if (strcmp(pcmfile.token, "DIS") == 0)
1366     {
1367     NL;
1368     NL;
1369     NL;
1370     L_1223: if (strcmp(pcmfile.token, "R") == 0)
1371     {
1372     NL;
1373     NL;
1374     goto L_1223;
1375     } else if (strcmp(pcmfile.token, "K") == 0)
1376     {
1377     NL;
1378     NL;
1379     goto L_1223;
1380     }
1381     }
1382     } else if (strcmp(pcmfile.token, "DD") == 0)
1383     {
1384     if (isubred == 1)
1385     goto L_30;
1386    
1387     NL;
1388    
1389     if (pcmfile.state == NUMERIC)
1390     {
1391     NL;
1392     NL;
1393     NL;
1394     NL;
1395     L_150: if (strcmp(pcmfile.token, "FROM") == 0)
1396     {
1397     NL;
1398     NL;
1399     goto L_150;
1400     } else if (strcmp(pcmfile.token, "TO") == 0)
1401     {
1402     NL;
1403     NL;
1404     goto L_150;
1405     } else if (strcmp(pcmfile.token, "BY") == 0)
1406     {
1407     NL;
1408     NL;
1409     goto L_150;
1410     }
1411     }
1412     }
1413     goto L_30;
1414     L_170:
1415     return;
1416     }