void chk_enx(const char *fn) { int nre, fnr, ndr; ener_file_t in; gmx_enxnm_t *enm = NULL; t_enxframe *fr; gmx_bool bShowTStep; real t0, old_t1, old_t2; char buf[22]; fprintf(stderr, "Checking energy file %s\n\n", fn); in = open_enx(fn, "r"); do_enxnms(in, &nre, &enm); fprintf(stderr, "%d groups in energy file", nre); snew(fr, 1); old_t2 = -2.0; old_t1 = -1.0; fnr = 0; t0 = NOTSET; bShowTStep = TRUE; while (do_enx(in, fr)) { if (fnr >= 2) { if (fabs((fr->t-old_t1)-(old_t1-old_t2)) > 0.1*(fabs(fr->t-old_t1)+fabs(old_t1-old_t2)) ) { bShowTStep = FALSE; fprintf(stderr, "\nTimesteps at t=%g don't match (%g, %g)\n", old_t1, old_t1-old_t2, fr->t-old_t1); } } old_t2 = old_t1; old_t1 = fr->t; if (t0 == NOTSET) { t0 = fr->t; } if (fnr == 0) { fprintf(stderr, "\rframe: %6s (index %6d), t: %10.3f\n", gmx_step_str(fr->step, buf), fnr, fr->t); } fnr++; } fprintf(stderr, "\n\nFound %d frames", fnr); if (bShowTStep && fnr > 1) { fprintf(stderr, " with a timestep of %g ps", (old_t1-t0)/(fnr-1)); } fprintf(stderr, ".\n"); free_enxframe(fr); free_enxnms(nre, enm); sfree(fr); }
void get_enx_state(char *fn, real t, gmx_groups_t *groups, t_inputrec *ir, t_state *state) { /* Should match the names in mdebin.c */ static const char *boxvel_nm[] = { "Box-Vel-XX", "Box-Vel-YY", "Box-Vel-ZZ", "Box-Vel-YX", "Box-Vel-ZX", "Box-Vel-ZY" }; static const char *pcouplmu_nm[] = { "Pcoupl-Mu-XX", "Pcoupl-Mu-YY", "Pcoupl-Mu-ZZ", "Pcoupl-Mu-YX", "Pcoupl-Mu-ZX", "Pcoupl-Mu-ZY" }; int ind0[] = { XX,YY,ZZ,YY,ZZ,ZZ }; int ind1[] = { XX,YY,ZZ,XX,XX,YY }; int in,nre,nfr,i,ni,npcoupl; char buf[STRLEN]; gmx_enxnm_t *enm; t_enxframe *fr; in = open_enx(fn,"r"); do_enxnms(in,&nre,&enm); snew(fr,1); nfr = 0; while ((nfr==0 || fr->t != t) && do_enx(in,fr)) { nfr++; } close_enx(in); fprintf(stderr,"\n"); if (nfr == 0 || fr->t != t) gmx_fatal(FARGS,"Could not find frame with time %f in '%s'",t,fn); npcoupl = TRICLINIC(ir->compress) ? 6 : 3; if (ir->epc == epcPARRINELLORAHMAN) { clear_mat(state->boxv); for(i=0; i<npcoupl; i++) { state->boxv[ind0[i]][ind1[i]] = find_energy(boxvel_nm[i],nre,enm,fr); } fprintf(stderr,"\nREAD %d BOX VELOCITIES FROM %s\n\n",npcoupl,fn); } if (ir->etc == etcNOSEHOOVER) { for(i=0; i<state->ngtc; i++) { ni = groups->grps[egcTC].nm_ind[i]; sprintf(buf,"Xi-%s",*(groups->grpname[ni])); state->nosehoover_xi[i] = find_energy(buf,nre,enm,fr); } fprintf(stderr,"\nREAD %d NOSE-HOOVER Xi's FROM %s\n\n",state->ngtc,fn); } free_enxnms(nre,enm); free_enxframe(fr); sfree(fr); }
void list_ene(char *fn) { int in,ndr; bool bCont; t_enxframe *fr; int i,nre,b; real rav,minthird; char **enm=NULL; printf("gmxdump: %s\n",fn); in = open_enx(fn,"r"); do_enxnms(in,&nre,&enm); printf("energy components:\n"); for(i=0; (i<nre); i++) printf("%5d %s\n",i,enm[i]); minthird=-1.0/3.0; snew(fr,1); do { bCont=do_enx(in,fr); if (bCont) { printf("\n%24s %12.5e %12s %12d\n","time:", fr->t,"step:",fr->step); if (fr->nre == nre) { printf("%24s %12s %12s %12s\n", "Component","Energy","Av. Energy","Sum Energy"); for(i=0; (i<nre); i++) printf("%24s %12.5e %12.5e %12.5e\n", enm[i],fr->ener[i].e,fr->ener[i].eav,fr->ener[i].esum); } if (fr->ndisre > 0) { printf("Distance restraint %8s %8s\n","r(t)","<r^-3>^-3"); for(i=0; i<fr->ndisre; i++) { rav=pow(fr->disre_rm3tav[i],minthird); printf("%17d %8.4f %8.4f\n",i,fr->disre_rt[i],rav); } } for(b=0; b<fr->nblock; b++) if (fr->nr[b] > 0) { printf("Block data %2d (%4d elm.) %8s\n",b,fr->nr[b],"value"); for(i=0; i<fr->nr[b]; i++) printf("%24d %8.4f\n",i,fr->block[b][i]); } } } while (bCont); close_enx(in); free_enxframe(fr); sfree(fr); sfree(enm); }
void list_ene(const char *fn) { int ndr; ener_file_t in; gmx_bool bCont; gmx_enxnm_t *enm = NULL; t_enxframe *fr; int i, j, nre, b; real rav, minthird; char buf[22]; printf("gmxdump: %s\n", fn); in = open_enx(fn, "r"); do_enxnms(in, &nre, &enm); assert(enm); /*printf("energy components:\n"); for (i = 0; (i < nre); i++) { printf("%5d %-24s (%s)\n", i, enm[i].name, enm[i].unit); }*/ minthird = -1.0/3.0; snew(fr, 1); do { bCont = do_enx(in, fr); if (bCont) { printf("\n%24s %12.5e %12s %12s\n", "time:", fr->t, "step:", gmx_step_str(fr->step, buf)); printf("%24s %12s %12s %12s\n", "", "", "nsteps:", gmx_step_str(fr->nsteps, buf)); printf("%24s %12.5e %12s %12s\n", "delta_t:", fr->dt, "sum steps:", gmx_step_str(fr->nsum, buf)); if (fr->nre == nre) { printf("%24s %12s %12s %12s\n", "Component", "Energy", "Av. Energy", "Sum Energy"); if (fr->nsum > 0) { for (i = 0; (i < nre); i++) { printf("%24s %12.5e %12.5e %12.5e\n", enm[i].name, fr->ener[i].e, fr->ener[i].eav, fr->ener[i].esum); } } else { for (i = 0; (i < nre); i++) { if(fr->ener[i].e != 0) { printf("%24s %12.5e\n", enm[i].name, fr->ener[i].e); } } } } for (b = 0; b < fr->nblock; b++) { const char *typestr = ""; t_enxblock *eb = &(fr->block[b]); printf("Block data %2d (%3d subblocks, id=%d)\n", b, eb->nsub, eb->id); if (eb->id < enxNR) { typestr = enx_block_id_name[eb->id]; } printf(" id='%s'\n", typestr); for (i = 0; i < eb->nsub; i++) { t_enxsubblock *sb = &(eb->sub[i]); printf(" Sub block %3d (%5d elems, type=%s) values:\n", i, sb->nr, xdr_datatype_names[sb->type]); switch (sb->type) { case xdr_datatype_float: for (j = 0; j < sb->nr; j++) { printf("%14d %8.4f\n", j, sb->fval[j]); } break; case xdr_datatype_double: for (j = 0; j < sb->nr; j++) { printf("%14d %10.6f\n", j, sb->dval[j]); } break; case xdr_datatype_int: for (j = 0; j < sb->nr; j++) { printf("%14d %10d\n", j, sb->ival[j]); } break; case xdr_datatype_large_int: for (j = 0; j < sb->nr; j++) { printf("%14d %s\n", j, gmx_step_str(sb->lval[j], buf)); } break; case xdr_datatype_char: for (j = 0; j < sb->nr; j++) { printf("%14d %1c\n", j, sb->cval[j]); } break; case xdr_datatype_string: for (j = 0; j < sb->nr; j++) { printf("%14d %80s\n", j, sb->sval[j]); } break; default: gmx_incons("Unknown subblock type"); } } } } } while (bCont); close_enx(in); free_enxframe(fr); sfree(fr); sfree(enm); }
int cmain (int argc, char *argv[]) { const char *desc[] = { "tpbconv can edit run input files in four ways.[PAR]", "[BB]1.[bb] by modifying the number of steps in a run input file", "with options [TT]-extend[tt], [TT]-until[tt] or [TT]-nsteps[tt]", "(nsteps=-1 means unlimited number of steps)[PAR]", "[BB]2.[bb] (OBSOLETE) by creating a run input file", "for a continuation run when your simulation has crashed due to e.g.", "a full disk, or by making a continuation run input file.", "This option is obsolete, since mdrun now writes and reads", "checkpoint files.", "[BB]Note[bb] that a frame with coordinates and velocities is needed.", "When pressure and/or Nose-Hoover temperature coupling is used", "an energy file can be supplied to get an exact continuation", "of the original run.[PAR]", "[BB]3.[bb] by creating a [TT].tpx[tt] file for a subset of your original", "tpx file, which is useful when you want to remove the solvent from", "your [TT].tpx[tt] file, or when you want to make e.g. a pure C[GRK]alpha[grk] [TT].tpx[tt] file.", "Note that you may need to use [TT]-nsteps -1[tt] (or similar) to get", "this to work.", "[BB]WARNING: this [TT].tpx[tt] file is not fully functional[bb].[PAR]", "[BB]4.[bb] by setting the charges of a specified group", "to zero. This is useful when doing free energy estimates", "using the LIE (Linear Interaction Energy) method." }; const char *top_fn, *frame_fn; t_fileio *fp; ener_file_t fp_ener = NULL; t_trnheader head; int i; gmx_large_int_t nsteps_req, run_step, frame; double run_t, state_t; gmx_bool bOK, bNsteps, bExtend, bUntil, bTime, bTraj; gmx_bool bFrame, bUse, bSel, bNeedEner, bReadEner, bScanEner, bFepState; gmx_mtop_t mtop; t_atoms atoms; t_inputrec *ir, *irnew = NULL; t_gromppopts *gopts; t_state state; rvec *newx = NULL, *newv = NULL, *tmpx, *tmpv; matrix newbox; int gnx; char *grpname; atom_id *index = NULL; int nre; gmx_enxnm_t *enm = NULL; t_enxframe *fr_ener = NULL; char buf[200], buf2[200]; output_env_t oenv; t_filenm fnm[] = { { efTPX, NULL, NULL, ffREAD }, { efTRN, "-f", NULL, ffOPTRD }, { efEDR, "-e", NULL, ffOPTRD }, { efNDX, NULL, NULL, ffOPTRD }, { efTPX, "-o", "tpxout", ffWRITE } }; #define NFILE asize(fnm) /* Command line options */ static int nsteps_req_int = 0; static real start_t = -1.0, extend_t = 0.0, until_t = 0.0; static int init_fep_state = 0; static gmx_bool bContinuation = TRUE, bZeroQ = FALSE, bVel = TRUE; static t_pargs pa[] = { { "-extend", FALSE, etREAL, {&extend_t}, "Extend runtime by this amount (ps)" }, { "-until", FALSE, etREAL, {&until_t}, "Extend runtime until this ending time (ps)" }, { "-nsteps", FALSE, etINT, {&nsteps_req_int}, "Change the number of steps" }, { "-time", FALSE, etREAL, {&start_t}, "Continue from frame at this time (ps) instead of the last frame" }, { "-zeroq", FALSE, etBOOL, {&bZeroQ}, "Set the charges of a group (from the index) to zero" }, { "-vel", FALSE, etBOOL, {&bVel}, "Require velocities from trajectory" }, { "-cont", FALSE, etBOOL, {&bContinuation}, "For exact continuation, the constraints should not be applied before the first step" }, { "-init_fep_state", FALSE, etINT, {&init_fep_state}, "fep state to initialize from" }, }; int nerror = 0; CopyRight(stderr, argv[0]); /* Parse the command line */ parse_common_args(&argc, argv, 0, NFILE, fnm, asize(pa), pa, asize(desc), desc, 0, NULL, &oenv); /* Convert int to gmx_large_int_t */ nsteps_req = nsteps_req_int; bNsteps = opt2parg_bSet("-nsteps", asize(pa), pa); bExtend = opt2parg_bSet("-extend", asize(pa), pa); bUntil = opt2parg_bSet("-until", asize(pa), pa); bFepState = opt2parg_bSet("-init_fep_state", asize(pa), pa); bTime = opt2parg_bSet("-time", asize(pa), pa); bTraj = (opt2bSet("-f", NFILE, fnm) || bTime); top_fn = ftp2fn(efTPX, NFILE, fnm); fprintf(stderr, "Reading toplogy and stuff from %s\n", top_fn); snew(ir, 1); read_tpx_state(top_fn, ir, &state, NULL, &mtop); run_step = ir->init_step; run_t = ir->init_step*ir->delta_t + ir->init_t; if (!EI_STATE_VELOCITY(ir->eI)) { bVel = FALSE; } if (bTraj) { fprintf(stderr, "\n" "NOTE: Reading the state from trajectory is an obsolete feature of tpbconv.\n" " Continuation should be done by loading a checkpoint file with mdrun -cpi\n" " This guarantees that all state variables are transferred.\n" " tpbconv is now only useful for increasing nsteps,\n" " but even that can often be avoided by using mdrun -maxh\n" "\n"); if (ir->bContinuation != bContinuation) { fprintf(stderr, "Modifying ir->bContinuation to %s\n", bool_names[bContinuation]); } ir->bContinuation = bContinuation; bNeedEner = (ir->epc == epcPARRINELLORAHMAN || ir->etc == etcNOSEHOOVER); bReadEner = (bNeedEner && ftp2bSet(efEDR, NFILE, fnm)); bScanEner = (bReadEner && !bTime); if (ir->epc != epcNO || EI_SD(ir->eI) || ir->eI == eiBD) { fprintf(stderr, "NOTE: The simulation uses pressure coupling and/or stochastic dynamics.\n" "tpbconv can not provide binary identical continuation.\n" "If you want that, supply a checkpoint file to mdrun\n\n"); } if (EI_SD(ir->eI) || ir->eI == eiBD) { fprintf(stderr, "\nChanging ld-seed from %d ", ir->ld_seed); ir->ld_seed = make_seed(); fprintf(stderr, "to %d\n\n", ir->ld_seed); } frame_fn = ftp2fn(efTRN, NFILE, fnm); if (fn2ftp(frame_fn) == efCPT) { int sim_part; fprintf(stderr, "\nREADING STATE FROM CHECKPOINT %s...\n\n", frame_fn); read_checkpoint_state(frame_fn, &sim_part, &run_step, &run_t, &state); } else { fprintf(stderr, "\nREADING COORDS, VELS AND BOX FROM TRAJECTORY %s...\n\n", frame_fn); fp = open_trn(frame_fn, "r"); if (bScanEner) { fp_ener = open_enx(ftp2fn(efEDR, NFILE, fnm), "r"); do_enxnms(fp_ener, &nre, &enm); snew(fr_ener, 1); fr_ener->t = -1e-12; } /* Now scan until the last set of x and v (step == 0) * or the ones at step step. */ bFrame = TRUE; frame = 0; while (bFrame) { bFrame = fread_trnheader(fp, &head, &bOK); if (bOK && frame == 0) { if (mtop.natoms != head.natoms) { gmx_fatal(FARGS, "Number of atoms in Topology (%d) " "is not the same as in Trajectory (%d)\n", mtop.natoms, head.natoms); } snew(newx, head.natoms); snew(newv, head.natoms); } bFrame = bFrame && bOK; if (bFrame) { bOK = fread_htrn(fp, &head, newbox, newx, newv, NULL); } bFrame = bFrame && bOK; bUse = FALSE; if (bFrame && (head.x_size) && (head.v_size || !bVel)) { bUse = TRUE; if (bScanEner) { /* Read until the energy time is >= the trajectory time */ while (fr_ener->t < head.t && do_enx(fp_ener, fr_ener)) { ; } bUse = (fr_ener->t == head.t); } if (bUse) { tmpx = newx; newx = state.x; state.x = tmpx; tmpv = newv; newv = state.v; state.v = tmpv; run_t = head.t; run_step = head.step; state.fep_state = head.fep_state; state.lambda[efptFEP] = head.lambda; copy_mat(newbox, state.box); } } if (bFrame || !bOK) { sprintf(buf, "\r%s %s frame %s%s: step %s%s time %s", "%s", "%s", "%6", gmx_large_int_fmt, "%6", gmx_large_int_fmt, " %8.3f"); fprintf(stderr, buf, bUse ? "Read " : "Skipped", ftp2ext(fn2ftp(frame_fn)), frame, head.step, head.t); frame++; if (bTime && (head.t >= start_t)) { bFrame = FALSE; } } } if (bScanEner) { close_enx(fp_ener); free_enxframe(fr_ener); free_enxnms(nre, enm); } close_trn(fp); fprintf(stderr, "\n"); if (!bOK) { fprintf(stderr, "%s frame %s (step %s, time %g) is incomplete\n", ftp2ext(fn2ftp(frame_fn)), gmx_step_str(frame-1, buf2), gmx_step_str(head.step, buf), head.t); } fprintf(stderr, "\nUsing frame of step %s time %g\n", gmx_step_str(run_step, buf), run_t); if (bNeedEner) { if (bReadEner) { get_enx_state(ftp2fn(efEDR, NFILE, fnm), run_t, &mtop.groups, ir, &state); } else { fprintf(stderr, "\nWARNING: The simulation uses %s temperature and/or %s pressure coupling,\n" " the continuation will only be exact when an energy file is supplied\n\n", ETCOUPLTYPE(etcNOSEHOOVER), EPCOUPLTYPE(epcPARRINELLORAHMAN)); } } if (bFepState) { ir->fepvals->init_fep_state = init_fep_state; } } } if (bNsteps) { fprintf(stderr, "Setting nsteps to %s\n", gmx_step_str(nsteps_req, buf)); ir->nsteps = nsteps_req; } else { /* Determine total number of steps remaining */ if (bExtend) { ir->nsteps = ir->nsteps - (run_step - ir->init_step) + (gmx_large_int_t)(extend_t/ir->delta_t + 0.5); printf("Extending remaining runtime of by %g ps (now %s steps)\n", extend_t, gmx_step_str(ir->nsteps, buf)); } else if (bUntil) { printf("nsteps = %s, run_step = %s, current_t = %g, until = %g\n", gmx_step_str(ir->nsteps, buf), gmx_step_str(run_step, buf2), run_t, until_t); ir->nsteps = (gmx_large_int_t)((until_t - run_t)/ir->delta_t + 0.5); printf("Extending remaining runtime until %g ps (now %s steps)\n", until_t, gmx_step_str(ir->nsteps, buf)); } else { ir->nsteps -= run_step - ir->init_step; /* Print message */ printf("%s steps (%g ps) remaining from first run.\n", gmx_step_str(ir->nsteps, buf), ir->nsteps*ir->delta_t); } } if (bNsteps || bZeroQ || (ir->nsteps > 0)) { ir->init_step = run_step; if (ftp2bSet(efNDX, NFILE, fnm) || !(bNsteps || bExtend || bUntil || bTraj)) { atoms = gmx_mtop_global_atoms(&mtop); get_index(&atoms, ftp2fn_null(efNDX, NFILE, fnm), 1, &gnx, &index, &grpname); if (!bZeroQ) { bSel = (gnx != state.natoms); for (i = 0; ((i < gnx) && (!bSel)); i++) { bSel = (i != index[i]); } } else { bSel = FALSE; } if (bSel) { fprintf(stderr, "Will write subset %s of original tpx containing %d " "atoms\n", grpname, gnx); reduce_topology_x(gnx, index, &mtop, state.x, state.v); state.natoms = gnx; } else if (bZeroQ) { zeroq(gnx, index, &mtop); fprintf(stderr, "Zero-ing charges for group %s\n", grpname); } else { fprintf(stderr, "Will write full tpx file (no selection)\n"); } } state_t = ir->init_t + ir->init_step*ir->delta_t; sprintf(buf, "Writing statusfile with starting step %s%s and length %s%s steps...\n", "%10", gmx_large_int_fmt, "%10", gmx_large_int_fmt); fprintf(stderr, buf, ir->init_step, ir->nsteps); fprintf(stderr, " time %10.3f and length %10.3f ps\n", state_t, ir->nsteps*ir->delta_t); write_tpx_state(opt2fn("-o", NFILE, fnm), ir, &state, &mtop); } else { printf("You've simulated long enough. Not writing tpr file\n"); } thanx(stderr); return 0; }
void print_ebin(ener_file_t fp_ene, gmx_bool bEne, gmx_bool bDR, gmx_bool bOR, FILE *log, gmx_int64_t step, double time, int mode, t_mdebin *md, t_fcdata *fcd, gmx_groups_t *groups, t_grpopts *opts) { /*static char **grpnms=NULL;*/ char buf[246]; int i, j, n, ni, nj, b; int ndisre = 0; real *disre_rm3tav, *disre_rt; /* these are for the old-style blocks (1 subblock, only reals), because there can be only one per ID for these */ int nr[enxNR]; int id[enxNR]; real *block[enxNR]; t_enxframe fr; switch (mode) { case eprNORMAL: init_enxframe(&fr); fr.t = time; fr.step = step; fr.nsteps = md->ebin->nsteps; fr.dt = md->delta_t; fr.nsum = md->ebin->nsum; fr.nre = (bEne) ? md->ebin->nener : 0; fr.ener = md->ebin->e; ndisre = bDR ? fcd->disres.npair : 0; disre_rm3tav = fcd->disres.rm3tav; disre_rt = fcd->disres.rt; /* Optional additional old-style (real-only) blocks. */ for (i = 0; i < enxNR; i++) { nr[i] = 0; } if (fcd->orires.nr > 0 && bOR) { diagonalize_orires_tensors(&(fcd->orires)); nr[enxOR] = fcd->orires.nr; block[enxOR] = fcd->orires.otav; id[enxOR] = enxOR; nr[enxORI] = (fcd->orires.oinsl != fcd->orires.otav) ? fcd->orires.nr : 0; block[enxORI] = fcd->orires.oinsl; id[enxORI] = enxORI; nr[enxORT] = fcd->orires.nex*12; block[enxORT] = fcd->orires.eig; id[enxORT] = enxORT; } /* whether we are going to wrte anything out: */ if (fr.nre || ndisre || nr[enxOR] || nr[enxORI]) { /* the old-style blocks go first */ fr.nblock = 0; for (i = 0; i < enxNR; i++) { if (nr[i] > 0) { fr.nblock = i + 1; } } add_blocks_enxframe(&fr, fr.nblock); for (b = 0; b < fr.nblock; b++) { add_subblocks_enxblock(&(fr.block[b]), 1); fr.block[b].id = id[b]; fr.block[b].sub[0].nr = nr[b]; #if !GMX_DOUBLE fr.block[b].sub[0].type = xdr_datatype_float; fr.block[b].sub[0].fval = block[b]; #else fr.block[b].sub[0].type = xdr_datatype_double; fr.block[b].sub[0].dval = block[b]; #endif } /* check for disre block & fill it. */ if (ndisre > 0) { int db = fr.nblock; fr.nblock += 1; add_blocks_enxframe(&fr, fr.nblock); add_subblocks_enxblock(&(fr.block[db]), 2); fr.block[db].id = enxDISRE; fr.block[db].sub[0].nr = ndisre; fr.block[db].sub[1].nr = ndisre; #if !GMX_DOUBLE fr.block[db].sub[0].type = xdr_datatype_float; fr.block[db].sub[1].type = xdr_datatype_float; fr.block[db].sub[0].fval = disre_rt; fr.block[db].sub[1].fval = disre_rm3tav; #else fr.block[db].sub[0].type = xdr_datatype_double; fr.block[db].sub[1].type = xdr_datatype_double; fr.block[db].sub[0].dval = disre_rt; fr.block[db].sub[1].dval = disre_rm3tav; #endif } /* here we can put new-style blocks */ /* Free energy perturbation blocks */ if (md->dhc) { mde_delta_h_coll_handle_block(md->dhc, &fr, fr.nblock); } /* we can now free & reset the data in the blocks */ if (md->dhc) { mde_delta_h_coll_reset(md->dhc); } /* do the actual I/O */ do_enx(fp_ene, &fr); if (fr.nre) { /* We have stored the sums, so reset the sum history */ reset_ebin_sums(md->ebin); } } free_enxframe(&fr); break; case eprAVER: if (log) { pprint(log, "A V E R A G E S", md); } break; case eprRMS: if (log) { pprint(log, "R M S - F L U C T U A T I O N S", md); } break; default: gmx_fatal(FARGS, "Invalid print mode (%d)", mode); } if (log) { for (i = 0; i < opts->ngtc; i++) { if (opts->annealing[i] != eannNO) { fprintf(log, "Current ref_t for group %s: %8.1f\n", *(groups->grpname[groups->grps[egcTC].nm_ind[i]]), opts->ref_t[i]); } } if (mode == eprNORMAL && fcd->orires.nr > 0) { print_orires_log(log, &(fcd->orires)); } fprintf(log, " Energies (%s)\n", unit_energy); pr_ebin(log, md->ebin, md->ie, md->f_nre+md->nCrmsd, 5, mode, TRUE); fprintf(log, "\n"); if (mode == eprAVER) { if (md->bDynBox) { pr_ebin(log, md->ebin, md->ib, md->bTricl ? NTRICLBOXS : NBOXS, 5, mode, TRUE); fprintf(log, "\n"); } if (md->bConstrVir) { fprintf(log, " Constraint Virial (%s)\n", unit_energy); pr_ebin(log, md->ebin, md->isvir, 9, 3, mode, FALSE); fprintf(log, "\n"); fprintf(log, " Force Virial (%s)\n", unit_energy); pr_ebin(log, md->ebin, md->ifvir, 9, 3, mode, FALSE); fprintf(log, "\n"); } fprintf(log, " Total Virial (%s)\n", unit_energy); pr_ebin(log, md->ebin, md->ivir, 9, 3, mode, FALSE); fprintf(log, "\n"); fprintf(log, " Pressure (%s)\n", unit_pres_bar); pr_ebin(log, md->ebin, md->ipres, 9, 3, mode, FALSE); fprintf(log, "\n"); if (md->bMu) { fprintf(log, " Total Dipole (%s)\n", unit_dipole_D); pr_ebin(log, md->ebin, md->imu, 3, 3, mode, FALSE); fprintf(log, "\n"); } if (md->nE > 1) { if (md->print_grpnms == NULL) { snew(md->print_grpnms, md->nE); n = 0; for (i = 0; (i < md->nEg); i++) { ni = groups->grps[egcENER].nm_ind[i]; for (j = i; (j < md->nEg); j++) { nj = groups->grps[egcENER].nm_ind[j]; sprintf(buf, "%s-%s", *(groups->grpname[ni]), *(groups->grpname[nj])); md->print_grpnms[n++] = gmx_strdup(buf); } } } sprintf(buf, "Epot (%s)", unit_energy); fprintf(log, "%15s ", buf); for (i = 0; (i < egNR); i++) { if (md->bEInd[i]) { fprintf(log, "%12s ", egrp_nm[i]); } } fprintf(log, "\n"); for (i = 0; (i < md->nE); i++) { fprintf(log, "%15s", md->print_grpnms[i]); pr_ebin(log, md->ebin, md->igrp[i], md->nEc, md->nEc, mode, FALSE); } fprintf(log, "\n"); } if (md->nTC > 1) { pr_ebin(log, md->ebin, md->itemp, md->nTC, 4, mode, TRUE); fprintf(log, "\n"); } if (md->nU > 1) { fprintf(log, "%15s %12s %12s %12s\n", "Group", "Ux", "Uy", "Uz"); for (i = 0; (i < md->nU); i++) { ni = groups->grps[egcACC].nm_ind[i]; fprintf(log, "%15s", *groups->grpname[ni]); pr_ebin(log, md->ebin, md->iu+3*i, 3, 3, mode, FALSE); } fprintf(log, "\n"); } } } }
int open_enx(char *fn,char *mode) { int fp,nre,i; char **nm=NULL; t_enxframe *fr; bool bDum=TRUE; /* Energy files should always be opened as binary files, * but that is checked in gmx_fio_open. */ if (mode[0]=='r') { fp=gmx_fio_open(fn,mode); gmx_fio_select(fp); gmx_fio_setprecision(fp,FALSE); do_enxnms(fp,&nre,&nm); snew(fr,1); do_eheader(fp,fr,&bDum); /* Now check whether this file is in single precision */ if (((fr->e_size && (fr->nre == nre) && (nre*4*sizeof(float) == fr->e_size)) || (fr->d_size && (fr->ndisre*sizeof(float)*2+sizeof(int) == fr->d_size)))){ fprintf(stderr,"Opened %s as single precision energy file\n",fn); for(i=0; (i<nre); i++) sfree(nm[i]); sfree(nm); } else { gmx_fio_rewind(fp); gmx_fio_select(fp); gmx_fio_setprecision(fp,TRUE); do_enxnms(fp,&nre,&nm); do_eheader(fp,fr,&bDum); if (((fr->e_size && (fr->nre == nre) && (nre*4*sizeof(double) == fr->e_size)) || (fr->d_size && (fr->ndisre*sizeof(double)*2+sizeof(int) == fr->d_size)))) fprintf(stderr,"Opened %s as double precision energy file\n",fn); else { if (empty_file(fn)) fatal_error(0,"File %s is empty",fn); else fatal_error(0,"Energy file %s not recognized, maybe different CPU?", fn); } for(i=0; (i<nre); i++) sfree(nm[i]); sfree(nm); } free_enxframe(fr); sfree(fr); gmx_fio_rewind(fp); } else fp = gmx_fio_open(fn,mode); framenr=0; return fp; }
ener_file_t open_enx(const char *fn,const char *mode) { int nre,i; gmx_enxnm_t *nms=NULL; int file_version=-1; t_enxframe *fr; gmx_bool bWrongPrecision,bOK=TRUE; struct ener_file *ef; snew(ef,1); if (mode[0]=='r') { ef->fio=gmx_fio_open(fn,mode); gmx_fio_checktype(ef->fio); gmx_fio_setprecision(ef->fio,FALSE); do_enxnms(ef,&nre,&nms); snew(fr,1); do_eheader(ef,&file_version,fr,nre,&bWrongPrecision,&bOK); if(!bOK) { gmx_file("Cannot read energy file header. Corrupt file?"); } /* Now check whether this file is in single precision */ if (!bWrongPrecision && ((fr->e_size && (fr->nre == nre) && (nre*4*(long int)sizeof(float) == fr->e_size)) ) ) { fprintf(stderr,"Opened %s as single precision energy file\n",fn); free_enxnms(nre,nms); } else { gmx_fio_rewind(ef->fio); gmx_fio_checktype(ef->fio); gmx_fio_setprecision(ef->fio,TRUE); do_enxnms(ef,&nre,&nms); do_eheader(ef,&file_version,fr,nre,&bWrongPrecision,&bOK); if(!bOK) { gmx_file("Cannot write energy file header; maybe you are out of quota?"); } if (((fr->e_size && (fr->nre == nre) && (nre*4*(long int)sizeof(double) == fr->e_size)) )) fprintf(stderr,"Opened %s as double precision energy file\n", fn); else { if (empty_file(fn)) gmx_fatal(FARGS,"File %s is empty",fn); else gmx_fatal(FARGS,"Energy file %s not recognized, maybe different CPU?", fn); } free_enxnms(nre,nms); } free_enxframe(fr); sfree(fr); gmx_fio_rewind(ef->fio); } else ef->fio = gmx_fio_open(fn,mode); ef->framenr=0; ef->frametime=0; return ef; }
void get_enx_state(const char *fn, real t, gmx_groups_t *groups, t_inputrec *ir, t_state *state) { /* Should match the names in mdebin.c */ static const char *boxvel_nm[] = { "Box-Vel-XX", "Box-Vel-YY", "Box-Vel-ZZ", "Box-Vel-YX", "Box-Vel-ZX", "Box-Vel-ZY" }; static const char *pcouplmu_nm[] = { "Pcoupl-Mu-XX", "Pcoupl-Mu-YY", "Pcoupl-Mu-ZZ", "Pcoupl-Mu-YX", "Pcoupl-Mu-ZX", "Pcoupl-Mu-ZY" }; static const char *baro_nm[] = { "Barostat" }; int ind0[] = { XX,YY,ZZ,YY,ZZ,ZZ }; int ind1[] = { XX,YY,ZZ,XX,XX,YY }; int nre,nfr,i,j,ni,npcoupl; char buf[STRLEN]; const char *bufi; gmx_enxnm_t *enm=NULL; t_enxframe *fr; ener_file_t in; in = open_enx(fn,"r"); do_enxnms(in,&nre,&enm); snew(fr,1); nfr = 0; while ((nfr==0 || fr->t != t) && do_enx(in,fr)) { nfr++; } close_enx(in); fprintf(stderr,"\n"); if (nfr == 0 || fr->t != t) gmx_fatal(FARGS,"Could not find frame with time %f in '%s'",t,fn); npcoupl = TRICLINIC(ir->compress) ? 6 : 3; if (ir->epc == epcPARRINELLORAHMAN) { clear_mat(state->boxv); for(i=0; i<npcoupl; i++) { state->boxv[ind0[i]][ind1[i]] = find_energy(boxvel_nm[i],nre,enm,fr); } fprintf(stderr,"\nREAD %d BOX VELOCITIES FROM %s\n\n",npcoupl,fn); } if (ir->etc == etcNOSEHOOVER) { for(i=0; i<state->ngtc; i++) { ni = groups->grps[egcTC].nm_ind[i]; bufi = *(groups->grpname[ni]); for(j=0; (j<state->nhchainlength); j++) { sprintf(buf,"Xi-%d-%s",j,bufi); state->nosehoover_xi[i] = find_energy(buf,nre,enm,fr); sprintf(buf,"vXi-%d-%s",j,bufi); state->nosehoover_vxi[i] = find_energy(buf,nre,enm,fr); } } fprintf(stderr,"\nREAD %d NOSE-HOOVER Xi chains FROM %s\n\n",state->ngtc,fn); if (IR_NPT_TROTTER(ir)) { for(i=0; i<state->nnhpres; i++) { bufi = baro_nm[0]; /* All barostat DOF's together for now */ for(j=0; (j<state->nhchainlength); j++) { sprintf(buf,"Xi-%d-%s",j,bufi); state->nhpres_xi[i] = find_energy(buf,nre,enm,fr); sprintf(buf,"vXi-%d-%s",j,bufi); state->nhpres_vxi[i] = find_energy(buf,nre,enm,fr); } } fprintf(stderr,"\nREAD %d NOSE-HOOVER BAROSTAT Xi chains FROM %s\n\n",state->nnhpres,fn); } } free_enxnms(nre,enm); free_enxframe(fr); sfree(fr); }
static int scan_ene_files(char **fnms, int nfiles, real *readtime, real *timestep, int *nremax) { /* Check number of energy terms and start time of all files */ int f, nre, nremin = 0, nresav = 0; ener_file_t in; real t1, t2; char inputstring[STRLEN]; gmx_enxnm_t *enm; t_enxframe *fr; snew(fr, 1); for (f = 0; f < nfiles; f++) { in = open_enx(fnms[f], "r"); enm = NULL; do_enxnms(in, &nre, &enm); if (f == 0) { nresav = nre; nremin = nre; *nremax = nre; do_enx(in, fr); t1 = fr->t; do_enx(in, fr); t2 = fr->t; *timestep = t2-t1; readtime[f] = t1; close_enx(in); } else { nremin = std::min(nremin, fr->nre); *nremax = std::max(*nremax, fr->nre); if (nre != nresav) { fprintf(stderr, "Energy files don't match, different number of energies:\n" " %s: %d\n %s: %d\n", fnms[f-1], nresav, fnms[f], fr->nre); fprintf(stderr, "\nContinue conversion using only the first %d terms (n/y)?\n" "(you should be sure that the energy terms match)\n", nremin); if (NULL == fgets(inputstring, STRLEN-1, stdin)) { gmx_fatal(FARGS, "Error reading user input"); } if (inputstring[0] != 'y' && inputstring[0] != 'Y') { fprintf(stderr, "Will not convert\n"); exit(0); } nresav = fr->nre; } do_enx(in, fr); readtime[f] = fr->t; close_enx(in); } fprintf(stderr, "\n"); free_enxnms(nre, enm); } free_enxframe(fr); sfree(fr); return nremin; }
int open_enx(const char *fn,const char *mode) { int fp,nre,i; gmx_enxnm_t *nms=NULL; int file_version=-1; t_enxframe *fr; bool bDum=TRUE; if (mode[0]=='r') { fp=gmx_fio_open(fn,mode); gmx_fio_select(fp); gmx_fio_setprecision(fp,FALSE); do_enxnms(fp,&nre,&nms); snew(fr,1); do_eheader(fp,&file_version,fr,TRUE,&bDum); if(!bDum) { gmx_file("Cannot read energy file header. Corrupt file?"); } /* Now check whether this file is in single precision */ if (((fr->e_size && (fr->nre == nre) && (nre*4*sizeof(float) == fr->e_size)) || (fr->d_size && (fr->ndisre*sizeof(float)*2+sizeof(int) == fr->d_size)))){ fprintf(stderr,"Opened %s as single precision energy file\n",fn); free_enxnms(nre,nms); } else { gmx_fio_rewind(fp); gmx_fio_select(fp); gmx_fio_setprecision(fp,TRUE); do_enxnms(fp,&nre,&nms); do_eheader(fp,&file_version,fr,TRUE,&bDum); if(!bDum) { gmx_file("Cannot write energy file header; maybe you are out of quota?"); } if (((fr->e_size && (fr->nre == nre) && (nre*4*sizeof(double) == fr->e_size)) || (fr->d_size && (fr->ndisre*sizeof(double)*2+sizeof(int) == fr->d_size)))) fprintf(stderr,"Opened %s as double precision energy file\n",fn); else { if (empty_file(fn)) gmx_fatal(FARGS,"File %s is empty",fn); else gmx_fatal(FARGS,"Energy file %s not recognized, maybe different CPU?", fn); } free_enxnms(nre,nms); } free_enxframe(fr); sfree(fr); gmx_fio_rewind(fp); } else fp = gmx_fio_open(fn,mode); framenr=0; frametime=0; return fp; }
void comp_enx(const char *fn1, const char *fn2, real ftol, real abstol, const char *lastener) { int nre, nre1, nre2; ener_file_t in1, in2; int i, j, maxener, *ind1, *ind2, *have; gmx_enxnm_t *enm1 = NULL, *enm2 = NULL; t_enxframe *fr1, *fr2; gmx_bool b1, b2; fprintf(stdout, "comparing energy file %s and %s\n\n", fn1, fn2); in1 = open_enx(fn1, "r"); in2 = open_enx(fn2, "r"); do_enxnms(in1, &nre1, &enm1); do_enxnms(in2, &nre2, &enm2); if (nre1 != nre2) { fprintf(stdout, "There are %d and %d terms in the energy files\n\n", nre1, nre2); } else { fprintf(stdout, "There are %d terms in the energy files\n\n", nre1); } snew(ind1, nre1); snew(ind2, nre2); snew(have, nre2); nre = 0; for (i = 0; i < nre1; i++) { for (j = 0; j < nre2; j++) { if (enernm_equal(enm1[i].name, enm2[j].name)) { ind1[nre] = i; ind2[nre] = j; have[j] = 1; nre++; break; } } if (nre == 0 || ind1[nre-1] != i) { cmp_str(stdout, "enm", i, enm1[i].name, "-"); } } for (i = 0; i < nre2; i++) { if (have[i] == 0) { cmp_str(stdout, "enm", i, "-", enm2[i].name); } } maxener = nre; for (i = 0; i < nre; i++) { if ((lastener != NULL) && (std::strstr(enm1[i].name, lastener) != NULL)) { maxener = i+1; break; } } fprintf(stdout, "There are %d terms to compare in the energy files\n\n", maxener); for (i = 0; i < maxener; i++) { cmp_str(stdout, "unit", i, enm1[ind1[i]].unit, enm2[ind2[i]].unit); } snew(fr1, 1); snew(fr2, 1); do { b1 = do_enx(in1, fr1); b2 = do_enx(in2, fr2); if (b1 && !b2) { fprintf(stdout, "\nEnd of file on %s but not on %s\n", fn2, fn1); } else if (!b1 && b2) { fprintf(stdout, "\nEnd of file on %s but not on %s\n", fn1, fn2); } else if (!b1 && !b2) { fprintf(stdout, "\nFiles read successfully\n"); } else { cmp_real(stdout, "t", -1, fr1->t, fr2->t, ftol, abstol); cmp_int(stdout, "step", -1, fr1->step, fr2->step); /* We don't want to print the nre mismatch for every frame */ /* cmp_int(stdout,"nre",-1,fr1->nre,fr2->nre); */ if ((fr1->nre >= nre) && (fr2->nre >= nre)) { cmp_energies(stdout, fr1->step, fr1->step, fr1->ener, fr2->ener, enm1, ftol, abstol, nre, ind1, ind2, maxener); } /*cmp_disres(fr1,fr2,ftol,abstol);*/ cmp_eblocks(fr1, fr2, ftol, abstol); } } while (b1 && b2); close_enx(in1); close_enx(in2); free_enxframe(fr2); sfree(fr2); free_enxframe(fr1); sfree(fr1); }
//! Helper function to clean up resources void done_enxframe(t_enxframe *fr) { // Free the contents, then the pointer itself free_enxframe(fr); sfree(fr); }