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 : rdfdat.c
14 AUTHOR(S) : Pat Walters
15 DATE : 12-93
16 PURPOSE : routines to read a CSD FDAT file
17 ******/
18
19 #include "bbltyp.h"
20 #undef PRINT_HEADER
21 #undef DEBUG
22
23 static warning wstr;
24
read_fdat(FILE * file1,ums_type * mol)25 int read_fdat(FILE *file1, ums_type *mol)
26 {
27 char csd_line[BUFF_SIZE];
28 fract_type f;
29 int remark_lines;
30 int remark_chars;
31 int symmetry_lines;
32 long int pos;
33
34 char REFCODE[9];
35 char NAT[4], NSAT[4], NCON[4], CELL[2];
36 char NRFAC[4],NREM[3],NDIS[4],NERR[4],NOPR[4],NRAD[4];
37 char A[7],B[7],C[7],ALPHA[7],BETA[7],GAMMA[7];
38 char Ap[2],Bp[2],Cp[2],ALPHAp[2],BETAp[2],GAMMAp[2];
39 int i,j,k;
40 int result;
41 matrix_3x3 m;
42 int pending = FALSE;
43 int ncon;
44
45 char previous[15];
46 int tokens, start;
47 char Xstr[10], Ystr[10], Zstr[10];
48 int done = FALSE;
49
50 strcpy(previous,"XXXXXXXXXX");
51 uppercase(InputKeywords);
52
53 while ((fgets(csd_line,sizeof(csd_line), file1) != NULL) && (!done))
54 {
55 if (check_for_eof(file1))
56 return(FALSE);
57 if (csd_line[0] == '#')
58 {
59 remark_lines = 0;
60 done = TRUE;
61 my_strncpy(REFCODE,&csd_line[1],8);
62 if (check_refcode(InputKeywords,csd_line,mol))
63 {
64 pending = TRUE;
65 strcpy(REFCODE,gettoken(REFCODE," ",1));
66 my_strncpy(NRFAC,&csd_line[26],3);
67 my_strncpy(NREM,&csd_line[29],3);
68 my_strncpy(NDIS,&csd_line[32],3);
69 my_strncpy(NERR,&csd_line[35],3);
70 my_strncpy(NOPR,&csd_line[38],3);
71 my_strncpy(NRAD,&csd_line[41],3);
72 my_strncpy(NAT,&csd_line[44],3);
73 my_strncpy(NSAT,&csd_line[47],3);
74 my_strncpy(NCON,&csd_line[53],3);
75 my_strncpy(CELL,&csd_line[56],3);
76 Atoms = atoi(NAT) + atoi(NSAT);
77 ShowProgress(Atoms,"Reading Atoms");
78 result = initialize_ums(&mol);
79 strcpy(Title,REFCODE);
80 #ifdef PRINT_HEADER
81 printf("REFCODE = %s NAT = %s NSAT = %s Atoms = %d\n",
82 REFCODE,NAT,NSAT,Atoms);
83 printf("NRFAC = %s NREM = %s NDIS = %s NERR =%s NOPR = %s NRAD = %s\n",
84 NRFAC,NREM,NDIS,NERR,NOPR,NRAD);
85 #endif
86 if ((CELL[0] == '1') && (Atoms > 0)) /* Make sure we have cell params */
87 {
88 fgets(csd_line,sizeof(csd_line), file1);
89 my_strncpy(A,&csd_line[0],6);
90 my_strncpy(B,&csd_line[6],6);
91 my_strncpy(C,&csd_line[12],6);
92 my_strncpy(ALPHA,&csd_line[18],6);
93 my_strncpy(BETA,&csd_line[24],6);
94 my_strncpy(GAMMA,&csd_line[30],6);
95 my_strncpy(Ap,&csd_line[36],1);
96 my_strncpy(Bp,&csd_line[37],1);
97 my_strncpy(Cp,&csd_line[38],1);
98 my_strncpy(ALPHAp,&csd_line[39],1);
99 my_strncpy(BETAp,&csd_line[40],1);
100 my_strncpy(GAMMAp,&csd_line[41],1);
101 f.A = my_atof(A)/pow(10.0,my_atof(Ap));
102 f.B = my_atof(B)/pow(10.0,my_atof(Bp));
103 f.C = my_atof(C)/pow(10.0,my_atof(Cp));
104 f.Alpha = my_atof(ALPHA)/pow(10.0,my_atof(ALPHAp));
105 f.Beta = my_atof(BETA)/pow(10.0,my_atof(BETAp));
106 f.Gamma = my_atof(GAMMA)/pow(10.0,my_atof(GAMMAp));
107 ncon = (int) my_atoi(NCON);
108
109 remark_chars = (atoi(NRFAC)+atoi(NREM)+atoi(NDIS)+atoi(NERR));
110 if (remark_chars > 0)
111 remark_lines = remark_chars/80 + 1;
112 if (remark_chars % 80 == 0)
113 remark_lines = remark_chars/80;
114
115 symmetry_lines = atoi(NOPR)/5 + 1;
116 #ifdef PRINT_HEADER
117 printf("A = %f B = %f C = %f \n",f.A,f.B,f.C);
118 printf("NCON = %s\n",NCON);
119 printf("Alpha = %f Beta = %f Gamma = %f \n",f.Alpha,f.Beta,f.Gamma);
120 printf("remark_chars = %d remark_lines = %d symmetry_lines = %d \n",
121 remark_chars,remark_lines,symmetry_lines);
122 #endif
123 fill_orth_matrix(&f,&m);
124
125 for (i = 1; i < 2; i++)
126 fgets(csd_line,sizeof(csd_line),file1);
127 for (i = 1; i <= symmetry_lines; i++)
128 {
129 fgets(csd_line,sizeof(csd_line),file1);
130 }
131 for (i = 1; i <= remark_lines; i++)
132 {
133 fgets(csd_line,sizeof(csd_line),file1);
134 }
135 k = 1;
136 for (i = 1; i <= Atoms; i += 3)
137 {
138 UpdateProgress();
139 fgets(csd_line,sizeof(csd_line),file1);
140 tokens = strlen(csd_line)/26;
141 for (j = 0; (j < tokens) && (k <= Atoms); j++)
142 {
143 start = j * 27;
144 my_strncpy(Type(k),&csd_line[start],5);
145 my_strncpy(Xstr,&csd_line[start + 5],7);
146 my_strncpy(Ystr,&csd_line[start + 12],7);
147 my_strncpy(Zstr,&csd_line[start + 19],7);
148 X(k) = my_atof(Xstr)/100000.0;
149 Y(k) = my_atof(Ystr)/100000.0;
150 Z(k) = my_atof(Zstr)/100000.0;
151 clean_atom_type(Type(k));
152 #ifdef DEBUG
153 printf("%d %s %f %f %f\n",k,Type(k),X(k),Y(k),Z(k));
154 #endif
155 fract_to_cart(&Point(k),&m);
156 k++;
157 }
158 }
159 }
160 }
161
162 if ((Atoms > 0) && (pending))
163 {
164 assign_radii(mol);
165 assign_bonds(mol);
166 assign_types(mol);
167 build_connection_table(mol);
168 assign_bond_order(mol);
169 }
170 if (!pending)
171 strcpy(Title,REFCODE);
172 pending = FALSE;
173 }
174 }
175
176 /* find the start of the next record */
177 pos = ftell(file1);
178 while (fgets(csd_line,sizeof(csd_line), file1))
179 {
180 if (csd_line[0] == '#')
181 break;
182 pos = ftell(file1);
183 }
184 fseek(file1,pos,0);
185
186 return(TRUE);
187 }
188
189
my_strncpy(char * str1,char * str2,int len)190 void my_strncpy(char *str1, char *str2, int len)
191 {
192 strncpy(str1,str2,len);
193 str1[len] = '\0';
194 }
195
my_atof(char * the_str)196 double my_atof(char *the_str)
197 {
198 if (strlen(the_str) > 0)
199 return(atof(the_str));
200 else
201 return(0.0);
202 }
203
my_atoi(char * the_str)204 double my_atoi(char *the_str)
205 {
206 if (strlen(the_str) > 0)
207 return(atoi(the_str));
208 else
209 return(0);
210 }
211
check_refcode(char * keywords,char * csd_line,ums_type * mol)212 int check_refcode(char *keywords, char *csd_line,ums_type *mol)
213 {
214 int want_this = FALSE;
215 char REFCODE[9];
216 char the_keywords[BUFF_SIZE];
217
218 strcpy(the_keywords,keywords);
219 uppercase(the_keywords);
220 my_strncpy(REFCODE,&csd_line[1],8);
221
222 strcpy(REFCODE,gettoken(REFCODE," ",1));
223 if ((!UseMenus) &&
224 (EQ(the_keywords,"KEYWORDS GO HERE") ||
225 (strstr(the_keywords,REFCODE) != NULL)))
226 want_this = TRUE;
227 if ((UseMenus) &&
228 (EQ(the_keywords,"KEYWORDS GO HERE") ||
229 (EQ(the_keywords,REFCODE))))
230 want_this = TRUE;
231 if ((strstr(the_keywords,"ALL")) || (strstr(the_keywords,"LAST")))
232 want_this = TRUE;
233 /* printf("%s %s %d\n",the_keywords,REFCODE,want_this); */
234 return(want_this);
235 }
236
237
238
239