Fix .gro large box writing
authorBerk Hess <hess@kth.se>
Tue, 5 Nov 2019 08:41:02 +0000 (09:41 +0100)
committerDavid van der Spoel <spoel@xray.bmc.uu.se>
Thu, 7 Nov 2019 15:36:44 +0000 (16:36 +0100)
Contrary to the format specification in the manual, the box components
in the .gro file were not separated by whitespace when components
(except for the first one) were >= 1000 or <= -100. Now a space is
always printed. This might not match the original GROMOS format,
but most codes reading .gro file assume space separation.
Note formatting of boxes that did have spacing is not changed.

Fixes #3176

Change-Id: I8cfcde98b46550b16b9f6bc299dc0b67454b2437

docs/release-notes/2019/2019.5.rst
src/gromacs/fileio/groio.cpp

index 1017afb17ff1ef5d864520d3357e1c3bb2b243d1..c0cd22cc01fa3f0924c0e9b85782122b25f24440 100644 (file)
@@ -61,3 +61,16 @@ Fixes that affect portability
 Miscellaneous
 ^^^^^^^^^^^^^
 
+Fix .gro file formatting with large boxes
+"""""""""""""""""""""""""""""""""""""""""
+
+The |Gromacs| manual says the box components in the .gro file
+format are separated by spaces. But no space was printed when
+a box component, except for the first, was 1000 nm or larger
+or an off-diagonal component was -100 nm or smaller.
+Now at least one space is always printed. Content that was written
+in a way that already had at least one space between components
+is unchanged. Existing parsers that conform to the documentation
+and expect whitespace separation will continue to work in all cases.
+
+:issue:`3176`
index d5dd610eeaef0574dfc72225ff93eb33d841f955..fcfb82e57529dd15f194a1e378f1668b3a7319bc 100644 (file)
@@ -439,14 +439,14 @@ static void write_hconf_box(FILE *out, const matrix box)
     if ((box[XX][YY] != 0.0f) || (box[XX][ZZ] != 0.0f) || (box[YY][XX] != 0.0f) || (box[YY][ZZ] != 0.0f) ||
         (box[ZZ][XX] != 0.0f) || (box[ZZ][YY] != 0.0f))
     {
-        fprintf(out, "%10.5f%10.5f%10.5f%10.5f%10.5f%10.5f%10.5f%10.5f%10.5f\n",
+        fprintf(out, "%10.5f %9.5f %9.5f %9.5f %9.5f %9.5f %9.5f %9.5f %9.5f\n",
                 box[XX][XX], box[YY][YY], box[ZZ][ZZ],
                 box[XX][YY], box[XX][ZZ], box[YY][XX],
                 box[YY][ZZ], box[ZZ][XX], box[ZZ][YY]);
     }
     else
     {
-        fprintf(out, "%10.5f%10.5f%10.5f\n",
+        fprintf(out, "%10.5f %9.5f %9.5f\n",
                 box[XX][XX], box[YY][YY], box[ZZ][ZZ]);
     }
 }