Update copyright year for tests/grompp.cpp
[alexxy/gromacs.git] / src / programs / mdrun / tests / grompp.cpp
index afd93175ba235b13b07ed664f38554d5fc3e505e..5b2b73563c44376106ad1e818b5e944733245b2f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2015, by the GROMACS development team, led by
+ * Copyright (c) 2015,2019,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.
  */
 #include "gmxpre.h"
 
+#include "gromacs/utility/stringutil.h"
+#include "gromacs/gmxpreprocess/readir.h"
+
 #include <gtest/gtest.h>
 
 #include "moduletest.h"
 
+#include "testutils/testexceptions.h"
+
 namespace
 {
 
 //! Test fixture for grompp
-class GromppTest :
-    public gmx::test::MdrunTestFixture
+class GromppTest : public gmx::test::MdrunTestFixture
 {
-    public:
-        //! Execute the trajectory writing test
-        void runTest()
-        {
-            runner_.useTopGroAndNdxFromDatabase("spc-and-methanol");
-            EXPECT_EQ(0, runner_.callGrompp());
-        }
+public:
+    //! Execute the trajectory writing test
+    void runTest()
+    {
+        runner_.useTopGroAndNdxFromDatabase("spc-and-methanol");
+        EXPECT_EQ(0, runner_.callGrompp());
+    }
 };
 
 /* This test ensures that an empty .mdp file (ie. all default values) works. */
 TEST_F(GromppTest, EmptyMdpFileWorks)
 {
-    /* TODO Now that Verlet is the default, change the implementation
-       of useEmptyMdpFile() to do that. */
-    runner_.useStringAsMdpFile("");
+    runner_.useEmptyMdpFile();
+    runTest();
+}
+
+/* Test for making sure grompp can handle simulated annealing data */
+TEST_F(GromppTest, SimulatedAnnealingWorks)
+{
+    runner_.useStringAsMdpFile(
+            "annealing = periodic\n"
+            "annealing-npoints = 4\n"
+            "annealing-time = 0 2 4 6\n"
+            "annealing-temp = 298 320 320 298\n");
+    runTest();
+}
+
+TEST_F(GromppTest, SimulatedAnnealingWorksWithMultipleGroups)
+{
+    runner_.useStringAsMdpFile(
+            "tc-grps = Methanol SOL\n"
+            "tau-t = 0.1 0.1\n"
+            "ref_t = 298 298\n"
+            "annealing = single periodic\n"
+            "annealing-npoints = 3 4\n"
+            "annealing-time = 0 3 6 0 2 4 6\n"
+            "annealing-temp = 298 280 270 298 320 320 298\n");
     runTest();
 }
 
+#if HAVE_MUPARSER
+
+TEST_F(GromppTest, ValidTransformationCoord)
+{
+    const char* inputMdpFile[] = {
+        "pull = yes",
+        "pull-ncoords = 2",
+        "pull-ngroups = 2",
+        "pull-group1-name = SOL",
+        "pull-group2-name = Methanol",
+        "pull-coord1-geometry = distance",
+        "pull-coord1-groups = 1 2",
+        "pull-coord2-geometry = transformation",
+        "pull-coord2-expression = x1", // Valid expression
+    };
+    runner_.useStringAsMdpFile(gmx::joinStrings(inputMdpFile, "\n"));
+    runTest();
+}
+
+TEST_F(GromppTest, InvalidTransformationCoord)
+{
+    const char* inputMdpFile[] = {
+        "pull = yes",
+        "pull-ncoords = 2",
+        "pull-ngroups = 2",
+        "pull-group1-name = SOL",
+        "pull-group2-name = Methanol",
+        "pull-coord1-geometry = distance",
+        "pull-coord1-groups = 1 2",
+        "pull-coord2-geometry = transformation",
+        "pull-coord2-expression = x2", // Invalid expression -> evaluation should fail
+    };
+    runner_.useStringAsMdpFile(gmx::joinStrings(inputMdpFile, "\n"));
+    ASSERT_THROW(runTest(), gmx::InconsistentInputError);
+    done_inputrec_strings(); // This allows grompp to be called again in another test
+}
+#endif // HAVE_MUPARSER
+
+
 } // namespace