Fix gro errors with PDB insertion codes
authorErik Lindahl <erik@kth.se>
Sat, 20 Jun 2015 14:01:46 +0000 (16:01 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Mon, 22 Jun 2015 09:35:16 +0000 (11:35 +0200)
The insertion codes are discarded when converting to GRO files,
which results in adjacent residues with different names but
identical numbers. The reading code has been altered to identify
new residues also when the resname changes; this does not fix
the duplicate numbers (it cannot be fixed in GRO files), but it
will correctly propagate all data so the correct labels can
be recovered by using gmx trjconv with the original PDB file for
the -s argument.

Fixes #1600.

Change-Id: Iaf79f3f9e548e8555d78cb39e869410aa8186029

src/gromacs/fileio/confio.c

index 18cf7a1c5936996849a5ced67aceba01d340679b..ee768140052fe22488d2a7079d5a455aff349514 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, 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.
@@ -922,6 +922,7 @@ static gmx_bool get_w_conf(FILE *in, const char *infile, char *title,
                            rvec x[], rvec *v, matrix box)
 {
     char       name[6];
+    char       resname[6], oldresname[6];
     char       line[STRLEN+1], *ptr;
     char       buf[256];
     double     x1, y1, z1, x2, y2, z2;
@@ -952,6 +953,9 @@ static gmx_bool get_w_conf(FILE *in, const char *infile, char *title,
 
     bVel = FALSE;
 
+    resname[0]     = '\0';
+    oldresname[0]  = '\0';
+
     /* just pray the arrays are big enough */
     for (i = 0; (i < natoms); i++)
     {
@@ -999,9 +1003,9 @@ static gmx_bool get_w_conf(FILE *in, const char *infile, char *title,
         memcpy(name, line, 5);
         name[5] = '\0';
         sscanf(name, "%d", &resnr);
-        memcpy(name, line+5, 5);
-        name[5] = '\0';
-        if (resnr != oldres)
+        sscanf(line+5, "%5s", resname);
+
+        if (resnr != oldres || strncmp(resname, oldresname, sizeof(resname)))
         {
             oldres = resnr;
             newres++;
@@ -1011,7 +1015,7 @@ static gmx_bool get_w_conf(FILE *in, const char *infile, char *title,
                           infile, natoms);
             }
             atoms->atom[i].resind = newres;
-            t_atoms_set_resinfo(atoms, i, symtab, name, resnr, ' ', 0, ' ');
+            t_atoms_set_resinfo(atoms, i, symtab, resname, resnr, ' ', 0, ' ');
         }
         else
         {
@@ -1022,6 +1026,9 @@ static gmx_bool get_w_conf(FILE *in, const char *infile, char *title,
         memcpy(name, line+10, 5);
         atoms->atomname[i] = put_symtab(symtab, name);
 
+        /* Copy resname to oldresname after we are done with the sanity check above */
+        strncpy(oldresname, resname, sizeof(oldresname));
+
         /* eventueel controle atomnumber met i+1 */
 
         /* coordinates (start after residue data) */