From 972032bfb8cd38c863c1cb7d2bb8e33c7cc185fb Mon Sep 17 00:00:00 2001 From: David van der Spoel Date: Fri, 16 May 2014 07:40:37 +0200 Subject: [PATCH] Fixes a complicated bug in g_anaeig. If the number of frames for a covariance analysis is fewer than the number of degrees of freedom, g_covar would happily print nonsense eigenvalues in the eigenval.xvg file. This would then lead g_anaeig to give NaN entropy values. By limiting the number of output lines in the eigenvalue file this should be resolved. In addition a warning is printed. Change-Id: I01693a0fa9f3ba5b5784543a04d0d88b33a755c2 --- src/tools/gmx_covar.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/tools/gmx_covar.c b/src/tools/gmx_covar.c index d82d515581..fc7d55e70f 100644 --- a/src/tools/gmx_covar.c +++ b/src/tools/gmx_covar.c @@ -566,7 +566,7 @@ int gmx_covar(int argc, char *argv[]) out = xvgropen(eigvalfile, "Eigenvalues of the covariance matrix", "Eigenvector index", str, oenv); - for (i = 0; (i < ndim); i++) + for (i = 0; (i < end); i++) { fprintf (out, "%10d %g\n", (int)i+1, eigenvalues[ndim-1-i]); } @@ -577,6 +577,9 @@ int gmx_covar(int argc, char *argv[]) if (nframes-1 < ndim) { end = nframes-1; + fprintf(out, "WARNING: there are fewer frames in your trajectory than there are\n"); + fprintf(out, "degrees of freedom in your system. Only generating the first\n"); + fprintf(out, "%d out of %d eigenvectors and eigenvalues.\n", end, (int)ndim); } else { @@ -659,7 +662,7 @@ int gmx_covar(int argc, char *argv[]) fprintf(out, "Trace of the covariance matrix after diagonalizing: %g\n\n", sum); - fprintf(out, "Wrote %d eigenvalues to %s\n", (int)ndim, eigvalfile); + fprintf(out, "Wrote %d eigenvalues to %s\n", (int)end, eigvalfile); if (WriteXref == eWXR_YES) { fprintf(out, "Wrote reference structure to %s\n", eigvecfile); -- 2.22.0