Merge "Add occupied fraction and PDB output to g_ana select."
[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 typedef gmx::test::TrajectoryAnalysisModuleTestFixture<gmx::analysismodules::Select>
64         SelectModuleTest;
65
66 TEST_F(SelectModuleTest, BasicTest)
67 {
68     const char *const cmdline[] = {
69         "select",
70         "-select", "y < 2.5", "resname RA"
71     };
72     setTopology("simple.gro");
73     setTrajectory("simple.gro");
74     setOutputFile("-oi", "index.dat");
75     setOutputFile("-on", "index.ndx");
76     excludeDataset("cfrac");
77     runTest(CommandLine::create(cmdline));
78 }
79
80 TEST_F(SelectModuleTest, HandlesPDBOutputWithNonPDBInput)
81 {
82     const char *const cmdline[] = {
83         "select",
84         "-select", "resname RA RD and y < 2.5"
85     };
86     setTopology("simple.gro");
87     setTrajectory("simple.gro");
88     includeDataset("occupancy");
89     setOutputFile("-ofpdb", "occupancy.pdb");
90     runTest(CommandLine::create(cmdline));
91 }
92
93 TEST_F(SelectModuleTest, HandlesPDBOutputWithPDBInput)
94 {
95     const char *const cmdline[] = {
96         "select",
97         "-select", "resname RA RD and y < 2.5"
98     };
99     setTopology("simple.pdb");
100     setTrajectory("simple.gro");
101     includeDataset("occupancy");
102     setOutputFile("-ofpdb", "occupancy.pdb");
103     runTest(CommandLine::create(cmdline));
104 }
105
106 TEST_F(SelectModuleTest, HandlesMaxPDBOutput)
107 {
108     const char *const cmdline[] = {
109         "select",
110         "-select", "resname RA RD and y < 2.5",
111         "-pdbatoms", "maxsel"
112     };
113     setTopology("simple.pdb");
114     setTrajectory("simple.gro");
115     includeDataset("occupancy");
116     setOutputFile("-ofpdb", "occupancy.pdb");
117     runTest(CommandLine::create(cmdline));
118 }
119
120 TEST_F(SelectModuleTest, HandlesSelectedPDBOutput)
121 {
122     const char *const cmdline[] = {
123         "select",
124         "-select", "resname RA RD and y < 2.5",
125         "-pdbatoms", "selected"
126     };
127     setTopology("simple.pdb");
128     setTrajectory("simple.gro");
129     includeDataset("occupancy");
130     setOutputFile("-ofpdb", "occupancy.pdb");
131     runTest(CommandLine::create(cmdline));
132 }
133
134 TEST_F(SelectModuleTest, HandlesDumpOption)
135 {
136     const char *const cmdline[] = {
137         "select",
138         "-select", "y < 2.5",
139         "-dump"
140     };
141     setTopology("simple.gro");
142     setOutputFile("-oi", "index.dat");
143     includeDataset("index");
144     runTest(CommandLine::create(cmdline));
145 }
146
147 TEST_F(SelectModuleTest, NormalizesSizes)
148 {
149     const char *const cmdline[] = {
150         "select",
151         "-select", "y < 2.5", "resname RA and y < 2.5", "resname RA",
152         "-norm"
153     };
154     setTopology("simple.gro");
155     includeDataset("size");
156     runTest(CommandLine::create(cmdline));
157 }
158
159 TEST_F(SelectModuleTest, WritesResidueNumbers)
160 {
161     const char *const cmdline[] = {
162         "select",
163         "-select", "res_com of resname RA RD"
164     };
165     setTopology("simple.gro");
166     includeDataset("index");
167     runTest(CommandLine::create(cmdline));
168 }
169
170 TEST_F(SelectModuleTest, WritesResidueIndices)
171 {
172     const char *const cmdline[] = {
173         "select",
174         "-select", "res_com of resname RA RD",
175         "-resnr", "index"
176     };
177     setTopology("simple.gro");
178     includeDataset("index");
179     runTest(CommandLine::create(cmdline));
180 }
181
182 } // namespace