Update copyright statements and change license to LGPL
[alexxy/gromacs.git] / src / gmxlib / txtdump.c
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  * check out http://www.gromacs.org for more information.
7  * Copyright (c) 2012, by the GROMACS development team, led by
8  * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9  * others, as listed in the AUTHORS file in the top-level source
10  * directory and at http://www.gromacs.org.
11  *
12  * GROMACS is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public License
14  * as published by the Free Software Foundation; either version 2.1
15  * of the License, or (at your option) any later version.
16  *
17  * GROMACS is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with GROMACS; if not, see
24  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
26  *
27  * If you want to redistribute modifications to GROMACS, please
28  * consider that scientific software is very special. Version
29  * control is crucial - bugs must be traceable. We will be happy to
30  * consider code for inclusion in the official distribution, but
31  * derived work must not be called official GROMACS. Details are found
32  * in the README & COPYING files - if they are missing, get the
33  * official version at http://www.gromacs.org.
34  *
35  * To help us fund GROMACS development, we humbly ask that you cite
36  * the research papers on the package. Check out http://www.gromacs.org.
37  */
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 /* This file is completely threadsafe - please keep it that way! */
43 #ifdef GMX_THREAD_MPI
44 #include <thread_mpi.h>
45 #endif
46
47
48 #include <stdio.h>
49 #include "smalloc.h"
50 #include "typedefs.h"
51 #include "names.h"
52 #include "txtdump.h"
53 #include "string2.h"
54 #include "vec.h"
55
56
57 int pr_indent(FILE *fp,int n)
58 {
59   int i;
60
61   for (i=0; i<n; i++) (void) fprintf(fp," ");
62   return n;
63 }
64
65 int available(FILE *fp,void *p,int indent,const char *title)
66 {
67   if (!p) {
68     if (indent > 0)
69       pr_indent(fp,indent);
70     (void) fprintf(fp,"%s: not available\n",title);
71   }
72   return (p!=NULL);
73 }
74
75 int pr_title(FILE *fp,int indent,const char *title)
76 {
77   (void) pr_indent(fp,indent);
78   (void) fprintf(fp,"%s:\n",title);
79   return (indent+INDENT);
80 }
81
82 int pr_title_n(FILE *fp,int indent,const char *title,int n)
83 {
84   (void) pr_indent(fp,indent);
85   (void) fprintf(fp,"%s (%d):\n",title,n);
86   return (indent+INDENT);
87 }
88
89 int pr_title_nxn(FILE *fp,int indent,const char *title,int n1,int n2)
90 {
91   (void) pr_indent(fp,indent);
92   (void) fprintf(fp,"%s (%dx%d):\n",title,n1,n2);
93   return (indent+INDENT);
94 }
95
96 void pr_ivec(FILE *fp,int indent,const char *title,int vec[],int n, gmx_bool bShowNumbers)
97 {
98   int i;
99
100   if (available(fp,vec,indent,title))
101     {
102       indent=pr_title_n(fp,indent,title,n);
103       for (i=0; i<n; i++)
104         {
105           (void) pr_indent(fp,indent);
106           (void) fprintf(fp,"%s[%d]=%d\n",title,bShowNumbers?i:-1,vec[i]);
107         }
108     }
109 }
110
111 void pr_ivec_block(FILE *fp,int indent,const char *title,int vec[],int n, gmx_bool bShowNumbers)
112 {
113     int i,j;
114     
115     if (available(fp,vec,indent,title))
116     {
117         indent=pr_title_n(fp,indent,title,n);
118         i = 0;
119         while (i < n)
120         {
121             j = i+1;
122             while (j < n && vec[j] == vec[j-1]+1)
123             {
124                 j++;
125             }
126             /* Print consecutive groups of 3 or more as blocks */
127             if (j - i < 3)
128             {
129                 while(i < j)
130                 {
131                     (void) pr_indent(fp,indent);
132                     (void) fprintf(fp,"%s[%d]=%d\n",
133                                    title,bShowNumbers?i:-1,vec[i]);
134                     i++;
135                 }
136             }
137             else
138             {
139                 (void) pr_indent(fp,indent);
140                 (void) fprintf(fp,"%s[%d,...,%d] = {%d,...,%d}\n",
141                                title,
142                                bShowNumbers?i:-1,
143                                bShowNumbers?j-1:-1,
144                                vec[i],vec[j-1]); 
145                 i = j;
146             }
147         }
148     }
149 }
150
151 void pr_bvec(FILE *fp,int indent,const char *title,gmx_bool vec[],int n, gmx_bool bShowNumbers)
152 {
153   int i;
154
155   if (available(fp,vec,indent,title))
156     {
157       indent=pr_title_n(fp,indent,title,n);
158       for (i=0; i<n; i++)
159         {
160           (void) pr_indent(fp,indent);
161           (void) fprintf(fp,"%s[%d]=%s\n",title,bShowNumbers?i:-1,
162                          EBOOL(vec[i]));
163         }
164     }
165 }
166
167 void pr_ivecs(FILE *fp,int indent,const char *title,ivec vec[],int n, gmx_bool bShowNumbers)
168 {
169   int i,j;
170
171   if (available(fp,vec,indent,title))
172     {  
173       indent=pr_title_nxn(fp,indent,title,n,DIM);
174       for (i=0; i<n; i++)
175         {
176           (void) pr_indent(fp,indent);
177           (void) fprintf(fp,"%s[%d]={",title,bShowNumbers?i:-1);
178           for (j=0; j<DIM; j++)
179             {
180               if (j!=0) (void) fprintf(fp,", ");
181               fprintf(fp,"%d",vec[i][j]);
182             }
183           (void) fprintf(fp,"}\n");
184         }
185     }
186 }
187
188 void pr_rvec(FILE *fp,int indent,const char *title,real vec[],int n, gmx_bool bShowNumbers)
189 {
190   int i;
191
192   if (available(fp,vec,indent,title))
193     {  
194       indent=pr_title_n(fp,indent,title,n);
195       for (i=0; i<n; i++)
196         {
197           pr_indent(fp,indent);
198           fprintf(fp,"%s[%d]=%12.5e\n",title,bShowNumbers?i:-1,vec[i]);
199         }
200     }
201 }
202
203 void pr_dvec(FILE *fp,int indent,const char *title,double vec[],int n, gmx_bool bShowNumbers)
204 {
205         int i;
206         
207         if (available(fp,vec,indent,title))
208     {  
209                 indent=pr_title_n(fp,indent,title,n);
210                 for (i=0; i<n; i++)
211         {
212                         pr_indent(fp,indent);
213                         fprintf(fp,"%s[%d]=%12.5e\n",title,bShowNumbers?i:-1,vec[i]);
214         }
215     }
216 }
217
218
219 /*
220 void pr_mat(FILE *fp,int indent,char *title,matrix m)
221 {
222   int i,j;
223   
224   if (available(fp,m,indent,title)) {  
225     indent=pr_title_n(fp,indent,title,n);
226     for(i=0; i<n; i++) {
227       pr_indent(fp,indent);
228       fprintf(fp,"%s[%d]=%12.5e %12.5e %12.5e\n",
229               title,bShowNumbers?i:-1,m[i][XX],m[i][YY],m[i][ZZ]);
230     }
231   }
232 }
233 */
234
235 void pr_rvecs_len(FILE *fp,int indent,const char *title,rvec vec[],int n)
236 {
237   int i,j;
238
239   if (available(fp,vec,indent,title)) {  
240     indent=pr_title_nxn(fp,indent,title,n,DIM);
241     for (i=0; i<n; i++) {
242       (void) pr_indent(fp,indent);
243       (void) fprintf(fp,"%s[%5d]={",title,i);
244       for (j=0; j<DIM; j++) {
245         if (j != 0) 
246           (void) fprintf(fp,", ");
247         (void) fprintf(fp,"%12.5e",vec[i][j]);
248       }
249       (void) fprintf(fp,"} len=%12.5e\n",norm(vec[i]));
250     }
251   }
252 }
253
254 void pr_rvecs(FILE *fp,int indent,const char *title,rvec vec[],int n)
255 {
256   const char *fshort = "%12.5e";
257   const char *flong  = "%15.8e";
258   const char *format;
259   int i,j;
260
261   if (getenv("LONGFORMAT") != NULL)
262     format = flong;
263   else
264     format = fshort;
265     
266   if (available(fp,vec,indent,title)) {  
267     indent=pr_title_nxn(fp,indent,title,n,DIM);
268     for (i=0; i<n; i++) {
269       (void) pr_indent(fp,indent);
270       (void) fprintf(fp,"%s[%5d]={",title,i);
271       for (j=0; j<DIM; j++) {
272         if (j != 0) 
273           (void) fprintf(fp,", ");
274         (void) fprintf(fp,format,vec[i][j]);
275       }
276       (void) fprintf(fp,"}\n");
277     }
278   }
279 }
280
281
282 void pr_reals(FILE *fp,int indent,const char *title,real *vec,int n)
283 {
284   int i;
285     
286   if (available(fp,vec,indent,title)) {  
287     (void) pr_indent(fp,indent);
288     (void) fprintf(fp,"%s:\t",title);
289     for(i=0; i<n; i++)
290       fprintf(fp,"  %10g",vec[i]);
291     (void) fprintf(fp,"\n");
292   }
293 }
294
295 void pr_doubles(FILE *fp,int indent,const char *title,double *vec,int n)
296 {
297   int i;
298     
299   if (available(fp,vec,indent,title)) {  
300     (void) pr_indent(fp,indent);
301     (void) fprintf(fp,"%s:\t",title);
302     for(i=0; i<n; i++)
303       fprintf(fp,"  %10g",vec[i]);
304     (void) fprintf(fp,"\n");
305   }
306 }
307
308 static void pr_int(FILE *fp,int indent,const char *title,int i)
309 {
310   pr_indent(fp,indent);
311   fprintf(fp,"%-20s = %d\n",title,i);
312 }
313
314 static void pr_gmx_large_int(FILE *fp,int indent,const char *title,gmx_large_int_t i)
315 {
316   char buf[STEPSTRSIZE];
317
318   pr_indent(fp,indent);
319   fprintf(fp,"%-20s = %s\n",title,gmx_step_str(i,buf));
320 }
321
322 static void pr_real(FILE *fp,int indent,const char *title,real r)
323 {
324   pr_indent(fp,indent);
325   fprintf(fp,"%-20s = %g\n",title,r);
326 }
327
328 static void pr_double(FILE *fp,int indent,const char *title,double d)
329 {
330   pr_indent(fp,indent);
331   fprintf(fp,"%-20s = %g\n",title,d);
332 }
333
334 static void pr_str(FILE *fp,int indent,const char *title,const char *s)
335 {
336   pr_indent(fp,indent);
337   fprintf(fp,"%-20s = %s\n",title,s);
338 }
339
340 void pr_qm_opts(FILE *fp,int indent,const char *title,t_grpopts *opts)
341 {
342   int i,m,j;
343
344   fprintf(fp,"%s:\n",title);
345   
346   pr_int(fp,indent,"ngQM",opts->ngQM);
347   if (opts->ngQM > 0) {
348     pr_ivec(fp,indent,"QMmethod",opts->QMmethod,opts->ngQM,FALSE);
349     pr_ivec(fp,indent,"QMbasis",opts->QMbasis,opts->ngQM,FALSE);
350     pr_ivec(fp,indent,"QMcharge",opts->QMcharge,opts->ngQM,FALSE);
351     pr_ivec(fp,indent,"QMmult",opts->QMmult,opts->ngQM,FALSE);
352     pr_bvec(fp,indent,"bSH",opts->bSH,opts->ngQM,FALSE);
353     pr_ivec(fp,indent,"CASorbitals",opts->CASorbitals,opts->ngQM,FALSE);
354     pr_ivec(fp,indent,"CASelectrons",opts->CASelectrons,opts->ngQM,FALSE);
355     pr_rvec(fp,indent,"SAon",opts->SAon,opts->ngQM,FALSE);
356     pr_rvec(fp,indent,"SAon",opts->SAon,opts->ngQM,FALSE);
357     pr_ivec(fp,indent,"SAsteps",opts->SAsteps,opts->ngQM,FALSE);
358     pr_bvec(fp,indent,"bOPT",opts->bOPT,opts->ngQM,FALSE);
359     pr_bvec(fp,indent,"bTS",opts->bTS,opts->ngQM,FALSE);
360   }
361 }
362
363 static void pr_grp_opts(FILE *out,int indent,const char *title,t_grpopts *opts,
364                         gmx_bool bMDPformat)
365 {
366   int i,m,j;
367
368   if (!bMDPformat)
369     fprintf(out,"%s:\n",title);
370   
371   pr_indent(out,indent);
372   fprintf(out,"nrdf%s",bMDPformat ? " = " : ":");
373   for(i=0; (i<opts->ngtc); i++)
374     fprintf(out,"  %10g",opts->nrdf[i]);
375   fprintf(out,"\n");
376   
377   pr_indent(out,indent);
378   fprintf(out,"ref-t%s",bMDPformat ? " = " : ":");
379   for(i=0; (i<opts->ngtc); i++)
380     fprintf(out,"  %10g",opts->ref_t[i]);
381   fprintf(out,"\n");
382
383   pr_indent(out,indent);
384   fprintf(out,"tau-t%s",bMDPformat ? " = " : ":");
385   for(i=0; (i<opts->ngtc); i++)
386     fprintf(out,"  %10g",opts->tau_t[i]);
387   fprintf(out,"\n");  
388   
389   /* Pretty-print the simulated annealing info */
390   fprintf(out,"anneal%s",bMDPformat ? " = " : ":");
391   for(i=0; (i<opts->ngtc); i++)
392     fprintf(out,"  %10s",EANNEAL(opts->annealing[i]));
393   fprintf(out,"\n");  
394  
395   fprintf(out,"ann-npoints%s",bMDPformat ? " = " : ":");
396   for(i=0; (i<opts->ngtc); i++)
397     fprintf(out,"  %10d",opts->anneal_npoints[i]);
398   fprintf(out,"\n");  
399  
400   for(i=0; (i<opts->ngtc); i++) {
401     if(opts->anneal_npoints[i]>0) {
402       fprintf(out,"ann. times [%d]:\t",i);
403       for(j=0; (j<opts->anneal_npoints[i]); j++)
404         fprintf(out,"  %10.1f",opts->anneal_time[i][j]);
405       fprintf(out,"\n");  
406       fprintf(out,"ann. temps [%d]:\t",i);
407       for(j=0; (j<opts->anneal_npoints[i]); j++)
408         fprintf(out,"  %10.1f",opts->anneal_temp[i][j]);
409       fprintf(out,"\n");  
410     }
411   }
412   
413   pr_indent(out,indent);
414   fprintf(out,"acc:\t");
415   for(i=0; (i<opts->ngacc); i++)
416     for(m=0; (m<DIM); m++)
417       fprintf(out,"  %10g",opts->acc[i][m]);
418   fprintf(out,"\n");
419
420   pr_indent(out,indent);
421   fprintf(out,"nfreeze:");
422   for(i=0; (i<opts->ngfrz); i++)
423     for(m=0; (m<DIM); m++)
424       fprintf(out,"  %10s",opts->nFreeze[i][m] ? "Y" : "N");
425   fprintf(out,"\n");
426
427
428   for(i=0; (i<opts->ngener); i++) {
429     pr_indent(out,indent);
430     fprintf(out,"energygrp-flags[%3d]:",i);
431     for(m=0; (m<opts->ngener); m++)
432       fprintf(out," %d",opts->egp_flags[opts->ngener*i+m]);
433     fprintf(out,"\n");
434   }
435
436   fflush(out);
437 }
438
439 static void pr_matrix(FILE *fp,int indent,const char *title,rvec *m,
440                       gmx_bool bMDPformat)
441 {
442   if (bMDPformat)
443     fprintf(fp,"%-10s    = %g %g %g %g %g %g\n",title,
444             m[XX][XX],m[YY][YY],m[ZZ][ZZ],m[XX][YY],m[XX][ZZ],m[YY][ZZ]);
445   else
446     pr_rvecs(fp,indent,title,m,DIM);
447 }
448
449 static void pr_cosine(FILE *fp,int indent,const char *title,t_cosines *cos,
450                       gmx_bool bMDPformat)
451 {
452   int j;
453   
454   if (bMDPformat) {
455     fprintf(fp,"%s = %d\n",title,cos->n);
456   }
457   else {
458     indent=pr_title(fp,indent,title);
459     (void) pr_indent(fp,indent);
460     fprintf(fp,"n = %d\n",cos->n);
461     if (cos->n > 0) {
462       (void) pr_indent(fp,indent+2);
463       fprintf(fp,"a =");
464       for(j=0; (j<cos->n); j++)
465         fprintf(fp," %e",cos->a[j]);
466       fprintf(fp,"\n");
467       (void) pr_indent(fp,indent+2);
468       fprintf(fp,"phi =");
469       for(j=0; (j<cos->n); j++)
470         fprintf(fp," %e",cos->phi[j]);
471       fprintf(fp,"\n");
472     }
473   }
474 }
475
476 #define PS(t,s) pr_str(fp,indent,t,s)
477 #define PI(t,s) pr_int(fp,indent,t,s)
478 #define PSTEP(t,s) pr_gmx_large_int(fp,indent,t,s)
479 #define PR(t,s) pr_real(fp,indent,t,s)
480 #define PD(t,s) pr_double(fp,indent,t,s)
481
482 static void pr_pullgrp(FILE *fp,int indent,int g,t_pullgrp *pg)
483 {
484   pr_indent(fp,indent);
485   fprintf(fp,"pull-group %d:\n",g);
486   indent += 2;
487   pr_ivec_block(fp,indent,"atom",pg->ind,pg->nat,TRUE);
488   pr_rvec(fp,indent,"weight",pg->weight,pg->nweight,TRUE);
489   PI("pbcatom",pg->pbcatom);
490   pr_rvec(fp,indent,"vec",pg->vec,DIM,TRUE);
491   pr_rvec(fp,indent,"init",pg->init,DIM,TRUE);
492   PR("rate",pg->rate);
493   PR("k",pg->k);
494   PR("kB",pg->kB);
495 }
496
497 static void pr_simtempvals(FILE *fp,int indent,t_simtemp *simtemp, int n_lambda, gmx_bool bMDPformat)
498 {
499     PR("simtemp_low",simtemp->simtemp_low);
500     PR("simtemp_high",simtemp->simtemp_high);
501     PS("simulated-tempering-scaling",ESIMTEMP(simtemp->eSimTempScale));
502     pr_rvec(fp,indent,"simulated tempering temperatures",simtemp->temperatures,n_lambda,TRUE);
503 }
504
505 static void pr_expandedvals(FILE *fp,int indent,t_expanded *expand, int n_lambda, gmx_bool bMDPformat)
506 {
507
508     PI("nstexpanded", expand->nstexpanded);
509     PS("lambda-stats", elamstats_names[expand->elamstats]);
510     PS("lambda-mc-move", elmcmove_names[expand->elmcmove]);
511     PI("lmc-repeats",expand->lmc_repeats);
512     PI("lmc-gibbsdelta",expand->gibbsdeltalam);
513     PI("lmc-nstart",expand->lmc_forced_nstart);
514     PS("symmetrized-transition-matrix", EBOOL(expand->bSymmetrizedTMatrix));
515     PI("nst-transition-matrix",expand->nstTij);
516     PI("mininum-var-min",expand->minvarmin); /*default is reasonable */
517     PI("weight-c-range",expand->c_range); /* default is just C=0 */
518     PR("wl-scale",expand->wl_scale);
519     PR("init-wl-delta",expand->init_wl_delta);
520     PR("wl-ratio",expand->wl_ratio);
521     PS("bWLoneovert",EBOOL(expand->bWLoneovert));
522     PI("lmc-seed",expand->lmc_seed);
523     PR("mc-temperature",expand->mc_temp);
524     PS("lmc-weights-equil",elmceq_names[expand->elmceq]);
525     if (expand->elmceq == elmceqNUMATLAM)
526     {
527         PI("weight-equil-number-all-lambda",expand->equil_n_at_lam);
528     }
529     if (expand->elmceq == elmceqSAMPLES)
530     {
531         PI("weight-equil-number-samples",expand->equil_samples);
532     }
533     if (expand->elmceq == elmceqSTEPS)
534     {
535         PI("weight-equil-number-steps",expand->equil_steps);
536     }
537     if (expand->elmceq == elmceqWLDELTA)
538     {
539         PR("weight-equil-wl-delta",expand->equil_wl_delta);
540     }
541     if (expand->elmceq == elmceqRATIO)
542     {
543         PR("weight-equil-count-ratio",expand->equil_ratio);
544     }
545
546     pr_indent(fp,indent);
547     pr_rvec(fp,indent,"init-lambda-weights",expand->init_lambda_weights,n_lambda,TRUE);
548     PS("init-weights",EBOOL(expand->bInit_weights));
549 }
550
551 static void pr_fepvals(FILE *fp,int indent,t_lambda *fep, gmx_bool bMDPformat)
552 {
553     int i,j;
554
555     PI("nstdhdl",fep->nstdhdl);
556     PI("init-lambda-state",fep->init_fep_state);
557     PR("init-lambda",fep->init_lambda);
558     PR("delta-lambda",fep->delta_lambda);
559     if (!bMDPformat)
560     {
561         PI("n-lambdas",fep->n_lambda);
562     }
563     if (fep->n_lambda > 0)
564     {
565         pr_indent(fp,indent);
566         fprintf(fp,"all-lambdas%s\n",bMDPformat ? " = " : ":");
567         for(i=0; i<efptNR; i++) {
568             fprintf(fp,"%18s = ",efpt_names[i]);
569             for(j=0; j<fep->n_lambda; j++)
570             {
571                 fprintf(fp,"  %10g",fep->all_lambda[i][j]);
572             }
573             fprintf(fp,"\n");
574         }
575     }
576
577     PR("sc-alpha",fep->sc_alpha);
578     PS("bScCoul",EBOOL(fep->bScCoul));
579     PS("bScPrintEnergy",EBOOL(fep->bPrintEnergy));
580     PI("sc-power",fep->sc_power);
581     PR("sc-r-power",fep->sc_r_power);
582     PR("sc-sigma",fep->sc_sigma);
583     PR("sc-sigma-min",fep->sc_sigma_min);
584     PS("separate-dhdl-file", SEPDHDLFILETYPE(fep->separate_dhdl_file));
585     PS("dhdl-derivatives", DHDLDERIVATIVESTYPE(fep->dhdl_derivatives));
586     PI("dh-hist-size", fep->dh_hist_size);
587     PD("dh-hist-spacing", fep->dh_hist_spacing);
588 };
589
590 static void pr_pull(FILE *fp,int indent,t_pull *pull)
591 {
592   int g;
593
594   PS("pull-geometry",EPULLGEOM(pull->eGeom));
595   pr_ivec(fp,indent,"pull-dim",pull->dim,DIM,TRUE);
596   PR("pull-r1",pull->cyl_r1);
597   PR("pull-r0",pull->cyl_r0);
598   PR("pull-constr-tol",pull->constr_tol);
599   PI("pull-nstxout",pull->nstxout);
600   PI("pull-nstfout",pull->nstfout);
601   PI("pull-ngrp",pull->ngrp);
602   for(g=0; g<pull->ngrp+1; g++)
603     pr_pullgrp(fp,indent,g,&pull->grp[g]);
604 }
605
606 static void pr_rotgrp(FILE *fp,int indent,int g,t_rotgrp *rotg)
607 {
608   pr_indent(fp,indent);
609   fprintf(fp,"rotation_group %d:\n",g);
610   indent += 2;
611   PS("type",EROTGEOM(rotg->eType));
612   PS("massw",EBOOL(rotg->bMassW));
613   pr_ivec_block(fp,indent,"atom",rotg->ind,rotg->nat,TRUE);
614   pr_rvecs(fp,indent,"x_ref",rotg->x_ref,rotg->nat);
615   pr_rvec(fp,indent,"vec",rotg->vec,DIM,TRUE);
616   pr_rvec(fp,indent,"pivot",rotg->pivot,DIM,TRUE);
617   PR("rate",rotg->rate);
618   PR("k",rotg->k);
619   PR("slab_dist",rotg->slab_dist);
620   PR("min_gaussian",rotg->min_gaussian);
621   PR("epsilon",rotg->eps);
622   PS("fit_method",EROTFIT(rotg->eFittype));
623   PI("potfitangle_nstep",rotg->PotAngle_nstep);
624   PR("potfitangle_step",rotg->PotAngle_step);
625 }
626
627 static void pr_rot(FILE *fp,int indent,t_rot *rot)
628 {
629   int g;
630
631   PI("rot_nstrout",rot->nstrout);
632   PI("rot_nstsout",rot->nstsout);
633   PI("rot_ngrp",rot->ngrp);
634   for(g=0; g<rot->ngrp; g++)
635     pr_rotgrp(fp,indent,g,&rot->grp[g]);
636 }
637
638 void pr_inputrec(FILE *fp,int indent,const char *title,t_inputrec *ir,
639                  gmx_bool bMDPformat)
640 {
641   const char *infbuf="inf";
642   int  i;
643   
644   if (available(fp,ir,indent,title)) {
645     if (!bMDPformat)
646       indent=pr_title(fp,indent,title);
647     PS("integrator",EI(ir->eI));
648     PSTEP("nsteps",ir->nsteps);
649     PSTEP("init-step",ir->init_step);
650     PS("cutoff-scheme",ECUTSCHEME(ir->cutoff_scheme));
651     PS("ns_type",ENS(ir->ns_type));
652     PI("nstlist",ir->nstlist);
653     PI("ndelta",ir->ndelta);
654     PI("nstcomm",ir->nstcomm);
655     PS("comm-mode",ECOM(ir->comm_mode));
656     PI("nstlog",ir->nstlog);
657     PI("nstxout",ir->nstxout);
658     PI("nstvout",ir->nstvout);
659     PI("nstfout",ir->nstfout);
660     PI("nstcalcenergy",ir->nstcalcenergy);
661     PI("nstenergy",ir->nstenergy);
662     PI("nstxtcout",ir->nstxtcout);
663     PR("init-t",ir->init_t);
664     PR("delta-t",ir->delta_t);
665     
666     PR("xtcprec",ir->xtcprec);
667     PR("fourierspacing",ir->fourier_spacing);
668     PI("nkx",ir->nkx);
669     PI("nky",ir->nky);
670     PI("nkz",ir->nkz);
671     PI("pme-order",ir->pme_order);
672     PR("ewald-rtol",ir->ewald_rtol);
673     PR("ewald-geometry",ir->ewald_geometry);
674     PR("epsilon-surface",ir->epsilon_surface);
675     PS("optimize-fft",EBOOL(ir->bOptFFT));
676     PS("ePBC",EPBC(ir->ePBC));
677     PS("bPeriodicMols",EBOOL(ir->bPeriodicMols));
678     PS("bContinuation",EBOOL(ir->bContinuation));
679     PS("bShakeSOR",EBOOL(ir->bShakeSOR));
680     PS("etc",ETCOUPLTYPE(ir->etc));
681     PS("bPrintNHChains",EBOOL(ir->bPrintNHChains));
682     PI("nsttcouple",ir->nsttcouple);
683     PS("epc",EPCOUPLTYPE(ir->epc));
684     PS("epctype",EPCOUPLTYPETYPE(ir->epct));
685     PI("nstpcouple",ir->nstpcouple);
686     PR("tau-p",ir->tau_p);
687     pr_matrix(fp,indent,"ref-p",ir->ref_p,bMDPformat);
688     pr_matrix(fp,indent,"compress",ir->compress,bMDPformat);
689     PS("refcoord-scaling",EREFSCALINGTYPE(ir->refcoord_scaling));
690     if (bMDPformat)
691       fprintf(fp,"posres-com  = %g %g %g\n",ir->posres_com[XX],
692               ir->posres_com[YY],ir->posres_com[ZZ]);
693     else
694       pr_rvec(fp,indent,"posres-com",ir->posres_com,DIM,TRUE);
695     if (bMDPformat)
696       fprintf(fp,"posres-comB = %g %g %g\n",ir->posres_comB[XX],
697               ir->posres_comB[YY],ir->posres_comB[ZZ]);
698     else
699       pr_rvec(fp,indent,"posres-comB",ir->posres_comB,DIM,TRUE);
700     PR("verlet-buffer-drift",ir->verletbuf_drift);
701     PR("rlist",ir->rlist);
702     PR("rlistlong",ir->rlistlong);
703     PR("nstcalclr",ir->nstcalclr);
704     PR("rtpi",ir->rtpi);
705     PS("coulombtype",EELTYPE(ir->coulombtype));
706     PS("coulomb-modifier",INTMODIFIER(ir->coulomb_modifier));
707     PR("rcoulomb-switch",ir->rcoulomb_switch);
708     PR("rcoulomb",ir->rcoulomb);
709     PS("vdwtype",EVDWTYPE(ir->vdwtype));
710     PS("vdw-modifier",INTMODIFIER(ir->vdw_modifier));
711     PR("rvdw-switch",ir->rvdw_switch);
712     PR("rvdw",ir->rvdw);
713     if (ir->epsilon_r != 0)
714       PR("epsilon-r",ir->epsilon_r);
715     else
716       PS("epsilon-r",infbuf);
717     if (ir->epsilon_rf != 0)
718       PR("epsilon-rf",ir->epsilon_rf);
719     else
720       PS("epsilon-rf",infbuf);
721     PR("tabext",ir->tabext);
722     PS("implicit-solvent",EIMPLICITSOL(ir->implicit_solvent));
723     PS("gb-algorithm",EGBALGORITHM(ir->gb_algorithm));
724     PR("gb-epsilon-solvent",ir->gb_epsilon_solvent);
725     PI("nstgbradii",ir->nstgbradii);
726     PR("rgbradii",ir->rgbradii);
727     PR("gb-saltconc",ir->gb_saltconc);
728     PR("gb-obc-alpha",ir->gb_obc_alpha);
729     PR("gb-obc-beta",ir->gb_obc_beta);
730     PR("gb-obc-gamma",ir->gb_obc_gamma);
731     PR("gb-dielectric-offset",ir->gb_dielectric_offset);
732     PS("sa-algorithm",ESAALGORITHM(ir->gb_algorithm));
733     PR("sa-surface-tension",ir->sa_surface_tension);
734     PS("DispCorr",EDISPCORR(ir->eDispCorr));
735     PS("bSimTemp",EBOOL(ir->bSimTemp));
736     if (ir->bSimTemp) {
737         pr_simtempvals(fp,indent,ir->simtempvals,ir->fepvals->n_lambda,bMDPformat);
738     }
739     PS("free-energy",EFEPTYPE(ir->efep));
740     if (ir->efep != efepNO || ir->bSimTemp) {
741         pr_fepvals(fp,indent,ir->fepvals,bMDPformat);
742     }
743     if (ir->bExpanded) {
744         pr_expandedvals(fp,indent,ir->expandedvals,ir->fepvals->n_lambda,bMDPformat);
745     }
746
747     PI("nwall",ir->nwall);
748     PS("wall-type",EWALLTYPE(ir->wall_type));
749     PI("wall-atomtype[0]",ir->wall_atomtype[0]);
750     PI("wall-atomtype[1]",ir->wall_atomtype[1]);
751     PR("wall-density[0]",ir->wall_density[0]);
752     PR("wall-density[1]",ir->wall_density[1]);
753     PR("wall-ewald-zfac",ir->wall_ewald_zfac);
754
755     PS("pull",EPULLTYPE(ir->ePull));
756     if (ir->ePull != epullNO)
757       pr_pull(fp,indent,ir->pull);
758     
759     PS("rotation",EBOOL(ir->bRot));
760     if (ir->bRot)
761       pr_rot(fp,indent,ir->rot);
762
763     PS("disre",EDISRETYPE(ir->eDisre));
764     PS("disre-weighting",EDISREWEIGHTING(ir->eDisreWeighting));
765     PS("disre-mixed",EBOOL(ir->bDisreMixed));
766     PR("dr-fc",ir->dr_fc);
767     PR("dr-tau",ir->dr_tau);
768     PR("nstdisreout",ir->nstdisreout);
769     PR("orires-fc",ir->orires_fc);
770     PR("orires-tau",ir->orires_tau);
771     PR("nstorireout",ir->nstorireout);
772
773     PR("dihre-fc",ir->dihre_fc);
774     
775     PR("em-stepsize",ir->em_stepsize);
776     PR("em-tol",ir->em_tol);
777     PI("niter",ir->niter);
778     PR("fc-stepsize",ir->fc_stepsize);
779     PI("nstcgsteep",ir->nstcgsteep);
780     PI("nbfgscorr",ir->nbfgscorr);
781
782     PS("ConstAlg",ECONSTRTYPE(ir->eConstrAlg));
783     PR("shake-tol",ir->shake_tol);
784     PI("lincs-order",ir->nProjOrder);
785     PR("lincs-warnangle",ir->LincsWarnAngle);
786     PI("lincs-iter",ir->nLincsIter);
787     PR("bd-fric",ir->bd_fric);
788     PI("ld-seed",ir->ld_seed);
789     PR("cos-accel",ir->cos_accel);
790     pr_matrix(fp,indent,"deform",ir->deform,bMDPformat);
791
792     PS("adress",EBOOL(ir->bAdress));
793     if (ir->bAdress){
794         PS("adress_type",EADRESSTYPE(ir->adress->type));
795         PR("adress_const_wf",ir->adress->const_wf);
796         PR("adress_ex_width",ir->adress->ex_width);
797         PR("adress_hy_width",ir->adress->hy_width);
798         PS("adress_interface_correction",EADRESSICTYPE(ir->adress->icor));
799         PS("adress_site",EADRESSSITETYPE(ir->adress->site));
800         PR("adress_ex_force_cap",ir->adress->ex_forcecap);
801         PS("adress_do_hybridpairs", EBOOL(ir->adress->do_hybridpairs));
802
803         pr_rvec(fp,indent,"adress_reference_coords",ir->adress->refs,DIM,TRUE);
804     }
805     PI("userint1",ir->userint1);
806     PI("userint2",ir->userint2);
807     PI("userint3",ir->userint3);
808     PI("userint4",ir->userint4);
809     PR("userreal1",ir->userreal1);
810     PR("userreal2",ir->userreal2);
811     PR("userreal3",ir->userreal3);
812     PR("userreal4",ir->userreal4);
813     pr_grp_opts(fp,indent,"grpopts",&(ir->opts),bMDPformat);
814     pr_cosine(fp,indent,"efield-x",&(ir->ex[XX]),bMDPformat);
815     pr_cosine(fp,indent,"efield-xt",&(ir->et[XX]),bMDPformat);
816     pr_cosine(fp,indent,"efield-y",&(ir->ex[YY]),bMDPformat);
817     pr_cosine(fp,indent,"efield-yt",&(ir->et[YY]),bMDPformat);
818     pr_cosine(fp,indent,"efield-z",&(ir->ex[ZZ]),bMDPformat);
819     pr_cosine(fp,indent,"efield-zt",&(ir->et[ZZ]),bMDPformat);
820     PS("bQMMM",EBOOL(ir->bQMMM));
821     PI("QMconstraints",ir->QMconstraints);
822     PI("QMMMscheme",ir->QMMMscheme);
823     PR("scalefactor",ir->scalefactor);
824     pr_qm_opts(fp,indent,"qm-opts",&(ir->opts));
825   }
826 }
827 #undef PS
828 #undef PR
829 #undef PI
830
831 static void pr_harm(FILE *fp,t_iparams *iparams,const char *r,const char *kr)
832 {
833   fprintf(fp,"%sA=%12.5e, %sA=%12.5e, %sB=%12.5e, %sB=%12.5e\n",
834           r,iparams->harmonic.rA,kr,iparams->harmonic.krA,
835           r,iparams->harmonic.rB,kr,iparams->harmonic.krB);
836 }
837
838 void pr_iparams(FILE *fp,t_functype ftype,t_iparams *iparams)
839 {
840   int i;
841   real VA[4],VB[4],*rbcA,*rbcB;
842
843   switch (ftype) {
844   case F_ANGLES:
845   case F_G96ANGLES:
846     pr_harm(fp,iparams,"th","ct");
847     break;
848   case F_CROSS_BOND_BONDS:
849     fprintf(fp,"r1e=%15.8e, r2e=%15.8e, krr=%15.8e\n",
850             iparams->cross_bb.r1e,iparams->cross_bb.r2e,
851             iparams->cross_bb.krr);
852     break;
853   case F_CROSS_BOND_ANGLES:
854     fprintf(fp,"r1e=%15.8e, r1e=%15.8e, r3e=%15.8e, krt=%15.8e\n",
855             iparams->cross_ba.r1e,iparams->cross_ba.r2e,
856             iparams->cross_ba.r3e,iparams->cross_ba.krt);
857     break;
858   case F_LINEAR_ANGLES:
859     fprintf(fp,"klinA=%15.8e, aA=%15.8e, klinB=%15.8e, aB=%15.8e\n",
860             iparams->linangle.klinA,iparams->linangle.aA,
861             iparams->linangle.klinB,iparams->linangle.aB);
862     break;
863   case F_UREY_BRADLEY:
864       fprintf(fp,"thetaA=%15.8e, kthetaA=%15.8e, r13A=%15.8e, kUBA=%15.8e, thetaB=%15.8e, kthetaB=%15.8e, r13B=%15.8e, kUBB=%15.8e\n",iparams->u_b.thetaA,iparams->u_b.kthetaA,iparams->u_b.r13A,iparams->u_b.kUBA,iparams->u_b.thetaB,iparams->u_b.kthetaB,iparams->u_b.r13B,iparams->u_b.kUBB);
865     break;
866   case F_QUARTIC_ANGLES:
867     fprintf(fp,"theta=%15.8e",iparams->qangle.theta);
868     for(i=0; i<5; i++)
869       fprintf(fp,", c%c=%15.8e",'0'+i,iparams->qangle.c[i]);
870     fprintf(fp,"\n");
871     break;
872   case F_BHAM:
873     fprintf(fp,"a=%15.8e, b=%15.8e, c=%15.8e\n",
874             iparams->bham.a,iparams->bham.b,iparams->bham.c);
875     break;
876   case F_BONDS:
877   case F_G96BONDS:
878   case F_HARMONIC:
879     pr_harm(fp,iparams,"b0","cb");
880     break;
881   case F_IDIHS:
882     pr_harm(fp,iparams,"xi","cx");
883     break;
884   case F_MORSE:
885     fprintf(fp,"b0A=%15.8e, cbA=%15.8e, betaA=%15.8e, b0B=%15.8e, cbB=%15.8e, betaB=%15.8e\n",
886             iparams->morse.b0A,iparams->morse.cbA,iparams->morse.betaA,
887             iparams->morse.b0B,iparams->morse.cbB,iparams->morse.betaB);
888     break;
889   case F_CUBICBONDS:
890     fprintf(fp,"b0=%15.8e, kb=%15.8e, kcub=%15.8e\n",
891             iparams->cubic.b0,iparams->cubic.kb,iparams->cubic.kcub);
892     break;
893   case F_CONNBONDS:
894     fprintf(fp,"\n");
895     break;
896   case F_FENEBONDS:
897     fprintf(fp,"bm=%15.8e, kb=%15.8e\n",iparams->fene.bm,iparams->fene.kb);
898     break;
899   case F_RESTRBONDS:
900       fprintf(fp,"lowA=%15.8e, up1A=%15.8e, up2A=%15.8e, kA=%15.8e, lowB=%15.8e, up1B=%15.8e, up2B=%15.8e, kB=%15.8e,\n",
901               iparams->restraint.lowA,iparams->restraint.up1A,
902               iparams->restraint.up2A,iparams->restraint.kA,
903               iparams->restraint.lowB,iparams->restraint.up1B,
904               iparams->restraint.up2B,iparams->restraint.kB);
905       break;
906   case F_TABBONDS:
907   case F_TABBONDSNC:
908   case F_TABANGLES:
909   case F_TABDIHS:
910     fprintf(fp,"tab=%d, kA=%15.8e, kB=%15.8e\n",
911             iparams->tab.table,iparams->tab.kA,iparams->tab.kB);
912     break;
913   case F_POLARIZATION:
914     fprintf(fp,"alpha=%15.8e\n",iparams->polarize.alpha);
915     break;
916   case F_ANHARM_POL:
917     fprintf(fp,"alpha=%15.8e drcut=%15.8e khyp=%15.8e\n",
918             iparams->anharm_polarize.alpha,
919             iparams->anharm_polarize.drcut,
920             iparams->anharm_polarize.khyp);
921     break;
922   case F_THOLE_POL:
923     fprintf(fp,"a=%15.8e, alpha1=%15.8e, alpha2=%15.8e, rfac=%15.8e\n",
924             iparams->thole.a,iparams->thole.alpha1,iparams->thole.alpha2,
925             iparams->thole.rfac);
926     break;
927   case F_WATER_POL:
928     fprintf(fp,"al_x=%15.8e, al_y=%15.8e, al_z=%15.8e, rOH=%9.6f, rHH=%9.6f, rOD=%9.6f\n",
929             iparams->wpol.al_x,iparams->wpol.al_y,iparams->wpol.al_z,
930             iparams->wpol.rOH,iparams->wpol.rHH,iparams->wpol.rOD);
931     break;
932   case F_LJ:
933     fprintf(fp,"c6=%15.8e, c12=%15.8e\n",iparams->lj.c6,iparams->lj.c12);
934     break;
935   case F_LJ14:
936     fprintf(fp,"c6A=%15.8e, c12A=%15.8e, c6B=%15.8e, c12B=%15.8e\n",
937             iparams->lj14.c6A,iparams->lj14.c12A,
938             iparams->lj14.c6B,iparams->lj14.c12B);
939     break;
940   case F_LJC14_Q:
941     fprintf(fp,"fqq=%15.8e, qi=%15.8e, qj=%15.8e, c6=%15.8e, c12=%15.8e\n",
942             iparams->ljc14.fqq,
943             iparams->ljc14.qi,iparams->ljc14.qj,
944             iparams->ljc14.c6,iparams->ljc14.c12);
945     break;
946   case F_LJC_PAIRS_NB:
947     fprintf(fp,"qi=%15.8e, qj=%15.8e, c6=%15.8e, c12=%15.8e\n",
948             iparams->ljcnb.qi,iparams->ljcnb.qj,
949             iparams->ljcnb.c6,iparams->ljcnb.c12);
950     break;
951   case F_PDIHS:
952   case F_PIDIHS:
953   case F_ANGRES:
954   case F_ANGRESZ:
955     fprintf(fp,"phiA=%15.8e, cpA=%15.8e, phiB=%15.8e, cpB=%15.8e, mult=%d\n",
956             iparams->pdihs.phiA,iparams->pdihs.cpA,
957             iparams->pdihs.phiB,iparams->pdihs.cpB,
958             iparams->pdihs.mult);
959     break;
960   case F_DISRES:
961     fprintf(fp,"label=%4d, type=%1d, low=%15.8e, up1=%15.8e, up2=%15.8e, fac=%15.8e)\n",
962             iparams->disres.label,iparams->disres.type,
963             iparams->disres.low,iparams->disres.up1,
964             iparams->disres.up2,iparams->disres.kfac);
965     break;
966   case F_ORIRES:
967     fprintf(fp,"ex=%4d, label=%d, power=%4d, c=%15.8e, obs=%15.8e, kfac=%15.8e)\n",
968             iparams->orires.ex,iparams->orires.label,iparams->orires.power,
969             iparams->orires.c,iparams->orires.obs,iparams->orires.kfac);
970     break;
971   case F_DIHRES:
972       fprintf(fp,"phiA=%15.8e, dphiA=%15.8e, kfacA=%15.8e, phiB=%15.8e, dphiB=%15.8e, kfacB=%15.8e\n",
973               iparams->dihres.phiA,iparams->dihres.dphiA,iparams->dihres.kfacA,
974               iparams->dihres.phiB,iparams->dihres.dphiB,iparams->dihres.kfacB);
975     break;
976   case F_POSRES:
977     fprintf(fp,"pos0A=(%15.8e,%15.8e,%15.8e), fcA=(%15.8e,%15.8e,%15.8e), pos0B=(%15.8e,%15.8e,%15.8e), fcB=(%15.8e,%15.8e,%15.8e)\n",
978             iparams->posres.pos0A[XX],iparams->posres.pos0A[YY],
979             iparams->posres.pos0A[ZZ],iparams->posres.fcA[XX],
980             iparams->posres.fcA[YY],iparams->posres.fcA[ZZ],
981             iparams->posres.pos0B[XX],iparams->posres.pos0B[YY],
982             iparams->posres.pos0B[ZZ],iparams->posres.fcB[XX],
983             iparams->posres.fcB[YY],iparams->posres.fcB[ZZ]);
984     break;
985   case F_RBDIHS:
986     for (i=0; i<NR_RBDIHS; i++) 
987       fprintf(fp,"%srbcA[%d]=%15.8e",i==0?"":", ",i,iparams->rbdihs.rbcA[i]);
988     fprintf(fp,"\n");
989     for (i=0; i<NR_RBDIHS; i++) 
990       fprintf(fp,"%srbcB[%d]=%15.8e",i==0?"":", ",i,iparams->rbdihs.rbcB[i]);
991     fprintf(fp,"\n");
992     break;
993   case F_FOURDIHS:
994     /* Use the OPLS -> Ryckaert-Bellemans formula backwards to get the
995      * OPLS potential constants back.
996      */
997     rbcA = iparams->rbdihs.rbcA;
998     rbcB = iparams->rbdihs.rbcB;
999
1000     VA[3] = -0.25*rbcA[4];
1001     VA[2] = -0.5*rbcA[3];
1002     VA[1] = 4.0*VA[3]-rbcA[2];
1003     VA[0] = 3.0*VA[2]-2.0*rbcA[1];
1004
1005     VB[3] = -0.25*rbcB[4];
1006     VB[2] = -0.5*rbcB[3];
1007     VB[1] = 4.0*VB[3]-rbcB[2];
1008     VB[0] = 3.0*VB[2]-2.0*rbcB[1];
1009
1010     for (i=0; i<NR_FOURDIHS; i++) 
1011       fprintf(fp,"%sFourA[%d]=%15.8e",i==0?"":", ",i,VA[i]);
1012     fprintf(fp,"\n");
1013     for (i=0; i<NR_FOURDIHS; i++) 
1014       fprintf(fp,"%sFourB[%d]=%15.8e",i==0?"":", ",i,VB[i]);
1015     fprintf(fp,"\n");
1016     break;
1017    
1018   case F_CONSTR:
1019   case F_CONSTRNC:
1020     fprintf(fp,"dA=%15.8e, dB=%15.8e\n",iparams->constr.dA,iparams->constr.dB);
1021     break;
1022   case F_SETTLE:
1023     fprintf(fp,"doh=%15.8e, dhh=%15.8e\n",iparams->settle.doh,
1024             iparams->settle.dhh);
1025     break;
1026   case F_VSITE2:
1027     fprintf(fp,"a=%15.8e\n",iparams->vsite.a);
1028     break;
1029   case F_VSITE3:
1030   case F_VSITE3FD:
1031   case F_VSITE3FAD:
1032     fprintf(fp,"a=%15.8e, b=%15.8e\n",iparams->vsite.a,iparams->vsite.b);
1033     break;
1034   case F_VSITE3OUT:
1035   case F_VSITE4FD:
1036   case F_VSITE4FDN:
1037     fprintf(fp,"a=%15.8e, b=%15.8e, c=%15.8e\n",
1038             iparams->vsite.a,iparams->vsite.b,iparams->vsite.c);
1039     break;
1040   case F_VSITEN:
1041     fprintf(fp,"n=%2d, a=%15.8e\n",iparams->vsiten.n,iparams->vsiten.a);
1042     break;
1043   case F_GB12:
1044   case F_GB13:
1045   case F_GB14:
1046     fprintf(fp, "sar=%15.8e, st=%15.8e, pi=%15.8e, gbr=%15.8e, bmlt=%15.8e\n",iparams->gb.sar,iparams->gb.st,iparams->gb.pi,iparams->gb.gbr,iparams->gb.bmlt);
1047     break;                
1048   case F_CMAP:
1049     fprintf(fp, "cmapA=%1d, cmapB=%1d\n",iparams->cmap.cmapA, iparams->cmap.cmapB);
1050     break;                
1051   default:
1052     gmx_fatal(FARGS,"unknown function type %d (%s) in %s line %d",
1053               ftype,interaction_function[ftype].name,__FILE__,__LINE__);
1054   }
1055 }
1056
1057 void pr_ilist(FILE *fp,int indent,const char *title,
1058               t_functype *functype,t_ilist *ilist, gmx_bool bShowNumbers)
1059 {
1060     int i,j,k,type,ftype;
1061     t_iatom *iatoms;
1062     
1063     if (available(fp,ilist,indent,title) && ilist->nr > 0)
1064     {  
1065         indent=pr_title(fp,indent,title);
1066         (void) pr_indent(fp,indent);
1067         fprintf(fp,"nr: %d\n",ilist->nr);
1068         if (ilist->nr > 0) {
1069             (void) pr_indent(fp,indent);
1070             fprintf(fp,"iatoms:\n");
1071             iatoms=ilist->iatoms;
1072             for (i=j=0; i<ilist->nr;) {
1073 #ifndef DEBUG
1074                 (void) pr_indent(fp,indent+INDENT);
1075                 type=*(iatoms++);
1076                 ftype=functype[type];
1077                 (void) fprintf(fp,"%d type=%d (%s)",
1078                                bShowNumbers?j:-1,bShowNumbers?type:-1,
1079                                interaction_function[ftype].name);
1080                 j++;
1081                 for (k=0; k<interaction_function[ftype].nratoms; k++)
1082                     (void) fprintf(fp," %u",*(iatoms++));
1083                 (void) fprintf(fp,"\n");
1084                 i+=1+interaction_function[ftype].nratoms;
1085 #else
1086                 fprintf(fp,"%5d%5d\n",i,iatoms[i]);
1087                 i++;
1088 #endif
1089             }
1090         }
1091     }
1092 }
1093
1094 static void pr_cmap(FILE *fp, int indent, const char *title,
1095                     gmx_cmap_t *cmap_grid, gmx_bool bShowNumbers)
1096 {
1097     int i,j,nelem;
1098     real dx,idx;
1099         
1100     dx    = 360.0 / cmap_grid->grid_spacing;
1101     nelem = cmap_grid->grid_spacing*cmap_grid->grid_spacing;
1102         
1103     if(available(fp,cmap_grid,indent,title))
1104     {
1105         fprintf(fp,"%s\n",title);
1106                 
1107         for(i=0;i<cmap_grid->ngrid;i++)
1108         {
1109             idx = -180.0;
1110             fprintf(fp,"%8s %8s %8s %8s\n","V","dVdx","dVdy","d2dV");
1111                         
1112             fprintf(fp,"grid[%3d]={\n",bShowNumbers?i:-1);
1113                         
1114             for(j=0;j<nelem;j++)
1115             {
1116                 if( (j%cmap_grid->grid_spacing)==0)
1117                 {
1118                     fprintf(fp,"%8.1f\n",idx);
1119                     idx+=dx;
1120                 }
1121                                 
1122                 fprintf(fp,"%8.3f ",cmap_grid->cmapdata[i].cmap[j*4]);
1123                 fprintf(fp,"%8.3f ",cmap_grid->cmapdata[i].cmap[j*4+1]);
1124                 fprintf(fp,"%8.3f ",cmap_grid->cmapdata[i].cmap[j*4+2]);
1125                 fprintf(fp,"%8.3f\n",cmap_grid->cmapdata[i].cmap[j*4+3]);
1126             }
1127             fprintf(fp,"\n");
1128         }
1129     }
1130         
1131 }
1132
1133 void pr_ffparams(FILE *fp,int indent,const char *title,
1134                  gmx_ffparams_t *ffparams,
1135                  gmx_bool bShowNumbers)
1136 {
1137   int i,j;
1138   
1139   indent=pr_title(fp,indent,title);
1140   (void) pr_indent(fp,indent);
1141   (void) fprintf(fp,"atnr=%d\n",ffparams->atnr);
1142   (void) pr_indent(fp,indent);
1143   (void) fprintf(fp,"ntypes=%d\n",ffparams->ntypes);
1144   for (i=0; i<ffparams->ntypes; i++) {
1145       (void) pr_indent(fp,indent+INDENT);
1146       (void) fprintf(fp,"functype[%d]=%s, ",
1147                      bShowNumbers?i:-1,
1148                      interaction_function[ffparams->functype[i]].name);
1149       pr_iparams(fp,ffparams->functype[i],&ffparams->iparams[i]);
1150   }
1151   (void) pr_double(fp,indent,"reppow",ffparams->reppow);
1152   (void) pr_real(fp,indent,"fudgeQQ",ffparams->fudgeQQ);
1153   pr_cmap(fp,indent,"cmap",&ffparams->cmap_grid,bShowNumbers);
1154 }
1155
1156 void pr_idef(FILE *fp,int indent,const char *title,t_idef *idef, gmx_bool bShowNumbers)
1157 {
1158   int i,j;
1159   
1160   if (available(fp,idef,indent,title)) {  
1161     indent=pr_title(fp,indent,title);
1162     (void) pr_indent(fp,indent);
1163     (void) fprintf(fp,"atnr=%d\n",idef->atnr);
1164     (void) pr_indent(fp,indent);
1165     (void) fprintf(fp,"ntypes=%d\n",idef->ntypes);
1166     for (i=0; i<idef->ntypes; i++) {
1167       (void) pr_indent(fp,indent+INDENT);
1168       (void) fprintf(fp,"functype[%d]=%s, ",
1169                      bShowNumbers?i:-1,
1170                      interaction_function[idef->functype[i]].name);
1171       pr_iparams(fp,idef->functype[i],&idef->iparams[i]);
1172     }
1173     (void) pr_real(fp,indent,"fudgeQQ",idef->fudgeQQ);
1174
1175     for(j=0; (j<F_NRE); j++)
1176       pr_ilist(fp,indent,interaction_function[j].longname,
1177                idef->functype,&idef->il[j],bShowNumbers);
1178   }
1179 }
1180
1181 static int pr_block_title(FILE *fp,int indent,const char *title,t_block *block)
1182 {
1183   int i;
1184
1185   if (available(fp,block,indent,title))
1186     {
1187       indent=pr_title(fp,indent,title);
1188       (void) pr_indent(fp,indent);
1189       (void) fprintf(fp,"nr=%d\n",block->nr);
1190     }
1191   return indent;
1192 }
1193
1194 static int pr_blocka_title(FILE *fp,int indent,const char *title,t_blocka *block)
1195 {
1196   int i;
1197
1198   if (available(fp,block,indent,title))
1199     {
1200       indent=pr_title(fp,indent,title);
1201       (void) pr_indent(fp,indent);
1202       (void) fprintf(fp,"nr=%d\n",block->nr);
1203       (void) pr_indent(fp,indent);
1204       (void) fprintf(fp,"nra=%d\n",block->nra);
1205     }
1206   return indent;
1207 }
1208
1209 static void low_pr_blocka(FILE *fp,int indent,const char *title,t_blocka *block, gmx_bool bShowNumbers)
1210 {
1211   int i;
1212   
1213   if (available(fp,block,indent,title))
1214     {
1215       indent=pr_blocka_title(fp,indent,title,block);
1216       for (i=0; i<=block->nr; i++)
1217         {
1218           (void) pr_indent(fp,indent+INDENT);
1219           (void) fprintf(fp,"%s->index[%d]=%u\n",
1220                          title,bShowNumbers?i:-1,block->index[i]);
1221         }
1222       for (i=0; i<block->nra; i++)
1223         {
1224           (void) pr_indent(fp,indent+INDENT);
1225           (void) fprintf(fp,"%s->a[%d]=%u\n",
1226                          title,bShowNumbers?i:-1,block->a[i]);
1227         }
1228     }
1229 }
1230
1231 void pr_block(FILE *fp,int indent,const char *title,t_block *block,gmx_bool bShowNumbers)
1232 {
1233   int i,j,ok,size,start,end;
1234   
1235   if (available(fp,block,indent,title))
1236     {
1237       indent=pr_block_title(fp,indent,title,block);
1238       start=0;
1239       end=start;
1240       if ((ok=(block->index[start]==0))==0)
1241         (void) fprintf(fp,"block->index[%d] should be 0\n",start);
1242       else
1243         for (i=0; i<block->nr; i++)
1244           {
1245             end=block->index[i+1];
1246             size=pr_indent(fp,indent);
1247             if (end<=start)
1248               size+=fprintf(fp,"%s[%d]={}\n",title,i);
1249             else
1250               size+=fprintf(fp,"%s[%d]={%d..%d}\n",
1251                             title,bShowNumbers?i:-1,
1252                             bShowNumbers?start:-1,bShowNumbers?end-1:-1);
1253             start=end;
1254           }
1255     }
1256 }
1257
1258 void pr_blocka(FILE *fp,int indent,const char *title,t_blocka *block,gmx_bool bShowNumbers)
1259 {
1260   int i,j,ok,size,start,end;
1261   
1262   if (available(fp,block,indent,title))
1263     {
1264       indent=pr_blocka_title(fp,indent,title,block);
1265       start=0;
1266       end=start;
1267       if ((ok=(block->index[start]==0))==0)
1268         (void) fprintf(fp,"block->index[%d] should be 0\n",start);
1269       else
1270         for (i=0; i<block->nr; i++)
1271           {
1272             end=block->index[i+1];
1273             size=pr_indent(fp,indent);
1274             if (end<=start)
1275               size+=fprintf(fp,"%s[%d]={",title,i);
1276             else
1277               size+=fprintf(fp,"%s[%d][%d..%d]={",
1278                             title,bShowNumbers?i:-1,
1279                             bShowNumbers?start:-1,bShowNumbers?end-1:-1);
1280             for (j=start; j<end; j++)
1281               {
1282                 if (j>start) size+=fprintf(fp,", ");
1283                 if ((size)>(USE_WIDTH))
1284                   {
1285                     (void) fprintf(fp,"\n");
1286                     size=pr_indent(fp,indent+INDENT);
1287                   }
1288                 size+=fprintf(fp,"%u",block->a[j]);
1289               }
1290             (void) fprintf(fp,"}\n");
1291             start=end;
1292           }
1293       if ((end!=block->nra)||(!ok)) 
1294         {
1295           (void) pr_indent(fp,indent);
1296           (void) fprintf(fp,"tables inconsistent, dumping complete tables:\n");
1297           low_pr_blocka(fp,indent,title,block,bShowNumbers);
1298         }
1299     }
1300 }
1301
1302 static void pr_strings(FILE *fp,int indent,const char *title,char ***nm,int n, gmx_bool bShowNumbers)
1303 {
1304   int i;
1305
1306   if (available(fp,nm,indent,title))
1307     {  
1308       indent=pr_title_n(fp,indent,title,n);
1309       for (i=0; i<n; i++)
1310         {
1311           (void) pr_indent(fp,indent);
1312           (void) fprintf(fp,"%s[%d]={name=\"%s\"}\n",
1313                          title,bShowNumbers?i:-1,*(nm[i]));
1314         }
1315     }
1316 }
1317
1318 static void pr_strings2(FILE *fp,int indent,const char *title,
1319                         char ***nm,char ***nmB,int n, gmx_bool bShowNumbers)
1320 {
1321   int i;
1322
1323   if (available(fp,nm,indent,title))
1324     {  
1325       indent=pr_title_n(fp,indent,title,n);
1326       for (i=0; i<n; i++)
1327         {
1328           (void) pr_indent(fp,indent);
1329           (void) fprintf(fp,"%s[%d]={name=\"%s\",nameB=\"%s\"}\n",
1330                          title,bShowNumbers?i:-1,*(nm[i]),*(nmB[i]));
1331         }
1332     }
1333 }
1334
1335 static void pr_resinfo(FILE *fp,int indent,const char *title,t_resinfo *resinfo,int n, gmx_bool bShowNumbers)
1336 {
1337     int i;
1338     
1339     if (available(fp,resinfo,indent,title))
1340     {  
1341         indent=pr_title_n(fp,indent,title,n);
1342         for (i=0; i<n; i++)
1343         {
1344             (void) pr_indent(fp,indent);
1345             (void) fprintf(fp,"%s[%d]={name=\"%s\", nr=%d, ic='%c'}\n",
1346                            title,bShowNumbers?i:-1,
1347                            *(resinfo[i].name),resinfo[i].nr,
1348                            (resinfo[i].ic == '\0') ? ' ' : resinfo[i].ic);
1349         }
1350     }
1351 }
1352
1353 static void pr_atom(FILE *fp,int indent,const char *title,t_atom *atom,int n)
1354 {
1355   int i,j;
1356   
1357   if (available(fp,atom,indent,title)) {  
1358     indent=pr_title_n(fp,indent,title,n);
1359     for (i=0; i<n; i++) {
1360       (void) pr_indent(fp,indent);
1361       fprintf(fp,"%s[%6d]={type=%3d, typeB=%3d, ptype=%8s, m=%12.5e, "
1362               "q=%12.5e, mB=%12.5e, qB=%12.5e, resind=%5d, atomnumber=%3d}\n",
1363               title,i,atom[i].type,atom[i].typeB,ptype_str[atom[i].ptype],
1364               atom[i].m,atom[i].q,atom[i].mB,atom[i].qB,
1365               atom[i].resind,atom[i].atomnumber);
1366     }
1367   }
1368 }
1369
1370 static void pr_grps(FILE *fp,int indent,const char *title,t_grps grps[],
1371                     char **grpname[], gmx_bool bShowNumbers)
1372 {
1373     int i,j;
1374
1375     for(i=0; (i<egcNR); i++)
1376     {
1377         fprintf(fp,"%s[%-12s] nr=%d, name=[",title,gtypes[i],grps[i].nr);
1378         for(j=0; (j<grps[i].nr); j++)
1379         {
1380             fprintf(fp," %s",*(grpname[grps[i].nm_ind[j]]));
1381         }
1382         fprintf(fp,"]\n");
1383     }
1384 }
1385
1386 static void pr_groups(FILE *fp,int indent,const char *title,
1387                       gmx_groups_t *groups,
1388                       gmx_bool bShowNumbers)
1389 {
1390     int grpnr[egcNR];
1391     int nat_max,i,g;
1392
1393     pr_grps(fp,indent,"grp",groups->grps,groups->grpname,bShowNumbers);
1394     pr_strings(fp,indent,"grpname",groups->grpname,groups->ngrpname,bShowNumbers);
1395
1396     (void) pr_indent(fp,indent);
1397     fprintf(fp,"groups          ");
1398     for(g=0; g<egcNR; g++)
1399     {
1400        printf(" %5.5s",gtypes[g]);
1401     }
1402     printf("\n");
1403
1404     (void) pr_indent(fp,indent);
1405     fprintf(fp,"allocated       ");
1406     nat_max = 0;
1407     for(g=0; g<egcNR; g++)
1408     {
1409         printf(" %5d",groups->ngrpnr[g]);
1410         nat_max = max(nat_max,groups->ngrpnr[g]);
1411     }
1412     printf("\n");
1413
1414     if (nat_max == 0)
1415     {
1416         (void) pr_indent(fp,indent);
1417         fprintf(fp,"groupnr[%5s] =","*");
1418         for(g=0; g<egcNR; g++)
1419         {
1420             fprintf(fp,"  %3d ",0);
1421         }
1422         fprintf(fp,"\n");
1423     }
1424     else
1425     {
1426         for(i=0; i<nat_max; i++)
1427         {
1428             (void) pr_indent(fp,indent);
1429             fprintf(fp,"groupnr[%5d] =",i);
1430             for(g=0; g<egcNR; g++)
1431             {
1432                 fprintf(fp,"  %3d ",
1433                         groups->grpnr[g] ? groups->grpnr[g][i] : 0);
1434             }
1435             fprintf(fp,"\n");
1436         }
1437     }
1438 }
1439
1440 void pr_atoms(FILE *fp,int indent,const char *title,t_atoms *atoms, 
1441               gmx_bool bShownumbers)
1442 {
1443   if (available(fp,atoms,indent,title))
1444     {
1445       indent=pr_title(fp,indent,title);
1446       pr_atom(fp,indent,"atom",atoms->atom,atoms->nr);
1447       pr_strings(fp,indent,"atom",atoms->atomname,atoms->nr,bShownumbers);
1448       pr_strings2(fp,indent,"type",atoms->atomtype,atoms->atomtypeB,atoms->nr,bShownumbers);
1449       pr_resinfo(fp,indent,"residue",atoms->resinfo,atoms->nres,bShownumbers);
1450     }
1451 }
1452
1453
1454 void pr_atomtypes(FILE *fp,int indent,const char *title,t_atomtypes *atomtypes, 
1455                   gmx_bool bShowNumbers)
1456 {
1457   int i;
1458   if (available(fp,atomtypes,indent,title)) 
1459   {
1460     indent=pr_title(fp,indent,title);
1461     for(i=0;i<atomtypes->nr;i++) {
1462       pr_indent(fp,indent);
1463                 fprintf(fp,
1464                                 "atomtype[%3d]={radius=%12.5e, volume=%12.5e, gb_radius=%12.5e, surftens=%12.5e, atomnumber=%4d, S_hct=%12.5e)}\n",
1465                                 bShowNumbers?i:-1,atomtypes->radius[i],atomtypes->vol[i],
1466                                 atomtypes->gb_radius[i],
1467                                 atomtypes->surftens[i],atomtypes->atomnumber[i],atomtypes->S_hct[i]);
1468     }
1469   }
1470 }
1471
1472 static void pr_moltype(FILE *fp,int indent,const char *title,
1473                        gmx_moltype_t *molt,int n,
1474                        gmx_ffparams_t *ffparams,
1475                        gmx_bool bShowNumbers)
1476 {
1477     int j;
1478
1479     indent = pr_title_n(fp,indent,title,n);
1480     (void) pr_indent(fp,indent);
1481     (void) fprintf(fp,"name=\"%s\"\n",*(molt->name));
1482     pr_atoms(fp,indent,"atoms",&(molt->atoms),bShowNumbers);
1483     pr_block(fp,indent,"cgs",&molt->cgs, bShowNumbers);
1484     pr_blocka(fp,indent,"excls",&molt->excls, bShowNumbers);
1485     for(j=0; (j<F_NRE); j++) {
1486         pr_ilist(fp,indent,interaction_function[j].longname,
1487                  ffparams->functype,&molt->ilist[j],bShowNumbers);
1488     }
1489 }
1490
1491 static void pr_molblock(FILE *fp,int indent,const char *title,
1492                         gmx_molblock_t *molb,int n,
1493                         gmx_moltype_t *molt,
1494                         gmx_bool bShowNumbers)
1495 {
1496     indent = pr_title_n(fp,indent,title,n);
1497     (void) pr_indent(fp,indent);
1498     (void) fprintf(fp,"%-20s = %d \"%s\"\n",
1499                    "moltype",molb->type,*(molt[molb->type].name));
1500     pr_int(fp,indent,"#molecules",molb->nmol);
1501     pr_int(fp,indent,"#atoms_mol",molb->natoms_mol);
1502     pr_int(fp,indent,"#posres_xA",molb->nposres_xA);
1503     if (molb->nposres_xA > 0) {
1504         pr_rvecs(fp,indent,"posres_xA",molb->posres_xA,molb->nposres_xA);
1505     }
1506     pr_int(fp,indent,"#posres_xB",molb->nposres_xB);
1507     if (molb->nposres_xB > 0) {
1508         pr_rvecs(fp,indent,"posres_xB",molb->posres_xB,molb->nposres_xB);
1509     }
1510 }
1511
1512 void pr_mtop(FILE *fp,int indent,const char *title,gmx_mtop_t *mtop,
1513              gmx_bool bShowNumbers)
1514 {
1515     int mt,mb;
1516
1517     if (available(fp,mtop,indent,title)) {
1518         indent=pr_title(fp,indent,title);
1519         (void) pr_indent(fp,indent);
1520         (void) fprintf(fp,"name=\"%s\"\n",*(mtop->name));
1521         pr_int(fp,indent,"#atoms",mtop->natoms);
1522         pr_int(fp,indent,"#molblock",mtop->nmolblock);
1523         for(mb=0; mb<mtop->nmolblock; mb++) {
1524             pr_molblock(fp,indent,"molblock",&mtop->molblock[mb],mb,
1525                         mtop->moltype,bShowNumbers);
1526         }
1527         pr_ffparams(fp,indent,"ffparams",&(mtop->ffparams),bShowNumbers);
1528         pr_atomtypes(fp,indent,"atomtypes",&(mtop->atomtypes),bShowNumbers);
1529         for(mt=0; mt<mtop->nmoltype; mt++) {
1530             pr_moltype(fp,indent,"moltype",&mtop->moltype[mt],mt,
1531                        &mtop->ffparams,bShowNumbers);
1532         }
1533         pr_groups(fp,indent,"groups",&mtop->groups,bShowNumbers);
1534     }
1535 }
1536
1537 void pr_top(FILE *fp,int indent,const char *title,t_topology *top, gmx_bool bShowNumbers)
1538 {
1539   if (available(fp,top,indent,title)) {
1540     indent=pr_title(fp,indent,title);
1541     (void) pr_indent(fp,indent);
1542     (void) fprintf(fp,"name=\"%s\"\n",*(top->name));
1543     pr_atoms(fp,indent,"atoms",&(top->atoms),bShowNumbers);
1544     pr_atomtypes(fp,indent,"atomtypes",&(top->atomtypes),bShowNumbers);
1545     pr_block(fp,indent,"cgs",&top->cgs, bShowNumbers);
1546     pr_block(fp,indent,"mols",&top->mols, bShowNumbers);
1547     pr_blocka(fp,indent,"excls",&top->excls, bShowNumbers);
1548     pr_idef(fp,indent,"idef",&top->idef,bShowNumbers);
1549   }
1550 }
1551
1552 void pr_header(FILE *fp,int indent,const char *title,t_tpxheader *sh)
1553 {
1554   char buf[22];
1555     
1556   if (available(fp,sh,indent,title))
1557     {
1558       indent=pr_title(fp,indent,title);
1559       pr_indent(fp,indent);
1560       fprintf(fp,"bIr    = %spresent\n",sh->bIr?"":"not ");
1561       pr_indent(fp,indent);
1562       fprintf(fp,"bBox   = %spresent\n",sh->bBox?"":"not ");
1563       pr_indent(fp,indent);
1564       fprintf(fp,"bTop   = %spresent\n",sh->bTop?"":"not ");
1565       pr_indent(fp,indent);
1566       fprintf(fp,"bX     = %spresent\n",sh->bX?"":"not ");
1567       pr_indent(fp,indent);
1568       fprintf(fp,"bV     = %spresent\n",sh->bV?"":"not ");
1569       pr_indent(fp,indent);
1570       fprintf(fp,"bF     = %spresent\n",sh->bF?"":"not ");
1571       
1572       pr_indent(fp,indent);
1573       fprintf(fp,"natoms = %d\n",sh->natoms);
1574       pr_indent(fp,indent);
1575       fprintf(fp,"lambda = %e\n",sh->lambda);
1576     }
1577 }
1578
1579 void pr_commrec(FILE *fp,int indent,t_commrec *cr)
1580 {
1581   pr_indent(fp,indent);
1582   fprintf(fp,"commrec:\n");
1583   indent+=2;
1584   pr_indent(fp,indent);
1585   fprintf(fp,"nodeid    = %d\n",cr->nodeid);
1586   pr_indent(fp,indent);
1587   fprintf(fp,"nnodes    = %d\n",cr->nnodes);
1588   pr_indent(fp,indent);
1589   fprintf(fp,"npmenodes = %d\n",cr->npmenodes);
1590   /*
1591   pr_indent(fp,indent);
1592   fprintf(fp,"threadid  = %d\n",cr->threadid);
1593   pr_indent(fp,indent);
1594   fprintf(fp,"nthreads  = %d\n",cr->nthreads);
1595   */
1596 }