Add DSSP v4 support to do_dssp
[alexxy/gromacs.git] / src / gromacs / gmxana / gmx_do_dssp.cpp
index 36fb601e93df2e5dde55686f2c0ae6abf661f9f4..f88a65c567f218f42a82d439a0f6dcd9c994bcc9 100644 (file)
@@ -485,15 +485,15 @@ int gmx_do_dssp(int argc, char* argv[])
         "that the dssp executable is located in ",
         // NOLINTNEXTLINE(bugprone-suspicious-missing-comma)
         "[TT]" GMX_DSSP_PROGRAM_PATH "[tt]. If this is not the case, then you should",
-        "set an environment variable [TT]DSSP[tt] pointing to the dssp",
+        "set an environment variable [TT]DSSP[tt] pointing to the dssp ",
         "executable, e.g.: [PAR]",
         "[TT]setenv DSSP /opt/dssp/bin/dssp[tt][PAR]",
-        "Since version 2.0.0, dssp is invoked with a syntax that differs",
-        "from earlier versions. If you have an older version of dssp,",
-        "use the [TT]-ver[tt] option to direct do_dssp to use the older syntax.",
+        "The dssp program is invoked with a syntax that differs",
+        "depending on version. Version 1, 2 and 4 are supported, and the correct",
+        "invocation format can be selected using the [TT]-ver[tt] option.",
         "By default, do_dssp uses the syntax introduced with version 2.0.0.",
-        "Even newer versions (which at the time of writing are not yet released)",
-        "are assumed to have the same syntax as 2.0.0.[PAR]",
+        "Newer versions might also have executable name [TT]mkdssp[tt] instead",
+        "of [TT]dssp[tt].[PAR]",
         "The structure assignment for each residue and time is written to an",
         "[REF].xpm[ref] matrix file. This file can be visualized with for instance",
         "[TT]xv[tt] and can be converted to postscript with [TT]xpm2ps[tt].",
@@ -523,7 +523,7 @@ int gmx_do_dssp(int argc, char* argv[])
           FALSE,
           etINT,
           { &dsspVersion },
-          "DSSP major version. Syntax changed with version 2" }
+          "DSSP major version. Syntax changed with version 2 and 4." }
     };
 
     t_trxstatus*      status;
@@ -643,14 +643,30 @@ int gmx_do_dssp(int argc, char* argv[])
     dsspStrings.tmpfile = tmpfile;
     if (dsspVersion >= 2)
     {
-        if (dsspVersion > 2)
+        if (dsspVersion == 4)
+        {
+            std::string mkdsspCommandLine = dsspStrings.dptr;
+            mkdsspCommandLine += " --output-format dssp ";
+            mkdsspCommandLine += dsspStrings.pdbfile;
+
+#if not HAVE_PIPES && not GMX_NATIVE_WINDOWS
+            // Without pipe/popen, rely on temporary file for output
+            mkdsspCommandLine += " " + dsspStrings.tmpfile;
+#endif
+
+            GMX_RELEASE_ASSERT(mkdsspCommandLine.size() < 255, "DSSP v4 command line too long");
+            strcpy(dssp, mkdsspCommandLine.c_str());
+        }
+        else if (dsspVersion == 2)
+        {
+            printDsspResult(dssp, dsspStrings, redirectionString);
+        }
+        else
         {
             printf("\nWARNING: You use DSSP version %d, which is not explicitly\nsupported by "
                    "do_dssp. Assuming version 2 syntax.\n\n",
                    dsspVersion);
         }
-
-        printDsspResult(dssp, dsspStrings, redirectionString);
     }
     else
     {
@@ -713,7 +729,8 @@ int gmx_do_dssp(int argc, char* argv[])
         }
         gmx_rmpbc(gpbc, natoms, box, x);
         tapein = gmx_ffopen(pdbfile, "w");
-        write_pdbfile_indexed(tapein, nullptr, atoms, x, pbcType, box, ' ', -1, gnx, index, nullptr, FALSE);
+        write_pdbfile_indexed(
+                tapein, nullptr, atoms, x, pbcType, box, 'A', -1, gnx, index, nullptr, FALSE, true);
         gmx_ffclose(tapein);
         /* strip_dssp returns the number of lines found in the dssp file, i.e.
          * the number of residues plus the separator lines */