Removed reference to nonexistent file in g_helix.
[gromacs.git] / src / tools / gmx_wheel.c
blob0d75eacf69a8de4559f94f41aacec75c2d694e80
1 /*
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 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012, 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.
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.
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.
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.
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.
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.
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
42 #include <math.h>
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include "sysstuff.h"
46 #include "physics.h"
47 #include "string2.h"
48 #include "typedefs.h"
49 #include "smalloc.h"
50 #include "macros.h"
51 #include "vec.h"
52 #include "xvgr.h"
53 #include "pbc.h"
54 #include "copyrite.h"
55 #include "futil.h"
56 #include "strdb.h"
57 #include "statutil.h"
58 #include "pbc.h"
59 #include "index.h"
60 #include "gstat.h"
61 #include "gmx_fatal.h"
62 #include "writeps.h"
63 #include "strdb.h"
64 #include "gmx_ana.h"
66 static gmx_bool *bPhobics(int nres,char *resnm[])
68 int i,nb;
69 char **cb;
70 gmx_bool *bb;
72 nb=get_strings("phbres.dat",&cb);
73 snew(bb,nres);
75 for(i=0; (i<nres); i++) {
76 if (search_str(nb,cb,resnm[i]) != -1)
77 bb[i]=TRUE;
79 return bb;
82 void wheel(const char *fn,int nres,char *resnm[],int r0,real rot0,char *title)
84 const real fontsize = 16;
85 const real gray = 0.9;
86 const real fontasp = 0.6;
87 const real fontwidth = fontsize*fontasp;
89 t_psdata out;
90 int i,sl,slen;
91 real ring,inner,outer;
92 real xc,yc,box;
93 gmx_bool *bPh;
94 char **rnms;
95 char sign;
97 inner=75.0;
98 slen=0;
99 snew(rnms,nres);
100 for(i=0; (i<nres); i++) {
101 snew(rnms[i],256);
102 sl=strlen(resnm[i]);
103 sign=resnm[i][sl-1];
104 if ((sign == '+') || (sign == '-'))
105 resnm[i][sl-1] = '\0';
106 sprintf(rnms[i],"%s-%d",resnm[i],i+r0);
107 if ((sign == '+') || (sign == '-')) {
108 sl=strlen(rnms[i]);
109 rnms[i][sl]=sign;
110 rnms[i][sl+1]='\0';
113 slen=max(slen,(int)strlen(rnms[i]));
115 ring=(2+slen)*fontwidth;
116 outer=inner+ring;
117 box=inner*1.5+(1+(nres / 18))*ring;
119 bPh=bPhobics(nres,resnm);
121 out=ps_open(fn,0,0,2.0*box,2.0*box);
122 xc=box;
123 yc=box;
125 ps_font(out,efontHELV,1.5*fontsize);
126 ps_translate(out,xc,yc);
127 if (title)
128 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); ) {
132 if (bPh[i]) {
133 ps_color(out,gray,gray,gray);
134 ps_fillarcslice(out,0,0,inner,outer,-10,10);
135 ps_color(out,0,0,0);
137 ps_arcslice(out,0,0,inner,outer,-10,10);
139 ps_ctext(out,inner+fontwidth,-fontsize/2.0,rnms[i],eXLeft);
140 ps_rotate(out,-100);
141 i++;
143 if ((i % 18) == 0) {
144 inner=outer;
145 outer+=ring;
148 ps_close(out);
151 void wheel2(const char *fn,int nres,char *resnm[],int r0,real rot0,char *title)
153 const real fontsize = 14;
154 const real gray = 0.9;
155 const real fontasp = 0.45;
156 const int angle = 9;
157 const real fontwidth = fontsize*fontasp;
159 t_psdata out;
160 int i,slen;
161 real ring,inner,outer;
162 real xc,yc,box;
164 inner=60.0;
165 slen=0;
166 for(i=0; (i<nres); i++) {
167 slen=max(slen,(int)strlen(resnm[i]));
169 fprintf(stderr,"slen = %d\n",slen);
170 ring=(slen)*fontwidth;
171 outer=inner+ring;
172 box=(1+(nres / (2*angle)))*outer;
174 out=ps_open(fn,0,0,2.0*box,2.0*box);
175 xc=box;
176 yc=box;
178 ps_font(out,efontHELV,1.5*fontsize);
179 ps_translate(out,xc,yc);
180 ps_color(out,0,0,0);
181 if (title)
182 ps_ctext(out,0,-fontsize*1.5/2.0,title,eXCenter);
183 ps_font(out,efontHELV,fontsize);
185 ps_rotate(out,rot0);
186 for(i=0; (i<nres); ) {
187 if ((i % 5) == 4) {
188 ps_color(out,gray,gray,1.0);
189 ps_fillarcslice(out,0,0,inner,outer,-angle,angle);
190 ps_color(out,0,0,0);
192 ps_arcslice(out,0,0,inner,outer,-angle,angle);
194 ps_ctext(out,inner+fontwidth,-fontsize/2.0,resnm[i],eXLeft);
195 ps_rotate(out,-2*angle);
196 i++;
198 if ((i % (2*angle)) == 0) {
199 inner=outer;
200 outer+=ring;
203 ps_close(out);
206 int gmx_wheel(int argc,char *argv[])
208 const char *desc[] = {
209 "[TT]g_wheel[tt] plots a helical wheel representation of your sequence.",
210 "The input sequence is in the [TT].dat[tt] file where the first line contains",
211 "the number of residues and each consecutive line contains a residue "
212 "name."
214 output_env_t oenv;
215 static real rot0=0;
216 static gmx_bool bNum=TRUE;
217 static char *title=NULL;
218 static int r0=1;
219 t_pargs pa [] = {
220 { "-r0", FALSE, etINT, {&r0},
221 "The first residue number in the sequence" },
222 { "-rot0",FALSE, etREAL,{&rot0},
223 "Rotate around an angle initially (90 degrees makes sense)" },
224 { "-T", FALSE, etSTR, {&title},
225 "Plot a title in the center of the wheel (must be shorter than 10 characters, or it will overwrite the wheel)" },
226 { "-nn", FALSE, etBOOL,{&bNum},
227 "Toggle numbers" }
229 t_filenm fnm[] = {
230 { efDAT, "-f", NULL, ffREAD },
231 { efEPS, "-o", NULL, ffWRITE }
233 #define NFILE asize(fnm)
235 int i,nres;
236 char **resnm;
238 CopyRight(stderr,argv[0]);
239 parse_common_args(&argc,argv,PCA_BE_NICE,NFILE,fnm,asize(pa),pa,
240 asize(desc),desc,0,NULL,&oenv);
242 for(i=1; (i<argc); i++) {
243 if (strcmp(argv[i],"-r0") == 0) {
244 r0=strtol(argv[++i],NULL,10);
245 fprintf(stderr,"First residue is %d\n",r0);
247 else if (strcmp(argv[i],"-rot0") == 0) {
248 rot0=strtod(argv[++i],NULL);
249 fprintf(stderr,"Initial rotation is %g\n",rot0);
251 else if (strcmp(argv[i],"-T") == 0) {
252 title=strdup(argv[++i]);
253 fprintf(stderr,"Title will be '%s'\n",title);
255 else if (strcmp(argv[i],"-nn") == 0) {
256 bNum=FALSE;
257 fprintf(stderr,"No residue numbers\n");
259 else
260 gmx_fatal(FARGS,"Incorrect usage of option %s",argv[i]);
263 nres=get_lines(ftp2fn(efDAT,NFILE,fnm),&resnm);
264 if (bNum)
265 wheel(ftp2fn(efEPS,NFILE,fnm),nres,resnm,r0,rot0,title);
266 else
267 wheel2(ftp2fn(efEPS,NFILE,fnm),nres,resnm,r0,rot0,title);
269 thanx(stderr);
271 return 0;