Upped the version to 3.2.0
[alexxy/gromacs.git] / src / contrib / anaf.c
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.
15
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.
20  * 
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.
27  * 
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.
30  * 
31  * For more info, check our website at http://www.gromacs.org
32  * 
33  * And Hey:
34  * Giving Russians Opium May Alter Current Situation
35  */
36 #include <stdio.h>
37 #include <string.h>
38 #include <math.h>
39 #include "main.h"
40 #include "macros.h"
41 #include "futil.h"
42 #include "statutil.h"
43 #include "copyrite.h"
44 #include "sysstuff.h"
45 #include "txtdump.h"
46 #include "fatal.h"
47 #include "xtcio.h"
48 #include "enxio.h"
49 #include "assert.h"
50 #include "smalloc.h"
51 #include "gmxfio.h"
52 #include "tpxio.h"
53 #include "trnio.h"
54 #include "txtdump.h"
55 #include "vec.h"
56
57 static char *nm[5]  = { "OW", "HW1", "HW2", "DW", "SW" };
58   
59 static void list_trn(char *fn)
60 {
61   static real mass[5] = { 15.9994, 1.008, 1.008, 0.0, 0.0 };
62   int         i,j=0,m,fpread,fpwrite,nframe;
63   rvec        *x,*v,*f,fmol[2],xcm[2],torque[j],dx;
64   real        mmm,len;
65   matrix      box;
66   t_trnheader trn;
67   bool        bOK;
68
69   printf("Going to open %s\n",fn);
70   fpread  = open_trn(fn,"r"); 
71   fpwrite = open_tpx(NULL,"w");
72   fio_setdebug(fpwrite,TRUE);
73   
74   mmm=mass[0]+2*mass[1];
75   for(i=0; (i<5); i++) 
76     mass[i] /= mmm;
77   
78   nframe = 0;
79   while (fread_trnheader(fpread,&trn,&bOK)) {
80     snew(x,trn.natoms);
81     snew(v,trn.natoms);
82     snew(f,trn.natoms);
83     if (fread_htrn(fpread,&trn,
84                    trn.box_size ? box : NULL,
85                    trn.x_size   ? x : NULL,
86                    trn.v_size   ? v : NULL,
87                    trn.f_size   ? f : NULL)) {
88                    
89       if (trn.x_size && trn.f_size) {
90         printf("There are %d atoms\n",trn.natoms);
91         for(j=0; (j<2); j++) {
92           clear_rvec(xcm[j]);
93           clear_rvec(fmol[j]);
94           clear_rvec(torque[j]);
95           for(i=5*j; (i<5*j+5); i++) {
96             rvec_inc(fmol[j],f[i]);
97             for(m=0; (m<DIM); m++)
98               xcm[j][m] += mass[i%5]*x[i][m];
99           }
100           for(i=5*j; (i<5*j+5); i++) {
101             rvec_dec(x[i],xcm[j]);
102             oprod(x[i],f[i],dx);
103             rvec_inc(torque[j],dx);
104             rvec_inc(x[i],xcm[j]);
105           }
106         }
107         pr_rvecs(stdout,0,"FMOL  ",fmol,2);
108         pr_rvecs(stdout,0,"TORQUE",torque,2);
109         printf("Distance matrix Water1-Water2\n%5s","");
110         for(j=0; (j<5); j++) 
111           printf("  %10s",nm[j]);
112         printf("\n");
113         for(j=0; (j<5); j++) {
114           printf("%5s",nm[j]);
115           for(i=5; (i<10); i++) {
116             rvec_sub(x[i],x[j],dx);
117             len = sqrt(iprod(dx,dx));
118             printf("  %10.7f",len);
119           }
120           printf("\n");
121         }
122       }
123     }
124     sfree(x);
125     sfree(v);
126     sfree(f);
127     nframe++;
128   }
129   if (!bOK)
130     fprintf(stderr,"\nWARNING: Incomplete frame header: nr %d, t=%g\n",
131             nframe,trn.t);
132   close_tpx(fpwrite);
133   close_trn(fpread);
134 }
135
136 int main(int argc,char *argv[])
137 {
138   static char *desc[] = {
139     "gmxdump reads a run input file ([TT].tpa[tt]/[TT].tpr[tt]/[TT].tpb[tt]),",
140     "a trajectory ([TT].trj[tt]/[TT].trr[tt]/[TT].xtc[tt]) or an energy",
141     "file ([TT].ene[tt]/[TT].edr[tt]) and prints that to standard",
142     "output in a readable format. This program is essential for",
143     "checking your run input file in case of problems.[PAR]"
144   };
145   t_filenm fnm[] = {
146     { efTRN, "-f", NULL, ffOPTRD }
147   };
148 #define NFILE asize(fnm)
149   char *fn;
150   
151   /* Command line options */
152   
153   CopyRight(stdout,argv[0]);
154   parse_common_args(&argc,argv,0,NFILE,fnm,0,NULL,
155                     asize(desc),desc,0,NULL);
156   
157   if (ftp2bSet(efTRN,NFILE,fnm)) {
158     fn = ftp2fn(efTRN,NFILE,fnm);
159     printf("Going to open %s\n",fn);
160     list_trn(fn);
161   }
162   
163   thanx(stderr);
164
165   return 0;
166 }