5e6487ea515fa102f92260cfc03a646ec591cf87
[alexxy/gromacs.git] / src / gromacs / trajectoryanalysis / tests / select.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014,2015,2019, 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 functionality of the "select" trajectory analysis module.
38  *
39  * These tests test most of the functionality of the module, but currently
40  * missing are:
41  *  - Tests related to -oc output.  This would require a more complex input
42  *    structure for reasonable testing (the same structure could also be used
43  *    in selection unit tests for 'insolidangle' keyword).
44  *  - Tests for XVG labels.  This is a limitation of the current testing
45  *    framework.
46  *
47  * \author Teemu Murtola <teemu.murtola@gmail.com>
48  * \ingroup module_trajectoryanalysis
49  */
50 #include "gmxpre.h"
51
52 #include "gromacs/trajectoryanalysis/modules/select.h"
53
54 #include <gtest/gtest.h>
55
56 #include "testutils/cmdlinetest.h"
57 #include "testutils/textblockmatchers.h"
58
59 #include "moduletest.h"
60
61 namespace
62 {
63
64 using gmx::test::CommandLine;
65 using gmx::test::ExactTextMatch;
66
67 /********************************************************************
68  * Tests for gmx::analysismodules::Select.
69  */
70
71 //! Test fixture for the select analysis module.
72 typedef gmx::test::TrajectoryAnalysisModuleTestFixture<gmx::analysismodules::SelectInfo> SelectModuleTest;
73
74 TEST_F(SelectModuleTest, BasicTest)
75 {
76     const char* const cmdline[] = { "select", "-select", "y < 2.5", "resname RA" };
77     setTopology("simple.gro");
78     setTrajectory("simple.gro");
79     setOutputFile("-oi", "index.dat", ExactTextMatch());
80     setOutputFile("-on", "index.ndx", ExactTextMatch());
81     excludeDataset("cfrac");
82     runTest(CommandLine(cmdline));
83 }
84
85 TEST_F(SelectModuleTest, HandlesPDBOutputWithNonPDBInput)
86 {
87     const char* const cmdline[] = { "select", "-select", "resname RA RD and y < 2.5" };
88     setTopology("simple.gro");
89     setTrajectory("simple.gro");
90     includeDataset("occupancy");
91     setOutputFile("-ofpdb", "occupancy.pdb", ExactTextMatch());
92     runTest(CommandLine(cmdline));
93 }
94
95 TEST_F(SelectModuleTest, HandlesPDBOutputWithPDBInput)
96 {
97     const char* const cmdline[] = { "select", "-select", "resname RA RD and y < 2.5" };
98     setTopology("simple.pdb");
99     setTrajectory("simple.gro");
100     includeDataset("occupancy");
101     setOutputFile("-ofpdb", "occupancy.pdb", ExactTextMatch());
102     runTest(CommandLine(cmdline));
103 }
104
105 TEST_F(SelectModuleTest, HandlesMaxPDBOutput)
106 {
107     const char* const cmdline[] = { "select",        "-select",   "resname RA RD and y < 2.5",
108                                     "resname RA RB", "-pdbatoms", "maxsel" };
109     setTopology("simple.pdb");
110     setTrajectory("simple.gro");
111     includeDataset("occupancy");
112     setOutputFile("-ofpdb", "occupancy.pdb", ExactTextMatch());
113     runTest(CommandLine(cmdline));
114 }
115
116 TEST_F(SelectModuleTest, HandlesSelectedPDBOutput)
117 {
118     const char* const cmdline[] = { "select",        "-select",   "resname RA RD and y < 2.5",
119                                     "resname RA RB", "-pdbatoms", "selected" };
120     setTopology("simple.pdb");
121     setTrajectory("simple.gro");
122     includeDataset("occupancy");
123     setOutputFile("-ofpdb", "occupancy.pdb", ExactTextMatch());
124     runTest(CommandLine(cmdline));
125 }
126
127 TEST_F(SelectModuleTest, NormalizesSizes)
128 {
129     const char* const cmdline[] = { "select",     "-select", "y < 2.5", "resname RA and y < 2.5",
130                                     "resname RA", "-norm" };
131     setTopology("simple.gro");
132     includeDataset("size");
133     runTest(CommandLine(cmdline));
134 }
135
136 TEST_F(SelectModuleTest, WritesResidueNumbers)
137 {
138     const char* const cmdline[] = { "select", "-select", "res_com of resname RA RD" };
139     setTopology("simple.gro");
140     includeDataset("index");
141     runTest(CommandLine(cmdline));
142 }
143
144 TEST_F(SelectModuleTest, WritesResidueIndices)
145 {
146     const char* const cmdline[] = { "select", "-select", "res_com of resname RA RD", "-resnr",
147                                     "index" };
148     setTopology("simple.gro");
149     includeDataset("index");
150     runTest(CommandLine(cmdline));
151 }
152
153 } // namespace