Fixing copyright issues and code contributors
[alexxy/gromacs.git] / src / contrib / compnl.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,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 "ns.h"
43 #include "smalloc.h"
44 #include "wnblist.h"
45 #include "futil.h"
46 #include "macros.h"
47 #include "statutil.h"
48 #include "copyrite.h"
49 #include "confio.h"
50 #include "pbc.h"
51 #include "vec.h"
52
53 int main(int argc,char *argv[])
54 {
55   static char *desc[] = {
56     "[TT]compnl[tt] compares two neighborlists as generated by [TT]mdrun[tt]",
57     "in the log file, when the environment variable DUMPNL is set to",
58     "a number larger than 0. [TT]compnl[tt] is mainly used for debugging the",
59     "[TT]mdrun[tt] internals and not for end-users."
60   };
61   FILE    *in,*out;
62   int     i,j,nmiss,mod;
63   char    **fn,title[256];
64   int     ***mat,nnb;
65   real    mb;
66   gmx_bool    bConf;
67   rvec    *x = NULL;
68   rvec    dx;
69   matrix  box;
70   t_atoms atoms;
71   t_pbc   pbc;
72   
73   t_filenm fnm[] = {
74     { efLOG, "-f1", NULL, ffREAD },
75     { efLOG, "-f2", NULL, ffREAD },
76     { efOUT, "-o",  "compnl", ffWRITE },
77     { efSTX, "-c",  NULL, ffOPTRD }
78   };
79 #define NFILE asize(fnm)
80   static int natoms=648;
81   static gmx_bool bSymm=TRUE;
82   static t_pargs pa[] = {
83     { "-nat",  FALSE, etINT, { &natoms }, "Number of atoms" },
84     { "-symm", FALSE, etBOOL,{ &bSymm  }, "Symmetrize the matrices" },
85   };
86
87   CopyRight(stderr,argv[0]);
88   parse_common_args(&argc,argv,0,NFILE,fnm,asize(pa),pa,
89                     asize(desc),desc,0,NULL);
90
91   bConf = (opt2bSet("-c",NFILE,fnm));
92   if (bConf) {
93     get_stx_coordnum (opt2fn("-c",NFILE,fnm),&natoms);
94     init_t_atoms(&atoms,natoms,FALSE);
95     snew(x,natoms);
96     read_stx_conf(opt2fn("-c",NFILE,fnm),title,&atoms,x,NULL,box);
97     set_pbc(&pbc,box);
98   }
99   snew(fn,2);
100   fn[0] = opt2fn("-f1",NFILE,fnm);
101   fn[1] = opt2fn("-f2",NFILE,fnm);
102   
103   snew(mat,2);  
104   out = gmx_fio_fopen(ftp2fn(efOUT,NFILE,fnm),"w");
105   mb  = sizeof(int)*sqr(natoms/1024.0);
106   for(i=0; (i<2); i++) {
107     in = gmx_fio_fopen(fn[i],"r");
108     fprintf(stderr,"Reading %s\n",fn[i]);
109     fprintf(out,   "Reading %s\n",fn[i]);
110     fprintf(stderr,"Going to allocate %.0f Mb of memory\n",mb);
111     fprintf(out,   "Going to allocate %.0f Mb of memory\n",mb);
112     snew(mat[i],natoms);
113     for(j=0; (j<natoms); j++) 
114       snew(mat[i][j],natoms);
115     nnb = read_nblist(in,out,mat[i],natoms,bSymm);
116     gmx_fio_fclose(in);
117     fprintf(stderr,"Interaction matrix %d has %d entries\n",i,nnb);
118     fprintf(out,   "Interaction matrix %d has %d entries\n",i,nnb);
119   }
120   fprintf(stderr,"Comparing Interaction Matrices\n");
121   mod=1;
122   nmiss = 0;
123   for(i=0; (i<natoms); i+=mod) {
124     for(j=0; (j<natoms); j+=mod) {
125       if (mat[0][i][j] != mat[1][i][j]) {
126         fprintf(out,"i: %5d, j: %5d, shift[%s]: %3d, shift[%s]: %3d",
127                 i,j,fn[0],mat[0][i][j]-1,fn[1],mat[1][i][j]-1);
128         if (bConf) {
129           pbc_dx(&pbc,x[i],x[j],dx);
130           fprintf(out," dist: %8.3f\n",norm(dx));
131         }
132         else
133           fprintf(out,"\n");
134         nmiss++;
135       }
136     }
137   }
138   fprintf(out,"There were %d mismatches\n",nmiss);
139   fprintf(out,"Done.\n");
140   gmx_fio_fclose(out);
141   fprintf(stderr,"There were %d mismatches\n",nmiss);
142   fprintf(stderr,"Finished\n");
143   
144   thanx(stdout);
145   
146   return 0;
147 }
148
149
150