ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/xyz2pov/src/pov_writer.c
Revision: 1095
Committed: Mon Apr 5 19:34:21 2004 UTC (20 years, 3 months ago) by mmeineke
Content type: text/plain
File size: 12545 byte(s)
Log Message:
more gcc friendly configure script
who knows

File Contents

# Content
1 #define _FILE_OFFSET_BITS 64
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <math.h>
7
8 #include "pov_writer.h"
9 #include "atom_parser.h"
10
11 struct bond{
12 int i;
13 int j;
14 };
15
16 struct linked_bond_list{
17 struct bond the_bond;
18 struct linked_bond_list *next;
19 };
20
21 void make_bonds(struct coords *, int);
22
23 struct linked_bond_list *bl_head;
24
25 void clean_bonds(void);
26
27 void initBondList(void){
28 bl_head = NULL;
29 }
30
31 void pov_write(FILE *out_file, struct coords *the_coords, int n_atoms,
32 int d_hydrogens, int d_bonds, int d_atoms, int d_vectors){
33
34 int i,j; /*loop counters */
35 int skip_atom, skip_bond, test1, test2; /*booleans */
36 double dx, dy, dz; /* used in making the bonds */
37
38 struct linked_bond_list *current_bond; /*keeps track of the linked list*/
39
40 for(i = 0; i < n_atoms; i++){
41 update_types(the_coords[i].name);
42 }
43
44 if(d_atoms){
45
46 fprintf(out_file,
47 "//************************************************************\n"
48 "// The list of atoms\n"
49 "//************************************************************\n"
50 "\n"
51 "\n");
52
53 for(i = 0; i < n_atoms; i++){
54
55 skip_atom = 0;
56
57 if(!d_hydrogens){
58 skip_atom = !strcmp("H", the_coords[i].name);
59 }
60
61 if(!skip_atom){
62
63 fprintf(out_file,
64 "make_%s_atom( %lf, %lf, %lf )\n",
65 the_coords[i].name,
66 the_coords[i].x,
67 the_coords[i].z,
68 the_coords[i].y);
69 }
70 }
71
72 fprintf(out_file,
73 "\n"
74 "\n");
75 }
76
77
78 if (d_vectors) {
79
80 fprintf(out_file,
81 "//************************************************************\n"
82 "// The list of vectors\n"
83 "//************************************************************\n"
84 "\n"
85 "\n");
86
87 for(i = 0; i < n_atoms; i++){
88
89 if (the_coords[i].hasVector) {
90 fprintf(out_file,
91 "make_%s_vector(%lf, %lf, %lf, %lf, %lf, %lf)\n",
92 the_coords[i].name,
93 the_coords[i].x,
94 the_coords[i].z,
95 the_coords[i].y,
96 the_coords[i].ux,
97 the_coords[i].uz,
98 the_coords[i].uy);
99 }
100 }
101
102 fprintf(out_file,
103 "\n"
104 "\n");
105 }
106
107 if(d_bonds){
108
109 fprintf(out_file,
110 "//************************************************************\n"
111 "// The list of bonds\n"
112 "//************************************************************\n"
113 "\n"
114 "\n");
115
116 if( bl_head == NULL ) make_bonds(the_coords, n_atoms);
117
118 current_bond = bl_head->next;
119
120 while(current_bond != NULL){
121
122 skip_bond = 0;
123
124 i = current_bond->the_bond.i;
125 j = current_bond->the_bond.j;
126
127 if(!d_hydrogens){
128
129 test1 = !strcmp("H", the_coords[i].name);
130 test2 = !strcmp("H", the_coords[j].name);
131
132 skip_bond = (test1 || test2);
133 }
134
135 if(!skip_bond){
136
137 dx = (the_coords[j].x - the_coords[i].x) / 2.0;
138 dy = (the_coords[j].y - the_coords[i].y) / 2.0;
139 dz = (the_coords[j].z - the_coords[i].z) / 2.0;
140
141 fprintf(out_file,
142 "make_%s_bond( %lf, %lf, %lf, %lf, %lf, %lf )\n",
143 the_coords[i].name,
144 the_coords[i].x,
145 the_coords[i].z,
146 the_coords[i].y,
147 (the_coords[i].x + dx),
148 (the_coords[i].z + dz),
149 (the_coords[i].y + dy));
150
151 fprintf(out_file,
152 "make_%s_bond( %lf, %lf, %lf, %lf, %lf, %lf )\n",
153 the_coords[j].name,
154 the_coords[j].x,
155 the_coords[j].z,
156 the_coords[j].y,
157 (the_coords[j].x - dx),
158 (the_coords[j].z - dz),
159 (the_coords[j].y - dy));
160
161 fprintf(out_file, "\n");
162 }
163
164 current_bond = current_bond->next;
165 }
166
167 if( regenerateBonds )clean_bonds();
168 }
169 }
170
171
172 void make_bonds(struct coords *the_coords, int n_atoms){
173
174 int i, j; /*counters */
175 struct linked_bond_list *temp_bond; /*bond place holder */
176
177 const double bond_fudge = 1.12; // a fudge factor
178 struct atom type_i, type_j; /* holds the atom types */
179
180 int test; /* booleans */
181 double dx, dy, dz, dr2, dcv, dcv2; // used to determine bond existence
182
183
184 bl_head = (struct linked_bond_list *)malloc(sizeof(struct linked_bond_list));
185 bl_head->next = NULL;
186
187 for(i = 0; i < (n_atoms - 1); i++){
188
189 for(j = (i+1); j < n_atoms; j++){
190
191 dx = the_coords[j].x - the_coords[i].x;
192 dy = the_coords[j].y - the_coords[i].y;
193 dz = the_coords[j].z - the_coords[i].z;
194
195 dr2 = dx * dx + dy * dy + dz * dz;
196
197 test = !findAtomType(the_coords[i].name, &type_i);
198 if(test){
199 fprintf(stderr, "Atom Type %s, not found!\n",
200 the_coords[i].name);
201 exit(8);
202 }
203
204 test = !findAtomType(the_coords[j].name, &type_j);
205 if(test){
206 fprintf(stderr, "Atom Type %s, not found!\n",
207 the_coords[j].name);
208 exit(8);
209 }
210
211
212 dcv = bond_fudge * (type_i.covalentRadii + type_j.covalentRadii);
213 dcv2 = dcv * dcv;
214
215 if(dr2 <= dcv2){
216
217 temp_bond =
218 (struct linked_bond_list *)malloc(sizeof(struct linked_bond_list));
219
220 bl_head->the_bond.i = i;
221 bl_head->the_bond.j = j;
222
223 temp_bond->next = bl_head;
224 bl_head = temp_bond;
225 }
226 }
227 }
228 }
229
230
231 void clean_bonds(){
232 struct linked_bond_list *current_bond;
233 struct linked_bond_list *next_bond; /* place holders */
234
235
236 current_bond = bl_head->next;
237
238 while(current_bond != NULL){
239
240 next_bond = current_bond->next;
241 free(current_bond);
242 current_bond = next_bond;
243 }
244
245 bl_head->next = NULL;
246 free( bl_head );
247 bl_head = NULL;
248 }
249
250
251 void make_header_macros(FILE *out_file){
252
253 struct linked_atom *type_list; // list of all atom types
254 struct linked_atom *current_type; // current atom type
255
256 char *name;
257 double red, green, blue;
258 double radius;
259
260 type_list = get_type_list();
261 current_type = type_list->next;
262
263 while(current_type != NULL){
264
265 name = current_type->myAtom.name;
266 radius = current_type->myAtom.vanDerWallRadii;
267 red = ((double)current_type->myAtom.red) / 255.0;
268 green = ((double)current_type->myAtom.green) / 255.0;
269 blue = ((double)current_type->myAtom.blue) / 255.0;
270
271
272
273 fprintf(out_file,
274 "//****************************************************\n"
275 "// DEFINE %s MACROS\n"
276 "//****************************************************\n"
277 "\n"
278 "#macro make_%s_bond "
279 "(end_1x, end_1y, end_1z, end_2x, end_2y, end_2z)\n"
280 "\n"
281 " #local x1 = end_1x;\n"
282 " #local y1 = end_1y;\n"
283 " #local z1 = end_1z;\n"
284 " #local x2 = end_2x;\n"
285 " #local y2 = end_2y;\n"
286 " #local z2 = end_2z;\n"
287 "\n"
288 " #if(ROTATE)\n"
289 " #local x1_new = rotatePointX + A11 * (x1-rotatePointX) + A12 * (y1-rotatePointY) + A13 * (z1-rotatePointZ);\n"
290 " #local y1_new = rotatePointY + A21 * (x1-rotatePointX) + A22 * (y1-rotatePointY) + A23 * (z1-rotatePointZ);\n"
291 " #local z1_new = rotatePointZ + A31 * (x1-rotatePointX) + A32 * (y1-rotatePointY) + A33 * (z1-rotatePointZ);\n"
292 "\n"
293 " #local x2_new = rotatePointX + A11 * (x2-rotatePointX) + A12 * (y2-rotatePointY) + A13 * (z2-rotatePointZ);\n"
294 " #local y2_new = rotatePointY + A21 * (x2-rotatePointX) + A22 * (y2-rotatePointY) + A23 * (z2-rotatePointZ);\n"
295 " #local z2_new = rotatePointZ + A31 * (x2-rotatePointX) + A32 * (y2-rotatePointY) + A33 * (z2-rotatePointZ);\n"
296 "\n"
297 " #else\n"
298 " #local x1_new = x1;"
299 " #local y1_new = y1;"
300 " #local z1_new = z1;"
301 "\n"
302 " #local x2_new = x2;"
303 " #local y2_new = y2;"
304 " #local z2_new = z2;"
305 "\n"
306 " #end\n"
307 "\n"
308 " cylinder{\n"
309 " < x1_new, y1_new, z1_new >,\n"
310 " < x2_new, y2_new, z2_new >,\n"
311 " BOND_RADIUS\n"
312 " texture{\n"
313 " pigment{ rgb < %lf, %lf, %lf > }\n"
314 " finish{\n"
315 " ambient .2\n"
316 " diffuse .6\n"
317 " specular 1\n"
318 " roughness .001\n"
319 " metallic\n"
320 " }\n"
321 " }\n"
322 " }\n"
323 "#end\n"
324 "#macro make_%s_atom "
325 "(center_x, center_y, center_z)\n"
326 "\n"
327 " #local x1 = center_x;\n"
328 " #local y1 = center_y;\n"
329 " #local z1 = center_z;\n"
330 "\n"
331 " #if(ROTATE)\n"
332 "\n"
333 " #local x1_new = rotatePointX + A11 * (x1-rotatePointX) + A12 * (y1-rotatePointY) + A13 * (z1-rotatePointZ);\n"
334 " #local y1_new = rotatePointY + A21 * (x1-rotatePointX) + A22 * (y1-rotatePointY) + A23 * (z1-rotatePointZ);\n"
335 " #local z1_new = rotatePointZ + A31 * (x1-rotatePointX) + A32 * (y1-rotatePointY) + A33 * (z1-rotatePointZ);\n"
336 "\n"
337 " #else\n"
338 "\n"
339 " #local x1_new = x1;"
340 " #local y1_new = y1;"
341 " #local z1_new = z1;"
342 "\n"
343 " #end\n"
344 "\n"
345 " sphere{\n"
346 " < x1_new, y1_new, z1_new >,\n"
347 " ATOM_SPHERE_FACTOR * %lf\n"
348 " texture{\n"
349 " pigment{ rgb < %lf, %lf, %lf > }\n"
350 " finish{\n"
351 " ambient .2\n"
352 " diffuse .6\n"
353 " specular 1\n"
354 " roughness .001\n"
355 " metallic\n"
356 " }\n"
357 " }\n"
358 " }\n"
359 "#end\n"
360 "#macro make_%s_vector "
361 "(center_x, center_y, center_z, ux, uy, uz)\n"
362 "\n"
363 " #local vx = VECTOR_SCALE * ux;\n"
364 " #local vy = VECTOR_SCALE * uy;\n"
365 " #local vz = VECTOR_SCALE * uz;\n"
366 " #local x1 = center_x - 0.5 * vx;\n"
367 " #local y1 = center_y - 0.5 * vy;\n"
368 " #local z1 = center_z - 0.5 * vz;\n"
369 " #local x2 = center_x + 0.5 * vx;\n"
370 " #local y2 = center_y + 0.5 * vy;\n"
371 " #local z2 = center_z + 0.5 * vz;\n"
372 " #local v2 = vx*vx + vy*vy + vz*vz;\n"
373 " #local vl = sqrt(v2);\n"
374 " #local x3 = x1 + vx * (1.0 - CONE_FRACTION);\n"
375 " #local y3 = y1 + vy * (1.0 - CONE_FRACTION);\n"
376 " #local z3 = z1 + vz * (1.0 - CONE_FRACTION);\n"
377 "\n"
378 " #if(ROTATE)\n"
379 " #local x1_new = rotatePointX + A11 * (x1-rotatePointX) + A12 * (y1-rotatePointY) + A13 * (z1-rotatePointZ);\n"
380 " #local y1_new = rotatePointY + A21 * (x1-rotatePointX) + A22 * (y1-rotatePointY) + A23 * (z1-rotatePointZ);\n"
381 " #local z1_new = rotatePointZ + A31 * (x1-rotatePointX) + A32 * (y1-rotatePointY) + A33 * (z1-rotatePointZ);\n"
382 "\n"
383 " #local x2_new = rotatePointX + A11 * (x2-rotatePointX) + A12 * (y2-rotatePointY) + A13 * (z2-rotatePointZ);\n"
384 " #local y2_new = rotatePointY + A21 * (x2-rotatePointX) + A22 * (y2-rotatePointY) + A23 * (z2-rotatePointZ);\n"
385 " #local z2_new = rotatePointZ + A31 * (x2-rotatePointX) + A32 * (y2-rotatePointY) + A33 * (z2-rotatePointZ);\n"
386 "\n"
387 " #local x3_new = rotatePointX + A11 * (x3-rotatePointX) + A12 * (y3-rotatePointY) + A13 * (z3-rotatePointZ);\n"
388 " #local y3_new = rotatePointY + A21 * (x3-rotatePointX) + A22 * (y3-rotatePointY) + A23 * (z3-rotatePointZ);\n"
389 " #local z3_new = rotatePointZ + A31 * (x3-rotatePointX) + A32 * (y3-rotatePointY) + A33 * (z3-rotatePointZ);\n"
390 "\n"
391 " #else\n"
392 " #local x1_new = x1;"
393 " #local y1_new = y1;"
394 " #local z1_new = z1;"
395 "\n"
396 " #local x2_new = x2;"
397 " #local y2_new = y2;"
398 " #local z2_new = z2;"
399 "\n"
400 " #local x3_new = x3;"
401 " #local y3_new = y3;"
402 " #local z3_new = z3;"
403 "\n"
404 " #end\n"
405 "\n"
406 " cylinder{\n"
407 " < x1_new, y1_new, z1_new >,\n"
408 " < x3_new, y3_new, z3_new >,\n"
409 " STICK_RADIUS\n"
410 " texture{\n"
411 " pigment{ rgb < %lf, %lf, %lf > }\n"
412 " finish{\n"
413 " ambient .2\n"
414 " diffuse .6\n"
415 " specular 1\n"
416 " roughness .001\n"
417 " metallic\n"
418 " }\n"
419 " }\n"
420 " }\n"
421 " cone{\n"
422 " < x2_new, y2_new, z2_new >, 0.0\n"
423 " < x3_new, y3_new, z3_new >, CONE_RADIUS\n"
424 " texture{\n"
425 " pigment{ rgb < %lf, %lf, %lf > }\n"
426 " finish{\n"
427 " ambient .2\n"
428 " diffuse .6\n"
429 " specular 1\n"
430 " roughness .001\n"
431 " metallic\n"
432 " }\n"
433 " }\n"
434 " }\n"
435 "#end\n"
436 "\n"
437 "\n",
438 name,
439 name,
440 red, green, blue,
441 name,
442 radius,
443 red, green, blue,
444 name,
445 red, green, blue,
446 red, green, blue);
447
448 current_type = current_type->next;
449 }
450 }