2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2019, 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
85 createMinimalTrajectoryFrameWriter(const std::string
&filename
,
86 const TopologyInformation
&topology
,
87 const Selection
&selection
,
88 OutputRequirements requirements
)
90 return createTrajectoryFrameWriter(topology
.mtop(),
93 topology
.hasTopology() ? topology
.copyAtoms() : nullptr,
96 /*! \libinternal \brief
97 * Helper class for tests that need an initialized selection.
102 ModuleSelection() : manager_(&sc_
)
104 options_
.addManager(&manager_
);
105 sc_
.setReferencePosType("atom");
106 sc_
.setOutputPosType("atom");
107 top_
.fillFromInputFile(TestFileManager::getInputFilePath("lysozyme.pdb"));
108 sc_
.setTopology(top_
.mtop(), 0);
112 * Method to add a valid selection option to the Module, or an invalid
115 * \param[in] sel Selection to add option to.
116 * \param[in] useValid Set if the added selection should be valid for the module.
118 void addOptionForSelection(Selection
*sel
, bool useValid
);
121 * Set the actual values for the selection.
123 * \param[in] options Option to set values for.
124 * \param[in] sel Selection to use.
125 * \param[in] useValid Set if the added selection should be valid for the module.
127 void setSelectionOptionValues(Options
*options
, Selection
*sel
, bool useValid
);
130 * Get pointer to options to set values.
132 * \returns Pointer to options.
134 Options
*getOption() { return &options_
; }
137 //! Selection collection used for handling test selection.
138 SelectionCollection sc_
;
139 //! Selection manager for test selection.
140 SelectionOptionManager manager_
;
141 //! Options manager for test selection input.
143 //! Topology information needed for test selection atoms.
144 TopologyInformation top_
;
149 ModuleSelection::addOptionForSelection(Selection
*sel
, bool useValid
)
153 options_
.addOption(SelectionOption("sel").store(sel
).onlyAtoms());
157 options_
.addOption(SelectionOption("sel").store(sel
).dynamicMask());
162 ModuleSelection::setSelectionOptionValues(Options
*options
, Selection
*sel
, bool useValid
)
164 OptionsAssigner
assigner(options
);
166 assigner
.startOption("sel");
169 assigner
.appendValue("all");
173 assigner
.appendValue("res_cog of all");
175 assigner
.finishOption();
178 ASSERT_TRUE(sel
->isValid());
179 EXPECT_NO_THROW(sc_
.compile());
182 /*! \libinternal \brief
183 * Test fixture to test matching file types for modules.
185 class ModuleTest
: public gmx::test::CommandLineTestBase
,
186 public ::testing::WithParamInterface
<const char *>
190 * Run the builder to create an TrajectoryFrameWriter during tests.
192 * \param[in] filename Name for output file, to determine filetype during construction.
193 * \param[in] requirements Requirements for adding to the object.
194 * \returns The newly created object.
196 const TrajectoryFrameWriterPointer
197 runTest(const char *filename
, const OutputRequirements
&requirements
)
199 return createMinimalTrajectoryFrameWriter(filename
,
204 //! Add topology information to test if needed.
207 dummyTopology_
.fillFromInputFile(
208 TestFileManager::getInputFilePath("lysozyme.pdb"));
210 //! Dummy topology to use to create CoordinateFile.
211 TopologyInformation dummyTopology_
;
213 Selection dummySelection_
;