/*
+ * This file is part of the GROMACS molecular simulation package.
*
- * This source code is part of
- *
- * G R O M A C S
- *
- * GROningen MAchine for Chemical Simulations
- *
- * VERSION 3.2.0
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2004, The GROMACS development team,
- * check out http://www.gromacs.org for more information.
-
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
+ * Copyright (c) 2001-2004, The GROMACS development team.
+ * Copyright (c) 2013,2014, 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.
*
- * If you want to redistribute modifications, 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 www.gromacs.org.
+ * 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.
*
- * To help us fund GROMACS development, we humbly ask that you cite
- * the papers on the package - you can find them in the top README file.
+ * 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.
*
- * For more info, check our website at http://www.gromacs.org
+ * 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.
*
- * And Hey:
- * Green Red Orange Magenta Azure Cyan Skyblue
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
*/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "gmxpre.h"
#include <math.h>
#include <stdlib.h>
-
-#include "sysstuff.h"
#include <string.h>
-#include "typedefs.h"
-#include "smalloc.h"
-#include "macros.h"
-#include "vec.h"
-#include "xvgr.h"
-#include "pbc.h"
-#include "gromacs/fileio/futil.h"
-#include "statutil.h"
-#include "index.h"
+
+#include "gromacs/legacyheaders/typedefs.h"
+#include "gromacs/utility/smalloc.h"
+#include "gromacs/legacyheaders/macros.h"
+#include "gromacs/math/vec.h"
+#include "gromacs/fileio/xvgr.h"
+#include "gromacs/legacyheaders/viewit.h"
+#include "gromacs/pbcutil/pbc.h"
+#include "gromacs/utility/futil.h"
+#include "gromacs/commandline/pargs.h"
+#include "gromacs/topology/index.h"
#include "gromacs/fileio/tpxio.h"
#include "gromacs/fileio/trxio.h"
-#include "rmpbc.h"
-#include "gromacs/fileio/xtcio.h"
+#include "gromacs/pbcutil/rmpbc.h"
#include "gmx_ana.h"
+#include "gromacs/legacyheaders/names.h"
-static void periodic_dist(matrix box, rvec x[], int n, atom_id index[],
+static void periodic_dist(int ePBC,
+ matrix box, rvec x[], int n, atom_id index[],
real *rmin, real *rmax, int *min_ind)
{
-#define NSHIFT 26
- int sx, sy, sz, i, j, s;
+#define NSHIFT_MAX 26
+ int nsz, nshift, sx, sy, sz, i, j, s;
real sqr_box, r2min, r2max, r2;
- rvec shift[NSHIFT], d0, d;
+ rvec shift[NSHIFT_MAX], d0, d;
- sqr_box = sqr(min(norm(box[XX]), min(norm(box[YY]), norm(box[ZZ]))));
+ sqr_box = min(norm2(box[XX]), norm2(box[YY]));
+ if (ePBC == epbcXYZ)
+ {
+ sqr_box = min(sqr_box, norm2(box[ZZ]));
+ nsz = 1;
+ }
+ else if (ePBC == epbcXY)
+ {
+ nsz = 0;
+ }
+ else
+ {
+ gmx_fatal(FARGS, "pbc = %s is not supported by g_mindist",
+ epbc_names[ePBC]);
+ nsz = 0; /* Keep compilers quiet */
+ }
- s = 0;
- for (sz = -1; sz <= 1; sz++)
+ nshift = 0;
+ for (sz = -nsz; sz <= nsz; sz++)
{
for (sy = -1; sy <= 1; sy++)
{
{
for (i = 0; i < DIM; i++)
{
- shift[s][i] = sx*box[XX][i]+sy*box[YY][i]+sz*box[ZZ][i];
+ shift[nshift][i] =
+ sx*box[XX][i] + sy*box[YY][i] + sz*box[ZZ][i];
}
- s++;
+ nshift++;
}
}
}
{
r2max = r2;
}
- for (s = 0; s < NSHIFT; s++)
+ for (s = 0; s < nshift; s++)
{
rvec_add(d0, shift[s], d);
r2 = norm2(d);
gmx_rmpbc(gpbc, natoms, box, x);
}
- periodic_dist(box, x, n, index, &rmin, &rmax, ind_min);
+ periodic_dist(ePBC, box, x, n, index, &rmin, &rmax, ind_min);
if (rmin < rmint)
{
rmint = rmin;
ind_mini = ind_min[0];
ind_minj = ind_min[1];
}
- if (bSplit && !bFirst && abs(t/output_env_get_time_factor(oenv)) < 1e-5)
+ if (bSplit && !bFirst && fabs(t/output_env_get_time_factor(oenv)) < 1e-5)
{
- fprintf(out, "&\n");
+ fprintf(out, "%s\n", output_env_get_print_xvgr_codes(oenv) ? "&" : "");
}
fprintf(out, "\t%g\t%6.3f %6.3f %6.3f %6.3f %6.3f\n",
output_env_conv_time(oenv, t), rmin, rmax, norm(box[0]), norm(box[1]), norm(box[2]));
gmx_rmpbc_done(gpbc);
}
- ffclose(out);
+ gmx_ffclose(out);
fprintf(stdout,
"\nThe shortest periodic distance is %g (nm) at time %g (%s),\n"
dist = xvgropen(dfile, buf, output_env_get_time_label(oenv), "Distance (nm)", oenv);
sprintf(buf, "Number of Contacts %s %g nm", bMin ? "<" : ">", rcut);
num = nfile ? xvgropen(nfile, buf, output_env_get_time_label(oenv), "Number", oenv) : NULL;
- atm = afile ? ffopen(afile, "w") : NULL;
+ atm = afile ? gmx_ffopen(afile, "w") : NULL;
trxout = xfile ? open_trx(xfile, "w") : NULL;
if (bMat)
{
snew(leg, 1);
sprintf(buf, "Internal in %s", grpn[0]);
- leg[0] = strdup(buf);
+ leg[0] = gmx_strdup(buf);
xvgr_legend(dist, 0, (const char**)leg, oenv);
if (num)
{
for (k = i+1; (k < ng); k++, j++)
{
sprintf(buf, "%s-%s", grpn[i], grpn[k]);
- leg[j] = strdup(buf);
+ leg[j] = gmx_strdup(buf);
}
}
xvgr_legend(dist, j, (const char**)leg, oenv);
for (i = 0; (i < ng-1); i++)
{
sprintf(buf, "%s-%s", grpn[0], grpn[i+1]);
- leg[i] = strdup(buf);
+ leg[i] = gmx_strdup(buf);
}
xvgr_legend(dist, ng-1, (const char**)leg, oenv);
if (num)
bFirst = TRUE;
do
{
- if (bSplit && !bFirst && abs(t/output_env_get_time_factor(oenv)) < 1e-5)
+ if (bSplit && !bFirst && fabs(t/output_env_get_time_factor(oenv)) < 1e-5)
{
- fprintf(dist, "&\n");
+ fprintf(dist, "%s\n", output_env_get_print_xvgr_codes(oenv) ? "&" : "");
if (num)
{
- fprintf(num, "&\n");
+ fprintf(num, "%s\n", output_env_get_print_xvgr_codes(oenv) ? "&" : "");
}
if (atm)
{
- fprintf(atm, "&\n");
+ fprintf(atm, "%s\n", output_env_get_print_xvgr_codes(oenv) ? "&" : "");
}
}
fprintf(dist, "%12e", output_env_conv_time(oenv, t));
while (read_next_x(oenv, status, &t, x0, box));
close_trj(status);
- ffclose(dist);
+ gmx_ffclose(dist);
if (num)
{
- ffclose(num);
+ gmx_ffclose(num);
}
if (atm)
{
- ffclose(atm);
+ gmx_ffclose(atm);
}
if (trxout)
{
#define NFILE asize(fnm)
if (!parse_common_args(&argc, argv,
- PCA_CAN_VIEW | PCA_CAN_TIME | PCA_TIME_UNIT | PCA_BE_NICE,
+ PCA_CAN_VIEW | PCA_CAN_TIME | PCA_TIME_UNIT,
NFILE, fnm, asize(pa), pa, asize(desc), desc, 0, NULL, &oenv))
{
return 0;