2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
39 * \author Mark Abraham <mark.j.abraham@gmail.com>
44 #include "gromacs/gmxpreprocess/pdb2gmx.h"
48 #include "gromacs/fileio/filetypes.h"
49 #include "gromacs/utility/futil.h"
50 #include "gromacs/utility/stringutil.h"
51 #include "gromacs/utility/textreader.h"
53 #include "testutils/cmdlinetest.h"
54 #include "testutils/conftest.h"
55 #include "testutils/filematchers.h"
56 #include "testutils/refdata.h"
57 #include "testutils/testfilemanager.h"
58 #include "testutils/textblockmatchers.h"
67 using test::CommandLine;
69 //! Test parameter struct.
70 using CommandLineOptionParams =
71 std::tuple<std::string, std::string, std::string, std::string, std::string, std::string, int, bool>;
73 /*! \brief Strings containing regular expressions for lines to skip
76 * \todo It would be preferable to just scrub the content that actually
77 * varies, but we don't use enough regular expression support for that
80 * Note that the "\n" are needed so these regular expressions match
81 * Windows line endings. */
82 std::vector<std::string> c_regexStringsToSkip = { "^;[[:blank:]] *File '.*' was generated.*\n",
83 "^;[[:blank:]]*By user:.*\n",
84 "^;[[:blank:]]*On host:.*\n",
85 "^;[[:blank:]]*At date:.*\n",
86 "^;[[:blank:]]*:-\\).*\\(-:.*\n",
87 "^;[[:blank:]]*Executable:.*\n",
88 "^;[[:blank:]]*Data prefix:.*\n",
89 "^;[[:blank:]]*Working dir:.*\n",
90 "^;[[:blank:]]*pdb2gmx.*-test.*\n" };
91 //! Compiled regular expressions for lines to skip when matching.
92 FilteringExactTextMatch c_textMatcher(c_regexStringsToSkip);
94 class Pdb2gmxTest : public test::CommandLineTestBase, public ::testing::WithParamInterface<CommandLineOptionParams>
99 int outputFileType = std::get<6>(GetParam());
100 // If the file type of the output configuration is one
101 // commonly used (ie. pdb, gro), then check its content.
102 if (outputFileType == efPDB)
104 // If we're writing PDB output, we are interested in
105 // testing things like TER records and chain IDs.
106 std::string outputfile = "conf.";
107 outputfile += ftp2ext(outputFileType);
108 ExactTextMatch settings;
109 setOutputFile("-o", outputfile.c_str(), TextFileMatch(settings));
111 else if (outputFileType == efGRO)
113 setOutputFile("-o", "conf.gro", ConfMatch().matchFullConfiguration(std::get<7>(GetParam())));
115 setOutputFile("-p", "topol.top", TextFileMatch(c_textMatcher));
118 void runTest(const CommandLine& args)
120 CommandLine& cmdline = commandLine();
123 TestReferenceChecker rootChecker(this->rootChecker());
125 ASSERT_EQ(0, CommandLineTestHelper::runModuleFactory(&pdb2gmxInfo::create, &cmdline));
131 TEST_P(Pdb2gmxTest, ProducesMatchingTopology)
133 const auto& params = GetParam();
134 std::string cmdline[] = { "pdb2gmx", "-ignh",
135 "-ff", std::get<0>(params),
136 "-water", std::get<1>(params),
137 "-vsite", std::get<2>(params),
138 "-chainsep", std::get<3>(params),
139 "-merge", std::get<4>(params) };
140 setInputFile("-f", std::get<5>(params));
141 runTest(CommandLine(cmdline));
144 //! Help GoogleTest name our test cases
145 std::string namesOfTests(const testing::TestParamInfo<Pdb2gmxTest::ParamType>& info)
147 const auto& param = info.param;
149 std::string testName = formatString(
157 "matchfullconfiguration_%s_",
158 std::get<0>(param).c_str(),
159 std::get<1>(param).c_str(),
160 std::get<2>(param).c_str(),
161 std::get<3>(param).c_str(),
162 std::get<4>(param).c_str(),
163 std::get<5>(param).c_str(),
164 ftp2ext(std::get<6>(param)),
165 std::get<7>(param) ? "true" : "false");
167 // Note that the returned names must be unique and may use only
168 // alphanumeric ASCII characters. It's not supposed to contain
169 // underscores (see the GoogleTest FAQ
170 // why-should-test-suite-names-and-test-names-not-contain-underscore),
171 // but doing so works for now, is likely to remain so, and makes
172 // such test names much more readable.
173 testName = replaceAll(testName, "-", "");
174 testName = replaceAll(testName, ".", "");
178 // These tests are still rather slow when run with TSAN, so in the
179 // CMakeLists.txt file we split them into separtae test binaries.
182 INSTANTIATE_TEST_CASE_P(ForOplsaa,
184 ::testing::Combine(::testing::Values("oplsaa"),
185 ::testing::Values("tip3p", "tip4p", "tip5p"),
186 ::testing::Values("none", "h"),
187 ::testing::Values("id_or_ter"),
188 ::testing::Values("no"),
189 ::testing::Values("fragment1.pdb",
193 ::testing::Values(efGRO),
194 ::testing::Values(false)),
199 INSTANTIATE_TEST_CASE_P(ForGromos43a1,
201 ::testing::Combine(::testing::Values("gromos43a1"),
202 ::testing::Values("spc", "spce"),
203 ::testing::Values("none", "h"),
204 ::testing::Values("id_or_ter"),
205 ::testing::Values("no"),
206 ::testing::Values("fragment1.pdb",
210 ::testing::Values(efGRO),
211 ::testing::Values(false)),
214 INSTANTIATE_TEST_CASE_P(ForGromos53a6,
216 ::testing::Combine(::testing::Values("gromos53a6"),
217 ::testing::Values("spc", "spce"),
218 ::testing::Values("none", "h"),
219 ::testing::Values("id_or_ter"),
220 ::testing::Values("no"),
221 ::testing::Values("fragment1.pdb",
225 ::testing::Values(efGRO),
226 ::testing::Values(false)),
231 INSTANTIATE_TEST_CASE_P(ForAmber99sb_ildn,
233 ::testing::Combine(::testing::Values("amber99sb-ildn"),
234 ::testing::Values("tip3p"),
235 ::testing::Values("none", "h"),
236 ::testing::Values("id_or_ter"),
237 ::testing::Values("no"),
238 ::testing::Values("fragment1.pdb",
242 ::testing::Values(efGRO),
243 ::testing::Values(false)),
245 INSTANTIATE_TEST_CASE_P(ForAmber99sb_ildnWithTip4p,
247 ::testing::Combine(::testing::Values("amber99sb-ildn"),
248 ::testing::Values("tip4p"),
249 ::testing::Values("none"),
250 ::testing::Values("id_or_ter"),
251 ::testing::Values("no"),
252 ::testing::Values("tip4p.pdb"),
253 ::testing::Values(efGRO),
254 ::testing::Values(true)),
259 INSTANTIATE_TEST_CASE_P(ForCharmm27,
261 ::testing::Combine(::testing::Values("charmm27"),
262 ::testing::Values("tip3p"),
263 ::testing::Values("none", "h"),
264 ::testing::Values("id_or_ter"),
265 ::testing::Values("no"),
266 ::testing::Values("fragment1.pdb",
270 "single-residue.pdb"),
271 ::testing::Values(efGRO),
272 ::testing::Values(false)),
276 INSTANTIATE_TEST_CASE_P(ChainSep,
278 ::testing::Combine(::testing::Values("charmm27"),
279 ::testing::Values("tip3p"),
280 ::testing::Values("none"),
281 ::testing::Values("id", "ter", "id_or_ter", "id_and_ter"),
282 ::testing::Values("all", "no"),
283 ::testing::Values("chainTer.pdb"),
284 ::testing::Values(efGRO),
285 ::testing::Values(false)),
288 INSTANTIATE_TEST_CASE_P(ChainChanges,
290 ::testing::Combine(::testing::Values("charmm27"),
291 ::testing::Values("tip3p"),
292 ::testing::Values("none"),
293 ::testing::Values("id", "ter", "id_or_ter", "id_and_ter"),
294 ::testing::Values("no"),
295 ::testing::Values("two-fragments.pdb"),
296 ::testing::Values(efPDB),
297 ::testing::Values(false)),
300 INSTANTIATE_TEST_CASE_P(ForCharmm27CyclicSystem,
302 ::testing::Combine(::testing::Values("charmm27"),
303 ::testing::Values("tip3p"),
304 ::testing::Values("none"),
305 ::testing::Values("id_or_ter"),
306 ::testing::Values("no", "all"),
307 ::testing::Values("cyclic-rna.pdb",
308 "cyclic-protein-small.pdb"),
309 ::testing::Values(efGRO),
310 ::testing::Values(false)),