Xpm test for gmx clustsize
authorDavid van der Spoel <spoel@xray.bmc.uu.se>
Fri, 24 Mar 2017 15:29:44 +0000 (16:29 +0100)
committerRoland Schulz <roland.schulz@intel.com>
Mon, 1 May 2017 18:38:32 +0000 (20:38 +0200)
Made computation of RGB colors for matrix double precision.

Removed printing of binary information in xpm files
since it makes the header not reproducible. This is
not very useful anyway and the alternative to write
an XPM matcher would be overkill.

Change-Id: I4b12da5aaae246e4a146496b6973d5d6880fbf91

src/gromacs/fileio/matio.cpp
src/gromacs/trajectoryanalysis/tests/clustsize.cpp
src/gromacs/trajectoryanalysis/tests/refdata/ClustsizeTest_MolCSize.xml [new file with mode: 0644]

index 56eb00cc522879eee986ac82baf408da50cafc14..8bf6934e41624fb113aeb7540d747d107246e7d0 100644 (file)
@@ -634,16 +634,6 @@ static void write_xpm_header(FILE *out,
                              gmx_bool bDiscrete)
 {
     fprintf(out,  "/* XPM */\n");
-    try
-    {
-        gmx::BinaryInformationSettings settings;
-        settings.generatedByHeader(true);
-        settings.linePrefix("/* ");
-        settings.lineSuffix(" */");
-        gmx::printBinaryInformation(out, gmx::getProgramContext(),
-                                    settings);
-    }
-    GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
     fprintf(out,  "/* This file can be converted to EPS by the GROMACS program xpm2ps */\n");
     fprintf(out,  "/* title:   \"%s\" */\n", title);
     fprintf(out,  "/* legend:  \"%s\" */\n", legend);
@@ -672,7 +662,7 @@ static void write_xpm_map3(FILE *out, int n_x, int n_y, int *nlevels,
                            t_rgb rlo, t_rgb rmid, t_rgb rhi)
 {
     int    i, nmid;
-    real   r, g, b, clev_lo, clev_hi;
+    double r, g, b, clev_lo, clev_hi;
 
     if (*nlevels > NMAP*NMAP)
     {
@@ -706,9 +696,9 @@ static void write_xpm_map3(FILE *out, int n_x, int n_y, int *nlevels,
         fprintf(out, "\"%c%c c #%02X%02X%02X \" /* \"%.3g\" */,\n",
                 mapper[i % NMAP],
                 (*nlevels <= NMAP) ? ' ' : mapper[i/NMAP],
-                static_cast<unsigned int>(round(255*r)),
-                static_cast<unsigned int>(round(255*g)),
-                static_cast<unsigned int>(round(255*b)),
+                static_cast<unsigned int>(std::round(255*r)),
+                static_cast<unsigned int>(std::round(255*g)),
+                static_cast<unsigned int>(std::round(255*b)),
                 ((nmid - i)*lo + i*mid)/clev_lo);
     }
     for (i = 0; (i < (*nlevels-nmid)); i++)
@@ -719,9 +709,9 @@ static void write_xpm_map3(FILE *out, int n_x, int n_y, int *nlevels,
         fprintf(out, "\"%c%c c #%02X%02X%02X \" /* \"%.3g\" */,\n",
                 mapper[(i+nmid) % NMAP],
                 (*nlevels <= NMAP) ? ' ' : mapper[(i+nmid)/NMAP],
-                static_cast<unsigned int>(round(255*r)),
-                static_cast<unsigned int>(round(255*g)),
-                static_cast<unsigned int>(round(255*b)),
+                static_cast<unsigned int>(std::round(255*r)),
+                static_cast<unsigned int>(std::round(255*g)),
+                static_cast<unsigned int>(std::round(255*b)),
                 ((*nlevels - 1 - nmid - i)*mid + i*hi)/clev_hi);
     }
 }
index 471d32887cdf02e2841d3b7e68a8c780f053ec36..72ed81be660abf6e9d10d80080d7905fb5bef479 100644 (file)
 #include <string>
 
 #include "gromacs/gmxana/gmx_ana.h"
-#include "gromacs/utility/filestream.h"
-#include "gromacs/utility/path.h"
 
 #include "testutils/cmdlinetest.h"
 #include "testutils/refdata.h"
 #include "testutils/testasserts.h"
+#include "testutils/textblockmatchers.h"
 #include "testutils/xvgtest.h"
 
 namespace gmx
@@ -72,44 +71,25 @@ class ClustsizeTest : public CommandLineTestBase
     public:
         ClustsizeTest()
         {
-            setInputFile("-f", "clustsize.pdb");
-        }
-
-        void runTest(bool        mol,
-                     bool        cutoff)
-        {
-            const char *const command[] = { "clustsize" };
-            CommandLine       args      = CommandLine(command);
             double            tolerance = 1e-4;
             test::XvgMatch    xvg;
+            test::XvgMatch   &toler     = xvg.tolerance(gmx::test::relativeToleranceAsFloatingPoint(1, tolerance));
 
-            setOutputFile("-mc", ".xvg",
-                          xvg.tolerance(gmx::test::relativeToleranceAsFloatingPoint(1, tolerance)));
-            setOutputFile("-nc", ".xvg",
-                          xvg.tolerance(gmx::test::relativeToleranceAsFloatingPoint(1, tolerance)));
-            setOutputFile("-ac", ".xvg",
-                          xvg.tolerance(gmx::test::relativeToleranceAsFloatingPoint(1, tolerance)));
-            setOutputFile("-hc", ".xvg",
-                          xvg.tolerance(gmx::test::relativeToleranceAsFloatingPoint(1, tolerance)));
-
-            if (mol)
-            {
-                setInputFile("-s", "clustsize.tpr");
-                args.addOption("-mol");
-            }
-            else
-            {
-                setInputFile("-n", "clustsize.ndx");
-            }
-            if (cutoff)
-            {
-                args.addOption("-cut", "0.3");
-            }
-            rootChecker().checkString(args.toString(), "CommandLine");
+            setOutputFile("-mc", ".xvg", toler);
+            setOutputFile("-nc", ".xvg", toler);
+            setOutputFile("-ac", ".xvg", toler);
+            setOutputFile("-hc", ".xvg", toler);
+            setInputFile("-f", "clustsize.pdb");
+        }
 
+        void runTest(const CommandLine &args)
+        {
             CommandLine &cmdline = commandLine();
             cmdline.merge(args);
 
+            gmx::test::TestReferenceChecker rootChecker(this->rootChecker());
+            rootChecker.checkString(args.toString(), "CommandLine");
+
             ASSERT_EQ(0, gmx_clustsize(cmdline.argc(), cmdline.argv()));
 
             checkOutputFiles();
@@ -118,22 +98,55 @@ class ClustsizeTest : public CommandLineTestBase
 
 TEST_F(ClustsizeTest, NoMolDefaultCutoff)
 {
-    runTest(false, false);
+    const char *const command[] = { "clustsize" };
+    CommandLine       args      = CommandLine(command);
+
+    setInputFile("-n", "clustsize.ndx");
+
+    runTest(args);
 }
 
 TEST_F(ClustsizeTest, NoMolShortCutoff)
 {
-    runTest(false, true);
+    const char *const command[] = { "clustsize", "-cut", "0.3" };
+    CommandLine       args      = CommandLine(command);
+
+    setInputFile("-n", "clustsize.ndx");
+
+    runTest(args);
 }
 
 TEST_F(ClustsizeTest, MolDefaultCutoff)
 {
-    runTest(true, false);
+    const char *const command[] = { "clustsize", "-mol" };
+    CommandLine       args      = CommandLine(command);
+
+    setInputFile("-s", "clustsize.tpr");
+
+    runTest(args);
 }
 
 TEST_F(ClustsizeTest, MolShortCutoff)
 {
-    runTest(true, true);
+    const char *const command[] = { "clustsize", "-mol", "-cut", "0.3" };
+    CommandLine       args      = CommandLine(command);
+
+    setInputFile("-s", "clustsize.tpr");
+
+    runTest(args);
+}
+
+TEST_F(ClustsizeTest, MolCSize)
+{
+    const char *const command[] = { "clustsize", "-mol", "-nlevels", "6" };
+    CommandLine       args      = CommandLine(command);
+
+    setOutputFile("-o", ".xpm", ExactTextMatch());
+    setOutputFile("-ow", ".xpm", ExactTextMatch());
+
+    setInputFile("-s", "clustsize.tpr");
+
+    runTest(args);
 }
 
 } // namespace
diff --git a/src/gromacs/trajectoryanalysis/tests/refdata/ClustsizeTest_MolCSize.xml b/src/gromacs/trajectoryanalysis/tests/refdata/ClustsizeTest_MolCSize.xml
new file mode 100644 (file)
index 0000000..aed915f
--- /dev/null
@@ -0,0 +1,151 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+  <String Name="CommandLine">clustsize -mol -nlevels 6</String>
+  <OutputFiles Name="Files">
+    <File Name="-o">
+      <String Name="Contents"><![CDATA[
+/* XPM */
+/* This file can be converted to EPS by the GROMACS program xpm2ps */
+/* title:   "Cluster size distribution" */
+/* legend:  "# clusters" */
+/* x-label: "Time (ps)" */
+/* y-label: "Size" */
+/* type:    "Continuous" */
+static char *gromacs_xpm[] = {
+"2 2   6 1",
+"A  c #FFFF00 " /* "1" */,
+"B  c #CCCC33 " /* "2" */,
+"C  c #999966 " /* "3" */,
+"D  c #666699 " /* "4" */,
+"E  c #3333CC " /* "5" */,
+"F  c #0000FF " /* "6" */,
+/* x-axis:  1 2 */
+/* y-axis:  1 2 */
+"AA",
+"FF"
+]]></String>
+    </File>
+    <File Name="-ow">
+      <String Name="Contents"><![CDATA[
+/* XPM */
+/* This file can be converted to EPS by the GROMACS program xpm2ps */
+/* title:   "Weighted cluster size distribution" */
+/* legend:  "Fraction" */
+/* x-label: "Time (ps)" */
+/* y-label: "Size" */
+/* type:    "Continuous" */
+static char *gromacs_xpm[] = {
+"2 2   6 1",
+"A  c #FFFFFF " /* "0" */,
+"B  c #FFFF00 " /* "2" */,
+"C  c #BFBF40 " /* "3" */,
+"D  c #808080 " /* "4" */,
+"E  c #4040BF " /* "5" */,
+"F  c #0000FF " /* "6" */,
+/* x-axis:  1 2 */
+/* y-axis:  1 2 */
+"BB",
+"FF"
+]]></String>
+    </File>
+    <File Name="-mc">
+      <XvgLegend Name="Legend">
+        <String Name="XvgLegend"><![CDATA[
+title "Max cluster size"
+xaxis  label "Time (ps)"
+yaxis  label "#molecules"
+TYPE xy
+]]></String>
+      </XvgLegend>
+      <XvgData Name="Data">
+        <Sequence Name="Row0">
+          <Int Name="Length">2</Int>
+          <Real>1.000000e+00</Real>
+          <Real>2</Real>
+        </Sequence>
+        <Sequence Name="Row1">
+          <Int Name="Length">2</Int>
+          <Real>2.000000e+00</Real>
+          <Real>2</Real>
+        </Sequence>
+      </XvgData>
+    </File>
+    <File Name="-nc">
+      <XvgLegend Name="Legend">
+        <String Name="XvgLegend"><![CDATA[
+title "Number of clusters"
+xaxis  label "Time (ps)"
+yaxis  label "N"
+TYPE xy
+]]></String>
+      </XvgLegend>
+      <XvgData Name="Data">
+        <Sequence Name="Row0">
+          <Int Name="Length">2</Int>
+          <Real>1.000000e+00</Real>
+          <Real>7</Real>
+        </Sequence>
+        <Sequence Name="Row1">
+          <Int Name="Length">2</Int>
+          <Real>2.000000e+00</Real>
+          <Real>7</Real>
+        </Sequence>
+      </XvgData>
+    </File>
+    <File Name="-ac">
+      <XvgLegend Name="Legend">
+        <String Name="XvgLegend"><![CDATA[
+title "Average cluster size"
+xaxis  label "Time (ps)"
+yaxis  label "#molecules"
+TYPE xy
+]]></String>
+      </XvgLegend>
+      <XvgData Name="Data">
+        <Sequence Name="Row0">
+          <Int Name="Length">2</Int>
+          <Real>1.000000e+00</Real>
+          <Real>2.000</Real>
+        </Sequence>
+        <Sequence Name="Row1">
+          <Int Name="Length">2</Int>
+          <Real>2.000000e+00</Real>
+          <Real>2.000</Real>
+        </Sequence>
+      </XvgData>
+    </File>
+    <File Name="-hc">
+      <XvgLegend Name="Legend">
+        <String Name="XvgLegend"><![CDATA[
+title "Cluster size distribution"
+xaxis  label "Cluster size"
+yaxis  label "()"
+TYPE xy
+]]></String>
+      </XvgLegend>
+      <XvgData Name="Data">
+        <Sequence Name="Row0">
+          <Int Name="Length">2</Int>
+          <Real>0</Real>
+          <Real>0.000</Real>
+        </Sequence>
+        <Sequence Name="Row1">
+          <Int Name="Length">2</Int>
+          <Real>1</Real>
+          <Real>6.000</Real>
+        </Sequence>
+        <Sequence Name="Row2">
+          <Int Name="Length">2</Int>
+          <Real>2</Real>
+          <Real>1.000</Real>
+        </Sequence>
+        <Sequence Name="Row3">
+          <Int Name="Length">2</Int>
+          <Real>3</Real>
+          <Real>0.000</Real>
+        </Sequence>
+      </XvgData>
+    </File>
+  </OutputFiles>
+</ReferenceData>