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