Moved pbc/cut-off related utilities from typedefs to pbcutil
authorDavid van der Spoel <spoel@xray.bmc.uu.se>
Wed, 14 Oct 2015 17:44:57 +0000 (19:44 +0200)
committerDavid van der Spoel <davidvanderspoel@gmail.com>
Sun, 18 Oct 2015 16:35:22 +0000 (18:35 +0200)
Change-Id: I0bf5e6e2221d8106ba3022c6b555c7098cfbacc6

12 files changed:
src/gromacs/fileio/tpxio.cpp
src/gromacs/gmxana/gmx_tune_pme.cpp
src/gromacs/gmxlib/typedefs.cpp
src/gromacs/gmxpreprocess/grompp.cpp
src/gromacs/legacyheaders/typedefs.h
src/gromacs/legacyheaders/types/state.h
src/gromacs/math/utilities.cpp
src/gromacs/math/utilities.h
src/gromacs/mdlib/coupling.cpp
src/gromacs/mdlib/update.cpp
src/gromacs/pbcutil/boxutilities.cpp [new file with mode: 0644]
src/gromacs/pbcutil/boxutilities.h [new file with mode: 0644]

index 927f3a0a3a703dc499c7801cc058cdbe7efbf5c7..62060c6a76f33db2845f98b0d1d28fce5072ecb7 100644 (file)
@@ -54,6 +54,7 @@
 #include "gromacs/legacyheaders/typedefs.h"
 #include "gromacs/legacyheaders/types/ifunc.h"
 #include "gromacs/math/vec.h"
+#include "gromacs/pbcutil/boxutilities.h"
 #include "gromacs/topology/block.h"
 #include "gromacs/topology/mtop_util.h"
 #include "gromacs/topology/symtab.h"
index 687b0de3c6ec00187f10ed36e3d714d0648595bc..4994118ce12c883447bc1535ae333bcb8bf91561 100644 (file)
@@ -60,6 +60,7 @@
 #include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/mdlib/perf_est.h"
+#include "gromacs/pbcutil/pbc.h"
 #include "gromacs/timing/walltime_accounting.h"
 #include "gromacs/utility/arraysize.h"
 #include "gromacs/utility/baseversion.h"
index 674992cde8bd4e54619fb0a7d9d384adeb391462..262d200f529083dc8f92f8b2a071133370d32752 100644 (file)
@@ -321,68 +321,6 @@ t_state *serial_init_local_state(t_state *state_global)
     return state_local;
 }
 
-static void do_box_rel(t_inputrec *ir, matrix box_rel, matrix b, gmx_bool bInit)
-{
-    int d, d2;
-
-    for (d = YY; d <= ZZ; d++)
-    {
-        for (d2 = XX; d2 <= (ir->epct == epctSEMIISOTROPIC ? YY : ZZ); d2++)
-        {
-            /* We need to check if this box component is deformed
-             * or if deformation of another component might cause
-             * changes in this component due to box corrections.
-             */
-            if (ir->deform[d][d2] == 0 &&
-                !(d == ZZ && d2 == XX && ir->deform[d][YY] != 0 &&
-                  (b[YY][d2] != 0 || ir->deform[YY][d2] != 0)))
-            {
-                if (bInit)
-                {
-                    box_rel[d][d2] = b[d][d2]/b[XX][XX];
-                }
-                else
-                {
-                    b[d][d2] = b[XX][XX]*box_rel[d][d2];
-                }
-            }
-        }
-    }
-}
-
-void set_box_rel(t_inputrec *ir, t_state *state)
-{
-    /* Make sure the box obeys the restrictions before we fix the ratios */
-    correct_box(NULL, 0, state->box, NULL);
-
-    clear_mat(state->box_rel);
-
-    if (PRESERVE_SHAPE(*ir))
-    {
-        do_box_rel(ir, state->box_rel, state->box, TRUE);
-    }
-}
-
-void preserve_box_shape(t_inputrec *ir, matrix box_rel, matrix b)
-{
-    if (PRESERVE_SHAPE(*ir))
-    {
-        do_box_rel(ir, box_rel, b, FALSE);
-    }
-}
-
-real max_cutoff(real cutoff1, real cutoff2)
-{
-    if (cutoff1 == 0 || cutoff2 == 0)
-    {
-        return 0;
-    }
-    else
-    {
-        return std::max(cutoff1, cutoff2);
-    }
-}
-
 void init_df_history(df_history_t *dfhist, int nlambda)
 {
     int i;
index 95e756a0f80831de4cf6370e82a3d38241f16d89..0c620336fb698892882eb4afc24a0ab3e4264bc9 100644 (file)
@@ -76,6 +76,7 @@
 #include "gromacs/mdlib/calc_verletbuf.h"
 #include "gromacs/mdlib/compute_io.h"
 #include "gromacs/mdlib/perf_est.h"
+#include "gromacs/pbcutil/boxutilities.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/random/random.h"
 #include "gromacs/topology/mtop_util.h"
index baef0177537d40dbeb295d2d18040ae4fd3bcd2e..eb9c1b373d34680b7e8a7f4333144a8b450beb49 100644 (file)
@@ -72,15 +72,6 @@ void done_df_history(df_history_t *dfhist);
 void copy_df_history(df_history_t * df_dest, df_history_t *df_source);
 void done_state(t_state *state);
 
-void set_box_rel(struct t_inputrec *ir, t_state *state);
-/* Set state->box_rel used in mdrun to preserve the box shape */
-
-void preserve_box_shape(struct t_inputrec *ir, matrix box_rel, matrix b);
-/* Preserve the box shape, b can be box or boxv */
-
-real max_cutoff(real cutoff1, real cutoff2);
-/* Returns the maximum of the cut-off's, taking into account that 0=inf. */
-
 #ifdef __cplusplus
 }
 #endif
