void write_pdbfile_indexed(FILE *out, const char *title, t_atoms *atoms, rvec x[], int ePBC, matrix box, char chainid, int model_nr, int nindex, const int index[], gmx_conect conect, gmx_bool bTerSepChains) { gmx_conect_t *gc = (gmx_conect_t *)conect; char resnm[6], nm[6]; int i, ii; int resind, resnr; enum PDB_record type; unsigned char resic, ch; char altloc; real occup, bfac; gmx_bool bOccup; int chainnum, lastchainnum; gmx_residuetype_t*rt; const char *p_restype; const char *p_lastrestype; gmx_residuetype_init(&rt); fprintf(out, "TITLE %s\n", (title && title[0]) ? title : gmx::bromacs().c_str()); if (box && ( norm2(box[XX]) || norm2(box[YY]) || norm2(box[ZZ]) ) ) { gmx_write_pdb_box(out, ePBC, box); } if (atoms->pdbinfo) { /* Check whether any occupancies are set, in that case leave it as is, * otherwise set them all to one */ bOccup = TRUE; for (ii = 0; (ii < nindex) && bOccup; ii++) { i = index[ii]; bOccup = bOccup && (atoms->pdbinfo[i].occup == 0.0); } } else { bOccup = FALSE; } fprintf(out, "MODEL %8d\n", model_nr > 0 ? model_nr : 1); lastchainnum = -1; p_restype = NULL; for (ii = 0; ii < nindex; ii++) { i = index[ii]; resind = atoms->atom[i].resind; chainnum = atoms->resinfo[resind].chainnum; p_lastrestype = p_restype; gmx_residuetype_get_type(rt, *atoms->resinfo[resind].name, &p_restype); /* Add a TER record if we changed chain, and if either the previous or this chain is protein/DNA/RNA. */ if (bTerSepChains && ii > 0 && chainnum != lastchainnum) { /* Only add TER if the previous chain contained protein/DNA/RNA. */ if (gmx_residuetype_is_protein(rt, p_lastrestype) || gmx_residuetype_is_dna(rt, p_lastrestype) || gmx_residuetype_is_rna(rt, p_lastrestype)) { fprintf(out, "TER\n"); } lastchainnum = chainnum; } strncpy(resnm, *atoms->resinfo[resind].name, sizeof(resnm)-1); resnm[sizeof(resnm)-1] = 0; strncpy(nm, *atoms->atomname[i], sizeof(nm)-1); nm[sizeof(nm)-1] = 0; /* rename HG12 to 2HG1, etc. */ xlate_atomname_gmx2pdb(nm); resnr = atoms->resinfo[resind].nr; resic = atoms->resinfo[resind].ic; if (chainid != ' ') { ch = chainid; } else { ch = atoms->resinfo[resind].chainid; if (ch == 0) { ch = ' '; } } if (resnr >= 10000) { resnr = resnr % 10000; } if (atoms->pdbinfo) { type = static_cast<enum PDB_record>(atoms->pdbinfo[i].type); altloc = atoms->pdbinfo[i].altloc; if (!isalnum(altloc)) { altloc = ' '; } occup = bOccup ? 1.0 : atoms->pdbinfo[i].occup; bfac = atoms->pdbinfo[i].bfac; } else { type = epdbATOM; occup = 1.0; bfac = 0.0; altloc = ' '; } gmx_fprintf_pdb_atomline(out, type, i+1, nm, altloc, resnm, ch, resnr, resic, 10*x[i][XX], 10*x[i][YY], 10*x[i][ZZ], occup, bfac, atoms->atom[i].elem); if (atoms->pdbinfo && atoms->pdbinfo[i].bAnisotropic) { fprintf(out, "ANISOU%5d %-4.4s%4.4s%c%4d%c %7d%7d%7d%7d%7d%7d\n", (i+1)%100000, nm, resnm, ch, resnr, (resic == '\0') ? ' ' : resic, atoms->pdbinfo[i].uij[0], atoms->pdbinfo[i].uij[1], atoms->pdbinfo[i].uij[2], atoms->pdbinfo[i].uij[3], atoms->pdbinfo[i].uij[4], atoms->pdbinfo[i].uij[5]); } } fprintf(out, "TER\n"); fprintf(out, "ENDMDL\n"); if (NULL != gc) { /* Write conect records */ for (i = 0; (i < gc->nconect); i++) { fprintf(out, "CONECT%5d%5d\n", gc->conect[i].ai+1, gc->conect[i].aj+1); } } gmx_residuetype_destroy(rt); }
void rename_atoms(const char *xlfile,const char *ffdir, t_atoms *atoms,t_symtab *symtab,const t_restp *restp, gmx_bool bResname,gmx_residuetype_t rt,gmx_bool bReorderNum, gmx_bool bVerbose) { FILE *fp; int nxlate,a,i,resind; t_xlate_atom *xlatom; int nf; char **f; char c,*rnm,atombuf[32],*ptr0,*ptr1; gmx_bool bReorderedNum,bRenamed,bMatch; nxlate = 0; xlatom = NULL; if (xlfile != NULL) { fp = libopen(xlfile); get_xlatoms(xlfile,fp,&nxlate,&xlatom); fclose(fp); } else { nf = fflib_search_file_end(ffdir,".arn",FALSE,&f); for(i=0; i<nf; i++) { fp = fflib_open(f[i]); get_xlatoms(f[i],fp,&nxlate,&xlatom); fclose(fp); sfree(f[i]); } sfree(f); } for(a=0; (a<atoms->nr); a++) { resind = atoms->atom[a].resind; if (bResname) { rnm = *(atoms->resinfo[resind].name); } else { rnm = *(atoms->resinfo[resind].rtp); } strcpy(atombuf,*(atoms->atomname[a])); bReorderedNum = FALSE; if (bReorderNum) { if (isdigit(atombuf[0])) { c = atombuf[0]; for (i=0; ((size_t)i<strlen(atombuf)-1); i++) { atombuf[i] = atombuf[i+1]; } atombuf[i] = c; bReorderedNum = TRUE; } } bRenamed = FALSE; for(i=0; (i<nxlate) && !bRenamed; i++) { /* Check if the base file name of the rtp and arn entry match */ if (restp == NULL || gmx_strcasecmp(restp[resind].filebase,xlatom[i].filebase) == 0) { /* Match the residue name */ bMatch = (xlatom[i].res == NULL || (gmx_strcasecmp("protein",xlatom[i].res) == 0 && gmx_residuetype_is_protein(rt,rnm)) || (gmx_strcasecmp("DNA",xlatom[i].res) == 0 && gmx_residuetype_is_dna(rt,rnm)) || (gmx_strcasecmp("RNA",xlatom[i].res) == 0 && gmx_residuetype_is_rna(rt,rnm))); if (!bMatch) { ptr0 = rnm; ptr1 = xlatom[i].res; while (ptr0[0] != '\0' && ptr1[0] != '\0' && (ptr0[0] == ptr1[0] || ptr1[0] == '?')) { ptr0++; ptr1++; } bMatch = (ptr0[0] == '\0' && ptr1[0] == '\0'); } if (bMatch && strcmp(atombuf,xlatom[i].atom) == 0) { /* We have a match. */ /* Don't free the old atomname, * since it might be in the symtab. */ ptr0 = strdup(xlatom[i].replace); if (bVerbose) { printf("Renaming atom '%s' in residue %d %s to '%s'\n", *atoms->atomname[a], atoms->resinfo[resind].nr, *atoms->resinfo[resind].name, ptr0); } atoms->atomname[a] = put_symtab(symtab,ptr0); bRenamed = TRUE; } } } if (bReorderedNum && !bRenamed) { atoms->atomname[a] = put_symtab(symtab,atombuf); } } done_xlatom(nxlate,xlatom); }
void write_pdbfile_indexed(FILE *out, const char *title, t_atoms *atoms, rvec x[], int ePBC, matrix box, char chainid, int model_nr, atom_id nindex, atom_id index[], gmx_conect conect, gmx_bool bTerSepChains) { gmx_conect_t *gc = (gmx_conect_t *)conect; char resnm[6], nm[6], pdbform[128], pukestring[100]; atom_id i, ii; int resind, resnr, type; unsigned char resic, ch; real occup, bfac; gmx_bool bOccup; int nlongname = 0; int chainnum, lastchainnum; int lastresind, lastchainresind; gmx_residuetype_t rt; const char *p_restype; const char *p_lastrestype; gmx_residuetype_init(&rt); bromacs(pukestring, 99); fprintf(out, "TITLE %s\n", (title && title[0]) ? title : pukestring); if (bWideFormat) { fprintf(out, "REMARK This file does not adhere to the PDB standard\n"); fprintf(out, "REMARK As a result of, some programs may not like it\n"); } if (box && ( norm2(box[XX]) || norm2(box[YY]) || norm2(box[ZZ]) ) ) { gmx_write_pdb_box(out, ePBC, box); } if (atoms->pdbinfo) { /* Check whether any occupancies are set, in that case leave it as is, * otherwise set them all to one */ bOccup = TRUE; for (ii = 0; (ii < nindex) && bOccup; ii++) { i = index[ii]; bOccup = bOccup && (atoms->pdbinfo[i].occup == 0.0); } } else { bOccup = FALSE; } fprintf(out, "MODEL %8d\n", model_nr > 0 ? model_nr : 1); lastchainresind = -1; lastchainnum = -1; resind = -1; p_restype = NULL; for (ii = 0; ii < nindex; ii++) { i = index[ii]; lastresind = resind; resind = atoms->atom[i].resind; chainnum = atoms->resinfo[resind].chainnum; p_lastrestype = p_restype; gmx_residuetype_get_type(rt, *atoms->resinfo[resind].name, &p_restype); /* Add a TER record if we changed chain, and if either the previous or this chain is protein/DNA/RNA. */ if (bTerSepChains && ii > 0 && chainnum != lastchainnum) { /* Only add TER if the previous chain contained protein/DNA/RNA. */ if (gmx_residuetype_is_protein(rt, p_lastrestype) || gmx_residuetype_is_dna(rt, p_lastrestype) || gmx_residuetype_is_rna(rt, p_lastrestype)) { fprintf(out, "TER\n"); } lastchainnum = chainnum; lastchainresind = lastresind; } strncpy(resnm, *atoms->resinfo[resind].name, sizeof(resnm)-1); strncpy(nm, *atoms->atomname[i], sizeof(nm)-1); /* rename HG12 to 2HG1, etc. */ xlate_atomname_gmx2pdb(nm); resnr = atoms->resinfo[resind].nr; resic = atoms->resinfo[resind].ic; if (chainid != ' ') { ch = chainid; } else { ch = atoms->resinfo[resind].chainid; if (ch == 0) { ch = ' '; } } if (resnr >= 10000) { resnr = resnr % 10000; } if (atoms->pdbinfo) { type = atoms->pdbinfo[i].type; occup = bOccup ? 1.0 : atoms->pdbinfo[i].occup; bfac = atoms->pdbinfo[i].bfac; } else { type = 0; occup = 1.0; bfac = 0.0; } if (bWideFormat) { strcpy(pdbform, "%-6s%5u %-4.4s %3.3s %c%4d%c %10.5f%10.5f%10.5f%8.4f%8.4f %2s\n"); } else { /* Check whether atomname is an element name */ if ((strlen(nm) < 4) && (gmx_strcasecmp(nm, atoms->atom[i].elem) != 0)) { strcpy(pdbform, pdbformat); } else { strcpy(pdbform, pdbformat4); if (strlen(nm) > 4) { int maxwln = 20; if (nlongname < maxwln) { fprintf(stderr, "WARNING: Writing out atom name (%s) longer than 4 characters to .pdb file\n", nm); } else if (nlongname == maxwln) { fprintf(stderr, "WARNING: More than %d long atom names, will not write more warnings\n", maxwln); } nlongname++; } } strcat(pdbform, "%6.2f%6.2f %2s\n"); } fprintf(out, pdbform, pdbtp[type], (i+1)%100000, nm, resnm, ch, resnr, (resic == '\0') ? ' ' : resic, 10*x[i][XX], 10*x[i][YY], 10*x[i][ZZ], occup, bfac, atoms->atom[i].elem); if (atoms->pdbinfo && atoms->pdbinfo[i].bAnisotropic) { fprintf(out, "ANISOU%5u %-4.4s%3.3s %c%4d%c %7d%7d%7d%7d%7d%7d\n", (i+1)%100000, nm, resnm, ch, resnr, (resic == '\0') ? ' ' : resic, atoms->pdbinfo[i].uij[0], atoms->pdbinfo[i].uij[1], atoms->pdbinfo[i].uij[2], atoms->pdbinfo[i].uij[3], atoms->pdbinfo[i].uij[4], atoms->pdbinfo[i].uij[5]); } } fprintf(out, "TER\n"); fprintf(out, "ENDMDL\n"); if (NULL != gc) { /* Write conect records */ for (i = 0; (i < gc->nconect); i++) { fprintf(out, "CONECT%5d%5d\n", gc->conect[i].ai+1, gc->conect[i].aj+1); } } gmx_residuetype_destroy(rt); }