Remove unnecessary config.h includes
[alexxy/gromacs.git] / src / gromacs / gmxana / gmx_rmsdist.c
index 19cf1d1d84deda305029e31f9dda729fabce340e..504ba2abc285f8e307414267199abeb111665d8e 100644 (file)
@@ -1,59 +1,59 @@
 /*
+ * 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 <ctype.h>
-
-#include "macros.h"
-#include "smalloc.h"
-#include "typedefs.h"
-#include "names.h"
-#include "statutil.h"
-#include "tpxio.h"
-#include "string2.h"
-#include "strdb.h"
-#include "vec.h"
-#include "macros.h"
-#include "index.h"
-#include "pbc.h"
-#include "xvgr.h"
-#include "futil.h"
-#include "matio.h"
+
+#include "gromacs/legacyheaders/macros.h"
+#include "gromacs/utility/smalloc.h"
+#include "gromacs/legacyheaders/typedefs.h"
+#include "gromacs/legacyheaders/names.h"
+#include "gromacs/commandline/pargs.h"
+#include "gromacs/fileio/tpxio.h"
+#include "gromacs/fileio/trxio.h"
+#include "gromacs/fileio/strdb.h"
+#include "gromacs/math/vec.h"
+#include "gromacs/legacyheaders/macros.h"
+#include "gromacs/topology/index.h"
+#include "gromacs/pbcutil/pbc.h"
+#include "gromacs/fileio/xvgr.h"
+#include "gromacs/legacyheaders/viewit.h"
+#include "gromacs/utility/futil.h"
+#include "gromacs/fileio/matio.h"
 #include "gmx_ana.h"
 
 
@@ -172,7 +172,7 @@ static int read_equiv(const char *eq_fn, t_equiv ***equivptr)
     int       neq, na, n, resnr;
     t_equiv **equiv;
 
-    fp    = ffopen(eq_fn, "r");
+    fp    = gmx_ffopen(eq_fn, "r");
     neq   = 0;
     equiv = NULL;
     while (get_a_line(fp, line, STRLEN))
@@ -186,14 +186,14 @@ static int read_equiv(const char *eq_fn, t_equiv ***equivptr)
         {
             lp += n;
             snew(equiv[neq], 1);
-            equiv[neq][0].nname = strdup(atomname);
+            equiv[neq][0].nname = gmx_strdup(atomname);
             while (sscanf(lp, "%d %s %s %n", &resnr, resname, atomname, &n) == 3)
             {
                 /* this is not efficient, but I'm lazy (again) */
                 srenew(equiv[neq], na+1);
                 equiv[neq][na].rnr   = resnr-1;
-                equiv[neq][na].rname = strdup(resname);
-                equiv[neq][na].aname = strdup(atomname);
+                equiv[neq][na].rname = gmx_strdup(resname);
+                equiv[neq][na].aname = gmx_strdup(atomname);
                 if (na > 0)
                 {
                     equiv[neq][na].nname = NULL;
@@ -211,7 +211,7 @@ static int read_equiv(const char *eq_fn, t_equiv ***equivptr)
         /* next */
         neq++;
     }
-    ffclose(fp);
+    gmx_ffclose(fp);
 
     *equivptr = equiv;
 
@@ -267,7 +267,7 @@ static gmx_bool is_equiv(int neq, t_equiv **equiv, char **nname,
     }
     if (bFound)
     {
-        *nname = strdup(equiv[i-1][0].nname);
+        *nname = gmx_strdup(equiv[i-1][0].nname);
     }
 
     return bFound;
@@ -318,12 +318,12 @@ static int analyze_noe_equivalent(const char *eq_fn,
                                  rnrj, *atoms->resinfo[rnrj].name, *atoms->atomname[index[j]]);
                     if (nnm[i] && bEquiv)
                     {
-                        nnm[j] = strdup(nnm[i]);
+                        nnm[j] = gmx_strdup(nnm[i]);
                     }
                     if (bEquiv)
                     {
                         /* set index for matching atom */
-                        noe_index[j] = groupnr;
+                        noe_index[i] = groupnr;
                         /* skip matching atom */
                         i = j;
                     }
