Remove unused thole polarization rfac parameter
[alexxy/gromacs.git] / src / gromacs / topology / idef.h
index 269d531fc0380b7a7fa022e4f0ff0cf22ecee8c9..60cf6bee0e122ce330e3cd199655bf9be1552800 100644 (file)
@@ -3,7 +3,8 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2018 by the GROMACS development team.
+ * Copyright (c) 2019,2020,2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include "gromacs/math/vectypes.h"
 #include "gromacs/topology/ifunc.h"
-#include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/real.h"
 
-typedef union t_iparams {
+struct gmx_ffparams_t;
+
+typedef union t_iparams
+{
     /* Some parameters have A and B values for free energy calculations.
      * The B values are not used for regular simulations of course.
      * Free Energy for nonbondeds can be computed by changing the atom type.
@@ -109,7 +112,7 @@ typedef union t_iparams {
     } wpol;
     struct
     {
-        real a, alpha1, alpha2, rfac;
+        real a, alpha1, alpha2;
     } thole;
     struct
     {
@@ -219,7 +222,44 @@ typedef int t_functype;
 struct InteractionList
 {
     /* Returns the total number of elements in iatoms */
-    int size() const { return gmx::ssize(iatoms); }
+    int size() const { return static_cast<int>(iatoms.size()); }
+
+    /* Returns whether the list is empty */
+    bool empty() const { return iatoms.empty(); }
+
+    /* Adds one interaction to the list */
+    template<std::size_t numAtoms>
+    void push_back(const int parameterType, const std::array<int, numAtoms>& atoms)
+    {
+        const std::size_t oldSize = iatoms.size();
+        iatoms.resize(iatoms.size() + 1 + numAtoms);
+        iatoms[oldSize] = parameterType;
+        for (std::size_t i = 0; i < numAtoms; i++)
+        {
+            iatoms[oldSize + 1 + i] = atoms[i];
+        }
+    }
+
+    /* Adds one interaction to the list */
+    void push_back(const int parameterType, const int numAtoms, const int* atoms)
+    {
+        const std::size_t oldSize = iatoms.size();
+        iatoms.resize(iatoms.size() + 1 + numAtoms);
+        iatoms[oldSize] = parameterType;
+        for (int i = 0; i < numAtoms; i++)
+        {
+            iatoms[oldSize + 1 + i] = atoms[i];
+        }
+    }
+
+    /* Appends \p ilist at the back of the list */
+    void append(const InteractionList& ilist)
+    {
+        iatoms.insert(iatoms.end(), ilist.iatoms.begin(), ilist.iatoms.end());
+    }
+
+    /* Clears the list */
+    void clear() { iatoms.clear(); }
 
     /* List of interactions, see explanation further down */
     std::vector<int> iatoms;
@@ -229,31 +269,23 @@ struct InteractionList
  *
  * TODO: Consider only including entries in use instead of all F_NRE
  */
-typedef std::array<InteractionList, F_NRE> InteractionLists;
+using InteractionLists = std::array<InteractionList, F_NRE>;
 
-/* Deprecated list of listed interactions.
- *
- * The nonperturbed/perturbed interactions are now separated (sorted) in the
- * ilist, such that the first 0..(nr_nonperturbed-1) ones are exactly that, and
- * the remaining ones from nr_nonperturbed..(nr-1) are perturbed bonded
- * interactions.
- */
+/* Deprecated list of listed interactions */
 struct t_ilist
 {
     /* Returns the total number of elements in iatoms */
     int size() const { return nr; }
 
+    /* Returns whether the list is empty */
+    bool empty() const { return nr == 0; }
+
     int      nr;
     t_iatom* iatoms;
     int      nalloc;
 };
 
-/* TODO: Replace t_ilist in gmx_localtop_t by InteractionList.
- *       The nr_nonperturbed functionality needs to be ported.
- *       Remove t_topology.
- *       Remove t_ilist and remove templating on list type
- *       in mshift.cpp, constr.cpp, vsite.cpp and domdec_topology.cpp.
- */
+/* TODO: Remove t_ilist and remove templating on list type in mshift.cpp */
 
 /*
  * The structs InteractionList and t_ilist defines a list of atoms with their interactions.
@@ -294,7 +326,7 @@ static inline std::vector<InteractionListHandle> extractILists(const Interaction
     std::vector<InteractionListHandle> handles;
     for (size_t ftype = 0; ftype < ilists.size(); ftype++)
     {
-        if ((interaction_function[ftype].flags & flags) && ilists[ftype].size() > 0)
+        if ((interaction_function[ftype].flags & flags) && !ilists[ftype].empty())
         {
             handles.push_back({ static_cast<int>(ftype), ilists[ftype].iatoms });
         }
@@ -328,26 +360,57 @@ enum
 {
     ilsortUNKNOWN,
     ilsortNO_FE,
-    ilsortFE_UNSORTED,
     ilsortFE_SORTED
 };
 
-typedef struct t_idef
+/* Struct with list of interaction parameters and lists of interactions
+ *
+ * TODO: Convert to a proper class with private data members so we can
+ * ensure that the free-energy sorting and sorting setting is consistent.
+ */
+class InteractionDefinitions
+{
+public:
+    /* Constructor
+     *
+     * \param[in] ffparams  The interaction parameters, the lifetime of the created object should not exceed the lifetime of the passed parameters
+     */
+    InteractionDefinitions(const gmx_ffparams_t& ffparams);
+
+    // Clears data not read in from ffparams
+    void clear();
+
+    // The interaction parameters
+    const std::vector<t_iparams>& iparams;
+    // The function type per type
+    const std::vector<int>& functype;
+    // Position restraint interaction parameters
+    std::vector<t_iparams> iparams_posres;
+    // Flat-bottomed position restraint parameters
+    std::vector<t_iparams> iparams_fbposres;
+    // The list of interactions for each type. Note that some, such as LJ and COUL will have 0 entries.
+    std::array<InteractionList, F_NRE> il;
+    /* The number of non-perturbed interactions at the start of each entry in il */
+    std::array<int, F_NRE> numNonperturbedInteractions;
+    // The sorting state of interaction in il
+    int ilsort = ilsortUNKNOWN;
+    // The dihedral correction maps
+    gmx_cmap_t cmap_grid;
+};
+
+/* Deprecated interation definitions, used in t_topology */
+struct t_idef
 {
     int         ntypes;
     int         atnr;
     t_functype* functype;
     t_iparams*  iparams;
     real        fudgeQQ;
-    gmx_cmap_t* cmap_grid;
     t_iparams * iparams_posres, *iparams_fbposres;
-    int         iparams_posres_nalloc, iparams_fbposres_nalloc;
 
     t_ilist il[F_NRE];
-    /* The number of non-perturbed interactions at the start of each entry in il */
-    int numNonperturbedInteractions[F_NRE];
-    int ilsort;
-} t_idef;
+    int     ilsort;
+};
 
 /*
  * The struct t_idef defines all the interactions for the complete
@@ -395,10 +458,10 @@ void pr_ilist(FILE*                  fp,
               const char*            title,
               const t_functype*      functype,
               const InteractionList& ilist,
-              gmx_bool               bShowNumbers,
-              gmx_bool               bShowParameters,
+              bool                   bShowNumbers,
+              bool                   bShowParameters,
               const t_iparams*       iparams);
-void pr_idef(FILE* fp, int indent, const char* title, const t_idef* idef, gmx_bool bShowNumbers, gmx_bool bShowParameters);
+void pr_idef(FILE* fp, int indent, const char* title, const t_idef* idef, bool bShowNumbers, bool bShowParameters);
 
 /*! \brief
  * Properly initialize idef struct.
@@ -414,6 +477,4 @@ void init_idef(t_idef* idef);
  */
 void done_idef(t_idef* idef);
 
-void copy_ilist(const t_ilist* src, t_ilist* dst);
-
 #endif