void write_eigenvectors(char *trnname,int natoms,real mat[], bool bReverse,int begin,int end, int WriteXref,rvec *xref,bool bDMR, rvec xav[], bool bDMA,real eigval[]) { int trnout; int ndim,i,j,d,vec; matrix zerobox; rvec *x; ndim = natoms*DIM; clear_mat(zerobox); snew(x,natoms); fprintf (stderr, "\nWriting %saverage structure & eigenvectors %d--%d to %s\n", (WriteXref==eWXR_YES) ? "reference, " : "", begin,end,trnname); trnout = open_tpx(trnname,"w"); if (WriteXref == eWXR_YES) { /* misuse lambda: 0/1 mass weighted fit no/yes */ fwrite_trn(trnout,-1,-1,bDMR ? 1.0 : 0.0,zerobox,natoms,xref,NULL,NULL); } else if (WriteXref == eWXR_NOFIT) { /* misuse lambda: -1 no fit */ fwrite_trn(trnout,-1,-1,-1.0,zerobox,natoms,x,NULL,NULL); } /* misuse lambda: 0/1 mass weighted analysis no/yes */ fwrite_trn(trnout,0,0,bDMA ? 1.0 : 0.0,zerobox,natoms,xav,NULL,NULL); for(i=0; i<=(end-begin); i++) { if (!bReverse) vec = i; else vec = ndim-i-1; for (j=0; j<natoms; j++) for(d=0; d<DIM; d++) x[j][d]=mat[vec*ndim+DIM*j+d]; /* Store the eigenvalue in the time field */ fwrite_trn(trnout,begin+i,eigval[vec],0,zerobox,natoms,x,NULL,NULL); } close_trn(trnout); sfree(x); }
int write_traj(FILE *log,t_commrec *cr, char *traj,t_nsborder *nsb, int step,real t,real lambda,t_nrnb nrnb[], int natoms,rvec *xx,rvec *vv,rvec *ff,matrix box) { static int fp=-1; if ((fp == -1) && MASTER(cr)) { #ifdef DEBUG fprintf(log,"Going to open trajectory file: %s\n",traj); #endif fp = open_trn(traj,"w"); } #define MX(xvf) moveit(log,cr->left,cr->right,#xvf,xvf,nsb) if (cr->nnodes > 1) { MX(xx); MX(vv); MX(ff); } if ((xx || vv || ff) && MASTER(cr)) { fwrite_trn(fp,step,t,lambda,box,natoms,xx,vv,ff); gmx_fio_flush(fp); } return fp; }
static void dump_dih_trn(int nframes,int nangles,real **dih,char *fn,real dt) { int i,j,k,l,m,na,trn; rvec *x; matrix box = {{2,0,0},{0,2,0},{0,0,2}}; na = (nangles*2); if ((na % 3) != 0) na = 1+na/3; else na = na/3; printf("There are %d dihedrals. Will fill %d atom positions with cos/sin\n", nangles,na); snew(x,na); trn = open_trn(fn,"w"); for(i=0; (i<nframes); i++) { k = l = 0; for(j=0; (j<nangles); j++) { for(m=0; (m<2); m++) { x[k][l] = (m == 0) ? cos(dih[j][i]) : sin(dih[j][i]); l++; if (l == DIM) { l = 0; k++; } } } fwrite_trn(trn,i,(real)i*dt,0,box,na,x,NULL,NULL); } close_trn(trn); sfree(x); }
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; }
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, 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]); } } /* no break */ 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: 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(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, 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 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(ftp)); break; } switch (ftp) { case efTRR: case efTNG: if (vout) { sfree(vout); } if (fout) { sfree(fout); } /* no break */ case efXTC: sfree(xout); break; default: break; } return 0; }
void mdoutf_write_to_trajectory_files(FILE *fplog, t_commrec *cr, gmx_mdoutf_t of, int mdof_flags, gmx_mtop_t *top_global, gmx_int64_t step, double t, t_state *state_local, t_state *state_global, rvec *f_local, rvec *f_global) { rvec *local_v; rvec *global_v; /* MRS -- defining these variables is to manage the difference * between half step and full step velocities, but there must be a better way . . . */ local_v = state_local->v; global_v = state_global->v; if (DOMAINDECOMP(cr)) { if (mdof_flags & MDOF_CPT) { dd_collect_state(cr->dd, state_local, state_global); } else { if (mdof_flags & (MDOF_X | MDOF_X_COMPRESSED)) { dd_collect_vec(cr->dd, state_local, state_local->x, state_global->x); } if (mdof_flags & MDOF_V) { dd_collect_vec(cr->dd, state_local, local_v, global_v); } } if (mdof_flags & MDOF_F) { dd_collect_vec(cr->dd, state_local, f_local, f_global); } } else { if (mdof_flags & MDOF_CPT) { /* All pointers in state_local are equal to state_global, * but we need to copy the non-pointer entries. */ state_global->lambda = state_local->lambda; state_global->veta = state_local->veta; state_global->vol0 = state_local->vol0; copy_mat(state_local->box, state_global->box); copy_mat(state_local->boxv, state_global->boxv); copy_mat(state_local->svir_prev, state_global->svir_prev); copy_mat(state_local->fvir_prev, state_global->fvir_prev); copy_mat(state_local->pres_prev, state_global->pres_prev); } } if (MASTER(cr)) { if (mdof_flags & MDOF_CPT) { fflush_tng(of->tng); fflush_tng(of->tng_low_prec); write_checkpoint(of->fn_cpt, of->bKeepAndNumCPT, fplog, cr, of->eIntegrator, of->simulation_part, of->bExpanded, of->elamstats, step, t, state_global); } if (mdof_flags & (MDOF_X | MDOF_V | MDOF_F)) { if (of->fp_trn) { fwrite_trn(of->fp_trn, step, t, state_local->lambda[efptFEP], state_local->box, top_global->natoms, (mdof_flags & MDOF_X) ? state_global->x : NULL, (mdof_flags & MDOF_V) ? global_v : NULL, (mdof_flags & MDOF_F) ? f_global : NULL); if (gmx_fio_flush(of->fp_trn) != 0) { gmx_file("Cannot write trajectory; maybe you are out of disk space?"); } } gmx_fwrite_tng(of->tng, FALSE, step, t, state_local->lambda[efptFEP], (const rvec *) state_local->box, top_global->natoms, (mdof_flags & MDOF_X) ? (const rvec *) state_global->x : NULL, (mdof_flags & MDOF_V) ? (const rvec *) global_v : NULL, (mdof_flags & MDOF_F) ? (const rvec *) f_global : NULL); } if (mdof_flags & MDOF_X_COMPRESSED) { rvec *xxtc = NULL; if (of->natoms_x_compressed == of->natoms_global) { /* We are writing the positions of all of the atoms to the compressed output */ xxtc = state_global->x; } else { /* We are writing the positions of only a subset of the atoms to the compressed output, so we have to make a copy of the subset of coordinates. */ int i, j; snew(xxtc, of->natoms_x_compressed); for (i = 0, j = 0; (i < of->natoms_x_compressed); i++) { if (ggrpnr(of->groups, egcCompressedX, i) == 0) { copy_rvec(state_global->x[i], xxtc[j++]); } } } if (write_xtc(of->fp_xtc, of->natoms_x_compressed, step, t, state_local->box, xxtc, of->x_compression_precision) == 0) { gmx_fatal(FARGS, "XTC error - maybe you are out of disk space?"); } gmx_fwrite_tng(of->tng_low_prec, TRUE, step, t, state_local->lambda[efptFEP], (const rvec *) state_local->box, of->natoms_x_compressed, (const rvec *) xxtc, NULL, NULL); if (of->natoms_x_compressed != of->natoms_global) { sfree(xxtc); } } } }
int write_trxframe_indexed(t_trxstatus *status,t_trxframe *fr,int nind, 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]); } 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); case efXTC: case efG87: sfree(xout); break; default: break; } return 0; }