Added conditional inclusion of config.h to source files
[gromacs.git] / src / gmxlib / copyrite.c
blob2c2f13d679e1462d722ec0ab691b1d4a79e276ee
1 /*
2 * $Id$
3 *
4 * This source code is part of
5 *
6 * G R O M A C S
7 *
8 * GROningen MAchine for Chemical Simulations
9 *
10 * VERSION 3.2.0
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2004, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * For more info, check our website at http://www.gromacs.org
33 * And Hey:
34 * GROningen Mixture of Alchemy and Childrens' Stories
36 #ifdef HAVE_CONFIG_H
37 #include <config.h>
38 #endif
40 #ifdef USE_THREADS
41 #include <pthread.h>
42 #endif
43 /* This file is completely threadsafe - keep it that way! */
45 #include <string.h>
46 #include <ctype.h>
47 #include "sysstuff.h"
48 #include "smalloc.h"
49 #include "string2.h"
50 #include "macros.h"
51 #include "time.h"
52 #include "random.h"
53 #include "statutil.h"
54 #include "copyrite.h"
55 #include "strdb.h"
56 #include "futil.h"
58 static void pr_two(FILE *out,int c,int i)
60 if (i < 10)
61 fprintf(out,"%c0%1d",c,i);
62 else
63 fprintf(out,"%c%2d",c,i);
66 void pr_difftime(FILE *out,double dt)
68 int ndays,nhours,nmins,nsecs;
69 bool bPrint,bPrinted;
71 ndays = dt/(24*3600);
72 dt = dt-24*3600*ndays;
73 nhours= dt/3600;
74 dt = dt-3600*nhours;
75 nmins = dt/60;
76 dt = dt-nmins*60;
77 nsecs = dt;
78 bPrint= (ndays > 0);
79 bPrinted=bPrint;
80 if (bPrint)
81 fprintf(out,"%d",ndays);
82 bPrint=bPrint || (nhours > 0);
83 if (bPrint) {
84 if (bPrinted)
85 pr_two(out,'d',nhours);
86 else
87 fprintf(out,"%d",nhours);
89 bPrinted=bPrinted || bPrint;
90 bPrint=bPrint || (nmins > 0);
91 if (bPrint) {
92 if (bPrinted)
93 pr_two(out,'h',nmins);
94 else
95 fprintf(out,"%d",nmins);
97 bPrinted=bPrinted || bPrint;
98 if (bPrinted)
99 pr_two(out,':',nsecs);
100 else
101 fprintf(out,"%ds",nsecs);
102 fprintf(out,"\n");
106 bool be_cool(void)
108 int cool=-1;
109 char *envptr;
111 /* Yes, it is bad to check the environment variable every call,
112 * but we dont call this routine often, and it avoids using
113 * a mutex for locking the variable...
115 if (cool == -1) {
116 envptr=getenv("IAMCOOL");
118 if ((envptr!=NULL) && (!strcmp(envptr,"no") || !strcmp(envptr,"NO")))
119 cool=0;
120 else
121 cool=1;
124 return cool;
127 void space(FILE *out, int n)
129 fprintf(out,"%*s",n,"");
132 void f(char *a){int i;for(i=0;i<(int)strlen(a);i++)a[i]=~a[i]; }
134 static void sp_print(FILE *out,const char *s)
136 int slen;
138 slen=strlen(s);
139 space(out,(80-slen)/2);
140 fprintf(out,"%s\n",s);
143 static void ster_print(FILE *out,const char *s)
145 int slen;
146 char buf[128];
148 sprintf(buf,":-) %s (-:",s);
149 slen=strlen(buf);
150 space(out,(80-slen)/2);
151 fprintf(out,"%s\n",buf);
155 static char *pukeit(char *db,char *defstring, char *retstring,
156 int retsize, int *cqnum)
158 FILE *fp;
159 char **help;
160 int i,nhlp;
161 int seed;
163 if (!be_cool())
164 return defstring;
165 else if ((fp = low_libopen(db,FALSE)) != NULL) {
166 nhlp=fget_lines(fp,&help);
167 fclose(fp);
168 seed=time(NULL);
169 *cqnum=nhlp*rando(&seed);
170 if (strlen(help[*cqnum]) >= STRLEN)
171 help[*cqnum][STRLEN-1] = '\0';
172 strncpy(retstring,help[*cqnum],retsize);
173 f(retstring);
174 for(i=0; (i<nhlp); i++)
175 sfree(help[i]);
176 sfree(help);
177 return retstring;
179 else
180 return defstring;
184 char *bromacs(char *retstring, int retsize)
186 int dum;
188 return pukeit("bromacs.dat",
189 "Groningen Machine for Chemical Simulation",
190 retstring,retsize,&dum);
194 char *cool_quote(char *retstring, int retsize, int *cqnum)
196 char tmpstr[1024];
197 char *s,*ptr;
198 int tmpcq,*p;
200 if(cqnum!=NULL)
201 p=cqnum;
202 else
203 p=&tmpcq;
205 /* protect audience from explicit lyrics */
206 pukeit("gurgle.dat","Thanx for Using GROMACS - Have a Nice Day",
207 tmpstr,1024,p);
209 if (be_cool() && ((ptr=strchr(tmpstr,'_')) != NULL)) {
210 *ptr='\0';
211 ptr++;
212 sprintf(retstring,"\"%s\" %s",tmpstr,ptr);
214 else {
215 strncpy(retstring,tmpstr,1023);
218 return retstring;
221 void CopyRight(FILE *out,char *szProgram)
223 /* Dont change szProgram arbitrarily - it must be argv[0], i.e. the
224 * name of a file. Otherwise, we won't be able to find the library dir.
226 #define NCR (int)asize(CopyrightText)
227 #define NGPL (int)asize(GPLText)
229 char buf[256],tmpstr[1024];
231 char *ptr;
233 int i;
235 set_program_name(szProgram);
237 ster_print(out,"G R O M A C S");
238 fprintf(out,"\n");
240 ptr=bromacs(tmpstr,1023);
241 sp_print(out,ptr);
242 fprintf(out,"\n");
244 ster_print(out,GromacsVersion());
245 fprintf(out,"\n\n");
247 /* fprintf(out,"\n");*/
249 /* sp_print(out,"PLEASE NOTE: THIS IS A BETA VERSION\n");
251 fprintf(out,"\n"); */
253 for(i=0; (i<NCR); i++)
254 sp_print(out,CopyrightText[i]);
255 for(i=0; (i<NGPL); i++)
256 sp_print(out,GPLText[i]);
258 fprintf(out,"\n");
260 sprintf(buf,"%s",Program());
261 #ifdef DOUBLE
262 strcat(buf," (double precision)");
263 #endif
264 ster_print(out,buf);
265 fprintf(out,"\n");
269 void thanx(FILE *fp)
271 char tmpbuf[1024];
272 char *cq,*c;
273 int cqnum;
275 /* protect the audience from suggestive discussions */
276 cq=cool_quote(tmpbuf,1023,&cqnum);
278 if (be_cool()) {
279 snew(c,strlen(cq)+20);
281 sprintf(c,"gcq#%d: %s\n",cqnum,cq);
283 fprintf(fp,"\n%s\n",c);
284 sfree(c);
286 else
287 fprintf(fp,"\n%s\n",cq);
290 typedef struct {
291 char *key;
292 char *author;
293 char *title;
294 char *journal;
295 int volume,year,p0,p1;
296 } t_citerec;
298 void please_cite(FILE *fp,char *key)
300 static t_citerec citedb[] = {
301 { "Berendsen95a",
302 "H. J. C. Berendsen, D. van der Spoel and R. van Drunen",
303 "GROMACS: A message-passing parallel molecular dynamics implementation",
304 "Comp. Phys. Comm.",
305 91, 1995, 43, 56 },
306 { "Berendsen84a",
307 "H. J. C. Berendsen, J. P. M. Postma, A. DiNola and J. R. Haak",
308 "Molecular dynamics with coupling to an external bath",
309 "J. Chem. Phys.",
310 81, 1984, 3684, 3690 },
311 { "Ryckaert77a",
312 "J. P. Ryckaert and G. Ciccotti and H. J. C. Berendsen",
313 "Numerical Integration of the Cartesian Equations of Motion of a System with Constraints; Molecular Dynamics of n-Alkanes",
314 "J. Comp. Phys.",
315 23, 1977, 327, 341 },
316 { "Miyamoto92a",
317 "S. Miyamoto and P. A. Kollman",
318 "SETTLE: An Analytical Version of the SHAKE and RATTLE Algorithms for Rigid Water Models",
319 "J. Comp. Chem.",
320 13, 1992, 952, 962 },
321 { "Barth95a",
322 "E. Barth and K. Kuczera and B. Leimkuhler and R. D. Skeel",
323 "Algorithms for Constrained Molecular Dynamics",
324 "J. Comp. Chem.",
325 16, 1995, 1192, 1209 },
326 { "Essman95a",
327 "U. Essman, L. Perela, M. L. Berkowitz, T. Darden, H. Lee and L. G. Pedersen ",
328 "A smooth particle mesh Ewald method",
329 "J. Chem. Phys.",
330 103, 1995, 8577, 8592 },
331 { "Torda89a",
332 "A. E. Torda and R. M. Scheek and W. F. van Gunsteren",
333 "Time-dependent distance restraints in molecular dynamics simulations",
334 "Chem. Phys. Lett.",
335 157, 1989, 289, 294 },
336 { "Tironi95a",
337 "I. G. Tironi and R. Sperb and P. E. Smith and W. F. van Gunsteren",
338 "Generalized reaction field method for molecular dynamics simulations",
339 "J. Chem. Phys",
340 102, 1995, 5451, 5459 },
341 { "Hess97a",
342 "B. Hess and H. Bekker and H. J. C. Berendsen and J. G. E. M. Fraaije",
343 "LINCS: A Linear Constraint Solver for molecular simulations",
344 "J. Comp. Chem.",
345 18, 1997, 1463, 1472 },
346 { "In-Chul99a",
347 "Y. In-Chul and M. L. Berkowitz",
348 "Ewald summation for systems with slab geometry",
349 "J. Chem. Phys.",
350 111, 1999, 3155, 3162 },
351 { "DeGroot97a",
352 "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",
353 "Prediction of Protein Conformational Freedom From Distance Constrains",
354 "Proteins",
355 29, 1997, 240, 251 },
356 { "Spoel98a",
357 "D. van der Spoel and P. J. van Maaren and H. J. C. Berendsen",
358 "A systematic study of water models for molecular simulation. Derivation of models optimized for use with a reaction-field.",
359 "J. Chem. Phys.",
360 108, 1998, 10220, 10230 },
361 { "Wishart98a",
362 "D. S. Wishart and A. M. Nip",
363 "Protein Chemical Shift Analysis: A Practical Guide",
364 "Biochem. Cell Biol.",
365 76, 1998, 153, 163 },
366 { "Maiorov95",
367 "V. N. Maiorov and G. M. Crippen",
368 "Size-Independent Comparison of Protein Three-Dimensional Structures",
369 "PROTEINS: Struct. Funct. Gen.",
370 22, 1995, 273, 283 },
371 { "Feenstra99",
372 "K. A. Feenstra and B. Hess and H. J. C. Berendsen",
373 "Improving Efficiency of Large Time-scale Molecular Dynamics Simulations of Hydrogen-rich Systems",
374 "J. Comput. Chem.",
375 20, 1999, 786, 798 },
376 { "Lindahl2001a",
377 "E. Lindahl and B. Hess and D. van der Spoel",
378 "GROMACS 3.0: A package for molecular simulation and trajectory analysis",
379 "J. Mol. Mod.",
380 7, 2001, 306, 317 },
381 { "Wang2001a",
382 "J. Wang and W. Wang and S. Huo and M. Lee and P. A. Kollman",
383 "Solvation model based on weighted solvent accessible surface area",
384 "J. Phys. Chem. B",
385 105, 2001, 5055, 5067 },
386 { "Eisenberg86a",
387 "D. Eisenberg and A. D. McLachlan",
388 "Solvation energy in protein folding and binding",
389 "Nature",
390 319, 1986, 199, 203 },
391 { "Eisenhaber95",
392 "Frank Eisenhaber and Philip Lijnzaad and Patrick Argos and Chris Sander and Michael Scharf",
393 "The Double Cube Lattice Method: Efficient Approaches to Numerical Integration of Surface Area and Volume and to Dot Surface Contouring of Molecular Assemblies",
394 "J. Comp. Chem.",
395 16, 1995, 273, 284 },
396 { "Hetenyi2002b",
397 "Csaba Hetenyi and David van der Spoel",
398 "Efficient docking of peptides to proteins without prior knowledge of the binding site.",
399 "Prot. Sci.",
400 11, 2002, 1729, 1737 }
402 #define NSTR (int)asize(citedb)
404 int j,index;
405 char *author;
406 char *title;
407 #define LINE_WIDTH 79
409 for(index=0; (index<NSTR) && (strcmp(citedb[index].key,key) != 0); index++)
412 fprintf(fp,"\n++++++++ PLEASE CITE THE FOLLOWING REFERENCE ++++++++\n");
413 if (index < NSTR) {
414 /* Insert newlines */
415 author = wrap_lines(citedb[index].author,LINE_WIDTH,0,FALSE);
416 title = wrap_lines(citedb[index].title,LINE_WIDTH,0,FALSE);
417 fprintf(fp,"%s\n%s\n%s %d (%d) pp. %d-%d\n",
418 author,title,citedb[index].journal,
419 citedb[index].volume,citedb[index].year,
420 citedb[index].p0,citedb[index].p1);
421 sfree(author);
422 sfree(title);
424 else {
425 fprintf(fp,"Entry %s not found in citation database\n",key);
427 fprintf(fp,"-------- -------- --- Thank You --- -------- --------\n\n");
428 fflush(fp);
431 /* This routine only returns a static (constant) string, so we use a
432 * mutex to initialize it. Since the string is only written to the
433 * first time, there is no risk with multiple calls overwriting the
434 * output for each other.
436 const char *GromacsVersion()
439 /* Concatenate the version info during preprocessing */
440 static const char ver_string[]="VERSION " VERSION;
442 return ver_string;