Add TNG to trjconv doc and more details about TNG selections.
[alexxy/gromacs.git] / src / gromacs / tools / trjconv.cpp
index f560ba3902b5bd83c2c64e9d34a1550080109fe3..132c862620664606598fafabfb18e405eae4f787 100644 (file)
@@ -3,7 +3,8 @@
  *
  * 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 by the GROMACS development team.
+ * Copyright (c) 2018,2019,2020,2021, 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.
@@ -74,8 +75,7 @@
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
 
-static void mk_filenm(char *base, const char *ext, int ndigit, int file_nr,
-                      char out_file[])
+static void mk_filenm(char* base, const char* ext, int ndigit, int file_nr, char out_file[])
 {
     char nbuf[128];
     int  nd = 0, fnr;
@@ -86,19 +86,18 @@ static void mk_filenm(char *base, const char *ext, int ndigit, int file_nr,
     {
         fnr /= 10;
         nd++;
-    }
-    while (fnr > 0);
+    } while (fnr > 0);
 
     if (nd < ndigit)
     {
-        std::strncat(out_file, "00000000000", ndigit-nd);
+        std::strncat(out_file, "00000000000", ndigit - nd);
     }
     sprintf(nbuf, "%d.", file_nr);
     std::strcat(out_file, nbuf);
     std::strcat(out_file, ext);
 }
 
-static void check_trr(const char *fn)
+static void check_trr(const charfn)
 {
     if (fn2ftp(fn) != efTRR)
     {
@@ -106,10 +105,10 @@ static void check_trr(const char *fn)
     }
 }
 
