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.
38 * Helper classes for coordinatefile and coordinateio tests
40 * \author Paul Bauer <paul.bauer.q@gmail.com>
42 * \ingroup module_coordinateio
45 #ifndef GMX_COORDINATEIO_TESTS_COORDINATEIO_H
46 #define GMX_COORDINATEIO_TESTS_COORDINATEIO_H
50 #include <gtest/gtest.h>
52 #include "gromacs/coordinateio/coordinatefile.h"
53 #include "gromacs/coordinateio/ioutputadapter.h"
54 #include "gromacs/coordinateio/requirements.h"
55 #include "gromacs/options/options.h"
56 #include "gromacs/options/optionsassigner.h"
57 #include "gromacs/selection/selectioncollection.h"
58 #include "gromacs/selection/selectionoption.h"
59 #include "gromacs/selection/selectionoptionmanager.h"
60 #include "gromacs/trajectoryanalysis/topologyinformation.h"
61 #include "gromacs/utility/exceptions.h"
62 #include "gromacs/utility/smalloc.h"
64 #include "testutils/cmdlinetest.h"
65 #include "testutils/testasserts.h"
66 #include "testutils/testfilemanager.h"
75 * Create minimal TrajectoryFrameWriter using the provided builder.
77 * \param[in] filename Name of file to create object for.
78 * \param[in] topology Reference to input top.
79 * \param[in] selection Reference to input selection.
80 * \param[in] requirements Requirements for constructing OutputManagar.
81 * \throws InconsistentInputError When builder can not create the CoordinateFile.
82 * \returns unique_ptr to new CoordinateFile object.
84 inline TrajectoryFrameWriterPointer createMinimalTrajectoryFrameWriter(const std::string& filename,
85 const TopologyInformation& topology,
86 const Selection& selection,
87 OutputRequirements requirements)
89 return createTrajectoryFrameWriter(topology.mtop(),
92 topology.hasTopology() ? topology.copyAtoms() : nullptr,
95 /*! \libinternal \brief
96 * Helper class for tests that need an initialized selection.
101 ModuleSelection() : manager_(&sc_)
103 options_.addManager(&manager_);
104 sc_.setReferencePosType("atom");
105 sc_.setOutputPosType("atom");
106 top_.fillFromInputFile(TestFileManager::getInputFilePath("lysozyme.pdb"));
107 sc_.setTopology(top_.mtop(), 0);
111 * Method to add a valid selection option to the Module, or an invalid
114 * \param[in] sel Selection to add option to.
115 * \param[in] useValid Set if the added selection should be valid for the module.
117 void addOptionForSelection(Selection* sel, bool useValid);
120 * Set the actual values for the selection.
122 * \param[in] options Option to set values for.
123 * \param[in] sel Selection to use.
124 * \param[in] useValid Set if the added selection should be valid for the module.
126 void setSelectionOptionValues(Options* options, Selection* sel, bool useValid);
129 * Get pointer to options to set values.
131 * \returns Pointer to options.
133 Options* getOption() { return &options_; }
136 //! Selection collection used for handling test selection.
137 SelectionCollection sc_;
138 //! Selection manager for test selection.
139 SelectionOptionManager manager_;
140 //! Options manager for test selection input.
142 //! Topology information needed for test selection atoms.
143 TopologyInformation top_;
146 inline void ModuleSelection::addOptionForSelection(Selection* sel, bool useValid)
150 options_.addOption(SelectionOption("sel").store(sel).onlyAtoms());
154 options_.addOption(SelectionOption("sel").store(sel).dynamicMask());
158 inline void ModuleSelection::setSelectionOptionValues(Options* options, Selection* sel, bool useValid)
160 OptionsAssigner assigner(options);
162 assigner.startOption("sel");
165 assigner.appendValue("all");
169 assigner.appendValue("res_cog of all");
171 assigner.finishOption();
174 ASSERT_TRUE(sel->isValid());
175 EXPECT_NO_THROW(sc_.compile());
178 /*! \libinternal \brief
179 * Test fixture to test matching file types for modules.
181 class ModuleTest : public gmx::test::CommandLineTestBase, public ::testing::WithParamInterface<const char*>
185 * Run the builder to create an TrajectoryFrameWriter during tests.
187 * \param[in] filename Name for output file, to determine filetype during construction.
188 * \param[in] requirements Requirements for adding to the object.
189 * \returns The newly created object.
191 TrajectoryFrameWriterPointer runTest(const char* filename, const OutputRequirements& requirements)
193 return createMinimalTrajectoryFrameWriter(filename, dummyTopology_, dummySelection_, requirements);
195 //! Add topology information to test if needed.
198 dummyTopology_.fillFromInputFile(TestFileManager::getInputFilePath("lysozyme.pdb"));
200 //! Dummy topology to use to create CoordinateFile.
201 TopologyInformation dummyTopology_;
203 Selection dummySelection_;