/* Radial distribution function calculation. Reads in an arbitrary number of configuration snapshots in XYZ format, and computes g(r). Cameron F. Abrams Written for the course CHE 800-002, Molecular Simulation Spring 0304 compile using "gcc -o rdf rdf.c -lm" Drexel University, Department of Chemical Engineering Philadelphia (c) 2004 */ #include #include #include /* Prints usage information */ void usage ( void ) { fprintf(stdout,"rdf usage:\n"); fprintf(stdout,"rdf [options]\n\n"); fprintf(stdout,"Options:\n"); fprintf(stdout,"\t -fnf [string]\t\tFile name format (%i.xyz)\n"); fprintf(stdout,"\t -for start,stop,step\t\tloop control\n"); fprintf(stdout,"\t -dr [real]\t\tRadial binsize (0.1)\n"); fprintf(stdout,"\t -rc [real]\t\tCutoff radius\n"); fprintf(stdout,"\t -rho [real]\t\tNumber density (0.85)\n"); fprintf(stdout,"\t -h \t\tPrint this info.\n"); } /* Reads in a configuration snapshot in XYZ format (such as that created by mdlj.c) */ int xyz_in (FILE * fp, double * rx, double * ry, double * rz, int * N) { int i; int has_vel, dum; double vx,vy,vz; fscanf(fp,"%i %i\n\n",N,&has_vel); for (i=0;i<(*N);i++) { fscanf(fp,"%i %lf %lf %lf ",&dum,&rx[i],&ry[i],&rz[i]); if (has_vel) fscanf(fp, "%lf %lf %lf\n",&vx,&vy,&vz); } return has_vel; } /* An N^2 algorithm for computing interparticle separations and updating the radial distribution function histogram. Implements parts of Algorithm 7 in F&S. */ void update_hist ( double * rx, double * ry, double * rz, int N, double L, double rc2, double dr, int * H ) { int i,j; double dx, dy, dz, r2; int bin; double hL = L/2; for (i=0;i<(N-1);i++) { for (j=i+1;jhL) dx-=L; else if (dx<-hL) dx+=L; if (dy>hL) dy-=L; else if (dy<-hL) dy+=L; if (dz>hL) dz-=L; else if (dz<-hL) dz+=L; r2 = dx*dx + dy*dy + dz*dz; if (r2L/2) { fprintf(stderr,"# Warning: the maximum radius you have requested," " %.5lf, is greater than one-half the box length, %.5lf\n", sqrt(rc2),L/2); fprintf(stderr,"# Reducing rc:\n"); rc2 = L/2; rc2 *= rc2; } } /* Update the histogram by sampling the configuration */ update_hist(rx,ry,rz,N,L,rc2,dr,H); fprintf(stderr,"# %s...\n",fn); } } /* Normalize and output g(r) to the terminal */ for (i=0;i