Remove unnecessary config.h includes
[alexxy/gromacs.git] / src / gromacs / gmxpreprocess / xlate.c
index dac0b3cd652d78b2783ba6e8ebbaabe369c3f491..d8dfc594f89a3b7352a6f78c401658a056dce705 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 <string.h>
-#include "typedefs.h"
-#include "gromacs/utility/cstringutil.h"
-#include "gromacs/utility/smalloc.h"
-#include "symtab.h"
-#include "index.h"
-#include "gromacs/fileio/futil.h"
+
+#include "gromacs/legacyheaders/typedefs.h"
 #include "fflibutil.h"
 #include "hackblock.h"
-#include "gmx_fatal.h"
 #include "xlate.h"
 
 #include "gromacs/fileio/strdb.h"
+#include "gromacs/topology/residuetypes.h"
+#include "gromacs/topology/symtab.h"
+#include "gromacs/utility/cstringutil.h"
+#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/futil.h"
+#include "gromacs/utility/smalloc.h"
 
 typedef struct {
     char *filebase;
@@ -91,12 +90,12 @@ static void get_xlatoms(const char *fn, FILE *fp,
         }
 
         srenew(xl, n+1);
-        xl[n].filebase = strdup(filebase);
+        xl[n].filebase = gmx_strdup(filebase);
 
         /* Use wildcards... */
         if (strcmp(rbuf, "*") != 0)
         {
-            xl[n].res = strdup(rbuf);
+            xl[n].res = gmx_strdup(rbuf);
         }
         else
         {
@@ -109,8 +108,8 @@ static void get_xlatoms(const char *fn, FILE *fp,
             *_ptr = ' ';
         }
 
-        xl[n].atom    = strdup(abuf);
-        xl[n].replace = strdup(repbuf);
+        xl[n].atom    = gmx_strdup(abuf);
+        xl[n].replace = gmx_strdup(repbuf);
         n++;
     }
 
@@ -137,7 +136,7 @@ static void done_xlatom(int nxlate, t_xlate_atom *xlatom)
 
 void rename_atoms(const char *xlfile, const char *ffdir,
                   t_atoms *atoms, t_symtab *symtab, const t_restp *restp,
-                  gmx_bool bResname, gmx_residuetype_t rt, gmx_bool bReorderNum,
+                  gmx_bool bResname, gmx_residuetype_t *rt, gmx_bool bReorderNum,
                   gmx_bool bVerbose)
 {
     FILE         *fp;
@@ -147,6 +146,7 @@ void rename_atoms(const char *xlfile, const char *ffdir,
     char        **f;
     char          c, *rnm, atombuf[32], *ptr0, *ptr1;
     gmx_bool      bReorderedNum, bRenamed, bMatch;
+    gmx_bool      bStartTerm, bEndTerm;
 
     nxlate = 0;
     xlatom = NULL;
@@ -172,6 +172,10 @@ void rename_atoms(const char *xlfile, const char *ffdir,
     for (a = 0; (a < atoms->nr); a++)
     {
         resind = atoms->atom[a].resind;
+
+        bStartTerm = (resind == 0) || atoms->resinfo[resind].chainnum != atoms->resinfo[resind-1].chainnum;
+        bEndTerm   = (resind >= atoms->nres-1) || atoms->resinfo[resind].chainnum != atoms->resinfo[resind+1].chainnum;
+
         if (bResname)
         {
             rnm = *(atoms->resinfo[resind].name);
@@ -205,6 +209,10 @@ void rename_atoms(const char *xlfile, const char *ffdir,
             {
                 /* Match the residue name */
                 bMatch = (xlatom[i].res == NULL ||
+                          (gmx_strcasecmp("protein-nterm", xlatom[i].res) == 0 &&
+                           gmx_residuetype_is_protein(rt, rnm) && bStartTerm) ||
+                          (gmx_strcasecmp("protein-cterm", xlatom[i].res) == 0 &&
+                           gmx_residuetype_is_protein(rt, rnm) && bEndTerm) ||
                           (gmx_strcasecmp("protein", xlatom[i].res) == 0 &&
                            gmx_residuetype_is_protein(rt, rnm)) ||
                           (gmx_strcasecmp("DNA", xlatom[i].res) == 0 &&
@@ -229,7 +237,7 @@ void rename_atoms(const char *xlfile, const char *ffdir,
                     /* Don't free the old atomname,
                      * since it might be in the symtab.
                      */
-                    ptr0 = strdup(xlatom[i].replace);
+                    ptr0 = gmx_strdup(xlatom[i].replace);
                     if (bVerbose)
                     {
                         printf("Renaming atom '%s' in residue %d %s to '%s'\n",