Tagged files with gromacs 3.0 header and added some license info
[alexxy/gromacs.git] / share / template / template.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.0
11  * 
12  * Copyright (c) 1991-2001
13  * BIOSON Research Institute, Dept. of Biophysical Chemistry
14  * University of Groningen, The Netherlands
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  * Do check out http://www.gromacs.org , or mail us at gromacs@gromacs.org .
32  * 
33  * And Hey:
34  * Gyas ROwers Mature At Cryogenic Speed
35  */
36 static char *SRCID_template_c = "$Id$";
37 #include "statutil.h"
38 #include "typedefs.h"
39 #include "smalloc.h"
40 #include "vec.h"
41 #include "copyrite.h"
42 #include "statutil.h"
43 #include "tpxio.h"
44
45
46 int main(int argc,char *argv[])
47 {
48   static char *desc[] = {
49     "this is a small test program meant to serve as a template ",
50     "when writing your own analysis tools. The advantage of ",
51     "using gromacs for this is that you have access to all ",
52     "information in the topology, and your program will be ",
53     "able to handle all types of coordinates and trajectory ",
54     "files supported by gromacs. Go ahead and try it! ",
55     "This test version just writes the coordinates of an ",
56     "arbitrary atom to standard out for each frame. You can ",
57     "select which atom you want to examine with the -n argument."
58   };
59   
60   static int n=1;
61
62   /* Extra arguments - but note how you always get the begin/end
63    * options when running the program, without mentioning them here!
64    */
65   
66   t_pargs pa[] = {
67     { "-n", FALSE, etINT, {&n},
68       "Plot data for atom number n (starting on 1)"
69     }
70   };
71   
72   t_topology top;
73   char       title[STRLEN];
74   t_trxframe fr;
75   rvec       *xtop;
76   matrix     box;
77   int        status,flags;
78  
79   t_filenm fnm[] = {
80     { efTPS,  NULL,  NULL, ffREAD },   /* this is for the topology */
81     { efTRX, "-f", NULL, ffREAD }      /* and this for the trajectory */
82   };
83   
84 #define NFILE asize(fnm)
85
86   CopyRight(stderr,argv[0]);
87
88   /* This is the routine responsible for adding default options,
89    * calling the X/motif interface, etc. */
90   parse_common_args(&argc,argv,PCA_CAN_TIME | PCA_CAN_VIEW,TRUE,
91                     NFILE,fnm,asize(pa),pa,asize(desc),desc,0,NULL);
92
93   /* We don't need any topology information to write the coordinates,
94    * but to show how it works we start by writing the name and
95    * charge of the selected atom. It returns a boolean telling us
96    * whether the topology was found and could be read
97    */
98   
99   read_tps_conf(ftp2fn(efTPS,NFILE,fnm),title,&top,&xtop,NULL,box,TRUE);
100   sfree(xtop);
101
102   n=n-1; /* Our enumeration started on 1, but C starts from 0 */
103   /* check that this atom exists */
104   if(n<0 || n>(top.atoms.nr)) 
105   {
106     printf("Error: Atom number %d is out of range.\n",n);
107     exit(1);
108   }
109   
110   printf("Atom name: %s\n",*(top.atoms.atomname[n]));
111   printf("Atom charge: %f\n",top.atoms.atom[n].q);
112   
113   /* The first time we read data is a little special */
114   read_first_frame(&status,ftp2fn(efTRX,NFILE,fnm),&fr,flags);
115   
116   /* This is the main loop over frames */
117   do {
118     /* coordinates are available in the vector fr.x
119      * you can find this and all other structures in
120      * the types directory under the gromacs include dir.
121      */
122     printf("Coordinates at t=%8.3f : %8.5f %8.5f %8.5f\n",fr.time,fr.x[n][XX],fr.x[n][YY],fr.x[n][ZZ]);
123   } while(read_next_frame(status,&fr));
124
125   thanx(stderr);
126   
127   return 0;
128 }
129