2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2019,2020, 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.
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.
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.
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.
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.
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.
37 * Tests for functionality of the "extract-cluster" trajectory analysis module.
39 * \author Paul Bauer <paul.bauer.q@gmail.com>
40 * \ingroup module_trajectoryanalysis
44 #include "gromacs/trajectoryanalysis/modules/extract_cluster.h"
46 #include <gtest/gtest.h>
48 #include "gromacs/utility/path.h"
49 #include "gromacs/utility/stringutil.h"
51 #include "testutils/cmdlinetest.h"
52 #include "testutils/filematchers.h"
53 #include "testutils/refdata.h"
54 #include "testutils/testfilemanager.h"
55 #include "testutils/textblockmatchers.h"
57 #include "moduletest.h"
68 /********************************************************************
69 * Tests for gmx::analysismodules::ExtractCluster.
72 //! Helper struct to combine filename, path and FileMatcher
73 struct ManualOutputFile
75 //! Generated file name.
77 //! Full generated file path.
78 std::string fullFilepath;
79 //! Corresponding file matcher to compare to reference.
80 FileMatcherPointer matcher;
83 //! Test fixture for the convert-trj analysis module.
84 class ExtractClusterModuleTest : public AbstractTrajectoryAnalysisModuleTestFixture
87 TrajectoryAnalysisModulePointer createModule() override
89 return analysismodules::ExtractClusterInfo::create();
94 ExtractClusterModuleTest();
96 //! Compare generated files to expected ones.
100 //! Array of names and paths for generated files.
101 std::array<ManualOutputFile, 8> generatedFiles;
104 ExtractClusterModuleTest::ExtractClusterModuleTest()
106 std::string outputFilepath = gmx::Path::getWorkingDirectory();
108 fileManager().setOutputTempDirectory(outputFilepath);
109 // Those are for cleaning up the files generated during testing.
110 fileManager().getTemporaryFilePath("csizew.xpm");
111 fileManager().getTemporaryFilePath("csize.xpm");
113 setTrajectory("extract_cluster.trr");
114 setInputFile("-clusters", "extract_cluster.ndx");
117 for (auto& generatedFile : generatedFiles)
119 generatedFile.filename = gmx::Path::concatenateBeforeExtension(
120 "test.g96", gmx::formatString("_Cluster_000%d", fileNumber));
121 generatedFile.matcher = TextFileMatch(ExactTextMatch()).createFileMatcher();
122 generatedFile.fullFilepath = fileManager().getTemporaryFilePath(generatedFile.filename);
127 void ExtractClusterModuleTest::compareFiles()
129 TestReferenceChecker outputChecker(rootChecker().checkCompound("ClusterOutputFiles", "Files"));
130 for (const auto& file : generatedFiles)
132 TestReferenceChecker manualFileChecker(outputChecker.checkCompound("File", file.filename.c_str()));
133 file.matcher->checkFile(file.fullFilepath, &manualFileChecker);
137 TEST_F(ExtractClusterModuleTest, WorksWithAllAtoms)
139 std::string realFileName = TestFileManager::getTestSpecificFileName("test.g96");
140 const char* const cmdline[] = { "extract-cluster", "-o", realFileName.c_str() };
142 runTest(CommandLine(cmdline));
146 TEST_F(ExtractClusterModuleTest, WorksWithAtomSubset)
148 std::string realFileName = TestFileManager::getTestSpecificFileName("test.g96");
149 const char* const cmdline[] = {
150 "extract-cluster", "-o", realFileName.c_str(), "-select", "atomnr 1 2"
153 runTest(CommandLine(cmdline));