/* This is the primary polymer generator C code. This file reads in parameters from mc_gen.input and produces a LAMMPS compatible input file for amorphous polyethylene on a FCC lattice. */ #include #include #include #include /* This code generates a series of amorphous polymer chains on a FCC lattice */ #define PI 3.14159265 #define MAX_X 300 #define MAX_Y 300 #define MAX_Z 300 #define MAX_ATOMS 16000000 /* define data structures */ typedef struct atom_t ATOM; struct atom_t{ int chain; /*chain number*/ int nic; /*number of atom in chain*/ int x[3]; /*lattice occupied by the atom*/ int spot; /*spot or position of atom in lattice*/ int type; /*atom type*/ }; int site[MAX_X][MAX_Y][MAX_Z][4]; /*0 if site is unoccupied 1 if occupied*/ int loc_dens[MAX_X][MAX_Y][MAX_Z][4]; /*local density of site in terms of number of occupied nearest neighbor sites 0-12*/ int snd_dens[MAX_X][MAX_Y][MAX_Z][4]; /*2nd nearest neighbor density 0-6*/ int natom; /*total number of atoms*/ float density; int c_length; int n_chains; int seed; int n_incs; float lat; float mass; FILE *fp,*fq; char *inf,*outf,fnames[1][40]; ATOM atom_list[MAX_ATOMS]; /*the array of atoms, the length will be Natom*/ static void read_input(void); static void gen_pos(void); static void write_file(void); main() { int i,j,k; inf = "mc_gen.input"; outf = (char *)malloc(256); fp = fopen(inf,"r"); if(fp==NULL) printf("input file not found\n"); printf("enter read _input\n"); read_input(); printf("exit read _input\n"); printf("exit read _input\n"); srand(seed); printf("enter gen_pos\n"); gen_pos(); printf("enter write_file\n"); fq = fopen(outf,"w"); if(fq==NULL) printf("output file not found\n"); write_file(); printf("exit write_file\n"); fclose(fq); } static void read_input(void) { int i,j,k,m,u,v; int ii,jj,kk,mm; char *keyw,buf[256]; /* Read output file name */ fgets(fnames[0],sizeof(fnames[0]),fp); /* Read approximate density */ fgets(buf,sizeof(buf),fp); fgets(buf,sizeof(buf),fp); sscanf(buf,"%f",&density); /* Read chain length*/ fgets(buf,sizeof(buf),fp); fgets(buf,sizeof(buf),fp); sscanf(buf,"%d",&c_length); /* Read number of chains*/ fgets(buf,sizeof(buf),fp); fgets(buf,sizeof(buf),fp); sscanf(buf,"%d",&n_chains); /* Read lattice size*/ fgets(buf,sizeof(buf),fp); fgets(buf,sizeof(buf),fp); sscanf(buf,"%f",&lat); lat=lat/sqrt(2.0)*2.0; /* Read random number seed*/ fgets(buf,sizeof(buf),fp); fgets(buf,sizeof(buf),fp); sscanf(buf,"%d",&seed); /* Read random number seed*/ fgets(buf,sizeof(buf),fp); fgets(buf,sizeof(buf),fp); sscanf(buf,"%f",&mass); printf("den %f c_leng %d n_ch %d l_s %f seed %d \n",density,c_length,n_chains,lat,seed); fclose(fp); printf("create names \n"); printf("fname is %s \n",fnames[0]); strncpy(outf,fnames[0],strlen(fnames[0])-1); printf("output file is is %s \n",outf); } static void gen_pos(void) { int i,j,k,m,u,v; int ii,jj,kk,mm,nn,n; int n_oc_sites,t_sites; int dx[3],dy[3],dz[3]; int st_ld[12][4]; int snd_ld[6][4]; int snd_count,nn_count,total_dens,point; int prob_low,prob_high; int reset; double sqrt_2_2; double angle,va_mag,vb_mag,d_prod; double a[3],aa[3],va[3],vb[3],vc[3]; double neigh[12][4],v_store[12][3],mag_store[12]; char buf[256]; /* Determine the edge lengths in lattice units from the density */ sqrt_2_2=sqrt(2)/2.0; n_oc_sites=c_length*n_chains; t_sites=(int)(n_oc_sites/density); n_incs=(int)(cbrt(t_sites/4.0))+1.0; printf("%f %d %d %d \n",sqrt_2_2,n_oc_sites,t_sites,n_incs); /* Initialize the sites as empty */ natom=0; for(i=0;i-150.0)||(angle>60.0&&angle<150.0)||v==1) { neigh[nn][0]=dx[ii]; neigh[nn][1]=dy[jj]; neigh[nn][2]=dz[kk]; neigh[nn][3]=mm; v_store[nn][0]=va[0]; v_store[nn][1]=va[1]; v_store[nn][2]=va[2]; mag_store[nn]=va_mag; nn++; } } } } } } } if(nn==0) { if(reset==1) { printf("has already been reset and still can not find a neighbor\n"); printf("chain %d atom %d \n",u,v); exit(1); } printf("there is not a free neighbor site and must reset\n"); reset=1; site[i][j][k][m]=2; natom--; i=atom_list[natom].x[0]; j=atom_list[natom].x[1]; k=atom_list[natom].x[2]; m=atom_list[natom].spot; for(ii=0;ii<12;ii++) { loc_dens[st_ld[ii][0]][st_ld[ii][1]][st_ld[ii][2]][st_ld[ii][3]]--; } /* for(ii=0;ii<6;ii++) { snd_dens[snd_ld[ii][0]][snd_ld[ii][1]][snd_ld[ii][2]][snd_ld[ii][3]]--; } */ vb[0]=vc[0]; vb[1]=vc[1]; vb[2]=vc[2]; v=v-2; } else { total_dens=0; for(ii=0;ii=prob_low&&point