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