6a9c975900177cbb6349f3b8c4aeef87678b6b69
[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 "gmxpre.h"
56
57 #include <gtest/gtest.h>
58
59 #include "gromacs/trajectoryanalysis/modules/sasa.h"
60
61 #include "testutils/cmdlinetest.h"
62 #include "testutils/testasserts.h"
63
64 #include "moduletest.h"
65
66 namespace
67 {
68
69 using gmx::test::CommandLine;
70
71 /********************************************************************
72  * Tests for gmx::analysismodules::Sas.
73  */
74
75 //! Test fixture for the select analysis module.
76 typedef gmx::test::TrajectoryAnalysisModuleTestFixture<gmx::analysismodules::SasaInfo>
77     SasaModuleTest;
78
79 TEST_F(SasaModuleTest, BasicTest)
80 {
81     const char *const cmdline[] = {
82         "sasa",
83         "-surface", "all",
84         "-output", "name N CA C O H"
85     };
86     setTopology("lysozyme.gro");
87     setOutputFileNoTest("-o", "xvg");
88     setOutputFileNoTest("-or", "xvg");
89     setOutputFileNoTest("-oa", "xvg");
90     setOutputFileNoTest("-tv", "xvg");
91     excludeDataset("dgsolv");
92     setDatasetTolerance("area", gmx::test::ulpTolerance(8));
93     setDatasetTolerance("volume", gmx::test::ulpTolerance(8));
94     runTest(CommandLine(cmdline));
95 }
96
97 TEST_F(SasaModuleTest, WritesConnollySurfaceWithSolute)
98 {
99     const char *const cmdline[] = {
100         "sasa",
101         "-surface", "atomnr 1"
102     };
103     setTopology("lysozyme.gro");
104     setOutputFileNoTest("-o", "xvg");
105     setOutputFile("-q", "connolly.pdb");
106     includeDataset("area");
107     runTest(CommandLine(cmdline));
108 }
109
110 // The CONECT records written to the output make this very difficult to test
111 // without parsing the output file, since by construction, there are a lot of
112 // dot pairs that are at exactly the same distance from each other in exact
113 // arithmetic, and depending on rounding etc., different pairs get picked into
114 // the output for single and double precision.
115 #if 0
116 TEST_F(SasaModuleTest, WritesConnollySurfaceWithoutSolute)
117 {
118     const char *const cmdline[] = {
119         "sasa",
120         "-surface", "atomnr 1",
121         "-noprot"
122     };
123     setTopology("lysozyme.gro");
124     setOutputFileNoTest("-o", "xvg");
125     setOutputFile("-q", "connolly.pdb");
126     includeDataset("area");
127     runTest(CommandLine(cmdline));
128 }
129 #endif
130
131 TEST_F(SasaModuleTest, HandlesDynamicOutputGroup)
132 {
133     const char *const cmdline[] = {
134         "sasa",
135         "-surface", "all",
136         "-output", "y > 1.5"
137     };
138     setTopology("lysozyme.gro");
139     setOutputFileNoTest("-o", "xvg");
140     setOutputFileNoTest("-or", "xvg");
141     setOutputFileNoTest("-oa", "xvg");
142     excludeDataset("volume");
143     excludeDataset("dgsolv");
144     setDatasetTolerance("area", gmx::test::ulpTolerance(8));
145     runTest(CommandLine(cmdline));
146 }
147
148 TEST_F(SasaModuleTest, HandlesDynamicCalculationGroup)
149 {
150     const char *const cmdline[] = {
151         "sasa",
152         "-surface", "y > 1.5",
153         "-output", "y > 1.5 and z > 0"
154     };
155     setTopology("lysozyme.gro");
156     setOutputFileNoTest("-o", "xvg");
157     setOutputFileNoTest("-or", "xvg");
158     setOutputFileNoTest("-oa", "xvg");
159     excludeDataset("volume");
160     excludeDataset("dgsolv");
161     setDatasetTolerance("area", gmx::test::ulpTolerance(8));
162     runTest(CommandLine(cmdline));
163 }
164
165 } // namespace