Merge release-4-6 into master
[alexxy/gromacs.git] / src / contrib / anaf.c
1 /*
2  * 
3  *                This source code is part of
4  * 
5  *                 G   R   O   M   A   C   S
6  * 
7  *          GROningen MAchine for Chemical Simulations
8  * 
9  *                        VERSION 3.3.99_development_20071104
10  * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12  * Copyright (c) 2001-2006, The GROMACS development team,
13  * check out http://www.gromacs.org for more information.
14
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  * 
20  * If you want to redistribute modifications, please consider that
21  * scientific software is very special. Version control is crucial -
22  * bugs must be traceable. We will be happy to consider code for
23  * inclusion in the official distribution, but derived work must not
24  * be called official GROMACS. Details are found in the README & COPYING
25  * files - if they are missing, get the official version at www.gromacs.org.
26  * 
27  * To help us fund GROMACS development, we humbly ask that you cite
28  * the papers on the package - you can find them in the top README file.
29  * 
30  * For more info, check our website at http://www.gromacs.org
31  * 
32  * And Hey:
33  * Groningen Machine for Chemical Simulation
34  */
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
38
39 #include <stdio.h>
40 #include <string.h>
41 #include <math.h>
42 #include "main.h"
43 #include "macros.h"
44 #include "futil.h"
45 #include "statutil.h"
46 #include "copyrite.h"
47 #include "sysstuff.h"
48 #include "txtdump.h"
49 #include "gmx_fatal.h"
50 #include "xtcio.h"
51 #include "enxio.h"
52 #include "smalloc.h"
53 #include "gmxfio.h"
54 #include "tpxio.h"
55 #include "trnio.h"
56 #include "txtdump.h"
57 #include "vec.h"
58
59 static char *nm[5]  = { "OW", "HW1", "HW2", "DW", "SW" };
60   
61 static void list_trn(char *fn)
62 {
63   static real mass[5] = { 15.9994, 1.008, 1.008, 0.0, 0.0 };
64   int         i,j=0,m,fpread,fpwrite,nframe;
65   rvec        *x,*v,*f,fmol[2],xcm[2],torque[j],dx;
66   real        mmm,len;
67   matrix      box;
68   t_trnheader trn;
69   gmx_bool        bOK;
70
71   printf("Going to open %s\n",fn);
72   fpread  = open_trn(fn,"r"); 
73   fpwrite = open_tpx(NULL,"w");
74   gmx_fio_setdebug(fpwrite,TRUE);
75   
76   mmm=mass[0]+2*mass[1];
77   for(i=0; (i<5); i++) 
78     mass[i] /= mmm;
79   
80   nframe = 0;
81   while (fread_trnheader(fpread,&trn,&bOK)) {
82     snew(x,trn.natoms);
83     snew(v,trn.natoms);
84     snew(f,trn.natoms);
85     if (fread_htrn(fpread,&trn,
86                    trn.box_size ? box : NULL,
87                    trn.x_size   ? x : NULL,
88                    trn.v_size   ? v : NULL,
89                    trn.f_size   ? f : NULL)) {
90                    
91       if (trn.x_size && trn.f_size) {
92         printf("There are %d atoms\n",trn.natoms);
93         for(j=0; (j<2); j++) {
94           clear_rvec(xcm[j]);
95           clear_rvec(fmol[j]);
96           clear_rvec(torque[j]);
97           for(i=5*j; (i<5*j+5); i++) {
98             rvec_inc(fmol[j],f[i]);
99             for(m=0; (m<DIM); m++)
100               xcm[j][m] += mass[i%5]*x[i][m];
101           }
102           for(i=5*j; (i<5*j+5); i++) {
103             rvec_dec(x[i],xcm[j]);
104             cprod(x[i],f[i],dx);
105             rvec_inc(torque[j],dx);
106             rvec_inc(x[i],xcm[j]);
107           }
108         }
109         pr_rvecs(stdout,0,"FMOL  ",fmol,2);
110         pr_rvecs(stdout,0,"TORQUE",torque,2);
111         printf("Distance matrix Water1-Water2\n%5s","");
112         for(j=0; (j<5); j++) 
113           printf("  %10s",nm[j]);
114         printf("\n");
115         for(j=0; (j<5); j++) {
116           printf("%5s",nm[j]);
117           for(i=5; (i<10); i++) {
118             rvec_sub(x[i],x[j],dx);
119             len = sqrt(iprod(dx,dx));
120             printf("  %10.7f",len);
121           }
122           printf("\n");
123         }
124       }
125     }
126     sfree(x);
127     sfree(v);
128     sfree(f);
129     nframe++;
130   }
131   if (!bOK)
132     fprintf(stderr,"\nWARNING: Incomplete frame header: nr %d, t=%g\n",
133             nframe,trn.t);
134   close_tpx(fpwrite);
135   close_trn(fpread);
136 }
137
138 int main(int argc,char *argv[])
139 {
140   static char *desc[] = {
141     "[TT]gmxdump[tt] reads a run input file ([TT].tpa[tt]/[TT].tpr[tt]/[TT].tpb[tt]),",
142     "a trajectory ([TT].trj[tt]/[TT].trr[tt]/[TT].xtc[tt]) or an energy",
143     "file ([TT].ene[tt]/[TT].edr[tt]) and prints that to standard",
144     "output in a readable format. This program is essential for",
145     "checking your run input file in case of problems.[PAR]"
146   };
147   t_filenm fnm[] = {
148     { efTRN, "-f", NULL, ffOPTRD }
149   };
150 #define NFILE asize(fnm)
151   char *fn;
152   
153   /* Command line options */
154   
155   CopyRight(stdout,argv[0]);
156   parse_common_args(&argc,argv,0,NFILE,fnm,0,NULL,
157                     asize(desc),desc,0,NULL);
158   
159   if (ftp2bSet(efTRN,NFILE,fnm)) {
160     fn = ftp2fn(efTRN,NFILE,fnm);
161     printf("Going to open %s\n",fn);
162     list_trn(fn);
163   }
164   
165   thanx(stderr);
166
167   return 0;
168 }