// Program: cpkdrawer // Sung Sakong, PhD // sung.sakong _at_ uni-due.de // ver 0.5 4. June 2007 // CONTCAR multiplier for CPK drawing in VMD // To remove the missing bond to the neighboring cell // input: CONTCAR output: CONTCAR.multiple #include #include #include #define LINESIZE 1024 #define MAXATOMTYPES 100 void main(void){ FILE *contcar, *contout; int eachatom[MAXATOMTYPES]; // number of atoms per atom type int i, j, k, numatoms; char lineptr[LINESIZE]; float cell[3][3]; // lattice vectors of the unit cell float lc; float crdx, crdy, crdz; contcar=fopen("CONTCAR", "r"); contout=fopen("CONTCAR.multiple", "w"); if (!contcar) { fclose(contcar); fclose(contout); printf("ERROR :: Cannot find CONTCAR!\n"); return NULL; } fgets(lineptr, LINESIZE, contcar); fprintf(contout, "%s", lineptr); fscanf(contcar, "%f", &lc); fprintf(contout, "%12.8f", lc); for(i=0; i<4; i++){ fgets(lineptr, LINESIZE, contcar); fprintf(contout, "%s", lineptr); } numatoms=0; fgets(lineptr, LINESIZE, contcar); for (i = 0; i < MAXATOMTYPES; i++) { char const *token = (i == 0 ? strtok(lineptr, " ") : strtok(NULL, " ")); int const n = (token ? atoi(token) : -1); if (n <= 0) break; eachatom[i] = n; numatoms += n; fprintf(contout, " %i", 4*n); } fprintf(contout, "\n"); fgets(lineptr, LINESIZE, contcar); // Ignore selective tag-line, starting with either 's' or 'S'. if (lineptr[0]=='s' || lineptr[0]=='S') fgets(lineptr, LINESIZE, contcar); fprintf(contout, "Direct\n"); // Check whether all coordinates are present in the file for (i = 0; i < numatoms; i++) { float coord; fgets(lineptr, LINESIZE, contcar); if (3 != sscanf(lineptr, "%f %f %f", &crdx, &crdy, &crdz)) { return NULL; } for(j=0; j<2; j++){ for(k=0; k<2; k++){ fprintf(contout, "%12.8f %12.8f %12.8f\n", crdx+j, crdy+k, crdz); } } } fclose(contcar); fclose(contout); return NULL; }