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