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 write_hconf_p(FILE *out,char *title,t_atoms *atoms, int pr, rvec *x,rvec *v,matrix box) { atom_id *aa; int i; snew(aa,atoms->nr); for(i=0; (i<atoms->nr); i++) aa[i]=i; write_hconf_indexed_p(out,title,atoms,atoms->nr,aa,pr,x,v,box); sfree(aa); }
int write_trxframe_indexed(t_trxstatus *status, const t_trxframe *fr, int nind, const int *ind, gmx_conect gc) { char title[STRLEN]; rvec *xout = nullptr, *vout = nullptr, *fout = nullptr; int i, ftp = -1; real prec; if (fr->bPrec) { prec = fr->prec; } else { prec = 1000.0; } if (status->tng) { ftp = efTNG; } else if (status->fio) { ftp = gmx_fio_getftp(status->fio); } else { gmx_incons("No input file available"); } switch (ftp) { case efTRR: case efTNG: break; default: if (!fr->bX) { gmx_fatal(FARGS, "Need coordinates to write a %s trajectory", ftp2ext(ftp)); } break; } switch (ftp) { case efTRR: case efTNG: if (fr->bV) { snew(vout, nind); for (i = 0; i < nind; i++) { copy_rvec(fr->v[ind[i]], vout[i]); } } if (fr->bF) { snew(fout, nind); for (i = 0; i < nind; i++) { copy_rvec(fr->f[ind[i]], fout[i]); } } // fallthrough case efXTC: if (fr->bX) { snew(xout, nind); for (i = 0; i < nind; i++) { copy_rvec(fr->x[ind[i]], xout[i]); } } break; default: break; } switch (ftp) { case efTNG: gmx_write_tng_from_trxframe(status->tng, fr, nind); break; case efXTC: write_xtc(status->fio, nind, fr->step, fr->time, fr->box, xout, prec); break; case efTRR: gmx_trr_write_frame(status->fio, nframes_read(status), fr->time, fr->step, fr->box, nind, xout, vout, fout); break; case efGRO: case efPDB: case efBRK: case efENT: if (!fr->bAtoms) { gmx_fatal(FARGS, "Can not write a %s file without atom names", ftp2ext(ftp)); } sprintf(title, "frame t= %.3f", fr->time); if (ftp == efGRO) { write_hconf_indexed_p(gmx_fio_getfp(status->fio), title, fr->atoms, nind, ind, fr->x, fr->bV ? fr->v : nullptr, fr->box); } else { write_pdbfile_indexed(gmx_fio_getfp(status->fio), title, fr->atoms, fr->x, -1, fr->box, ' ', fr->step, nind, ind, gc, TRUE); } break; case efG96: sprintf(title, "frame t= %.3f", fr->time); write_g96_conf(gmx_fio_getfp(status->fio), title, fr, nind, ind); break; default: gmx_fatal(FARGS, "Sorry, write_trxframe_indexed can not write %s", ftp2ext(ftp)); break; } switch (ftp) { case efTRR: case efTNG: if (vout) { sfree(vout); } if (fout) { sfree(fout); } // fallthrough case efXTC: sfree(xout); break; default: break; } return 0; }
int write_trxframe_indexed(t_trxstatus *status, t_trxframe *fr, int nind, const atom_id *ind, gmx_conect gc) { char title[STRLEN]; rvec *xout = NULL, *vout = NULL, *fout = NULL; int i; real prec; if (fr->bPrec) { prec = fr->prec; } else { prec = 1000.0; } switch (gmx_fio_getftp(status->fio)) { case efTRJ: case efTRR: break; default: if (!fr->bX) { gmx_fatal(FARGS, "Need coordinates to write a %s trajectory", ftp2ext(gmx_fio_getftp(status->fio))); } break; } switch (gmx_fio_getftp(status->fio)) { case efTRJ: case efTRR: if (fr->bV) { snew(vout, nind); for (i = 0; i < nind; i++) { copy_rvec(fr->v[ind[i]], vout[i]); } } if (fr->bF) { snew(fout, nind); for (i = 0; i < nind; i++) { copy_rvec(fr->f[ind[i]], fout[i]); } } /* no break */ case efXTC: case efG87: if (fr->bX) { snew(xout, nind); for (i = 0; i < nind; i++) { copy_rvec(fr->x[ind[i]], xout[i]); } } break; default: break; } switch (gmx_fio_getftp(status->fio)) { case efXTC: write_xtc(status->fio, nind, fr->step, fr->time, fr->box, xout, prec); break; case efTRJ: case efTRR: fwrite_trn(status->fio, nframes_read(status), fr->time, fr->step, fr->box, nind, xout, vout, fout); break; case efGRO: case efPDB: case efBRK: case efENT: if (!fr->bAtoms) { gmx_fatal(FARGS, "Can not write a %s file without atom names", ftp2ext(gmx_fio_getftp(status->fio))); } sprintf(title, "frame t= %.3f", fr->time); if (gmx_fio_getftp(status->fio) == efGRO) { write_hconf_indexed_p(gmx_fio_getfp(status->fio), title, fr->atoms, nind, ind, prec2ndec(prec), fr->x, fr->bV ? fr->v : NULL, fr->box); } else { write_pdbfile_indexed(gmx_fio_getfp(status->fio), title, fr->atoms, fr->x, -1, fr->box, ' ', fr->step, nind, ind, gc, TRUE); } break; case efG87: write_gms(gmx_fio_getfp(status->fio), nind, xout, fr->box); break; case efG96: write_g96_conf(gmx_fio_getfp(status->fio), fr, nind, ind); break; default: gmx_fatal(FARGS, "Sorry, write_trxframe_indexed can not write %s", ftp2ext(gmx_fio_getftp(status->fio))); break; } switch (gmx_fio_getftp(status->fio)) { case efTRN: case efTRJ: case efTRR: if (vout) { sfree(vout); } if (fout) { sfree(fout); } /* no break */ case efXTC: case efG87: sfree(xout); break; default: break; } return 0; }