2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
7 * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by
8 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
9 * and including many others, as listed in the AUTHORS file in the
10 * top-level source directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
40 #include "gromacs/fileio/filetypes.h"
44 #include "gromacs/utility/arraysize.h"
45 #include "gromacs/utility/cstringutil.h"
56 /* To support multiple file types with one general (eg TRX) we have
59 static const int trxs[] = { efXTC, efTRR, efCPT, efGRO, efG96, efPDB, efTNG };
60 #define NTRXS asize(trxs)
62 static const int trcompressed[] = { efXTC, efTNG };
63 #define NTRCOMPRESSED asize(trcompressed)
65 static const int tros[] = { efXTC, efTRR, efGRO, efG96, efPDB, efTNG };
66 #define NTROS asize(tros)
68 static const int trns[] = { efTRR, efCPT, efTNG };
69 #define NTRNS asize(trns)
71 static const int stos[] = { efGRO, efG96, efPDB, efBRK, efENT, efESP };
72 #define NSTOS asize(stos)
74 static const int stxs[] = { efGRO, efG96, efPDB, efBRK, efENT, efESP, efTPR };
75 #define NSTXS asize(stxs)
77 static const int tpss[] = { efTPR, efGRO, efG96, efPDB, efBRK, efENT };
78 #define NTPSS asize(tpss)
80 typedef struct // NOLINT(clang-analyzer-optin.performance.Padding)
91 /* this array should correspond to the enum in filetypes.h */
92 static const t_deffile deffile[efNR] = {
93 { eftASC, ".mdp", "grompp", "-f", "grompp input file with MD parameters" },
94 { eftGEN, ".???", "traj", "-f", "Trajectory", NTRXS, trxs },
95 { eftGEN, ".???", "trajout", "-f", "Trajectory", NTROS, tros },
96 { eftGEN, ".???", "traj", nullptr, "Full precision trajectory", NTRNS, trns },
97 { eftXDR, ".trr", "traj", nullptr, "Trajectory in portable xdr format" },
102 "Compressed trajectory (tng format or portable xdr format)",
105 { eftXDR, ".xtc", "traj", nullptr, "Compressed trajectory (portable xdr format): xtc" },
106 { eftTNG, ".tng", "traj", nullptr, "Trajectory file (tng format)" },
107 { eftXDR, ".edr", "ener", nullptr, "Energy file" },
108 { eftGEN, ".???", "conf", "-c", "Structure file", NSTXS, stxs },
109 { eftGEN, ".???", "out", "-o", "Structure file", NSTOS, stos },
110 { eftASC, ".gro", "conf", "-c", "Coordinate file in Gromos-87 format" },
111 { eftASC, ".g96", "conf", "-c", "Coordinate file in Gromos-96 format" },
112 { eftASC, ".pdb", "eiwit", "-f", "Protein data bank file" },
113 { eftASC, ".brk", "eiwit", "-f", "Brookhaven data bank file" },
114 { eftASC, ".ent", "eiwit", "-f", "Entry in the protein date bank" },
115 { eftASC, ".esp", "conf", "-f", "Coordinate file in Espresso format" },
116 { eftASC, ".pqr", "state", "-o", "Coordinate file for MEAD" },
117 { eftXDR, ".cpt", "state", "-cp", "Checkpoint file" },
118 { eftASC, ".log", "run", "-l", "Log file" },
119 { eftASC, ".xvg", "graph", "-o", "xvgr/xmgr file" },
120 { eftASC, ".out", "hello", "-o", "Generic output file" },
128 { eftASC, ".top", "topol", "-p", "Topology file" },
129 { eftASC, ".itp", "topinc", nullptr, "Include file for topology" },
130 { eftGEN, ".???", "topol", "-s", "Structure+mass(db)", NTPSS, tpss },
131 { eftXDR, ".tpr", "topol", "-s", "Portable xdr run input file" },
132 { eftASC, ".tex", "doc", "-o", "LaTeX file" },
133 { eftASC, ".rtp", "residue", nullptr, "Residue Type file used by pdb2gmx" },
134 { eftASC, ".atp", "atomtp", nullptr, "Atomtype file used by pdb2gmx" },
135 { eftASC, ".hdb", "polar", nullptr, "Hydrogen data base" },
136 { eftASC, ".dat", "nnnice", nullptr, "Generic data file" },
137 { eftASC, ".dlg", "user", nullptr, "Dialog Box data for ngmx" },
138 { eftASC, ".map", "ss", nullptr, "File that maps matrix data to colors" },
139 { eftASC, ".eps", "plot", nullptr, "Encapsulated PostScript (tm) file" },
140 { eftASC, ".mat", "ss", nullptr, "Matrix Data file" },
141 { eftASC, ".m2p", "ps", nullptr, "Input file for mat2ps" },
142 { eftXDR, ".mtx", "hessian", "-m", "Hessian matrix" },
143 { eftASC, ".edi", "sam", nullptr, "ED sampling input" },
144 { eftASC, ".cub", "pot", nullptr, "Gaussian cube file" },
145 { eftASC, ".xpm", "root", nullptr, "X PixMap compatible matrix file" },
146 { eftASC, "", "rundir", nullptr, "Run directory" },
147 { eftASC, ".csv", "bench", nullptr, "CSV data file" },
148 { eftASC, ".inp", "topol-qmmm", nullptr, "Input file for QM program" }
151 const char* ftp2ext(int ftp)
153 if ((0 <= ftp) && (ftp < efNR))
155 return deffile[ftp].ext[0] != '\0' ? deffile[ftp].ext + 1 : "";
163 const char* ftp2ext_generic(int ftp)
165 if ((0 <= ftp) && (ftp < efNR))
169 case efTRX: return "trx";
170 case efTRN: return "trn";
171 case efSTO: return "sto";
172 case efSTX: return "stx";
173 case efTPS: return "tps";
174 default: return ftp2ext(ftp);
183 const char* ftp2ext_with_dot(int ftp)
185 if ((0 <= ftp) && (ftp < efNR))
187 return deffile[ftp].ext;
195 int ftp2generic_count(int ftp)
197 if ((0 <= ftp) && (ftp < efNR))
199 return deffile[ftp].ntps;
207 const int* ftp2generic_list(int ftp)
209 if ((0 <= ftp) && (ftp < efNR))
211 return deffile[ftp].tps;
219 const char* ftp2desc(int ftp)
221 if ((0 <= ftp) && (ftp < efNR))
223 return deffile[ftp].descr;
227 return "unknown filetype";
231 gmx_bool ftp_is_text(int ftp)
233 if ((ftp >= 0) && (ftp < efNR))
235 return deffile[ftp].ftype == eftASC;
240 gmx_bool ftp_is_xdr(int ftp)
242 if ((ftp >= 0) && (ftp < efNR))
244 return deffile[ftp].ftype == eftXDR;
249 const char* ftp2defnm(int ftp)
251 if ((0 <= ftp) && (ftp < efNR))
253 return deffile[ftp].defnm;
261 const char* ftp2defopt(int ftp)
263 if ((0 <= ftp) && (ftp < efNR))
265 return deffile[ftp].defopt;
273 int fn2ftp(const char* fn)
284 len = std::strlen(fn);
285 if ((len >= 4) && (fn[len - 4] == '.'))
287 feptr = &(fn[len - 4]);
294 for (i = 0; (i < efNR); i++)
296 if ((eptr = deffile[i].ext) != nullptr)
298 if (gmx_strcasecmp(feptr, eptr) == 0)