Merge branch 'origin/release-2020' into merge-2020-into-2021
[alexxy/gromacs.git] / src / gromacs / gmxana / gmx_h2order.cpp
index 1e52fe0b491ac09cc4d5024cae6931318e39455b..509801a57292a95c46647a7da56057469c0ffa9d 100644 (file)
@@ -259,6 +259,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[] = {
@@ -271,13 +280,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,
@@ -285,7 +294,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, "
@@ -316,11 +325,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), &pbcType); /* read topology file */