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