*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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.
xvgrclose(res);
}
- sfree(x0);
+ if (x0)
+ {
+ sfree(x0);
+ }
+
+ int freeLeg = bMat ? (ng == 1 ? 1 : (ng*(ng-1))/2) : ng - 1;
+ for (int i = 0; i < freeLeg; i++)
+ {
+ sfree(leg[i]);
+ }
+ sfree(leg);
}
static int find_residues(const t_atoms *atoms, int n, const int index[], int **resindex)
"Also [gmx-distance] and [gmx-pairdist] calculate distances."
};
- static gmx_bool bMat = FALSE, bPI = FALSE, bSplit = FALSE, bMax = FALSE, bPBC = TRUE;
- static gmx_bool bGroup = FALSE;
- static real rcutoff = 0.6;
- static int ng = 1;
- static gmx_bool bEachResEachTime = FALSE, bPrintResName = FALSE;
+ gmx_bool bMat = FALSE, bPI = FALSE, bSplit = FALSE, bMax = FALSE, bPBC = TRUE;
+ gmx_bool bGroup = FALSE;
+ real rcutoff = 0.6;
+ int ng = 1;
+ gmx_bool bEachResEachTime = FALSE, bPrintResName = FALSE;
t_pargs pa[] = {
{ "-matrix", FALSE, etBOOL, {&bMat},
"Calculate half a matrix of group-group distances" },
gmx_output_env_t *oenv;
t_topology *top = nullptr;
int ePBC = -1;
- rvec *x;
+ rvec *x = nullptr;
matrix box;
gmx_bool bTop = FALSE;
do_view(oenv, numfnm, "-nxy");
}
+ output_env_done(oenv);
+ done_top(top);
+ for (int i = 0; i < ng; i++)
+ {
+ sfree(index[i]);
+ }
+ sfree(index);
+ sfree(gnx);
+ sfree(x);
+ sfree(grpname);
+ sfree(top);
+
return 0;
}
--- /dev/null
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2019, 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
+ * Tests for gmx mindist.
+ *
+ * \author Kevin Boyd <kevin.boyd@uconn.edu>
+ */
+
+#include "gmxpre.h"
+
+#include <cstdio>
+#include <cstdlib>
+
+#include "gromacs/gmxana/gmx_ana.h"
+#include "gromacs/utility/futil.h"
+#include "gromacs/utility/path.h"
+#include "gromacs/utility/textreader.h"
+
+#include "testutils/cmdlinetest.h"
+#include "testutils/refdata.h"
+#include "testutils/stdiohelper.h"
+#include "testutils/testfilemanager.h"
+#include "testutils/textblockmatchers.h"
+#include "testutils/xvgtest.h"
+
+namespace
+{
+
+using gmx::test::CommandLine;
+using gmx::test::XvgMatch;
+using gmx::test::StdioTestHelper;
+
+class MindistTest : public gmx::test::CommandLineTestBase
+{
+ public:
+ MindistTest()
+ {
+ setInputFile("-f", "mindist_coords.gro");
+ setInputFile("-s", "mindist_coords.gro");
+ setInputFile("-n", "mindist.ndx");
+ }
+
+ void runTest(const CommandLine &args, const char * stringForStdin)
+ {
+ StdioTestHelper stdioHelper(&fileManager());
+ stdioHelper.redirectStringToStdin(stringForStdin);
+
+ CommandLine &cmdline = commandLine();
+ cmdline.merge(args);
+ ASSERT_EQ(0, gmx_mindist(cmdline.argc(), cmdline.argv()));
+ checkOutputFiles();
+ }
+};
+
+/* mindist_coords.pdb has 3 beads spaced out in a 5 nm box, with the same yz coordinates
+ * and x coordinates of 1, 4, and 4.5. Indices are as follows
+ * index 0 : atom 1
+ * index 1 : atom 2
+ * index 2 : atom 3
+ * index 3 : atoms (1 ,2)
+ * index 4 : atoms (2, 3)
+ * index 5 : atoms (1, 2, 3)
+ */
+
+// Mindist between beads 0 and 1 should = 2 (across periodic boundaries)
+TEST_F(MindistTest, mindistWorksWithSingleAtoms)
+{
+ setOutputFile("-od", "mindist.xvg", XvgMatch());
+ const char *const cmdline[] = {
+ "mindist"
+ };
+ const char * const stdIn = "0 1";
+ runTest(CommandLine(cmdline), stdIn);
+}
+
+// Mindist between group (0, 1) and bead 2 should = 0.5
+TEST_F(MindistTest, mindistWorksWithMultipleAtoms)
+{
+ setOutputFile("-od", "mindist.xvg", XvgMatch());
+ const char *const cmdline[] = {
+ "mindist"
+ };
+ const char * const stdIn = "2 3";
+ runTest(CommandLine(cmdline), stdIn);
+}
+
+/* Should have 0 contacts with default cutoff */
+TEST_F(MindistTest, mindistDoesNotPickUpContacts)
+{
+ setOutputFile("-on", "ncontacts.xvg", XvgMatch());
+ const char * const cmdline[] = {
+ "mindist"
+ };
+ const char * const stdIn = "0 1";
+ runTest(CommandLine(cmdline), stdIn);
+}
+
+/* Should pick up one contact with 2.5 nm cutoff */
+TEST_F(MindistTest, mindistPicksUpContacts)
+{
+ setOutputFile("-on", "ncontacts.xvg", XvgMatch());
+ const char *const cmdline[] = {
+ "mindist", "-d", "2.5",
+ };
+ const char * const stdIn = "0 1";
+ runTest(CommandLine(cmdline), stdIn);
+}
+
+TEST_F(MindistTest, ngWorks)
+{
+ setOutputFile("-od", "mindist.xvg", XvgMatch());
+ const char *const cmdline[] = {
+ "mindist", "-ng", "2",
+ };
+ const char * const stdIn = "0 1 2";
+ runTest(CommandLine(cmdline), stdIn);
+}
+
+// 2 contacts within this cutoff, but only one should be reported
+TEST_F(MindistTest, groupWorks)
+{
+ setOutputFile("-on", "ncontacts.xvg", XvgMatch());
+ const char *const cmdline[] = {
+ "mindist", "-group", "-d", "3"
+ };
+ const char * const stdIn = "3, 2";
+ runTest(CommandLine(cmdline), stdIn);
+}
+
+// Maximum distance between group (1, 2) and atom 3
+TEST_F(MindistTest, maxDistWorks)
+{
+ setOutputFile("-od", "mindist.xvg", XvgMatch());
+ const char *const cmdline[] = {
+ "mindist", "-max"
+ };
+ const char * const stdIn = "2 3";
+ runTest(CommandLine(cmdline), stdIn);
+}
+
+/* Particles 1 and 2 are 2 nm away through pbc, but
+ should be 3 nm away with no pbc */
+TEST_F(MindistTest, noPbcWorks)
+{
+ setOutputFile("-od", "mindist.xvg", XvgMatch());
+ const char *const cmdline[] = {
+ "mindist", "-nopbc"
+ };
+ const char * const stdIn = "0 1";
+ runTest(CommandLine(cmdline), stdIn);
+}
+
+// Group (1, 2), each res compared to particle 3
+TEST_F(MindistTest, resPerTimeWorks)
+{
+ setOutputFile("-or", "respertime.xvg", XvgMatch());
+ const char *const cmdline[] = {
+ "mindist", "-respertime"
+ };
+ const char * const stdIn = "3 2";
+ runTest(CommandLine(cmdline), stdIn);
+}
+
+TEST_F(MindistTest, matrixWorks)
+{
+ setOutputFile("-od", "mindist.xvg", XvgMatch());
+ const char *const cmdline[] = {
+ "mindist", "-matrix"
+ };
+ const char * const stdIn = "5";
+ runTest(CommandLine(cmdline), stdIn);
+}
+
+// TODO test periodic image - needs a tpr?
+
+} //namespace