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