2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2010,2014,2015,2016,2017 by the GROMACS development team.
7 * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by
8 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
9 * and including many others, as listed in the AUTHORS file in the
10 * top-level source directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
38 #ifndef GMX_MDLIB_MDATOMS_H
39 #define GMX_MDLIB_MDATOMS_H
46 #include "gromacs/gpu_utils/hostallocator.h"
47 #include "gromacs/utility/real.h"
48 #include "gromacs/utility/unique_cptr.h"
58 * \brief Contains a C-style t_mdatoms while managing some of its
59 * memory with C++ vectors with allocators.
61 * \todo The group-scheme kernels needed a plain C-style t_mdatoms, so
62 * this type combines that with the memory management needed for
63 * efficient PME on GPU transfers. The mdatoms_ member should be
67 //! C-style mdatoms struct.
68 unique_cptr<t_mdatoms> mdatoms_;
69 //! Memory for chargeA that can be set up for efficient GPU transfer.
70 gmx::PaddedHostVector<real> chargeA_;
71 //! Memory for chargeB that can be set up for efficient GPU transfer.
72 gmx::PaddedHostVector<real> chargeB_;
75 // TODO make this private
79 t_mdatoms* mdatoms() { return mdatoms_.get(); }
81 const t_mdatoms* mdatoms() const { return mdatoms_.get(); }
82 /*! \brief Resizes memory for charges of FEP state A.
84 * \throws std::bad_alloc If out of memory.
86 void resizeChargeA(int newSize);
87 /*! \brief Resizes memory for charges of FEP state B.
89 * \throws std::bad_alloc If out of memory.
91 void resizeChargeB(int newSize);
92 /*! \brief Reserves memory for charges of FEP state A.
94 * \throws std::bad_alloc If out of memory.
96 void reserveChargeA(int newCapacity);
97 /*! \brief Reserves memory for charges of FEP state B.
99 * \throws std::bad_alloc If out of memory.
101 void reserveChargeB(int newCapacity);
102 //! Builder function.
103 friend std::unique_ptr<MDAtoms>
104 makeMDAtoms(FILE* fp, const gmx_mtop_t& mtop, const t_inputrec& ir, bool rankHasPmeGpuTask);
107 //! Builder function for MdAtomsWrapper.
108 std::unique_ptr<MDAtoms> makeMDAtoms(FILE* fp, const gmx_mtop_t& mtop, const t_inputrec& ir, bool useGpuForPme);
112 /*! \brief This routine copies the atoms->atom struct into md.
114 * \param[in] mtop The molecular topology.
115 * \param[in] inputrec The input record.
116 * \param[in] nindex If nindex>=0 we are doing DD.
117 * \param[in] index Lookup table for global atom index.
118 * \param[in] homenr Number of atoms on this processor.
119 * \param[inout] mdAtoms Data set up by this routine.
121 * If index!=NULL only the indexed atoms are copied.
122 * For the masses the A-state (lambda=0) mass is used.
123 * Sets md->lambda = 0.
124 * In free-energy runs, update_mdatoms() should be called after atoms2md()
125 * to set the masses corresponding to the value of lambda at each step.
127 void atoms2md(const gmx_mtop_t& mtop,
128 const t_inputrec& inputrec,
130 gmx::ArrayRef<int> index,
132 gmx::MDAtoms* mdAtoms);
134 void update_mdatoms(t_mdatoms* md, real lambda);
135 /* When necessary, sets all the mass parameters to values corresponding
136 * to the free-energy parameter lambda.
137 * Sets md->lambda = lambda.