Merge branch release-2021
[alexxy/gromacs.git] / src / gromacs / mdrunutility / handlerestart.cpp
index 05b6a4f3bede7a2412e35313c645d4c333769dc0..68db1fbfd7316e0b435bcc0c19ad503c82f6ef39 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()));