-static void do_trunc(const char *fn, real t0)
+static void do_trunc(const charfn, real t0)
 {
-    t_fileio        *in;
-    FILE            *fp;
+    t_fileio*        in;
+    FILE*            fp;
     gmx_bool         bStop, bOK;
     gmx_trr_header_t sh;
     gmx_off_t        fpos;
@@ -125,8 +124,8 @@ static void do_trunc(const char *fn, real t0)
     /* Check whether this is a .trr file */
     check_trr(fn);
 
-    in   = gmx_trr_open(fn, "r");
-    fp   = gmx_fio_getfp(in);
+    in = gmx_trr_open(fn, "r");
+    fp = gmx_fio_getfp(in);
     if (fp == nullptr)
     {
         fprintf(stderr, "Sorry, can not trunc %s, truncation of this filetype is not supported\n", fn);
@@ -150,9 +149,13 @@ static void do_trunc(const char *fn, real t0)
         }
         if (bStop)
         {
-            fprintf(stderr, "Do you REALLY want to truncate this trajectory (%s) at:\n"
+            fprintf(stderr,
+                    "Do you REALLY want to truncate this trajectory (%s) at:\n"
                     "frame %d, time %g, bytes %ld ??? (type YES if so)\n",
-                    fn, j, t, static_cast<long int>(fpos));
+                    fn,
+                    j,
+                    t,
+                    static_cast<long int>(fpos));
             if (1 != scanf("%s", yesno))
             {
                 gmx_fatal(FARGS, "Error reading user input");
@@ -199,29 +202,25 @@ static void do_trunc(const char *fn, real t0)
  * molecule information will generally be present if the input TNG
  * file was written by a GROMACS tool, this seems like reasonable
  * behaviour. */
-static std::unique_ptr<gmx_mtop_t>
-read_mtop_for_tng(const char *tps_file,
-                  const char *input_file,
-                  const char *output_file)
+static std::unique_ptr<gmx_mtop_t> read_mtop_for_tng(const char* tps_file,
+                                                     const char* input_file,
+                                                     const char* output_file)
 {
     std::unique_ptr<gmx_mtop_t> mtop;
 
-    if (fn2bTPX(tps_file) &&
-        efTNG != fn2ftp(input_file) &&
-        efTNG == fn2ftp(output_file))
+    if (fn2bTPX(tps_file) && efTNG != fn2ftp(input_file) && efTNG == fn2ftp(output_file))
     {
         int temp_natoms = -1;
-        mtop = std::make_unique<gmx_mtop_t>();
-        read_tpx(tps_file, nullptr, nullptr, &temp_natoms,
-                 nullptr, nullptr, mtop.get());
+        mtop            = std::make_unique<gmx_mtop_t>();
+        read_tpx(tps_file, nullptr, nullptr, &temp_natoms, nullptr, nullptr, mtop.get());
     }
 
     return mtop;
 }
 
-int gmx_trjconv(int argc, char *argv[])
+int gmx_trjconv(int argc, charargv[])
 {
-    const char *desc[] = {
+    const chardesc[] = {
         "[THISMODULE] can convert trajectory files in many ways:",
         "",
         "* from one format to another",
@@ -243,8 +242,8 @@ int gmx_trjconv(int argc, char *argv[])
         "[PAR]",
 
         "The following formats are supported for input and output:",
-        "[REF].xtc[ref], [REF].trr[ref], [REF].gro[ref], [TT].g96[tt]",
-        "and [REF].pdb[ref].",
+        "[REF].xtc[ref], [REF].trr[ref], [REF].gro[ref], [TT].g96[tt],",
+        "[REF].pdb[ref] and [REF].tng[ref].",
         "The file formats are detected from the file extension.",
         "The precision of the [REF].xtc[ref] output is taken from the",
         "input file for [REF].xtc[ref], [REF].gro[ref] and [REF].pdb[ref],",
@@ -254,10 +253,11 @@ int gmx_trjconv(int argc, char *argv[])
         "output can be single or double precision, depending on the precision",
         "of the [THISMODULE] binary.",
         "Note that velocities are only supported in",
-        "[REF].trr[ref], [REF].gro[ref] and [TT].g96[tt] files.[PAR]",
+        "[REF].trr[ref], [REF].tng[ref], [REF].gro[ref] and [TT].g96[tt] files.[PAR]",
 
         "Option [TT]-sep[tt] can be used to write every frame to a separate",
-        "[TT].gro, .g96[tt] or [REF].pdb[ref] file. By default, all frames all written to one file.",
+        "[TT].gro, .g96[tt] or [REF].pdb[ref] file. By default, all frames all written to ",
+        "one file.",
         "[REF].pdb[ref] files with all frames concatenated can be viewed with",
         "[TT]rasmol -nmrpdb[tt].[PAR]",
 
@@ -266,7 +266,11 @@ int gmx_trjconv(int argc, char *argv[])
         "out the water from a trajectory of a protein in water.",
         "[BB]ALWAYS[bb] put the original trajectory on tape!",
         "We recommend to use the portable [REF].xtc[ref] format for your analysis",
-        "to save disk space and to have portable files.[PAR]",
+        "to save disk space and to have portable files. When writing [REF].tng[ref]",
+        "output the file will contain one molecule type of the correct count",
+        "if the selection name matches the molecule name and the selected atoms",
+        "match all atoms of that molecule. Otherwise the whole selection will",
+        "be treated as one single molecule containing all the selected atoms.[PAR]",
 
         "There are two options for fitting the trajectory to a reference",
         "either for essential dynamics analysis, etc.",
@@ -357,7 +361,7 @@ int gmx_trjconv(int argc, char *argv[])
         "will not be written."
     };
 
-    int         pbc_enum;
+    int pbc_enum;
     enum
     {
         epSel,
@@ -370,185 +374,177 @@ int gmx_trjconv(int argc, char *argv[])
         epWhole,
         epNR
     };
-    const char *pbc_opt[epNR + 1] =
-    {
-        nullptr, "none", "mol", "res", "atom", "nojump", "cluster", "whole",
-        nullptr
-    };
+    const char* pbc_opt[epNR + 1] = { nullptr,  "none",    "mol",   "res",  "atom",
+                                      "nojump", "cluster", "whole", nullptr };
 
     int         unitcell_enum;
-    const char *unitcell_opt[euNR+1] =
-    { nullptr, "rect", "tric", "compact", nullptr };
+    const char* unitcell_opt[euNR + 1] = { nullptr, "rect", "tric", "compact", nullptr };
 
     enum
     {
-        ecSel, ecTric, ecRect, ecZero, ecNR
+        ecSel,
+        ecTric,
+        ecRect,
+        ecZero,
+        ecNR
     };
-    const char *center_opt[ecNR+1] =
-    { nullptr, "tric", "rect", "zero", nullptr };
+    const char* center_opt[ecNR + 1] = { nullptr, "tric", "rect", "zero", nullptr };
     int         ecenter;
 
-    int         fit_enum;
+    int fit_enum;
     enum
     {
-        efSel, efNone, efFit, efFitXY, efReset, efResetXY, efPFit, efNR
-    };
-    const char *fit[efNR + 1] =
-    {
-        nullptr, "none", "rot+trans", "rotxy+transxy", "translation", "transxy",
-        "progressive", nullptr
+        efSel,
+        efNone,
+        efFit,
+        efFitXY,
+        efReset,
+        efResetXY,
+        efPFit,
+        efNR
     };
-
-    static gmx_bool  bSeparate     = FALSE, bVels = TRUE, bForce = FALSE, bCONECT = FALSE;
-    static gmx_bool  bCenter       = FALSE;
-    static int       skip_nr       = 1, ndec = 3, nzero = 0;
-    static real      tzero         = 0, delta_t = 0, timestep = 0, ttrunc = -1, tdump = -1, split_t = 0;
-    static rvec      newbox        = {0, 0, 0}, shift = {0, 0, 0}, trans = {0, 0, 0};
-    static char     *exec_command  = nullptr;
-    static real      dropunder     = 0, dropover = 0;
-    static gmx_bool  bRound        = FALSE;
-
-    t_pargs
-        pa[] =
-    {
-        { "-skip", FALSE, etINT,
-          { &skip_nr }, "Only write every nr-th frame" },
-        { "-dt", FALSE, etTIME,
-          { &delta_t },
-          "Only write frame when t MOD dt = first time (%t)" },
-        { "-round", FALSE, etBOOL,
-          { &bRound }, "Round measurements to nearest picosecond"},
-        { "-dump", FALSE, etTIME,
-          { &tdump }, "Dump frame nearest specified time (%t)" },
-        { "-t0", FALSE, etTIME,
-          { &tzero },
-          "Starting time (%t) (default: don't change)" },
-        { "-timestep", FALSE, etTIME,
-          { &timestep },
-          "Change time step between input frames (%t)" },
-        { "-pbc", FALSE, etENUM,
-          { pbc_opt },
-          "PBC treatment (see help text for full description)" },
-        { "-ur", FALSE, etENUM,
-          { unitcell_opt }, "Unit-cell representation" },
-        { "-center", FALSE, etBOOL,
-          { &bCenter }, "Center atoms in box" },
-        { "-boxcenter", FALSE, etENUM,
-          { center_opt }, "Center for -pbc and -center" },
-        { "-box", FALSE, etRVEC,
-          { newbox },
-          "Size for new cubic box (default: read from input)" },
-        { "-trans", FALSE, etRVEC,
+    const char* fit[efNR + 1] = { nullptr,       "none",    "rot+trans",   "rotxy+transxy",
+                                  "translation", "transxy", "progressive", nullptr };
+
+    gmx_bool bSeparate = FALSE, bVels = TRUE, bForce = FALSE, bCONECT = FALSE;
+    gmx_bool bCenter = FALSE;
+    int      skip_nr = 1, ndec = 3, nzero = 0;
+    real     tzero = 0, delta_t = 0, timestep = 0, ttrunc = -1, tdump = -1, split_t = 0;
+    rvec     newbox = { 0, 0, 0 }, shift = { 0, 0, 0 }, trans = { 0, 0, 0 };
+    char*    exec_command = nullptr;
+    real     dropunder = 0, dropover = 0;
+    gmx_bool bRound = FALSE;
+
+    t_pargs pa[] = {
+        { "-skip", FALSE, etINT, { &skip_nr }, "Only write every nr-th frame" },
+        { "-dt", FALSE, etTIME, { &delta_t }, "Only write frame when t MOD dt = first time (%t)" },
+        { "-round", FALSE, etBOOL, { &bRound }, "Round measurements to nearest picosecond" },
+        { "-dump", FALSE, etTIME, { &tdump }, "Dump frame nearest specified time (%t)" },
+        { "-t0", FALSE, etTIME, { &tzero }, "Starting time (%t) (default: don't change)" },
+        { "-timestep", FALSE, etTIME, { &timestep }, "Change time step between input frames (%t)" },
+        { "-pbc", FALSE, etENUM, { pbc_opt }, "PBC treatment (see help text for full description)" },
+        { "-ur", FALSE, etENUM, { unitcell_opt }, "Unit-cell representation" },
+        { "-center", FALSE, etBOOL, { &bCenter }, "Center atoms in box" },
+        { "-boxcenter", FALSE, etENUM, { center_opt }, "Center for -pbc and -center" },
+        { "-box", FALSE, etRVEC, { newbox }, "Size for new cubic box (default: read from input)" },
+        { "-trans",
+          FALSE,
+          etRVEC,
           { trans },
           "All coordinates will be translated by trans. This "
           "can advantageously be combined with -pbc mol -ur "
           "compact." },
-        { "-shift", FALSE, etRVEC,
-          { shift },
-          "All coordinates will be shifted by framenr*shift" },
-        { "-fit", FALSE, etENUM,
-          { fit },
-          "Fit molecule to ref structure in the structure file" },
-        { "-ndec", FALSE, etINT,
-          { &ndec },
-          "Number of decimal places to write to .xtc output" },
-        { "-vel", FALSE, etBOOL,
-          { &bVels }, "Read and write velocities if possible" },
-        { "-force", FALSE, etBOOL,
-          { &bForce }, "Read and write forces if possible" },
-        { "-trunc", FALSE, etTIME,
+        { "-shift", FALSE, etRVEC, { shift }, "All coordinates will be shifted by framenr*shift" },
+        { "-fit", FALSE, etENUM, { fit }, "Fit molecule to ref structure in the structure file" },
+        { "-ndec", FALSE, etINT, { &ndec }, "Number of decimal places to write to .xtc output" },
+        { "-vel", FALSE, etBOOL, { &bVels }, "Read and write velocities if possible" },
+        { "-force", FALSE, etBOOL, { &bForce }, "Read and write forces if possible" },
+        { "-trunc",
+          FALSE,
+          etTIME,
           { &ttrunc },
           "Truncate input trajectory file after this time (%t)" },
-        { "-exec", FALSE, etSTR,
+        { "-exec",
+          FALSE,
+          etSTR,
           { &exec_command },
           "Execute command for every output frame with the "
           "frame number as argument" },
-        { "-split", FALSE, etTIME,
+        { "-split",
+          FALSE,
+          etTIME,
           { &split_t },
           "Start writing new file when t MOD split = first "
           "time (%t)" },
-        { "-sep", FALSE, etBOOL,
+        { "-sep",
+          FALSE,
+          etBOOL,
           { &bSeparate },
           "Write each frame to a separate .gro, .g96 or .pdb "
           "file" },
-        { "-nzero", FALSE, etINT,
+        { "-nzero",
+          FALSE,
+          etINT,
           { &nzero },
           "If the -sep flag is set, use these many digits "
           "for the file numbers and prepend zeros as needed" },
-        { "-dropunder", FALSE, etREAL,
-          { &dropunder }, "Drop all frames below this value" },
-        { "-dropover", FALSE, etREAL,
-          { &dropover }, "Drop all frames above this value" },
-        { "-conect", FALSE, etBOOL,
+        { "-dropunder", FALSE, etREAL, { &dropunder }, "Drop all frames below this value" },
+        { "-dropover", FALSE, etREAL, { &dropover }, "Drop all frames above this value" },
+        { "-conect",
+          FALSE,
+          etBOOL,
           { &bCONECT },
-          "Add conect records when writing [REF].pdb[ref] files. Useful "
+          "Add CONECT PDB records when writing [REF].pdb[ref] files. Useful "
           "for visualization of non-standard molecules, e.g. "
           "coarse grained ones" }
     };
 #define NPA asize(pa)
 
-    FILE             *out    = nullptr;
-    t_trxstatus      *trxout = nullptr;
-    t_trxstatus      *trxin;
-    int               file_nr;
-    t_trxframe        fr, frout;
-    int               flags;
-    rvec             *xmem  = nullptr, *vmem = nullptr, *fmem = nullptr;
-    rvec             *xp    = nullptr, x_shift, hbox;
-    real             *w_rls = nullptr;
-    int               m, i, d, frame, outframe, natoms, nout, ncent, newstep = 0, model_nr;
+    FILE*        out    = nullptr;
+    t_trxstatustrxout = nullptr;
+    t_trxstatustrxin;
+    int          file_nr;
+    t_trxframe   fr, frout;
+    int          flags;
+    rvec *       xmem = nullptr, *vmem = nullptr, *fmem = nullptr;
+    rvec *       xp    = nullptr, x_shift, hbox;
+    real*        w_rls = nullptr;
+    int          m, i, d, frame, outframe, natoms, nout, ncent, newstep = 0, model_nr;
 #define SKIP 10
-    t_topology       *top   = nullptr;
-    gmx_conect        gc    = nullptr;
-    int               ePBC  = -1;
-    t_atoms          *atoms = nullptr, useatoms;
-    matrix            top_box;
-    int              *index = nullptr, *cindex = nullptr;
-    char             *grpnm = nullptr;
-    int              *frindex, nrfri;
-    char             *frname;
-    int               ifit;
-    int              *ind_fit;
-    char             *gn_fit;
-    int               ndrop           = 0, ncol, drop0 = 0, drop1 = 0, dropuse = 0;
-    double          **dropval;
-    real              tshift = 0, dt = -1, prec;
-    gmx_bool          bFit, bPFit, bReset;
-    int               nfitdim;
-    gmx_rmpbc_t       gpbc = nullptr;
-    gmx_bool          bRmPBC, bPBCWhole, bPBCcomRes, bPBCcomMol, bPBCcomAtom, bPBC, bNoJump, bCluster;
-    gmx_bool          bCopy, bDoIt, bIndex, bTDump, bSetTime, bTPS = FALSE, bDTset = FALSE;
-    gmx_bool          bExec, bTimeStep = FALSE, bDumpFrame = FALSE, bSetXtcPrec, bNeedPrec;
-    gmx_bool          bHaveFirstFrame, bHaveNextFrame, bSetBox, bSetUR, bSplit = FALSE;
-    gmx_bool          bDropUnder = FALSE, bDropOver = FALSE, bTrans = FALSE;
-    gmx_bool          bWriteFrame, bSplitHere;
-    const char       *top_file, *in_file, *out_file = nullptr;
-    char              out_file2[256], *charpt;
-    char             *outf_base = nullptr;
-    const char       *outf_ext  = nullptr;
-    char              top_title[256], timestr[32], stepstr[32], filemode[5];
-    gmx_output_env_t *oenv;
-
-    t_filenm          fnm[] = {
-        { efTRX, "-f",   nullptr,      ffREAD  },
-        { efTRO, "-o",   nullptr,      ffWRITE },
-        { efTPS, nullptr,   nullptr,      ffOPTRD },
-        { efNDX, nullptr,   nullptr,      ffOPTRD },
-        { efNDX, "-fr",  "frames",  ffOPTRD },
-        { efNDX, "-sub", "cluster", ffOPTRD },
-        { efXVG, "-drop", "drop",    ffOPTRD }
-    };
+    t_topology* top     = nullptr;
+    gmx_conect  gc      = nullptr;
+    PbcType     pbcType = PbcType::Unset;
+    t_atoms *   atoms   = nullptr, useatoms;
+    matrix      top_box;
+    int *       index = nullptr, *cindex = nullptr;
+    char*       grpnm = nullptr;
+    int *       frindex, nrfri;
+    char*       frname;
+    int         ifit;
+    int*        ind_fit;
+    char*       gn_fit;
+    int         ndrop = 0, ncol, drop0 = 0, drop1 = 0, dropuse = 0;
+    double**    dropval;
+    real        tshift = 0, dt = -1, prec;
+    gmx_bool    bFit, bPFit, bReset;
+    int         nfitdim;
+    gmx_rmpbc_t gpbc = nullptr;
+    gmx_bool    bRmPBC, bPBCWhole, bPBCcomRes, bPBCcomMol, bPBCcomAtom, bPBC, bNoJump, bCluster;
+    gmx_bool    bCopy, bDoIt, bIndex, bTDump, bSetTime, bTPS = FALSE, bDTset = FALSE;
+    gmx_bool    bExec, bTimeStep = FALSE, bDumpFrame = FALSE, bSetXtcPrec, bNeedPrec;
+    gmx_bool    bHaveFirstFrame, bHaveNextFrame, bSetBox, bSetUR, bSplit = FALSE;
+    gmx_bool    bDropUnder = FALSE, bDropOver = FALSE, bTrans = FALSE;
+    gmx_bool    bWriteFrame, bSplitHere;
+    const char *top_file, *in_file, *out_file = nullptr;
+    char        out_file2[256], *charpt;
+    char*       outf_base = nullptr;
+    const char* outf_ext  = nullptr;
+    char        top_title[256], timestr[32], stepstr[32], filemode[5];
+    gmx_output_env_t* oenv;
+
+    t_filenm fnm[] = { { efTRX, "-f", nullptr, ffREAD },     { efTRO, "-o", nullptr, ffWRITE },
+                       { efTPS, nullptr, nullptr, ffOPTRD }, { efNDX, nullptr, nullptr, ffOPTRD },
+                       { efNDX, "-fr", "frames", ffOPTRD },  { efNDX, "-sub", "cluster", ffOPTRD },
+                       { efXVG, "-drop", "drop", ffOPTRD } };
 #define NFILE asize(fnm)
 
-    if (!parse_common_args(&argc, argv,
-                           PCA_CAN_BEGIN | PCA_CAN_END | PCA_CAN_VIEW |
-                           PCA_TIME_UNIT,
-                           NFILE, fnm, NPA, pa, asize(desc), desc,
-                           0, nullptr, &oenv))
+    if (!parse_common_args(&argc,
+                           argv,
+                           PCA_CAN_BEGIN | PCA_CAN_END | PCA_CAN_VIEW | PCA_TIME_UNIT,
+                           NFILE,
+                           fnm,
+                           NPA,
+                           pa,
+                           asize(desc),
+                           desc,
+                           0,
+                           nullptr,
+                           &oenv))
     {
         return 0;
     }
-    fprintf(stdout, "Note that major changes are planned in future for "
+    fprintf(stdout,
+            "Note that major changes are planned in future for "
             "trjconv, to improve usability and utility.\n");
 
     top_file = ftp2fn(efTPS, NFILE, fnm);
@@ -594,11 +590,11 @@ int gmx_trjconv(int argc, char *argv[])
         /* set and check option dependencies */
         if (bPFit)
         {
-            bFit = TRUE;        /* for pfit, fit *must* be set */
+            bFit = TRUE; /* for pfit, fit *must* be set */
         }
         if (bFit)
         {
-            bReset = TRUE;       /* for fit, reset *must* be set */
+            bReset = TRUE; /* for fit, reset *must* be set */
         }
         nfitdim = 0;
         if (bFit || bReset)
@@ -609,21 +605,27 @@ int gmx_trjconv(int argc, char *argv[])
 
         if (bSetUR)
         {
-            if (!(bPBCcomRes || bPBCcomMol ||  bPBCcomAtom))
+            if (!(bPBCcomRes || bPBCcomMol || bPBCcomAtom))
             {
                 fprintf(stderr,
                         "WARNING: Option for unitcell representation (-ur %s)\n"
                         "         only has effect in combination with -pbc %s, %s or %s.\n"
                         "         Ingoring unitcell representation.\n\n",
-                        unitcell_opt[0], pbc_opt[2], pbc_opt[3], pbc_opt[4]);
+                        unitcell_opt[0],
+                        pbc_opt[2],
+                        pbc_opt[3],
+                        pbc_opt[4]);
             }
         }
         if (bFit && bPBC)
         {
-            gmx_fatal(FARGS, "PBC condition treatment does not work together with rotational fit.\n"
-                      "Please do the PBC condition treatment first and then run trjconv in a second step\n"
+            gmx_fatal(FARGS,
+                      "PBC condition treatment does not work together with rotational fit.\n"
+                      "Please do the PBC condition treatment first and then run trjconv in a "
+                      "second step\n"
                       "for the rotational fit.\n"
-                      "First doing the rotational fit and then doing the PBC treatment gives incorrect\n"
+                      "First doing the rotational fit and then doing the PBC treatment gives "
+                      "incorrect\n"
                       "results!");
         }
 
@@ -646,10 +648,9 @@ int gmx_trjconv(int argc, char *argv[])
         if (bVels)
         {
             /* check if velocities are possible in input and output files */
-            bVels = (ftp == efTRR || ftp == efGRO ||
-                     ftp == efG96 || ftp == efTNG)
-                && (ftpin == efTRR || ftpin == efGRO ||
-                    ftpin == efG96 || ftpin == efTNG || ftpin == efCPT);
+            bVels = (ftp == efTRR || ftp == efGRO || ftp == efG96 || ftp == efTNG)
+                    && (ftpin == efTRR || ftpin == efGRO || ftpin == efG96 || ftpin == efTNG
+                        || ftpin == efCPT);
         }
         if (bSeparate || bSplit)
         {
@@ -658,14 +659,15 @@ int gmx_trjconv(int argc, char *argv[])
             {
                 gmx_fatal(FARGS, "Output file name '%s' does not contain a '.'", out_file);
             }
-            outf_base = gmx_strdup(out_file);
+            outf_base                      = gmx_strdup(out_file);
             outf_base[outf_ext - out_file] = '\0';
         }
 
         bool bSubTraj = opt2bSet("-sub", NFILE, fnm);
         if (bSubTraj)
         {
-            gmx_fatal(FARGS, "The -sub option has been removed from gmx trjconv and is now part\n"
+            gmx_fatal(FARGS,
+                      "The -sub option has been removed from gmx trjconv and is now part\n"
                       "of gmx extract-cluster and does nothing here\n");
         }
 
@@ -678,9 +680,8 @@ int gmx_trjconv(int argc, char *argv[])
         std::unique_ptr<gmx_mtop_t> mtop = read_mtop_for_tng(top_file, in_file, out_file);
 
         /* Determine whether to read a topology */
-        bTPS = (ftp2bSet(efTPS, NFILE, fnm) ||
-                bRmPBC || bReset || bPBCcomMol || bCluster ||
-                (ftp == efGRO) || (ftp == efPDB) || bCONECT);
+        bTPS = (ftp2bSet(efTPS, NFILE, fnm) || bRmPBC || bReset || bPBCcomMol || bCluster
+                || (ftp == efGRO) || (ftp == efPDB) || bCONECT);
 
         /* Determine if when can read index groups */
         bIndex = (bIndex || bTPS);
@@ -688,8 +689,7 @@ int gmx_trjconv(int argc, char *argv[])
         if (bTPS)
         {
             snew(top, 1);
-            read_tps_conf(top_file, top, &ePBC, &xp, nullptr, top_box,
-                          bReset || bPBCcomRes);
+            read_tps_conf(top_file, top, &pbcType, &xp, nullptr, top_box, bReset || bPBCcomRes);
             std::strncpy(top_title, *top->name, 255);
             top_title[255] = '\0';
             atoms          = &top->atoms;
@@ -721,7 +721,7 @@ int gmx_trjconv(int argc, char *argv[])
             }
             if (bRmPBC)
             {
-                gpbc = gmx_rmpbc_init(&top->idef, ePBC, top->atoms.nr);
+                gpbc = gmx_rmpbc_init(&top->idef, pbcType, top->atoms.nr);
             }
         }
 
@@ -743,10 +743,8 @@ int gmx_trjconv(int argc, char *argv[])
         /* get index groups etc. */
         if (bReset)
         {
-            printf("Select group for %s fit\n",
-                   bFit ? "least squares" : "translational");
-            get_index(atoms, ftp2fn_null(efNDX, NFILE, fnm),
-                      1, &ifit, &ind_fit, &gn_fit);
+            printf("Select group for %s fit\n", bFit ? "least squares" : "translational");
+            get_index(atoms, ftp2fn_null(efNDX, NFILE, fnm), 1, &ifit, &ind_fit, &gn_fit);
 
             if (bFit)
             {
@@ -763,8 +761,7 @@ int gmx_trjconv(int argc, char *argv[])
         else if (bCluster)
         {
             printf("Select group for clustering\n");
-            get_index(atoms, ftp2fn_null(efNDX, NFILE, fnm),
-                      1, &ifit, &ind_fit, &gn_fit);
+            get_index(atoms, ftp2fn_null(efNDX, NFILE, fnm), 1, &ifit, &ind_fit, &gn_fit);
         }
 
         if (bIndex)
@@ -772,12 +769,10 @@ int gmx_trjconv(int argc, char *argv[])
             if (bCenter)
             {
                 printf("Select group for centering\n");
-                get_index(atoms, ftp2fn_null(efNDX, NFILE, fnm),
-                          1, &ncent, &cindex, &grpnm);
+                get_index(atoms, ftp2fn_null(efNDX, NFILE, fnm), 1, &ncent, &cindex, &grpnm);
             }
             printf("Select group for output\n");
-            get_index(atoms, ftp2fn_null(efNDX, NFILE, fnm),
-                      1, &nout, &index, &grpnm);
+            get_index(atoms, ftp2fn_null(efNDX, NFILE, fnm), 1, &nout, &index, &grpnm);
         }
         else
         {
@@ -833,8 +828,7 @@ int gmx_trjconv(int argc, char *argv[])
             fprintf(stderr, " %d time points\n", ndrop);
             if (ndrop == 0 || ncol < 2)
             {
-                gmx_fatal(FARGS, "Found no data points in %s",
-                          opt2fn("-drop", NFILE, fnm));
+                gmx_fatal(FARGS, "Found no data points in %s", opt2fn("-drop", NFILE, fnm));
             }
             drop0 = 0;
             drop1 = 0;
@@ -855,9 +849,9 @@ int gmx_trjconv(int argc, char *argv[])
                 useatoms.atom[i]     = atoms->atom[index[i]];
                 if (atoms->havePdbInfo)
                 {
-                    useatoms.pdbinfo[i]  = atoms->pdbinfo[index[i]];
+                    useatoms.pdbinfo[i] = atoms->pdbinfo[index[i]];
                 }
-                useatoms.nres        = std::max(useatoms.nres, useatoms.atom[i].resind+1);
+                useatoms.nres = std::max(useatoms.nres, useatoms.atom[i].resind + 1);
             }
             useatoms.nr = nout;
         }
@@ -883,17 +877,17 @@ int gmx_trjconv(int argc, char *argv[])
         bHaveFirstFrame = read_first_frame(oenv, &trxin, in_file, &fr, flags);
         if (fr.bPrec)
         {
-            fprintf(stderr, "\nPrecision of %s is %g (nm)\n", in_file, 1/fr.prec);
+            fprintf(stderr, "\nPrecision of %s is %g (nm)\n", in_file, 1 / fr.prec);
         }
         if (bNeedPrec)
         {
             if (bSetXtcPrec || !fr.bPrec)
             {
-                fprintf(stderr, "\nSetting output precision to %g (nm)\n", 1/prec);
+                fprintf(stderr, "\nSetting output precision to %g (nm)\n", 1 / prec);
             }
             else
             {
-                fprintf(stderr, "Using output precision of %g (nm)\n", 1/prec);
+                fprintf(stderr, "Using output precision of %g (nm)\n", 1 / prec);
             }
         }
 
@@ -911,7 +905,9 @@ int gmx_trjconv(int argc, char *argv[])
                     bDTset = TRUE;
                     if (dt <= 0)
                     {
-                        fprintf(stderr, "Warning: Frame times are not incrementing - will dump first frame.\n");
+                        fprintf(stderr,
+                                "Warning: Frame times are not incrementing - will dump first "
+                                "frame.\n");
                     }
                 }
                 // Now close and reopen so we are at first frame again
@@ -921,12 +917,12 @@ int gmx_trjconv(int argc, char *argv[])
                 read_first_frame(oenv, &trxin, in_file, &fr, flags);
             }
 
-            set_trxframe_ePBC(&fr, ePBC);
+            setTrxFramePbcType(&fr, pbcType);
             natoms = fr.natoms;
 
             if (bSetTime)
             {
-                tshift = tzero-fr.time;
+                tshift = tzero - fr.time;
             }
             else
             {
@@ -944,7 +940,10 @@ int gmx_trjconv(int argc, char *argv[])
                         gmx_fatal(FARGS,
                                   "Index[%d] %d is larger than the number of atoms in the\n"
                                   "trajectory file (%d). There is a mismatch in the contents\n"
-                                  "of your -f, -s and/or -n files.", i, index[i]+1, natoms);
+                                  "of your -f, -s and/or -n files.",
+                                  i,
+                                  index[i] + 1,
+                                  natoms);
                     }
                     bCopy = bCopy || (i != index[i]);
                 }
@@ -980,8 +979,7 @@ int gmx_trjconv(int argc, char *argv[])
                         out = gmx_ffopen(out_file, filemode);
                     }
                     break;
-                default:
-                    gmx_incons("Illegal output file format");
+                default: gmx_incons("Illegal output file format");
             }
 
             if (bCopy)
@@ -998,10 +996,10 @@ int gmx_trjconv(int argc, char *argv[])
             }
 
             /* Start the big loop over frames */
-            file_nr  =  0;
-            frame    =  0;
-            outframe =  0;
-            model_nr =  0;
+            file_nr  = 0;
+            frame    = 0;
+            outframe = 0;
+            model_nr = 0;
 
             /* Main loop over frames */
             do
@@ -1061,7 +1059,7 @@ int gmx_trjconv(int argc, char *argv[])
                         // and we have overrun the frame time. Once we dump one
                         // frame based on time we quit, so it does not matter
                         // that this might be true for all subsequent frames too.
-                        bDumpFrame = (fr.time > tdump-0.5*dt);
+                        bDumpFrame = (fr.time > tdump - 0.5 * dt);
                     }
                 }
                 else
@@ -1074,7 +1072,7 @@ int gmx_trjconv(int argc, char *argv[])
                 {
                     for (d = 0; d < DIM; d++)
                     {
-                        hbox[d] = 0.5*fr.box[d][d];
+                        hbox[d] = 0.5 * fr.box[d][d];
                     }
                     for (i = 0; i < natoms; i++)
                     {
@@ -1082,18 +1080,18 @@ int gmx_trjconv(int argc, char *argv[])
                         {
                             rvec_dec(fr.x[i], x_shift);
                         }
-                        for (m = DIM-1; m >= 0; m--)
+                        for (m = DIM - 1; m >= 0; m--)
                         {
                             if (hbox[m] > 0)
                             {
-                                while (fr.x[i][m]-xp[i][m] <= -hbox[m])
+                                while (fr.x[i][m] - xp[i][m] <= -hbox[m])
                                 {
                                     for (d = 0; d <= m; d++)
                                     {
                                         fr.x[i][d] += fr.box[m][d];
                                     }
                                 }
-                                while (fr.x[i][m]-xp[i][m] > hbox[m])
+                                while (fr.x[i][m] - xp[i][m] > hbox[m])
                                 {
                                     for (d = 0; d <= m; d++)
                                     {
@@ -1106,7 +1104,7 @@ int gmx_trjconv(int argc, char *argv[])
                 }
                 else if (bCluster)
                 {
-                    calc_pbc_cluster(ecenter, ifit, top, ePBC, fr.x, ind_fit, fr.box);
+                    calc_pbc_cluster(ecenter, ifit, top, pbcType, fr.x, ind_fit, fr.box);
                 }
 
                 if (bPFit)
@@ -1149,18 +1147,16 @@ int gmx_trjconv(int argc, char *argv[])
                     fprintf(debug, "dumping %d\n", frame);
                 }
 
-                bWriteFrame =
-                    ( ( !bTDump && (frindex == nullptr) && frame % skip_nr == 0 ) || bDumpFrame );
+                bWriteFrame = ((!bTDump && (frindex == nullptr) && frame % skip_nr == 0) || bDumpFrame);
 
                 if (bWriteFrame && (bDropUnder || bDropOver))
                 {
-                    while (dropval[0][drop1] < fr.time && drop1+1 < ndrop)
+                    while (dropval[0][drop1] < fr.time && drop1 + 1 < ndrop)
                     {
                         drop0 = drop1;
                         drop1++;
                     }
-                    if (std::abs(dropval[0][drop0] - fr.time)
-                        < std::abs(dropval[0][drop1] - fr.time))
+                    if (std::abs(dropval[0][drop0] - fr.time) < std::abs(dropval[0][drop1] - fr.time))
                     {
                         dropuse = drop0;
                     }
@@ -1168,8 +1164,8 @@ int gmx_trjconv(int argc, char *argv[])
                     {
                         dropuse = drop1;
                     }
-                    if ((bDropUnder && dropval[1][dropuse] < dropunder) ||
-                        (bDropOver && dropval[1][dropuse] > dropover))
+                    if ((bDropUnder && dropval[1][dropuse] < dropunder)
+                        || (bDropOver && dropval[1][dropuse] > dropover))
                     {
                         bWriteFrame = FALSE;
                     }
@@ -1188,7 +1184,7 @@ int gmx_trjconv(int argc, char *argv[])
                     /* calc new time */
                     if (bTimeStep)
                     {
-                        frout_time = tzero + frame*timestep;
+                        frout_time = tzero + frame * timestep;
                     }
                     else if (bSetTime)
                     {
@@ -1197,8 +1193,10 @@ int gmx_trjconv(int argc, char *argv[])
 
                     if (bTDump)
                     {
-                        fprintf(stderr, "\nDumping frame at t= %g %s\n",
-                                output_env_conv_time(oenv, frout_time), output_env_get_time_unit(oenv).c_str());
+                        fprintf(stderr,
+                                "\nDumping frame at t= %g %s\n",
+                                output_env_conv_time(oenv, frout_time),
+                                output_env_get_time_unit(oenv).c_str());
                     }
 
                     /* check for writing at each delta_t */
@@ -1212,18 +1210,21 @@ int gmx_trjconv(int argc, char *argv[])
                         else
                         {
                             /* round() is not C89 compatible, so we do this:  */
-                            bDoIt = bRmod(std::floor(frout_time+0.5), std::floor(tzero+0.5),
-                                          std::floor(delta_t+0.5));
+                            bDoIt = bRmod(std::floor(frout_time + 0.5),
+                                          std::floor(tzero + 0.5),
+                                          std::floor(delta_t + 0.5));
                         }
                     }
 
                     if (bDoIt || bTDump)
                     {
                         /* print sometimes */
-                        if ( ((outframe % SKIP) == 0) || (outframe < SKIP) )
+                        if (((outframe % SKIP) == 0) || (outframe < SKIP))
                         {
-                            fprintf(stderr, " ->  frame %6d time %8.3f      \r",
-                                    outframe, output_env_conv_time(oenv, frout_time));
+                            fprintf(stderr,
+                                    " ->  frame %6d time %8.3f      \r",
+                                    outframe,
+                                    output_env_conv_time(oenv, frout_time));
                             fflush(stderr);
                         }
 
@@ -1259,33 +1260,33 @@ int gmx_trjconv(int argc, char *argv[])
                             }
                         }
 
-                        auto positionsArrayRef = gmx::arrayRefFromArray(reinterpret_cast<gmx::RVec *>(fr.x), natoms);
+                        auto positionsArrayRef =
+                                gmx::arrayRefFromArray(reinterpret_cast<gmx::RVec*>(fr.x), natoms);
                         if (bPBCcomAtom)
                         {
                             switch (unitcell_enum)
                             {
                                 case euRect:
-                                    put_atoms_in_box(ePBC, fr.box, positionsArrayRef);
+                                    put_atoms_in_box(pbcType, fr.box, positionsArrayRef);
                                     break;
                                 case euTric:
                                     put_atoms_in_triclinic_unitcell(ecenter, fr.box, positionsArrayRef);
                                     break;
                                 case euCompact:
-                                    put_atoms_in_compact_unitcell(ePBC, ecenter, fr.box,
-                                                                  positionsArrayRef);
+                                    put_atoms_in_compact_unitcell(
+                                            pbcType, ecenter, fr.box, positionsArrayRef);
                                     break;
                             }
                         }
                         if (bPBCcomRes)
                         {
-                            put_residue_com_in_box(unitcell_enum, ecenter,
-                                                   natoms, atoms->atom, ePBC, fr.box, fr.x);
+                            put_residue_com_in_box(
+                                    unitcell_enum, ecenter, natoms, atoms->atom, pbcType, fr.box, fr.x);
                         }
                         if (bPBCcomMol)
                         {
-                            put_molecule_com_in_box(unitcell_enum, ecenter,
-                                                    &top->mols,
-                                                    natoms, atoms->atom, ePBC, fr.box, fr.x);
+                            put_molecule_com_in_box(
+                                    unitcell_enum, ecenter, &top->mols, natoms, atoms->atom, pbcType, fr.box, fr.x);
                         }
                         /* Copy the input trxframe struct to the output trxframe struct */
                         frout        = fr;
@@ -1329,7 +1330,7 @@ int gmx_trjconv(int argc, char *argv[])
                             {
                                 for (d = 0; d < DIM; d++)
                                 {
-                                    frout.x[i][d] += outframe*shift[d];
+                                    frout.x[i][d] += outframe * shift[d];
                                 }
                             }
                         }
@@ -1341,9 +1342,10 @@ int gmx_trjconv(int argc, char *argv[])
                         else
                         {
                             /* round() is not C89 compatible, so we do this: */
-                            bSplitHere = bSplit && bRmod(std::floor(frout.time+0.5),
-                                                         std::floor(tzero+0.5),
-                                                         std::floor(split_t+0.5));
+                            bSplitHere = bSplit
+                                         && bRmod(std::floor(frout.time + 0.5),
+                                                  std::floor(tzero + 0.5),
+                                                  std::floor(split_t + 0.5));
                         }
                         if (bSeparate || bSplitHere)
                         {
@@ -1402,8 +1404,12 @@ int gmx_trjconv(int argc, char *argv[])
                                 switch (ftp)
                                 {
                                     case efGRO:
-                                        write_hconf_p(out, title.c_str(), &useatoms,
-                                                      frout.x, frout.bV ? frout.v : nullptr, frout.box);
+                                        write_hconf_p(out,
+                                                      title.c_str(),
+                                                      &useatoms,
+                                                      frout.x,
+                                                      frout.bV ? frout.v : nullptr,
+                                                      frout.box);
                                         break;
                                     case efPDB:
                                         fprintf(out, "REMARK    GENERATED BY TRJCONV\n");
@@ -1418,11 +1424,18 @@ int gmx_trjconv(int argc, char *argv[])
                                         {
                                             model_nr++;
                                         }
-                                        write_pdbfile(out, title.c_str(), &useatoms, frout.x,
-                                                      frout.ePBC, frout.box, ' ', model_nr, gc);
+                                        write_pdbfile(out,
+                                                      title.c_str(),
+                                                      &useatoms,
+                                                      frout.x,
+                                                      frout.pbcType,
+                                                      frout.box,
+                                                      ' ',
+                                                      model_nr,
+                                                      gc);
                                         break;
                                     case efG96:
-                                        const char *outputTitle = "";
+                                        const charoutputTitle = "";
                                         if (bSeparate || bTDump)
                                         {
                                             outputTitle = title.c_str();
@@ -1430,9 +1443,9 @@ int gmx_trjconv(int argc, char *argv[])
                                             {
                                                 frout.bAtoms = TRUE;
                                             }
-                                            frout.atoms  = &useatoms;
-                                            frout.bStep  = FALSE;
-                                            frout.bTime  = FALSE;
+                                            frout.atoms = &useatoms;
+                                            frout.bStep = FALSE;
+                                            frout.bTime = FALSE;
                                         }
                                         else
                                         {
@@ -1452,8 +1465,7 @@ int gmx_trjconv(int argc, char *argv[])
                                     out = nullptr;
                                 }
                                 break;
-                            default:
-                                gmx_fatal(FARGS, "DHE, ftp=%d\n", ftp);
+                            default: gmx_fatal(FARGS, "DHE, ftp=%d\n", ftp);
                         }
                         if (bSeparate || bSplitHere)
                         {
@@ -1464,7 +1476,7 @@ int gmx_trjconv(int argc, char *argv[])
                         if (bExec)
                         {
                             char c[255];
-                            sprintf(c, "%s  %d", exec_command, file_nr-1);
+                            sprintf(c, "%s  %d", exec_command, file_nr - 1);
                             /*fprintf(stderr,"Executing '%s'\n",c);*/
                             if (0 != system(c))
                             {
@@ -1476,14 +1488,15 @@ int gmx_trjconv(int argc, char *argv[])
                 }
                 frame++;
                 bHaveNextFrame = read_next_frame(oenv, trxin, &fr);
-            }
-            while (!(bTDump && bDumpFrame) && bHaveNextFrame);
+            } while (!(bTDump && bDumpFrame) && bHaveNextFrame);
         }
 
         if (!bHaveFirstFrame || (bTDump && !bDumpFrame))
         {
-            fprintf(stderr, "\nWARNING no output, "
-                    "last frame read at t=%g\n", fr.time);
+            fprintf(stderr,
+                    "\nWARNING no output, "
+                    "last frame read at t=%g\n",
+                    fr.time);
         }
         fprintf(stderr, "\n");