static void read_prop(gmx_atomprop_t aps, int eprop, double factor) { gmx_atomprop *ap2 = (gmx_atomprop*) aps; FILE *fp; char line[STRLEN], resnm[32], atomnm[32]; double pp; int line_no; aprop_t *ap; ap = &ap2->prop[eprop]; fp = libopen(ap->db); line_no = 0; while (get_a_line(fp, line, STRLEN)) { line_no++; if (sscanf(line, "%31s %31s %20lf", resnm, atomnm, &pp) == 3) { pp *= factor; add_prop(ap, aps->restype, resnm, atomnm, pp, line_no); } else { fprintf(stderr, "WARNING: Error in file %s at line %d ignored\n", ap->db, line_no); } } /* for libraries we can use the low-level close routines */ gmx_ffclose(fp); ap->bSet = TRUE; }
int get_strings(const char *db,char ***strings) { FILE *in; char **ptr; char buf[256]; int i,nstr; in=libopen(db); if (fscanf(in,"%d",&nstr) != 1) { gmx_warning("File %s is empty",db); ffclose(in); return 0; } snew(ptr,nstr); for(i=0; (i<nstr); i++) { if(1 != fscanf(in,"%s",buf)) { gmx_fatal(FARGS,"Cannot read string from buffer"); } #ifdef DEBUG fprintf(stderr,"Have read: %s\n",buf); #endif ptr[i] = strdup(buf); } ffclose(in); *strings=ptr; return nstr; }
int gmx_residuetype_init(gmx_residuetype_t **prt) { FILE * db; char line[STRLEN]; char resname[STRLEN], restype[STRLEN], dum[STRLEN]; gmx_residuetype_t *rt; snew(rt, 1); *prt = rt; rt->n = 0; rt->resname = NULL; rt->restype = NULL; db = libopen("residuetypes.dat"); while (get_a_line(db, line, STRLEN)) { strip_comment(line); trim(line); if (line[0] != '\0') { if (sscanf(line, "%1000s %1000s %1000s", resname, restype, dum) != 2) { gmx_fatal(FARGS, "Incorrect number of columns (2 expected) for line in residuetypes.dat"); } gmx_residuetype_add(rt, resname, restype); } } fclose(db); return 0; }
int get_file(const char *db,char ***strings) { FILE *in; char **ptr=NULL; char buf[STRLEN]; int i,nstr,maxi; in=libopen(db); i=maxi=0; while (fgets2(buf,STRLEN-1,in)) { if (i>=maxi) { maxi+=50; srenew(ptr,maxi); } ptr[i] = strdup(buf); i++; } nstr=i; ffclose(in); srenew(ptr,nstr); *strings=ptr; return nstr; }
Subfont* _getsubfont(Display *d, char *name) { int fd; Subfont *f; fd = libopen(name, OREAD); if(fd < 0){ _drawprint(2, "getsubfont: can't open %s: %r\n", name); return 0; } /* * unlock display so i/o happens with display released, unless * user is doing his own locking, in which case this could break things. * _getsubfont is called only from string.c and stringwidth.c, * which are known to be safe to have this done. */ if(d->local == 0) unlockdisplay(d); f = readsubfont(d, name, fd, d->local == 0); if(d->local == 0) lockdisplay(d); if(f == 0) _drawprint(2, "getsubfont: can't read %s: %r\n", name); libclose(fd); return f; }
t_fgrid *FGridFromFile(const char *infile) { FILE *in; char buf[STRLEN]; char *gmxlib; char newinfile[STRLEN]; t_fgrid *fgrid; t_fgroup *fgroup; t_fsimple *fsimple; int gridx,gridy; in = libopen(infile); GetBuf(in,buf); if (strcmp(buf,"grid")!=0) ReadDlgErr(infile,eGRIDEXP,buf); fgrid=NewFGrid(); if ((fscanf(in,"%d%d",&gridx,&gridy))!=2) ReadDlgErr(infile,eNOVALS,"grid w,h"); fgrid->w=gridx; fgrid->h=gridy; ReadAccOpen(infile,in); GetBuf(in,buf); while (bNotAccClose(buf)) { if (strcmp(buf,"group")==0) { fgroup=AddFGridFGroup(fgrid); ReadQuoteString(infile,in,buf); fgroup->name=strdup(buf); if ((fscanf(in,"%d%d%d%d",&fgroup->x,&fgroup->y,&fgroup->w,&fgroup->h))!=4) ReadDlgErr(infile,eNOVALS,"group x,y,w,h"); if (fgroup->x+fgroup->w > gridx) ReadDlgErr(infile,eTOOWIDE,buf); if (fgroup->y+fgroup->h > gridy) ReadDlgErr(infile,eTOOHIGH,buf); ReadAccOpen(infile,in); GetBuf(in,buf); while (bNotAccClose(buf)) { AddFGroupFItem(fgroup,ScanFItem(infile,in,buf)); GetBuf(in,buf); } } else if (strcmp(buf,"simple")==0) { fsimple=AddFGridFSimple(fgrid); if ((fscanf(in,"%d%d%d%d",&fsimple->x,&fsimple->y,&fsimple->w,&fsimple->h))!=4) ReadDlgErr(infile,eNOVALS,"simple x,y,w,h"); if (fsimple->x+fsimple->w > gridx) ReadDlgErr(infile,eTOOWIDE,"simple"); if (fsimple->y+fsimple->h > gridy) ReadDlgErr(infile,eTOOHIGH,"simple"); ReadAccOpen(infile,in); GetBuf(in,buf); fsimple->fitem=ScanFItem(infile,in,buf); ReadAccClose(infile,in); } GetBuf(in,buf); } fclose(in); return fgrid; }
gmx_neutron_atomic_structurefactors_t *gmx_neutronstructurefactors_init(const char *datfn) { /* read nsfactor.dat */ FILE *fp; char line[STRLEN]; int nralloc = 10; int n, p; int i, line_no; char atomnm[8]; double slength; gmx_neutron_atomic_structurefactors_t *gnsf; fp = libopen(datfn); line_no = 0; /* allocate memory for structure */ snew(gnsf, nralloc); snew(gnsf->atomnm, nralloc); snew(gnsf->p, nralloc); snew(gnsf->n, nralloc); snew(gnsf->slength, nralloc); gnsf->nratoms = line_no; while (get_a_line(fp, line, STRLEN)) { i = line_no; if (sscanf(line, "%s %d %d %lf", atomnm, &p, &n, &slength) == 4) { gnsf->atomnm[i] = strdup(atomnm); gnsf->n[i] = n; gnsf->p[i] = p; gnsf->slength[i] = slength; line_no++; gnsf->nratoms = line_no; if (line_no == nralloc) { nralloc++; srenew(gnsf->atomnm, nralloc); srenew(gnsf->p, nralloc); srenew(gnsf->n, nralloc); srenew(gnsf->slength, nralloc); } } else { fprintf(stderr, "WARNING: Error in file %s at line %d ignored\n", datfn, line_no); } } srenew(gnsf->atomnm, gnsf->nratoms); srenew(gnsf->p, gnsf->nratoms); srenew(gnsf->n, gnsf->nratoms); srenew(gnsf->slength, gnsf->nratoms); fclose(fp); return (gmx_neutron_atomic_structurefactors_t *) gnsf; }
int get_lines(const char *db,char ***strings) { FILE *in; int nstr; in = libopen(db); nstr = fget_lines(in,strings); ffclose(in); return nstr; }
int readcmap(char *fn,t_mapping **map) { FILE *in; int n; in=libopen(fn); n=getcmap(in,fn,map); gmx_fio_fclose(in); return n; }
int read_h_db(char *fn,t_hackblock **ah) { FILE *in; char hfn[STRLEN], line[STRLEN], buf[STRLEN]; int i, n, nab, nah; t_hackblock *aah; sprintf(hfn,"%s.hdb",fn); in=libopen(hfn); if (debug) fprintf(debug,"Hydrogen Database (%s):\n",hfn); nah=0; aah=NULL; while (fgets2(line,STRLEN-1,in)) { if (sscanf(line,"%s%n",buf,&n) != 1) { fprintf(stderr,"Error in hdb file: nah = %d\nline = '%s'\n", nah,line); break; } if (debug) fprintf(debug,"%s",buf); srenew(aah,nah+1); clear_t_hackblock(&aah[nah]); aah[nah].name=strdup(buf); if (sscanf(line+n,"%d",&nab) == 1) { if (debug) fprintf(debug," %d\n",nab); snew(aah[nah].hack,nab); aah[nah].nhack = nab; for(i=0; (i<nab); i++) { if (feof(in)) gmx_fatal(FARGS, "Expected %d lines of hydrogens, found only %d " "while reading Hydrogen Database %s residue %s", nab, i-1, aah[nah].name, hfn); if(NULL==fgets(buf, STRLEN, in)) { gmx_fatal(FARGS,"Error reading from file %s",fn); } read_ab(buf,hfn,&(aah[nah].hack[i])); } } nah++; } fclose(in); /* Sort the list (necessary to be able to use bsearch */ qsort(aah,nah,(size_t)sizeof(**ah),compaddh); if (debug) dump_h_db(fn,nah,aah); *ah=aah; return nah; }
static t_shiftdata *read_shifts(const char *fn) { FILE *fp; double xx; int i, j, nx, ny; t_shiftdata *sd; snew(sd, 1); fp = libopen(fn); if (2 != fscanf(fp, "%d%d", &nx, &ny)) { gmx_fatal(FARGS, "Error reading from file %s", fn); } sd->nx = nx; sd->ny = ny; sd->dx = nx/(2*M_PI); sd->dy = ny/(2*M_PI); snew(sd->data, nx+1); for (i = 0; (i <= nx); i++) { snew(sd->data[i], ny+1); for (j = 0; (j < ny); j++) { if (i == nx) { sd->data[i][j] = sd->data[0][j]; } else { if (1 != fscanf(fp, "%lf", &xx)) { gmx_fatal(FARGS, "Error reading from file %s", fn); } sd->data[i][j] = xx; } } sd->data[i][j] = sd->data[i][0]; } ffclose(fp); if (bDebugMode()) { dump_sd(fn, sd); } return sd; }
static t_2morse *read_dissociation_energies(int *n2morse) { FILE *fp; char ai[32], aj[32]; double e_diss; const char *fn = "edissoc.dat"; t_2morse *t2m = NULL; int maxn2m = 0, n2m = 0; int nread; /* Open the file with dissociation energies */ fp = libopen(fn); do { /* Try and read two atom names and an energy term from it */ nread = fscanf(fp, "%s%s%lf", ai, aj, &e_diss); if (nread == 3) { /* If we got three terms, it probably was OK, no further checking */ if (n2m >= maxn2m) { /* Increase memory for 16 at once, some mallocs are stupid */ maxn2m += 16; srenew(t2m, maxn2m); } /* Copy the values */ t2m[n2m].ai = strdup(ai); t2m[n2m].aj = strdup(aj); t2m[n2m].e_diss = e_diss; /* Increment counter */ n2m++; } /* If we did not read three items, quit reading */ } while (nread == 3); ffclose(fp); /* Set the return values */ *n2morse = n2m; return t2m; }
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); }
int gmx_do_dssp(int argc, char *argv[]) { const char *desc[] = { "[THISMODULE] ", "reads a trajectory file and computes the secondary structure for", "each time frame ", "calling the dssp program. If you do not have the dssp program,", "get it from http://swift.cmbi.ru.nl/gv/dssp. [THISMODULE] assumes ", "that the dssp executable is located in ", "[TT]/usr/local/bin/dssp[tt]. If this is not the case, then you should", "set an environment variable [TT]DSSP[tt] pointing to the dssp", "executable, e.g.: [PAR]", "[TT]setenv DSSP /opt/dssp/bin/dssp[tt][PAR]", "Since version 2.0.0, dssp is invoked with a syntax that differs", "from earlier versions. If you have an older version of dssp,", "use the [TT]-ver[tt] option to direct do_dssp to use the older syntax.", "By default, do_dssp uses the syntax introduced with version 2.0.0.", "Even newer versions (which at the time of writing are not yet released)", "are assumed to have the same syntax as 2.0.0.[PAR]", "The structure assignment for each residue and time is written to an", "[TT].xpm[tt] matrix file. This file can be visualized with for instance", "[TT]xv[tt] and can be converted to postscript with [TT]xpm2ps[tt].", "Individual chains are separated by light grey lines in the [TT].xpm[tt] and", "postscript files.", "The number of residues with each secondary structure type and the", "total secondary structure ([TT]-sss[tt]) count as a function of", "time are also written to file ([TT]-sc[tt]).[PAR]", "Solvent accessible surface (SAS) per residue can be calculated, both in", "absolute values (A^2) and in fractions of the maximal accessible", "surface of a residue. The maximal accessible surface is defined as", "the accessible surface of a residue in a chain of glycines.", "[BB]Note[bb] that the program [gmx-sas] can also compute SAS", "and that is more efficient.[PAR]", "Finally, this program can dump the secondary structure in a special file", "[TT]ssdump.dat[tt] for usage in the program [gmx-chi]. Together", "these two programs can be used to analyze dihedral properties as a", "function of secondary structure type." }; static gmx_bool bVerbose; static const char *ss_string = "HEBT"; static int dsspVersion = 2; t_pargs pa[] = { { "-v", FALSE, etBOOL, {&bVerbose}, "HIDDENGenerate miles of useless information" }, { "-sss", FALSE, etSTR, {&ss_string}, "Secondary structures for structure count"}, { "-ver", FALSE, etINT, {&dsspVersion}, "DSSP major version. Syntax changed with version 2"} }; t_trxstatus *status; FILE *tapein; FILE *ss, *acc, *fTArea, *tmpf; const char *fnSCount, *fnArea, *fnTArea, *fnAArea; const char *leg[] = { "Phobic", "Phylic" }; t_topology top; int ePBC; t_atoms *atoms; t_matrix mat; int nres, nr0, naccr, nres_plus_separators; gmx_bool *bPhbres, bDoAccSurf; real t; int i, j, natoms, nframe = 0; matrix box; int gnx; char *grpnm, *ss_str; atom_id *index; rvec *xp, *x; int *average_area; real **accr, *accr_ptr = NULL, *av_area, *norm_av_area; char pdbfile[32], tmpfile[32], title[256]; char dssp[256]; const char *dptr; output_env_t oenv; gmx_rmpbc_t gpbc = NULL; t_filenm fnm[] = { { efTRX, "-f", NULL, ffREAD }, { efTPS, NULL, NULL, ffREAD }, { efNDX, NULL, NULL, ffOPTRD }, { efDAT, "-ssdump", "ssdump", ffOPTWR }, { efMAP, "-map", "ss", ffLIBRD }, { efXPM, "-o", "ss", ffWRITE }, { efXVG, "-sc", "scount", ffWRITE }, { efXPM, "-a", "area", ffOPTWR }, { efXVG, "-ta", "totarea", ffOPTWR }, { efXVG, "-aa", "averarea", ffOPTWR } }; #define NFILE asize(fnm) if (!parse_common_args(&argc, argv, PCA_CAN_TIME | PCA_CAN_VIEW | PCA_TIME_UNIT | PCA_BE_NICE, NFILE, fnm, asize(pa), pa, asize(desc), desc, 0, NULL, &oenv)) { return 0; } fnSCount = opt2fn("-sc", NFILE, fnm); fnArea = opt2fn_null("-a", NFILE, fnm); fnTArea = opt2fn_null("-ta", NFILE, fnm); fnAArea = opt2fn_null("-aa", NFILE, fnm); bDoAccSurf = (fnArea || fnTArea || fnAArea); read_tps_conf(ftp2fn(efTPS, NFILE, fnm), title, &top, &ePBC, &xp, NULL, box, FALSE); atoms = &(top.atoms); check_oo(atoms); bPhbres = bPhobics(atoms); get_index(atoms, ftp2fn_null(efNDX, NFILE, fnm), 1, &gnx, &index, &grpnm); nres = 0; nr0 = -1; for (i = 0; (i < gnx); i++) { if (atoms->atom[index[i]].resind != nr0) { nr0 = atoms->atom[index[i]].resind; nres++; } } fprintf(stderr, "There are %d residues in your selected group\n", nres); strcpy(pdbfile, "ddXXXXXX"); gmx_tmpnam(pdbfile); if ((tmpf = fopen(pdbfile, "w")) == NULL) { sprintf(pdbfile, "%ctmp%cfilterXXXXXX", DIR_SEPARATOR, DIR_SEPARATOR); gmx_tmpnam(pdbfile); if ((tmpf = fopen(pdbfile, "w")) == NULL) { gmx_fatal(FARGS, "Can not open tmp file %s", pdbfile); } } else { fclose(tmpf); } strcpy(tmpfile, "ddXXXXXX"); gmx_tmpnam(tmpfile); if ((tmpf = fopen(tmpfile, "w")) == NULL) { sprintf(tmpfile, "%ctmp%cfilterXXXXXX", DIR_SEPARATOR, DIR_SEPARATOR); gmx_tmpnam(tmpfile); if ((tmpf = fopen(tmpfile, "w")) == NULL) { gmx_fatal(FARGS, "Can not open tmp file %s", tmpfile); } } else { fclose(tmpf); } if ((dptr = getenv("DSSP")) == NULL) { dptr = "/usr/local/bin/dssp"; } if (!gmx_fexist(dptr)) { gmx_fatal(FARGS, "DSSP executable (%s) does not exist (use setenv DSSP)", dptr); } if (dsspVersion >= 2) { if (dsspVersion > 2) { printf("\nWARNING: You use DSSP version %d, which is not explicitly\nsupported by do_dssp. Assuming version 2 syntax.\n\n", dsspVersion); } sprintf(dssp, "%s -i %s -o %s > /dev/null %s", dptr, pdbfile, tmpfile, bVerbose ? "" : "2> /dev/null"); } else { sprintf(dssp, "%s %s %s %s > /dev/null %s", dptr, bDoAccSurf ? "" : "-na", pdbfile, tmpfile, bVerbose ? "" : "2> /dev/null"); } fprintf(stderr, "dssp cmd='%s'\n", dssp); if (fnTArea) { fTArea = xvgropen(fnTArea, "Solvent Accessible Surface Area", output_env_get_xvgr_tlabel(oenv), "Area (nm\\S2\\N)", oenv); xvgr_legend(fTArea, 2, leg, oenv); } else { fTArea = NULL; } mat.map = NULL; mat.nmap = getcmap(libopen(opt2fn("-map", NFILE, fnm)), opt2fn("-map", NFILE, fnm), &(mat.map)); natoms = read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &x, box); if (natoms > atoms->nr) { gmx_fatal(FARGS, "\nTrajectory does not match topology!"); } if (gnx > natoms) { gmx_fatal(FARGS, "\nTrajectory does not match selected group!"); } snew(average_area, atoms->nres); snew(av_area, atoms->nres); snew(norm_av_area, atoms->nres); accr = NULL; naccr = 0; gpbc = gmx_rmpbc_init(&top.idef, ePBC, natoms); do { t = output_env_conv_time(oenv, t); if (bDoAccSurf && nframe >= naccr) { naccr += 10; srenew(accr, naccr); for (i = naccr-10; i < naccr; i++) { snew(accr[i], 2*atoms->nres-1); } } gmx_rmpbc(gpbc, natoms, box, x); tapein = gmx_ffopen(pdbfile, "w"); write_pdbfile_indexed(tapein, NULL, atoms, x, ePBC, box, ' ', -1, gnx, index, NULL, TRUE); gmx_ffclose(tapein); #ifdef GMX_NO_SYSTEM printf("Warning-- No calls to system(3) supported on this platform."); printf("Warning-- Skipping execution of 'system(\"%s\")'.", dssp); exit(1); #else if (0 != system(dssp)) { gmx_fatal(FARGS, "Failed to execute command: %s\n", "Try specifying your dssp version with the -ver option.", dssp); } #endif /* strip_dssp returns the number of lines found in the dssp file, i.e. * the number of residues plus the separator lines */ if (bDoAccSurf) { accr_ptr = accr[nframe]; } nres_plus_separators = strip_dssp(tmpfile, nres, bPhbres, t, accr_ptr, fTArea, &mat, average_area, oenv); remove(tmpfile); remove(pdbfile); nframe++; } while (read_next_x(oenv, status, &t, x, box)); fprintf(stderr, "\n"); close_trj(status); if (fTArea) { gmx_ffclose(fTArea); } gmx_rmpbc_done(gpbc); prune_ss_legend(&mat); ss = opt2FILE("-o", NFILE, fnm, "w"); mat.flags = 0; write_xpm_m(ss, mat); gmx_ffclose(ss); if (opt2bSet("-ssdump", NFILE, fnm)) { ss = opt2FILE("-ssdump", NFILE, fnm, "w"); snew(ss_str, nres+1); fprintf(ss, "%d\n", nres); for (j = 0; j < mat.nx; j++) { for (i = 0; (i < mat.ny); i++) { ss_str[i] = mat.map[mat.matrix[j][i]].code.c1; } ss_str[i] = '\0'; fprintf(ss, "%s\n", ss_str); } gmx_ffclose(ss); sfree(ss_str); } analyse_ss(fnSCount, &mat, ss_string, oenv); if (bDoAccSurf) { write_sas_mat(fnArea, accr, nframe, nres_plus_separators, &mat); for (i = 0; i < atoms->nres; i++) { av_area[i] = (average_area[i] / (real)nframe); } norm_acc(atoms, nres, av_area, norm_av_area); if (fnAArea) { acc = xvgropen(fnAArea, "Average Accessible Area", "Residue", "A\\S2", oenv); for (i = 0; (i < nres); i++) { fprintf(acc, "%5d %10g %10g\n", i+1, av_area[i], norm_av_area[i]); } gmx_ffclose(acc); } } view_all(oenv, NFILE, fnm); return 0; }
int main(int argc,char *argv[]) { static char *desc[] = { "do_dssp ", "reads a trajectory file and computes the secondary structure for", "each time frame ", "calling the dssp program. If you do not have the dssp program,", "get it. do_dssp assumes that the dssp executable is", "/usr/local/bin/dssp. If this is not the case, then you should", "set an environment variable [BB]DSSP[bb] pointing to the dssp", "executable, e.g.: [PAR]", "[TT]setenv DSSP /opt/dssp/bin/dssp[tt][PAR]", "The structure assignment for each residue and time is written to an", "[TT].xpm[tt] matrix file. This file can be visualized with for instance", "[TT]xv[tt] and can be converted to postscript with [TT]xpm2ps[tt].", "The number of residues with each secondary structure type and the", "total secondary structure ([TT]-sss[tt]) count as a function of", "time are also written to file ([TT]-sc[tt]).[PAR]", "Solvent accessible surface (SAS) per residue can be calculated, both in", "absolute values (A^2) and in fractions of the maximal accessible", "surface of a residue. The maximal accessible surface is defined as", "the accessible surface of a residue in a chain of glycines.", "[BB]Note[bb] that the program [TT]g_sas[tt] can also compute SAS", "and that is more efficient.[PAR]", "Finally, this program can dump the secondary structure in a special file", "[TT]ssdump.dat[tt] for usage in the program [TT]g_chi[tt]. Together", "these two programs can be used to analyze dihedral properties as a", "function of secondary structure type." }; static bool bVerbose; static char *ss_string="HEBT"; t_pargs pa[] = { { "-v", FALSE, etBOOL, {&bVerbose}, "HIDDENGenerate miles of useless information" }, { "-sss", FALSE, etSTR, {&ss_string}, "Secondary structures for structure count"} }; int status; FILE *tapein; FILE *ss,*acc,*fTArea,*tmpf; char *fnSCount,*fnArea,*fnTArea,*fnAArea; char *leg[] = { "Phobic", "Phylic" }; t_topology top; int ePBC; t_atoms *atoms; t_matrix mat; int nres,nr0,naccr; bool *bPhbres,bDoAccSurf; real t; int i,j,natoms,nframe=0; matrix box; int gnx; char *grpnm,*ss_str; atom_id *index; rvec *xp,*x; int *average_area; real **accr,*av_area, *norm_av_area; char pdbfile[32],tmpfile[32],title[256]; char dssp[256],*dptr; t_filenm fnm[] = { { efTRX, "-f", NULL, ffREAD }, { efTPS, NULL, NULL, ffREAD }, { efNDX, NULL, NULL, ffOPTRD }, { efDAT, "-ssdump", "ssdump", ffOPTWR }, { efMAP, "-map", "ss", ffLIBRD }, { efXPM, "-o", "ss", ffWRITE }, { efXVG, "-sc", "scount", ffWRITE }, { efXPM, "-a", "area", ffOPTWR }, { efXVG, "-ta", "totarea", ffOPTWR }, { efXVG, "-aa", "averarea",ffOPTWR } }; #define NFILE asize(fnm) CopyRight(stderr,argv[0]); parse_common_args(&argc,argv,PCA_CAN_TIME | PCA_CAN_VIEW | PCA_TIME_UNIT | PCA_BE_NICE , NFILE,fnm, asize(pa),pa, asize(desc),desc,0,NULL); fnSCount= opt2fn("-sc",NFILE,fnm); fnArea = opt2fn_null("-a", NFILE,fnm); fnTArea = opt2fn_null("-ta",NFILE,fnm); fnAArea = opt2fn_null("-aa",NFILE,fnm); bDoAccSurf=(fnArea || fnTArea || fnAArea); read_tps_conf(ftp2fn(efTPS,NFILE,fnm),title,&top,&ePBC,&xp,NULL,box,FALSE); atoms=&(top.atoms); check_oo(atoms); bPhbres=bPhobics(atoms); get_index(atoms,ftp2fn_null(efNDX,NFILE,fnm),1,&gnx,&index,&grpnm); nres=0; nr0=-1; for(i=0; (i<gnx); i++) { if (atoms->atom[index[i]].resnr != nr0) { nr0=atoms->atom[index[i]].resnr; nres++; } } fprintf(stderr,"There are %d residues in your selected group\n",nres); strcpy(pdbfile,"ddXXXXXX"); gmx_tmpnam(pdbfile); if ((tmpf = fopen(pdbfile,"w")) == NULL) { sprintf(pdbfile,"%ctmp%cfilterXXXXXX",DIR_SEPARATOR,DIR_SEPARATOR); gmx_tmpnam(pdbfile); if ((tmpf = fopen(pdbfile,"w")) == NULL) gmx_fatal(FARGS,"Can not open tmp file %s",pdbfile); } else fclose(tmpf); strcpy(tmpfile,"ddXXXXXX"); gmx_tmpnam(tmpfile); if ((tmpf = fopen(tmpfile,"w")) == NULL) { sprintf(tmpfile,"%ctmp%cfilterXXXXXX",DIR_SEPARATOR,DIR_SEPARATOR); gmx_tmpnam(tmpfile); if ((tmpf = fopen(tmpfile,"w")) == NULL) gmx_fatal(FARGS,"Can not open tmp file %s",tmpfile); } else fclose(tmpf); if ((dptr=getenv("DSSP")) == NULL) dptr="/usr/local/bin/dssp"; if (!fexist(dptr)) gmx_fatal(FARGS,"DSSP executable (%s) does not exist (use setenv DSSP)", dptr); sprintf(dssp,"%s %s %s %s > /dev/null %s", dptr,bDoAccSurf?"":"-na",pdbfile,tmpfile,bVerbose?"":"2> /dev/null"); if (bVerbose) fprintf(stderr,"dssp cmd='%s'\n",dssp); if (fnTArea) { fTArea=xvgropen(fnTArea,"Solvent Accessible Surface Area", xvgr_tlabel(),"Area (nm\\S2\\N)"); xvgr_legend(fTArea,2,leg); } else fTArea=NULL; mat.map=NULL; mat.nmap=getcmap(libopen(opt2fn("-map",NFILE,fnm)), opt2fn("-map",NFILE,fnm),&(mat.map)); natoms=read_first_x(&status,ftp2fn(efTRX,NFILE,fnm),&t,&x,box); if (natoms > atoms->nr) gmx_fatal(FARGS,"\nTrajectory does not match topology!"); if (gnx > natoms) gmx_fatal(FARGS,"\nTrajectory does not match selected group!"); snew(average_area,atoms->nres+10); snew(av_area,atoms->nres+10); snew(norm_av_area,atoms->nres+10); accr=NULL; naccr=0; do { t = convert_time(t); if (nframe>=naccr) { naccr+=10; srenew(accr,naccr); for(i=naccr-10; i<naccr; i++) snew(accr[i],atoms->nres+10); } rm_pbc(&(top.idef),ePBC,natoms,box,x,x); tapein=ffopen(pdbfile,"w"); write_pdbfile_indexed(tapein,NULL,atoms,x,ePBC,box,0,-1,gnx,index); fclose(tapein); #ifdef GMX_NO_SYSTEM printf("Warning-- No calls to system(3) supported on this platform."); printf("Warning-- Skipping execution of 'system(\"%s\")'.", dssp); exit(1); #else if(0 != system(dssp)) { gmx_fatal(FARGS,"Failed to execute command: %s",dssp); } #endif strip_dssp(tmpfile,nres,bPhbres,t, accr[nframe],fTArea,&mat,average_area); remove(tmpfile); remove(pdbfile); nframe++; } while(read_next_x(status,&t,natoms,x,box)); fprintf(stderr,"\n"); close_trj(status); if (fTArea) ffclose(fTArea); prune_ss_legend(&mat); ss=opt2FILE("-o",NFILE,fnm,"w"); write_xpm_m(ss,mat); ffclose(ss); if (opt2bSet("-ssdump",NFILE,fnm)) { snew(ss_str,nres+1); for(i=0; (i<nres); i++) ss_str[i] = mat.map[mat.matrix[0][i]].code.c1; ss_str[i] = '\0'; ss = opt2FILE("-ssdump",NFILE,fnm,"w"); fprintf(ss,"%d\n%s\n",nres,ss_str); fclose(ss); sfree(ss_str); } analyse_ss(fnSCount,&mat,ss_string); if (bDoAccSurf) { write_sas_mat(fnArea,accr,nframe,nres,&mat); for(i=0; i<atoms->nres; i++) av_area[i] = (average_area[i] / (real)nframe); norm_acc(atoms, nres, av_area, norm_av_area); if (fnAArea) { acc=xvgropen(fnAArea,"Average Accessible Area", "Residue","A\\S2"); for(i=0; (i<nres); i++) fprintf(acc,"%5d %10g %10g\n",i+1,av_area[i], norm_av_area[i]); ffclose(acc); } } view_all(NFILE, fnm); thanx(stderr); return 0; }
FILE *findfontfile(const char *fontname) { int i; char tempname[256]; FILE *fd; /* Add subdirectory "fonts". We will try both with and */ /* without the subdirectory. */ sprintf(_STR, "fonts/%s", fontname); /* change string to all lowercase and remove dashes */ for (i = 0; i < strlen(_STR); i++) { _STR[i] = tolower(_STR[i]); if (_STR[i] == '-') _STR[i] = '_'; } /* Fprintf(stdout, "Searching for font file \"%s\"\n", _STR); */ /* Use the mechanism of "libopen" to find the encoding file */ /* in the search path */ fd = libopen(_STR + 6, FONTENCODING); if (fd == NULL) fd = libopen(_STR, FONTENCODING); /* Some other, probably futile, attempts (call findfontfile recursively) */ if (fd == NULL) { char *dashptr; /* If this font has a suffix, remove it and look for its root */ /* font on the supposition that this font is derived from the */ /* root font. */ strncpy(tempname, fontname, 99); if ((dashptr = strrchr(tempname, '-')) != NULL) { *dashptr = '\0'; if ((fd = findfontfile(tempname)) != NULL) return fd; /* And finally, because it's a common case, try adding */ /* -Roman and trying again (but don't infinite loop!) */ if (strcmp(dashptr + 1, "Roman")) { strcat(dashptr, "-Roman"); if ((fd = findfontfile(tempname)) != NULL) return fd; } } Wprintf("No font encoding file found."); if (fontcount > 0) { /* Make font substitution */ char *dchr, *psname = NULL; short fval; if ((dchr = strrchr(_STR, '.')) != NULL) *dchr = '\0'; if ((fval = findhelvetica()) == fontcount) { /* This will cause some chaos. . . */ Fprintf(stderr, "Error: No fonts available! Check library path?\n"); qApp->exit(1); return NULL; } psname = (char *)malloc((1 + strlen(fontname)) * sizeof(char)); strcpy(psname, fontname); Wprintf("No encoding file found for font %s: substituting %s", psname, fonts[fval].psname); fonts = (fontinfo *)realloc(fonts, (fontcount + 1) * sizeof(fontinfo)); fonts[fontcount].psname = psname; fonts[fontcount].family = psname; fonts[fontcount].encoding = fonts[fval].encoding; fonts[fontcount].flags = 0; fonts[fontcount].scale = 1.0; fontcount++; makenewfontbutton(); } else { Fprintf(stderr, "Error: font encoding file missing for font \"%s\"\n", fontname); Fprintf(stderr, "No fonts exist for a subsitution. Make sure " "fonts are installed or that\nenvironment variable " "XCIRCUIT_LIB_DIR points to a directory of valid fonts.\n"); } return (FILE *)NULL; } return fd; }
extern gmx_structurefactors_t *gmx_structurefactors_init(const char *datfn) { /* Read the database for the structure factor of the different atoms */ FILE *fp; char line[STRLEN]; gmx_structurefactors *gsf; double a1, a2, a3, a4, b1, b2, b3, b4, c; int p; int i; int nralloc = 10; int line_no; char atomn[32]; fp = libopen(datfn); line_no = 0; snew(gsf, 1); snew(gsf->atomnm, nralloc); snew(gsf->a, nralloc); snew(gsf->b, nralloc); snew(gsf->c, nralloc); snew(gsf->p, nralloc); gsf->n = NULL; gsf->nratoms = line_no; while (get_a_line(fp, line, STRLEN)) { i = line_no; if (sscanf(line, "%s %d %lf %lf %lf %lf %lf %lf %lf %lf %lf", atomn, &p, &a1, &a2, &a3, &a4, &b1, &b2, &b3, &b4, &c) == 11) { gsf->atomnm[i] = strdup(atomn); gsf->p[i] = p; snew(gsf->a[i], 4); snew(gsf->b[i], 4); gsf->a[i][0] = a1; gsf->a[i][1] = a2; gsf->a[i][2] = a3; gsf->a[i][3] = a4; gsf->b[i][0] = b1; gsf->b[i][1] = b2; gsf->b[i][2] = b3; gsf->b[i][3] = b4; gsf->c[i] = c; line_no++; gsf->nratoms = line_no; if (line_no == nralloc) { nralloc += 10; srenew(gsf->atomnm, nralloc); srenew(gsf->a, nralloc); srenew(gsf->b, nralloc); srenew(gsf->c, nralloc); srenew(gsf->p, nralloc); } } else { fprintf(stderr, "WARNING: Error in file %s at line %d ignored\n", datfn, line_no); } } srenew(gsf->atomnm, gsf->nratoms); srenew(gsf->a, gsf->nratoms); srenew(gsf->b, gsf->nratoms); srenew(gsf->c, gsf->nratoms); srenew(gsf->p, gsf->nratoms); fclose(fp); return (gmx_structurefactors_t *) gsf; }
int read_ter_db(char *FF,char ter,t_hackblock **tbptr,gpp_atomtype_t atype) { FILE *in; char inf[STRLEN],header[STRLEN],buf[STRLEN],line[STRLEN]; t_hackblock *tb; int i,j,n,ni,kwnr,nb,maxnb,nh; sprintf(inf,"%s-%c.tdb",FF,ter); in=libopen(inf); if (debug) fprintf(debug,"Opened %s\n",inf); tb=NULL; nb=-1; maxnb=0; kwnr=NOTSET; get_a_line(in,line,STRLEN); while (!feof(in)) { if (get_header(line,header)) { /* this is a new block, or a new keyword */ kwnr=find_kw(header); if (kwnr == NOTSET) { nb++; /* here starts a new block */ if ( nb >= maxnb ) { maxnb+=100; srenew(tb,maxnb); } clear_t_hackblock(&tb[nb]); tb[nb].name=strdup(header); } } else { if (nb < 0) gmx_fatal(FARGS,"reading termini database: " "directive expected before line:\n%s\n" "This might be a file in an old format.",line); /* this is not a header, so it must be data */ if (kwnr >= ebtsNR) { /* this is a hack: add/rename/delete atoms */ /* make space for hacks */ if (tb[nb].nhack >= tb[nb].maxhack) { tb[nb].maxhack+=10; srenew(tb[nb].hack, tb[nb].maxhack); } nh=tb[nb].nhack; clear_t_hack(&(tb[nb].hack[nh])); for(i=0; i<4; i++) tb[nb].hack[nh].a[i]=NULL; tb[nb].nhack++; /* get data */ n=0; if ( kwnr==ekwRepl || kwnr==ekwDel ) { if (sscanf(line, "%s%n", buf, &n) != 1) gmx_fatal(FARGS,"Reading Termini Database: " "expected atom name on line\n%s",line); tb[nb].hack[nh].oname = strdup(buf); /* we only replace or delete one atom at a time */ tb[nb].hack[nh].nr = 1; } else if ( kwnr==ekwAdd ) { read_ab(line, inf, &(tb[nb].hack[nh])); get_a_line(in, line, STRLEN); } else gmx_fatal(FARGS,"unimplemented keyword number %d (%s:%d)", kwnr,__FILE__,__LINE__); if ( kwnr==ekwRepl || kwnr==ekwAdd ) { snew(tb[nb].hack[nh].atom, 1); read_atom(line+n, tb[nb].hack[nh].atom, atype, &tb[nb].hack[nh].cgnr); if (!tb[nb].hack[nh].nname) { if (tb[nb].hack[nh].oname) tb[nb].hack[nh].nname = strdup(tb[nb].hack[nh].oname); else gmx_fatal(FARGS,"Don't know which name the new atom should have"); } } } else if (kwnr >= 0 && kwnr < ebtsNR) { /* this is bonded data: bonds, angles, dihedrals or impropers */ srenew(tb[nb].rb[kwnr].b,tb[nb].rb[kwnr].nb+1); n=0; for(j=0; j<btsNiatoms[kwnr]; j++) { if ( sscanf(line+n, "%s%n", buf, &ni) == 1 ) tb[nb].rb[kwnr].b[tb[nb].rb[kwnr].nb].a[j] = strdup(buf); else gmx_fatal(FARGS,"Reading Termini Database: expected %d atom names (found %d) on line\n%s", btsNiatoms[kwnr], j-1, line); n+=ni; } for( ; j<MAXATOMLIST; j++) tb[nb].rb[kwnr].b[tb[nb].rb[kwnr].nb].a[j] = NULL; strcpy(buf, ""); sscanf(line+n, "%s", buf); tb[nb].rb[kwnr].b[tb[nb].rb[kwnr].nb].s = strdup(buf); tb[nb].rb[kwnr].nb++; } else gmx_fatal(FARGS,"Reading Termini Database: Expecting a header at line\n" "%s",line); } get_a_line(in,line,STRLEN); } nb++; srenew(tb,nb); fclose(in); if (debug) print_ter_db(FF,ter,nb,tb,atype); *tbptr=tb; return nb; }