2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2013, The GROMACS development team.
6 * Copyright (c) 2013,2014, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
50 #include "checkpoint.h"
51 #include "mtop_util.h"
52 #include "gromacs/fileio/xtcio.h"
53 #include "gromacs/fileio/enxio.h"
54 #include "gromacs/fileio/gmxfio.h"
55 #include "gromacs/fileio/tpxio.h"
56 #include "gromacs/fileio/trnio.h"
57 #include "gromacs/utility/futil.h"
58 #include "gromacs/fileio/tngio.h"
59 #include "gromacs/fileio/tngio_for_tools.h"
65 #include "gromacs/commandline/pargs.h"
66 #include "gromacs/fileio/mtxio.h"
67 #include "gromacs/gmxpreprocess/gmxcpp.h"
68 #include "gromacs/linearalgebra/sparsematrix.h"
69 #include "gromacs/utility/fatalerror.h"
70 #include "gromacs/utility/smalloc.h"
72 static void list_tpx(const char *fn, gmx_bool bShowNumbers, const char *mdpfn,
76 int fp, indent, i, j, **gcount, atot;
85 read_tpxheader(fn, &tpx, TRUE, NULL, NULL);
89 &state, tpx.bF ? f : NULL,
90 tpx.bTop ? &mtop : NULL);
94 gp = gmx_fio_fopen(mdpfn, "w");
95 pr_inputrec(gp, 0, NULL, &(ir), TRUE);
103 top = gmx_mtop_t_to_t_topology(&mtop);
106 if (available(stdout, &tpx, 0, fn))
109 indent = pr_title(stdout, indent, fn);
110 pr_inputrec(stdout, 0, "inputrec", tpx.bIr ? &(ir) : NULL, FALSE);
113 pr_header(stdout, indent, "header", &(tpx));
117 pr_mtop(stdout, indent, "topology", &(mtop), bShowNumbers);
121 pr_top(stdout, indent, "topology", &(top), bShowNumbers);
124 pr_rvecs(stdout, indent, "box", tpx.bBox ? state.box : NULL, DIM);
125 pr_rvecs(stdout, indent, "box_rel", tpx.bBox ? state.box_rel : NULL, DIM);
126 pr_rvecs(stdout, indent, "boxv", tpx.bBox ? state.boxv : NULL, DIM);
127 pr_rvecs(stdout, indent, "pres_prev", tpx.bBox ? state.pres_prev : NULL, DIM);
128 pr_rvecs(stdout, indent, "svir_prev", tpx.bBox ? state.svir_prev : NULL, DIM);
129 pr_rvecs(stdout, indent, "fvir_prev", tpx.bBox ? state.fvir_prev : NULL, DIM);
130 /* leave nosehoover_xi in for now to match the tpr version */
131 pr_doubles(stdout, indent, "nosehoover_xi", state.nosehoover_xi, state.ngtc);
132 /*pr_doubles(stdout,indent,"nosehoover_vxi",state.nosehoover_vxi,state.ngtc);*/
133 /*pr_doubles(stdout,indent,"therm_integral",state.therm_integral,state.ngtc);*/
134 pr_rvecs(stdout, indent, "x", tpx.bX ? state.x : NULL, state.natoms);
135 pr_rvecs(stdout, indent, "v", tpx.bV ? state.v : NULL, state.natoms);
138 pr_rvecs(stdout, indent, "f", f, state.natoms);
142 groups = &mtop.groups;
145 for (i = 0; (i < egcNR); i++)
147 snew(gcount[i], groups->grps[i].nr);
150 for (i = 0; (i < mtop.natoms); i++)
152 for (j = 0; (j < egcNR); j++)
154 gcount[j][ggrpnr(groups, j, i)]++;
157 printf("Group statistics\n");
158 for (i = 0; (i < egcNR); i++)
161 printf("%-12s: ", gtypes[i]);
162 for (j = 0; (j < groups->grps[i].nr); j++)
164 printf(" %5d", gcount[i][j]);
165 atot += gcount[i][j];
167 printf(" (total %d atoms)\n", atot);
176 static void list_top(const char *fn)
182 char *cppopts[] = { NULL };
184 status = cpp_open_file(fn, &handle, cppopts);
187 gmx_fatal(FARGS, cpp_error(&handle, status));
191 status = cpp_read_line(&handle, BUFLEN, buf);
192 done = (status == eCPP_EOF);
195 if (status != eCPP_OK)
197 gmx_fatal(FARGS, cpp_error(&handle, status));
206 status = cpp_close_file(&handle);
207 if (status != eCPP_OK)
209 gmx_fatal(FARGS, cpp_error(&handle, status));
213 static void list_trn(const char *fn)
215 t_fileio *fpread, *fpwrite;
223 fpread = open_trn(fn, "r");
224 fpwrite = open_tpx(NULL, "w");
225 gmx_fio_setdebug(fpwrite, TRUE);
228 while (fread_trnheader(fpread, &trn, &bOK))
233 if (fread_htrn(fpread, &trn,
234 trn.box_size ? box : NULL,
235 trn.x_size ? x : NULL,
236 trn.v_size ? v : NULL,
237 trn.f_size ? f : NULL))
239 sprintf(buf, "%s frame %d", fn, nframe);
241 indent = pr_title(stdout, indent, buf);
242 pr_indent(stdout, indent);
243 fprintf(stdout, "natoms=%10d step=%10d time=%12.7e lambda=%10g\n",
244 trn.natoms, trn.step, trn.t, trn.lambda);
247 pr_rvecs(stdout, indent, "box", box, DIM);
251 pr_rvecs(stdout, indent, "x", x, trn.natoms);
255 pr_rvecs(stdout, indent, "v", v, trn.natoms);
259 pr_rvecs(stdout, indent, "f", f, trn.natoms);
264 fprintf(stderr, "\nWARNING: Incomplete frame: nr %d, t=%g\n",
275 fprintf(stderr, "\nWARNING: Incomplete frame header: nr %d, t=%g\n",
282 void list_xtc(const char *fn)
289 int nframe, natoms, step;
293 xd = open_xtc(fn, "r");
294 read_first_xtc(xd, &natoms, &step, &time, box, &x, &prec, &bOK);
299 sprintf(buf, "%s frame %d", fn, nframe);
301 indent = pr_title(stdout, indent, buf);
302 pr_indent(stdout, indent);
303 fprintf(stdout, "natoms=%10d step=%10d time=%12.7e prec=%10g\n",
304 natoms, step, time, prec);
305 pr_rvecs(stdout, indent, "box", box, DIM);
306 pr_rvecs(stdout, indent, "x", x, natoms);
309 while (read_next_xtc(xd, natoms, &step, &time, box, x, &prec, &bOK));
312 fprintf(stderr, "\nWARNING: Incomplete frame at time %g\n", time);
318 /*! \brief Callback used by list_tng_for_gmx_dump. */
319 static void list_tng_inner(const char *fn,
320 gmx_bool bFirstFrame,
324 gmx_int64_t n_values_per_frame,
335 sprintf(buf, "%s frame %" GMX_PRId64, fn, nframe);
337 indent = pr_title(stdout, indent, buf);
338 pr_indent(stdout, indent);
339 fprintf(stdout, "natoms=%10" GMX_PRId64 " step=%10" GMX_PRId64 " time=%12.7e",
340 n_atoms, step, frame_time);
343 fprintf(stdout, " prec=%10g", prec);
345 fprintf(stdout, "\n");
347 pr_reals_of_dim(stdout, indent, block_name, values, n_atoms, n_values_per_frame);
350 static void list_tng(const char gmx_unused *fn)
353 tng_trajectory_t tng;
354 gmx_int64_t nframe = 0;
355 gmx_int64_t i, *block_ids = NULL, step, ndatablocks;
358 gmx_tng_open(fn, 'r', &tng);
359 gmx_print_tng_molecule_system(tng, stdout);
361 bOK = gmx_get_tng_data_block_types_of_next_frame(tng, -1,
368 for (i = 0; i < ndatablocks; i++)
371 real prec, *values = NULL;
372 gmx_int64_t n_values_per_frame, n_atoms;
373 char block_name[STRLEN];
375 gmx_get_tng_data_next_frame_of_block_type(tng, block_ids[i], &values,
377 &n_values_per_frame, &n_atoms,
379 block_name, STRLEN, &bOK);
382 /* Can't write any output because we don't know what
384 fprintf(stderr, "\nWARNING: Incomplete frame at time %g, will not write output\n", frame_time);
385 list_tng_inner(fn, (0 == i), values, step, frame_time,
386 n_values_per_frame, n_atoms, prec, nframe, block_name);
391 while (gmx_get_tng_data_block_types_of_next_frame(tng, step,
407 void list_trx(const char *fn)
416 else if ((ftp == efTRR) || (ftp == efTRJ))
420 else if (ftp == efTNG)
426 fprintf(stderr, "File %s is of an unsupported type. Try using the command\n 'less %s'\n",
431 void list_ene(const char *fn)
436 gmx_enxnm_t *enm = NULL;
442 printf("gmx dump: %s\n", fn);
443 in = open_enx(fn, "r");
444 do_enxnms(in, &nre, &enm);
447 printf("energy components:\n");
448 for (i = 0; (i < nre); i++)
450 printf("%5d %-24s (%s)\n", i, enm[i].name, enm[i].unit);
457 bCont = do_enx(in, fr);
461 printf("\n%24s %12.5e %12s %12s\n", "time:",
462 fr->t, "step:", gmx_step_str(fr->step, buf));
463 printf("%24s %12s %12s %12s\n",
464 "", "", "nsteps:", gmx_step_str(fr->nsteps, buf));
465 printf("%24s %12.5e %12s %12s\n",
466 "delta_t:", fr->dt, "sum steps:", gmx_step_str(fr->nsum, buf));
469 printf("%24s %12s %12s %12s\n",
470 "Component", "Energy", "Av. Energy", "Sum Energy");
473 for (i = 0; (i < nre); i++)
475 printf("%24s %12.5e %12.5e %12.5e\n",
476 enm[i].name, fr->ener[i].e, fr->ener[i].eav,
482 for (i = 0; (i < nre); i++)
484 printf("%24s %12.5e\n",
485 enm[i].name, fr->ener[i].e);
489 for (b = 0; b < fr->nblock; b++)
491 const char *typestr = "";
493 t_enxblock *eb = &(fr->block[b]);
494 printf("Block data %2d (%3d subblocks, id=%d)\n",
495 b, eb->nsub, eb->id);
499 typestr = enx_block_id_name[eb->id];
501 printf(" id='%s'\n", typestr);
502 for (i = 0; i < eb->nsub; i++)
504 t_enxsubblock *sb = &(eb->sub[i]);
505 printf(" Sub block %3d (%5d elems, type=%s) values:\n",
506 i, sb->nr, xdr_datatype_names[sb->type]);
510 case xdr_datatype_float:
511 for (j = 0; j < sb->nr; j++)
513 printf("%14d %8.4f\n", j, sb->fval[j]);
516 case xdr_datatype_double:
517 for (j = 0; j < sb->nr; j++)
519 printf("%14d %10.6f\n", j, sb->dval[j]);
522 case xdr_datatype_int:
523 for (j = 0; j < sb->nr; j++)
525 printf("%14d %10d\n", j, sb->ival[j]);
528 case xdr_datatype_int64:
529 for (j = 0; j < sb->nr; j++)
532 j, gmx_step_str(sb->lval[j], buf));
535 case xdr_datatype_char:
536 for (j = 0; j < sb->nr; j++)
538 printf("%14d %1c\n", j, sb->cval[j]);
541 case xdr_datatype_string:
542 for (j = 0; j < sb->nr; j++)
544 printf("%14d %80s\n", j, sb->sval[j]);
548 gmx_incons("Unknown subblock type");
563 static void list_mtx(const char *fn)
565 int nrow, ncol, i, j, k;
566 real *full = NULL, value;
567 gmx_sparsematrix_t * sparse = NULL;
569 gmx_mtxio_read(fn, &nrow, &ncol, &full, &sparse);
573 snew(full, nrow*ncol);
574 for (i = 0; i < nrow*ncol; i++)
579 for (i = 0; i < sparse->nrow; i++)
581 for (j = 0; j < sparse->ndata[i]; j++)
583 k = sparse->data[i][j].col;
584 value = sparse->data[i][j].value;
585 full[i*ncol+k] = value;
586 full[k*ncol+i] = value;
589 gmx_sparsematrix_destroy(sparse);
592 printf("%d %d\n", nrow, ncol);
593 for (i = 0; i < nrow; i++)
595 for (j = 0; j < ncol; j++)
597 printf(" %g", full[i*ncol+j]);
605 int gmx_dump(int argc, char *argv[])
607 const char *desc[] = {
608 "[THISMODULE] reads a run input file ([TT].tpa[tt]/[TT].tpr[tt]/[TT].tpb[tt]),",
609 "a trajectory ([TT].trj[tt]/[TT].trr[tt]/[TT].xtc[tt]), an energy",
610 "file ([TT].ene[tt]/[TT].edr[tt]), or a checkpoint file ([TT].cpt[tt])",
611 "and prints that to standard output in a readable format.",
612 "This program is essential for checking your run input file in case of",
614 "The program can also preprocess a topology to help finding problems.",
615 "Note that currently setting [TT]GMXLIB[tt] is the only way to customize",
616 "directories used for searching include files.",
618 const char *bugs[] = {
619 "Position restraint output from -sys -s is broken"
622 { efTPX, "-s", NULL, ffOPTRD },
623 { efTRX, "-f", NULL, ffOPTRD },
624 { efEDR, "-e", NULL, ffOPTRD },
625 { efCPT, NULL, NULL, ffOPTRD },
626 { efTOP, "-p", NULL, ffOPTRD },
627 { efMTX, "-mtx", "hessian", ffOPTRD },
628 { efMDP, "-om", NULL, ffOPTWR }
630 #define NFILE asize(fnm)
633 /* Command line options */
634 static gmx_bool bShowNumbers = TRUE;
635 static gmx_bool bSysTop = FALSE;
637 { "-nr", FALSE, etBOOL, {&bShowNumbers}, "Show index numbers in output (leaving them out makes comparison easier, but creates a useless topology)" },
638 { "-sys", FALSE, etBOOL, {&bSysTop}, "List the atoms and bonded interactions for the whole system instead of for each molecule type" }
641 if (!parse_common_args(&argc, argv, 0, NFILE, fnm, asize(pa), pa,
642 asize(desc), desc, asize(bugs), bugs, &oenv))
648 if (ftp2bSet(efTPX, NFILE, fnm))
650 list_tpx(ftp2fn(efTPX, NFILE, fnm), bShowNumbers,
651 ftp2fn_null(efMDP, NFILE, fnm), bSysTop);
653 else if (ftp2bSet(efTRX, NFILE, fnm))
655 list_trx(ftp2fn(efTRX, NFILE, fnm));
657 else if (ftp2bSet(efEDR, NFILE, fnm))
659 list_ene(ftp2fn(efEDR, NFILE, fnm));
661 else if (ftp2bSet(efCPT, NFILE, fnm))
663 list_checkpoint(ftp2fn(efCPT, NFILE, fnm), stdout);
665 else if (ftp2bSet(efTOP, NFILE, fnm))
667 list_top(ftp2fn(efTOP, NFILE, fnm));
669 else if (ftp2bSet(efMTX, NFILE, fnm))
671 list_mtx(ftp2fn(efMTX, NFILE, fnm));