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 * 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/fileio/trxio.h"
51 #include "gromacs/trajectory/trajectoryframe.h"
52 #include "gromacs/trajectoryanalysis/topologyinformation.h"
54 #include "gromacs/coordinateio/tests/coordinate_test.h"
55 #include "testutils/testfilemanager.h"
64 * Test fixture to prepare a setatoms object to pass data through.
66 class SetAtomsTest
: public gmx::test::CommandLineTestBase
69 //! Prepare test fixture topology to have atoms available.
72 topology_
.fillFromInputFile(TestFileManager::getInputFilePath("lysozyme.pdb"));
76 * Get access to the method for changing atom information.
78 * \param[in] type Type to use for setting up method.
79 * \param[in] haveAtomsAvailable Decide if method shouöd have atoms stored or not.
81 SetAtoms
* setAtoms(ChangeAtomsType type
, bool haveAtomsAvailable
)
85 if (haveAtomsAvailable
)
87 setAtoms_
= std::make_unique
<SetAtoms
>(type
, topology_
.copyAtoms());
91 setAtoms_
= std::make_unique
<SetAtoms
>(type
, nullptr);
94 return setAtoms_
.get();
96 //! Get access to a t_atoms struct to use in the dummy t_trxframe.
97 t_atoms
* getAtomsCopy() { return const_cast<t_atoms
*>(topology_
.atoms()); }
100 //! Object to use for tests
101 SetAtomsPointer setAtoms_
;
102 //! Local topology to get atoms from
103 TopologyInformation topology_
;
106 TEST_F(SetAtomsTest
, RemovesExistingAtoms
)
109 clear_trxframe(&frame
, true);
112 frame
.atoms
= getAtomsCopy();
114 EXPECT_NE(frame
.atoms
, nullptr);
116 SetAtoms
* method
= setAtoms(ChangeAtomsType::Never
, true);
117 EXPECT_NO_THROW(method
->processFrame(0, &frame
));
119 EXPECT_FALSE(frame
.bAtoms
);
120 EXPECT_EQ(frame
.atoms
, nullptr);
123 TEST_F(SetAtomsTest
, AddsNewAtoms
)
126 clear_trxframe(&frame
, true);
128 frame
.bAtoms
= false;
129 frame
.atoms
= nullptr;
131 SetAtoms
* method
= setAtoms(ChangeAtomsType::AlwaysFromStructure
, true);
132 EXPECT_NO_THROW(method
->processFrame(0, &frame
));
134 EXPECT_TRUE(frame
.bAtoms
);
135 EXPECT_NE(frame
.atoms
, nullptr);
138 TEST_F(SetAtomsTest
, ThrowsOnRequiredAtomsNotAvailable
)
141 clear_trxframe(&frame
, true);
143 frame
.bAtoms
= false;
144 frame
.atoms
= nullptr;
146 SetAtoms
* method
= setAtoms(ChangeAtomsType::Always
, false);
147 EXPECT_THROW(method
->processFrame(0, &frame
), InconsistentInputError
);
150 TEST_F(SetAtomsTest
, WillUseOldAtomsWhenNoNewAvailable
)
153 clear_trxframe(&frame
, true);
156 frame
.atoms
= getAtomsCopy();
158 EXPECT_NE(frame
.atoms
, nullptr);
160 SetAtoms
* method
= setAtoms(ChangeAtomsType::Always
, false);
161 EXPECT_NO_THROW(method
->processFrame(0, &frame
));
164 TEST_F(SetAtomsTest
, ThrowsWhenUserAtomReplacementNotPossible
)
167 clear_trxframe(&frame
, true);
170 frame
.atoms
= getAtomsCopy();
172 EXPECT_NE(frame
.atoms
, nullptr);
174 SetAtoms
* method
= setAtoms(ChangeAtomsType::AlwaysFromStructure
, false);
175 EXPECT_THROW(method
->processFrame(0, &frame
), InconsistentInputError
);