/* Calculate gr by choosing each monomer as origin and then average over sum of g_i(r), modified to read in multiple configurations. g(r) is defined as the par-pair correlation funcion between monomers belonging to different polymers*/ /* Algorithm written with the help of Allen & Tildesley, Dr. Duane Johnson, and Mr. Mark Dewing */ /* Yeng-Long Chen, Winter 1999 */ #define BUFFER 1 #define PI 3.14159 #include #include #include #include void gr(double *GR, double box, double rho, double Dr); void sk(double *SK, double *SK2, double Dk, double Kl); void unwrap(double box); double **matrix(int num, int size); void free_matrix(double **M, int num); double *dvector(int size); void error_exit(char *error_message); void adjust(double *dx, double *dy, double *dz, double box); double **X, **Y, **Z; int CN, chainl; /* CN = number of chains, chainl = #of monomers/chain */ void main() { int nconfig, nskip; int i, j, n, C, C_n, dummy; int bin, rbin, kbin, Kl; double box, rho, dummy2; double Dr, *GR, *sumGR; double Dk, *SK, *SK2, *sumSK, *sumSK2, errsq; char dummy1[10]; FILE *stream; nconfig = 1; /* Read in the configuration file that contains multiple configurations of polymer coordinates generated by cbmc */ if((stream = fopen("CONF.crd", "r"))!=NULL) { fscanf(stream, "%s", dummy1); fscanf(stream, "%s %d", dummy1, &nconfig); fscanf(stream, "%s %lf %lf %lf", dummy1, &box, &dummy2, &dummy2); fscanf(stream, "%s %lf %lf %lf", dummy1, &dummy2, &dummy2, &dummy2); /* Define the grid size of g(r) and s(k) */ Dr = 0.05; Kl = 20; Dk = 2*PI / 50; rbin = (int)(box/2/Dr) +1; kbin = (int)(Kl /Dk) +1; GR = dvector(rbin); sumGR = dvector(rbin); SK = dvector(kbin); SK2 = dvector(kbin); sumSK = dvector(kbin); sumSK2 = dvector(kbin); for(n=1; n<=nconfig; n++) { fscanf(stream, "%s %d %d", dummy1, &CN, &chainl); rho = (CN*chainl) / (box*box*box); printf("\nCN=%d chainl=%d box=%lf, rho=%lf, nconfig=%d", CN, chainl, box, rho, nconfig); X = matrix(CN, chainl); Y = matrix(CN, chainl); Z = matrix(CN, chainl); for(i=1; i<=CN; i++) for(j=1; j<=chainl; j++) fscanf(stream, "%lf %lf %lf", &X[i][j], &Y[i][j], &Z[i][j]); /* unwrap the periodic boundary conditions */ unwrap(box); /* find g(r) and s(k) of a given configuration */ gr(GR, box, rho, Dr); sk(SK, SK2, Dk, Kl); for(bin = 1; bin<= rbin; bin++) sumGR[bin] = sumGR[bin] + GR[bin]; for(bin = 1; bin<= kbin; bin++) { sumSK[bin] = sumSK[bin] + SK[bin]; sumSK2[bin] = sumSK2[bin] +SK2[bin]; } free_matrix(X, CN); free_matrix(Y, CN); free_matrix(Z, CN); } } else error_exit("Configuration File Not Found!"); fclose(stream); printf("\n"); /* Average over g(r) and s(k) of all configurations */ for(bin = 1; bin<=rbin; bin++) GR[bin] = sumGR[bin] / nconfig; for(bin = 1; bin<=kbin; bin++) { SK[bin] = sumSK[bin] / nconfig; SK2[bin] = sumSK2[bin] / nconfig; } stream = fopen("gr.dat", "w"); for(bin=1; bin hbox) X[i][j+1] = X[i][j+1] - box; if(dx < (-1*hbox)) X[i][j+1] = X[i][j+1] + box; if(dy > hbox) Y[i][j+1] = Y[i][j+1] - box; if(dy < (-1*hbox)) Y[i][j+1] = Y[i][j+1] + box; if(dz > hbox) Z[i][j+1] = Z[i][j+1] - box; if(dz < (-1* hbox)) Z[i][j+1] = Z[i][j+1] + box; } stream = fopen("newcord.dat", "w"); for(i=1; i<=CN; i++) for(j=1; j (box/2)) *dx = *dx - box; else if(*dx < (-box/2)) *dx = *dx + box; if(*dy > (box/2)) *dy = *dy - box; else if(*dy < (-box/2)) *dy = *dy + box; if(*dz > (box/2)) *dz = *dz - box; else if(*dz < (-box/2)) *dz = *dz + box; }