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