Update instructions in containers.rst
[gromacs.git] / src / gromacs / gmxpreprocess / tests / pdb2gmx.cpp
blobf9bac4c8282411917c0e7fab95b2b0bbd5017e09
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2018,2019,2020, 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.
35 /*! \internal \file
36 * \brief
37 * Tests for pdb2gmx
39 * \author Mark Abraham <mark.j.abraham@gmail.com>
42 #include "gmxpre.h"
44 #include "gromacs/gmxpreprocess/pdb2gmx.h"
46 #include "gromacs/fileio/filetypes.h"
47 #include "gromacs/utility/futil.h"
48 #include "gromacs/utility/textreader.h"
50 #include "testutils/cmdlinetest.h"
51 #include "testutils/conftest.h"
52 #include "testutils/filematchers.h"
53 #include "testutils/refdata.h"
54 #include "testutils/testfilemanager.h"
55 #include "testutils/textblockmatchers.h"
57 namespace gmx
59 namespace test
61 namespace
64 using test::CommandLine;
66 //! Test parameter struct.
67 using CommandLineOptionParams =
68 std::tuple<std::string, std::string, std::string, std::string, std::string, std::string, int>;
70 /*! \brief Strings containing regular expressions for lines to skip
71 * when matching.
73 * \todo It would be preferable to just scrub the content that actually
74 * varies, but we don't use enough regular expression support for that
75 * yet.
77 * Note that the "\n" are needed so these regular expressions match
78 * Windows line endings. */
79 std::vector<std::string> c_regexStringsToSkip = { "^;[[:blank:]] *File '.*' was generated.*\n",
80 "^;[[:blank:]]*By user:.*\n",
81 "^;[[:blank:]]*On host:.*\n",
82 "^;[[:blank:]]*At date:.*\n",
83 "^;[[:blank:]]*:-\\).*\\(-:.*\n",
84 "^;[[:blank:]]*Executable:.*\n",
85 "^;[[:blank:]]*Data prefix:.*\n",
86 "^;[[:blank:]]*Working dir:.*\n",
87 "^;[[:blank:]]*pdb2gmx.*-test.*\n" };
88 //! Compiled regular expressions for lines to skip when matching.
89 FilteringExactTextMatch c_textMatcher(c_regexStringsToSkip);
91 class Pdb2gmxTest : public test::CommandLineTestBase, public ::testing::WithParamInterface<CommandLineOptionParams>
93 public:
94 Pdb2gmxTest()
96 int outputFileType = std::get<6>(GetParam());
97 if (outputFileType == efPDB)
99 // If we're writing PDB output, we are interested in
100 // testing things like TER records and chain IDs.
101 std::string outputfile = "conf.";
102 outputfile += ftp2ext(outputFileType);
103 ExactTextMatch settings;
104 setOutputFile("-o", outputfile.c_str(), TextFileMatch(settings));
106 else
108 setOutputFile("-o", "conf.gro", ConfMatch());
110 setOutputFile("-p", "topol.top", TextFileMatch(c_textMatcher));
113 void runTest(const CommandLine& args)
115 CommandLine& cmdline = commandLine();
116 cmdline.merge(args);
118 TestReferenceChecker rootChecker(this->rootChecker());
120 ASSERT_EQ(0, CommandLineTestHelper::runModuleFactory(&pdb2gmxInfo::create, &cmdline));
122 checkOutputFiles();
126 TEST_P(Pdb2gmxTest, ProducesMatchingTopology)
128 const auto& params = GetParam();
129 std::string cmdline[] = { "pdb2gmx", "-ignh",
130 "-ff", std::get<0>(params),
131 "-water", std::get<1>(params),
132 "-vsite", std::get<2>(params),
133 "-chainsep", std::get<3>(params),
134 "-merge", std::get<4>(params) };
135 setInputFile("-f", std::get<5>(params));
136 runTest(CommandLine(cmdline));
139 // These tests are still rather slow when run with TSAN, so in the
140 // CMakeLists.txt file we split them into separtae test binaries.
142 #if OPLSAA
143 INSTANTIATE_TEST_CASE_P(ForOplsaa,
144 Pdb2gmxTest,
145 ::testing::Combine(::testing::Values("oplsaa"),
146 ::testing::Values("tip3p", "tip4p", "tip5p"),
147 ::testing::Values("none", "h"),
148 ::testing::Values("id_or_ter"),
149 ::testing::Values("no"),
150 ::testing::Values("fragment1.pdb",
151 "fragment2.pdb",
152 "fragment3.pdb",
153 "fragment4.pdb"),
154 ::testing::Values(efGRO)));
155 #endif
157 #if GROMOS
158 INSTANTIATE_TEST_CASE_P(ForGromos43a1,
159 Pdb2gmxTest,
160 ::testing::Combine(::testing::Values("gromos43a1"),
161 ::testing::Values("spc", "spce"),
162 ::testing::Values("none", "h"),
163 ::testing::Values("id_or_ter"),
164 ::testing::Values("no"),
165 ::testing::Values("fragment1.pdb",
166 "fragment2.pdb",
167 "fragment3.pdb",
168 "fragment4.pdb"),
169 ::testing::Values(efGRO)));
171 INSTANTIATE_TEST_CASE_P(ForGromos53a6,
172 Pdb2gmxTest,
173 ::testing::Combine(::testing::Values("gromos53a6"),
174 ::testing::Values("spc", "spce"),
175 ::testing::Values("none", "h"),
176 ::testing::Values("id_or_ter"),
177 ::testing::Values("no"),
178 ::testing::Values("fragment1.pdb",
179 "fragment2.pdb",
180 "fragment3.pdb",
181 "fragment4.pdb"),
182 ::testing::Values(efGRO)));
183 #endif
185 #if AMBER
186 INSTANTIATE_TEST_CASE_P(ForAmber99sb_ildn,
187 Pdb2gmxTest,
188 ::testing::Combine(::testing::Values("amber99sb-ildn"),
189 ::testing::Values("tip3p"),
190 ::testing::Values("none", "h"),
191 ::testing::Values("id_or_ter"),
192 ::testing::Values("no"),
193 ::testing::Values("fragment1.pdb",
194 "fragment2.pdb",
195 "fragment3.pdb",
196 "fragment4.pdb"),
197 ::testing::Values(efGRO)));
198 #endif
200 #if CHARMM
201 INSTANTIATE_TEST_CASE_P(ForCharmm27,
202 Pdb2gmxTest,
203 ::testing::Combine(::testing::Values("charmm27"),
204 ::testing::Values("tip3p"),
205 ::testing::Values("none", "h"),
206 ::testing::Values("id_or_ter"),
207 ::testing::Values("no"),
208 ::testing::Values("fragment1.pdb",
209 "fragment2.pdb",
210 "fragment3.pdb",
211 "fragment4.pdb"),
212 ::testing::Values(efGRO)));
215 INSTANTIATE_TEST_CASE_P(ChainSep,
216 Pdb2gmxTest,
217 ::testing::Combine(::testing::Values("charmm27"),
218 ::testing::Values("tip3p"),
219 ::testing::Values("none"),
220 ::testing::Values("id", "ter", "id_or_ter", "id_and_ter"),
221 ::testing::Values("all", "no"),
222 ::testing::Values("chainTer.pdb"),
223 ::testing::Values(efGRO)));
225 INSTANTIATE_TEST_CASE_P(ChainChanges,
226 Pdb2gmxTest,
227 ::testing::Combine(::testing::Values("charmm27"),
228 ::testing::Values("tip3p"),
229 ::testing::Values("none"),
230 ::testing::Values("id", "ter", "id_or_ter", "id_and_ter"),
231 ::testing::Values("no"),
232 ::testing::Values("two-fragments.pdb"),
233 ::testing::Values(efPDB)));
235 INSTANTIATE_TEST_CASE_P(ForCharmm27CyclicSystem,
236 Pdb2gmxTest,
237 ::testing::Combine(::testing::Values("charmm27"),
238 ::testing::Values("tip3p"),
239 ::testing::Values("none"),
240 ::testing::Values("id_or_ter"),
241 ::testing::Values("no", "all"),
242 ::testing::Values("cyclic-rna.pdb",
243 "cyclic-protein-small.pdb"),
244 ::testing::Values(efGRO)));
245 #endif
247 } // namespace
248 } // namespace test
249 } // namespace gmx