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