From: Kevin Boyd Date: Tue, 15 Jan 2019 02:18:49 +0000 (-0500) Subject: Add tests for gmx mindist X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=2f9e9799983deb0ae36980e2eb82cb260f08458a;p=alexxy%2Fgromacs.git Add tests for gmx mindist Freed up some memory in gmx_mindist Changed some static variables to normal variables, as their values were propagating between tests and messing with the options Change-Id: Ideb0341659ad2d8a66769e671e1fafadd6ea8d02 --- diff --git a/src/gromacs/gmxana/gmx_mindist.cpp b/src/gromacs/gmxana/gmx_mindist.cpp index 9ce1732513..52cd5148f0 100644 --- a/src/gromacs/gmxana/gmx_mindist.cpp +++ b/src/gromacs/gmxana/gmx_mindist.cpp @@ -3,7 +3,7 @@ * * 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. @@ -593,7 +593,17 @@ static void dist_plot(const char *fn, const char *afile, const char *dfile, 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) @@ -667,11 +677,11 @@ int gmx_mindist(int argc, char *argv[]) "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" }, @@ -697,7 +707,7 @@ int gmx_mindist(int argc, char *argv[]) gmx_output_env_t *oenv; t_topology *top = nullptr; int ePBC = -1; - rvec *x; + rvec *x = nullptr; matrix box; gmx_bool bTop = FALSE; @@ -823,5 +833,17 @@ int gmx_mindist(int argc, char *argv[]) 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; } diff --git a/src/gromacs/gmxana/tests/CMakeLists.txt b/src/gromacs/gmxana/tests/CMakeLists.txt index e8db2e4fc2..4738db4f77 100644 --- a/src/gromacs/gmxana/tests/CMakeLists.txt +++ b/src/gromacs/gmxana/tests/CMakeLists.txt @@ -1,7 +1,7 @@ # # This file is part of the GROMACS molecular simulation package. # -# 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. @@ -39,6 +39,7 @@ gmx_add_gtest_executable( entropy.cpp gmx_traj.cpp gmx_trjconv.cpp + gmx_mindist.cpp gmx_msd.cpp ) gmx_register_gtest_test(GmxAnaTest ${exename} INTEGRATION_TEST) diff --git a/src/gromacs/gmxana/tests/gmx_mindist.cpp b/src/gromacs/gmxana/tests/gmx_mindist.cpp new file mode 100644 index 0000000000..b2e5459366 --- /dev/null +++ b/src/gromacs/gmxana/tests/gmx_mindist.cpp @@ -0,0 +1,209 @@ +/* + * 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 + */ + +#include "gmxpre.h" + +#include +#include + +#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 diff --git a/src/gromacs/gmxana/tests/refdata/MindistTest_groupWorks.xml b/src/gromacs/gmxana/tests/refdata/MindistTest_groupWorks.xml new file mode 100644 index 0000000000..90825861d7 --- /dev/null +++ b/src/gromacs/gmxana/tests/refdata/MindistTest_groupWorks.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + 2 + 0.000000e+00 + 1 + + + + + diff --git a/src/gromacs/gmxana/tests/refdata/MindistTest_matrixWorks.xml b/src/gromacs/gmxana/tests/refdata/MindistTest_matrixWorks.xml new file mode 100644 index 0000000000..26f206fa54 --- /dev/null +++ b/src/gromacs/gmxana/tests/refdata/MindistTest_matrixWorks.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + 4 + 0.000000e+00 + 2.000000e+00 + 1.500000e+00 + 5.000000e-01 + + + + + diff --git a/src/gromacs/gmxana/tests/refdata/MindistTest_maxDistWorks.xml b/src/gromacs/gmxana/tests/refdata/MindistTest_maxDistWorks.xml new file mode 100644 index 0000000000..b697a2b05d --- /dev/null +++ b/src/gromacs/gmxana/tests/refdata/MindistTest_maxDistWorks.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + 2 + 0.000000e+00 + 1.500000e+00 + + + + + diff --git a/src/gromacs/gmxana/tests/refdata/MindistTest_mindistDoesNotPickUpContacts.xml b/src/gromacs/gmxana/tests/refdata/MindistTest_mindistDoesNotPickUpContacts.xml new file mode 100644 index 0000000000..4a3dd3b88d --- /dev/null +++ b/src/gromacs/gmxana/tests/refdata/MindistTest_mindistDoesNotPickUpContacts.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + 2 + 0.000000e+00 + 0 + + + + + diff --git a/src/gromacs/gmxana/tests/refdata/MindistTest_mindistPicksUpContacts.xml b/src/gromacs/gmxana/tests/refdata/MindistTest_mindistPicksUpContacts.xml new file mode 100644 index 0000000000..3716b7c977 --- /dev/null +++ b/src/gromacs/gmxana/tests/refdata/MindistTest_mindistPicksUpContacts.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + 2 + 0.000000e+00 + 1 + + + + + diff --git a/src/gromacs/gmxana/tests/refdata/MindistTest_mindistWorksWithMultipleAtoms.xml b/src/gromacs/gmxana/tests/refdata/MindistTest_mindistWorksWithMultipleAtoms.xml new file mode 100644 index 0000000000..7b1c5cf948 --- /dev/null +++ b/src/gromacs/gmxana/tests/refdata/MindistTest_mindistWorksWithMultipleAtoms.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + 2 + 0.000000e+00 + 5.000000e-01 + + + + + diff --git a/src/gromacs/gmxana/tests/refdata/MindistTest_mindistWorksWithSingleAtoms.xml b/src/gromacs/gmxana/tests/refdata/MindistTest_mindistWorksWithSingleAtoms.xml new file mode 100644 index 0000000000..4e9a41db24 --- /dev/null +++ b/src/gromacs/gmxana/tests/refdata/MindistTest_mindistWorksWithSingleAtoms.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + 2 + 0.000000e+00 + 2.000000e+00 + + + + + diff --git a/src/gromacs/gmxana/tests/refdata/MindistTest_ngWorks.xml b/src/gromacs/gmxana/tests/refdata/MindistTest_ngWorks.xml new file mode 100644 index 0000000000..29b3c08f7f --- /dev/null +++ b/src/gromacs/gmxana/tests/refdata/MindistTest_ngWorks.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + 3 + 0.000000e+00 + 2.000000e+00 + 1.500000e+00 + + + + + diff --git a/src/gromacs/gmxana/tests/refdata/MindistTest_noPbcWorks.xml b/src/gromacs/gmxana/tests/refdata/MindistTest_noPbcWorks.xml new file mode 100644 index 0000000000..f9cbb0693e --- /dev/null +++ b/src/gromacs/gmxana/tests/refdata/MindistTest_noPbcWorks.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + 2 + 0.000000e+00 + 3.000000e+00 + + + + + diff --git a/src/gromacs/gmxana/tests/refdata/MindistTest_resPerTimeWorks.xml b/src/gromacs/gmxana/tests/refdata/MindistTest_resPerTimeWorks.xml new file mode 100644 index 0000000000..eeeab60031 --- /dev/null +++ b/src/gromacs/gmxana/tests/refdata/MindistTest_resPerTimeWorks.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + 3 + 0.000000e+00 + 1.5 + 0.5 + + + + + diff --git a/src/testutils/simulationdatabase/mindist.ndx b/src/testutils/simulationdatabase/mindist.ndx new file mode 100644 index 0000000000..3b54e32952 --- /dev/null +++ b/src/testutils/simulationdatabase/mindist.ndx @@ -0,0 +1,12 @@ +[ atom1 ] +1 +[ atom2 ] +2 +[ atom3 ] +3 +[ atoms12 ] +1 2 +[ atoms23 ] +2 3 +[ atoms123 ] +1 2 3 diff --git a/src/testutils/simulationdatabase/mindist_coords.gro b/src/testutils/simulationdatabase/mindist_coords.gro new file mode 100644 index 0000000000..5205564009 --- /dev/null +++ b/src/testutils/simulationdatabase/mindist_coords.gro @@ -0,0 +1,6 @@ +mindist_beads + 3 + 1A A 1 1.000 3.000 3.000 + 2A A 2 4.000 3.000 3.000 + 2B B 3 4.500 3.000 3.000 + 5.00000 5.00000 5.00000 \ No newline at end of file