int read_ter_db(const char *ffdir, char ter, t_hackblock **tbptr, gpp_atomtype_t atype) { char ext[STRLEN]; int ntb; sprintf(ext, ".%c.tdb", ter); /* Search for termini database files. * Do not generate an error when none are found. */ std::vector<std::string> tdbf = fflib_search_file_end(ffdir, ext, FALSE); ntb = 0; *tbptr = nullptr; for (const auto &filename : tdbf) { read_ter_db_file(filename.c_str(), &ntb, tbptr, atype); } if (debug) { print_ter_db("new", ter, ntb, *tbptr, atype); } return ntb; }
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; }