Merge "Script for analyzing include dependencies."
[alexxy/gromacs.git] / src / gromacs / trajectoryanalysis / tests / select.cpp
1 /*
2  *
3  *                This source code is part of
4  *
5  *                 G   R   O   M   A   C   S
6  *
7  *          GROningen MAchine for Chemical Simulations
8  *
9  * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
10  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
11  * Copyright (c) 2001-2009, The GROMACS development team,
12  * check out http://www.gromacs.org for more information.
13
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * If you want to redistribute modifications, please consider that
20  * scientific software is very special. Version control is crucial -
21  * bugs must be traceable. We will be happy to consider code for
22  * inclusion in the official distribution, but derived work must not
23  * be called official GROMACS. Details are found in the README & COPYING
24  * files - if they are missing, get the official version at www.gromacs.org.
25  *
26  * To help us fund GROMACS development, we humbly ask that you cite
27  * the papers on the package - you can find them in the top README file.
28  *
29  * For more info, check our website at http://www.gromacs.org
30  */
31 /*! \internal \file
32  * \brief
33  * Tests for functionality of the "select" trajectory analysis module.
34  *
35  * These tests test most of the functionality of the module, but currently
36  * missing are:
37  *  - Tests related to -oc output.  This would require a more complex input
38  *    structure for reasonable testing (the same structure could also be used
39  *    in selection unit tests for 'insolidangle' keyword).
40  *  - Tests for XVG labels.  This is a limitation of the current testing
41  *    framework.
42  *
43  * \author Teemu Murtola <teemu.murtola@cbr.su.se>
44  * \ingroup module_trajectoryanalysis
45  */
46 #include <gtest/gtest.h>
47
48 #include "gromacs/trajectoryanalysis/modules/select.h"
49
50 #include "testutils/cmdlinetest.h"
51
52 #include "moduletest.h"
53
54 namespace
55 {
56
57 using gmx::test::CommandLine;
58
59 /********************************************************************
60  * Tests for gmx::analysismodules::Select.
61  */
62
63 //! Test fixture for the select analysis module.
64 typedef gmx::test::TrajectoryAnalysisModuleTestFixture<gmx::analysismodules::Select>
65         SelectModuleTest;
66
67 TEST_F(SelectModuleTest, BasicTest)
68 {
69     const char *const cmdline[] = {
70         "select",
71         "-select", "y < 2.5", "resname RA"
72     };
73     setTopology("simple.gro");
74     setTrajectory("simple.gro");
75     setOutputFile("-oi", "index.dat");
76     setOutputFile("-on", "index.ndx");
77     excludeDataset("cfrac");
78     runTest(CommandLine::create(cmdline));
79 }
80
81 TEST_F(SelectModuleTest, HandlesPDBOutputWithNonPDBInput)
82 {
83     const char *const cmdline[] = {
84         "select",
85         "-select", "resname RA RD and y < 2.5"
86     };
87     setTopology("simple.gro");
88     setTrajectory("simple.gro");
89     includeDataset("occupancy");
90     setOutputFile("-ofpdb", "occupancy.pdb");
91     runTest(CommandLine::create(cmdline));
92 }
93
94 TEST_F(SelectModuleTest, HandlesPDBOutputWithPDBInput)
95 {
96     const char *const cmdline[] = {
97         "select",
98         "-select", "resname RA RD and y < 2.5"
99     };
100     setTopology("simple.pdb");
101     setTrajectory("simple.gro");
102     includeDataset("occupancy");
103     setOutputFile("-ofpdb", "occupancy.pdb");
104     runTest(CommandLine::create(cmdline));
105 }
106
107 TEST_F(SelectModuleTest, HandlesMaxPDBOutput)
108 {
109     const char *const cmdline[] = {
110         "select",
111         "-select", "resname RA RD and y < 2.5",
112         "-pdbatoms", "maxsel"
113     };
114     setTopology("simple.pdb");
115     setTrajectory("simple.gro");
116     includeDataset("occupancy");
117     setOutputFile("-ofpdb", "occupancy.pdb");
118     runTest(CommandLine::create(cmdline));
119 }
120
121 TEST_F(SelectModuleTest, HandlesSelectedPDBOutput)
122 {
123     const char *const cmdline[] = {
124         "select",
125         "-select", "resname RA RD and y < 2.5",
126         "-pdbatoms", "selected"
127     };
128     setTopology("simple.pdb");
129     setTrajectory("simple.gro");
130     includeDataset("occupancy");
131     setOutputFile("-ofpdb", "occupancy.pdb");
132     runTest(CommandLine::create(cmdline));
133 }
134
135 TEST_F(SelectModuleTest, HandlesDumpOption)
136 {
137     const char *const cmdline[] = {
138         "select",
139         "-select", "y < 2.5",
140         "-dump"
141     };
142     setTopology("simple.gro");
143     setOutputFile("-oi", "index.dat");
144     includeDataset("index");
145     runTest(CommandLine::create(cmdline));
146 }
147
148 TEST_F(SelectModuleTest, NormalizesSizes)
149 {
150     const char *const cmdline[] = {
151         "select",
152         "-select", "y < 2.5", "resname RA and y < 2.5", "resname RA",
153         "-norm"
154     };
155     setTopology("simple.gro");
156     includeDataset("size");
157     runTest(CommandLine::create(cmdline));
158 }
159
160 TEST_F(SelectModuleTest, WritesResidueNumbers)
161 {
162     const char *const cmdline[] = {
163         "select",
164         "-select", "res_com of resname RA RD"
165     };
166     setTopology("simple.gro");
167     includeDataset("index");
168     runTest(CommandLine::create(cmdline));
169 }
170
171 TEST_F(SelectModuleTest, WritesResidueIndices)
172 {
173     const char *const cmdline[] = {
174         "select",
175         "-select", "res_com of resname RA RD",
176         "-resnr", "index"
177     };
178     setTopology("simple.gro");
179     includeDataset("index");
180     runTest(CommandLine::create(cmdline));
181 }
182
183 } // namespace