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 * Tests for gmx::SetAtoms
40 * \author Paul Bauer <paul.bauer.q@gmail.com>
41 * \ingroup module_coordinateio
49 #include "gromacs/coordinateio/outputadapters/setatoms.h"
50 #include "gromacs/trajectory/trajectoryframe.h"
51 #include "gromacs/trajectoryanalysis/topologyinformation.h"
53 #include "gromacs/coordinateio/tests/coordinate_test.h"
54 #include "testutils/testfilemanager.h"
63 * Test fixture to prepare a setatoms object to pass data through.
65 class SetAtomsTest : public gmx::test::CommandLineTestBase
68 //! Prepare test fixture topology to have atoms available.
71 topology_.fillFromInputFile(TestFileManager::getInputFilePath("lysozyme.pdb"));
75 * Get access to the method for changing atom information.
77 * \param[in] type Type to use for setting up method.
78 * \param[in] haveAtomsAvailable Decide if method shouöd have atoms stored or not.
80 SetAtoms* setAtoms(ChangeAtomsType type, bool haveAtomsAvailable)
84 if (haveAtomsAvailable)
86 setAtoms_ = std::make_unique<SetAtoms>(type, topology_.copyAtoms());
90 setAtoms_ = std::make_unique<SetAtoms>(type, nullptr);
93 return setAtoms_.get();
95 //! Get access to a t_atoms struct to use in the dummy t_trxframe.
96 t_atoms* getAtomsCopy() { return const_cast<t_atoms*>(topology_.atoms()); }
99 //! Object to use for tests
100 SetAtomsPointer setAtoms_;
101 //! Local topology to get atoms from
102 TopologyInformation topology_;
105 TEST_F(SetAtomsTest, RemovesExistingAtoms)
108 clear_trxframe(&frame, true);
111 frame.atoms = getAtomsCopy();
113 EXPECT_NE(frame.atoms, nullptr);
115 SetAtoms* method = setAtoms(ChangeAtomsType::Never, true);
116 EXPECT_NO_THROW(method->processFrame(0, &frame));
118 EXPECT_FALSE(frame.bAtoms);
119 EXPECT_EQ(frame.atoms, nullptr);
122 TEST_F(SetAtomsTest, AddsNewAtoms)
125 clear_trxframe(&frame, true);
127 frame.bAtoms = false;
128 frame.atoms = nullptr;
130 SetAtoms* method = setAtoms(ChangeAtomsType::AlwaysFromStructure, true);
131 EXPECT_NO_THROW(method->processFrame(0, &frame));
133 EXPECT_TRUE(frame.bAtoms);
134 EXPECT_NE(frame.atoms, nullptr);
137 TEST_F(SetAtomsTest, ThrowsOnRequiredAtomsNotAvailable)
140 clear_trxframe(&frame, true);
142 frame.bAtoms = false;
143 frame.atoms = nullptr;
145 SetAtoms* method = setAtoms(ChangeAtomsType::Always, false);
146 EXPECT_THROW(method->processFrame(0, &frame), InconsistentInputError);
149 TEST_F(SetAtomsTest, WillUseOldAtomsWhenNoNewAvailable)
152 clear_trxframe(&frame, true);
155 frame.atoms = getAtomsCopy();
157 EXPECT_NE(frame.atoms, nullptr);
159 SetAtoms* method = setAtoms(ChangeAtomsType::Always, false);
160 EXPECT_NO_THROW(method->processFrame(0, &frame));
163 TEST_F(SetAtomsTest, ThrowsWhenUserAtomReplacementNotPossible)
166 clear_trxframe(&frame, true);
169 frame.atoms = getAtomsCopy();
171 EXPECT_NE(frame.atoms, nullptr);
173 SetAtoms* method = setAtoms(ChangeAtomsType::AlwaysFromStructure, false);
174 EXPECT_THROW(method->processFrame(0, &frame), InconsistentInputError);