int main() { char coordinate_input[BUFSIZ]; char ammp_output[BUFSIZ]; char dictionary[BUFSIZ]; char work[1000],keep[1000]; char atype[20],aname[20]; char *fgets(); float sigma,emin; int ifile,i,imreading,ii,myres; FILE *in1,*dict,*output,*fopen(); printf(" atom definition file:>\n"); /* strip out the file name and put it in the right place for opening */ fgets( work,80,stdin ); for(i= 0; i<80; i++) if( work[i] != ' ') break; for( ifile = i; ifile < 80 ; ifile++) { if( work[ifile] == ' ' ) break; if( work[ifile] == '\0' ) break; if( work[ifile] == '\n' ) break; dictionary[ifile -i ] = work[ifile]; dictionary[ifile -i +1 ] = '\0'; } /* now read in the atoms */ dict = fopen( dictionary, "r"); if( dict == NULL) { fprintf(stderr," sorry i can't open %s\n",dictionary); exit(0);} inkinds = 0; while ( fgets( work,256, dict) != NULL) { sscanf( work,"%s %f %f %f %f %f %f %f %f %f %f %f %f %f \n", &kinds[inkinds].type[0], &kinds[inkinds].r , &kinds[inkinds].theta , &sigma , &emin , &kinds[inkinds].Z , &kinds[inkinds].angle_inc, &kinds[inkinds].X , &kinds[inkinds].jaa , &kinds[inkinds].mass , &kinds[inkinds].charge , &kinds[inkinds].V, &kinds[inkinds].U , &kinds[inkinds].hybrid ); /* kinds[inkinds].theta *= 3.14159265/180.; */ sigma = sigma*sigma; sigma = sigma*sigma*sigma; /* kinds[inkinds].b = sqrt( 4.*emin*sigma*sigma); kinds[inkinds].a = sqrt( 4.*emin*sigma); */ kinds[inkinds].b = sqrt( emin*sigma*sigma); kinds[inkinds].a = sqrt( 2*emin*sigma); inkinds ++; if( inkinds > MAX_ATOM) { fprintf( stderr," too many kinds of atoms in dictionary\n"); exit(0); } } fclose( dict); printf(" Residue dictionary directory:>\n"); /* strip out the file name and put it in the right place for opening */ fgets( work,80,stdin ); for(i= 0; i<80; i++) if( work[i] != ' ') break; for( ifile = i; ifile < 80 ; ifile++) { if( work[ifile] == ' ' ) break; if( work[ifile] == '\0' ) break; if( work[ifile] == '\n' ) break; dictionary[ifile -i ] = work[ifile]; dictionary[ifile -i +1 ] = '\0'; } ifile = ifile -i ; if( ifile == 0 ){ dictionary[ifile++] = '.'; dictionary[ifile] = '\0'; } if( dictionary[ifile-1] != '/') { ifile++; dictionary[ifile-1] = '/'; dictionary[ifile] = '\0';} printf(" atom input coordinate file:>\n"); /* strip out the file name and put it in the right place for opening */ fgets( work,80,stdin ); for(i= 0; i<80; i++) if( work[i] != ' ') break; for( ifile = i; ifile < 80 ; ifile++) { if( work[ifile] == ' ' ) break; if( work[ifile] == '\0' ) break; if( work[ifile] == '\n' ) break; coordinate_input[ifile -i ] = work[ifile]; coordinate_input[ifile -i +1 ] = '\0'; } printf(" AMMP file:>\n"); /* strip out the file name and put it in the right place for opening */ fgets( work,80,stdin ); for(i= 0; i<80; i++) if( work[i] != ' ') break; for( ifile = i; ifile < 80 ; ifile++) { if( work[ifile] == ' ' ) break; if( work[ifile] == '\0' ) break; if( work[ifile] == '\n' ) break; ammp_output[ifile -i ] = work[ifile]; ammp_output[ifile -i +1 ] = '\0'; } in1 = fopen( coordinate_input, "r"); output = fopen( ammp_output, "w"); if (in1 == NULL) goto NO_IN1_FILE; /* read in the first residue * stuff is read into work when the residue number changes then * work is copied into keep, so the first atom of any residue is * going to be in the keep buffer. to initialize we read the * first atom into keep */ keep[0] = '\0'; while( !(keep[0] == 'A' && keep[1] == 'T' && keep[2] == 'O' && keep[3] == 'M') && !(keep[0] == 'H'&& keep[1] == 'E' && keep[1] == 'T'&& keep[1] == 'A'&& keep[1] == 'T' ) ) { if( fgets(keep,90,in1) == NULL) { fprintf(stderr," no atoms in input file ? \n") ; NO_IN1_FILE: printf(" enter the dictionary name >\n"); fgets( keep, 90, stdin); i=0; while( (keep[i] == ' ' || keep[i] == '\t') && keep[i] != '\0') i++; for( imreading = 0; imreading < 3; imreading++) { aname[imreading] = toupper( keep[i + imreading] ); } aname[3] = '\0'; goto NO_ATOMS; } } imreading = 0; while( imreading == 0) {/* begining of imreading loop */ inres = 0; for(i=0; i< MAX_RES; i++) { mykind[i] = -1; defined[i] = -1; name[i][0] = '\0'; x[i] = 0.; y[i] = 0.; z[i] = 0.; } sscanf( &keep[22],"%d",&myres); sscanf(&keep[29],"%f %f %f",&x[inres],&y[inres],&z[inres]); sscanf(&keep[11],"%s",&atype[0]); sscanf(&keep[17],"%s",&aname[0]); serial[inres] = 100*myres + inres; ii = 0; for( i=0; i< 3; i++ ) { if( aname[i] == '\0') break; name[inres][ii++] = (char)tolower(aname[i]); } name[inres][ii++] = '.'; for(i=0; i< 4; i++) { if( atype[i] == '\0' ) break; name[inres][ii++] = (char)tolower(atype[i]); } name[inres][ii] = '\0'; a[inres] = 0.; b[inres] = 0.; q[inres] = 0.; mass[inres] = 1.; defined[inres] = 0; for( inres = 1; inres < MAX_RES; inres ++) { /* start of reading an atom loop */ if( fgets( work,90,in1) == NULL) { imreading = 1; break; } if( work[0] != 'A' && work[0] != 'H') { imreading = 1; break; } /* printf("%s\n",work); printf("%d\n",inres); */ sscanf( &work[22],"%d",&ii); if( ii != myres ) {ii = 0; while( work[ii] != '\0'){ keep[ii] = work[ii] ; ii++;} /* inres += 1; */ break; } sscanf(&work[29],"%f %f %f",&x[inres],&y[inres],&z[inres]); sscanf(&work[11],"%s",&atype[0]); sscanf(&work[17],"%s",&aname[0]); serial[inres] = 100*myres + inres; ii = 0; for( i=0; i< 3; i++ ) { if( aname[i] == '\0') break; name[inres][ii++] = (char)tolower(aname[i]); } name[inres][ii++] = '.'; for(i=0; i< 4; i++) { if( atype[i] == '\0' ) break; name[inres][ii++] = (char)tolower(atype[i]); } name[inres][ii] = '\0'; a[inres] = 0.; b[inres] = 0.; q[inres] = 0.; mass[inres] = 1.; defined[inres] = 0; }/* end of reading an atom loop */ /* for( i=0; i< inres; i++) printf(">%s<\n",&name[i][0]); */ /* if here then all of the atoms in the residue are read in */ /* now we have to open and read the dictionary file * there could be atoms in either the residue or dictionary which * are not there i.e. oxt for a residue or a missing H */ /* prepare the filename */ NO_ATOMS: i = 0; while(dictionary[i] != '\0') { work[i] = dictionary[i]; i++;} ii = 0; while(aname[ii] != '\0') {work[i] = aname[ii]; i++; ii++;} work[i++] = '\0'; dict = fopen(work,"r"); if( dict == NULL ){ fprintf(stderr," dictionary %s not found \n", work); write_atoms(output); goto DONE; } /* read the number of atoms */ if(fgets( work,80,dict)==NULL) { fprintf(stderr,"BAD DICTIONARY %s\n",aname); exit(0);} sscanf(work,"%d",&natoms); read_atoms( dict,natoms ); write_atoms(output); if(fgets( work,80,dict)==NULL) { fprintf(stderr,"BAD DICTIONARY %s\n",aname); exit(0);} sscanf(work,"%d",&nbond); do_bonds( dict,nbond,output); inbondlist = nbond; nangle = 0; if(fgets( work,80,dict)!=NULL) sscanf(work,"%d",&nangle); do_angle(dict,nangle,output); nhybrid = 0; if(fgets( work,80,dict)!=NULL) sscanf(work,"%d",&nhybrid); do_hybrid(dict,nhybrid,output); ntorsion = 0; if(fgets( work,80,dict)!=NULL) sscanf(work,"%d",&ntorsion); do_torsion(dict,ntorsion,output); DONE: fclose( dict ); }/* end of imreading loop */ }/* end of module main */
void calc_angles(void) { cell *p, *q,* r, *s; int i1, i2, i3, j1, j2, j3; int k1, k2, k3, l1, l2, l3; int a1, a2, a3, b1, b2, b3, c1, c2, c3; vektor pbc_q, pbc_r, pbc_s; /* for each cell p */ for (i1 = 0; i1 < cell_dim.x; ++i1) for (i2 = 0; i2 < cell_dim.y; ++i2) for (i3 = 0; i3 < cell_dim.z; ++i3) /* For half of the neighbours q of this cell */ for (j1 = 0; j1 <= 1; ++j1) for (j2 = -j1; j2 <= 1; ++j2) for (j3= (j1 == 0 ? -j2 : -j1); j3 <= 1; ++j3) /* For the neighbours r of cell p */ for (k1 = -1; k1 <= 1; ++k1) for (k2 = -1; k2 <= 1; ++k2) for (k3 = -1; k3 <= 1; ++k3) /* for the neighbours s of cell q */ for (l1 = -1; l1 <= 1; ++l1) for (l2 = -1; l2 <= 1; ++l2) for (l3 = -1; l3 <= 1; ++l3) { /* Given cell */ p = PTR_3D_V(cell_array,i1,i2,i3,cell_dim); /* Calculate Indices of Neighbour */ a1 = i1 + j1; pbc_q.x = 0; a2 = i2 + j2; pbc_q.y = 0; a3 = i3 + j3; pbc_q.z = 0; /* deal with periodic boundary conditions if necessary */ if (a1 < 0) { if (pbc_dirs.x == 1) { a1 = cell_dim.x-1; pbc_q.x -= box_x.x; pbc_q.y -= box_x.y; pbc_q.z -= box_x.z; } else continue; } if (a2 < 0) { if (pbc_dirs.y == 1) { a2 = cell_dim.y-1; pbc_q.x -= box_y.x; pbc_q.y -= box_y.y; pbc_q.z -= box_y.z; } else continue; } if (a3 < 0) { if (pbc_dirs.z == 1) { a3 = cell_dim.z-1; pbc_q.x -= box_z.x; pbc_q.y -= box_z.y; pbc_q.z -= box_z.z; } else continue; } if (a1 > cell_dim.x-1) { if (pbc_dirs.x == 1) { a1 = 0; pbc_q.x += box_x.x; pbc_q.y += box_x.y; pbc_q.z += box_x.z; } else continue; } if (a2 > cell_dim.y-1) { if (pbc_dirs.y == 1) { a2 = 0; pbc_q.x += box_y.x; pbc_q.y += box_y.y; pbc_q.z += box_y.z; } else continue; } if (a3 > cell_dim.z-1) { if (pbc_dirs.z == 1) { a3 = 0; pbc_q.x += box_z.x; pbc_q.y += box_z.y; pbc_q.z += box_z.z; } else continue; } /* Neighbour cell q (note that p==q ist possible) */ q = PTR_3D_V(cell_array,a1,a2,a3,cell_dim); /* Calculate Indices of neighbour r of p */ b1 = i1 + k1; pbc_r.x = 0; b2 = i2 + k2; pbc_r.y = 0; b3 = i3 + k3; pbc_r.z = 0; /* deal with periodic boundary conditions if necessary */ if (b1 < 0) { if (pbc_dirs.x == 1) { b1 = cell_dim.x-1; pbc_r.x -= box_x.x; pbc_r.y -= box_x.y; pbc_r.z -= box_x.z; } else continue; } if (b2 < 0) { if (pbc_dirs.y == 1) { b2 = cell_dim.y-1; pbc_r.x -= box_y.x; pbc_r.y -= box_y.y; pbc_r.z -= box_y.z; } else continue; } if (b3 < 0) { if (pbc_dirs.z == 1) { b3 = cell_dim.z-1; pbc_r.x -= box_z.x; pbc_r.y -= box_z.y; pbc_r.z -= box_z.z; } else continue; } if (b1 > cell_dim.x-1) { if (pbc_dirs.x == 1) { b1 = 0; pbc_r.x += box_x.x; pbc_r.y += box_x.y; pbc_r.z += box_x.z; } else continue; } if (b2 > cell_dim.y-1) { if (pbc_dirs.y == 1) { b2 = 0; pbc_r.x += box_y.x; pbc_r.y += box_y.y; pbc_r.z += box_y.z; } else continue; } if (b3 > cell_dim.z-1) { if (pbc_dirs.z == 1) { b3 = 0; pbc_r.x += box_z.x; pbc_r.y += box_z.y; pbc_r.z += box_z.z; } else continue; } /* Neighbour cell r */ r = PTR_3D_V(cell_array, b1, b2, b3, cell_dim); /* Calculate Indices of neighbour s of q */ c1 = j1 + l1; pbc_s.x = 0; c2 = j2 + l2; pbc_s.y = 0; c3 = j3 + l3; pbc_s.z = 0; /* deal with periodic boundary conditions if necessary */ if (c1 < 0) { if (pbc_dirs.x == 1) { c1 = cell_dim.x-1; pbc_s.x -= box_x.x; pbc_s.y -= box_x.y; pbc_s.z -= box_x.z; } else continue; } if (c2 < 0) { if (pbc_dirs.y == 1) { c2 = cell_dim.y-1; pbc_s.x -= box_y.x; pbc_s.y -= box_y.y; pbc_s.z -= box_y.z; } else continue; } if (c3 < 0) { if (pbc_dirs.z == 1) { c3 = cell_dim.z-1; pbc_s.x -= box_z.x; pbc_s.y -= box_z.y; pbc_s.z -= box_z.z; } else continue; } if (c1 > cell_dim.x-1) { if (pbc_dirs.x == 1) { c1 = 0; pbc_s.x += box_x.x; pbc_s.y += box_x.y; pbc_s.z += box_x.z; } else continue; } if (c2 > cell_dim.y-1) { if (pbc_dirs.y == 1) { c2 = 0; pbc_s.x += box_y.x; pbc_s.y += box_y.y; pbc_s.z += box_y.z; } else continue; } if (c3 > cell_dim.z-1) { if (pbc_dirs.z == 1) { c3 = 0; pbc_s.x += box_z.x; pbc_s.y += box_z.y; pbc_s.z += box_z.z; } else continue; } /* Neighbour cell s */ s = PTR_3D_V(cell_array, c1, c2, c3, cell_dim); /* Do the work */ do_angle(p,q,r,s,pbc_q,pbc_r,pbc_s); } }