void done_mdoutf(gmx_mdoutf_t of) { if (of->fp_ene != NULL) { close_enx(of->fp_ene); } if (of->fp_xtc) { close_xtc(of->fp_xtc); } if (of->fp_trn) { gmx_trr_close(of->fp_trn); } if (of->fp_dhdl != NULL) { gmx_fio_fclose(of->fp_dhdl); } if (of->fp_field != NULL) { /* This is opened sometimes with xvgropen, sometimes with * gmx_fio_fopen, so we use the least common denominator for closing. */ gmx_fio_fclose(of->fp_field); } gmx_tng_close(&of->tng); gmx_tng_close(&of->tng_low_prec); sfree(of); }
void done_mdoutf(gmx_mdoutf_t of) { if (of->fp_ene != NULL) { close_enx(of->fp_ene); } if (of->fp_xtc) { close_xtc(of->fp_xtc); } if (of->fp_trn) { close_trn(of->fp_trn); } if (of->fp_dhdl != NULL) { gmx_fio_fclose(of->fp_dhdl); } if (of->fp_field != NULL) { gmx_fio_fclose(of->fp_field); } gmx_tng_close(&of->tng); gmx_tng_close(&of->tng_low_prec); sfree(of); }
void write_sto_conf_indexed(const char *outfile, const char *title, t_atoms *atoms, rvec x[], rvec *v, int ePBC, matrix box, atom_id nindex, atom_id index[]) { FILE *out; int ftp; t_trxframe fr; ftp = fn2ftp(outfile); switch (ftp) { case efGRO: out = gmx_fio_fopen(outfile, "w"); write_hconf_indexed_p(out, title, atoms, nindex, index, 3, x, v, box); gmx_fio_fclose(out); break; case efG96: clear_trxframe(&fr, TRUE); fr.bTitle = TRUE; fr.title = title; fr.natoms = atoms->nr; fr.bAtoms = TRUE; fr.atoms = atoms; fr.bX = TRUE; fr.x = x; if (v) { fr.bV = TRUE; fr.v = v; } fr.bBox = TRUE; copy_mat(box, fr.box); out = gmx_fio_fopen(outfile, "w"); write_g96_conf(out, &fr, nindex, index); gmx_fio_fclose(out); break; case efPDB: case efBRK: case efENT: case efPQR: out = gmx_fio_fopen(outfile, "w"); write_pdbfile_indexed(out, title, atoms, x, ePBC, box, ' ', -1, nindex, index, NULL, TRUE); gmx_fio_fclose(out); break; case efESP: out = gmx_fio_fopen(outfile, "w"); write_espresso_conf_indexed(out, title, atoms, nindex, index, x, v, box); gmx_fio_fclose(out); break; case efTPR: case efTPB: case efTPA: gmx_fatal(FARGS, "Sorry, can not write a topology to %s", outfile); break; default: gmx_incons("Not supported in write_sto_conf_indexed"); } }
void finish_pull(FILE *fplog,t_pull *pull) { if (pull->out_x) { gmx_fio_fclose(pull->out_x); } if (pull->out_f) { gmx_fio_fclose(pull->out_f); } }
void finish_pull(t_pull *pull) { if (pull->out_x) { gmx_fio_fclose(pull->out_x); } if (pull->out_f) { gmx_fio_fclose(pull->out_f); } }
void get_stx_coordnum(const char *infile, int *natoms) { FILE *in; int ftp, tpxver, tpxgen; t_trxframe fr; char g96_line[STRLEN+1]; ftp = fn2ftp(infile); range_check(ftp, 0, efNR); switch (ftp) { case efGRO: get_coordnum(infile, natoms); break; case efG96: in = gmx_fio_fopen(infile, "r"); fr.title = NULL; fr.natoms = -1; fr.atoms = NULL; fr.x = NULL; fr.v = NULL; fr.f = NULL; *natoms = read_g96_conf(in, infile, &fr, g96_line); gmx_fio_fclose(in); break; case efPDB: case efBRK: case efENT: in = gmx_fio_fopen(infile, "r"); get_pdb_coordnum(in, natoms); gmx_fio_fclose(in); break; case efESP: *natoms = get_espresso_coordnum(infile); break; case efTPA: case efTPB: case efTPR: { t_tpxheader tpx; read_tpxheader(infile, &tpx, TRUE, &tpxver, &tpxgen); *natoms = tpx.natoms; break; } default: gmx_fatal(FARGS, "File type %s not supported in get_stx_coordnum", ftp2ext(ftp)); } }
static void print_rtp(const char *filenm, const char *title, t_atoms *atoms, t_params plist[], gpp_atomtype_t atype, int cgnr[]) { FILE *fp; int i, tp; char *tpnm; fp = gmx_fio_fopen(filenm, "w"); fprintf(fp, "; %s\n", title); fprintf(fp, "\n"); fprintf(fp, "[ %s ]\n", *atoms->resinfo[0].name); fprintf(fp, "\n"); fprintf(fp, "[ atoms ]\n"); for (i = 0; (i < atoms->nr); i++) { tp = atoms->atom[i].type; if ((tpnm = get_atomtype_name(tp, atype)) == NULL) { gmx_fatal(FARGS, "tp = %d, i = %d in print_rtp", tp, i); } fprintf(fp, "%-8s %12s %8.4f %5d\n", *atoms->atomname[i], tpnm, atoms->atom[i].q, cgnr[i]); } print_pl(fp, plist, F_BONDS, "bonds", atoms->atomname); print_pl(fp, plist, F_ANGLES, "angles", atoms->atomname); print_pl(fp, plist, F_PDIHS, "dihedrals", atoms->atomname); print_pl(fp, plist, F_IDIHS, "impropers", atoms->atomname); gmx_fio_fclose(fp); }
void write_inpfile(const char *fn,int ninp,t_inpfile inp[],gmx_bool bHaltOnUnknown, warninp_t wi) { FILE *out; int i; char warn_buf[STRLEN]; sort_inp(ninp,inp); out=gmx_fio_fopen(fn,"w"); nice_header(out,fn); for(i=0; (i<ninp); i++) { if (inp[i].bSet) { if(inp[i].name[0]==';' || (strlen(inp[i].name)>2 && inp[i].name[1]==';')) fprintf(out,"%-24s\n",inp[i].name); else fprintf(out,"%-24s = %s\n",inp[i].name,inp[i].value ? inp[i].value : ""); } else if (!inp[i].bObsolete) { sprintf(warn_buf,"Unknown left-hand '%s' in parameter file\n", inp[i].name); if (bHaltOnUnknown) { warning_error(wi,warn_buf); } else { warning(wi,warn_buf); } } } gmx_fio_fclose(out); check_warning_error(wi,FARGS); }
void gmx_log_close(FILE *fp) { if (fp) { gmx_fatal_set_log_file(NULL); gmx_fio_fclose(fp); } }
void write_sto_conf_mtop(const char *outfile, const char *title, gmx_mtop_t *mtop, rvec x[], rvec *v, int ePBC, matrix box) { int ftp; FILE *out; t_atoms atoms; ftp = fn2ftp(outfile); switch (ftp) { case efGRO: out = gmx_fio_fopen(outfile, "w"); write_hconf_mtop(out, title, mtop, 3, x, v, box); gmx_fio_fclose(out); break; default: /* This is a brute force approach which requires a lot of memory. * We should implement mtop versions of all writing routines. */ atoms = gmx_mtop_global_atoms(mtop); write_sto_conf(outfile, title, &atoms, x, v, ePBC, box); done_atom(&atoms); break; } }
void print_rgrid_pdb(char *fn,int nx,int ny,int nz,real ***grid) { FILE *fp; int ix,iy,iz,n,ig; real x,y,z,g; n=1; fp=gmx_fio_fopen(fn,"w"); for(ix=0; (ix<nx); ix++) { for(iy=0; (iy<ny); iy++) { for(iz=0; (iz<nz); iz++) { g=grid[ix][iy][iz]; ig=g; if ((ig != 0) || (1)) { x = 4*ix; y = 4*iy; z = 4*iz; fprintf(fp,"ATOM %5d Na Na 1 %8.3f%8.3f%8.3f%6.2f%6.2f\n", n++,x,y,z,0.0,g); } } } } gmx_fio_fclose(fp); }
int main(int argc,char *argv[]) { FILE *fp; int nnn[] = { 8, 10, 12, 15, 16, 18, 20, 24, 25, 27, 30, 32, 36, 40, 45, 48, 50, 54, 60, 64, 72, 75, 80, 81, 90, 100 }; #define NNN asize(nnn) int *niter; int i,j,n,nit,ntot,n3; double t,nflop; double *rt,*ct; t_complex ***g; real ***h; snew(rt,NNN); snew(ct,NNN); snew(niter,NNN); for(i=0; (i<NNN); i++) { n = nnn[i]; fprintf(stderr,"\rReal %d ",n); if (n < 16) niter[i] = 100; else if (n < 26) niter[i] = 50; else if (n < 51) niter[i] = 10; else niter[i] = 5; nit = niter[i]; h = mk_rgrid(n+2,n,n); start_time(); for(j=0; (j<nit); j++) { testrft(stdout,h,n,n,n,(j==0)); } update_time(); rt[i] = node_time(); free_rgrid(h,n,n); fprintf(stderr,"\rComplex %d ",n); g = mk_cgrid(n,n,n); start_time(); for(j=0; (j<nit); j++) { testfft(stdout,g,n,n,n,(j==0)); } update_time(); ct[i] = node_time(); free_cgrid(g,n,n); } fprintf(stderr,"\n"); fp=xvgropen("timing.xvg","FFT timings per grid point","n","t (s)"); for(i=0; (i<NNN); i++) { n3 = 2*niter[i]*nnn[i]*nnn[i]*nnn[i]; fprintf(fp,"%10d %10g %10g\n",nnn[i],rt[i]/n3,ct[i]/n3); } gmx_fio_fclose(fp); return 0; }
void ps_close(t_psdata ps) { fprintf(ps->fp, "%%showpage\n"); fprintf(ps->fp, "%%%%EOF\n"); gmx_fio_fclose(ps->fp); sfree(ps->rgb); sfree(ps); }
void writecmap(char *fn,int n,t_mapping map[]) { FILE *out; out=gmx_fio_fopen(fn,"w"); printcmap(out,n,map); gmx_fio_fclose(out); }
static void write_constr_pdb(const char *fn, const char *title, gmx_mtop_t *mtop, int start, int homenr, t_commrec *cr, rvec x[], matrix box) { char fname[STRLEN], format[STRLEN]; FILE *out; int dd_ac0 = 0, dd_ac1 = 0, i, ii, resnr; gmx_domdec_t *dd; char *anm, *resnm; dd = NULL; if (DOMAINDECOMP(cr)) { dd = cr->dd; dd_get_constraint_range(dd, &dd_ac0, &dd_ac1); start = 0; homenr = dd_ac1; } if (PAR(cr)) { sprintf(fname, "%s_n%d.pdb", fn, cr->sim_nodeid); } else { sprintf(fname, "%s.pdb", fn); } sprintf(format, "%s\n", get_pdbformat()); out = gmx_fio_fopen(fname, "w"); fprintf(out, "TITLE %s\n", title); gmx_write_pdb_box(out, -1, box); for (i = start; i < start+homenr; i++) { if (dd != NULL) { if (i >= dd->nat_home && i < dd_ac0) { continue; } ii = dd->gatindex[i]; } else { ii = i; } gmx_mtop_atominfo_global(mtop, ii, &anm, &resnr, &resnm); fprintf(out, format, "ATOM", (ii+1)%100000, anm, resnm, ' ', resnr%10000, ' ', 10*x[i][XX], 10*x[i][YY], 10*x[i][ZZ]); } fprintf(out, "TER\n"); gmx_fio_fclose(out); }
void gmx_pdb_read_conf(const char *infile, t_topology *top, rvec x[], int *ePBC, matrix box) { FILE *in = gmx_fio_fopen(infile, "r"); char title[STRLEN]; read_pdbfile(in, title, NULL, &top->atoms, &top->symtab, x, ePBC, box, TRUE, NULL); top->name = put_symtab(&top->symtab, title); gmx_fio_fclose(in); }
static void get_coordnum (const char *infile, int *natoms) { FILE *in; char title[STRLEN]; in = gmx_fio_fopen(infile, "r"); get_coordnum_fp(in, title, natoms); gmx_fio_fclose (in); }
void gmx_pdb_read_conf(const char *infile, t_symtab *symtab, char ***name, t_atoms *atoms, rvec x[], int *ePBC, matrix box) { FILE *in = gmx_fio_fopen(infile, "r"); char title[STRLEN]; read_pdbfile(in, title, NULL, atoms, symtab, x, ePBC, box, TRUE, NULL); *name = put_symtab(symtab, title); gmx_fio_fclose(in); }
void write_conf_p(char *outfile, char *title, t_atoms *atoms, int pr, rvec *x, rvec *v,matrix box) { FILE *out; out=gmx_fio_fopen(outfile,"w"); write_hconf_p(out,title,atoms,pr,x,v,box); gmx_fio_fclose (out); }
void pr_f(char *fn,int natoms,rvec f[]) { FILE *fp; int i; fp=gmx_fio_fopen(fn,"w"); for(i=0; (i<natoms); i++) fprintf(fp," %12.5e\n %12.5e\n %12.5e\n",f[i][XX],f[i][YY],f[i][ZZ]); gmx_fio_fclose(fp); }
static void get_stx_coordnum(const char *infile, int *natoms) { FILE *in; int ftp; t_trxframe fr; char g96_line[STRLEN+1]; ftp = fn2ftp(infile); range_check(ftp, 0, efNR); switch (ftp) { case efGRO: get_coordnum(infile, natoms); break; case efG96: { in = gmx_fio_fopen(infile, "r"); fr.title = NULL; fr.natoms = -1; fr.atoms = NULL; fr.x = NULL; fr.v = NULL; fr.f = NULL; *natoms = read_g96_conf(in, infile, &fr, NULL, g96_line); sfree(const_cast<char *>(fr.title)); gmx_fio_fclose(in); break; } case efPDB: case efBRK: case efENT: in = gmx_fio_fopen(infile, "r"); get_pdb_coordnum(in, natoms); gmx_fio_fclose(in); break; case efESP: *natoms = get_espresso_coordnum(infile); break; default: gmx_fatal(FARGS, "File type %s not supported in get_stx_coordnum", ftp2ext(ftp)); } }
void print_phi(char *fn,int natoms,rvec x[],real phi[]) { FILE *fp; int i; fp=gmx_fio_fopen(fn,"w"); for(i=0; (i<natoms); i++) fprintf(fp,"%10d %12.5e\n",i,phi[i]); gmx_fio_fclose(fp); }
void read_pdb_conf(char *infile,char *title, t_atoms *atoms,rvec x[],int *ePBC,matrix box,bool bChange, gmx_conect conect) { FILE *in; in = gmx_fio_fopen(infile,"r"); read_pdbfile(in,title,NULL,atoms,x,ePBC,box,bChange,conect); gmx_fio_fclose(in); }
static void read_stx_conf(const char *infile, t_topology *top, rvec x[], rvec *v, int *ePBC, matrix box) { FILE *in; t_trxframe fr; int ftp; char g96_line[STRLEN+1]; if (top->atoms.nr == 0) { fprintf(stderr, "Warning: Number of atoms in %s is 0\n", infile); } else if (top->atoms.atom == NULL) { gmx_mem("Uninitialized array atom"); } if (ePBC) { *ePBC = -1; } ftp = fn2ftp(infile); switch (ftp) { case efGRO: gmx_gro_read_conf(infile, top, x, v, box); break; case efG96: fr.title = NULL; fr.natoms = top->atoms.nr; fr.atoms = &top->atoms; fr.x = x; fr.v = v; fr.f = NULL; in = gmx_fio_fopen(infile, "r"); read_g96_conf(in, infile, &fr, &top->symtab, g96_line); gmx_fio_fclose(in); copy_mat(fr.box, box); top->name = put_symtab(&top->symtab, fr.title); sfree(const_cast<char *>(fr.title)); break; case efPDB: case efBRK: case efENT: gmx_pdb_read_conf(infile, top, x, ePBC, box); break; case efESP: gmx_espresso_read_conf(infile, top, x, v, box); break; default: gmx_incons("Not supported in read_stx_conf"); } }
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 get_espresso_coordnum(const char *infile) { FILE *fp; char word[STRLEN]; int natoms, level, r; gmx_bool bFoundParticles; natoms = 0; fp = gmx_fio_fopen(infile, "r"); bFoundParticles = FALSE; level = 0; while ((r = get_espresso_word(fp, word)) && !bFoundParticles) { if (level == 1 && strcmp(word, "particles") == 0 && !bFoundParticles) { bFoundParticles = TRUE; level += check_open_parenthesis(fp, r, infile, "particles"); while (level > 0 && (r = get_espresso_word(fp, word))) { if (r == 2) { level++; if (level == 2) { natoms++; } } else if (r == 3) { level--; } } } 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); return natoms; }
static void read_whole_conf(char *infile, char *title, t_atoms *atoms, rvec x[],rvec *v, matrix box) { FILE *in; int ndec; /* open file */ in=gmx_fio_fopen(infile,"r"); get_w_conf(in, infile, title, atoms, &ndec, x, v, box); gmx_fio_fclose(in); }
static void tpx2methods(const char *tpx, const char *tex) { FILE *fp; t_inputrec ir; t_state state; gmx_mtop_t mtop; read_tpx_state(tpx, &ir, &state, &mtop); fp = gmx_fio_fopen(tex, "w"); fprintf(fp, "\\section{Methods}\n"); tpx2system(fp, &mtop); tpx2params(fp, &ir); gmx_fio_fclose(fp); }
void write_inpfile(const char *fn, int ninp, t_inpfile inp[], gmx_bool bHaltOnUnknown, warninp_t wi) { FILE *out; int i; char warn_buf[STRLEN]; sort_inp(ninp, inp); out = gmx_fio_fopen(fn, "w"); nice_header(out, fn); try { gmx::BinaryInformationSettings settings; settings.generatedByHeader(true); settings.linePrefix(";\t"); gmx::printBinaryInformation(out, gmx::getProgramContext(), settings); } GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR; for (i = 0; (i < ninp); i++) { if (inp[i].bSet) { if (inp[i].name[0] == ';' || (strlen(inp[i].name) > 2 && inp[i].name[1] == ';')) { fprintf(out, "%-24s\n", inp[i].name); } else { fprintf(out, "%-24s = %s\n", inp[i].name, inp[i].value ? inp[i].value : ""); } } else if (!inp[i].bObsolete) { sprintf(warn_buf, "Unknown left-hand '%s' in parameter file\n", inp[i].name); if (bHaltOnUnknown) { warning_error(wi, warn_buf); } else { warning(wi, warn_buf); } } } gmx_fio_fclose(out); check_warning_error(wi, FARGS); }
static gmx_bool empty_file(const char *fn) { FILE *fp; char dum; int ret; gmx_bool bEmpty; fp = gmx_fio_fopen(fn,"r"); ret = fread(&dum,sizeof(dum),1,fp); bEmpty = feof(fp); gmx_fio_fclose(fp); return bEmpty; }