ef241c716bdc0bfde59bbbbd4c6589192be8afa2
[alexxy/gromacs.git] / src / gromacs / mdlib / mdatoms.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
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, 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.
11  *
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.
16  *
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.
21  *
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.
26  *
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.
34  *
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.
37  */
38 #ifndef GMX_MDLIB_MDATOMS_H
39 #define GMX_MDLIB_MDATOMS_H
40
41 #include <cstdio>
42
43 #include <memory>
44 #include <vector>
45
46 #include "gromacs/gpu_utils/hostallocator.h"
47 #include "gromacs/mdtypes/mdatom.h"
48 #include "gromacs/utility/basedefinitions.h"
49 #include "gromacs/utility/real.h"
50 #include "gromacs/utility/unique_cptr.h"
51
52 struct gmx_mtop_t;
53 struct t_inputrec;
54
55 namespace gmx
56 {
57
58 /*! \libinternal
59  * \brief Contains a C-style t_mdatoms while managing some of its
60  * memory with C++ vectors with allocators.
61  *
62  * \todo The group-scheme kernels needed a plain C-style t_mdatoms, so
63  * this type combines that with the memory management needed for
64  * efficient PME on GPU transfers. The mdatoms_ member should be
65  * removed. */
66 class MDAtoms
67 {
68     //! C-style mdatoms struct.
69     unique_cptr<t_mdatoms> mdatoms_;
70     //! Memory for chargeA that can be set up for efficient GPU transfer.
71     gmx::PaddedHostVector<real> chargeA_;
72
73 public:
74     // TODO make this private
75     MDAtoms();
76     ~MDAtoms();
77     //! Getter.
78     t_mdatoms* mdatoms() { return mdatoms_.get(); }
79     //! Const getter.
80     const t_mdatoms* mdatoms() const { return mdatoms_.get(); }
81     /*! \brief Resizes memory.
82      *
83      * \throws std::bad_alloc  If out of memory.
84      */
85     void resize(int newSize);
86     /*! \brief Reserves memory.
87      *
88      * \throws std::bad_alloc  If out of memory.
89      */
90     void reserve(int newCapacity);
91     //! Builder function.
92     friend std::unique_ptr<MDAtoms>
93     makeMDAtoms(FILE* fp, const gmx_mtop_t& mtop, const t_inputrec& ir, bool rankHasPmeGpuTask);
94 };
95
96 //! Builder function for MdAtomsWrapper.
97 std::unique_ptr<MDAtoms> makeMDAtoms(FILE* fp, const gmx_mtop_t& mtop, const t_inputrec& ir, bool useGpuForPme);
98
99 } // namespace gmx
100
101 void atoms2md(const gmx_mtop_t* mtop,
102               const t_inputrec* ir,
103               int               nindex,
104               const int*        index,
105               int               homenr,
106               gmx::MDAtoms*     mdAtoms);
107 /* This routine copies the atoms->atom struct into md.
108  * If index!=NULL only the indexed atoms are copied.
109  * For the masses the A-state (lambda=0) mass is used.
110  * Sets md->lambda = 0.
111  * In free-energy runs, update_mdatoms() should be called after atoms2md()
112  * to set the masses corresponding to the value of lambda at each step.
113  */
114
115 void update_mdatoms(t_mdatoms* md, real lambda);
116 /* When necessary, sets all the mass parameters to values corresponding
117  * to the free-energy parameter lambda.
118  * Sets md->lambda = lambda.
119  */
120
121 #endif