2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017, 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 * Implements classes in moduletest.h.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
40 * \ingroup module_trajectoryanalysis
44 #include "moduletest.h"
50 #include "gromacs/commandline/cmdlineoptionsmodule.h"
51 #include "gromacs/trajectoryanalysis/analysismodule.h"
52 #include "gromacs/trajectoryanalysis/cmdlinerunner.h"
54 #include "gromacs/analysisdata/tests/datatest.h"
55 #include "testutils/cmdlinetest.h"
56 #include "testutils/refdata.h"
57 #include "testutils/testasserts.h"
64 /********************************************************************
65 * AbstractTrajectoryAnalysisModuleTestFixture::Impl
68 class AbstractTrajectoryAnalysisModuleTestFixture::Impl
74 : bCheck(true), tolerance(defaultRealTolerance())
79 FloatingPointTolerance tolerance;
82 typedef std::map<std::string, DatasetInfo> DatasetList;
84 explicit Impl(AbstractTrajectoryAnalysisModuleTestFixture *parent);
86 TrajectoryAnalysisModule &module();
87 void ensureModuleCreated();
88 bool hasCheckedDatasets() const;
90 AbstractTrajectoryAnalysisModuleTestFixture &parent_;
91 TrajectoryAnalysisModulePointer module_;
92 DatasetList datasets_;
93 bool bDatasetsIncluded_;
96 AbstractTrajectoryAnalysisModuleTestFixture::Impl::Impl(
97 AbstractTrajectoryAnalysisModuleTestFixture *parent)
98 : parent_(*parent), bDatasetsIncluded_(false)
102 TrajectoryAnalysisModule &
103 AbstractTrajectoryAnalysisModuleTestFixture::Impl::module()
105 ensureModuleCreated();
110 AbstractTrajectoryAnalysisModuleTestFixture::Impl::ensureModuleCreated()
112 if (module_.get() == nullptr)
114 module_ = parent_.createModule();
115 const std::vector<std::string> &datasetNames(module_->datasetNames());
117 std::vector<std::string>::const_iterator i;
118 for (i = datasetNames.begin(); i != datasetNames.end(); ++i)
120 datasets_[*i] = DatasetInfo();
126 AbstractTrajectoryAnalysisModuleTestFixture::Impl::hasCheckedDatasets() const
128 DatasetList::const_iterator dataset;
129 for (dataset = datasets_.begin(); dataset != datasets_.end(); ++dataset)
131 if (dataset->second.bCheck)
139 /********************************************************************
140 * AbstractTrajectoryAnalysisModuleTestFixture
143 AbstractTrajectoryAnalysisModuleTestFixture::AbstractTrajectoryAnalysisModuleTestFixture()
144 : impl_(new Impl(this))
148 AbstractTrajectoryAnalysisModuleTestFixture::~AbstractTrajectoryAnalysisModuleTestFixture()
153 AbstractTrajectoryAnalysisModuleTestFixture::setTopology(const char *filename)
155 setInputFile("-s", filename);
159 AbstractTrajectoryAnalysisModuleTestFixture::setTrajectory(const char *filename)
161 setInputFile("-f", filename);
165 AbstractTrajectoryAnalysisModuleTestFixture::includeDataset(const char *name)
167 impl_->ensureModuleCreated();
168 if (!impl_->bDatasetsIncluded_)
170 Impl::DatasetList::iterator i;
171 for (i = impl_->datasets_.begin(); i != impl_->datasets_.end(); ++i)
173 i->second.bCheck = false;
176 Impl::DatasetList::iterator dataset = impl_->datasets_.find(name);
177 const bool bFound = (dataset != impl_->datasets_.end());
178 GMX_RELEASE_ASSERT(bFound, "Attempted to include a non-existent dataset");
179 dataset->second.bCheck = true;
183 AbstractTrajectoryAnalysisModuleTestFixture::excludeDataset(const char *name)
185 impl_->ensureModuleCreated();
186 Impl::DatasetList::iterator dataset = impl_->datasets_.find(name);
187 const bool bFound = (dataset != impl_->datasets_.end());
188 GMX_RELEASE_ASSERT(bFound, "Attempted to exclude a non-existent dataset");
189 dataset->second.bCheck = false;
193 AbstractTrajectoryAnalysisModuleTestFixture::setDatasetTolerance(
194 const char *name, const FloatingPointTolerance &tolerance)
196 impl_->ensureModuleCreated();
197 Impl::DatasetList::iterator dataset = impl_->datasets_.find(name);
198 const bool bFound = (dataset != impl_->datasets_.end());
199 GMX_RELEASE_ASSERT(bFound, "Attempted to set a tolerance for a non-existent dataset");
200 dataset->second.tolerance = tolerance;
204 AbstractTrajectoryAnalysisModuleTestFixture::runTest(const CommandLine &args)
206 TrajectoryAnalysisModule &module = impl_->module();
207 CommandLine &cmdline = commandLine();
210 TestReferenceChecker rootChecker(this->rootChecker());
211 rootChecker.checkString(args.toString(), "CommandLine");
213 if (impl_->hasCheckedDatasets())
215 TestReferenceChecker dataChecker(
216 rootChecker.checkCompound("OutputData", "Data"));
217 Impl::DatasetList::const_iterator dataset;
218 for (dataset = impl_->datasets_.begin();
219 dataset != impl_->datasets_.end();
222 if (dataset->second.bCheck)
224 const char *const name = dataset->first.c_str();
225 AbstractAnalysisData &data = module.datasetFromName(name);
226 AnalysisDataTestFixture::addReferenceCheckerModule(
227 dataChecker, name, &data, dataset->second.tolerance);
232 ICommandLineOptionsModulePointer runner(
233 TrajectoryAnalysisCommandLineRunner::createModule(std::move(impl_->module_)));
235 EXPECT_NO_THROW_GMX(rc = CommandLineTestHelper::runModuleDirect(std::move(runner), &cmdline));