Manually sort some includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / gmxana / gmx_trjconv.c
index db0e1fa94a32ef5fd5a78eb54c3041145ab1c1a4..f0aa6b5d808eac396d8d787f63fc9cb64717fcf8 100644 (file)
  * To help us fund GROMACS development, we humbly ask that you cite
  * the research papers on the package. Check out http://www.gromacs.org.
  */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "gmxpre.h"
 
-#include <string.h>
 #include <math.h>
+#include <stdlib.h>
+#include <string.h>
 
-#include "copyrite.h"
-#include "macros.h"
-#include "sysstuff.h"
-#include "smalloc.h"
-#include "typedefs.h"
-#include "gromacs/fileio/gmxfio.h"
-#include "gromacs/fileio/tpxio.h"
-#include "gromacs/fileio/trxio.h"
-#include "gromacs/fileio/trnio.h"
-#include "gromacs/fileio/tngio_for_tools.h"
-#include "gromacs/commandline/pargs.h"
-#include "gromacs/fileio/futil.h"
-#include "gromacs/fileio/pdbio.h"
-#include "gromacs/fileio/confio.h"
-#include "names.h"
-#include "index.h"
-#include "vec.h"
-#include "gromacs/fileio/xtcio.h"
-#include "do_fit.h"
-#include "rmpbc.h"
-#include "gromacs/fileio/g87io.h"
-#include "pbc.h"
-#include "viewit.h"
-#include "xvgr.h"
-#include "gmx_ana.h"
+#include "config.h"
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
+#include "gromacs/commandline/pargs.h"
+#include "gromacs/fileio/confio.h"
+#include "gromacs/fileio/gmxfio.h"
+#include "gromacs/fileio/pdbio.h"
+#include "gromacs/fileio/tngio_for_tools.h"
+#include "gromacs/fileio/tpxio.h"
+#include "gromacs/fileio/trnio.h"
+#include "gromacs/fileio/trxio.h"
+#include "gromacs/fileio/xtcio.h"
+#include "gromacs/fileio/xvgr.h"
+#include "gromacs/gmxana/gmx_ana.h"
+#include "gromacs/legacyheaders/copyrite.h"
+#include "gromacs/legacyheaders/macros.h"
+#include "gromacs/legacyheaders/names.h"
+#include "gromacs/legacyheaders/typedefs.h"
+#include "gromacs/legacyheaders/viewit.h"
+#include "gromacs/math/do_fit.h"
+#include "gromacs/math/vec.h"
+#include "gromacs/pbcutil/pbc.h"
+#include "gromacs/pbcutil/rmpbc.h"
+#include "gromacs/topology/index.h"
+#include "gromacs/topology/topology.h"
+#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/futil.h"
+#include "gromacs/utility/smalloc.h"
+
 enum {
     euSel, euRect, euTric, euCompact, euNR
 };
