Save excluded non-bonded interactions in .tpr file
authorChristian Blau <cblau@gwdg.de>
Tue, 18 Feb 2020 12:47:41 +0000 (13:47 +0100)
committerPaul Bauer <paul.bauer.q@gmail.com>
Wed, 4 Mar 2020 10:08:36 +0000 (11:08 +0100)
The intermolecularExclusionGroup of the molecular topology (mtop) has
not been saved in the tpr file before, which lead to the unexpected
behviour that an mtop as set up in grompp was not available in the same
state when the simulation was started.

Excluding non-bonded interactions of a group with the rest of the system
is currently needed for the QM/MM implementation. This change will allow
to complete system setup for simulations that need to exclude non-bonded
interactions at grompp time instead when starting the simulation.

refs #3172

Change-Id: Ia0e3f0571fa467337664bedec2e91a5a008507ca

src/gromacs/fileio/tpxio.cpp

index 301d07bb576cbaee3cc1be876f4381d70e4bed8d..4266291098ce20370e74817d7b8f17b4f2daf27e 100644 (file)
@@ -130,7 +130,8 @@ enum tpxv
     tpxv_GenericInternalParameters, /**< Added internal parameters for mdrun modules*/
     tpxv_VSite2FD,                  /**< Added 2FD type virtual site */
     tpxv_AddSizeField, /**< Added field with information about the size of the serialized tpr file in bytes, excluding the header */
-    tpxv_Count         /**< the total number of tpxv versions */
+    tpxv_StoreNonBondedInteractionExclusionGroup, /**< Store the non bonded interaction exclusion group in the topology */
+    tpxv_Count                                    /**< the total number of tpxv versions */
 };
 
 /*! \brief Version number of the file format written to run input
@@ -2590,6 +2591,18 @@ static void do_mtop(gmx::ISerializer* serializer, gmx_mtop_t* mtop, int file_ver
 
     mtop->haveMoleculeIndices = true;
 
+    if (file_version >= tpxv_StoreNonBondedInteractionExclusionGroup)
+    {
+        std::int64_t intermolecularExclusionGroupSize = gmx::ssize(mtop->intermolecularExclusionGroup);
+        serializer->doInt64(&intermolecularExclusionGroupSize);
+        GMX_RELEASE_ASSERT(intermolecularExclusionGroupSize >= 0,
+                           "Number of atoms with excluded intermolecular non-bonded interactions "
+                           "is negative.");
+        mtop->intermolecularExclusionGroup.resize(intermolecularExclusionGroupSize); // no effect when writing
+        serializer->doIntArray(mtop->intermolecularExclusionGroup.data(),
+                               mtop->intermolecularExclusionGroup.size());
+    }
+
     if (serializer->reading())
     {
         close_symtab(&(mtop->symtab));