/* Molecular Dynamics simulation of a Lennard-Jones fluid in a periodic boundary using the Berendsen Thermostat Cameron F. Abrams Written for the course CHE 800-002, Molecular Simulation Spring 0304 compile using "gcc -o mdlj_ber mdlj_ber.c -lm -lgsl" (assumes the GNU Scientific Library is installed) You must have the GNU Scientific Library installed; see the coursenotes to learn how to do this. Drexel University, Department of Chemical Engineering Philadelphia (c) 2004 */ #include #include #include #include #include /* Prints usage information */ void usage ( void ) { fprintf(stdout,"mdlj_ber usage:\n"); fprintf(stdout,"mdlj_ber [options]\n\n"); fprintf(stdout,"Options:\n"); fprintf(stdout,"\t -N [integer]\t\tNumber of particles\n"); fprintf(stdout,"\t -rho [real]\t\tNumber density\n"); fprintf(stdout,"\t -dt [real]\t\tTime step\n"); fprintf(stdout,"\t -rc [real]\t\tCutoff radius\n"); fprintf(stdout,"\t -ns [real]\t\tNumber of integration steps\n"); fprintf(stdout,"\t -so \t\tShort-form output (unused)\n"); fprintf(stdout,"\t -T0 [real]\t\tSetpoint temperature\n"); fprintf(stdout,"\t -tau [real]\t\tRise time of thermostat\n"); fprintf(stdout,"\t -fs [integer]\t\tSample frequency\n"); fprintf(stdout,"\t -sf [a|w]\t\tAppend or write config output file\n"); fprintf(stdout,"\t -icf [string]\t\tInitial configuration file\n"); fprintf(stdout,"\t -seed [integer]\tRandom number generator seed\n"); fprintf(stdout,"\t -uf \t\tPrint unfolded coordinates in output files\n"); fprintf(stdout,"\t -h \t\tPrint this info\n"); } /* Writes the coordinates in XYZ format to the output stream fp. The integer "z" is the atomic number of the particles, required for the XYZ format. The array ix contains the number of x-dir periodic boundary crossings a particle has performed; thus, the "unfolded" coordinate is rx[i]+ix[i]*L. */ void xyz_out (FILE * fp, double * rx, double * ry, double * rz, double * vx, double * vy, double * vz, int * ix, int * iy, int * iz, double L, int N, int z, int put_vel, int unfold) { int i; fprintf(fp,"%i %i\n\n",N,put_vel); for (i=0;ihL) 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 (r20.0) { T=(*KE)/n*2./3.; fac=sqrt(T0/T); (*KE)=0; for (i=0;iL) { rx[i]-=L; ix[i]++; } if (ry[i]<0.0) { ry[i]+=L; iy[i]--; } if (ry[i]>L) { ry[i]-=L; iy[i]++; } if (rz[i]<0.0) { rz[i]+=L; iz[i]--; } if (rz[i]>L) { rz[i]-=L; iz[i]++; } } /* Calculate forces */ PE = total_e(rx,ry,rz,fx,fy,fz,N,L,rc2,ecor,ecut,&vir); /* Second integration half-step */ KE = 0.0; for (i=0;i