1 |
#include<stdio.h> |
2 |
#include<string.h> |
3 |
#include<stdlib.h> |
4 |
#include<math.h> |
5 |
#include<fftw.h> |
6 |
#include<mkl_lapack64.h> |
7 |
|
8 |
//extern void dsyev(char *jobz, char *uplo, int *n, double *a, int *lda, |
9 |
// double *w, double *work, int *lwork,int *info); |
10 |
|
11 |
//void direct(double rcut, double box, int n, int nstep, int maxbin); |
12 |
|
13 |
//double* dsyev_ctof(double **in, int rows, int cols); |
14 |
|
15 |
//void dsyev_ftoc2(double *in, double **out, int rows, int cols); |
16 |
|
17 |
// Structures to store our data: |
18 |
|
19 |
inline double roundMe( double x ){ |
20 |
return ( x >= 0 ) ? floor( x + 0.5 ) : ceil( x - 0.5 ); |
21 |
} |
22 |
inline double min( double a, double b ){ |
23 |
return (a < b ) ? a : b; |
24 |
} |
25 |
inline double max( double a, double b ){ |
26 |
return (a > b ) ? a : b; |
27 |
} |
28 |
|
29 |
|
30 |
// coords holds the data for a single tethered dipole: |
31 |
struct coords{ |
32 |
double pos[3]; // cartesian coords |
33 |
double theta; // orientational angle relative to z axis |
34 |
double phi; // orientational angle in x-y plane |
35 |
double mu; // dipole strength |
36 |
char name[30]; // an identifier for the type of atom |
37 |
}; |
38 |
|
39 |
// state holds the current "configuration" of the entire system |
40 |
struct system { |
41 |
int nAtoms; // Number of Atoms in this configuration |
42 |
struct coords *r; // The set of coordinates for all atoms |
43 |
double beta; // beta = 1 /(kb*T) |
44 |
double strength; // strength of the dipoles (Debye) |
45 |
double z0; // default z axis position |
46 |
double theta0; // default theta angle |
47 |
double kz; // force constant for z displacement |
48 |
double ktheta; // force constant for theta displacement |
49 |
int nCycles; // How many cycles to do in total |
50 |
int iCycle; // How many cycles have we done? |
51 |
int nMoves; // How many MC moves in each cycle |
52 |
int nSample; // How many cycles between samples |
53 |
double Hmat[2][2]; // The information about the size of the per. box |
54 |
double HmatI[2][2]; // The inverse box |
55 |
double energy; // The current Energy |
56 |
double dtheta; // maximum size of a theta move |
57 |
double deltaz; // maximum size of a z move |
58 |
double deltaphi; // maximum size of a phi move |
59 |
int nAttempts; // number of MC moves that have been attempted |
60 |
int nAccepts; // number of MC moves that have been accepted |
61 |
int nx; // number of unit cells in x direction |
62 |
int ny; // number of unit cells in y direction |
63 |
struct system *next; // Next frame in the linked list |
64 |
}; |
65 |
|
66 |
char *program_name; /* the name of the program */ |
67 |
|
68 |
// Function prototypes: |
69 |
void usage(void); |
70 |
void invertMat2(double a[2][2], double b[2][2]); |
71 |
void wrapVector( double thePos[2], double Hmat[2][2], double HmatI[2][2]); |
72 |
|
73 |
int main(argc, argv) |
74 |
int argc; |
75 |
char *argv[]; |
76 |
{ |
77 |
FILE *in_file; |
78 |
char in_name[500]; |
79 |
char *eof_test, *foo; |
80 |
char read_buffer[1000]; |
81 |
//int lineCount = 0; |
82 |
int lineCount; |
83 |
int nAtoms; |
84 |
double *mag, *newmag; |
85 |
int *present_in_old; |
86 |
double *ux, *uy, *uz, p1; |
87 |
double aLat, bLat; |
88 |
int cells; |
89 |
double sumZ, sumUx, sumUy, sumUz, sumP; |
90 |
double interpsum, value; |
91 |
int ninterp, px, py, newp; |
92 |
int i, j, k, l, nloops; |
93 |
int newx, newy, newindex, index; |
94 |
int new_i, new_j, new_index; |
95 |
int N, nframes; |
96 |
double freq_x, freq_y, zero_freq_x, zero_freq_y, freq; |
97 |
double maxfreqx, maxfreqy, maxfreq, dfreq; |
98 |
double dx, dy, dx1, dy1, xTemp, yTemp, pt1x, pt1y, pt2x, pt2y; |
99 |
int nx, ny; |
100 |
int *samples; |
101 |
double *bin, binmin, binmax, delr; |
102 |
double *x, *y, *z; |
103 |
double dh2, dh, sumh2, sumh, averh2, averh, t, delta, gamma, hi, proj; |
104 |
double *corrhist, *h2hist; |
105 |
double vrhist[1000]; |
106 |
double sum_vrhist[1000]; |
107 |
int vrsamp[1000]; |
108 |
int *ophist; |
109 |
double d[2], hcorr; |
110 |
double hsum, hsum_frame, h2sum, have, h2ave, h_ave_frame; |
111 |
double fluc, bigL, smallA, areaPerMolecule, area, h, h2; |
112 |
int nbins, nbins2, opbin, whichbinx, whichbiny, whichbin2, n1, n2, n3, n4, m, selfx, selfy; |
113 |
|
114 |
int which; |
115 |
int highestAtom; |
116 |
double highestZ; |
117 |
double omat[3][3]; |
118 |
double myPerp[3]; |
119 |
double myDir[3]; |
120 |
double myVec[2]; |
121 |
double lperp; |
122 |
double ldir; |
123 |
double dot; |
124 |
double maxProj, maxProjOut; |
125 |
double avgHeightAtProj; |
126 |
double wrapMat[9]; |
127 |
double onethird, ordvals[5000]; |
128 |
double maxEval; |
129 |
double director[3][1000], vr[3][1000]; |
130 |
double sum_director[3], ave_director[3], sum_vr[3], ave_vr[3]; |
131 |
double orderpar[1000]; |
132 |
double sum_orderpar, sum2_orderpar, ave_orderpar, ave2_orderpar, err_orderpar; |
133 |
char job, uplo; |
134 |
int ndiag; |
135 |
int nfilled; |
136 |
double evals[100]; |
137 |
int lwork; |
138 |
double* work; |
139 |
int ifail; |
140 |
int done, lastData, firstData; |
141 |
char current_flag; |
142 |
|
143 |
lineCount = 0; |
144 |
|
145 |
program_name = argv[0]; |
146 |
if (argc >= 2) |
147 |
strcpy(in_name, argv[1]); |
148 |
/* |
149 |
for(i = 1; i < argc; i++){ |
150 |
if(argv[i][0] == '-'){ |
151 |
done = 0; |
152 |
j = 1; |
153 |
current_flag = argv[i][j]; |
154 |
while( (current_flag != '\0') && ( !done ) ){ |
155 |
switch(current_flag){ |
156 |
case 'i': |
157 |
i++; |
158 |
strcpy( in_name, argv[i] ); |
159 |
done = 1; |
160 |
break; |
161 |
} |
162 |
} |
163 |
} |
164 |
} |
165 |
*/ |
166 |
|
167 |
struct system* state; |
168 |
struct system* temp_state; |
169 |
struct coords* r; |
170 |
|
171 |
lwork = 9; |
172 |
|
173 |
work = (double *) malloc(lwork * sizeof(double)); |
174 |
|
175 |
onethird = 1.0 / 3.0; |
176 |
ndiag = 3; |
177 |
nfilled = 3; |
178 |
job = 'V'; |
179 |
uplo = 'U'; |
180 |
ifail = 0; |
181 |
|
182 |
nbins = 30; |
183 |
nbins2 = 100; |
184 |
binmin = 0.0; |
185 |
binmax = 1.0; |
186 |
delr = (binmax - binmin) / (double) nbins2; |
187 |
corrhist = (double *) calloc(nbins*nbins, sizeof(double)); |
188 |
h2hist = (double *) calloc(nbins*nbins, sizeof(double)); |
189 |
ophist = (int *) calloc(nbins2, sizeof(int)); |
190 |
hsum = 0.0; |
191 |
h2sum = 0.0; |
192 |
sum_orderpar = 0.0; |
193 |
sum2_orderpar = 0.0; |
194 |
ave_orderpar = 0.0; |
195 |
ave2_orderpar = 0.0; |
196 |
|
197 |
for(i = 0; i < 3; i++){ |
198 |
for(j = 0; j < 1000; j++){ |
199 |
director[i][j] = 0.0; |
200 |
vr[i][j] = 0.0; |
201 |
} |
202 |
} |
203 |
|
204 |
for(i = 0; i < 1000; i++){ |
205 |
sum_vrhist[i] = 0.0; |
206 |
} |
207 |
|
208 |
for(i = 0; i < 3; i++){ |
209 |
sum_director[i] = 0.0; |
210 |
ave_director[i] = 0.0; |
211 |
sum_vr[i] = 0.0; |
212 |
ave_vr[i] = 0.0; |
213 |
} |
214 |
|
215 |
for (i = 0; i < nbins; i++) { |
216 |
for (j = 0; j < nbins; j++) { |
217 |
corrhist[nbins * i + j] = 0.0; |
218 |
h2hist[nbins * i + j] = 0.0; |
219 |
} |
220 |
} |
221 |
|
222 |
for (i = 0; i < 1000; i++) { |
223 |
vrhist[i] = 0.0; |
224 |
} |
225 |
|
226 |
for(i = 0; i < nbins2; i++){ |
227 |
ophist[i] = 0; |
228 |
} |
229 |
|
230 |
t = 300; |
231 |
|
232 |
in_file = fopen(in_name, "r"); |
233 |
if(in_file == NULL){ |
234 |
printf("Cannot open file \"%s\" for reading.\n", in_name); |
235 |
exit(8); |
236 |
} |
237 |
|
238 |
nframes = 0; |
239 |
n1 = 0; |
240 |
n2 = 0; |
241 |
n3 = 0; |
242 |
n4 = 0; |
243 |
|
244 |
// start reading the first frame |
245 |
|
246 |
eof_test = fgets(read_buffer, sizeof(read_buffer), in_file); |
247 |
nAtoms = atoi(read_buffer); |
248 |
ux = (double *) calloc(nAtoms, sizeof(double)); |
249 |
uy = (double *) calloc(nAtoms, sizeof(double)); |
250 |
uz = (double *) calloc(nAtoms, sizeof(double)); |
251 |
lineCount++; |
252 |
|
253 |
for(i = 0; i < nAtoms; i++){ |
254 |
ux[i] = 0.0; |
255 |
uy[i] = 0.0; |
256 |
uz[i] = 0.0; |
257 |
} |
258 |
|
259 |
state = (struct system *) malloc(sizeof(struct system)); |
260 |
state->next = NULL; |
261 |
state->strength = 7.0; |
262 |
|
263 |
while(eof_test != NULL){ |
264 |
|
265 |
highestAtom = -1; |
266 |
highestZ = 0.0; |
267 |
|
268 |
nframes++; |
269 |
(void)sscanf(read_buffer, "%d", &state->nAtoms); |
270 |
N = 2 * state->nAtoms; |
271 |
|
272 |
state->r = (struct coords *)calloc(N, sizeof(struct coords)); |
273 |
|
274 |
for(i = 0; i < 3; i++){ |
275 |
for(j = 0; j < 3; j++){ |
276 |
omat[i][j] = 0.0; |
277 |
} |
278 |
} |
279 |
|
280 |
// read and the comment line and grab the time and box dimensions |
281 |
|
282 |
eof_test = fgets(read_buffer, sizeof(read_buffer), in_file); |
283 |
lineCount++; |
284 |
if(eof_test == NULL){ |
285 |
printf("error in reading file at line: %d\n", lineCount); |
286 |
exit(8); |
287 |
} |
288 |
|
289 |
foo = strtok( read_buffer, " ,;\t\n" ); |
290 |
(void)sscanf( read_buffer, "%d", &state->iCycle ); |
291 |
|
292 |
foo = strtok(NULL, " ,;\t\0"); |
293 |
if(foo == NULL){ |
294 |
printf("error in reading file at line: %d\n", lineCount); |
295 |
exit(8); |
296 |
} |
297 |
(void)sscanf(foo, "%d", &state->nx); |
298 |
|
299 |
nx = state->nx; |
300 |
|
301 |
foo = strtok(NULL, " ,;\t\0"); |
302 |
if(foo == NULL){ |
303 |
printf("error in reading file at line: %d\n", lineCount); |
304 |
exit(8); |
305 |
} |
306 |
(void)sscanf(foo, "%d", &state->ny); |
307 |
|
308 |
ny = state->ny; |
309 |
|
310 |
foo = strtok(NULL, " ,;\t\0"); |
311 |
if(foo == NULL){ |
312 |
printf("error in reading file at line: %d\n", lineCount); |
313 |
exit(8); |
314 |
} |
315 |
(void)sscanf(foo, "%lf",&state->Hmat[0][0]); |
316 |
|
317 |
foo = strtok(NULL, " ,;\t\0"); |
318 |
if(foo == NULL){ |
319 |
printf("error in reading file at line: %d\n", lineCount); |
320 |
exit(8); |
321 |
} |
322 |
(void)sscanf(foo, "%lf",&state->Hmat[1][0]); |
323 |
|
324 |
foo = strtok(NULL, " ,;\t\0"); |
325 |
if(foo == NULL){ |
326 |
printf("error in reading file at line: %d\n", lineCount); |
327 |
exit(8); |
328 |
} |
329 |
(void)sscanf(foo, "%lf",&state->Hmat[0][1]); |
330 |
|
331 |
foo = strtok(NULL, " ,;\t\0"); |
332 |
if(foo == NULL){ |
333 |
printf("error in reading file at line: %d\n", lineCount); |
334 |
exit(8); |
335 |
} |
336 |
(void)sscanf(foo, "%lf",&state->Hmat[1][1]); |
337 |
|
338 |
//Find HmatI: |
339 |
|
340 |
invertMat2(state->Hmat, state->HmatI); |
341 |
|
342 |
// Length of the two box vectors: |
343 |
|
344 |
dx = sqrt(pow(state->Hmat[0][0], 2) + pow(state->Hmat[1][0], 2)); |
345 |
dy = sqrt(pow(state->Hmat[0][1], 2) + pow(state->Hmat[1][1], 2)); |
346 |
|
347 |
aLat = dx / (double)(state->nx); |
348 |
bLat = dy / (double)(state->ny); |
349 |
|
350 |
// FFT stuff depends on nx and ny, so delay allocation until we have |
351 |
// that information |
352 |
|
353 |
for (i=0;i<state->nAtoms;i++){ |
354 |
|
355 |
eof_test = fgets(read_buffer, sizeof(read_buffer), in_file); |
356 |
lineCount++; |
357 |
if(eof_test == NULL){ |
358 |
printf("error in reading file at line: %d\n", lineCount); |
359 |
exit(8); |
360 |
} |
361 |
|
362 |
foo = strtok(read_buffer, " ,;\t\0"); |
363 |
(void)strcpy(state->r[i].name, foo); //copy the atom name |
364 |
|
365 |
// next we grab the positions |
366 |
|
367 |
foo = strtok(NULL, " ,;\t\0"); |
368 |
if(foo == NULL){ |
369 |
printf("error in reading postition x from %s\n" |
370 |
"natoms = %d, line = %d\n", |
371 |
in_name, state->nAtoms, lineCount ); |
372 |
exit(8); |
373 |
} |
374 |
(void)sscanf( foo, "%lf", &state->r[i].pos[0] ); |
375 |
|
376 |
foo = strtok(NULL, " ,;\t\0"); |
377 |
if(foo == NULL){ |
378 |
printf("error in reading postition y from %s\n" |
379 |
"natoms = %d, line = %d\n", |
380 |
in_name, state->nAtoms, lineCount ); |
381 |
exit(8); |
382 |
} |
383 |
(void)sscanf( foo, "%lf", &state->r[i].pos[1] ); |
384 |
|
385 |
foo = strtok(NULL, " ,;\t\0"); |
386 |
if(foo == NULL){ |
387 |
printf("error in reading postition z from %s\n" |
388 |
"natoms = %d, line = %d\n", |
389 |
in_name, state->nAtoms, lineCount ); |
390 |
exit(8); |
391 |
} |
392 |
(void)sscanf( foo, "%lf", &state->r[i].pos[2] ); |
393 |
if (state->r[i].pos[2] > highestZ) { |
394 |
highestAtom = i; |
395 |
highestZ = state->r[i].pos[2]; |
396 |
} |
397 |
|
398 |
foo = strtok(NULL, " ,;\t\0"); |
399 |
if(foo == NULL){ |
400 |
printf("error in reading angle phi from %s\n" |
401 |
"natoms = %d, line = %d\n", |
402 |
in_name, state->nAtoms, lineCount ); |
403 |
exit(8); |
404 |
} |
405 |
(void)sscanf( foo, "%lf", &state->r[i].phi ); |
406 |
|
407 |
foo = strtok(NULL, " ,;\t\0"); |
408 |
if(foo == NULL){ |
409 |
printf("error in reading unit vector x from %s\n" |
410 |
"natoms = %d, line = %d\n", |
411 |
in_name, state->nAtoms, lineCount ); |
412 |
exit(8); |
413 |
} |
414 |
(void)sscanf( foo, "%lf", &ux[i] ); |
415 |
|
416 |
foo = strtok(NULL, " ,;\t\0"); |
417 |
if(foo == NULL){ |
418 |
printf("error in reading unit vector y from %s\n" |
419 |
"natoms = %d, line = %d\n", |
420 |
in_name, state->nAtoms, lineCount ); |
421 |
exit(8); |
422 |
} |
423 |
(void)sscanf( foo, "%lf", &uy[i] ); |
424 |
|
425 |
foo = strtok(NULL, " ,;\t\0"); |
426 |
if(foo == NULL){ |
427 |
printf("error in reading unit vector z from %s\n" |
428 |
"natoms = %d, line = %d\n", |
429 |
in_name, state->nAtoms, lineCount ); |
430 |
exit(8); |
431 |
} |
432 |
(void)sscanf( foo, "%lf", &uz[i] ); |
433 |
|
434 |
state->r[i].theta = acos(uz[i]); |
435 |
|
436 |
// The one parameter not stored in the dump file is the dipole strength |
437 |
state->r[i].mu = state->strength; |
438 |
} |
439 |
|
440 |
hsum_frame = 0.0; |
441 |
for (i = 0; i < state->nAtoms; i++) { |
442 |
|
443 |
h = state->r[i].pos[2]; |
444 |
h2 = pow(h,2); |
445 |
|
446 |
hsum_frame += h; |
447 |
hsum += h; |
448 |
h2sum += h2; |
449 |
|
450 |
n1++; |
451 |
} |
452 |
|
453 |
h_ave_frame = hsum_frame / (double) state->nAtoms; |
454 |
|
455 |
for(i = 0; i < state->nAtoms; i++){ |
456 |
|
457 |
omat[0][0] += ux[i] * ux[i] - onethird; |
458 |
omat[0][1] += ux[i] * uy[i]; |
459 |
omat[0][2] += ux[i] * uz[i]; |
460 |
omat[1][0] += uy[i] * ux[i]; |
461 |
omat[1][1] += uy[i] * uy[i] - onethird; |
462 |
omat[1][2] += uy[i] * uz[i]; |
463 |
omat[2][0] += uz[i] * ux[i]; |
464 |
omat[2][1] += uz[i] * uy[i]; |
465 |
omat[2][2] += uz[i] * uz[i] - onethird; |
466 |
|
467 |
} |
468 |
|
469 |
for(i = 0; i < 3; i++){ |
470 |
for(j = 0; j < 3; j++){ |
471 |
omat[i][j] /= (double) state->nAtoms; |
472 |
} |
473 |
} |
474 |
|
475 |
// temp_array = dsyev_ctof(omat, nfilled, nfilled); |
476 |
|
477 |
for(j=0;j<3;j++) |
478 |
for(i=0;i<3;i++) |
479 |
wrapMat[i+j*3] = omat[i][j]; |
480 |
|
481 |
ifail = 0; |
482 |
dsyev(&job, &uplo, &nfilled, wrapMat, &ndiag, evals, work, &lwork, &ifail); |
483 |
|
484 |
for(j=0;j<3;j++) |
485 |
for(i=0;i<3;i++) |
486 |
omat[i][j] = wrapMat[i+j*3]; |
487 |
|
488 |
//dsyev_ftoc2(temp_array, omat, nfilled, nfilled); |
489 |
|
490 |
//free(temp_array); |
491 |
|
492 |
maxEval = 0.0; |
493 |
for(j = 0; j < 3; j++){ |
494 |
if(fabs(evals[j]) > maxEval){ |
495 |
which = j; |
496 |
maxEval = fabs(evals[j]); |
497 |
} |
498 |
} |
499 |
|
500 |
orderpar[nframes-1] = 1.5 * maxEval; |
501 |
opbin = (int) (orderpar[nframes-1] / delr); |
502 |
if(opbin < nbins2) ophist[opbin] += 1; |
503 |
|
504 |
for(i = 0; i < 3; i++){ |
505 |
myDir[i] = 0.0; |
506 |
myPerp[i] = 0.0; |
507 |
} |
508 |
|
509 |
myDir[0] = omat[0][which]; |
510 |
myDir[1] = omat[1][which]; |
511 |
myDir[2] = omat[2][which]; |
512 |
|
513 |
if (myDir[0] < 0.0) { |
514 |
myDir[0] = -myDir[0]; |
515 |
myDir[1] = -myDir[1]; |
516 |
} |
517 |
|
518 |
ldir = sqrt(myDir[0]*myDir[0] + myDir[1]*myDir[1] + myDir[2]*myDir[2]); |
519 |
|
520 |
myDir[0] /= ldir; |
521 |
myDir[1] /= ldir; |
522 |
myDir[2] /= ldir; |
523 |
|
524 |
//printf("%f\t%f\t%f\n", myDir[0], myDir[1], myDir[2]); |
525 |
|
526 |
director[0][nframes-1] = myDir[0]; |
527 |
director[1][nframes-1] = myDir[1]; |
528 |
director[2][nframes-1] = myDir[2]; |
529 |
|
530 |
//printf("%f\t%f\t%f\n", director[0][nframes-1], director[1][nframes-1], director[2][nframes-1]); |
531 |
|
532 |
myPerp[0] = myDir[1]; |
533 |
myPerp[1] = -myDir[0]; |
534 |
myPerp[2] = 0.0; |
535 |
|
536 |
if (myPerp[0] < 0.0) { |
537 |
myPerp[0] = -myPerp[0]; |
538 |
myPerp[1] = -myPerp[1]; |
539 |
} |
540 |
|
541 |
lperp = sqrt(myPerp[0]*myPerp[0] + myPerp[1]*myPerp[1] + myPerp[2]*myPerp[2]); |
542 |
|
543 |
myPerp[0] /= lperp; |
544 |
myPerp[1] /= lperp; |
545 |
myPerp[2] /= lperp; |
546 |
|
547 |
vr[0][nframes-1] = myPerp[0]; |
548 |
vr[1][nframes-1] = myPerp[1]; |
549 |
vr[2][nframes-1] = myPerp[2]; |
550 |
|
551 |
maxProj = 0.5 * sqrt(dx*dx + dy*dy); |
552 |
//maxProj = myPerp[0]*dx + myPerp[1]*dy; |
553 |
// for now, assume highest atom is atom 0 |
554 |
highestAtom = 0; |
555 |
|
556 |
for(i = 0; i < state->nAtoms; i++){ |
557 |
|
558 |
// difference vector from highest point: |
559 |
myVec[0] = state->r[i].pos[0] - state->r[highestAtom].pos[0]; |
560 |
myVec[1] = state->r[i].pos[1] - state->r[highestAtom].pos[1]; |
561 |
// wrapped in periodic boundary conditions: |
562 |
wrapVector(myVec, state->Hmat, state->HmatI); |
563 |
|
564 |
// then projected onto myPerp: |
565 |
proj = myPerp[0]*myVec[0] + myPerp[1]*myVec[1]; |
566 |
// and binned: |
567 |
|
568 |
whichbin2 = (int) (((1.0 + (proj/maxProj)) / 2.0) * (double) nbins2); |
569 |
// printf( "proj/maxProj = %f\twhichbin2 = %d\n", proj/maxProj, whichbin2); |
570 |
|
571 |
hi = state->r[i].pos[2] - h_ave_frame; |
572 |
// for(i = 0; i < nbins2; i++) printf("%f\t%d\n", vrhist[i], vrsamp[i]); |
573 |
vrhist[whichbin2] += hi; |
574 |
vrsamp[whichbin2] ++; |
575 |
} |
576 |
|
577 |
for(i = 0; i < state->nAtoms; i++){ |
578 |
for(j = 0; j < state->nAtoms; j++){ |
579 |
|
580 |
d[0] = state->r[j].pos[0] - state->r[i].pos[0]; |
581 |
d[1] = state->r[j].pos[1] - state->r[i].pos[1]; |
582 |
|
583 |
wrapVector(d, state->Hmat, state->HmatI); |
584 |
|
585 |
whichbinx = (int) ((nbins-1) * (dx/2.0 + d[0]) / dx); |
586 |
whichbiny = (int) ((nbins-1) * (dy/2.0 + d[1]) / dy); |
587 |
|
588 |
//if (i == j) { |
589 |
//printf("whichbinx = %i, whichbiny = %i\n", whichbinx, whichbiny); |
590 |
//} |
591 |
|
592 |
//printf("d0 = %lf, d1 = %lf\n", d[0], d[1]); |
593 |
//printf("wx = %d, wy = %d\n", whichbinx, whichbiny); |
594 |
|
595 |
if (whichbinx >= nbins || whichbiny >= nbins) { |
596 |
printf("off by one error\n"); |
597 |
printf("whichbinx = %i, whichbiny = %i\n", whichbinx, whichbiny); |
598 |
exit(0); |
599 |
} |
600 |
if (whichbinx < 0 || whichbiny < 0) { |
601 |
printf("off by one error\n"); |
602 |
printf("whichbinx = %i, whichbiny = %i\n", whichbinx, whichbiny); |
603 |
exit(0); |
604 |
} |
605 |
|
606 |
hcorr = state->r[j].pos[2] * state->r[i].pos[2]; |
607 |
|
608 |
corrhist[nbins * whichbinx + whichbiny] += hcorr; |
609 |
|
610 |
dh = state->r[j].pos[2] - state->r[i].pos[2]; |
611 |
dh2 = pow(dh, 2); |
612 |
|
613 |
h2hist[nbins * whichbinx + whichbiny] += dh2; |
614 |
|
615 |
n2++; |
616 |
} |
617 |
} |
618 |
|
619 |
temp_state = state->next; |
620 |
state->next = NULL; |
621 |
|
622 |
if (temp_state != NULL) { |
623 |
free(temp_state->r); |
624 |
free(temp_state); |
625 |
} |
626 |
|
627 |
// Make a new frame |
628 |
|
629 |
temp_state = (struct system *) malloc(sizeof(struct system)); |
630 |
temp_state->next = state; |
631 |
state = temp_state; |
632 |
eof_test = fgets(read_buffer, sizeof(read_buffer), in_file); |
633 |
lineCount++; |
634 |
} |
635 |
|
636 |
|
637 |
have = hsum / (double) n1; |
638 |
h2ave = h2sum / (double) n1; |
639 |
fluc = h2ave - pow(have, 2); |
640 |
|
641 |
printf("# <h> = %lf\n", have); |
642 |
printf("# <h2> = %lf\n", h2ave); |
643 |
printf("# sigma(h) = %lf\n", sqrt(h2ave - have * have)); |
644 |
printf("# fluctuation = %lf\n", fluc); |
645 |
|
646 |
for(i = 0; i < nframes; i++){ |
647 |
sum_orderpar += orderpar[i]; |
648 |
sum2_orderpar += pow(orderpar[i], 2); |
649 |
} |
650 |
ave_orderpar = sum_orderpar / (double) nframes; |
651 |
ave2_orderpar = sum2_orderpar / (double) nframes; |
652 |
err_orderpar = ave2_orderpar - pow(ave_orderpar, 2); |
653 |
|
654 |
for(i = 0; i < 3; i++){ |
655 |
sum_director[i] = 0.0; |
656 |
ave_director[i] = 0.0; |
657 |
sum_vr[i] = 0.0; |
658 |
ave_vr[i] = 0.0; |
659 |
} |
660 |
|
661 |
for(i = 0; i < nframes; i++){ |
662 |
sum_director[0] += director[0][i]; |
663 |
sum_director[1] += director[1][i]; |
664 |
sum_director[2] += director[2][i]; |
665 |
} |
666 |
ave_director[0] = sum_director[0] / (double) nframes; |
667 |
ave_director[1] = sum_director[1] / (double) nframes; |
668 |
ave_director[2] = sum_director[2] / (double) nframes; |
669 |
|
670 |
for(i = 0; i < nframes; i++){ |
671 |
sum_vr[0] += vr[0][i]; |
672 |
sum_vr[1] += vr[1][i]; |
673 |
sum_vr[2] += vr[2][i]; |
674 |
} |
675 |
ave_vr[0] = sum_vr[0] / (double) nframes; |
676 |
ave_vr[1] = sum_vr[1] / (double) nframes; |
677 |
ave_vr[2] = sum_vr[2] / (double) nframes; |
678 |
|
679 |
printf("# orderparameter = %lf\n", ave_orderpar); |
680 |
printf("# error = %lf\n", err_orderpar); |
681 |
printf("# director axis is ( %lf\t%lf\t%lf )\n", |
682 |
ave_director[0], ave_director[1], ave_director[2]); |
683 |
printf("# vr axis is ( %lf\t%lf\t%lf )\n", ave_vr[0], ave_vr[1], ave_vr[2]); |
684 |
|
685 |
dx = sqrt(pow(state->Hmat[0][0], 2) + pow(state->Hmat[1][0], 2)); |
686 |
dy = sqrt(pow(state->Hmat[0][1], 2) + pow(state->Hmat[1][1], 2)); |
687 |
|
688 |
area = dx * dy; |
689 |
|
690 |
bigL = sqrt(area); |
691 |
|
692 |
areaPerMolecule = area / (double) state->nAtoms; |
693 |
|
694 |
smallA = sqrt(areaPerMolecule); |
695 |
|
696 |
gamma = t * log(bigL / smallA) / (2.0 * M_PI * fluc); |
697 |
|
698 |
printf("# first gamma estimate = %lf\n", gamma); |
699 |
|
700 |
firstData = -1; |
701 |
lastData = -1; |
702 |
|
703 |
for (i=0; i< nbins2; i++) { |
704 |
if (vrsamp[i] > 0) { |
705 |
if (firstData == -1) firstData = i; |
706 |
lastData = i; |
707 |
} |
708 |
} |
709 |
|
710 |
maxProj = 0.5*sqrt(dx*dx + dy*dy); |
711 |
maxProjOut = 2.0*maxProj*(double)(lastData - firstData)/(double)nbins2; |
712 |
|
713 |
printf("# maximum projection = %lf\n", maxProjOut); |
714 |
printf("# \n"); |
715 |
|
716 |
for (i = firstData ; i < lastData; i++) { |
717 |
//proj = maxProj * ((double)i / (double)nbins2); |
718 |
|
719 |
proj = maxProj*( (2.0 * (double)i / (double)nbins2) -1.0); |
720 |
|
721 |
if (vrsamp[i] > 0) { |
722 |
avgHeightAtProj = vrhist[i]/(double)vrsamp[i]; |
723 |
} else { |
724 |
avgHeightAtProj = 0.0; |
725 |
} |
726 |
printf("%lf\t%lf\n", proj, avgHeightAtProj); |
727 |
} |
728 |
|
729 |
selfx = (int) ((double)nbins / 2.0); |
730 |
selfy = (int) ((double)nbins / 2.0); |
731 |
|
732 |
/* for (i = 0; i < nbins; i++) { */ |
733 |
/* for (j = 0; j < nbins; j++) { */ |
734 |
/* printf("%lf\t", h2hist[nbins * i + j] / (double) n2); */ |
735 |
/* } */ |
736 |
/* printf("\n"); */ |
737 |
/* } */ |
738 |
|
739 |
free(work); |
740 |
free(corrhist); |
741 |
free(h2hist); |
742 |
free(ux); |
743 |
free(uy); |
744 |
free(uz); |
745 |
return 1; |
746 |
|
747 |
} |
748 |
|
749 |
double matDet2(double a[2][2]) { |
750 |
|
751 |
double determinant; |
752 |
|
753 |
determinant = (a[0][0] * a[1][1]) - (a[0][1] * a[1][0]); |
754 |
|
755 |
return determinant; |
756 |
} |
757 |
|
758 |
|
759 |
void invertMat2(double a[2][2], double b[2][2]) { |
760 |
|
761 |
double determinant; |
762 |
|
763 |
determinant = matDet2( a ); |
764 |
|
765 |
if (determinant == 0.0) { |
766 |
printf("Can't invert a matrix with a zero determinant!\n"); |
767 |
} |
768 |
|
769 |
b[0][0] = a[1][1] / determinant; |
770 |
b[0][1] = -a[0][1] / determinant; |
771 |
b[1][0] = -a[1][0] / determinant; |
772 |
b[1][1] = a[0][0] / determinant; |
773 |
} |
774 |
|
775 |
void matVecMul2(double m[2][2], double inVec[2], double outVec[2]) { |
776 |
double a0, a1, a2; |
777 |
|
778 |
a0 = inVec[0]; a1 = inVec[1]; |
779 |
|
780 |
outVec[0] = m[0][0]*a0 + m[0][1]*a1; |
781 |
outVec[1] = m[1][0]*a0 + m[1][1]*a1; |
782 |
} |
783 |
|
784 |
void wrapVector( double thePos[2], double Hmat[2][2], double HmatInv[2][2]){ |
785 |
|
786 |
int i; |
787 |
double scaled[2]; |
788 |
|
789 |
// calc the scaled coordinates. |
790 |
|
791 |
matVecMul2(HmatInv, thePos, scaled); |
792 |
|
793 |
for(i=0; i<2; i++) |
794 |
scaled[i] -= roundMe(scaled[i]); |
795 |
|
796 |
// calc the wrapped real coordinates from the wrapped scaled coordinates |
797 |
|
798 |
matVecMul2(Hmat, scaled, thePos); |
799 |
|
800 |
} |
801 |
|
802 |
/* double* dsyev_ctof(double **in, int rows, int cols) */ |
803 |
/* { */ |
804 |
/* double *out; */ |
805 |
/* int i, j; */ |
806 |
|
807 |
/* out = (double *) calloc(rows * cols, sizeof(double)); */ |
808 |
|
809 |
/* if (!out){ */ |
810 |
/* printf("Fail to allocate memory\n"); */ |
811 |
/* exit(1); */ |
812 |
/* } */ |
813 |
|
814 |
/* for (i = 0; i < rows; i++) */ |
815 |
/* for (j = 0; j < cols; j++) */ |
816 |
/* out[i+j*cols] = in[i][j]; */ |
817 |
|
818 |
/* return(out); */ |
819 |
/* } */ |
820 |
|
821 |
/* void dsyev_ftoc2(double *in, double **out, int rows, int cols) */ |
822 |
/* { */ |
823 |
/* int i, j; */ |
824 |
|
825 |
/* for (i = 0; i < rows; i++) */ |
826 |
/* for (j = 0; j < cols; j++) */ |
827 |
/* out[i][j] = in[i+j*cols]; */ |
828 |
/* } */ |
829 |
/* void direct(double rcut, double box, int n, int nstep, int maxbin){ */ |
830 |
|
831 |
/* int bin, maxbin, nbins, i, j, k, n, bind, which; */ |
832 |
/* int hist[maxbin], histd[maxbin], startstep; */ |
833 |
/* int nstep, stopstep, ndiag, nfilled, ifail, lwork; */ |
834 |
/* double delr, rijsp, rxij, ryij, rzij, rij; */ |
835 |
/* double delrd, rijsqd, rijd, orderpar[1000], nideal; */ |
836 |
/* double omat[3][3], evals[100], cons, rlower; */ |
837 |
/* double rcut, box, dens, director[3][1000], rupper; */ |
838 |
/* double rx[1000][1000], ry[1000][1000], rz[1000][1000]; */ |
839 |
/* double ux[1000][1000], uy[1000][1000], uz[1000][1000]; */ |
840 |
/* double vx[1000][1000], vy[1000][1000], vz[1000][1000]; */ |
841 |
/* double jx[1000][1000], jy[1000][1000], jz[1000][1000]; */ |
842 |
/* double grd[5000], gr[5000], max, binmin, binmax; */ |
843 |
/* double onethird, ordvals[5000]; */ |
844 |
/* char job, uplo; */ |
845 |
/* int ndiag; */ |
846 |
/* int nfilled; */ |
847 |
/* double omat[3][3]; */ |
848 |
/* double evals[100]; */ |
849 |
/* double work[]; */ |
850 |
/* int lwork; */ |
851 |
/* int ifail; */ |
852 |
|
853 |
/* lwork = 9; */ |
854 |
/* work = (double *)calloc(lwork, sizeof(double)); */ |
855 |
|
856 |
/* onethird = 1.0 / 3.0; */ |
857 |
/* ndiag = 3; */ |
858 |
/* nfilled = 3; */ |
859 |
/* job = 'V'; */ |
860 |
/* uplo = 'U'; */ |
861 |
/* ifail = 0; */ |
862 |
|
863 |
/* binmin = 0.0; */ |
864 |
/* binmax = 1.0; */ |
865 |
/* delr = (binmax - binmin) / (double) maxbin; */ |
866 |
|
867 |
/* for(i = 0; i < maxbin; i++){ */ |
868 |
|
869 |
/* ordvals(i) = 0.0; */ |
870 |
/* hist(i) = 0.0; */ |
871 |
|
872 |
/* } */ |
873 |
|
874 |
/* for(i = 0; i < stopstep; i++){ */ |
875 |
|
876 |
/* for(j = 0; j < 3; j++){ */ |
877 |
/* for(k = 0; k < 3; k++){ */ |
878 |
/* omat[j][k] = 0.0; */ |
879 |
/* } */ |
880 |
/* } */ |
881 |
|
882 |
/* for(j = 0; j < n; j++){ */ |
883 |
|
884 |
/* omat[1][1] = omat[1][1] + ux[j][i] * ux[j][i] - onethird; */ |
885 |
/* omat[1][2] = omat[1][2] + ux[j][i] * uy[j][i]; */ |
886 |
/* omat[1][3] = omat[1][3] + ux[j][i] * uz[j][i]; */ |
887 |
/* omat[2][1] = omat[2][1] + uy[j][i] * ux[j][i]; */ |
888 |
/* omat[2][2] = omat[2][2] + uy[j][i] * uy[j][i] - onethird; */ |
889 |
/* omat[2][3] = omat[2][3] + uy[j][i] * uz[j][i]; */ |
890 |
/* omat[3][1] = omat[3][1] + uz[j][i] * ux[j][i]; */ |
891 |
/* omat[3][2] = omat[3][2] + uz[j][i] * uy[j][i]; */ |
892 |
/* omat[3][3] = omat[3][3] + uz[j][i] * uz[j][i] - onethird; */ |
893 |
|
894 |
/* } */ |
895 |
|
896 |
|
897 |
/* for(j = 0; j < 3; j++){ */ |
898 |
/* for(k = 0; k < 3; k++){ */ |
899 |
/* omat[j][k] = omat[j][k] / (double) n; */ |
900 |
/* } */ |
901 |
/* } */ |
902 |
|
903 |
/* dsyev_(job, uplo, nfilled, omat, ndiag, evals, work, lwork, ifail); */ |
904 |
|
905 |
/* max = 0.0; */ |
906 |
/* for(j = 0; j < 3; j++){ */ |
907 |
/* if(fabs(evals(j)) > max){ */ |
908 |
/* which = j; */ |
909 |
/* max = fabs(evals(j)); */ |
910 |
/* } */ |
911 |
/* } */ |
912 |
|
913 |
/* director[1][i] = omat[1][which]; */ |
914 |
/* director[2][i] = omat[2][which]; */ |
915 |
/* director[3][i] = omat[3][which]; */ |
916 |
|
917 |
/* orderpar(i) = 1.5 * max; */ |
918 |
|
919 |
/* bin = (int) (orderpar(i) / delr) + 1; */ |
920 |
|
921 |
/* if(bin < maxbin) */ |
922 |
/* hist(bin) = hist(bin) + 1; */ |
923 |
/* } */ |
924 |
|
925 |
/* cons = 1.0; */ |
926 |
/* for(bin = 0; bin < maxbin; bin++){ */ |
927 |
|
928 |
/* rlower = (double) (bin - 1) * delr; */ |
929 |
/* rupper = rlower + delr; */ |
930 |
/* ordvals(bin) = rlower + (delr / 2.0); */ |
931 |
/* nideal = cons * (pow(rupper, 3) - pow(rlower, 3)); */ |
932 |
/* gr(bin) = (double) (hist(bin)) / (double) nstep /nideal; */ |
933 |
|
934 |
/* } */ |
935 |
/* } */ |