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 * This file defines functions for setting up a benchmark system
40 * \author Berk Hess <hess@kth.se>
41 * \ingroup module_nbnxm
46 #include "bench_system.h"
50 #include "gromacs/math/vec.h"
51 #include "gromacs/mdlib/dispersioncorrection.h"
52 #include "gromacs/mdtypes/forcerec.h"
53 #include "gromacs/nbnxm/nbnxm.h"
54 #include "gromacs/pbcutil/ishift.h"
55 #include "gromacs/pbcutil/pbc.h"
56 #include "gromacs/utility/fatalerror.h"
58 #include "bench_coords.h"
66 // A 3-site water model
67 //! The number of atoms in a molecule
68 constexpr int numAtomsInMolecule = 3;
69 //! The atom type of the oxygen atom
70 constexpr int typeOxygen = 0;
71 //! The atom type of the hydrogen atom
72 constexpr int typeHydrogen = 1;
73 //! The charge of the oxygen atom
74 constexpr real chargeOxygen = -0.8476;
75 //! The charge of the hydrogen atom
76 constexpr real chargeHydrogen = 0.4238;
77 //! The LJ C6 parameter of the Oxygen atom
78 constexpr real c6Oxygen = 0.0026173456;
79 //! The LJ C12 parameter of the Oxygen atom
80 constexpr real c12Oxygen = 2.634129e-06;
81 // Note that the hydrogen has LJ parameters all zero
85 //! Generates coordinates and a box for the base system scaled by \p multiplicationFactor
87 // The parameter \p multiplicationFactor should be a power of 2.
88 // A fatal error is generated when this is not the case.
89 static void generateCoordinates(int multiplicationFactor, std::vector<gmx::RVec>* coordinates, matrix box)
91 if (multiplicationFactor < 1 || (multiplicationFactor & (multiplicationFactor - 1)) != 0)
93 gmx_fatal(FARGS, "The size factor has to be a power of 2");
96 if (multiplicationFactor == 1)
98 *coordinates = coordinates1000;
99 copy_mat(box1000, box);
104 ivec factors = { 1, 1, 1 };
107 while (multiplicationFactor > 1)
110 multiplicationFactor /= 2;
117 printf("Stacking a box of %zu atoms %d x %d x %d times\n", coordinates1000.size(), factors[XX],
118 factors[YY], factors[ZZ]);
120 coordinates->resize(factors[XX] * factors[YY] * factors[ZZ] * coordinates1000.size());
124 for (int x = 0; x < factors[XX]; x++)
126 shift[XX] = x * box1000[XX][XX];
127 for (int y = 0; y < factors[YY]; y++)
129 shift[YY] = y * box1000[YY][YY];
130 for (int z = 0; z < factors[ZZ]; z++)
132 shift[ZZ] = z * box1000[ZZ][ZZ];
134 for (const gmx::RVec& coordOrig : coordinates1000)
136 (*coordinates)[i] = coordOrig + shift;
143 for (int d1 = 0; d1 < DIM; d1++)
145 for (int d2 = 0; d2 < DIM; d2++)
147 box[d1][d2] = factors[d1] * box1000[d1][d2];
152 BenchmarkSystem::BenchmarkSystem(const int multiplicationFactor)
155 nonbondedParameters.resize(numAtomTypes * numAtomTypes * 2, 0);
156 nonbondedParameters[0] = c6Oxygen;
157 nonbondedParameters[1] = c12Oxygen;
159 generateCoordinates(multiplicationFactor, &coordinates, box);
160 put_atoms_in_box(epbcXYZ, box, coordinates);
162 int numAtoms = coordinates.size();
163 GMX_RELEASE_ASSERT(numAtoms % numAtomsInMolecule == 0,
164 "Coordinates should match whole molecules");
166 atomTypes.resize(numAtoms);
167 charges.resize(numAtoms);
168 atomInfoAllVdw.resize(numAtoms);
169 atomInfoOxygenVdw.resize(numAtoms);
170 snew(excls.index, numAtoms + 1);
171 snew(excls.a, numAtoms * numAtomsInMolecule);
174 for (int a = 0; a < numAtoms; a++)
176 if (a % numAtomsInMolecule == 0)
179 atomTypes[a] = typeOxygen;
180 charges[a] = chargeOxygen;
181 SET_CGINFO_HAS_VDW(atomInfoAllVdw[a]);
182 SET_CGINFO_HAS_VDW(atomInfoOxygenVdw[a]);
187 atomTypes[a] = typeHydrogen;
188 charges[a] = chargeHydrogen;
189 SET_CGINFO_HAS_VDW(atomInfoAllVdw[a]);
191 SET_CGINFO_HAS_Q(atomInfoAllVdw[a]);
192 SET_CGINFO_HAS_Q(atomInfoOxygenVdw[a]);
194 const int firstAtomInMolecule = a - (a % numAtomsInMolecule);
195 for (int aj = 0; aj < numAtomsInMolecule; aj++)
197 excls.a[a * numAtomsInMolecule + aj] = firstAtomInMolecule + aj;
199 excls.index[a + 1] = (a + 1) * numAtomsInMolecule;
202 forceRec.ntype = numAtomTypes;
203 forceRec.nbfp = nonbondedParameters;
204 snew(forceRec.shift_vec, SHIFTS);
205 calc_shifts(box, forceRec.shift_vec);