Improve CUDA codegen flags
[alexxy/gromacs.git] / src / gromacs / gmxpreprocess / tests / pdb2gmx.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
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.
8  *
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.
13  *
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.
18  *
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.
23  *
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.
31  *
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.
34  */
35 /*! \internal \file
36  * \brief
37  * Tests for pdb2gmx
38  *
39  * \author Mark Abraham <mark.j.abraham@gmail.com>
40  */
41
42 #include "gmxpre.h"
43
44 #include "gromacs/gmxpreprocess/pdb2gmx.h"
45
46 #include "gromacs/fileio/filetypes.h"
47 #include "gromacs/utility/futil.h"
48 #include "gromacs/utility/textreader.h"
49
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"
56
57 namespace gmx
58 {
59 namespace test
60 {
61 namespace
62 {
63
64 using test::CommandLine;
65
66 //! Test parameter struct.
67 using CommandLineOptionParams =
68         std::tuple<std::string, std::string, std::string, std::string, std::string, std::string, int, bool>;
69
70 /*! \brief Strings containing regular expressions for lines to skip
71  * when matching.
72  *
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.
76  *
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);
90
91 class Pdb2gmxTest : public test::CommandLineTestBase, public ::testing::WithParamInterface<CommandLineOptionParams>
92 {
93 public:
94     Pdb2gmxTest()
95     {
96         int outputFileType = std::get<6>(GetParam());
97         // If the file type of the output configuration is one
98         // commonly used (ie. pdb, gro), then check its content.
99         if (outputFileType == efPDB)
100         {
101             // If we're writing PDB output, we are interested in
102             // testing things like TER records and chain IDs.
103             std::string outputfile = "conf.";
104             outputfile += ftp2ext(outputFileType);
105             ExactTextMatch settings;
106             setOutputFile("-o", outputfile.c_str(), TextFileMatch(settings));
107         }
108         else if (outputFileType == efGRO)
109         {
110             setOutputFile("-o", "conf.gro", ConfMatch().matchFullConfiguration(std::get<7>(GetParam())));
111         }
112         setOutputFile("-p", "topol.top", TextFileMatch(c_textMatcher));
113     }
114
115     void runTest(const CommandLine& args)
116     {
117         CommandLine& cmdline = commandLine();
118         cmdline.merge(args);
119
120         TestReferenceChecker rootChecker(this->rootChecker());
121
122         ASSERT_EQ(0, CommandLineTestHelper::runModuleFactory(&pdb2gmxInfo::create, &cmdline));
123
124         checkOutputFiles();
125     }
126 };
127
128 TEST_P(Pdb2gmxTest, ProducesMatchingTopology)
129 {
130     const auto& params    = GetParam();
131     std::string cmdline[] = { "pdb2gmx",   "-ignh",
132                               "-ff",       std::get<0>(params),
133                               "-water",    std::get<1>(params),
134                               "-vsite",    std::get<2>(params),
135                               "-chainsep", std::get<3>(params),
136                               "-merge",    std::get<4>(params) };
137     setInputFile("-f", std::get<5>(params));
138     runTest(CommandLine(cmdline));
139 }
140
141 // These tests are still rather slow when run with TSAN, so in the
142 // CMakeLists.txt file we split them into separtae test binaries.
143
144 #if OPLSAA
145 INSTANTIATE_TEST_CASE_P(ForOplsaa,
146                         Pdb2gmxTest,
147                         ::testing::Combine(::testing::Values("oplsaa"),
148                                            ::testing::Values("tip3p", "tip4p", "tip5p"),
149                                            ::testing::Values("none", "h"),
150                                            ::testing::Values("id_or_ter"),
151                                            ::testing::Values("no"),
152                                            ::testing::Values("fragment1.pdb",
153                                                              "fragment2.pdb",
154                                                              "fragment3.pdb",
155                                                              "fragment4.pdb"),
156                                            ::testing::Values(efGRO),
157                                            ::testing::Values(false)));
158 #endif
159
160 #if GROMOS
161 INSTANTIATE_TEST_CASE_P(ForGromos43a1,
162                         Pdb2gmxTest,
163                         ::testing::Combine(::testing::Values("gromos43a1"),
164                                            ::testing::Values("spc", "spce"),
165                                            ::testing::Values("none", "h"),
166                                            ::testing::Values("id_or_ter"),
167                                            ::testing::Values("no"),
168                                            ::testing::Values("fragment1.pdb",
169                                                              "fragment2.pdb",
170                                                              "fragment3.pdb",
171                                                              "fragment4.pdb"),
172                                            ::testing::Values(efGRO),
173                                            ::testing::Values(false)));
174
175 INSTANTIATE_TEST_CASE_P(ForGromos53a6,
176                         Pdb2gmxTest,
177                         ::testing::Combine(::testing::Values("gromos53a6"),
178                                            ::testing::Values("spc", "spce"),
179                                            ::testing::Values("none", "h"),
180                                            ::testing::Values("id_or_ter"),
181                                            ::testing::Values("no"),
182                                            ::testing::Values("fragment1.pdb",
183                                                              "fragment2.pdb",
184                                                              "fragment3.pdb",
185                                                              "fragment4.pdb"),
186                                            ::testing::Values(efGRO),
187                                            ::testing::Values(false)));
188 #endif
189
190 #if AMBER
191 INSTANTIATE_TEST_CASE_P(ForAmber99sb_ildn,
192                         Pdb2gmxTest,
193                         ::testing::Combine(::testing::Values("amber99sb-ildn"),
194                                            ::testing::Values("tip3p"),
195                                            ::testing::Values("none", "h"),
196                                            ::testing::Values("id_or_ter"),
197                                            ::testing::Values("no"),
198                                            ::testing::Values("fragment1.pdb",
199                                                              "fragment2.pdb",
200                                                              "fragment3.pdb",
201                                                              "fragment4.pdb"),
202                                            ::testing::Values(efGRO),
203                                            ::testing::Values(false)));
204 INSTANTIATE_TEST_CASE_P(ForAmber99sb_ildnWithTip4p,
205                         Pdb2gmxTest,
206                         ::testing::Combine(::testing::Values("amber99sb-ildn"),
207                                            ::testing::Values("tip4p"),
208                                            ::testing::Values("none"),
209                                            ::testing::Values("id_or_ter"),
210                                            ::testing::Values("no"),
211                                            ::testing::Values("tip4p.pdb"),
212                                            ::testing::Values(efGRO),
213                                            ::testing::Values(true)));
214 #endif
215
216 #if CHARMM
217 INSTANTIATE_TEST_CASE_P(ForCharmm27,
218                         Pdb2gmxTest,
219                         ::testing::Combine(::testing::Values("charmm27"),
220                                            ::testing::Values("tip3p"),
221                                            ::testing::Values("none", "h"),
222                                            ::testing::Values("id_or_ter"),
223                                            ::testing::Values("no"),
224                                            ::testing::Values("fragment1.pdb",
225                                                              "fragment2.pdb",
226                                                              "fragment3.pdb",
227                                                              "fragment4.pdb"),
228                                            ::testing::Values(efGRO),
229                                            ::testing::Values(false)));
230
231
232 INSTANTIATE_TEST_CASE_P(ChainSep,
233                         Pdb2gmxTest,
234                         ::testing::Combine(::testing::Values("charmm27"),
235                                            ::testing::Values("tip3p"),
236                                            ::testing::Values("none"),
237                                            ::testing::Values("id", "ter", "id_or_ter", "id_and_ter"),
238                                            ::testing::Values("all", "no"),
239                                            ::testing::Values("chainTer.pdb"),
240                                            ::testing::Values(efGRO),
241                                            ::testing::Values(false)));
242
243 INSTANTIATE_TEST_CASE_P(ChainChanges,
244                         Pdb2gmxTest,
245                         ::testing::Combine(::testing::Values("charmm27"),
246                                            ::testing::Values("tip3p"),
247                                            ::testing::Values("none"),
248                                            ::testing::Values("id", "ter", "id_or_ter", "id_and_ter"),
249                                            ::testing::Values("no"),
250                                            ::testing::Values("two-fragments.pdb"),
251                                            ::testing::Values(efPDB),
252                                            ::testing::Values(false)));
253
254 INSTANTIATE_TEST_CASE_P(ForCharmm27CyclicSystem,
255                         Pdb2gmxTest,
256                         ::testing::Combine(::testing::Values("charmm27"),
257                                            ::testing::Values("tip3p"),
258                                            ::testing::Values("none"),
259                                            ::testing::Values("id_or_ter"),
260                                            ::testing::Values("no", "all"),
261                                            ::testing::Values("cyclic-rna.pdb",
262                                                              "cyclic-protein-small.pdb"),
263                                            ::testing::Values(efGRO),
264                                            ::testing::Values(false)));
265 #endif
266
267 } // namespace
268 } // namespace test
269 } // namespace gmx