From b7bb8083ed6fa53c66b595f62d4ac26403fbf5fd Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 6 Aug 2024 17:14:46 -0400 Subject: [PATCH] implement -restart2info command line flag and document it --- doc/lammps.1 | 14 ++++++++++++++ doc/src/Run_options.rst | 31 +++++++++++++++++++++++++++++++ doc/src/read_restart.rst | 6 ++++++ src/info.cpp | 2 +- src/lammps.cpp | 31 ++++++++++++++++++++++++++++--- 5 files changed, 80 insertions(+), 4 deletions(-) diff --git a/doc/lammps.1 b/doc/lammps.1 index a66083ed07..eef23dd52f 100644 --- a/doc/lammps.1 +++ b/doc/lammps.1 @@ -226,6 +226,20 @@ arguments of the "dump" command. See the .B LAMMPS manual for details on either of the two commands. .TP +\fB\-r2info ...\fR or +\fB\-restart2info ...\fR +Write infomation about the previously written by +.B LAMMPS +to the screen and immediately exit. Following +argument, additional keywords for the +.B LAMMPS +"info" command may be added to increase the amount of information +written. By default "system" "group" "fix" "compute" are already +set. See the +.B LAMMPS +manual for details on either of the two commands. +.TP +.TP \fB\-sc \fR or \fB\-screen \fR Specify a file for .B LAMMPS diff --git a/doc/src/Run_options.rst b/doc/src/Run_options.rst index 79c363d009..fba030e3b1 100644 --- a/doc/src/Run_options.rst +++ b/doc/src/Run_options.rst @@ -22,6 +22,7 @@ letter abbreviation can be used: * :ref:`-ro or -reorder ` * :ref:`-r2data or -restart2data ` * :ref:`-r2dump or -restart2dump ` +* :ref:`-r2info or -restart2info ` * :ref:`-sc or -screen ` * :ref:`-sr or skiprun ` * :ref:`-sf or -suffix ` @@ -503,6 +504,36 @@ e.g. the *nfile* and *fileper* keywords. See the ---------- +.. _restart2info: + +**-restart2info restartfile keyword ...** + +.. versionadded:: TBD + +Write out some info about the restart file and and immediately exit. This +is the same operation as if the following 2-line input script were +run: + +.. code-block:: LAMMPS + + read_restart restartfile + info system group compute fix keyword ... + +The specified restartfile name may contain the wild-card character "\*". +The restartfile name may also contain the wild-card character "%". The +meaning of these characters is explained on the :doc:`read_restart +` documentation. The use of "%" means that a parallel +restart file can be read. Note that a filename such as file.\* may need +to be enclosed in quotes or the "\*" character prefixed with a backslash +("\") to avoid shell expansion of the "\*" character. + +The :doc:`info command ` is already followed by the most useful +keywords, but additional keywords like *coeffs* or *comm* may be +appended to write out more details about the information stored in the +restart file. + +---------- + .. _screen: **-screen file** diff --git a/doc/src/read_restart.rst b/doc/src/read_restart.rst index 42f18022cb..6a875550a4 100644 --- a/doc/src/read_restart.rst +++ b/doc/src/read_restart.rst @@ -47,6 +47,12 @@ Restart files are saved in binary format to enable exact restarts, meaning that the trajectories of a restarted run will precisely match those produced by the original run had it continued on. +Some information about a restart file can be gathered directly from the +command line when using LAMMPS with the :ref:`-restart2info +` command line flag. On Unix-like operating systems (like +Linux or macOS), one can also :ref:`configure the "file" command line +program ` to display basic information about a restart file + The binary restart file format was not designed with backward, forward, or cross-platform compatibility in mind, so the files are only expected to be read correctly by the same LAMMPS executable on the same platform. diff --git a/src/info.cpp b/src/info.cpp index a5da285efc..0959d53e64 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -261,7 +261,7 @@ void Info::command(int narg, char **arg) ++idx; } } else { - error->warning(FLERR,"Ignoring unknown or incorrect info command flag"); + error->warning(FLERR,"Ignoring unknown or incorrect info command flag: {}",arg[idx]); ++idx; } } diff --git a/src/lammps.cpp b/src/lammps.cpp index fee24e785b..52b328ff48 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -210,6 +210,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : int kokkosflag = 0; int restart2data = 0; int restart2dump = 0; + int restart2info = 0; int restartremap = 0; int citeflag = 1; int citescreen = CiteMe::TERSE; @@ -383,6 +384,8 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : error->universe_all(FLERR,"Invalid command-line argument"); if (restart2dump) error->universe_all(FLERR, "Cannot use both -restart2data and -restart2dump"); + if (restart2info) + error->universe_all(FLERR, "Cannot use both -restart2data and -restart2info"); restart2data = 1; restartfile = arg[iarg+1]; inflag = -1; // skip inflag check @@ -405,6 +408,8 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : error->universe_all(FLERR,"Invalid command-line argument"); if (restart2data) error->universe_all(FLERR, "Cannot use both -restart2data and -restart2dump"); + if (restart2info) + error->universe_all(FLERR, "Cannot use both -restart2dump and -restart2info"); restart2dump = 1; restartfile = arg[iarg+1]; inflag = -1; // skip inflag check @@ -421,6 +426,23 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : while (iarg < narg && arg[iarg][0] != '-') iarg++; wlast = iarg; + } else if (strcmp(arg[iarg],"-restart2info") == 0 || + strcmp(arg[iarg],"-r2info") == 0) { + if (iarg+2 > narg) + error->universe_all(FLERR,"Invalid command-line argument"); + if (restart2data) + error->universe_all(FLERR, "Cannot use both -restart2data and -restart2info"); + if (restart2dump) + error->universe_all(FLERR, "Cannot use both -restart2dump and -restart2info"); + restart2info = 1; + restartfile = arg[iarg+1]; + inflag = -1; // skip inflag check + iarg += 2; + // delimit args for the write_data command + wfirst = iarg; + while (iarg < narg && arg[iarg][0] != '-') iarg++; + wlast = iarg; + } else if (strcmp(arg[iarg],"-screen") == 0 || strcmp(arg[iarg],"-sc") == 0) { if (iarg+2 > narg) @@ -727,15 +749,17 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : // add args between wfirst and wlast to write_data or write_data command // add "noinit" to write_data to prevent a system init - if (restart2data || restart2dump) { + if (restart2data || restart2dump || restart2info) { std::string cmd = fmt::format("read_restart {}",restartfile); if (restartremap) cmd += " remap\n"; input->one(cmd); if (restart2data) cmd = "write_data "; - else cmd = "write_dump"; + else if (restart2dump) cmd = "write_dump"; + else cmd = "info system group compute fix"; for (iarg = wfirst; iarg < wlast; iarg++) cmd += fmt::format(" {}", arg[iarg]); - cmd += " noinit"; + if (restart2data || restart2dump) + cmd += " noinit"; input->one(cmd); error->done(0); } @@ -1260,6 +1284,7 @@ void _noopt LAMMPS::help() "-restart2data rfile dfile ... : convert restart to data file (-r2data)\n" "-restart2dump rfile dgroup dstyle dfile ... \n" " : convert restart to dump file (-r2dump)\n" + "-restart2info rfile : print info about restart rfile (-r2info)\n" "-reorder topology-specs : processor reordering (-r)\n" "-screen none/filename : where to send screen output (-sc)\n" "-skiprun : skip loops in run and minimize (-sr)\n"