@@ -341,7 +341,7 @@ static int analyze_noe_equivalent(const char *eq_fn,
                    This is supposed to cover all CH3 groups and the like */
                 anmi   = *atoms->atomname[index[i]];
                 anmil  = strlen(anmi);
-                bMatch = i < isize-3 && anmi[anmil-1] == '1';
+                bMatch = i <= isize-3 && anmi[anmil-1] == '1';
                 if (bMatch)
                 {
                     for (j = 1; j < 3; j++)
@@ -399,18 +399,18 @@ static int analyze_noe_equivalent(const char *eq_fn,
             noe_gr[gi].anr  = index[i];
             if (nnm[i])
             {
-                noe_gr[gi].aname = strdup(nnm[i]);
+                noe_gr[gi].aname = gmx_strdup(nnm[i]);
             }
             else
             {
-                noe_gr[gi].aname = strdup(*atoms->atomname[index[i]]);
+                noe_gr[gi].aname = gmx_strdup(*atoms->atomname[index[i]]);
                 if (noe_index[i] == noe_index[i+1])
                 {
                     noe_gr[gi].aname[strlen(noe_gr[gi].aname)-1] = '*';
                 }
             }
             noe_gr[gi].rnr   = atoms->atom[index[i]].resind;
-            noe_gr[gi].rname = strdup(*atoms->resinfo[noe_gr[gi].rnr].name);
+            noe_gr[gi].rname = gmx_strdup(*atoms->resinfo[noe_gr[gi].rnr].name);
             /* dump group definitions */
             if (debug)
             {
@@ -624,17 +624,17 @@ real rms_diff(int natom, real **d, real **d_r)
     return sqrt(r2);
 }
 
-int gmx_rmsdist (int argc, char *argv[])
+int gmx_rmsdist(int argc, char *argv[])
 {
     const char     *desc[] = {
-        "[TT]g_rmsdist[tt] computes the root mean square deviation of atom distances,",
+        "[THISMODULE] computes the root mean square deviation of atom distances,",
         "which has the advantage that no fit is needed like in standard RMS",
-        "deviation as computed by [TT]g_rms[tt].",
+        "deviation as computed by [gmx-rms].",
         "The reference structure is taken from the structure file.",
         "The RMSD at time t is calculated as the RMS",
         "of the differences in distance between atom-pairs in the reference",
         "structure and the structure at time t.[PAR]",
-        "[TT]g_rmsdist[tt] can also produce matrices of the rms distances, rms distances",
+        "[THISMODULE] can also produce matrices of the rms distances, rms distances",
         "scaled with the mean distance and the mean distances and matrices with",
         "NMR averaged distances (1/r^3 and 1/r^6 averaging). Finally, lists",
         "of atom pairs with 1/r^3 and 1/r^6 averaged distance below the",
@@ -644,7 +644,7 @@ int gmx_rmsdist (int argc, char *argv[])
         "equivalent atoms can be supplied ([TT]-equiv[tt]), each line containing",
         "a set of equivalent atoms specified as residue number and name and",
         "atom name; e.g.:[PAR]",
-        "[TT]3 SER  HB1 3 SER  HB2[tt][PAR]",
+        "[TT]HB* 3 SER  HB1 3 SER  HB2[tt][PAR]",
         "Residue and atom names must exactly match those in the structure",
         "file, including case. Specifying non-sequential atoms is undefined."
 
@@ -705,8 +705,11 @@ int gmx_rmsdist (int argc, char *argv[])
     };
 #define NFILE asize(fnm)
 
-    parse_common_args(&argc, argv, PCA_CAN_VIEW | PCA_CAN_TIME | PCA_BE_NICE,
-                      NFILE, fnm, asize(pa), pa, asize(desc), desc, 0, NULL, &oenv);
+    if (!parse_common_args(&argc, argv, PCA_CAN_VIEW | PCA_CAN_TIME,
+                           NFILE, fnm, asize(pa), pa, asize(desc), desc, 0, NULL, &oenv))
+    {
+        return 0;
+    }
 
     bRMS   = opt2bSet("-rms", NFILE, fnm);
     bScale = opt2bSet("-scl", NFILE, fnm);
@@ -782,7 +785,8 @@ int gmx_rmsdist (int argc, char *argv[])
     }
 
     /*do a first step*/
-    natom = read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &x, box);
+    natom  = read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &x, box);
+    teller = 0;
 
     do
     {
@@ -790,13 +794,12 @@ int gmx_rmsdist (int argc, char *argv[])
 
         rmsnow = rms_diff(isize, d, d_r);
         fprintf(fp, "%g  %g\n", t, rmsnow);
+        teller++;
     }
     while (read_next_x(oenv, status, &t, x, box));
     fprintf(stderr, "\n");
 
-    ffclose(fp);
-
-    teller = nframes_read(status);
+    gmx_ffclose(fp);
 
     close_trj(status);