Remove unnecessary config.h includes
[alexxy/gromacs.git] / src / gromacs / gmxana / gmx_make_ndx.c
index a5bb67e4a27ae1baea42d13c2c90e747a334ac91..be16251aefdbd1ded43fa13387901390e7025564 100644 (file)
  * 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 <ctype.h>
-#include "sysstuff.h"
-#include "gromacs/fileio/futil.h"
-#include "macros.h"
-#include "string2.h"
-#include "gromacs/commandline/pargs.h"
+#include <string.h>
+
+#include "gromacs/utility/futil.h"
+#include "gromacs/legacyheaders/macros.h"
 #include "gromacs/fileio/confio.h"
-#include "typedefs.h"
-#include "index.h"
-#include "smalloc.h"
-#include "vec.h"
-#include "index.h"
+#include "gromacs/legacyheaders/typedefs.h"
+#include "gromacs/topology/index.h"
+#include "gromacs/math/vec.h"
 
-#define MAXNAMES 30
-#define NAME_LEN 30
+#include "gromacs/commandline/pargs.h"
+#include "gromacs/topology/block.h"
+#include "gromacs/utility/cstringutil.h"
+#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/smalloc.h"
+
+/* It's not nice to have size limits, but we should not spend more time
+ * on this ancient tool, but instead use the new selection library.
+ */
+#define MAXNAMES 1024
+#define NAME_LEN 1024
 
 gmx_bool bCase = FALSE;
 
@@ -274,7 +278,7 @@ static gmx_bool parse_string(char **string, int *nr, int ngrps, char **grpname)
     {
         c = (*string)[0];
         (*string)++;
-        s  = strdup((*string));
+        s  = gmx_strdup((*string));
         sp = strchr(s, c);
         if (sp != NULL)
         {
@@ -743,7 +747,7 @@ static void remove_group(int nr, int nr2, t_blocka *block, char ***gn)
             {
                 block->index[i] = block->index[i+1]-shift;
             }
-            name = strdup((*gn)[nr]);
+            name = gmx_strdup((*gn)[nr]);
             sfree((*gn)[nr]);
             for (i = nr; i < block->nr-1; i++)
             {
@@ -792,7 +796,7 @@ static void split_group(t_atoms *atoms, int sel_nr, t_blocka *block, char ***gn,
             {
                 sprintf(buf, "%s_%s_%d", (*gn)[sel_nr], name, atoms->resinfo[resind].nr);
             }
-            (*gn)[block->nr-1] = strdup(buf);
+            (*gn)[block->nr-1] = gmx_strdup(buf);
         }
         block->a[block->nra] = a;
         block->nra++;
@@ -843,8 +847,12 @@ static int split_chain(t_atoms *atoms, rvec *x,
                 {
                     rvec_sub(x[ca_end], x[i], vec);
                 }
+                else
+                {
+                    break;
+                }
             }
-            while ((i < natoms) && (norm(vec) < 0.45));
+            while (norm(vec) < 0.45);
 
             end[nchain] = ca_end;
             while ((end[nchain]+1 < natoms) &&
@@ -879,7 +887,7 @@ static int split_chain(t_atoms *atoms, rvec *x,
             srenew(block->index, block->nr+1);
             srenew(*gn, block->nr);
             sprintf(buf, "%s_chain%d", (*gn)[sel_nr], j+1);
-            (*gn)[block->nr-1] = strdup(buf);
+            (*gn)[block->nr-1] = gmx_strdup(buf);
             for (i = block->index[sel_nr]; i < block->index[sel_nr+1]; i++)
             {
                 a = block->a[i];
@@ -1322,7 +1330,7 @@ static void edit_index(int natoms, t_atoms *atoms, rvec *x, t_blocka *block, cha
                 {
                     sscanf(string, "%s", gname);
                     sfree((*gn)[sel_nr]);
-                    (*gn)[sel_nr] = strdup(gname);
+                    (*gn)[sel_nr] = gmx_strdup(gname);
                 }
             }
         }
@@ -1440,7 +1448,7 @@ static void edit_index(int natoms, t_atoms *atoms, rvec *x, t_blocka *block, cha
                 copy2block(nr, index, block);
                 srenew(*gn, block->nr);
                 newgroup        = block->nr-1;
-                (*gn)[newgroup] = strdup(gname);
+                (*gn)[newgroup] = gmx_strdup(gname);
             }
             else
             {
@@ -1511,14 +1519,20 @@ int gmx_make_ndx(int argc, char *argv[])
         "When a run input file is supplied you can also select on atom type.",
         "You can use NOT, AND and OR, you can split groups",
         "into chains, residues or atoms. You can delete and rename groups.[PAR]",
-        "The atom numbering in the editor and the index file starts at 1."
+        "The atom numbering in the editor and the index file starts at 1.[PAR]",
+        "The [TT]-twin[tt] switch duplicates all index groups with an offset of",
+        "[TT]-natoms[tt], which is useful for Computational Electrophysiology",
+        "double-layer membrane setups."
     };
 
-    static int      natoms   = 0;
-    static gmx_bool bVerbose = FALSE;
-    t_pargs         pa[]     = {
+    static int      natoms     = 0;
+    static gmx_bool bVerbose   = FALSE;
+    static gmx_bool bDuplicate = FALSE;
+    t_pargs         pa[]       = {
         { "-natoms",  FALSE, etINT, {&natoms},
           "set number of atoms (default: read from coordinate or index file)" },
+        { "-twin",     FALSE, etBOOL, {&bDuplicate},
+          "Duplicate all index groups with an offset of -natoms" },
         { "-verbose", FALSE, etBOOL, {&bVerbose},
           "HIDDENVerbose output" }
     };
@@ -1622,7 +1636,7 @@ int gmx_make_ndx(int argc, char *argv[])
 
     edit_index(natoms, atoms, x, block, &gnames, bVerbose);
 
-    write_index(ndxoutfile, block, gnames);
+    write_index(ndxoutfile, block, gnames, bDuplicate, natoms);
 
     return 0;
 }