index a0299a4b84fafbed80c556f50d81bec4146283f4..2148850cc2a30fdd358aced2b3690f6d9ec7d105 100644 (file)
@@ -214,7 +214,7 @@ typedef struct
 swapstate_t;
 
 
-typedef struct
+typedef struct t_state
 {
     int              natoms;
     int              ngtc;
index aab8a36078403c773849f9cfc0acde0a7ce4d48e..941ac91f7f17de402f3d2d9fbd49d6d792f3d86d 100644 (file)
@@ -44,6 +44,9 @@
 #include <limits.h>
 
 #include <cmath>
+
+#include <algorithm>
+
 #ifdef GMX_NATIVE_WINDOWS
 // for _BitScanReverse()
 #include <intrin.h>
@@ -190,3 +193,15 @@ int gmx_feenableexcept()
     return -1;
 #endif
 }
+
+real max_cutoff(real cutoff1, real cutoff2)
+{
+    if (cutoff1 == 0 || cutoff2 == 0)
+    {
+        return 0;
+    }
+    else
+    {
+        return std::max(cutoff1, cutoff2);
+    }
+}
index 2f65fef687d9c7b35ea1534e7ff77cac161945dd..7752efe1a1e1538adaf5b6c9f9dd0420fe360c63 100644 (file)
@@ -149,6 +149,17 @@ gmx_greatest_common_divisor(int p, int q);
  */
 int gmx_feenableexcept();
 
+/*! \brief Return cut-off to use
+ *
+ * Takes the max of two cut-offs. However a cut-off of 0
+ * signifies that the cut-off in fact is infinite, and
+ * this requires this special routine.
+ * \param[in] cutoff1 The first cutoff (e.g. coulomb)
+ * \param[in] cutoff2 The second cutoff (e.g. vdw)
+ * \return 0 if either is 0, the normal max of the two otherwise.
+ */
+real max_cutoff(real cutoff1, real cutoff2);
+
 #ifdef __cplusplus
 }
 #endif
index ab3397e40d90472d2f863dd1812835c46cb7e0f3..c1c72f6b72cfab04b958a62a98da9a8808880742 100644 (file)
@@ -54,6 +54,7 @@
 #include "gromacs/mdlib/mdrun.h"
 #include "gromacs/mdlib/sim_util.h"
 #include "gromacs/mdlib/update.h"
+#include "gromacs/pbcutil/boxutilities.h"
 #include "gromacs/random/random.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
index 1ad0507bde364a94c76b751f78e6bf26bd5602fa..76ae56d714c34cdef17e60bf20eefa728be3209c 100644 (file)
@@ -60,6 +60,7 @@
 #include "gromacs/mdlib/mdrun.h"
 #include "gromacs/mdlib/sim_util.h"
 #include "gromacs/mdlib/tgroup.h"
