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),
91 nbfp.getC6(atom1.name(), atom2.name()),
92 gmx::test::defaultRealTolerance());
94 EXPECT_REAL_EQ_TOL(std::sqrt(c6_1 * c6_2),
95 nbfp.getC6(atom2.name(), atom1.name()),
96 gmx::test::defaultRealTolerance());
98 //! geometric comb rule for c12
99 EXPECT_REAL_EQ_TOL(std::sqrt(c12_1 * c12_2),
100 nbfp.getC12(atom1.name(), atom2.name()),
101 gmx::test::defaultRealTolerance());
104 EXPECT_REAL_EQ_TOL(std::sqrt(c12_1 * c12_2),
105 nbfp.getC12(atom2.name(), atom1.name()),
106 gmx::test::defaultRealTolerance());
108 //! explicit pairwise interaction c6
109 EXPECT_REAL_EQ_TOL(c6comb, nbfp.getC6(atom2.name(), atom3.name()), gmx::test::defaultRealTolerance());
110 EXPECT_REAL_EQ_TOL(c6comb, nbfp.getC6(atom3.name(), atom2.name()), gmx::test::defaultRealTolerance());
112 //! explicit pairwise interaction c12
114 c12comb, nbfp.getC12(atom2.name(), atom3.name()), gmx::test::defaultRealTolerance());
116 c12comb, nbfp.getC12(atom3.name(), atom2.name()), gmx::test::defaultRealTolerance());
118 ParticleType atom4(ParticleTypeName("a4"), Mass(1));
119 interactions.add(atom3.name(), atom4.name(), C6(1), C12(2));
120 //! need to have self-interaction for all particles
121 EXPECT_THROW(auto interactionsTable = interactions.generateTable(), InputException);
124 TEST(NBlibTest, CanMergeInteractions)
126 ParticleType atom1(ParticleTypeName("a1"), Mass(1));
127 ParticleType atom2(ParticleTypeName("a2"), Mass(1));
128 ParticleType atom3(ParticleTypeName("a3"), Mass(1));
130 ParticleTypesInteractions interactions;
133 auto c12_1 = C12(1.12);
137 C12 c12_3 = C12(3.12);
139 auto c6comb = C6{ 40 };
140 auto c12comb = C12{ 41 };
142 interactions.add(atom1.name(), c6_1, c12_1);
143 interactions.add(atom2.name(), c6_2, c12_2);
144 interactions.add(atom3.name(), c6_3, c12_3);
145 interactions.add(atom2.name(), atom3.name(), c6comb, c12comb);
147 ParticleType atom4(ParticleTypeName("a4"), Mass(1));
148 ParticleType atom5(ParticleTypeName("a5"), Mass(1));
149 auto c6_4 = C6{ 4.6 };
150 auto c12_4 = C12{ 4.12 };
155 C6 c6_override = C6(45.6);
156 C12 c12_override = C12(45.12);
158 ParticleTypesInteractions otherInteractions;
159 otherInteractions.add(atom4.name(), c6_4, c12_4);
160 otherInteractions.add(atom5.name(), c6_5, c12_5);
161 otherInteractions.add(atom4.name(), atom5.name(), c6_override, c12_override);
163 interactions.merge(otherInteractions);
165 auto nbfp = interactions.generateTable();
167 EXPECT_REAL_EQ_TOL(std::sqrt(c6_3 * c6_4),
168 nbfp.getC6(atom3.name(), atom4.name()),
169 gmx::test::defaultRealTolerance());
170 EXPECT_REAL_EQ_TOL(std::sqrt(c12_3 * c12_4),
171 nbfp.getC12(atom3.name(), atom4.name()),
172 gmx::test::defaultRealTolerance());
174 c6_override, nbfp.getC6(atom4.name(), atom5.name()), gmx::test::defaultRealTolerance());
176 c12_override, nbfp.getC12(atom4.name(), atom5.name()), gmx::test::defaultRealTolerance());