Fix gmx h2order -d option
authorPaul Bauer <paul.bauer.q@gmail.com>
Tue, 24 Nov 2020 10:22:47 +0000 (11:22 +0100)
committerMark Abraham <mark.j.abraham@gmail.com>
Tue, 24 Nov 2020 12:30:28 +0000 (12:30 +0000)
The code to implement this was never added.

Fixes #3820

docs/release-notes/2020/2020.5.rst
src/gromacs/gmxana/gmx_h2order.cpp

index cfe31a2d33b70ec1a5045803c7712742c4b40319..761dee81f16e51ae6447afd0a90e218f78b5ae24 100644 (file)
@@ -60,6 +60,13 @@ Improve CHARMM support in gmx do_dssp
 
 :issue:`3568`
 
+Fix non-funtioning gmx h2order -d option
+""""""""""""""""""""""""""""""""""""""""
+
+The gmx h2order tool would always take the normal along the z-axis.
+
+:issue:`3820`
+
 Fixes that affect portability
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
index 790aa6f72b9d9408c3aa995aaaa420d2dc987790..889016981933f32132612ffb994899016ab1774f 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,2015,2016,2017,2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019,2020, 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.
@@ -258,6 +258,15 @@ static void h2order_plot(rvec dipole[], real order[], const char* afile, int nsl
     xvgrclose(ord);
 }
 
+enum
+{
+    axisSEL,
+    axisZ,
+    axisY,
+    axisX,
+    axisNR
+};
+
 int gmx_h2order(int argc, char* argv[])
 {
     const char* desc[] = {
@@ -270,13 +279,13 @@ int gmx_h2order(int argc, char* argv[])
         "dipole and the axis from the center of mass to the oxygen is calculated",
         "instead of the angle between the dipole and a box axis."
     };
-    static int         axis    = 2; /* normal to memb. default z  */
-    static const char* axtitle = "Z";
-    static int         nslices = 0; /* nr of slices defined       */
-    t_pargs            pa[]    = { { "-d",
+    static const char* axisOption[axisNR + 1] = { nullptr, "Z", "Y", "X", nullptr };
+    static int         nslices                = 0; /* nr of slices defined       */
+    // The struct that will hold the parsed user input
+    t_pargs     pa[]   = { { "-d",
                        FALSE,
-                       etSTR,
-                       { &axtitle },
+                       etENUM,
+                       { axisOption },
                        "Take the normal on the membrane in direction X, Y or Z." },
                      { "-sl",
                        FALSE,
@@ -284,7 +293,7 @@ int gmx_h2order(int argc, char* argv[])
                        { &nslices },
                        "Calculate order parameter as function of boxlength, dividing the box"
                        " in this number of slices." } };
-    const char*        bugs[]  = {
+    const char* bugs[] = {
         "The program assigns whole water molecules to a slice, based on the first "
         "atom of three in the index file group. It assumes an order O,H,H. "
         "Name is not important, but the order is. If this demand is not met, "
@@ -315,11 +324,25 @@ int gmx_h2order(int argc, char* argv[])
 
 #define NFILE asize(fnm)
 
+    // Parse the user input in argv into pa
     if (!parse_common_args(&argc, argv, PCA_CAN_VIEW | PCA_CAN_TIME, NFILE, fnm, asize(pa), pa,
                            asize(desc), desc, asize(bugs), bugs, &oenv))
     {
         return 0;
     }
+
+    // Process the axis option chosen by the user to set the
+    // axis used for the computation. The useful choice is an
+    // axis normal to the membrane. Default is z-axis.
+    int axis = ZZ;
+    switch (nenum(axisOption))
+    {
+        case axisX: axis = XX; break;
+        case axisY: axis = YY; break;
+        case axisZ: axis = ZZ; break;
+        default: axis = ZZ;
+    }
+
     bMicel = opt2bSet("-nm", NFILE, fnm);
 
     top = read_top(ftp2fn(efTPR, NFILE, fnm), &ePBC); /* read topology file */