Move parse_common_args() into commandline/pargs.*
[alexxy/gromacs.git] / src / gromacs / gmxlib / copyrite.cpp
1 /*
2  *
3  *                This source code is part of
4  *
5  *                 G   R   O   M   A   C   S
6  *
7  *          GROningen MAchine for Chemical Simulations
8  *
9  *                        VERSION 3.2.0
10  * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12  * Copyright (c) 2001-2004, The GROMACS development team,
13  * check out http://www.gromacs.org for more information.
14
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * If you want to redistribute modifications, please consider that
21  * scientific software is very special. Version control is crucial -
22  * bugs must be traceable. We will be happy to consider code for
23  * inclusion in the official distribution, but derived work must not
24  * be called official GROMACS. Details are found in the README & COPYING
25  * files - if they are missing, get the official version at www.gromacs.org.
26  *
27  * To help us fund GROMACS development, we humbly ask that you cite
28  * the papers on the package - you can find them in the top README file.
29  *
30  * For more info, check our website at http://www.gromacs.org
31  *
32  * And Hey:
33  * GROningen Mixture of Alchemy and Childrens' Stories
34  */
35 #include "copyrite.h"
36
37 #ifdef HAVE_CONFIG_H
38 #include "config.h"
39 #endif
40
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <time.h>
45
46 #ifdef HAVE_LIBMKL
47 #include <mkl.h>
48 #endif
49
50 /* This file is completely threadsafe - keep it that way! */
51
52 #include "gromacs/fileio/futil.h"
53 #include "gromacs/legacyheaders/macros.h"
54 #include "gromacs/legacyheaders/random.h"
55 #include "gromacs/legacyheaders/smalloc.h"
56 #include "gromacs/legacyheaders/strdb.h"
57 #include "gromacs/legacyheaders/string2.h"
58 #include "gromacs/legacyheaders/vec.h"
59
60 #include "gromacs/fft/fft.h"
61 #include "gromacs/utility/exceptions.h"
62 #include "gromacs/utility/gmxassert.h"
63 #include "gromacs/utility/programinfo.h"
64
65 #include "buildinfo.h"
66
67 static gmx_bool be_cool(void)
68 {
69     /* Yes, it is bad to check the environment variable every call,
70      * but we dont call this routine often, and it avoids using
71      * a mutex for locking the variable...
72      */
73 #ifdef GMX_COOL_QUOTES
74     return (getenv("GMX_NO_QUOTES") == NULL);
75 #else
76     /*be uncool*/
77     return FALSE;
78 #endif
79 }
80
81 static void pukeit(const char *db, const char *defstring, char *retstring,
82                    int retsize, int *cqnum)
83 {
84     FILE  *fp;
85     char **help;
86     int    i, nhlp;
87     int    seed;
88
89     if (be_cool() && ((fp = low_libopen(db, FALSE)) != NULL))
90     {
91         nhlp = fget_lines(fp, &help);
92         /* for libraries we can use the low-level close routines */
93         ffclose(fp);
94         seed   = time(NULL);
95         *cqnum = static_cast<int>(nhlp*rando(&seed));
96         if (strlen(help[*cqnum]) >= STRLEN)
97         {
98             help[*cqnum][STRLEN-1] = '\0';
99         }
100         strncpy(retstring, help[*cqnum], retsize);
101         for (i = 0; (i < nhlp); i++)
102         {
103             sfree(help[i]);
104         }
105         sfree(help);
106     }
107     else
108     {
109         *cqnum = -1;
110         strncpy(retstring, defstring, retsize);
111     }
112 }
113
114 void bromacs(char *retstring, int retsize)
115 {
116     int dum;
117
118     pukeit("bromacs.dat",
119            "Groningen Machine for Chemical Simulation",
120            retstring, retsize, &dum);
121 }
122
123 void cool_quote(char *retstring, int retsize, int *cqnum)
124 {
125     char *tmpstr;
126     char *ptr;
127     int   tmpcq, *p;
128
129     if (cqnum != NULL)
130     {
131         p = cqnum;
132     }
133     else
134     {
135         p = &tmpcq;
136     }
137
138     /* protect audience from explicit lyrics */
139     snew(tmpstr, retsize+1);
140     pukeit("gurgle.dat", "Thanx for Using GROMACS - Have a Nice Day",
141            tmpstr, retsize-2, p);
142
143     if ((ptr = strchr(tmpstr, '_')) != NULL)
144     {
145         *ptr = '\0';
146         ptr++;
147         sprintf(retstring, "\"%s\" %s", tmpstr, ptr);
148     }
149     else
150     {
151         strcpy(retstring, tmpstr);
152     }
153     sfree(tmpstr);
154 }
155
156 static void printCopyright(FILE *fp)
157 {
158     static const char * const CopyrightText[] = {
159         "GROMACS is written by:",
160         "Emile Apol, Rossen Apostolov, Herman J.C. Berendsen,",
161         "Aldert van Buuren, Pär Bjelkmar, Rudi van Drunen, Anton Feenstra,",
162         "Gerrit Groenhof, Christoph Junghans, Peter Kasson, Carsten Kutzner",
163         "Per Larsson, Magnus Lundborg, Pieter Meulenhoff, Teemu Murtola,",
164         "Szilard Pall, Sander Pronk, Roland Schulz,",
165         "Michael Shirts, Alfons Sijbers, Peter Tieleman,\n",
166         "Christian Wennberg, Mark Abraham\n",
167         "Berk Hess, David van der Spoel, and Erik Lindahl.\n",
168         "Copyright (c) 1991-2000, University of Groningen, The Netherlands.",
169         "Copyright (c) 2001-2013, The GROMACS development team at",
170         "Uppsala University & The Royal Institute of Technology, Sweden.",
171         "check out http://www.gromacs.org for more information."
172     };
173
174     static const char * const LicenseText[] = {
175         "GROMACS is free software; you can redistribute it and/or modify it",
176         "under the terms of the GNU Lesser General Public License",
177         "as published by the Free Software Foundation; either version 2.1",
178         "of the License, or (at your option) any later version."
179     };
180
181 #define NCR (int)asize(CopyrightText)
182 // FAH has an exception permission from LGPL to allow digital signatures in Gromacs.
183 #ifdef GMX_FAHCORE
184 #define NLICENSE 0
185 #else
186 #define NLICENSE (int)asize(LicenseText)
187 #endif
188
189     for (int i = 0; i < NCR; ++i)
190     {
191         fprintf(fp, "%s\n", CopyrightText[i]);
192     }
193     fprintf(fp, "\n");
194     for (int i = 0; i < NLICENSE; ++i)
195     {
196         fprintf(fp, "%s\n", LicenseText[i]);
197     }
198 }
199
200
201 void gmx_thanx(FILE *fp)
202 {
203     char cq[1024];
204     int  cqnum = -1;
205
206     /* protect the audience from suggestive discussions */
207     cool_quote(cq, 1023, &cqnum);
208
209     if (cqnum >= 0)
210     {
211         fprintf(fp, "\ngcq#%d: %s\n\n", cqnum, cq);
212     }
213     else
214     {
215         fprintf(fp, "\n%s\n\n", cq);
216     }
217 }
218
219 typedef struct {
220     const char *key;
221     const char *author;
222     const char *title;
223     const char *journal;
224     int         volume, year;
225     const char *pages;
226 } t_citerec;
227
228 void please_cite(FILE *fp, const char *key)
229 {
230     static const t_citerec citedb[] = {
231         { "Allen1987a",
232           "M. P. Allen and D. J. Tildesley",
233           "Computer simulation of liquids",
234           "Oxford Science Publications",
235           1, 1987, "1" },
236         { "Berendsen95a",
237           "H. J. C. Berendsen, D. van der Spoel and R. van Drunen",
238           "GROMACS: A message-passing parallel molecular dynamics implementation",
239           "Comp. Phys. Comm.",
240           91, 1995, "43-56" },
241         { "Berendsen84a",
242           "H. J. C. Berendsen, J. P. M. Postma, A. DiNola and J. R. Haak",
243           "Molecular dynamics with coupling to an external bath",
244           "J. Chem. Phys.",
245           81, 1984, "3684-3690" },
246         { "Ryckaert77a",
247           "J. P. Ryckaert and G. Ciccotti and H. J. C. Berendsen",
248           "Numerical Integration of the Cartesian Equations of Motion of a System with Constraints; Molecular Dynamics of n-Alkanes",
249           "J. Comp. Phys.",
250           23, 1977, "327-341" },
251         { "Miyamoto92a",
252           "S. Miyamoto and P. A. Kollman",
253           "SETTLE: An Analytical Version of the SHAKE and RATTLE Algorithms for Rigid Water Models",
254           "J. Comp. Chem.",
255           13, 1992, "952-962" },
256         { "Cromer1968a",
257           "D. T. Cromer & J. B. Mann",
258           "X-ray scattering factors computed from numerical Hartree-Fock wave functions",
259           "Acta Cryst. A",
260           24, 1968, "321" },
261         { "Barth95a",
262           "E. Barth and K. Kuczera and B. Leimkuhler and R. D. Skeel",
263           "Algorithms for Constrained Molecular Dynamics",
264           "J. Comp. Chem.",
265           16, 1995, "1192-1209" },
266         { "Essmann95a",
267           "U. Essmann, L. Perera, M. L. Berkowitz, T. Darden, H. Lee and L. G. Pedersen ",
268           "A smooth particle mesh Ewald method",
269           "J. Chem. Phys.",
270           103, 1995, "8577-8592" },
271         { "Torda89a",
272           "A. E. Torda and R. M. Scheek and W. F. van Gunsteren",
273           "Time-dependent distance restraints in molecular dynamics simulations",
274           "Chem. Phys. Lett.",
275           157, 1989, "289-294" },
276         { "Tironi95a",
277           "I. G. Tironi and R. Sperb and P. E. Smith and W. F. van Gunsteren",
278           "Generalized reaction field method for molecular dynamics simulations",
279           "J. Chem. Phys",
280           102, 1995, "5451-5459" },
281         { "Hess97a",
282           "B. Hess and H. Bekker and H. J. C. Berendsen and J. G. E. M. Fraaije",
283           "LINCS: A Linear Constraint Solver for molecular simulations",
284           "J. Comp. Chem.",
285           18, 1997, "1463-1472" },
286         { "Hess2008a",
287           "B. Hess",
288           "P-LINCS: A Parallel Linear Constraint Solver for molecular simulation",
289           "J. Chem. Theory Comput.",
290           4, 2008, "116-122" },
291         { "Hess2008b",
292           "B. Hess and C. Kutzner and D. van der Spoel and E. Lindahl",
293           "GROMACS 4: Algorithms for highly efficient, load-balanced, and scalable molecular simulation",
294           "J. Chem. Theory Comput.",
295           4, 2008, "435-447" },
296         { "Hub2010",
297           "J. S. Hub, B. L. de Groot and D. van der Spoel",
298           "g_wham - A free weighted histogram analysis implementation including robust error and autocorrelation estimates",
299           "J. Chem. Theory Comput.",
300           6, 2010, "3713-3720"},
301         { "In-Chul99a",
302           "Y. In-Chul and M. L. Berkowitz",
303           "Ewald summation for systems with slab geometry",
304           "J. Chem. Phys.",
305           111, 1999, "3155-3162" },
306         { "DeGroot97a",
307           "B. L. de Groot and D. M. F. van Aalten and R. M. Scheek and A. Amadei and G. Vriend and H. J. C. Berendsen",
308           "Prediction of Protein Conformational Freedom From Distance Constrains",
309           "Proteins",
310           29, 1997, "240-251" },
311         { "Spoel98a",
312           "D. van der Spoel and P. J. van Maaren and H. J. C. Berendsen",
313           "A systematic study of water models for molecular simulation. Derivation of models optimized for use with a reaction-field.",
314           "J. Chem. Phys.",
315           108, 1998, "10220-10230" },
316         { "Wishart98a",
317           "D. S. Wishart and A. M. Nip",
318           "Protein Chemical Shift Analysis: A Practical Guide",
319           "Biochem. Cell Biol.",
320           76, 1998, "153-163" },
321         { "Maiorov95",
322           "V. N. Maiorov and G. M. Crippen",
323           "Size-Independent Comparison of Protein Three-Dimensional Structures",
324           "PROTEINS: Struct. Funct. Gen.",
325           22, 1995, "273-283" },
326         { "Feenstra99",
327           "K. A. Feenstra and B. Hess and H. J. C. Berendsen",
328           "Improving Efficiency of Large Time-scale Molecular Dynamics Simulations of Hydrogen-rich Systems",
329           "J. Comput. Chem.",
330           20, 1999, "786-798" },
331         { "Lourenco2013a",
332           "Tuanan C. Lourenco and Mariny F. C. Coelho and Teodorico C. Ramalho and David van der Spoel and Luciano T. Costa",
333           "Insights on the Solubility of CO2 in 1-Ethyl-3-methylimidazolium Bis(trifluoromethylsulfonyl)imide from the Microscopic Point of View",
334           "Environ. Sci. Technol.",
335           47, 2013, "7421-7429" },
336         { "Timneanu2004a",
337           "N. Timneanu and C. Caleman and J. Hajdu and D. van der Spoel",
338           "Auger Electron Cascades in Water and Ice",
339           "Chem. Phys.",
340           299, 2004, "277-283" },
341         { "Pascal2011a",
342           "T. A. Pascal and S. T. Lin and W. A. Goddard III",
343           "Thermodynamics of liquids: standard molar entropies and heat capacities of common solvents from 2PT molecular dynamics",
344           "Phys. Chem. Chem. Phys.",
345           13, 2011, "169-181" },
346         { "Caleman2011b",
347           "C. Caleman and P. J. van Maaren and M. Hong and J. S. Hub and L. T. da Costa and D. van der Spoel",
348           "Force Field Benchmark of Organic Liquids: Density, Enthalpy of Vaporization, Heat Capacities, Surface Tension, Isothermal Compressibility, Volumetric Expansion Coefficient, and Dielectric Constant",
349           "J. Chem. Theo. Comp.",
350           8, 2012, "61" },
351         { "Lindahl2001a",
352           "E. Lindahl and B. Hess and D. van der Spoel",
353           "GROMACS 3.0: A package for molecular simulation and trajectory analysis",
354           "J. Mol. Mod.",
355           7, 2001, "306-317" },
356         { "Wang2001a",
357           "J. Wang and W. Wang and S. Huo and M. Lee and P. A. Kollman",
358           "Solvation model based on weighted solvent accessible surface area",
359           "J. Phys. Chem. B",
360           105, 2001, "5055-5067" },
361         { "Eisenberg86a",
362           "D. Eisenberg and A. D. McLachlan",
363           "Solvation energy in protein folding and binding",
364           "Nature",
365           319, 1986, "199-203" },
366         { "Bondi1964a",
367           "A. Bondi",
368           "van der Waals Volumes and Radii",
369           "J. Phys. Chem.",
370           68, 1964, "441-451" },
371         { "Eisenhaber95",
372           "Frank Eisenhaber and Philip Lijnzaad and Patrick Argos and Chris Sander and Michael Scharf",
373           "The Double Cube Lattice Method: Efficient Approaches to Numerical Integration of Surface Area and Volume and to Dot Surface Contouring of Molecular Assemblies",
374           "J. Comp. Chem.",
375           16, 1995, "273-284" },
376         { "Hess2002",
377           "B. Hess, H. Saint-Martin and H.J.C. Berendsen",
378           "Flexible constraints: an adiabatic treatment of quantum degrees of freedom, with application to the flexible and polarizable MCDHO model for water",
379           "J. Chem. Phys.",
380           116, 2002, "9602-9610" },
381         { "Hetenyi2002b",
382           "Csaba Hetenyi and David van der Spoel",
383           "Efficient docking of peptides to proteins without prior knowledge of the binding site.",
384           "Prot. Sci.",
385           11, 2002, "1729-1737" },
386         { "Hess2003",
387           "B. Hess and R.M. Scheek",
388           "Orientation restraints in molecular dynamics simulations using time and ensemble averaging",
389           "J. Magn. Res.",
390           164, 2003, "19-27" },
391         { "Rappe1991a",
392           "A. K. Rappe and W. A. Goddard III",
393           "Charge Equillibration for Molecular Dynamics Simulations",
394           "J. Phys. Chem.",
395           95, 1991, "3358-3363" },
396         { "Mu2005a",
397           "Y. Mu, P. H. Nguyen and G. Stock",
398           "Energy landscape of a small peptide revelaed by dihedral angle principal component analysis",
399           "Prot. Struct. Funct. Bioinf.",
400           58, 2005, "45-52" },
401         { "Okabe2001a",
402           "T. Okabe and M. Kawata and Y. Okamoto and M. Mikami",
403           "Replica-exchange {M}onte {C}arlo method for the isobaric-isothermal ensemble",
404           "Chem. Phys. Lett.",
405           335, 2001, "435-439" },
406         { "Hukushima96a",
407           "K. Hukushima and K. Nemoto",
408           "Exchange Monte Carlo Method and Application to Spin Glass Simulations",
409           "J. Phys. Soc. Jpn.",
410           65, 1996, "1604-1608" },
411         { "Tropp80a",
412           "J. Tropp",
413           "Dipolar Relaxation and Nuclear Overhauser effects in nonrigid molecules: The effect of fluctuating internuclear distances",
414           "J. Chem. Phys.",
415           72, 1980, "6035-6043" },
416         { "Bultinck2002a",
417           "P. Bultinck and W. Langenaeker and P. Lahorte and F. De Proft and P. Geerlings and M. Waroquier and J. P. Tollenaere",
418           "The electronegativity equalization method I: Parametrization and validation for atomic charge calculations",
419           "J. Phys. Chem. A",
420           106, 2002, "7887-7894" },
421         { "Yang2006b",
422           "Q. Y. Yang and K. A. Sharp",
423           "Atomic charge parameters for the finite difference Poisson-Boltzmann method using electronegativity neutralization",
424           "J. Chem. Theory Comput.",
425           2, 2006, "1152-1167" },
426         { "Spoel2005a",
427           "D. van der Spoel, E. Lindahl, B. Hess, G. Groenhof, A. E. Mark and H. J. C. Berendsen",
428           "GROMACS: Fast, Flexible and Free",
429           "J. Comp. Chem.",
430           26, 2005, "1701-1719" },
431         { "Spoel2006b",
432           "D. van der Spoel, P. J. van Maaren, P. Larsson and N. Timneanu",
433           "Thermodynamics of hydrogen bonding in hydrophilic and hydrophobic media",
434           "J. Phys. Chem. B",
435           110, 2006, "4393-4398" },
436         { "Spoel2006d",
437           "D. van der Spoel and M. M. Seibert",
438           "Protein folding kinetics and thermodynamics from atomistic simulations",
439           "Phys. Rev. Letters",
440           96, 2006, "238102" },
441         { "Palmer94a",
442           "B. J. Palmer",
443           "Transverse-current autocorrelation-function calculations of the shear viscosity for molecular liquids",
444           "Phys. Rev. E",
445           49, 1994, "359-366" },
446         { "Bussi2007a",
447           "G. Bussi, D. Donadio and M. Parrinello",
448           "Canonical sampling through velocity rescaling",
449           "J. Chem. Phys.",
450           126, 2007, "014101" },
451         { "Hub2006",
452           "J. S. Hub and B. L. de Groot",
453           "Does CO2 permeate through Aquaporin-1?",
454           "Biophys. J.",
455           91, 2006, "842-848" },
456         { "Hub2008",
457           "J. S. Hub and B. L. de Groot",
458           "Mechanism of selectivity in aquaporins and aquaglyceroporins",
459           "PNAS",
460           105, 2008, "1198-1203" },
461         { "Friedrich2009",
462           "M. S. Friedrichs, P. Eastman, V. Vaidyanathan, M. Houston, S. LeGrand, A. L. Beberg, D. L. Ensign, C. M. Bruns, and V. S. Pande",
463           "Accelerating Molecular Dynamic Simulation on Graphics Processing Units",
464           "J. Comp. Chem.",
465           30, 2009, "864-872" },
466         { "Engin2010",
467           "O. Engin, A. Villa, M. Sayar and B. Hess",
468           "Driving Forces for Adsorption of Amphiphilic Peptides to Air-Water Interface",
469           "J. Phys. Chem. B",
470           114, 2010, "11093" },
471         { "Fritsch12",
472           "S. Fritsch, C. Junghans and K. Kremer",
473           "Adaptive molecular simulation study on structure formation of toluene around C60 using Gromacs",
474           "J. Chem. Theo. Comp.",
475           8, 2012, "398" },
476         { "Junghans10",
477           "C. Junghans and S. Poblete",
478           "A reference implementation of the adaptive resolution scheme in ESPResSo",
479           "Comp. Phys. Comm.",
480           181, 2010, "1449" },
481         { "Wang2010",
482           "H. Wang, F. Dommert, C.Holm",
483           "Optimizing working parameters of the smooth particle mesh Ewald algorithm in terms of accuracy and efficiency",
484           "J. Chem. Phys. B",
485           133, 2010, "034117" },
486         { "Sugita1999a",
487           "Y. Sugita, Y. Okamoto",
488           "Replica-exchange molecular dynamics method for protein folding",
489           "Chem. Phys. Lett.",
490           314, 1999, "141-151" },
491         { "Kutzner2011",
492           "C. Kutzner and J. Czub and H. Grubmuller",
493           "Keep it Flexible: Driving Macromolecular Rotary Motions in Atomistic Simulations with GROMACS",
494           "J. Chem. Theory Comput.",
495           7, 2011, "1381-1393" },
496         { "Hoefling2011",
497           "M. Hoefling, N. Lima, D. Haenni, C.A.M. Seidel, B. Schuler, H. Grubmuller",
498           "Structural Heterogeneity and Quantitative FRET Efficiency Distributions of Polyprolines through a Hybrid Atomistic Simulation and Monte Carlo Approach",
499           "PLoS ONE",
500           6, 2011, "e19791" },
501         { "Hockney1988",
502           "R. W. Hockney and J. W. Eastwood",
503           "Computer simulation using particles",
504           "IOP, Bristol",
505           1, 1988, "1" },
506         { "Ballenegger2012",
507           "V. Ballenegger, J.J. Cerda, and C. Holm",
508           "How to Convert SPME to P3M: Influence Functions and Error Estimates",
509           "J. Chem. Theory Comput.",
510           8, 2012, "936-947" },
511         { "Garmay2012",
512           "Garmay Yu, Shvetsov A, Karelov D, Lebedev D, Radulescu A, Petukhov M, Isaev-Ivanov V",
513           "Correlated motion of protein subdomains and large-scale conformational flexibility of RecA protein filament",
514           "Journal of Physics: Conference Series",
515           340, 2012, "012094" }
516     };
517 #define NSTR (int)asize(citedb)
518
519     int   index;
520     char *author;
521     char *title;
522 #define LINE_WIDTH 79
523
524     if (fp == NULL)
525     {
526         return;
527     }
528
529     for (index = 0; (index < NSTR) && (strcmp(citedb[index].key, key) != 0); index++)
530     {
531         ;
532     }
533
534     fprintf(fp, "\n++++ PLEASE READ AND CITE THE FOLLOWING REFERENCE ++++\n");
535     if (index < NSTR)
536     {
537         /* Insert newlines */
538         author = wrap_lines(citedb[index].author, LINE_WIDTH, 0, FALSE);
539         title  = wrap_lines(citedb[index].title, LINE_WIDTH, 0, FALSE);
540         fprintf(fp, "%s\n%s\n%s %d (%d) pp. %s\n",
541                 author, title, citedb[index].journal,
542                 citedb[index].volume, citedb[index].year,
543                 citedb[index].pages);
544         sfree(author);
545         sfree(title);
546     }
547     else
548     {
549         fprintf(fp, "Entry %s not found in citation database\n", key);
550     }
551     fprintf(fp, "-------- -------- --- Thank You --- -------- --------\n\n");
552     fflush(fp);
553 }
554
555 #ifdef GMX_GIT_VERSION_INFO
556 /* Version information generated at compile time. */
557 #include "gromacs/utility/gitversion.h"
558 #else
559 /* Fall back to statically defined version. */
560 static const char _gmx_ver_string[] = "VERSION " VERSION;
561 #endif
562
563 const char *GromacsVersion()
564 {
565     return _gmx_ver_string;
566 }
567
568 const char *ShortProgram(void)
569 {
570     try
571     {
572         // TODO: Use the display name once it doesn't break anything.
573         return gmx::ProgramInfo::getInstance().programName().c_str();
574     }
575     GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
576 }
577
578 const char *Program(void)
579 {
580     try
581     {
582         return gmx::ProgramInfo::getInstance().fullBinaryPath().c_str();
583     }
584     GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
585 }
586
587
588 extern void gmx_print_version_info_gpu(FILE *fp);
589
590 static void gmx_print_version_info(FILE *fp)
591 {
592     fprintf(fp, "Gromacs version:    %s\n", _gmx_ver_string);
593 #ifdef GMX_GIT_VERSION_INFO
594     fprintf(fp, "GIT SHA1 hash:      %s\n", _gmx_full_git_hash);
595     /* Only print out the branch information if present.
596      * The generating script checks whether the branch point actually
597      * coincides with the hash reported above, and produces an empty string
598      * in such cases. */
599     if (_gmx_central_base_hash[0] != 0)
600     {
601         fprintf(fp, "Branched from:      %s\n", _gmx_central_base_hash);
602     }
603 #endif
604
605 #ifdef GMX_DOUBLE
606     fprintf(fp, "Precision:          double\n");
607 #else
608     fprintf(fp, "Precision:          single\n");
609 #endif
610     fprintf(fp, "Memory model:       %lu bit\n", 8*sizeof(void *));
611
612 #ifdef GMX_THREAD_MPI
613     fprintf(fp, "MPI library:        thread_mpi\n");
614 #elif defined(GMX_MPI)
615     fprintf(fp, "MPI library:        MPI\n");
616 #else
617     fprintf(fp, "MPI library:        none\n");
618 #endif
619 #ifdef GMX_OPENMP
620     fprintf(fp, "OpenMP support:     enabled\n");
621 #else
622     fprintf(fp, "OpenMP support:     disabled\n");
623 #endif
624 #ifdef GMX_GPU
625     fprintf(fp, "GPU support:        enabled\n");
626 #else
627     fprintf(fp, "GPU support:        disabled\n");
628 #endif
629     /* A preprocessor trick to avoid duplicating logic from vec.h */
630 #define gmx_stringify2(x) #x
631 #define gmx_stringify(x) gmx_stringify2(x)
632     fprintf(fp, "invsqrt routine:    %s\n", gmx_stringify(gmx_invsqrt(x)));
633     fprintf(fp, "CPU acceleration:   %s\n", GMX_CPU_ACCELERATION_STRING);
634
635     fprintf(fp, "FFT library:        %s\n", gmx_fft_get_version_info());
636 #ifdef GMX_LARGEFILES
637     fprintf(fp, "Large file support: enabled\n");
638 #else
639     fprintf(fp, "Large file support: disabled\n");
640 #endif
641 #ifdef HAVE_RDTSCP
642     fprintf(fp, "RDTSCP usage:       enabled\n");
643 #else
644     fprintf(fp, "RDTSCP usage:       disabled\n");
645 #endif
646
647     fprintf(fp, "Built on:           %s\n", BUILD_TIME);
648     fprintf(fp, "Built by:           %s\n", BUILD_USER);
649     fprintf(fp, "Build OS/arch:      %s\n", BUILD_HOST);
650     fprintf(fp, "Build CPU vendor:   %s\n", BUILD_CPU_VENDOR);
651     fprintf(fp, "Build CPU brand:    %s\n", BUILD_CPU_BRAND);
652     fprintf(fp, "Build CPU family:   %d   Model: %d   Stepping: %d\n",
653             BUILD_CPU_FAMILY, BUILD_CPU_MODEL, BUILD_CPU_STEPPING);
654     /* TODO: The below strings can be quite long, so it would be nice to wrap
655      * them. Can wait for later, as the master branch has ready code to do all
656      * that. */
657     fprintf(fp, "Build CPU features: %s\n", BUILD_CPU_FEATURES);
658     fprintf(fp, "C compiler:         %s\n", BUILD_C_COMPILER);
659     fprintf(fp, "C compiler flags:   %s\n", BUILD_CFLAGS);
660     fprintf(fp, "C++ compiler:       %s\n", BUILD_CXX_COMPILER);
661     fprintf(fp, "C++ compiler flags: %s\n", BUILD_CXXFLAGS);
662 #ifdef HAVE_LIBMKL
663     /* MKL might be used for LAPACK/BLAS even if FFTs use FFTW, so keep it separate */
664     fprintf(fp, "Linked with Intel MKL version %d.%d.%d.\n",
665             __INTEL_MKL__, __INTEL_MKL_MINOR__, __INTEL_MKL_UPDATE__);
666 #endif
667 #ifdef GMX_GPU
668     gmx_print_version_info_gpu(fp);
669 #endif
670 }
671
672 namespace gmx
673 {
674
675 BinaryInformationSettings::BinaryInformationSettings()
676     : bExtendedInfo_(false), bCopyright_(false),
677       bGeneratedByHeader_(false), prefix_(""), suffix_("")
678 {
679 }
680
681 void printBinaryInformation(FILE *fp, const ProgramInfo &programInfo)
682 {
683     printBinaryInformation(fp, programInfo, BinaryInformationSettings());
684 }
685
686 void printBinaryInformation(FILE *fp, const ProgramInfo &programInfo,
687                             const BinaryInformationSettings &settings)
688 {
689     const char *prefix          = settings.prefix_;
690     const char *suffix          = settings.suffix_;
691     const char *precisionString = "";
692 #ifdef GMX_DOUBLE
693     precisionString = " (double precision)";
694 #endif
695     const std::string &name = programInfo.displayName();
696     if (settings.bGeneratedByHeader_)
697     {
698         fprintf(fp, "%sCreated by:%s\n", prefix, suffix);
699     }
700     if (settings.bCopyright_)
701     {
702         GMX_RELEASE_ASSERT(prefix[0] == '\0' && suffix[0] == '\0',
703                            "Prefix/suffix not supported with copyright");
704         // This line is printed again after the copyright notice to make it
705         // appear together with all the other information, so that it is not
706         // necessary to read stuff above the copyright notice.
707         // The line above the copyright notice puts the copyright notice is
708         // context, though.
709         // TODO: It would be nice to know here whether we are really running a
710         // Gromacs binary or some other binary that is calling Gromacs; we
711         // could then print "%s is part of GROMACS" or some alternative text.
712         fprintf(fp, "%sGROMACS:    %s, %s%s%s\n", prefix, name.c_str(),
713                 GromacsVersion(), precisionString, suffix);
714         fprintf(fp, "\n");
715         printCopyright(fp);
716         fprintf(fp, "\n");
717     }
718     fprintf(fp, "%sGROMACS:    %s, %s%s%s\n", prefix, name.c_str(),
719             GromacsVersion(), precisionString, suffix);
720     fprintf(fp, "%sExecutable: %s%s\n", prefix,
721             programInfo.fullBinaryPath().c_str(), suffix);
722     fprintf(fp, "%sCommand line:%s\n%s  %s%s\n",
723             prefix, suffix, prefix, programInfo.commandLine().c_str(), suffix);
724     if (settings.bExtendedInfo_)
725     {
726         GMX_RELEASE_ASSERT(prefix[0] == '\0' && suffix[0] == '\0',
727                            "Prefix/suffix not supported with extended info");
728         fprintf(fp, "\n");
729         gmx_print_version_info(fp);
730     }
731 }
732
733 } // namespace gmx