1 /*****
2 This file is part of the Babel Program
3 Copyright (C) 1992-96 W. Patrick Walters and Matthew T. Stahl
4 All Rights Reserved
5 All Rights Reserved
6 All Rights Reserved
7 All Rights Reserved
8
9 For more information please contact :
10
11 babel@mercury.aichem.arizona.edu
12 --------------------------------------------------------------------------------
13 FILE : rdgzmat.c
14 AUTHOR(S) : Pat Walters
15 DATE : 12-93
16 PURPOSE : routines to read a Gaussian Z-matrix
17 ******/
18
19 #include "bbltyp.h"
20 #define GAU_DELIMS "\t\n, "
21
22 int
read_gau_zmatrix(FILE * file1,ums_type * mol)23 read_gau_zmatrix(FILE *file1, ums_type *mol)
24 {
25 char the_line[BUFF_SIZE];
26 int i = 0, j;
27 int sym_count = 0;
28 int result;
29 zsymbol *the_syms;
30 char lab1[10],lab2[10],lab3[10];
31 char sym1[10],sym2[10],sym3[10];
32 int blank_lines = 0;
33 int stop = FALSE;
34 long int atom_start,variable_start;
35 char first_token[BUFF_SIZE];
36 int tokens;
37 double factor;
38
39 Atoms = 0;
40 while (fgets(the_line,sizeof(the_line), file1) != NULL)
41 {
42 if (the_line[0] == '#')
43 break;
44 }
45 while (fgets(the_line,sizeof(the_line), file1) != NULL)
46 {
47 if (is_blank_line(the_line))
48 blank_lines++;
49 if (blank_lines == 2)
50 break;
51 }
52 toss(file1,1);
53 atom_start = ftell(file1);
54 while (fgets(the_line,sizeof(the_line), file1) != NULL)
55 {
56 if (is_blank_line(the_line))
57 stop = TRUE;
58 else
59 {
60 strcpy(first_token,gettoken(the_line,", \t\n",1));
61 uppercase(first_token);
62 if (EQn(first_token,"VARIABLE",8))
63 stop = TRUE;
64 }
65 if (stop == TRUE)
66 break;
67 else
68 Atoms++;
69 }
70 initialize_ums(&mol);
71 initialize_internal(&mol);
72 variable_start = ftell(file1);
73 i = 0;
74 while ((fgets(the_line,sizeof(the_line), file1) != NULL))
75 {
76 i++;
77 }
78 the_syms = (zsymbol *)malloc(3 * Atoms * sizeof(zsymbol));
79 fseek(file1,variable_start,0);
80 while (fgets(the_line,sizeof(the_line), file1) != NULL)
81 {
82 if (count_tokens(the_line," =\t\n") == 2)
83 {
84 strcpy(the_syms[sym_count].sym,gettoken(the_line," =\t\n",1));
85 the_syms[sym_count].val = (double)atof(gettoken(the_line," =\t\n",2));
86 sym_count++;
87 }
88 }
89 ShowProgress(Atoms,"Reading Atoms");
90 fseek(file1,atom_start,0);
91 for (j = 1; j <= Atoms; j++)
92 {
93 factor = 0.0;
94 UpdateProgress();
95 fgets(the_line,sizeof(the_line), file1);
96 tokens = count_tokens(the_line,GAU_DELIMS);
97 switch(j)
98 {
99 case 1 :
100 strcpy(Type(j),gettoken(the_line,GAU_DELIMS,1));
101 break;
102 case 2 :
103 strcpy(Type(j),gettoken(the_line,GAU_DELIMS,1));
104 strcpy(lab1,gettoken(the_line,GAU_DELIMS,2));
105 strcpy(sym1,gettoken(the_line,GAU_DELIMS,3));
106
107 mol->internal[j].na = xlate_label(mol,lab1,j);
108 mol->internal[j].r = xlate_symbol(the_syms,sym1,sym_count);
109 break;
110 case 3 :
111 sscanf(the_line,"%s,%s,%s,%s,%s",Type(j),lab1,sym1,lab2,sym2);
112 strcpy(Type(j),gettoken(the_line,GAU_DELIMS,1));
113 strcpy(lab1,gettoken(the_line,GAU_DELIMS,2));
114 strcpy(sym1,gettoken(the_line,GAU_DELIMS,3));
115 strcpy(lab2,gettoken(the_line,GAU_DELIMS,4));
116 strcpy(sym2,gettoken(the_line,GAU_DELIMS,5));
117
118 mol->internal[j].na = xlate_label(mol,lab1,j);
119 mol->internal[j].nb = xlate_label(mol,lab2,j);
120 mol->internal[j].r = xlate_symbol(the_syms,sym1,sym_count);
121 mol->internal[j].w = xlate_symbol(the_syms,sym2,sym_count);
122 break;
123 default :
124 strcpy(Type(j),gettoken(the_line,GAU_DELIMS,1));
125 strcpy(lab1,gettoken(the_line,GAU_DELIMS,2));
126 strcpy(sym1,gettoken(the_line,GAU_DELIMS,3));
127 strcpy(lab2,gettoken(the_line,GAU_DELIMS,4));
128 strcpy(sym2,gettoken(the_line,GAU_DELIMS,5));
129 strcpy(lab3,gettoken(the_line,GAU_DELIMS,6));
130 strcpy(sym3,gettoken(the_line,GAU_DELIMS,7));
131 if (tokens == 8)
132 factor = atof(gettoken(the_line,GAU_DELIMS,8));
133
134 mol->internal[j].na = xlate_label(mol,lab1,j);
135 mol->internal[j].nb = xlate_label(mol,lab2,j);
136 mol->internal[j].nc = xlate_label(mol,lab3,j);
137 mol->internal[j].r = xlate_symbol(the_syms,sym1,sym_count);
138 mol->internal[j].w = xlate_symbol(the_syms,sym2,sym_count);
139 mol->internal[j].t = xlate_symbol(the_syms,sym3,sym_count);
140 if (factor != 0.0)
141 mol->internal[j].t *= factor;
142 break;
143 }
144 }
145 for (i = 1; i <= Atoms; i++)
146 clean_atom_type(Type(i));
147
148 if (Atoms > 0)
149 {
150 result = int_to_cart(mol);
151 result = assign_radii(mol);
152 result = assign_bonds(mol);
153 result = assign_types(mol);
154 result = build_connection_table(mol);
155 assign_bond_order(mol);
156 }
157 free(the_syms);
158 read_to_eof(file1);
159 return(TRUE);
160 }
161
162
163
xlate_label(ums_type * mol,char * sym,int max)164 int xlate_label(ums_type *mol, char *sym, int max)
165 {
166 int i;
167 char the_str[100];
168
169 if (isdigit(sym[0]))
170 return(atoi(sym));
171 for (i = 1; i < max; i++)
172 if (EQ(Type(i),sym))
173 return(i);
174 sprintf(the_str,"cant translate label %s\n",sym);
175 show_warning(the_str);
176 return(0);
177 }
178
xlate_symbol(zsymbol * the_syms,char * sym,int max)179 double xlate_symbol(zsymbol *the_syms, char *sym, int max)
180 {
181 int i;
182 int is_neg = FALSE;
183 char the_str[100];
184
185 if ((sym[0] == '-') || (isdigit(sym[0])))
186 return(atof(sym));
187
188 if (sym[0] == '-')
189 {
190 is_neg = TRUE;
191 sym++;
192 }
193
194 for (i = 0; i < max; i++)
195 if (EQ(the_syms[i].sym,sym))
196 {
197 if (is_neg == TRUE)
198 return(the_syms[i].val * (-1));
199 else
200 return(the_syms[i].val);
201 }
202 sprintf(the_str,"cant translate symbol %s\n",sym);
203 show_warning(the_str);
204 return(0.0);
205 }
206
207
208
209
210
211
212
213
214
215
216
217
218