Suggest a workaround for pulling with -deffnm
authorMark Abraham <mark.j.abraham@gmail.com>
Wed, 20 Jan 2021 10:56:38 +0000 (11:56 +0100)
committerArtem Zhmurov <zhmurov@gmail.com>
Thu, 21 Jan 2021 04:22:22 +0000 (04:22 +0000)
Also fixed use of settings, use settings to do the line wrapping,
and wrote some newlines to make the output more readable.

Refs #3875
Fixes #3442

src/gromacs/mdrunutility/handlerestart.cpp

index b21f11302978c1c0019ac4a10592e7fe21c9e2d8..6c6804f1bbf9181d02ae91b2d46c68aa10a34b65 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2015,2016,2017,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017,2018,2019,2020,2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -120,15 +120,16 @@ gmx_bool exist_output_file(const char* fnm_cp, int nfile, const t_filenm fnm[])
 {
     StringOutputStream stream;
     TextWriter         writer(&stream);
-    writer.writeStringFormatted(
+    writer.writeLineFormatted(
             "Some output files listed in the checkpoint file %s are not present or not named "
             "as the output files by the current program:)",
             checkpointFilename);
-    auto settings  = writer.wrapperSettings();
-    auto oldIndent = settings.indent(), newIndent = 2;
+    auto& settings  = writer.wrapperSettings();
+    auto  oldIndent = settings.indent(), newIndent = 2;
 
     writer.writeLine("Expected output files that are present:");
     settings.setIndent(newIndent);
+    settings.setLineLength(78);
     for (const auto& outputfile : outputfiles)
     {
         if (exist_output_file(outputfile.filename, nfile, fnm))
@@ -139,6 +140,15 @@ gmx_bool exist_output_file(const char* fnm_cp, int nfile, const t_filenm fnm[])
     settings.setIndent(oldIndent);
     writer.ensureEmptyLine();
 
+    // The implementation of -deffnm does not handle properly the
+    // naming of output files that share a common suffix, such as
+    // pullx.xvg and pullf.xvg from the pull module. Such output files
+    // will be sought by the wrong name by the code that handles the
+    // restart, even though the pull module would later work out what
+    // they should have been called. Since there is a straightforward
+    // way to work around that, we help the user with that. This can
+    // be removed when gitlab issue #3875 is resolved.
+    bool missingFilesIncludedPullOutputFiles = false;
     writer.writeLine("Expected output files that are not present or named differently:");
     settings.setIndent(newIndent);
     for (const auto& outputfile : outputfiles)
@@ -146,16 +156,38 @@ gmx_bool exist_output_file(const char* fnm_cp, int nfile, const t_filenm fnm[])
         if (!exist_output_file(outputfile.filename, nfile, fnm))
         {
             writer.writeLine(outputfile.filename);
+            // If this was a pull file, then we have a known issue and
+            // work-around (See gitlab issue #3442).
+            if (!missingFilesIncludedPullOutputFiles
+                && (contains(outputfile.filename, "pullx")
+                    || contains(outputfile.filename, "pullf")))
+            {
+                missingFilesIncludedPullOutputFiles = true;
+            }
         }
     }
+    if (missingFilesIncludedPullOutputFiles)
+    {
+        writer.ensureEmptyLine();
+        writer.writeLineFormatted(
+                "It appears that pull output files were not found. It is known that "
+                "using gmx mdrun -deffnm test with pulling and later "
+                "gmx mdrun -deffnm test -cpi will fail to consider the changed default "
+                "filename when checking the pull output files for restarting with "
+                "appending. You may be able to work around this by using a command like "
+                "gmx mdrun -deffnm test -px test_pullx -pf test_pullf -cpi.");
+    }
     settings.setIndent(oldIndent);
 
+    writer.ensureEmptyLine();
     writer.writeLineFormatted(
-            R"(To keep your simulation files safe, this simulation will not restart. Either name your
-output files exactly the same as the previous simulation part (e.g. with -deffnm), or
-make sure all the output files are present (e.g. run from the same directory as the
-previous simulation part), or instruct mdrun to write new output files with mdrun -noappend.
-In the last case, you will not be able to use appending in future for this simulation.)",
+            "To keep your simulation files safe, this simulation will not restart. "
+            "Either name your output files exactly the same as the previous simulation "
+            "part (e.g. with -deffnm or explicit naming), or make sure all the output "
+            "files are present (e.g. run from the same directory as the previous simulation "
+            "part), or instruct mdrun to write new output files with mdrun -noappend. In "
+            "the last case, you will not be able to use appending in future for this "
+            "simulation.",
             numFilesMissing, outputfiles.size());
     GMX_THROW(InconsistentInputError(stream.toString()));
 }