9f0997c879c51bf8261a3d0092ee79a65d59a042
[alexxy/gromacs.git] / src / tools / gmx_rama.c
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.2.0
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-2004, The GROMACS development team,
13  * check out http://www.gromacs.org for more information.
14
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.
19  * 
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.
26  * 
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.
29  * 
30  * For more info, check our website at http://www.gromacs.org
31  * 
32  * And Hey:
33  * Green Red Orange Magenta Azure Cyan Skyblue
34  */
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
38
39 #include <math.h>
40 #include "sysstuff.h"
41 #include <string.h>
42 #include "typedefs.h"
43 #include "smalloc.h"
44 #include "macros.h"
45 #include "vec.h"
46 #include "xvgr.h"
47 #include "physics.h"
48 #include "pbc.h"
49 #include "copyrite.h"
50 #include "futil.h"
51 #include "statutil.h"
52 #include "index.h"
53 #include "nrama.h"
54 #include "gmx_ana.h"
55
56
57 static void plot_rama(FILE *out,t_xrama *xr)
58 {
59   int i;
60   real phi,psi;
61   
62   for(i=0; (i<xr->npp); i++) {
63     phi=xr->dih[xr->pp[i].iphi].ang*RAD2DEG;
64     psi=xr->dih[xr->pp[i].ipsi].ang*RAD2DEG;
65     fprintf(out,"%g  %g  %s\n",phi,psi,xr->pp[i].label);
66   }
67 }
68
69 int gmx_rama(int argc,char *argv[])
70 {
71   const char *desc[] = {
72     "[TT]g_rama[tt] selects the [GRK]phi[grk]/[GRK]psi[grk] dihedral combinations from your topology file",
73     "and computes these as a function of time.",
74     "Using simple Unix tools such as [IT]grep[it] you can select out", 
75     "specific residues."
76   };
77
78   FILE      *out;
79   t_xrama   *xr;
80   int       j;
81   output_env_t oenv;
82   t_filenm  fnm[] = {
83     { efTRX, "-f", NULL,  ffREAD },
84     { efTPX, NULL, NULL,  ffREAD },
85     { efXVG, NULL, "rama",ffWRITE }
86   };
87 #define NFILE asize(fnm)
88
89   CopyRight(stderr,argv[0]);
90   parse_common_args(&argc,argv,PCA_CAN_VIEW | PCA_CAN_TIME | PCA_BE_NICE,
91                     NFILE,fnm,0,NULL,asize(desc),desc,0,NULL,&oenv);
92
93                       
94   snew(xr,1);
95   init_rama(oenv,ftp2fn(efTRX,NFILE,fnm),ftp2fn(efTPX,NFILE,fnm),xr,3);
96   
97   out=xvgropen(ftp2fn(efXVG,NFILE,fnm),"Ramachandran Plot","Phi","Psi",oenv);
98   xvgr_line_props(out,0,elNone,ecFrank,oenv);
99   xvgr_view(out,0.2,0.2,0.8,0.8,oenv);
100   xvgr_world(out,-180,-180,180,180,oenv);
101   fprintf(out,"@    xaxis  tick on\n@    xaxis  tick major 60\n@    xaxis  tick minor 30\n");
102   fprintf(out,"@    yaxis  tick on\n@    yaxis  tick major 60\n@    yaxis  tick minor 30\n");
103   fprintf(out,"@ s0 symbol 2\n@ s0 symbol size 0.4\n@ s0 symbol fill 1\n");
104   
105   j=0;
106   do {
107     plot_rama(out,xr);
108     j++;
109   } while (new_data(xr));
110   fprintf(stderr,"\n");
111   ffclose(out);
112   
113   do_view(oenv,ftp2fn(efXVG,NFILE,fnm),NULL);
114   
115   thanx(stderr);
116   
117   return 0;
118 }