-
Notifications
You must be signed in to change notification settings - Fork 0
/
write_car.c
executable file
·282 lines (232 loc) · 9.08 KB
/
write_car.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/*********************************************************************/
/*** write_car will now just write out the co-ords it is sent ******/
/*** without alterations. Any messing with the structure should ******/
/*** be done elsewhere! Dave Willock November 2005 ******/
/*********************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include "maxima.h"
#include "ewald.h"
#include "constants.h"
#include "structures.h"
#include "global_values.h"
#define DEBUG FALSE
/* ------Prototype-list---------------------------------------- */
void write_atom_data(FILE *fp, atom *p_atom, double scale_factor, coord_flags *p_fix_flags);
void put_string (FILE *fp, int *p_ichar, int length);
void min_image( double *x, double *y, double *z, double *p_recip_latt_vec, double *p_latt_vec);
void cart_to_fract( double cart_x, double cart_y, double cart_z,
double *fract_a, double *fract_b, double *fract_c,
double *p_recip_latt_vec );
void fract_to_cart( double *cart_x, double *cart_y, double *cart_z,
double frac_a, double frac_b, double frac_c,
double *p_latt_vec );
void vec_cross(double *p_A, double *p_B, double *p_cross);
double size_vector(double *p_vector);
double unit_vector(double *p_vector);
/* ------------------------------------------------------------ */
void write_car( FILE *fp, int *p_header_line, int *p_title_line, char *p_c_title_line,
int *p_date_line, atom *p_molecule, int *p_mol_number,
int pbc, double *p_abc, int num_atoms, double scale_factor,
int start_frame, int *p_super, double *p_latt_vec,
double *p_recip_latt_vec, coord_flags *p_fix_flags,
int need_draw, win_details *p_win_geom, int num_windows )
{
int iii, iwin, iloop, mol_current, this_atom;
int iavec, ibvec, icvec;
double ta[3],tb[3],t[3], x,y,z;
double fract_a, fract_b, fract_c;
double rrr, yyy[3], theta, dtheta;
char *p_this_char;
atom current_atom;
atom draw_atom;
atom *p_atom;
coord_flags *p_this_fix;
/*** Drawing variables ***/
int idraw;
/*** Use the first element of header_line equal -1 as an indicator that */
/*** the header line has not been read */
if (start_frame)
{
if (*p_header_line != -1)
{
put_string( fp, p_header_line,100);
}
else
{
fprintf(fp, "!BIOSYM archive 3\n");
}
}
/* check if periodic boundaries were set */
if (pbc)
{
if (start_frame) fprintf(fp, "PBC=ON\n");
/*
if (*p_title_line != -1)
{
put_string(fp, p_title_line,100);
fprintf(fp, "\n");
}
else
{
fprintf(fp, "%s", p_c_title_line);
}
*/
fprintf(fp, "analyse_hist generated file\n");
/*** Use the first element of date_line equal -1 as an indicator that */
/*** the header line has not been read */
if (*p_date_line != -1)
{
put_string(fp, p_date_line,100);
}
else
{
fprintf(fp, "!DATE Mon Oct 12 12:17:26 1998\n");
}
fprintf(fp,"PBC");
for (iloop=0; iloop < 6; iloop++)
{
if ( iloop <= 2 )
{
fprintf(fp,"%10.4f",*(p_abc+iloop) * scale_factor * *(p_super+iloop));
}
else
{
fprintf(fp,"%10.4f",*(p_abc+iloop)*RAD_TO_DEG);
}
}
fprintf(fp," (P1)\n");
}
else
{
if (start_frame) fprintf(fp,"PBC=OFF\n");
put_string(fp, p_title_line,100);
put_string(fp, p_date_line,100);
}
if (need_draw)
{
idraw=0;
}
if (pbc)
{
mol_current=0;
p_atom=p_molecule;
for (iavec=0; iavec<= (*p_super)-1; iavec++)
{
ta[0]=iavec * *p_latt_vec;
ta[1]=iavec * *(p_latt_vec+1);
ta[2]=iavec * *(p_latt_vec+2);
for (ibvec=0; ibvec<=*(p_super+1)-1; ibvec++)
{
tb[0]=ibvec * *(p_latt_vec+3);
tb[1]=ibvec * *(p_latt_vec+4);
tb[2]=ibvec * *(p_latt_vec+5);
for (icvec=0; icvec<=*(p_super+2)-1; icvec++)
{
t[0]= ta[0] + tb[0] + icvec * *(p_latt_vec+6);
t[1]= ta[1] + tb[1] + icvec * *(p_latt_vec+7);
t[2]= ta[2] + tb[2] + icvec * *(p_latt_vec+8);
p_atom=p_molecule;
p_this_fix= p_fix_flags;
for (this_atom=0; this_atom < num_atoms; this_atom++)
{
if (*(p_mol_number+this_atom) != mol_current)
{
mol_current++;
fprintf(fp, "end\n");
}
current_atom = *p_atom;
current_atom.x += t[0];
current_atom.y += t[1];
current_atom.z += t[2];
if (DEBUG) printf("writing data for atom at %10.6f %10.6f %10.6f\n",
current_atom.x,current_atom.y,current_atom.z);
write_atom_data(fp, ¤t_atom, scale_factor, p_this_fix );
p_this_fix++;
p_atom++;
}
/*** Add any features requested by drawing options ****/
if (need_draw)
{
/*** DEBUG, Check centres *********/
sprintf(current_atom.group,"DRAW");
sprintf(current_atom.group_no,"1");
sprintf(current_atom.pot,"dr");
sprintf(current_atom.elem,"S");
current_atom.part_chge=0.0;
p_this_fix= p_fix_flags;
for (iwin=0; iwin<=num_windows; iwin++)
{
sprintf(current_atom.label,"%s%d","S",iwin);
current_atom.x= p_win_geom->centre[iwin][0];
current_atom.y= p_win_geom->centre[iwin][1];
current_atom.z= p_win_geom->centre[iwin][2];
write_atom_data(fp, ¤t_atom, scale_factor, p_this_fix );
}
/*** DEBUG, Check centres end *****/
printf("Drawing circles\n");
sprintf(current_atom.group,"DRAW");
sprintf(current_atom.group_no,"1");
sprintf(current_atom.pot,"dr");
sprintf(current_atom.elem,"H");
current_atom.part_chge=0.0;
p_this_fix= p_fix_flags;
for (iwin=0; iwin<=num_windows; iwin++)
{
/*** Form a y axis in the plane ***/
vec_cross(&(p_win_geom->r_vec[iwin][0]),
&(p_win_geom->norm[iwin][0]),
&yyy[0]);
rrr= size_vector(&(p_win_geom->r_vec[iwin][0]));
unit_vector(&yyy[0]);
printf("yyy: %10.6f %10.6f %10.6f rrr: %10.6f\n",
yyy[0],yyy[1],yyy[2],rrr);
theta= 0.0;
dtheta= two_pi/20;
/*** Don't bother with circles just yet ***/
for (iii=0; iii<20; iii++)
{
idraw++;
sprintf(current_atom.label,"%s%d","H",idraw);
theta += dtheta;
current_atom.x= p_win_geom->centre[iwin][0]
+ p_win_geom->r_vec[iwin][0]* sin(theta)
+ rrr*yyy[0]*cos(theta);
current_atom.y= p_win_geom->centre[iwin][1]
+ p_win_geom->r_vec[iwin][1]* sin(theta)
+ rrr*yyy[1]*cos(theta);
current_atom.z= p_win_geom->centre[iwin][2]
+ p_win_geom->r_vec[iwin][2]* sin(theta)
+ rrr*yyy[2]*cos(theta);
write_atom_data(fp, ¤t_atom, scale_factor, p_this_fix );
}
printf("All done for window %d\n",iwin);
}
}
}
}
}
}
else
{
mol_current=0;
p_atom=p_molecule;
p_this_fix= p_fix_flags;
for (this_atom=0; this_atom < num_atoms; this_atom++)
{
if (*(p_mol_number+this_atom) != mol_current)
{
mol_current++;
fprintf(fp, "end\n");
}
write_atom_data(fp, p_atom, scale_factor, p_this_fix );
p_this_fix++;
p_atom++;
}
}
fprintf(fp, "end\nend\n");
return;
}