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()
98 return const_cast<t_atoms
*>(topology_
.atoms());
102 //! Object to use for tests
103 SetAtomsPointer setAtoms_
;
104 //! Local topology to get atoms from
105 TopologyInformation topology_
;
108 TEST_F(SetAtomsTest
, RemovesExistingAtoms
)
111 clear_trxframe(&frame
, true);
114 frame
.atoms
= getAtomsCopy();
116 EXPECT_NE(frame
.atoms
, nullptr);
118 SetAtoms
*method
= setAtoms(ChangeAtomsType::Never
, true);
119 EXPECT_NO_THROW(method
->processFrame(0, &frame
));
121 EXPECT_FALSE(frame
.bAtoms
);
122 EXPECT_EQ(frame
.atoms
, nullptr);
125 TEST_F(SetAtomsTest
, AddsNewAtoms
)
128 clear_trxframe(&frame
, true);
130 frame
.bAtoms
= false;
131 frame
.atoms
= nullptr;
133 SetAtoms
*method
= setAtoms(ChangeAtomsType::AlwaysFromStructure
, true);
134 EXPECT_NO_THROW(method
->processFrame(0, &frame
));
136 EXPECT_TRUE(frame
.bAtoms
);
137 EXPECT_NE(frame
.atoms
, nullptr);
140 TEST_F(SetAtomsTest
, ThrowsOnRequiredAtomsNotAvailable
)
143 clear_trxframe(&frame
, true);
145 frame
.bAtoms
= false;
146 frame
.atoms
= nullptr;
148 SetAtoms
*method
= setAtoms(ChangeAtomsType::Always
, false);
149 EXPECT_THROW(method
->processFrame(0, &frame
), InconsistentInputError
);
152 TEST_F(SetAtomsTest
, WillUseOldAtomsWhenNoNewAvailable
)
155 clear_trxframe(&frame
, true);
158 frame
.atoms
= getAtomsCopy();
160 EXPECT_NE(frame
.atoms
, nullptr);
162 SetAtoms
*method
= setAtoms(ChangeAtomsType::Always
, false);
163 EXPECT_NO_THROW(method
->processFrame(0, &frame
));
166 TEST_F(SetAtomsTest
, ThrowsWhenUserAtomReplacementNotPossible
)
169 clear_trxframe(&frame
, true);
172 frame
.atoms
= getAtomsCopy();
174 EXPECT_NE(frame
.atoms
, nullptr);
176 SetAtoms
*method
= setAtoms(ChangeAtomsType::AlwaysFromStructure
, false);
177 EXPECT_THROW(method
->processFrame(0, &frame
), InconsistentInputError
);