2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 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.
37 * This implements molecule setup tests
39 * \author Victor Holanda <victor.holanda@cscs.ch>
40 * \author Joe Jordan <ejjordan@kth.se>
41 * \author Prashanth Kanduri <kanduri@cscs.ch>
42 * \author Sebastian Keller <keller@cscs.ch>
43 * \author Artem Zhmurov <zhmurov@gmail.com>
45 #include "nblib/interactions.h"
46 #include "nblib/exception.h"
47 #include "nblib/particletype.h"
48 #include "nblib/tests/testsystems.h"
50 #include "testutils/testasserts.h"
59 TEST(NBlibTest, NonBondedForceParamsCorrect)
61 ParticleType atom1(ParticleTypeName("a1"), Mass(1));
62 ParticleType atom2(ParticleTypeName("a2"), Mass(1));
63 ParticleType atom3(ParticleTypeName("a3"), Mass(1));
65 ParticleTypesInteractions interactions;
68 auto c12_1 = C12(1.12);
72 C12 c12_3 = C12(3.12);
74 auto c6comb = C6{ 40 };
75 auto c12comb = C12{ 41 };
77 interactions.add(atom1.name(), c6_1, c12_1);
78 interactions.add(atom2.name(), c6_2, c12_2);
79 interactions.add(atom3.name(), c6_3, c12_3);
80 interactions.add(atom2.name(), atom3.name(), c6comb, c12comb);
82 auto nbfp = interactions.generateTable();
84 //! self interaction for c6
85 EXPECT_REAL_EQ_TOL(c6_1, nbfp.getC6(atom1.name(), atom1.name()), gmx::test::defaultRealTolerance());
87 EXPECT_REAL_EQ_TOL(c12_1, nbfp.getC12(atom1.name(), atom1.name()), gmx::test::defaultRealTolerance());
89 //! geometric comb rule for c6
90 EXPECT_REAL_EQ_TOL(std::sqrt(c6_1 * c6_2), nbfp.getC6(atom1.name(), atom2.name()),
91 gmx::test::defaultRealTolerance());
93 EXPECT_REAL_EQ_TOL(std::sqrt(c6_1 * c6_2), nbfp.getC6(atom2.name(), atom1.name()),
94 gmx::test::defaultRealTolerance());
96 //! geometric comb rule for c12
97 EXPECT_REAL_EQ_TOL(std::sqrt(c12_1 * c12_2), nbfp.getC12(atom1.name(), atom2.name()),
98 gmx::test::defaultRealTolerance());
101 EXPECT_REAL_EQ_TOL(std::sqrt(c12_1 * c12_2), nbfp.getC12(atom2.name(), atom1.name()),
102 gmx::test::defaultRealTolerance());
104 //! explicit pairwise interaction c6
105 EXPECT_REAL_EQ_TOL(c6comb, nbfp.getC6(atom2.name(), atom3.name()), gmx::test::defaultRealTolerance());
106 EXPECT_REAL_EQ_TOL(c6comb, nbfp.getC6(atom3.name(), atom2.name()), gmx::test::defaultRealTolerance());
108 //! explicit pairwise interaction c12
109 EXPECT_REAL_EQ_TOL(c12comb, nbfp.getC12(atom2.name(), atom3.name()),
110 gmx::test::defaultRealTolerance());
111 EXPECT_REAL_EQ_TOL(c12comb, nbfp.getC12(atom3.name(), atom2.name()),
112 gmx::test::defaultRealTolerance());
114 ParticleType atom4(ParticleTypeName("a4"), Mass(1));
115 interactions.add(atom3.name(), atom4.name(), C6(1), C12(2));
116 //! need to have self-interaction for all particles
117 EXPECT_THROW(auto interactionsTable = interactions.generateTable(), InputException);
120 TEST(NBlibTest, CanMergeInteractions)
122 ParticleType atom1(ParticleTypeName("a1"), Mass(1));
123 ParticleType atom2(ParticleTypeName("a2"), Mass(1));
124 ParticleType atom3(ParticleTypeName("a3"), Mass(1));
126 ParticleTypesInteractions interactions;
129 auto c12_1 = C12(1.12);
133 C12 c12_3 = C12(3.12);
135 auto c6comb = C6{ 40 };
136 auto c12comb = C12{ 41 };
138 interactions.add(atom1.name(), c6_1, c12_1);
139 interactions.add(atom2.name(), c6_2, c12_2);
140 interactions.add(atom3.name(), c6_3, c12_3);
141 interactions.add(atom2.name(), atom3.name(), c6comb, c12comb);
143 ParticleType atom4(ParticleTypeName("a4"), Mass(1));
144 ParticleType atom5(ParticleTypeName("a5"), Mass(1));
145 auto c6_4 = C6{ 4.6 };
146 auto c12_4 = C12{ 4.12 };
151 C6 c6_override = C6(45.6);
152 C12 c12_override = C12(45.12);
154 ParticleTypesInteractions otherInteractions;
155 otherInteractions.add(atom4.name(), c6_4, c12_4);
156 otherInteractions.add(atom5.name(), c6_5, c12_5);
157 otherInteractions.add(atom4.name(), atom5.name(), c6_override, c12_override);
159 interactions.merge(otherInteractions);
161 auto nbfp = interactions.generateTable();
163 EXPECT_REAL_EQ_TOL(std::sqrt(c6_3 * c6_4), nbfp.getC6(atom3.name(), atom4.name()),
164 gmx::test::defaultRealTolerance());
165 EXPECT_REAL_EQ_TOL(std::sqrt(c12_3 * c12_4), nbfp.getC12(atom3.name(), atom4.name()),
166 gmx::test::defaultRealTolerance());
167 EXPECT_REAL_EQ_TOL(c6_override, nbfp.getC6(atom4.name(), atom5.name()),
168 gmx::test::defaultRealTolerance());
169 EXPECT_REAL_EQ_TOL(c12_override, nbfp.getC12(atom4.name(), atom5.name()),
170 gmx::test::defaultRealTolerance());