static int read_vaspoutcar_timestep(void *mydata, int natoms, molfile_timestep_t *ts) { vasp_plugindata_t *data = (vasp_plugindata_t *)mydata; char lineptr[LINESIZE]; int atomcount; /* Save coords only if we're given a timestep pointer, * otherwise assume that VMD wants us to skip past it. */ if (!data || !ts) return MOLFILE_EOF; atomcount = 0; while (fgets(lineptr, LINESIZE, data->file) && atomcount == 0) { if (strstr(lineptr, "TOTAL-FORCE") != NULL) { int i; fgets(lineptr, LINESIZE, data->file); for (i = 0; i < data->numatoms; ++i, ++atomcount) { float x, y, z; fgets(lineptr, LINESIZE, data->file); if (3 != sscanf(lineptr, "%f %f %f", &x, &y, &z)) return MOLFILE_EOF; ts->coords[3*i ] = data->rotmat[0][0]*x+data->rotmat[0][1]*y+data->rotmat[0][2]*z; ts->coords[3*i+1] = data->rotmat[1][0]*x+data->rotmat[1][1]*y+data->rotmat[1][2]*z; ts->coords[3*i+2] = data->rotmat[2][0]*x+data->rotmat[2][1]*y+data->rotmat[2][2]*z; } } } if (atomcount != data->numatoms) return MOLFILE_EOF; vasp_timestep_unitcell(ts, data); return MOLFILE_SUCCESS; }
static int read_vaspxml_timestep(void *mydata, int natoms, molfile_timestep_t *ts) { vasp_plugindata_t *data = (vasp_plugindata_t *)mydata; char lineptr[LINESIZE]; /* only save coords if we're given a timestep pointer, */ /* otherwise assume that VMD wants us to skip past it. */ if (!data || !ts) return MOLFILE_EOF; /* Scan xml file */ while (fgets(lineptr, LINESIZE, data->file)) { /* Extract coordinates of all atoms */ if (strstr(lineptr, "positions") != NULL) { int i; for (i = 0; i < data->numatoms && fgets(lineptr, LINESIZE, data->file); ++i) { float x, y, z, rotx, roty, rotz; if (3 != sscanf(lineptr, " <v> %f %f %f </v>", &x, &y, &z)) return MOLFILE_EOF; rotx = x*data->cell[0][0] + y*data->cell[1][0] + z*data->cell[2][0]; roty = x*data->cell[0][1] + y*data->cell[1][1] + z*data->cell[2][1]; rotz = x*data->cell[0][2] + y*data->cell[1][2] + z*data->cell[2][2]; ts->coords[3*i ] = data->rotmat[0][0]*rotx + data->rotmat[0][1]*roty + data->rotmat[0][2]*rotz; ts->coords[3*i+1] = data->rotmat[1][0]*rotx + data->rotmat[1][1]*roty + data->rotmat[1][2]*rotz; ts->coords[3*i+2] = data->rotmat[2][0]*rotx + data->rotmat[2][1]*roty + data->rotmat[2][2]*rotz; } vasp_timestep_unitcell(ts, data); return MOLFILE_SUCCESS; } } return MOLFILE_EOF; }
static int read_vasp5xdatcar_timestep(void *mydata, int natoms, molfile_timestep_t *ts) { int i; char lineptr[LINESIZE]; vasp_plugindata_t *data = (vasp_plugindata_t *)mydata; /* Save coords only if we're given a timestep pointer, * otherwise assume that VMD wants us to skip past it. */ if (!ts || !data) return MOLFILE_EOF; for (i = 0; i < data->numatoms; ++i) { float x, y, z, rotx, roty, rotz; fgets(lineptr, LINESIZE, data->file); if (3 != sscanf(lineptr, "%f %f %f", &x, &y, &z)) { fprintf(stderr, "VASP5 XDATCAR read) missing type or coordinate(s) in file '%s' for atom '%d'\n", data->filename, i+1); return MOLFILE_EOF; } rotx = x*data->cell[0][0]+y*data->cell[1][0]+z*data->cell[2][0]; roty = x*data->cell[0][1]+y*data->cell[1][1]+z*data->cell[2][1]; rotz = x*data->cell[0][2]+y*data->cell[1][2]+z*data->cell[2][2]; ts->coords[3*i ] = data->rotmat[0][0]*rotx+data->rotmat[0][1]*roty+data->rotmat[0][2]*rotz; ts->coords[3*i+1] = data->rotmat[1][0]*rotx+data->rotmat[1][1]*roty+data->rotmat[1][2]*rotz; ts->coords[3*i+2] = data->rotmat[2][0]*rotx+data->rotmat[2][1]*roty+data->rotmat[2][2]*rotz; } vasp_timestep_unitcell(ts, data); /* VMD keeps calling for a next timestep, until we reach End-Of-File here */ if (fgets(lineptr, LINESIZE, data->file) == NULL) return MOLFILE_EOF; return MOLFILE_SUCCESS; }
static int read_vaspposcar_timestep(void *mydata, int natoms, molfile_timestep_t *ts) { int i, direct; char lineptr[LINESIZE]; float lc; vasp_plugindata_t *data = (vasp_plugindata_t *)mydata; /* Save coords only if we're given a timestep pointer, * otherwise assume that VMD wants us to skip past it. */ if (!ts || !data) return MOLFILE_EOF; /* VMD keeps calling for a next timestep, until we reach End-Of-File here */ if (fgets(lineptr, LINESIZE, data->file) == NULL) return MOLFILE_EOF; fgets(lineptr, LINESIZE, data->file); sscanf(lineptr, "%f", &lc); for (i = 0; i < 3; ++i) { float x, y, z; fgets(lineptr, LINESIZE, data->file); sscanf(lineptr, "%f %f %f", &x, &y, &z); data->cell[i][0] = x*lc; data->cell[i][1] = y*lc; data->cell[i][2] = z*lc; } vasp_buildrotmat(data); /* Skip numbers of atom types */ for (i = 0; i < data->version - 2; ++i) fgets(lineptr, LINESIZE, data->file); /* Skip selective tag-line, starting with 's' or 'S'. */ if (tolower(lineptr[0]) == 's') fgets(lineptr, LINESIZE, data->file); /* Detect direct coordinates tag, starting with 'd' or 'D'. */ direct = (tolower(lineptr[0]) == 'd' ? 1 : 0); for (i = 0; i < data->numatoms; ++i) { float x, y, z, rotx, roty, rotz; fgets(lineptr, LINESIZE, data->file); if (3 != sscanf(lineptr, "%f %f %f", &x, &y, &z)) { fprintf(stderr, "VASP POSCAR read) missing type or coordinate(s) in file '%s' for atom '%d'\n", data->filename, i+1); return MOLFILE_EOF; } if (direct) { rotx = x*data->cell[0][0]+y*data->cell[1][0]+z*data->cell[2][0]; roty = x*data->cell[0][1]+y*data->cell[1][1]+z*data->cell[2][1]; rotz = x*data->cell[0][2]+y*data->cell[1][2]+z*data->cell[2][2]; } else { rotx = x*lc; roty = y*lc; rotz = z*lc; } ts->coords[3*i ] = data->rotmat[0][0]*rotx+data->rotmat[0][1]*roty+data->rotmat[0][2]*rotz; ts->coords[3*i+1] = data->rotmat[1][0]*rotx+data->rotmat[1][1]*roty+data->rotmat[1][2]*rotz; ts->coords[3*i+2] = data->rotmat[2][0]*rotx+data->rotmat[2][1]*roty+data->rotmat[2][2]*rotz; } vasp_timestep_unitcell(ts, data); /* POSCAR type files have only one single timestep. * Therefore proceed till end of file after reading the coordinates. */ fseek(data->file, 0, SEEK_END); return MOLFILE_SUCCESS; }