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 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)); } }
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 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; } }
t_psdata ps_open(const char *fn, real x1, real y1, real x2, real y2) { t_psdata ps; snew(ps, 1); ps->fp = gmx_fio_fopen(fn, "w"); fprintf(ps->fp, "%%!PS-Adobe-2.0 EPSF-1.2\n"); fprintf(ps->fp, "%%%%Creator: GROMACS\n"); fprintf(ps->fp, "%%%%Title: %s\n", fn); fprintf(ps->fp, "%%%%BoundingBox: %g %g %g %g\n", x1, y1, x2, y2); fprintf(ps->fp, "%%%%EndComments\n"); fprintf(ps->fp, "/m {moveto} bind def\n"); fprintf(ps->fp, "/l {lineto} bind def\n"); fprintf(ps->fp, "/rm {rmoveto} bind def\n"); fprintf(ps->fp, "/r {rlineto} bind def\n"); fprintf(ps->fp, "/f {fill} bind def\n"); fprintf(ps->fp, "/s {stroke} bind def\n"); ps->nrgb = 0; ps->maxrgb = 0; ps->rgb = NULL; ps->gen_ybox = 0; ps->ostack = 0; return ps; }
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 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); }
void init_debug (const int dbglevel,const char *dbgfile) { no_buffers(); debug=gmx_fio_fopen(dbgfile,"w"); bDebug = TRUE; if (dbglevel >= 2) gmx_debug_at = TRUE; }
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 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); }
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); }
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); }
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 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 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); }
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_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"); } }
FILE *xvgropen_type(const char *fn, const char *title, const char *xaxis, const char *yaxis, int exvg_graph_type, const gmx_output_env_t *oenv) { FILE *fp; fp = gmx_fio_fopen(fn, "w"); xvgr_header(fp, title, xaxis, yaxis, exvg_graph_type, oenv); return fp; }
void gmx_log_open(const char *lognm, const t_commrec *cr, gmx_bool bAppendFiles, FILE** fplog) { int pid; char host[256]; char timebuf[STRLEN]; FILE *fp = *fplog; debug_gmx(); if (!bAppendFiles) { fp = gmx_fio_fopen(lognm, bAppendFiles ? "a+" : "w+" ); } gmx_fatal_set_log_file(fp); /* Get some machine parameters */ gmx_gethostname(host, 256); pid = gmx_getpid(); gmx_format_current_time(timebuf, STRLEN); if (bAppendFiles) { fprintf(fp, "\n" "\n" "-----------------------------------------------------------\n" "Restarting from checkpoint, appending to previous log file.\n" "\n" ); } fprintf(fp, "Log file opened on %s" "Host: %s pid: %d rank ID: %d number of ranks: %d\n", timebuf, host, pid, cr->nodeid, cr->nnodes); try { gmx::BinaryInformationSettings settings; settings.extendedInfo(true); settings.copyright(!bAppendFiles); gmx::printBinaryInformation(fp, gmx::getProgramContext(), settings); } GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR; fprintf(fp, "\n"); fflush(fp); debug_gmx(); *fplog = fp; }
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 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; }
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 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); }
static FILE *man_file(const output_env_t oenv,const char *mantp) { FILE *fp; char buf[256]; const char *pr = output_env_get_short_program_name(oenv); if (strcmp(mantp,"ascii") != 0) sprintf(buf,"%s.%s",pr,mantp); else sprintf(buf,"%s.txt",pr); fp = gmx_fio_fopen(buf,"w"); return fp; }
void write_grid_pqr(char *fn,int nx,int ny,int nz,real ***phi) { FILE *fp; int i,j,k,rnr=0; real fac=4.0; fp=gmx_fio_fopen(fn,"w"); for(i=0; (i<nx); i++) for(j=0; (j<ny); j++) for(k=0; (k<nz); k++,rnr++) fprintf(fp,"%-6s%5d %-4.4s%3.3s %c%4d %8.3f%8.3f%8.3f%6.2f%6.2f\n", "ATOM",(i+1),"C","C",' ', 1+((rnr+1) % 10000),fac*i,fac*j,fac*k,0.0,phi[i][j][k]); gmx_fio_fclose(fp); }
void write_pqr(char *fn,t_atoms *atoms,rvec x[],real phi[],real dx) { FILE *fp; int i,rnr; fp=gmx_fio_fopen(fn,"w"); for(i=0; (i<atoms->nr); i++) { rnr=atoms->atom[i].resnr; fprintf(fp,"%-6s%5d %-4.4s%3.3s %c%4d %8.3f%8.3f%8.3f%6.2f%6.2f\n", "ATOM",(i+1),*atoms->atomname[i],*atoms->resname[rnr],' ', (rnr+1) % 10000, 10*(dx+x[i][XX]),10*x[i][YY],10*(x[i][ZZ]),0.0,phi[i]); } gmx_fio_fclose(fp); }
void AbstractPlotModule::dataStarted(AbstractAnalysisData * /* data */) { if (!impl_->filename_.empty()) { if (impl_->bPlain_) { impl_->fp_ = gmx_fio_fopen(impl_->filename_.c_str(), "w"); } else { time_unit_t time_unit = static_cast<time_unit_t>(impl_->settings_.timeUnit() + 1); xvg_format_t xvg_format = (impl_->settings_.plotFormat() > 0 ? static_cast<xvg_format_t>(impl_->settings_.plotFormat()) : exvgNONE); output_env_t oenv; output_env_init(&oenv, getProgramContext(), time_unit, FALSE, xvg_format, 0); boost::shared_ptr<output_env> oenvGuard(oenv, &output_env_done); impl_->fp_ = xvgropen(impl_->filename_.c_str(), impl_->title_.c_str(), impl_->xlabel_.c_str(), impl_->ylabel_.c_str(), oenv); const SelectionCollection *selections = impl_->settings_.selectionCollection(); if (selections != NULL) { selections->printXvgrInfo(impl_->fp_, oenv); } if (!impl_->subtitle_.empty()) { xvgr_subtitle(impl_->fp_, impl_->subtitle_.c_str(), oenv); } if (output_env_get_print_xvgr_codes(oenv) && !impl_->legend_.empty()) { std::vector<const char *> legend; legend.reserve(impl_->legend_.size()); for (size_t i = 0; i < impl_->legend_.size(); ++i) { legend.push_back(impl_->legend_[i].c_str()); } xvgr_legend(impl_->fp_, legend.size(), &legend[0], oenv); } } } }