Added new testing code for normal mode analysis.
authorDavid van der Spoel <spoel@xray.bmc.uu.se>
Fri, 23 Nov 2018 21:05:22 +0000 (22:05 +0100)
committerDavid van der Spoel <spoel@xray.bmc.uu.se>
Wed, 5 Dec 2018 14:58:16 +0000 (15:58 +0100)
Part of #2771

Change-Id: Ifb44841b36be5076fe8d77d5982876f881fdc69b

src/programs/mdrun/tests/CMakeLists.txt
src/programs/mdrun/tests/moduletest.cpp
src/programs/mdrun/tests/moduletest.h
src/programs/mdrun/tests/normalmodes.cpp [new file with mode: 0644]
src/programs/mdrun/tests/refdata/NormalModesWorks_NormalModesTest_WithinTolerances_0.xml [new file with mode: 0644]
src/programs/mdrun/tests/simulationdatabase.cpp
src/testutils/simulationdatabase/scaled-water.g96 [new file with mode: 0644]
src/testutils/simulationdatabase/scaled-water.ndx [new file with mode: 0644]
src/testutils/simulationdatabase/scaled-water.top [new file with mode: 0644]

index 37b0c0e4620577e0e64625236635011fb27ec3d3..e56de915683660fe3e705902073c2e06c1e1f131 100644 (file)
@@ -77,6 +77,7 @@ gmx_add_gtest_executable(
     ${exename}
     # files with code for tests
     minimize.cpp
+    normalmodes.cpp
     rerun.cpp
     # pseudo-library for code for testing mdrun
     $<TARGET_OBJECTS:mdrun_test_objlib>
index 5733d41d64f67780a468f289a74e50f044519b25..a3034dd19baccf5b73ab364cbf6092094c94165c 100644 (file)
@@ -47,6 +47,7 @@
 
 #include <cstdio>
 
+#include "gromacs/gmxana/gmx_ana.h"
 #include "gromacs/gmxpreprocess/grompp.h"
 #include "gromacs/hardware/detecthardware.h"
 #include "gromacs/options/basicoptions.h"
@@ -96,6 +97,7 @@ SimulationRunner::SimulationRunner(TestFileManager *fileManager) :
     tprFileName_(fileManager->getTemporaryFilePath(".tpr")),
     logFileName_(fileManager->getTemporaryFilePath(".log")),
     edrFileName_(fileManager->getTemporaryFilePath(".edr")),
+    mtxFileName_(fileManager->getTemporaryFilePath(".mtx")),
     nsteps_(-2),
     fileManager_(*fileManager)
 {
@@ -216,6 +218,28 @@ SimulationRunner::callGrompp()
     return callGrompp(CommandLine());
 }
 
+int
+SimulationRunner::callNmeig()
+{
+    /* Conforming to style guide by not passing a non-const reference
+       to this function. Passing a non-const reference might make it
+       easier to write code that incorrectly re-uses callerRef after
+       the call to this function. */
+
+    CommandLine caller;
+    caller.append("nmeig");
+    caller.addOption("-s", tprFileName_);
+    caller.addOption("-f", mtxFileName_);
+    // Ignore the overall translation and rotation in the
+    // first six eigenvectors.
+    caller.addOption("-first", "7");
+    // No need to check more than a number of output values.
+    caller.addOption("-last", "50");
+    caller.addOption("-xvg", "none");
+
+    return gmx_nmeig(caller.argc(), caller.argv());
+}
+
 int
 SimulationRunner::callMdrun(const CommandLine &callerRef)
 {
@@ -231,6 +255,7 @@ SimulationRunner::callMdrun(const CommandLine &callerRef)
 
     caller.addOption("-g", logFileName_);
     caller.addOption("-e", edrFileName_);
+    caller.addOption("-mtx", mtxFileName_);
     caller.addOption("-o", fullPrecisionTrajectoryFileName_);
     caller.addOption("-x", reducedPrecisionTrajectoryFileName_);
 
index e10be452669636880e4cdb8131ba347222bfa4c6..450decba483299a58d9271bcfe69c594869ecb6e 100644 (file)
@@ -112,6 +112,8 @@ class SimulationRunner
         int callGromppOnThisRank(const CommandLine &callerRef);
         //! Convenience wrapper for a default call to \c callGromppOnThisRank
         int callGromppOnThisRank();
+        //! Calls nmeig for testing
+        int callNmeig();
         //! Calls mdrun for testing with a customized command line
         int callMdrun(const CommandLine &callerRef);
         /*! \brief Convenience wrapper for calling mdrun for testing
@@ -139,6 +141,7 @@ class SimulationRunner
         std::string tprFileName_;
         std::string logFileName_;
         std::string edrFileName_;
+        std::string mtxFileName_;
         std::string cptFileName_;
         std::string swapFileName_;
         int         nsteps_;
diff --git a/src/programs/mdrun/tests/normalmodes.cpp b/src/programs/mdrun/tests/normalmodes.cpp
new file mode 100644 (file)
index 0000000..4535c62
--- /dev/null
@@ -0,0 +1,170 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2018, 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.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+
+/*! \internal \file
+ * \brief
+ * Tests for the normal modes functionality.
+ *
+ * \author David van der Spoel <david.vanderspoel@icm.uu.se>
+ * \ingroup module_mdrun_integration_tests
+ */
+#include "gmxpre.h"
+
+#include <map>
+#include <memory>
+#include <string>
+#include <tuple>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#include "gromacs/compat/make_unique.h"
+#include "gromacs/options/filenameoption.h"
+#include "gromacs/topology/idef.h"
+#include "gromacs/topology/ifunc.h"
+#include "gromacs/trajectory/energyframe.h"
+#include "gromacs/trajectory/trajectoryframe.h"
+#include "gromacs/utility/basenetwork.h"
+#include "gromacs/utility/filestream.h"
+#include "gromacs/utility/stringutil.h"
+
+#include "testutils/mpitest.h"
+#include "testutils/refdata.h"
+#include "testutils/testasserts.h"
+#include "testutils/xvgtest.h"
+
+#include "energycomparison.h"
+#include "energyreader.h"
+#include "moduletest.h"
+#include "simulationdatabase.h"
+
+namespace gmx
+{
+namespace test
+{
+namespace
+{
+
+//! Helper type
+using MdpField = MdpFieldValues::value_type;
+
+/*! \brief Test fixture base for normal mode analysis
+ *
+ * This test ensures mdrun can run a normal mode analys, reaching
+ * a reproducible eigenvalues following diagonalization.
+ *
+ * The choices for tolerance are arbitrary but sufficient. */
+class NormalModesTest : public MdrunTestFixture,
+                        public ::testing::WithParamInterface <
+                        std::tuple < std::string, std::string>>
+{
+};
+
+TEST_P(NormalModesTest, WithinTolerances)
+{
+    auto params         = GetParam();
+    auto simulationName = std::get<0>(params);
+    auto integrator     = std::get<1>(params);
+    SCOPED_TRACE(formatString("Comparing normal modes for '%s'",
+                              simulationName.c_str()));
+
+    // TODO At some point we should also test PME-only ranks.
+    int numRanksAvailable = getNumberOfTestMpiRanks();
+    if (!isNumberOfPpRanksSupported(simulationName, numRanksAvailable))
+    {
+        fprintf(stdout, "Test system '%s' cannot run with %d ranks.\n"
+                "The supported numbers are: %s\n",
+                simulationName.c_str(), numRanksAvailable,
+                reportNumbersOfPpRanksSupported(simulationName).c_str());
+        return;
+    }
+    auto mdpFieldValues = prepareMdpFieldValues(simulationName.c_str(),
+                                                integrator.c_str(),
+                                                "no", "no");
+    mdpFieldValues["nsteps"]      = "1";
+    mdpFieldValues["rcoulomb"]    = "5.6";
+    mdpFieldValues["rlist"]       = "5.6";
+    mdpFieldValues["rvdw"]        = "5.6";
+    mdpFieldValues["constraints"] = "none";
+    mdpFieldValues.insert(MdpField("coulombtype", "Cut-off"));
+    mdpFieldValues.insert(MdpField("vdwtype", "Cut-off"));
+
+    // prepare the .tpr file
+    {
+        CommandLine caller;
+        caller.append("grompp");
+        runner_.useTopG96AndNdxFromDatabase(simulationName);
+        runner_.useStringAsMdpFile(prepareMdpFileContents(mdpFieldValues));
+        EXPECT_EQ(0, runner_.callGrompp(caller));
+    }
+    // Do mdrun, preparing to check the normal modes later
+    {
+        CommandLine mdrunCaller;
+        mdrunCaller.append("mdrun");
+        ASSERT_EQ(0, runner_.callMdrun(mdrunCaller));
+    }
+    // Now run gmx nmeig and check the output
+    {
+        ASSERT_EQ(0, runner_.callNmeig());
+        TestReferenceData refData;
+        auto              checker  = refData.rootChecker()
+                .checkCompound("System", simulationName)
+                .checkCompound("Integrator", integrator);
+        auto          settings = XvgMatchSettings();
+        TextInputFile input("eigenval.xvg");
+        checkXvgFile(&input, &checker, settings);
+    }
+}
+
+//! Containers of systems and integrators to test.
+//! \{
+std::vector<std::string> systemsToTest_g     = { "scaled-water" };
+std::vector<std::string> integratorsToTest_g = { "nm" };
+
+//! \}
+
+// The time for OpenCL kernel compilation means these tests might time
+// out. If that proves to be a problem, these can be disabled for
+// OpenCL builds. However, once that compilation is cached for the
+// lifetime of the whole test binary process, these tests should run in
+// such configurations.
+#if GMX_DOUBLE
+INSTANTIATE_TEST_CASE_P(NormalModesWorks, NormalModesTest,
+                            ::testing::Combine(::testing::ValuesIn(systemsToTest_g),
+                                                   ::testing::ValuesIn(integratorsToTest_g)));
+#endif
+} // namespace
+} // namespace test
+} // namespace gmx
diff --git a/src/programs/mdrun/tests/refdata/NormalModesWorks_NormalModesTest_WithinTolerances_0.xml b/src/programs/mdrun/tests/refdata/NormalModesWorks_NormalModesTest_WithinTolerances_0.xml
new file mode 100644 (file)
index 0000000..11948dd
--- /dev/null
@@ -0,0 +1,74 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+  <System Name="scaled-water">
+    <Integrator Name="nm">
+      <XvgLegend Name="Legend">
+        <String Name="XvgLegend"><![CDATA[
+]]></String>
+      </XvgLegend>
+      <XvgData Name="Data">
+        <Sequence Name="Row0">
+          <Int Name="Length">2</Int>
+          <Real>7</Real>
+          <Real>0.068698</Real>
+        </Sequence>
+        <Sequence Name="Row1">
+          <Int Name="Length">2</Int>
+          <Real>8</Real>
+          <Real>0.311942</Real>
+        </Sequence>
+        <Sequence Name="Row2">
+          <Int Name="Length">2</Int>
+          <Real>9</Real>
+          <Real>0.318822</Real>
+        </Sequence>
+        <Sequence Name="Row3">
+          <Int Name="Length">2</Int>
+          <Real>10</Real>
+          <Real>0.916834</Real>
+        </Sequence>
+        <Sequence Name="Row4">
+          <Int Name="Length">2</Int>
+          <Real>11</Real>
+          <Real>3.24034</Real>
+        </Sequence>
+        <Sequence Name="Row5">
+          <Int Name="Length">2</Int>
+          <Real>12</Real>
+          <Real>13.6069</Real>
+        </Sequence>
+        <Sequence Name="Row6">
+          <Int Name="Length">2</Int>
+          <Real>13</Real>
+          <Real>14.2014</Real>
+        </Sequence>
+        <Sequence Name="Row7">
+          <Int Name="Length">2</Int>
+          <Real>14</Real>
+          <Real>39.3613</Real>
+        </Sequence>
+        <Sequence Name="Row8">
+          <Int Name="Length">2</Int>
+          <Real>15</Real>
+          <Real>5257.53</Real>
+        </Sequence>
+        <Sequence Name="Row9">
+          <Int Name="Length">2</Int>
+          <Real>16</Real>
+          <Real>5280.78</Real>
+        </Sequence>
+        <Sequence Name="Row10">
+          <Int Name="Length">2</Int>
+          <Real>17</Real>
+          <Real>5315.76</Real>
+        </Sequence>
+        <Sequence Name="Row11">
+          <Int Name="Length">2</Int>
+          <Real>18</Real>
+          <Real>5340.06</Real>
+        </Sequence>
+      </XvgData>
+    </Integrator>
+  </System>
+</ReferenceData>
index a4d87197f79f4c38ecc680187729e70b90b8d536..edbaa8f8a208958e3194a292e41b093f012a41e8 100644 (file)
@@ -168,6 +168,13 @@ const MdpFileValues mdpFileValueDatabase_g
                                               1, 2, 3, 4, 5, 6, 7, 8, 9
                                           } }
     },
