Relax requirement for bonded atom type names
[alexxy/gromacs.git] / src / gromacs / gmxpreprocess / tests / grompp_directives.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2021 by the GROMACS development team.
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 grompp directives parsing
38  *
39  * \author Eliane Briand <eliane@br.iand.fr>
40  */
41
42 #include "gmxpre.h"
43
44 #include "gromacs/fileio/tpxio.h"
45 #include "gromacs/gmxpreprocess/grompp.h"
46 #include "gromacs/mdtypes/inputrec.h"
47 #include "gromacs/mdtypes/state.h"
48 #include "gromacs/utility/futil.h"
49 #include "gromacs/utility/textreader.h"
50 #include "gromacs/utility/textwriter.h"
51 #include "gromacs/topology/topology.h"
52
53 #include "testutils/cmdlinetest.h"
54 #include "testutils/conftest.h"
55 #include "testutils/refdata.h"
56 #include "testutils/testfilemanager.h"
57 #include "testutils/textblockmatchers.h"
58
59 namespace
60 {
61
62 using gmx::test::CommandLine;
63 using gmx::test::TestFileManager;
64
65 class GromppDirectiveTest : public ::testing::Test
66 {
67 public:
68     GromppDirectiveTest() = default;
69
70 protected:
71     gmx::test::TestFileManager fileManager_;
72     std::string                mdpContentString_ =
73             "title                   = Directive edge case test \n"
74             "integrator              = md \n"
75             "nsteps                  = 1 \n"
76             "dt                      = 0.002 \n"
77             "vdwtype                 = cutoff \n"
78             "coulombtype             = cutoff \n"
79             "tcoupl                  = no \n"
80             "pcoupl                  = no \n"
81             "pbc                     = xyz \n"
82             "gen_vel                 = yes \n";
83 };
84
85 TEST_F(GromppDirectiveTest, edgeCaseAtomTypeNames)
86 {
87     CommandLine cmdline;
88     cmdline.addOption("grompp");
89
90     const std::string mdpInputFileName = fileManager_.getTemporaryFilePath("directives.mdp");
91     gmx::TextWriter::writeFileFromString(mdpInputFileName, mdpContentString_);
92     cmdline.addOption("-f", mdpInputFileName);
93
94
95     cmdline.addOption("-c", TestFileManager::getInputFilePath("directives.gro"));
96     cmdline.addOption("-p", TestFileManager::getInputFilePath("directives.top"));
97
98     std::string outTprFilename = fileManager_.getTemporaryFilePath("directives.tpr");
99     cmdline.addOption("-o", outTprFilename);
100
101     ASSERT_EQ(0, gmx_grompp(cmdline.argc(), cmdline.argv()));
102
103     {
104         gmx_mtop_t top_after;
105         t_inputrec ir_after;
106         t_state    state;
107         read_tpx_state(outTprFilename.c_str(), &ir_after, &state, &top_after);
108
109         // Check atomic numbers (or lack thereof coded as -1)
110         ASSERT_EQ(top_after.atomtypes.nr, 4);
111         EXPECT_EQ(top_after.atomtypes.atomnumber[0], -1);
112         EXPECT_EQ(top_after.atomtypes.atomnumber[1], 6);
113         EXPECT_EQ(top_after.atomtypes.atomnumber[2], 7);
114         EXPECT_EQ(top_after.atomtypes.atomnumber[3], -1);
115     }
116 }
117
118 } // namespace