Merge branch release-4-6
[alexxy/gromacs.git] / src / gromacs / trajectoryanalysis / tests / sasa.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2014, 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 "sasa" trajectory analysis module.
38  *
39  * These tests test the basic functionality of the tool itself, but currently
40  * the following are missing:
41  *  - Tests related to -odg output.  This would require a full tpr file, and
42  *    some investigation on what kind of tpr it should be to produce reasonable
43  *    output.
44  *  - Tests for the X axes in the area per atom/residue plots.  These could be
45  *    added once better X axes are implemented.
46  *  - Tests for XVG labels.  This is a limitation of the current testing
47  *    framework.
48  *
49  * The actual surface area algorithm should be tested separately with a more
50  * extensive set of data, but those fit better as a separate set of unit tests.
51  *
52  * \author Teemu Murtola <teemu.murtola@gmail.com>
53  * \ingroup module_trajectoryanalysis
54  */
55 #include <gtest/gtest.h>
56
57 #include "gromacs/trajectoryanalysis/modules/sasa.h"
58
59 #include "testutils/cmdlinetest.h"
60 #include "testutils/testasserts.h"
61
62 #include "moduletest.h"
63
64 namespace
65 {
66
67 using gmx::test::CommandLine;
68
69 /********************************************************************
70  * Tests for gmx::analysismodules::Sas.
71  */
72
73 //! Test fixture for the select analysis module.
74 typedef gmx::test::TrajectoryAnalysisModuleTestFixture<gmx::analysismodules::SasaInfo>
75     SasaModuleTest;
76
77 TEST_F(SasaModuleTest, BasicTest)
78 {
79     const char *const cmdline[] = {
80         "sasa",
81         "-surface", "all",
82         "-output", "name N CA C O H"
83     };
84     setTopology("lysozyme.gro");
85     setOutputFileNoTest("-o", "xvg");
86     setOutputFileNoTest("-or", "xvg");
87     setOutputFileNoTest("-oa", "xvg");
88     setOutputFileNoTest("-tv", "xvg");
89     excludeDataset("dgsolv");
90     setDatasetTolerance("area", gmx::test::ulpTolerance(8));
91     setDatasetTolerance("volume", gmx::test::ulpTolerance(8));
92     runTest(CommandLine(cmdline));
93 }
94
95 TEST_F(SasaModuleTest, WritesConnollySurfaceWithSolute)
96 {
97     const char *const cmdline[] = {
98         "sasa",
99         "-surface", "atomnr 1"
100     };
101     setTopology("lysozyme.gro");
102     setOutputFileNoTest("-o", "xvg");
103     setOutputFile("-q", "connolly.pdb");
104     includeDataset("area");
105     runTest(CommandLine(cmdline));
106 }
107
108 // The CONECT records written to the output make this very difficult to test
109 // without parsing the output file, since by construction, there are a lot of
110 // dot pairs that are at exactly the same distance from each other in exact
111 // arithmetic, and depending on rounding etc., different pairs get picked into
112 // the output for single and double precision.
113 #if 0
114 TEST_F(SasaModuleTest, WritesConnollySurfaceWithoutSolute)
115 {
116     const char *const cmdline[] = {
117         "sasa",
118         "-surface", "atomnr 1",
119         "-noprot"
120     };
121     setTopology("lysozyme.gro");
122     setOutputFileNoTest("-o", "xvg");
123     setOutputFile("-q", "connolly.pdb");
124     includeDataset("area");
125     runTest(CommandLine(cmdline));
126 }
127 #endif
128
129 TEST_F(SasaModuleTest, HandlesDynamicOutputGroup)
130 {
131     const char *const cmdline[] = {
132         "sasa",
133         "-surface", "all",
134         "-output", "y > 1.5"
135     };
136     setTopology("lysozyme.gro");
137     setOutputFileNoTest("-o", "xvg");
138     setOutputFileNoTest("-or", "xvg");
139     setOutputFileNoTest("-oa", "xvg");
140     excludeDataset("volume");
141     excludeDataset("dgsolv");
142     setDatasetTolerance("area", gmx::test::ulpTolerance(8));
143     runTest(CommandLine(cmdline));
144 }
145
146 TEST_F(SasaModuleTest, HandlesDynamicCalculationGroup)
147 {
148     const char *const cmdline[] = {
149         "sasa",
150         "-surface", "y > 1.5",
151         "-output", "y > 1.5 and z > 0"
152     };
153     setTopology("lysozyme.gro");
154     setOutputFileNoTest("-o", "xvg");
155     setOutputFileNoTest("-or", "xvg");
156     setOutputFileNoTest("-oa", "xvg");
157     excludeDataset("volume");
158     excludeDataset("dgsolv");
159     setDatasetTolerance("area", gmx::test::ulpTolerance(8));
160     runTest(CommandLine(cmdline));
161 }
162
163 } // namespace