412938e3ab39a50c164042bf166571d90168f219
[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, 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/utility/futil.h"
47 #include "gromacs/utility/textreader.h"
48
49 #include "testutils/cmdlinetest.h"
50 #include "testutils/conftest.h"
51 #include "testutils/filematchers.h"
52 #include "testutils/refdata.h"
53 #include "testutils/testfilemanager.h"
54 #include "testutils/textblockmatchers.h"
55
56 namespace gmx
57 {
58 namespace test
59 {
60 namespace
61 {
62
63 using gmx::test::CommandLine;
64 using gmx::test::ConfMatch;
65
66 //! Test parameter struct.
67 using CommandLineOptionParams = std::tuple<std::string, std::string, std::string, std::string,
68                                            std::string, std::string>;
69
70 class Pdb2gmxTest : public gmx::test::CommandLineTestBase,
71                     public ::testing::WithParamInterface<CommandLineOptionParams>
72 {
73     public:
74         Pdb2gmxTest()
75         {
76             // TODO It would be preferable to just scrub the content
77             // that actually varies, but we don't have enough regular
78             // expression support for that yet.
79
80             // Note that the "\n" are needed so these regular
81             // expressions match Windows line endings.
82             textMatcher_.addRegexToSkip("^;[[:blank:]] *File '.*' was generated.*\n");
83             textMatcher_.addRegexToSkip("^;[[:blank:]]*By user:.*\n");
84             textMatcher_.addRegexToSkip("^;[[:blank:]]*On host:.*\n");
85             textMatcher_.addRegexToSkip("^;[[:blank:]]*At date:.*\n");
86             textMatcher_.addRegexToSkip("^;[[:blank:]]*:-\\).*\\(-:.*\n");
87             textMatcher_.addRegexToSkip("^;[[:blank:]]*Executable:.*\n");
88             textMatcher_.addRegexToSkip("^;[[:blank:]]*Data prefix:.*\n");
89             textMatcher_.addRegexToSkip("^;[[:blank:]]*Working dir:.*\n");
90             textMatcher_.addRegexToSkip("^;[[:blank:]]*pdb2gmx-test.*\n");
91             setOutputFile("-o", "conf.gro", ConfMatch());
92             setOutputFile("-p", "topol.top", TextFileMatch(textMatcher_));
93         }
94
95         void runTest(const CommandLine &args)
96         {
97             CommandLine &cmdline = commandLine();
98             cmdline.merge(args);
99
100             ASSERT_EQ(0, gmx_pdb2gmx(cmdline.argc(), cmdline.argv()));
101             checkOutputFiles();
102         }
103         FilteringExactTextMatch textMatcher_;
104 };
105
106 TEST_P(Pdb2gmxTest, ProducesMatchingTopology)
107 {
108     const auto &params    = GetParam();
109     std::string cmdline[] = {
110         "pdb2gmx", "-ignh", "-ff", std::get<0>(params), "-water", std::get<1>(params), "-vsite", std::get<2>(params),
111         "-chainsep", std::get<3>(params), "-merge", std::get<4>(params)
112     };
113     setInputFile("-f", std::get<5>(params));
114     runTest(CommandLine(cmdline));
115 }
116
117 INSTANTIATE_TEST_CASE_P(ForOplsaa, Pdb2gmxTest,
118                             ::testing::Combine
119                             (::testing::Values("oplsaa"),
120                                 ::testing::Values("tip3p", "tip4p", "tip5p"),
121                                 ::testing::Values("none", "h"),
122                                 ::testing::Values("id_or_ter"),
123                                 ::testing::Values("no"),
124                                 ::testing::Values("fragment1.pdb", "fragment2.pdb", "fragment3.pdb", "fragment4.pdb"))
125                         );
126
127 INSTANTIATE_TEST_CASE_P(ForGromos43a1, Pdb2gmxTest,
128                             ::testing::Combine
129                             (::testing::Values("gromos43a1"),
130                                 ::testing::Values("spc", "spce"),
131                                 ::testing::Values("none", "h"),
132                                 ::testing::Values("id_or_ter"),
133                                 ::testing::Values("no"),
134                                 ::testing::Values("fragment1.pdb", "fragment2.pdb", "fragment3.pdb", "fragment4.pdb"))
135                         );
136
137 INSTANTIATE_TEST_CASE_P(ForGromos53a6, Pdb2gmxTest,
138                             ::testing::Combine
139                             (::testing::Values("gromos53a6"),
140                                 ::testing::Values("spc", "spce"),
141                                 ::testing::Values("none", "h"),
142                                 ::testing::Values("id_or_ter"),
143                                 ::testing::Values("no"),
144                                 ::testing::Values("fragment1.pdb", "fragment2.pdb", "fragment3.pdb", "fragment4.pdb"))
145                         );
146
147 INSTANTIATE_TEST_CASE_P(ForAmber99sb_ildn, Pdb2gmxTest,
148                             ::testing::Combine
149                             (::testing::Values("amber99sb-ildn"),
150                                 ::testing::Values("tip3p"),
151                                 ::testing::Values("none", "h"),
152                                 ::testing::Values("id_or_ter"),
153                                 ::testing::Values("no"),
154                                 ::testing::Values("fragment1.pdb", "fragment2.pdb", "fragment3.pdb", "fragment4.pdb"))
155                         );
156
157 INSTANTIATE_TEST_CASE_P(ForCharmm27, Pdb2gmxTest,
158                             ::testing::Combine
159                             (::testing::Values("charmm27"),
160                                 ::testing::Values("tip3p"),
161                                 ::testing::Values("none", "h"),
162                                 ::testing::Values("id_or_ter"),
163                                 ::testing::Values("no"),
164                                 ::testing::Values("fragment1.pdb", "fragment2.pdb", "fragment3.pdb", "fragment4.pdb"))
165                         );
166
167
168 INSTANTIATE_TEST_CASE_P(ChainSep, Pdb2gmxTest,
169                             ::testing::Combine
170                             (::testing::Values("charmm27"),
171                                 ::testing::Values("tip3p"),
172                                 ::testing::Values("none"),
173                                 ::testing::Values("id", "ter", "id_or_ter", "id_and_ter"),
174                                 ::testing::Values("all", "no"),
175                                 ::testing::Values("chainTer.pdb"))
176                         );
177
178
179 } // namespace
180 } // namespace
181 } // namespace