Esempio 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);
}
Esempio n. 2
0
bool read_first_frame(const gmx_output_env_t *oenv, t_trxstatus **status,
                      const char *fn, t_trxframe *fr, int flags)
{
    t_fileio      *fio = nullptr;
    gmx_bool       bFirst, bOK;
    int            ftp   = fn2ftp(fn);

    clear_trxframe(fr, TRUE);

    bFirst = TRUE;

    snew((*status), 1);

    status_init( *status );
    initcount(*status);
    (*status)->flags = flags;

    if (efTNG == ftp)
    {
        /* Special treatment for TNG files */
        gmx_tng_open(fn, 'r', &(*status)->tng);
    }
    else
    {
        fio = (*status)->fio = gmx_fio_open(fn, "r");
    }
    switch (ftp)
    {
        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);
            }
            t_symtab *symtab = nullptr;
            read_g96_conf(gmx_fio_getfp(fio), fn, nullptr, fr, symtab, (*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);
            }
            (*status)->fio = gmx_fio_open(fn, "r");
            break;
        }
        case efXTC:
            if (read_first_xtc(fio, &fr->natoms, &fr->step, &fr->time, fr->box, &fr->x,
                               &fr->prec, &bOK) == 0)
            {
                GMX_RELEASE_ASSERT(!bOK, "Inconsistent results - OK status from read_first_xtc, but 0 atom coords read");
                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 efTNG:
            fr->step = -1;
            if (!gmx_read_next_tng_frame((*status)->tng, fr, nullptr, 0))
            {
                fr->not_ok = DATA_NOT_OK;
                fr->natoms = 0;
                printincomp(*status, fr);
            }
            else
            {
                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:
#if 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, &(*status)->vmdplugin, 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;
    }
    (*status)->tf = fr->time;

    /* Return FALSE if we read a frame that's past the set ending time. */
    if (!bFirst && (!(flags & TRX_DONT_SKIP) && check_times(fr->time) > 0))
    {
        (*status)->t0 = fr->time;
        return FALSE;
    }

    if (bFirst ||
        (!(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;
        }
    }
    (*status)->t0 = fr->time;

    /* We need the number of atoms for random-access XTC searching, even when
     * we don't have access to the actual frame data.
     */
    (*status)->natoms = fr->natoms;

    return (fr->natoms > 0);
}
Esempio n. 3
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);
}