2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013,2014, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
45 #include "gromacs/utility/smalloc.h"
47 #include "gromacs/math/vec.h"
49 #include "gromacs/utility/fatalerror.h"
52 #include "gromacs/commandline/pargs.h"
53 #include "gromacs/utility/futil.h"
54 #include "gromacs/fileio/strdb.h"
55 #include "gromacs/fileio/writeps.h"
57 static gmx_bool *bPhobics(int nres, char *resnm[])
63 nb = get_strings("phbres.dat", &cb);
66 for (i = 0; (i < nres); i++)
68 if (search_str(nb, cb, resnm[i]) != -1)
76 void wheel(const char *fn, int nres, char *resnm[], int r0, real rot0, char *title)
78 const real fontsize = 16;
79 const real gray = 0.9;
80 const real fontasp = 0.6;
81 const real fontwidth = fontsize*fontasp;
85 real ring, inner, outer;
94 for (i = 0; (i < nres); i++)
97 sl = strlen(resnm[i]);
98 sign = resnm[i][sl-1];
99 if ((sign == '+') || (sign == '-'))
101 resnm[i][sl-1] = '\0';
103 sprintf(rnms[i], "%s-%d", resnm[i], i+r0);
104 if ((sign == '+') || (sign == '-'))
106 sl = strlen(rnms[i]);
108 rnms[i][sl+1] = '\0';
111 slen = max(slen, (int)strlen(rnms[i]));
113 ring = (2+slen)*fontwidth;
115 box = inner*1.5+(1+(nres / 18))*ring;
117 bPh = bPhobics(nres, resnm);
119 out = ps_open(fn, 0, 0, 2.0*box, 2.0*box);
123 ps_font(out, efontHELV, 1.5*fontsize);
124 ps_translate(out, xc, yc);
127 ps_ctext(out, 0, -fontsize*1.5/2.0, title, eXCenter);
129 ps_font(out, efontHELV, fontsize);
130 ps_rotate(out, rot0);
131 for (i = 0; (i < nres); )
135 ps_color(out, gray, gray, gray);
136 ps_fillarcslice(out, 0, 0, inner, outer, -10, 10);
137 ps_color(out, 0, 0, 0);
139 ps_arcslice(out, 0, 0, inner, outer, -10, 10);
141 ps_ctext(out, inner+fontwidth, -fontsize/2.0, rnms[i], eXLeft);
142 ps_rotate(out, -100);
154 void wheel2(const char *fn, int nres, char *resnm[], real rot0, char *title)
156 const real fontsize = 14;
157 const real gray = 0.9;
158 const real fontasp = 0.45;
160 const real fontwidth = fontsize*fontasp;
164 real ring, inner, outer;
169 for (i = 0; (i < nres); i++)
171 slen = max(slen, (int)strlen(resnm[i]));
173 fprintf(stderr, "slen = %d\n", slen);
174 ring = (slen)*fontwidth;
176 box = (1+(nres / (2*angle)))*outer;
178 out = ps_open(fn, 0, 0, 2.0*box, 2.0*box);
182 ps_font(out, efontHELV, 1.5*fontsize);
183 ps_translate(out, xc, yc);
184 ps_color(out, 0, 0, 0);
187 ps_ctext(out, 0, -fontsize*1.5/2.0, title, eXCenter);
189 ps_font(out, efontHELV, fontsize);
191 ps_rotate(out, rot0);
192 for (i = 0; (i < nres); )
196 ps_color(out, gray, gray, 1.0);
197 ps_fillarcslice(out, 0, 0, inner, outer, -angle, angle);
198 ps_color(out, 0, 0, 0);
200 ps_arcslice(out, 0, 0, inner, outer, -angle, angle);
202 ps_ctext(out, inner+fontwidth, -fontsize/2.0, resnm[i], eXLeft);
203 ps_rotate(out, -2*angle);
206 if ((i % (2*angle)) == 0)
215 int gmx_wheel(int argc, char *argv[])
217 const char *desc[] = {
218 "[THISMODULE] plots a helical wheel representation of your sequence.",
219 "The input sequence is in the [TT].dat[tt] file where the first line contains",
220 "the number of residues and each consecutive line contains a residue "
224 static real rot0 = 0;
225 static gmx_bool bNum = TRUE;
226 static char *title = NULL;
229 { "-r0", FALSE, etINT, {&r0},
230 "The first residue number in the sequence" },
231 { "-rot0", FALSE, etREAL, {&rot0},
232 "Rotate around an angle initially (90 degrees makes sense)" },
233 { "-T", FALSE, etSTR, {&title},
234 "Plot a title in the center of the wheel (must be shorter than 10 characters, or it will overwrite the wheel)" },
235 { "-nn", FALSE, etBOOL, {&bNum},
239 { efDAT, "-f", NULL, ffREAD },
240 { efEPS, "-o", NULL, ffWRITE }
242 #define NFILE asize(fnm)
247 if (!parse_common_args(&argc, argv, PCA_BE_NICE, NFILE, fnm, asize(pa), pa,
248 asize(desc), desc, 0, NULL, &oenv))
253 for (i = 1; (i < argc); i++)
255 if (strcmp(argv[i], "-r0") == 0)
257 r0 = strtol(argv[++i], NULL, 10);
258 fprintf(stderr, "First residue is %d\n", r0);
260 else if (strcmp(argv[i], "-rot0") == 0)
262 rot0 = strtod(argv[++i], NULL);
263 fprintf(stderr, "Initial rotation is %g\n", rot0);
265 else if (strcmp(argv[i], "-T") == 0)
267 title = strdup(argv[++i]);
268 fprintf(stderr, "Title will be '%s'\n", title);
270 else if (strcmp(argv[i], "-nn") == 0)
273 fprintf(stderr, "No residue numbers\n");
277 gmx_fatal(FARGS, "Incorrect usage of option %s", argv[i]);
281 nres = get_lines(ftp2fn(efDAT, NFILE, fnm), &resnm);
284 wheel(ftp2fn(efEPS, NFILE, fnm), nres, resnm, r0, rot0, title);
288 wheel2(ftp2fn(efEPS, NFILE, fnm), nres, resnm, rot0, title);