Ejemplo n.º 1
0
int read_first_frame(const output_env_t oenv, t_trxstatus **status,
                     const char *fn, t_trxframe *fr, int flags)
{
    t_fileio *fio;
    gmx_bool  bFirst, bOK;
    int       dummy = 0;

    clear_trxframe(fr, TRUE);
    fr->flags = flags;

    bFirst = TRUE;

    snew((*status), 1);

    status_init( *status );
    (*status)->nxframe = 1;
    initcount(*status);

    fio = (*status)->fio = gmx_fio_open(fn, "r");
    switch (gmx_fio_getftp(fio))
    {
    case efTRJ:
    case efTRR:
        break;
    case efCPT:
        read_checkpoint_trxframe(fio, fr);
        bFirst = FALSE;
        break;
    case efG96:
        /* Can not rewind a compressed file, so open it twice */
        if (!(*status)->persistent_line)
        {
            /* allocate the persistent line */
            snew((*status)->persistent_line, STRLEN+1);
        }
        read_g96_conf(gmx_fio_getfp(fio), fn, fr, (*status)->persistent_line);
        gmx_fio_close(fio);
        clear_trxframe(fr, FALSE);
        if (flags & (TRX_READ_X | TRX_NEED_X))
        {
            snew(fr->x, fr->natoms);
        }
        if (flags & (TRX_READ_V | TRX_NEED_V))
        {
            snew(fr->v, fr->natoms);
        }
        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)
        {
            if (bOK)
            {
                gmx_fatal(FARGS, "No XTC!\n");
            }
            else
            {
                fr->not_ok = DATA_NOT_OK;
            }
        }
        if (fr->not_ok)
        {
            fr->natoms = 0;
            printincomp(*status, fr);
        }
        else
        {
            fr->bPrec = (fr->prec > 0);
            fr->bStep = TRUE;
            fr->bTime = TRUE;
            fr->bX    = TRUE;
            fr->bBox  = TRUE;
            printcount(*status, oenv, fr->time, FALSE);
        }
        bFirst = FALSE;
        break;
    case efPDB:
        pdb_first_x(*status, gmx_fio_getfp(fio), fr);
        if (fr->natoms)
        {
            printcount(*status, oenv, fr->time, FALSE);
        }
        bFirst = FALSE;
        break;
    case efGRO:
        if (gro_first_x_or_v(gmx_fio_getfp(fio), fr))
        {
            printcount(*status, oenv, fr->time, FALSE);
        }
        bFirst = FALSE;
        break;
    default:
#ifdef GMX_USE_PLUGINS
        fprintf(stderr, "The file format of %s is not a known trajectory format to GROMACS.\n"
                "Please make sure that the file is a trajectory!\n"
                "GROMACS will now assume it to be a trajectory and will try to open it using the VMD plug-ins.\n"
                "This will only work in case the VMD plugins are found and it is a trajectory format supported by VMD.\n", fn);
        gmx_fio_fp_close(fio); /*only close the file without removing FIO entry*/
        if (!read_first_vmd_frame(fn, fr))
        {
            gmx_fatal(FARGS, "Not supported in read_first_frame: %s", fn);
        }
#else
        gmx_fatal(FARGS, "Not supported in read_first_frame: %s. Please make sure that the file is a trajectory.\n"
                  "GROMACS is not compiled with plug-in support. Thus it cannot read non-GROMACS trajectory formats using the VMD plug-ins.\n"
                  "Please compile with plug-in support if you want to read non-GROMACS trajectory formats.\n", fn);
#endif
        break;
    }

    /* 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))
    {
        fr->t0 = fr->time;
        return FALSE;
    }

    if (bFirst ||
            (!(fr->flags & TRX_DONT_SKIP) && check_times(fr->time) < 0))
    {
        /* Read a frame when no frame was read or the first was skipped */
        if (!read_next_frame(oenv, *status, fr))
        {
            return FALSE;
        }
    }
    fr->t0 = fr->time;

    return (fr->natoms > 0);
}
Ejemplo n.º 2
0
int read_first_frame(const output_env_t oenv,t_trxstatus **status,
                     const char *fn,t_trxframe *fr,int flags)
{
  t_fileio *fio;
  gmx_bool bFirst,bOK;
  int dummy=0;

  clear_trxframe(fr,TRUE);
  fr->flags = flags;

  bFirst = TRUE;

  snew((*status), 1);

  status_init( *status );
  (*status)->nxframe=1;
  initcount(*status);
  
  fio = (*status)->fio =gmx_fio_open(fn,"r");
  switch (gmx_fio_getftp(fio)) 
  {
  case efTRJ:
  case efTRR:
    break;
  case efCPT:
    read_checkpoint_trxframe(fio,fr);
    bFirst = FALSE;
    break;
  case efG96:
    /* Can not rewind a compressed file, so open it twice */
    read_g96_conf(gmx_fio_getfp(fio),fn,fr);
    gmx_fio_close(fio);
    clear_trxframe(fr,FALSE);
    if (flags & (TRX_READ_X | TRX_NEED_X))
      snew(fr->x,fr->natoms);
    if (flags & (TRX_READ_V | TRX_NEED_V))
      snew(fr->v,fr->natoms);
    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) {
      if (bOK) {
	gmx_fatal(FARGS,"No XTC!\n");
      } else {
	fr->not_ok = DATA_NOT_OK;
      }
    }
    if (fr->not_ok) {
      fr->natoms = 0;
      printincomp(*status,fr);
    } else {
      fr->bPrec = (fr->prec > 0);
      fr->bStep = TRUE;
      fr->bTime = TRUE;
      fr->bX    = TRUE;
      fr->bBox  = TRUE;
      printcount(*status,oenv,fr->time,FALSE);
    }
    bFirst = FALSE;
    break;
  case efPDB:
    pdb_first_x(*status, gmx_fio_getfp(fio),fr);
    if (fr->natoms)
      printcount(*status,oenv,fr->time,FALSE);
    bFirst = FALSE;
    break;
  case efGRO:
    if (gro_first_x_or_v(gmx_fio_getfp(fio),fr))
      printcount(*status,oenv,fr->time,FALSE);
    bFirst = FALSE;
    break;
  default:
#ifdef GMX_DLOPEN
      gmx_fio_fp_close(fio); /*only close the file without removing FIO entry*/
      if (!read_first_vmd_frame(&dummy,fn,fr,flags))
      {
	  gmx_fatal(FARGS,"Not supported in read_first_frame: %s",fn);
      }
#else
      gmx_fatal(FARGS,"Not supported in read_first_frame: %s",fn);
#endif
      break;
  }

  /* 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)) {
    fr->t0 = fr->time;
    return FALSE;
  }
  
  if (bFirst || 
      (!(fr->flags & TRX_DONT_SKIP) && check_times(fr->time) < 0))
    /* Read a frame when no frame was read or the first was skipped */
    if (!read_next_frame(oenv,*status,fr))
      return FALSE;
  fr->t0 = fr->time;
  
  return (fr->natoms > 0);
}