+#include "gromacs/pbcutil/boxutilities.h"
 #include "gromacs/pbcutil/mshift.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/pulling/pull.h"
diff --git a/src/gromacs/pbcutil/boxutilities.cpp b/src/gromacs/pbcutil/boxutilities.cpp
new file mode 100644 (file)
index 0000000..2727408
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2015, 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.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \internal \file
+ * \brief
+ * Implements routines in boxutilities.h.
+ *
+ * Utility functions for handling boxes.
+ */
+#include "gmxpre.h"
+
+#include "boxutilities.h"
+
+#include <cmath>
+
+#include <algorithm>
+
+#include "gromacs/legacyheaders/types/inputrec.h"
+#include "gromacs/legacyheaders/types/state.h"
+#include "gromacs/math/vec.h"
+#include "gromacs/math/vectypes.h"
+#include "gromacs/pbcutil/pbc.h"
+#include "gromacs/utility/basedefinitions.h"
+#include "gromacs/utility/real.h"
+
+/*! \brief Change box components to preserve the relative box shape
+ *
+ * Change box components to box[XX][XX]*box_rel to preserve the relative box shape
+ */
+static void do_box_rel(t_inputrec *ir, matrix box_rel, matrix b, gmx_bool bInit)
+{
+    int d, d2;
+
+    for (d = YY; d <= ZZ; d++)
+    {
+        for (d2 = XX; d2 <= (ir->epct == epctSEMIISOTROPIC ? YY : ZZ); d2++)
+        {
+            /* We need to check if this box component is deformed
+             * or if deformation of another component might cause
+             * changes in this component due to box corrections.
+             */
+            if (ir->deform[d][d2] == 0 &&
+                !(d == ZZ && d2 == XX && ir->deform[d][YY] != 0 &&
+                  (b[YY][d2] != 0 || ir->deform[YY][d2] != 0)))
+            {
+                if (bInit)
+                {
+                    box_rel[d][d2] = b[d][d2]/b[XX][XX];
+                }
+                else
+                {
+                    b[d][d2] = b[XX][XX]*box_rel[d][d2];
+                }
+            }
+        }
+    }
+}
+
+void preserve_box_shape(t_inputrec *ir, matrix box_rel, matrix b)
+{
+    if (PRESERVE_SHAPE(*ir))
+    {
+        do_box_rel(ir, box_rel, b, FALSE);
+    }
+}
+
+void set_box_rel(t_inputrec *ir, t_state *state)
+{
+    /* Make sure the box obeys the restrictions before we fix the ratios */
+    correct_box(NULL, 0, state->box, NULL);
+
+    clear_mat(state->box_rel);
+
+    if (PRESERVE_SHAPE(*ir))
+    {
+        do_box_rel(ir, state->box_rel, state->box, TRUE);
+    }
+}
diff --git a/src/gromacs/pbcutil/boxutilities.h b/src/gromacs/pbcutil/boxutilities.h
new file mode 100644 (file)
index 0000000..5ee46ae
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2015, 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.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+#ifndef GMX_PBCUTIL_BOXUTILITIES_H
+#define GMX_PBCUTIL_BOXUTILITIES_H
+
+#include <stdio.h>
+
+#include "gromacs/legacyheaders/types/inputrec.h"
+#include "gromacs/math/vectypes.h"
+#include "gromacs/utility/basedefinitions.h"
+#include "gromacs/utility/real.h"
+
+struct t_state;
+
+/*! \brief Make sure the relative box shape remains the same
+ *
+ * This function ensures that the relative box dimensions are
+ * preserved, which otherwise might diffuse away due to rounding
+ * errors in pressure coupling or the deform option.
+ *
+ * \param[in] ir      Input record
+ * \param[in] box_rel Relative box
+ * \param[out] b      The corrected box
+ */
+void preserve_box_shape(t_inputrec *ir, matrix box_rel, matrix b);
+
+/*! \brief Determine the relative box components
+ *
+ * Set state->box_rel used in mdrun to preserve the box shape
+ * \param[in] ir       Input record
+ * \param[inout] state Structure containing the box
+ */
+void set_box_rel(struct t_inputrec *ir, t_state *state);
+
+#endif