* This file is part of the GROMACS molecular simulation package.
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2004, The GROMACS development team,
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2001-2004, The GROMACS development team.
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
* To help us fund GROMACS development, we humbly ask that you cite
* the research papers on the package. Check out http://www.gromacs.org.
*/
+#include "gmxpre.h"
+
#include "trxio.h"
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "config.h"
-#include <ctype.h>
-#include <math.h>
#include <assert.h>
+#include <math.h>
-#include "sysstuff.h"
-#include "typedefs.h"
-#include "vmdio.h"
-#include "string2.h"
-#include "smalloc.h"
-#include "pbc.h"
-#include "gmxfio.h"
-#include "trxio.h"
-#include "tpxio.h"
-#include "trnio.h"
-#include "tngio.h"
-#include "tngio_for_tools.h"
-#include "names.h"
-#include "vec.h"
-#include "futil.h"
-#include "xtcio.h"
-#include "pdbio.h"
-#include "confio.h"
-#include "checkpoint.h"
-#include "g87io.h"
-
+#include "gromacs/fileio/confio.h"
+#include "gromacs/fileio/gmxfio.h"
+#include "gromacs/fileio/pdbio.h"
#include "gromacs/fileio/timecontrol.h"
+#include "gromacs/fileio/tngio.h"
+#include "gromacs/fileio/tngio_for_tools.h"
+#include "gromacs/fileio/tpxio.h"
+#include "gromacs/fileio/trnio.h"
+#include "gromacs/fileio/trx.h"
+#include "gromacs/fileio/xdrf.h"
+#include "gromacs/fileio/xtcio.h"
+#include "gromacs/legacyheaders/checkpoint.h"
+#include "gromacs/legacyheaders/names.h"
+#include "gromacs/math/vec.h"
+#include "gromacs/topology/atoms.h"
+#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/futil.h"
+#include "gromacs/utility/smalloc.h"
+
+#ifdef GMX_USE_PLUGINS
+#include "gromacs/fileio/vmdio.h"
+#endif
/* defines for frame counter output */
#define SKIP1 10
#define SKIP2 100
#define SKIP3 1000
-/* Globals for gromos-87 input */
-typedef enum {
- effXYZ, effXYZBox, effG87, effG87Box, effNR
-} eFileFormat;
-
struct t_trxstatus
{
int __frame;
int nxframe;
t_fileio *fio;
tng_trajectory_t tng;
- eFileFormat eFF;
int NATOMS;
double DT, BOX[3];
gmx_bool bReadBox;
return status->fio;
}
-tng_trajectory_t trx_get_tng(t_trxstatus *status)
+float trx_get_time_of_final_frame(t_trxstatus *status)
{
- return status->tng;
+ t_fileio *stfio = trx_get_fileio(status);
+ int filetype = gmx_fio_getftp(stfio);
+ int bOK;
+ float lasttime = -1;
+
+ if (filetype == efXTC)
+ {
+ lasttime =
+ xdr_xtc_get_last_frame_time(gmx_fio_getfp(stfio),
+ gmx_fio_getxdr(stfio),
+ status->xframe->natoms, &bOK);
+ if (!bOK)
+ {
+ gmx_fatal(FARGS, "Error reading last frame. Maybe seek not supported." );
+ }
+ }
+ else if (filetype == efTNG)
+ {
+ tng_trajectory_t tng = status->tng;
+ if (!tng)
+ {
+ gmx_fatal(FARGS, "Error opening TNG file.");
+ }
+ lasttime = gmx_tng_get_time_of_final_frame(tng);
+ }
+ else
+ {
+ gmx_incons("Only supported for TNG and XTC");
+ }
+ return lasttime;
}
void clear_trxframe(t_trxframe *fr, gmx_bool bFirst)
fr->bDouble = FALSE;
fr->natoms = -1;
fr->t0 = 0;
+ fr->tf = 0;
fr->tpf = 0;
fr->tppf = 0;
fr->title = NULL;
switch (ftp)
{
- case efTRJ:
case efTRR:
case efTNG:
break;
switch (ftp)
{
- case efTRJ:
case efTRR:
case efTNG:
if (fr->bV)
}
/* no break */
case efXTC:
- case efG87:
if (fr->bX)
{
snew(xout, nind);
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);
fr->x, -1, fr->box, ' ', fr->step, nind, ind, gc, TRUE);
}
break;
- case efG87:
- write_g87(gmx_fio_getfp(status->fio), nind, xout, fr->box);
- break;
case efG96:
write_g96_conf(gmx_fio_getfp(status->fio), fr, nind, ind);
break;
switch (ftp)
{
- case efTRN:
- case efTRJ:
case efTRR:
case efTNG:
if (vout)
}
/* no break */
case efXTC:
- case efG87:
sfree(xout);
break;
default:
switch (gmx_fio_getftp(status->fio))
{
- case efTRJ:
case efTRR:
break;
default:
case efXTC:
write_xtc(status->fio, fr->natoms, fr->step, fr->time, fr->box, fr->x, prec);
break;
- case efTRJ:
case efTRR:
fwrite_trn(status->fio, fr->step, fr->time, fr->lambda, fr->box, fr->natoms,
fr->bX ? fr->x : NULL, fr->bV ? fr->v : NULL, fr->bF ? fr->f : NULL);
' ', fr->step, gc, TRUE);
}
break;
- case efG87:
- write_g87(gmx_fio_getfp(status->fio), fr->natoms, fr->x, fr->box);
- break;
case efG96:
write_g96_conf(gmx_fio_getfp(status->fio), fr, -1, NULL);
break;
return bRet;
}
-static void choose_file_format(FILE *fp)
-{
- int i, m, c;
- int rc;
- eFileFormat eFF;
- t_trxstatus *stat;
-
- printf("\n\n");
- printf(" Select File Format\n");
- printf("---------------------------\n");
- printf("1. XYZ File\n");
- printf("2. XYZ File with Box\n");
- printf("3. Gromos-87 Ascii Trajectory\n");
- printf("4. Gromos-87 Ascii Trajectory with Box\n");
-
- snew(stat, 1);
- status_init(stat);
-
- do
- {
- printf("\nChoice: ");
- fflush(stdout);
- do
- {
- rc = scanf("%d", &i);
- }
- while (rc != 1);
- i--;
- }
- while ((i < 0) || (i >= effNR));
- printf("\n");
-
- stat->eFF = (eFileFormat) i;
-
- for (m = 0; (m < DIM); m++)
- {
- stat->BOX[m] = 0;
- }
-
- stat->bReadBox = (stat->eFF == effG87Box) || (stat->eFF == effXYZBox);
-
- switch (stat->eFF)
- {
- case effXYZ:
- case effXYZBox:
- if (5 != fscanf(fp, "%d%lf%lf%lf%lf", &stat->NATOMS, &stat->BOX[XX], &stat->BOX[YY], &stat->BOX[ZZ], &stat->DT))
- {
- gmx_fatal(FARGS, "Error reading natoms/box in file");
- }
- break;
- case effG87:
- case effG87Box:
- printf("GROMOS! OH DEAR...\n\n");
- printf("Number of atoms ? ");
- fflush(stdout);
- if (1 != scanf("%d", &stat->NATOMS))
- {
- gmx_fatal(FARGS, "Error reading natoms in file");
- }
-
- printf("Time between timeframes ? ");
- fflush(stdout);
- if (1 != scanf("%lf", &stat->DT))
- {
- gmx_fatal(FARGS, "Error reading dt from file");
- }
-
- if (stat->eFF == effG87)
- {
- printf("Box X Y Z ? ");
- fflush(stdout);
- if (3 != scanf("%lf%lf%lf", &stat->BOX[XX], &stat->BOX[YY], &stat->BOX[ZZ]))
- {
- gmx_fatal(FARGS, "Error reading box in file");
- }
- }
- do
- {
- c = fgetc(fp);
- printf("%c", c);
- }
- while (c != '\n');
- printf("\n");
- fflush(stdout);
- break;
- default:
- printf("Hellow World\n");
- }
-}
-
-static gmx_bool do_read_xyz(t_trxstatus *status, FILE *fp, int natoms,
- rvec x[], matrix box)
-{
- int i, m;
- double x0;
-
- for (i = 0; (i < natoms); i++)
- {
- for (m = 0; (m < DIM); m++)
- {
- if (fscanf(fp, "%lf", &x0) != 1)
- {
- if (i || m)
- {
- fprintf(stderr, "error reading statusfile: x[%d][%d]\n", i, m);
- }
- /* else eof! */
- return FALSE;
- }
- x[i][m] = x0;
- }
- }
- if (status->bReadBox)
- {
- for (m = 0; (m < DIM); m++)
- {
- if (fscanf(fp, "%lf", &x0) != 1)
- {
- return FALSE;
- }
- box[m][m] = x0;
- }
- }
- return TRUE;
-}
-
-static gmx_bool xyz_next_x(t_trxstatus *status, FILE *fp, const output_env_t oenv,
- real *t, int natoms, rvec x[], matrix box)
-/* Reads until a new x can be found (return TRUE)
- * or eof (return FALSE)
- */
-{
- real pt;
-
- pt = *t;
- while (!bTimeSet(TBEGIN) || (*t < rTimeValue(TBEGIN)))
- {
- if (!do_read_xyz(status, fp, natoms, x, box))
- {
- return FALSE;
- }
- printcount(status, oenv, *t, FALSE);
- *t += status->DT;
- pt = *t;
- }
- if (!bTimeSet(TEND) || (*t <= rTimeValue(TEND)))
- {
- if (!do_read_xyz(status, fp, natoms, x, box))
- {
- printlast(status, oenv, *t);
- return FALSE;
- }
- printcount(status, oenv, *t, FALSE);
- pt = *t;
- *t += status->DT;
- return TRUE;
- }
- printlast(status, oenv, pt);
- return FALSE;
-}
-
-static int xyz_first_x(t_trxstatus *status, FILE *fp, const output_env_t oenv,
- real *t, rvec **x, matrix box)
-/* Reads fp, mallocs x, and returns x and box
- * Returns natoms when successful, FALSE otherwise
- */
-{
- int m;
-
- initcount(status);
-
- clear_mat(box);
- choose_file_format(fp);
-
- for (m = 0; (m < DIM); m++)
- {
- box[m][m] = status->BOX[m];
- }
-
- snew(*x, status->NATOMS);
- *t = status->DT;
- if (!xyz_next_x(status, fp, oenv, t, status->NATOMS, *x, box))
- {
- return 0;
- }
- *t = 0.0;
-
- return status->NATOMS;
-}
-
static gmx_bool pdb_next_x(t_trxstatus *status, FILE *fp, t_trxframe *fr)
{
t_atoms atoms;
int ftp;
bRet = FALSE;
- pt = fr->time;
+ pt = fr->tf;
do
{
clear_trxframe(fr, FALSE);
fr->tppf = fr->tpf;
- fr->tpf = fr->time;
+ fr->tpf = fr->tf;
if (status->tng)
{
}
switch (ftp)
{
- case efTRJ:
case efTRR:
bRet = gmx_next_frame(status, fr);
break;
status->persistent_line);
bRet = (fr->natoms > 0);
break;
- case efG87:
- bRet = xyz_next_x(status, gmx_fio_getfp(status->fio), oenv, &fr->time,
- fr->natoms, fr->x, fr->box);
- fr->bTime = bRet;
- fr->bX = bRet;
- fr->bBox = bRet;
- break;
case efXTC:
/* B. Hess 2005-4-20
* Sometimes is off by one frame
/* DvdS 2005-05-31: this has been fixed along with the increased
* accuracy of the control over -b and -e options.
*/
- if (bTimeSet(TBEGIN) && (fr->time < rTimeValue(TBEGIN)))
+ if (bTimeSet(TBEGIN) && (fr->tf < rTimeValue(TBEGIN)))
{
if (xtc_seek_time(status->fio, rTimeValue(TBEGIN), fr->natoms, TRUE))
{
gmx_fio_getname(status->fio));
#endif
}
+ fr->tf = fr->time;
if (bRet)
{
}
switch (ftp)
{
- case efTRJ:
case efTRR:
break;
case efCPT:
}
fio = (*status)->fio = gmx_fio_open(fn, "r");
break;
- case efG87:
- fr->natoms = xyz_first_x(*status, gmx_fio_getfp(fio), oenv, &fr->time,
- &fr->x, fr->box);
- if (fr->natoms)
- {
- fr->bTime = TRUE;
- fr->bX = TRUE;
- fr->bBox = TRUE;
- printcount(*status, oenv, fr->time, FALSE);
- }
- bFirst = FALSE;
- break;
case efXTC:
if (read_first_xtc(fio, &fr->natoms, &fr->step, &fr->time, fr->box, &fr->x,
&fr->prec, &bOK) == 0)
#endif
break;
}
+ fr->tf = fr->time;
/* Return FALSE if we read a frame that's past the set ending time. */
if (!bFirst && (!(fr->flags & TRX_DONT_SKIP) && check_times(fr->time) > 0))