@@ -468,7 +469,7 @@ static void mk_filenm(char *base, const char *ext, int ndigit, int file_nr,
 
 void check_trn(const char *fn)
 {
-    if ((fn2ftp(fn) != efTRJ)  && (fn2ftp(fn) != efTRR))
+    if (fn2ftp(fn) != efTRR)
     {
         gmx_fatal(FARGS, "%s is not a trajectory file, exiting\n", fn);
     }
@@ -491,7 +492,7 @@ void do_trunc(const char *fn, real t0)
         gmx_fatal(FARGS, "You forgot to set the truncation time");
     }
 
-    /* Check whether this is a .trj file */
+    /* Check whether this is a .trr file */
     check_trn(fn);
 
     in   = open_trn(fn, "r");
@@ -592,45 +593,40 @@ int gmx_trjconv(int argc, char *argv[])
 {
     const char *desc[] = {
         "[THISMODULE] can convert trajectory files in many ways:[BR]",
-        "[BB]1.[bb] from one format to another[BR]",
-        "[BB]2.[bb] select a subset of atoms[BR]",
-        "[BB]3.[bb] change the periodicity representation[BR]",
-        "[BB]4.[bb] keep multimeric molecules together[BR]",
-        "[BB]5.[bb] center atoms in the box[BR]",
-        "[BB]6.[bb] fit atoms to reference structure[BR]",
-        "[BB]7.[bb] reduce the number of frames[BR]",
-        "[BB]8.[bb] change the timestamps of the frames ",
+        "* from one format to another[BR]",
+        "* select a subset of atoms[BR]",
+        "* change the periodicity representation[BR]",
+        "* keep multimeric molecules together[BR]",
+        "* center atoms in the box[BR]",
+        "* fit atoms to reference structure[BR]",
+        "* reduce the number of frames[BR]",
+        "* change the timestamps of the frames ",
         "([TT]-t0[tt] and [TT]-timestep[tt])[BR]",
-        "[BB]9.[bb] cut the trajectory in small subtrajectories according",
+        "* cut the trajectory in small subtrajectories according",
         "to information in an index file. This allows subsequent analysis of",
         "the subtrajectories that could, for example, be the result of a",
         "cluster analysis. Use option [TT]-sub[tt].",
         "This assumes that the entries in the index file are frame numbers and",
         "dumps each group in the index file to a separate trajectory file.[BR]",
-        "[BB]10.[bb] select frames within a certain range of a quantity given",
+        "* select frames within a certain range of a quantity given",
         "in an [TT].xvg[tt] file.[PAR]",
 
         "[gmx-trjcat] is better suited for concatenating multiple trajectory files.",
         "[PAR]",
 
-        "Currently seven formats are supported for input and output:",
-        "[TT].xtc[tt], [TT].trr[tt], [TT].trj[tt], [TT].gro[tt], [TT].g96[tt],",
-        "[TT].pdb[tt] and [TT].g87[tt].",
+        "The following formats are supported for input and output:",
+        "[TT].xtc[tt], [TT].trr[tt], [TT].gro[tt], [TT].g96[tt]",
+        "and [TT].pdb[tt].",
         "The file formats are detected from the file extension.",
         "The precision of [TT].xtc[tt] and [TT].gro[tt] output is taken from the",
         "input file for [TT].xtc[tt], [TT].gro[tt] and [TT].pdb[tt],",
         "and from the [TT]-ndec[tt] option for other input formats. The precision",
         "is always taken from [TT]-ndec[tt], when this option is set.",
-        "All other formats have fixed precision. [TT].trr[tt] and [TT].trj[tt]",
+        "All other formats have fixed precision. [TT].trr[tt]",
         "output can be single or double precision, depending on the precision",
         "of the [THISMODULE] binary.",
         "Note that velocities are only supported in",
-        "[TT].trr[tt], [TT].trj[tt], [TT].gro[tt] and [TT].g96[tt] files.[PAR]",
-
-        "Option [TT]-app[tt] can be used to",
-        "append output to an existing trajectory file.",
-        "No checks are performed to ensure integrity",
-        "of the resulting combined trajectory file.[PAR]",
+        "[TT].trr[tt], [TT].gro[tt] 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 [TT].pdb[tt] file. By default, all frames all written to one file.",
@@ -701,6 +697,10 @@ int gmx_trjconv(int argc, char *argv[])
         "Use option [TT]-pbc mol[tt] in addition to [TT]-center[tt] when you",
         "want all molecules in the box after the centering.[PAR]",
 
+        "Option [TT]-box[tt] sets the size of the new box. If you want to"
+        "modify only some of the dimensions, e.g. when reading from a trajectory,"
+        "you can use -1 for those dimensions that should stay the same"
+
         "It is not always possible to use combinations of [TT]-pbc[tt],",
         "[TT]-fit[tt], [TT]-ur[tt] and [TT]-center[tt] to do exactly what",
         "you want in one call to [THISMODULE]. Consider using multiple",
@@ -714,7 +714,7 @@ int gmx_trjconv(int argc, char *argv[])
         "can reduce the number of frames while using low-pass frequency",
         "filtering, this reduces aliasing of high frequency motions.[PAR]",
 
-        "Using [TT]-trunc[tt] [THISMODULE] can truncate [TT].trj[tt] in place, i.e.",
+        "Using [TT]-trunc[tt] [THISMODULE] can truncate [TT].trr[tt] in place, i.e.",
         "without copying the file. This is useful when a run has crashed",
         "during disk I/O (i.e. full disk), or when two contiguous",
         "trajectories must be concatenated without having double frames.[PAR]",
@@ -770,7 +770,7 @@ int gmx_trjconv(int argc, char *argv[])
         "progressive", NULL
     };
 
-    static gmx_bool  bAppend       = FALSE, bSeparate = FALSE, bVels = TRUE, bForce = FALSE, bCONECT = FALSE;
+    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;
@@ -837,8 +837,6 @@ int gmx_trjconv(int argc, char *argv[])
           { &exec_command },
           "Execute command for every output frame with the "
           "frame number as argument" },
-        { "-app", FALSE, etBOOL,
-          { &bAppend }, "Append output" },
         { "-split", FALSE, etTIME,
           { &split_t },
           "Start writing new file when t MOD split = first "
@@ -927,7 +925,7 @@ int gmx_trjconv(int argc, char *argv[])
 
     if (!parse_common_args(&argc, argv,
                            PCA_CAN_BEGIN | PCA_CAN_END | PCA_CAN_VIEW |
-                           PCA_TIME_UNIT | PCA_BE_NICE,
+                           PCA_TIME_UNIT,
                            NFILE, fnm, NPA, pa, asize(desc), desc,
                            0, NULL, &oenv))
     {
@@ -1034,9 +1032,10 @@ int gmx_trjconv(int argc, char *argv[])
         {
             /* check if velocities are possible in input and output files */
             ftpin = fn2ftp(in_file);
-            bVels = (ftp == efTRR || ftp == efTRJ || ftp == efGRO || ftp == efG96)
-                && (ftpin == efTRR || ftpin == efTRJ || ftpin == efGRO || ftpin == efG96 ||
-                    ftpin == efCPT);
+            bVels = (ftp == efTRR || ftp == efGRO ||
+                     ftp == efG96 || ftp == efTNG)
+                && (ftpin == efTRR || ftpin == efGRO ||
+                    ftpin == efG96 || ftpin == efTNG || ftpin == efCPT);
         }
         if (bSeparate || bSplit)
         {
@@ -1045,7 +1044,7 @@ int gmx_trjconv(int argc, char *argv[])
             {
                 gmx_fatal(FARGS, "Output file name '%s' does not contain a '.'", out_file);
             }
-            outf_base = strdup(out_file);
+            outf_base = gmx_strdup(out_file);
             outf_base[outf_ext - out_file] = '\0';
         }
 
@@ -1250,20 +1249,26 @@ int gmx_trjconv(int argc, char *argv[])
         /* Make atoms struct for output in GRO or PDB files */
         if ((ftp == efGRO) || ((ftp == efG96) && bTPS) || (ftp == efPDB))
         {
-            /* get memory for stuff to go in .pdb file */
-            init_t_atoms(&useatoms, atoms->nr, FALSE);
+            /* get memory for stuff to go in .pdb file, and initialize
+             * the pdbinfo structure part if the input has it.
+             */
+            init_t_atoms(&useatoms, atoms->nr, (atoms->pdbinfo != NULL));
             sfree(useatoms.resinfo);
             useatoms.resinfo = atoms->resinfo;
             for (i = 0; (i < nout); i++)
             {
                 useatoms.atomname[i] = atoms->atomname[index[i]];
                 useatoms.atom[i]     = atoms->atom[index[i]];
+                if (atoms->pdbinfo != NULL)
+                {
+                    useatoms.pdbinfo[i]  = atoms->pdbinfo[index[i]];
+                }
                 useatoms.nres        = max(useatoms.nres, useatoms.atom[i].resind+1);
             }
             useatoms.nr = nout;
         }
         /* select what to read */
-        if (ftp == efTRR || ftp == efTRJ)
+        if (ftp == efTRR)
         {
             flags = TRX_READ_X;
         }
@@ -1331,15 +1336,7 @@ int gmx_trjconv(int argc, char *argv[])
             }
 
             /* open output for writing */
-            if ((bAppend) && (gmx_fexist(out_file)))
-            {
-                strcpy(filemode, "a");
-                fprintf(stderr, "APPENDING to existing file %s\n", out_file);
-            }
-            else
-            {
-                strcpy(filemode, "w");
-            }
+            strcpy(filemode, "w");
             switch (ftp)
             {
                 case efTNG:
@@ -1354,9 +1351,7 @@ int gmx_trjconv(int argc, char *argv[])
                                                      grpnm);
                     break;
                 case efXTC:
-                case efG87:
                 case efTRR:
-                case efTRJ:
                     out = NULL;
                     if (!bSplit && !bSubTraj)
                     {
@@ -1368,7 +1363,7 @@ int gmx_trjconv(int argc, char *argv[])
                 case efPDB:
                     if (( !bSeparate && !bSplit ) && !bSubTraj)
                     {
-                        out = ffopen(out_file, filemode);
+                        out = gmx_ffopen(out_file, filemode);
                     }
                     break;
                 default:
@@ -1388,13 +1383,6 @@ int gmx_trjconv(int argc, char *argv[])
                 }
             }
 
-            if (ftp == efG87)
-            {
-                fprintf(gmx_fio_getfp(trx_get_fileio(trxout)),
-                        "Generated by %s. #atoms=%d, a BOX is"
-                        " stored in this file.\n", ShortProgram(), nout);
-            }
-
             /* Start the big loop over frames */
             file_nr  =  0;
             frame    =  0;
@@ -1436,7 +1424,10 @@ int gmx_trjconv(int argc, char *argv[])
                     clear_mat(fr.box);
                     for (m = 0; m < DIM; m++)
                     {
-                        fr.box[m][m] = newbox[m];
+                        if (newbox[m] >= 0)
+                        {
+                            fr.box[m][m] = newbox[m];
+                        }
                     }
                 }
 
@@ -1755,9 +1746,7 @@ int gmx_trjconv(int argc, char *argv[])
                                 write_tng_frame(trxout, &frout);
                                 // TODO when trjconv behaves better: work how to read and write lambda
                                 break;
-                            case efTRJ:
                             case efTRR:
-                            case efG87:
                             case efXTC:
                                 if (bSplitHere)
                                 {
@@ -1814,7 +1803,7 @@ int gmx_trjconv(int argc, char *argv[])
                                         top_title, fr.time);
                                 if (bSeparate || bSplitHere)
                                 {
-                                    out = ffopen(out_file2, "w");
+                                    out = gmx_ffopen(out_file2, "w");
                                 }
                                 switch (ftp)
                                 {
@@ -1863,7 +1852,7 @@ int gmx_trjconv(int argc, char *argv[])
                                 }
                                 if (bSeparate)
                                 {
-                                    ffclose(out);
+                                    gmx_ffclose(out);
                                     out = NULL;
                                 }
                                 break;
@@ -1921,7 +1910,7 @@ int gmx_trjconv(int argc, char *argv[])
         }
         else if (out != NULL)
         {
-            ffclose(out);
+            gmx_ffclose(out);
         }
         if (bSubTraj)
         {