beb75a2a632fefad343e7fc3b9238805fa5fdb85
[alexxy/gromacs.git] / api / nblib / listed_forces / definitions.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2020,2021, 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.
8  *
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.
13  *
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.
18  *
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.
23  *
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.
31  *
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.
34  */
35 /*! \inpublicapi \file
36  * \brief
37  * Definitions for supported nblib listed interaction data, such as bonds, angles, dihedrals, etc
38  *
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>
44  */
45 #ifndef NBLIB_LISTEDFORCES_DEFINITIONS_H
46 #define NBLIB_LISTEDFORCES_DEFINITIONS_H
47
48 #include <variant>
49
50 #include "nblib/util/traits.hpp"
51 #include "bondtypes.h"
52
53 namespace nblib
54 {
55
56 //***********************************************************************************
57
58 /*! \brief These type lists define what interaction types are supported in
59  *  -Molecule
60  *  -Topology
61  *  -ListedForceCalculator
62  *
63  *  To enable force calculation for your new interaction type that you've added to bondtypes.h,
64  *  list your new type here under the appropriate category and make sure that you've added
65  *  a kernel in kernels.hpp
66  */
67
68 using SupportedTwoCenterTypes =
69         TypeList<HarmonicBondType, G96BondType, CubicBondType, FENEBondType, HalfAttractiveQuarticBondType>;
70 using SupportedThreeCenterTypes = TypeList<HarmonicAngle>;
71 using SupportedFourCenterTypes = TypeList<ProperDihedral, ImproperDihedral, RyckaertBellemanDihedral>;
72 using SupportedFiveCenterTypes = TypeList<Default5Center>;
73
74 //***********************************************************************************
75
76 using SupportedListedTypes =
77         Fuse<SupportedTwoCenterTypes, SupportedThreeCenterTypes, SupportedFourCenterTypes, SupportedFiveCenterTypes>;
78
79 //! \brief meta function to map from an Interaction type to the number of interaction centers
80 template<class Interaction, class = void>
81 struct NCenter
82 {
83 };
84
85 //! \brief meta function return value for two-center interactions
86 template<class Interaction>
87 struct NCenter<Interaction, std::enable_if_t<Contains<Interaction, SupportedTwoCenterTypes>{}>> :
88     std::integral_constant<std::size_t, 2>
89 {
90 };
91
92 //! \brief meta function return value for three-center interactions
93 template<class Interaction>
94 struct NCenter<Interaction, std::enable_if_t<Contains<Interaction, SupportedThreeCenterTypes>{}>> :
95     std::integral_constant<std::size_t, 3>
96 {
97 };
98
99 //! \brief meta function return value for four-center interactions
100 template<class Interaction>
101 struct NCenter<Interaction, std::enable_if_t<Contains<Interaction, SupportedFourCenterTypes>{}>> :
102     std::integral_constant<std::size_t, 4>
103 {
104 };
105
106 //! \brief meta function return value for five-center interactions
107 template<class Interaction>
108 struct NCenter<Interaction, std::enable_if_t<Contains<Interaction, SupportedFiveCenterTypes>{}>> :
109     std::integral_constant<std::size_t, 5>
110 {
111 };
112
113 template<size_t N>
114 using IndexArray = std::array<int, N>;
115
116 /*! \brief encodes the number of integers needed to represent N-center interactions
117  *
118  *  number of indices to store is the the number of interaction center
119  *  plus 1 index for the interaction parameter lookup
120  */
121 template<class Interaction>
122 using InteractionIndex = IndexArray<NCenter<Interaction>{} + 1>;
123
124 // same as InteractionIndex, but just the coordinate indices
125 template<class Interaction>
126 using CoordinateIndex = IndexArray<NCenter<Interaction>{}>;
127
128 //! \brief container data type for listed interactions
129 template<class InteractionType>
130 struct ListedTypeData
131 {
132     using type = InteractionType;
133
134     // tuple format: <particleID i, particleID j, ..., InteractionInstanceIndex>
135     std::vector<InteractionIndex<InteractionType>> indices;
136     // vector of unique TwoCenterType instances
137     std::vector<InteractionType> parameters;
138 };
139
140 using TwoCenterInteraction   = Reduce<std::variant, SupportedTwoCenterTypes>;
141 using ThreeCenterInteraction = Reduce<std::variant, SupportedThreeCenterTypes>;
142 using FourCenterInteraction  = Reduce<std::variant, SupportedFourCenterTypes>;
143 using FiveCenterInteraction  = Reduce<std::variant, SupportedFiveCenterTypes>;
144
145 //! This is the complete type that holds all listed interaction data
146 // result: std::tuple<ListedTypeData<SupportedListedType1>, ...>
147 using ListedInteractionData = Reduce<std::tuple, Map<ListedTypeData, SupportedListedTypes>>;
148
149 } // namespace nblib
150
151 #endif // NBLIB_LISTEDFORCES_DEFINITIONS_H