void gmx_espresso_read_conf(const char *infile, t_topology *top, rvec x[], rvec *v, matrix box) { t_atoms *atoms = &top->atoms; FILE *fp; char word[STRLEN], buf[STRLEN]; int level, r, nprop, p, i, m, molnr; int prop[32]; double d; gmx_bool bFoundParticles, bFoundProp, bFoundVariable, bMol; // TODO: The code does not understand titles it writes... top->name = put_symtab(&top->symtab, ""); clear_mat(box); fp = gmx_fio_fopen(infile, "r"); bFoundParticles = FALSE; bFoundVariable = FALSE; bMol = FALSE; level = 0; while ((r = get_espresso_word(fp, word))) { if (level == 1 && std::strcmp(word, "particles") == 0 && !bFoundParticles) { bFoundParticles = TRUE; level += check_open_parenthesis(fp, r, infile, "particles"); nprop = 0; while (level == 2 && (r = get_espresso_word(fp, word))) { bFoundProp = FALSE; for (p = 0; p < espNR; p++) { if (strcmp(word, esp_prop[p]) == 0) { bFoundProp = TRUE; prop[nprop++] = p; /* printf(" prop[%d] = %s\n",nprop-1,esp_prop[prop[nprop-1]]); */ } } if (!bFoundProp && word[0] != '}') { gmx_fatal(FARGS, "Can not read Espresso files with particle property '%s'", word); } if (bFoundProp && p == espMOLECULE) { bMol = TRUE; } if (r == 3) { level--; } } i = 0; while (level > 0 && (r = get_espresso_word(fp, word))) { if (r == 2) { level++; } else if (r == 3) { level--; } if (level == 2) { for (p = 0; p < nprop; p++) { switch (prop[p]) { case espID: r = get_espresso_word(fp, word); /* Not used */ break; case espPOS: for (m = 0; m < 3; m++) { r = get_espresso_word(fp, word); sscanf(word, "%lf", &d); x[i][m] = d; } break; case espTYPE: r = get_espresso_word(fp, word); atoms->atom[i].type = std::strtol(word, NULL, 10); break; case espQ: r = get_espresso_word(fp, word); sscanf(word, "%lf", &d); atoms->atom[i].q = d; break; case espV: for (m = 0; m < 3; m++) { r = get_espresso_word(fp, word); sscanf(word, "%lf", &d); v[i][m] = d; } break; case espF: for (m = 0; m < 3; m++) { r = get_espresso_word(fp, word); /* not used */ } break; case espMOLECULE: r = get_espresso_word(fp, word); molnr = std::strtol(word, NULL, 10); if (i == 0 || atoms->resinfo[atoms->atom[i-1].resind].nr != molnr) { atoms->atom[i].resind = (i == 0 ? 0 : atoms->atom[i-1].resind+1); atoms->resinfo[atoms->atom[i].resind].nr = molnr; atoms->resinfo[atoms->atom[i].resind].ic = ' '; atoms->resinfo[atoms->atom[i].resind].chainid = ' '; atoms->resinfo[atoms->atom[i].resind].chainnum = molnr; /* Not sure if this is right? */ } else { atoms->atom[i].resind = atoms->atom[i-1].resind; } break; } } /* Generate an atom name from the particle type */ sprintf(buf, "T%u", atoms->atom[i].type); atoms->atomname[i] = put_symtab(&top->symtab, buf); if (bMol) { if (i == 0 || atoms->atom[i].resind != atoms->atom[i-1].resind) { atoms->resinfo[atoms->atom[i].resind].name = put_symtab(&top->symtab, "MOL"); } } else { /* Residue number is the atom number */ atoms->atom[i].resind = i; /* Generate an residue name from the particle type */ if (atoms->atom[i].type < 26) { sprintf(buf, "T%c", 'A'+atoms->atom[i].type); } else { sprintf(buf, "T%c%c", 'A'+atoms->atom[i].type/26, 'A'+atoms->atom[i].type%26); } t_atoms_set_resinfo(atoms, i, &top->symtab, buf, i, ' ', 0, ' '); } if (r == 3) { level--; } i++; } } atoms->nres = atoms->nr; if (i != atoms->nr) { gmx_fatal(FARGS, "Internal inconsistency in Espresso routines, read %d atoms, expected %d atoms", i, atoms->nr); } } else if (level == 1 && std::strcmp(word, "variable") == 0 && !bFoundVariable) { bFoundVariable = TRUE; level += check_open_parenthesis(fp, r, infile, "variable"); while (level == 2 && (r = get_espresso_word(fp, word))) { if (level == 2 && std::strcmp(word, "box_l") == 0) { for (m = 0; m < 3; m++) { r = get_espresso_word(fp, word); sscanf(word, "%lf", &d); box[m][m] = d; } level += check_close_parenthesis(fp, r, infile, "box_l"); } } } else if (r == 2) { level++; } else if (r == 3) { level--; } } if (!bFoundParticles) { fprintf(stderr, "Did not find a particles section in Espresso file '%s'\n", infile); } gmx_fio_fclose(fp); }
void connelly_plot(const char *fn,int ndots,real dots[],rvec x[],t_atoms *atoms, t_symtab *symtab,int ePBC,matrix box,gmx_bool bSave) { static const char *atomnm="DOT"; static const char *resnm ="DOT"; static const char *title ="Connely Dot Surface Generated by g_sas"; int i,i0,r0,ii0,k; rvec *xnew; t_atoms aaa; if (bSave) { i0 = atoms->nr; r0 = atoms->nres; srenew(atoms->atom,atoms->nr+ndots); srenew(atoms->atomname,atoms->nr+ndots); srenew(atoms->resinfo,r0+1); atoms->atom[i0].resind = r0; t_atoms_set_resinfo(atoms,i0,symtab,resnm,r0+1,' ',0,' '); srenew(atoms->pdbinfo,atoms->nr+ndots); snew(xnew,atoms->nr+ndots); for(i=0; (i<atoms->nr); i++) copy_rvec(x[i],xnew[i]); for(i=k=0; (i<ndots); i++) { ii0 = i0+i; atoms->atomname[ii0] = put_symtab(symtab,atomnm); atoms->pdbinfo[ii0].type = epdbATOM; atoms->pdbinfo[ii0].atomnr= ii0; atoms->atom[ii0].resind = r0; xnew[ii0][XX] = dots[k++]; xnew[ii0][YY] = dots[k++]; xnew[ii0][ZZ] = dots[k++]; atoms->pdbinfo[ii0].bfac = 0.0; atoms->pdbinfo[ii0].occup = 0.0; } atoms->nr = i0+ndots; atoms->nres = r0+1; write_sto_conf(fn,title,atoms,xnew,NULL,ePBC,box); atoms->nres = r0; atoms->nr = i0; } else { init_t_atoms(&aaa,ndots,TRUE); aaa.atom[0].resind = 0; t_atoms_set_resinfo(&aaa,0,symtab,resnm,1,' ',0,' '); snew(xnew,ndots); for(i=k=0; (i<ndots); i++) { ii0 = i; aaa.atomname[ii0] = put_symtab(symtab,atomnm); aaa.pdbinfo[ii0].type = epdbATOM; aaa.pdbinfo[ii0].atomnr= ii0; aaa.atom[ii0].resind = 0; xnew[ii0][XX] = dots[k++]; xnew[ii0][YY] = dots[k++]; xnew[ii0][ZZ] = dots[k++]; aaa.pdbinfo[ii0].bfac = 0.0; aaa.pdbinfo[ii0].occup = 0.0; } aaa.nr = ndots; write_sto_conf(fn,title,&aaa,xnew,NULL,ePBC,box); do_conect(fn,ndots,xnew); free_t_atoms(&aaa,FALSE); } sfree(xnew); }
static gmx_bool get_w_conf(FILE *in, const char *infile, char *title, t_symtab *symtab, t_atoms *atoms, int *ndec, rvec x[], rvec *v, matrix box) { char name[6]; char line[STRLEN+1], *ptr; char buf[256]; double x1, y1, z1, x2, y2, z2; rvec xmin, xmax; int natoms, i, m, resnr, newres, oldres, ddist, c; gmx_bool bFirst, bVel; char *p1, *p2, *p3; newres = -1; oldres = NOTSET; /* Unlikely number for the first residue! */ ddist = 0; /* Read the title and number of atoms */ get_coordnum_fp(in, title, &natoms); if (natoms > atoms->nr) { gmx_fatal(FARGS, "gro file contains more atoms (%d) than expected (%d)", natoms, atoms->nr); } else if (natoms < atoms->nr) { fprintf(stderr, "Warning: gro file contains less atoms (%d) than expected" " (%d)\n", natoms, atoms->nr); } bFirst = TRUE; bVel = FALSE; /* just pray the arrays are big enough */ for (i = 0; (i < natoms); i++) { if ((fgets2 (line, STRLEN, in)) == NULL) { gmx_fatal(FARGS, "Unexpected end of file in file %s at line %d", infile, i+2); } if (strlen(line) < 39) { gmx_fatal(FARGS, "Invalid line in %s for atom %d:\n%s", infile, i+1, line); } /* determine read precision from distance between periods (decimal points) */ if (bFirst) { bFirst = FALSE; p1 = strchr(line, '.'); if (p1 == NULL) { gmx_fatal(FARGS, "A coordinate in file %s does not contain a '.'", infile); } p2 = strchr(&p1[1], '.'); if (p2 == NULL) { gmx_fatal(FARGS, "A coordinate in file %s does not contain a '.'", infile); } ddist = p2 - p1; *ndec = ddist - 5; p3 = strchr(&p2[1], '.'); if (p3 == NULL) { gmx_fatal(FARGS, "A coordinate in file %s does not contain a '.'", infile); } if (p3 - p2 != ddist) { gmx_fatal(FARGS, "The spacing of the decimal points in file %s is not consistent for x, y and z", infile); } } /* residue number*/ memcpy(name, line, 5); name[5] = '\0'; sscanf(name, "%d", &resnr); memcpy(name, line+5, 5); name[5] = '\0'; if (resnr != oldres) { oldres = resnr; newres++; if (newres >= natoms) { gmx_fatal(FARGS, "More residues than atoms in %s (natoms = %d)", infile, natoms); } atoms->atom[i].resind = newres; t_atoms_set_resinfo(atoms, i, symtab, name, resnr, ' ', 0, ' '); } else { atoms->atom[i].resind = newres; } /* atomname */ memcpy(name, line+10, 5); atoms->atomname[i] = put_symtab(symtab, name); /* eventueel controle atomnumber met i+1 */ /* coordinates (start after residue data) */ ptr = line + 20; /* Read fixed format */ for (m = 0; m < DIM; m++) { for (c = 0; (c < ddist && ptr[0]); c++) { buf[c] = ptr[0]; ptr++; } buf[c] = '\0'; if (sscanf (buf, "%lf %lf", &x1, &x2) != 1) { gmx_fatal(FARGS, "Something is wrong in the coordinate formatting of file %s. Note that gro is fixed format (see the manual)", infile); } else { x[i][m] = x1; } } /* velocities (start after residues and coordinates) */ if (v) { /* Read fixed format */ for (m = 0; m < DIM; m++) { for (c = 0; (c < ddist && ptr[0]); c++) { buf[c] = ptr[0]; ptr++; } buf[c] = '\0'; if (sscanf (buf, "%lf", &x1) != 1) { v[i][m] = 0; } else { v[i][m] = x1; bVel = TRUE; } } } } atoms->nres = newres + 1; /* box */ fgets2 (line, STRLEN, in); if (sscanf (line, "%lf%lf%lf", &x1, &y1, &z1) != 3) { gmx_warning("Bad box in file %s", infile); /* Generate a cubic box */ for (m = 0; (m < DIM); m++) { xmin[m] = xmax[m] = x[0][m]; } for (i = 1; (i < atoms->nr); i++) { for (m = 0; (m < DIM); m++) { xmin[m] = min(xmin[m], x[i][m]); xmax[m] = max(xmax[m], x[i][m]); } } for (i = 0; i < DIM; i++) { for (m = 0; m < DIM; m++) { box[i][m] = 0.0; } } for (m = 0; (m < DIM); m++) { box[m][m] = (xmax[m]-xmin[m]); } fprintf(stderr, "Generated a cubic box %8.3f x %8.3f x %8.3f\n", box[XX][XX], box[YY][YY], box[ZZ][ZZ]); } else { /* We found the first three values, the diagonal elements */ box[XX][XX] = x1; box[YY][YY] = y1; box[ZZ][ZZ] = z1; if (sscanf (line, "%*f%*f%*f%lf%lf%lf%lf%lf%lf", &x1, &y1, &z1, &x2, &y2, &z2) != 6) { x1 = y1 = z1 = x2 = y2 = z2 = 0.0; } box[XX][YY] = x1; box[XX][ZZ] = y1; box[YY][XX] = z1; box[YY][ZZ] = x2; box[ZZ][XX] = y2; box[ZZ][YY] = z2; } return bVel; }
static int read_atom(t_symtab *symtab, char line[], int type, int natom, t_atoms *atoms, rvec x[], int chainnum, gmx_bool bChange) { t_atom *atomn; int j, k; char nc = '\0'; char anr[12], anm[12], anm_copy[12], altloc, resnm[12], rnr[12], elem[3]; char xc[12], yc[12], zc[12], occup[12], bfac[12]; unsigned char resic; char chainid; int resnr, atomnumber; if (natom >= atoms->nr) { gmx_fatal(FARGS, "\nFound more atoms (%d) in pdb file than expected (%d)", natom+1, atoms->nr); } /* Skip over type */ j = 6; for (k = 0; (k < 5); k++, j++) { anr[k] = line[j]; } anr[k] = nc; trim(anr); j++; for (k = 0; (k < 4); k++, j++) { anm[k] = line[j]; } anm[k] = nc; std::strcpy(anm_copy, anm); rtrim(anm_copy); atomnumber = 0; trim(anm); altloc = line[j]; j++; for (k = 0; (k < 4); k++, j++) { resnm[k] = line[j]; } resnm[k] = nc; trim(resnm); chainid = line[j]; j++; for (k = 0; (k < 4); k++, j++) { rnr[k] = line[j]; } rnr[k] = nc; trim(rnr); resnr = std::strtol(rnr, NULL, 10); resic = line[j]; j += 4; /* X,Y,Z Coordinate */ for (k = 0; (k < 8); k++, j++) { xc[k] = line[j]; } xc[k] = nc; for (k = 0; (k < 8); k++, j++) { yc[k] = line[j]; } yc[k] = nc; for (k = 0; (k < 8); k++, j++) { zc[k] = line[j]; } zc[k] = nc; /* Weight */ for (k = 0; (k < 6); k++, j++) { occup[k] = line[j]; } occup[k] = nc; /* B-Factor */ for (k = 0; (k < 7); k++, j++) { bfac[k] = line[j]; } bfac[k] = nc; /* 10 blanks */ j += 10; /* Element name */ for (k = 0; (k < 2); k++, j++) { elem[k] = line[j]; } elem[k] = nc; trim(elem); if (atoms->atom) { atomn = &(atoms->atom[natom]); if ((natom == 0) || atoms->resinfo[atoms->atom[natom-1].resind].nr != resnr || atoms->resinfo[atoms->atom[natom-1].resind].ic != resic || (strcmp(*atoms->resinfo[atoms->atom[natom-1].resind].name, resnm) != 0)) { if (natom == 0) { atomn->resind = 0; } else { atomn->resind = atoms->atom[natom-1].resind + 1; } atoms->nres = atomn->resind + 1; t_atoms_set_resinfo(atoms, natom, symtab, resnm, resnr, resic, chainnum, chainid); } else { atomn->resind = atoms->atom[natom-1].resind; } if (bChange) { xlate_atomname_pdb2gmx(anm); } atoms->atomname[natom] = put_symtab(symtab, anm); atomn->m = 0.0; atomn->q = 0.0; atomn->atomnumber = atomnumber; strncpy(atomn->elem, elem, 4); } x[natom][XX] = strtod(xc, NULL)*0.1; x[natom][YY] = strtod(yc, NULL)*0.1; x[natom][ZZ] = strtod(zc, NULL)*0.1; if (atoms->pdbinfo) { atoms->pdbinfo[natom].type = type; atoms->pdbinfo[natom].atomnr = strtol(anr, NULL, 10); atoms->pdbinfo[natom].altloc = altloc; strcpy(atoms->pdbinfo[natom].atomnm, anm_copy); atoms->pdbinfo[natom].bfac = strtod(bfac, NULL); atoms->pdbinfo[natom].occup = strtod(occup, NULL); } natom++; return natom; }
static int read_g96_pos(char line[], t_symtab *symtab, FILE *fp, const char *infile, t_trxframe *fr) { t_atoms *atoms; gmx_bool bEnd; int nwanted, natoms, atnr, resnr = 0, oldres, newres, shift; char anm[STRLEN], resnm[STRLEN]; char c1, c2; double db1, db2, db3; nwanted = fr->natoms; atoms = fr->atoms; natoms = 0; if (fr->bX) { if (fr->bAtoms) { shift = CHAR_SHIFT; } else { shift = 0; } newres = -1; oldres = -666; /* Unlikely number for the first residue! */ bEnd = FALSE; while (!bEnd && fgets2(line, STRLEN, fp)) { bEnd = (strncmp(line, "END", 3) == 0); if (!bEnd && (line[0] != '#')) { if (sscanf(line+shift, "%15lf%15lf%15lf", &db1, &db2, &db3) != 3) { gmx_fatal(FARGS, "Did not find 3 coordinates for atom %d in %s\n", natoms+1, infile); } if ((nwanted != -1) && (natoms >= nwanted)) { gmx_fatal(FARGS, "Found more coordinates (%d) in %s than expected %d\n", natoms, infile, nwanted); } if (atoms) { if (fr->bAtoms && (sscanf(line, "%5d%c%5s%c%5s%7d", &resnr, &c1, resnm, &c2, anm, &atnr) != 6)) { if (oldres >= 0) { resnr = oldres; } else { resnr = 1; strncpy(resnm, "???", sizeof(resnm)-1); } strncpy(anm, "???", sizeof(anm)-1); } atoms->atomname[natoms] = put_symtab(symtab, anm); if (resnr != oldres) { oldres = resnr; newres++; if (newres >= atoms->nr) { gmx_fatal(FARGS, "More residues than atoms in %s (natoms = %d)", infile, atoms->nr); } atoms->atom[natoms].resind = newres; if (newres+1 > atoms->nres) { atoms->nres = newres+1; } t_atoms_set_resinfo(atoms, natoms, symtab, resnm, resnr, ' ', 0, ' '); } else { atoms->atom[natoms].resind = newres; } } if (fr->x) { fr->x[natoms][0] = db1; fr->x[natoms][1] = db2; fr->x[natoms][2] = db3; } natoms++; } } if ((nwanted != -1) && natoms != nwanted) { fprintf(stderr, "Warning: found less coordinates (%d) in %s than expected %d\n", natoms, infile, nwanted); } } fr->natoms = natoms; return natoms; }