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, 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" },
98 { eftGEN
, ".???", "traj_comp", nullptr,
99 "Compressed trajectory (tng format or portable xdr format)", NTRCOMPRESSED
, trcompressed
},
100 { eftXDR
, ".xtc", "traj", nullptr, "Compressed trajectory (portable xdr format): xtc" },
101 { eftTNG
, ".tng", "traj", nullptr, "Trajectory file (tng format)" },
102 { eftXDR
, ".edr", "ener", nullptr, "Energy file" },
103 { eftGEN
, ".???", "conf", "-c", "Structure file", NSTXS
, stxs
},
104 { eftGEN
, ".???", "out", "-o", "Structure file", NSTOS
, stos
},
105 { eftASC
, ".gro", "conf", "-c", "Coordinate file in Gromos-87 format" },
106 { eftASC
, ".g96", "conf", "-c", "Coordinate file in Gromos-96 format" },
107 { eftASC
, ".pdb", "eiwit", "-f", "Protein data bank file" },
108 { eftASC
, ".brk", "eiwit", "-f", "Brookhaven data bank file" },
109 { eftASC
, ".ent", "eiwit", "-f", "Entry in the protein date bank" },
110 { eftASC
, ".esp", "conf", "-f", "Coordinate file in Espresso format" },
111 { eftASC
, ".pqr", "state", "-o", "Coordinate file for MEAD" },
112 { eftXDR
, ".cpt", "state", "-cp", "Checkpoint file" },
113 { eftASC
, ".log", "run", "-l", "Log file" },
114 { eftASC
, ".xvg", "graph", "-o", "xvgr/xmgr file" },
115 { eftASC
, ".out", "hello", "-o", "Generic output file" },
123 { eftASC
, ".top", "topol", "-p", "Topology file" },
124 { eftASC
, ".itp", "topinc", nullptr, "Include file for topology" },
125 { eftGEN
, ".???", "topol", "-s", "Structure+mass(db)", NTPSS
, tpss
},
126 { eftXDR
, ".tpr", "topol", "-s", "Portable xdr run input file" },
127 { eftASC
, ".tex", "doc", "-o", "LaTeX file" },
128 { eftASC
, ".rtp", "residue", nullptr, "Residue Type file used by pdb2gmx" },
129 { eftASC
, ".atp", "atomtp", nullptr, "Atomtype file used by pdb2gmx" },
130 { eftASC
, ".hdb", "polar", nullptr, "Hydrogen data base" },
131 { eftASC
, ".dat", "nnnice", nullptr, "Generic data file" },
132 { eftASC
, ".dlg", "user", nullptr, "Dialog Box data for ngmx" },
133 { eftASC
, ".map", "ss", nullptr, "File that maps matrix data to colors" },
134 { eftASC
, ".eps", "plot", nullptr, "Encapsulated PostScript (tm) file" },
135 { eftASC
, ".mat", "ss", nullptr, "Matrix Data file" },
136 { eftASC
, ".m2p", "ps", nullptr, "Input file for mat2ps" },
137 { eftXDR
, ".mtx", "hessian", "-m", "Hessian matrix" },
138 { eftASC
, ".edi", "sam", nullptr, "ED sampling input" },
139 { eftASC
, ".cub", "pot", nullptr, "Gaussian cube file" },
140 { eftASC
, ".xpm", "root", nullptr, "X PixMap compatible matrix file" },
141 { eftASC
, "", "rundir", nullptr, "Run directory" },
142 { eftASC
, ".csv", "bench", nullptr, "CSV data file" }
145 const char* ftp2ext(int ftp
)
147 if ((0 <= ftp
) && (ftp
< efNR
))
149 return deffile
[ftp
].ext
[0] != '\0' ? deffile
[ftp
].ext
+ 1 : "";
157 const char* ftp2ext_generic(int ftp
)
159 if ((0 <= ftp
) && (ftp
< efNR
))
163 case efTRX
: return "trx";
164 case efTRN
: return "trn";
165 case efSTO
: return "sto";
166 case efSTX
: return "stx";
167 case efTPS
: return "tps";
168 default: return ftp2ext(ftp
);
177 const char* ftp2ext_with_dot(int ftp
)
179 if ((0 <= ftp
) && (ftp
< efNR
))
181 return deffile
[ftp
].ext
;
189 int ftp2generic_count(int ftp
)
191 if ((0 <= ftp
) && (ftp
< efNR
))
193 return deffile
[ftp
].ntps
;
201 const int* ftp2generic_list(int ftp
)
203 if ((0 <= ftp
) && (ftp
< efNR
))
205 return deffile
[ftp
].tps
;
213 const char* ftp2desc(int ftp
)
215 if ((0 <= ftp
) && (ftp
< efNR
))
217 return deffile
[ftp
].descr
;
221 return "unknown filetype";
225 gmx_bool
ftp_is_text(int ftp
)
227 if ((ftp
>= 0) && (ftp
< efNR
))
229 return deffile
[ftp
].ftype
== eftASC
;
234 gmx_bool
ftp_is_xdr(int ftp
)
236 if ((ftp
>= 0) && (ftp
< efNR
))
238 return deffile
[ftp
].ftype
== eftXDR
;
243 const char* ftp2defnm(int ftp
)
245 if ((0 <= ftp
) && (ftp
< efNR
))
247 return deffile
[ftp
].defnm
;
255 const char* ftp2defopt(int ftp
)
257 if ((0 <= ftp
) && (ftp
< efNR
))
259 return deffile
[ftp
].defopt
;
267 int fn2ftp(const char* fn
)
278 len
= std::strlen(fn
);
279 if ((len
>= 4) && (fn
[len
- 4] == '.'))
281 feptr
= &(fn
[len
- 4]);
288 for (i
= 0; (i
< efNR
); i
++)
290 if ((eptr
= deffile
[i
].ext
) != nullptr)
292 if (gmx_strcasecmp(feptr
, eptr
) == 0)