+    // Scaled water for NMA
+    {
+        "scaled-water", { { },
+                          {
+                              1, 2, 3, 4, 5, 6
+                          } }
+    },
     // Nonanol molecule in vacuo, topology suitable for testing FEP
     // on KE, angles, dihedral restraints, coulomb and vdw
     {
diff --git a/src/testutils/simulationdatabase/scaled-water.g96 b/src/testutils/simulationdatabase/scaled-water.g96
new file mode 100644 (file)
index 0000000..4aee8f4
--- /dev/null
@@ -0,0 +1,14 @@
+TITLE
+2 scaled waters
+END
+POSITION
+    1 SOL   OW         1    0.914818904   17.114674936   24.974532564
+    1 SOL   HW1        2    1.207239659   16.434171182   24.367718701
+    1 SOL   HW2        3    1.794362088   17.256320895    0.323592571
+    2 SOL   OW         4    2.688663748   14.887261002   23.182636745
+    2 SOL   HW1        5    2.999853477   14.939893657   22.278872288
+    2 SOL   HW2        6    2.760097525   13.938314213   23.286543655
+END
+BOX
+   25.001000000   25.001000000   25.001000000
+END
diff --git a/src/testutils/simulationdatabase/scaled-water.ndx b/src/testutils/simulationdatabase/scaled-water.ndx
new file mode 100644 (file)
index 0000000..03ad1d8
--- /dev/null
@@ -0,0 +1,6 @@
+[ System ]
+   1    2    3    4    5    6
+[ Water ]
+   1    2    3    4    5    6
+[ SOL ]
+   1    2    3    4    5    6
diff --git a/src/testutils/simulationdatabase/scaled-water.top b/src/testutils/simulationdatabase/scaled-water.top
new file mode 100644 (file)
index 0000000..e7add3c
--- /dev/null
@@ -0,0 +1,34 @@
+[ defaults ]
+; nbfunc        comb-rule       gen-pairs       fudgeLJ fudgeQQ
+1               3               yes             0.5     0.5
+
+[ atomtypes ]
+; full atom descriptions are available in ffoplsaa.atp
+; name  bond_type    mass    charge   ptype   sigma      epsilon
+ OW   O  8      15.99940     0.000       A    3          50
+ HW   H  1       1.00800     0.000       A    0.00000e+00  0.00000e+00
+
+[ moleculetype ]
+; molname       nrexcl
+SOL             2
+
+[ atoms ]
+; id    at type res nr  residu name     at name         cg nr   charge
+1       OW     1       SOL              OW             1      -0.6
+2       HW     1       SOL             HW1             1       0.3
+3       HW     1       SOL             HW2             1       0.3
+
+[ bonds ]
+; i     j       funct   length  force.c.
+1       2       1       0.9572 5024.0
+1       3       1       0.9572 5024.0
+
+[ angles ]
+; i     j       k       funct   angle   force.c.
+2       1       3       1       100.0  6.0
+
+[ system ]
+2 scaled waters
+
+[ molecules ]
+SOL 2