Example #1
0
int write_trxframe(t_trxstatus *status,t_trxframe *fr,gmx_conect gc)
{
  char title[STRLEN];
  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 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);
    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_p(gmx_fio_getfp(status->fio),title,fr->atoms,
		    prec2ndec(prec),fr->x,fr->bV ? fr->v : NULL,fr->box);
    else
      write_pdbfile(gmx_fio_getfp(status->fio),title,
		    fr->atoms,fr->x,fr->bPBC ? fr->ePBC : -1,fr->box,
		    ' ',fr->step,gc,TRUE);
    break;
  case efG87:
    write_gms(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;
  default:
    gmx_fatal(FARGS,"Sorry, write_trxframe can not write %s",
		ftp2ext(gmx_fio_getftp(status->fio)));
    break;
  }

  return 0;
}
Example #2
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;
}