Merge branch 'release-4-6' into master
[alexxy/gromacs.git] / src / gromacs / gmxana / 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     {
64         phi = xr->dih[xr->pp[i].iphi].ang*RAD2DEG;
65         psi = xr->dih[xr->pp[i].ipsi].ang*RAD2DEG;
66         fprintf(out, "%g  %g  %s\n", phi, psi, xr->pp[i].label);
67     }
68 }
69
70 int gmx_rama(int argc, char *argv[])
71 {
72     const char  *desc[] = {
73         "[TT]g_rama[tt] selects the [GRK]phi[grk]/[GRK]psi[grk] dihedral combinations from your topology file",
74         "and computes these as a function of time.",
75         "Using simple Unix tools such as [IT]grep[it] you can select out",
76         "specific residues."
77     };
78
79     FILE        *out;
80     t_xrama     *xr;
81     int          j;
82     output_env_t oenv;
83     t_filenm     fnm[] = {
84         { efTRX, "-f", NULL,  ffREAD },
85         { efTPX, NULL, NULL,  ffREAD },
86         { efXVG, NULL, "rama", ffWRITE }
87     };
88 #define NFILE asize(fnm)
89
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     {
108         plot_rama(out, xr);
109         j++;
110     }
111     while (new_data(xr));
112     fprintf(stderr, "\n");
113     ffclose(out);
114
115     do_view(oenv, ftp2fn(efXVG, NFILE, fnm), NULL);
116
117     thanx(stderr);
118
119     return 0;
120 }