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; }
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; }
static void read_h_db_file(const char *hfn,int *nahptr,t_hackblock **ah) { FILE *in; char filebase[STRLEN],line[STRLEN], buf[STRLEN]; int i, n, nab, nah; t_hackblock *aah; if (debug) fprintf(debug,"Hydrogen Database (%s):\n",hfn); fflib_filename_base(hfn,filebase,STRLEN); /* Currently filebase is read and set, but not used. * hdb entries from any hdb file and be applied to rtp entries * in any rtp file. */ in = fflib_open(hfn); nah = *nahptr; aah = *ah; 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); aah[nah].filebase = strdup(filebase); 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",hfn); } read_ab(buf,hfn,&(aah[nah].hack[i])); } } nah++; } ffclose(in); /* Sort the list (necessary to be able to use bsearch */ qsort(aah,nah,(size_t)sizeof(**ah),compaddh); /* if (debug) dump_h_db(hfn,nah,aah); */ *nahptr = nah; *ah = aah; }
static void read_ter_db_file(const char *fn, int *ntbptr, t_hackblock **tbptr, gpp_atomtype_t atype) { char filebase[STRLEN], *ptr; FILE *in; char header[STRLEN], buf[STRLEN], line[STRLEN]; t_hackblock *tb; int i, j, n, ni, kwnr, nb, maxnb, nh; fflib_filename_base(fn, filebase, STRLEN); /* Remove the C/N termini extension */ ptr = strrchr(filebase, '.'); if (ptr != nullptr) { ptr[0] = '\0'; } in = fflib_open(fn); tb = *tbptr; nb = *ntbptr - 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 = nb + 100; srenew(tb, maxnb); } clear_t_hackblock(&tb[nb]); tb[nb].name = gmx_strdup(header); tb[nb].filebase = gmx_strdup(filebase); } } 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] = nullptr; } 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 '%s': " "expected atom name on line\n%s", fn, line); } tb[nb].hack[nh].oname = gmx_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, fn, &(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, kwnr == ekwAdd, &tb[nb].hack[nh].nname, tb[nb].hack[nh].atom, atype, &tb[nb].hack[nh].cgnr); if (tb[nb].hack[nh].nname == nullptr) { if (tb[nb].hack[nh].oname != nullptr) { tb[nb].hack[nh].nname = gmx_strdup(tb[nb].hack[nh].oname); } else { gmx_fatal(FARGS, "Reading Termini Database '%s': don't know which name the new atom should have on line\n%s", fn, line); } } } } 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] = gmx_strdup(buf); } else { gmx_fatal(FARGS, "Reading Termini Database '%s': expected %d atom names (found %d) on line\n%s", fn, btsNiatoms[kwnr], j-1, line); } n += ni; } for (; j < MAXATOMLIST; j++) { tb[nb].rb[kwnr].b[tb[nb].rb[kwnr].nb].a[j] = nullptr; } strcpy(buf, ""); sscanf(line+n, "%s", buf); tb[nb].rb[kwnr].b[tb[nb].rb[kwnr].nb].s = gmx_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); gmx_ffclose(in); *ntbptr = nb; *tbptr = tb; }