Fixed make_edi.c
[gromacs/rigid-bodies.git] / src / tools / gmx_wheel.c
blobaa60df9a1b1c51e0e657b891103b5e90550f1953
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.
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.
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.
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.
30 * For more info, check our website at http://www.gromacs.org
32 * And Hey:
33 * Green Red Orange Magenta Azure Cyan Skyblue
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
39 #include <math.h>
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include "sysstuff.h"
43 #include "physics.h"
44 #include "string2.h"
45 #include "typedefs.h"
46 #include "smalloc.h"
47 #include "macros.h"
48 #include "vec.h"
49 #include "xvgr.h"
50 #include "pbc.h"
51 #include "copyrite.h"
52 #include "futil.h"
53 #include "strdb.h"
54 #include "statutil.h"
55 #include "pbc.h"
56 #include "index.h"
57 #include "gstat.h"
58 #include "gmx_fatal.h"
59 #include "writeps.h"
60 #include "strdb.h"
61 #include "gmx_ana.h"
63 bool *bPhobics(int nres,char *resnm[])
65 int i,nb;
66 char **cb;
67 bool *bb;
69 nb=get_strings("phbres.dat",&cb);
70 snew(bb,nres);
72 for(i=0; (i<nres); i++) {
73 if (search_str(nb,cb,resnm[i]) != -1)
74 bb[i]=TRUE;
76 return bb;
79 void wheel(const char *fn,int nres,char *resnm[],int r0,real rot0,char *title)
81 const real fontsize = 16;
82 const real gray = 0.9;
83 const real fontasp = 0.6;
84 const real fontwidth = fontsize*fontasp;
86 t_psdata out;
87 int i,sl,slen;
88 real ring,inner,outer;
89 real xc,yc,box;
90 bool *bPh;
91 char **rnms;
92 char sign;
94 inner=75.0;
95 slen=0;
96 snew(rnms,nres);
97 for(i=0; (i<nres); i++) {
98 snew(rnms[i],256);
99 sl=strlen(resnm[i]);
100 sign=resnm[i][sl-1];
101 if ((sign == '+') || (sign == '-'))
102 resnm[i][sl-1] = '\0';
103 sprintf(rnms[i],"%s-%d",resnm[i],i+r0);
104 if ((sign == '+') || (sign == '-')) {
105 sl=strlen(rnms[i]);
106 rnms[i][sl]=sign;
107 rnms[i][sl+1]='\0';
110 slen=max(slen,(int)strlen(rnms[i]));
112 ring=(2+slen)*fontwidth;
113 outer=inner+ring;
114 box=inner*1.5+(1+(nres / 18))*ring;
116 bPh=bPhobics(nres,resnm);
118 out=ps_open(fn,0,0,2.0*box,2.0*box);
119 xc=box;
120 yc=box;
122 ps_font(out,efontHELV,1.5*fontsize);
123 ps_translate(out,xc,yc);
124 if (title)
125 ps_ctext(out,0,-fontsize*1.5/2.0,title,eXCenter);
126 ps_font(out,efontHELV,fontsize);
127 ps_rotate(out,rot0);
128 for(i=0; (i<nres); ) {
129 if (bPh[i]) {
130 ps_color(out,gray,gray,gray);
131 ps_fillarcslice(out,0,0,inner,outer,-10,10);
132 ps_color(out,0,0,0);
134 ps_arcslice(out,0,0,inner,outer,-10,10);
136 ps_ctext(out,inner+fontwidth,-fontsize/2.0,rnms[i],eXLeft);
137 ps_rotate(out,-100);
138 i++;
140 if ((i % 18) == 0) {
141 inner=outer;
142 outer+=ring;
145 ps_close(out);
148 void wheel2(const char *fn,int nres,char *resnm[],int r0,real rot0,char *title)
150 const real fontsize = 14;
151 const real gray = 0.9;
152 const real fontasp = 0.45;
153 const int angle = 9;
154 const real fontwidth = fontsize*fontasp;
156 t_psdata out;
157 int i,slen;
158 real ring,inner,outer;
159 real xc,yc,box;
161 inner=60.0;
162 slen=0;
163 for(i=0; (i<nres); i++) {
164 slen=max(slen,(int)strlen(resnm[i]));
166 fprintf(stderr,"slen = %d\n",slen);
167 ring=(slen)*fontwidth;
168 outer=inner+ring;
169 box=(1+(nres / (2*angle)))*outer;
171 out=ps_open(fn,0,0,2.0*box,2.0*box);
172 xc=box;
173 yc=box;
175 ps_font(out,efontHELV,1.5*fontsize);
176 ps_translate(out,xc,yc);
177 ps_color(out,0,0,0);
178 if (title)
179 ps_ctext(out,0,-fontsize*1.5/2.0,title,eXCenter);
180 ps_font(out,efontHELV,fontsize);
182 ps_rotate(out,rot0);
183 for(i=0; (i<nres); ) {
184 if ((i % 5) == 4) {
185 ps_color(out,gray,gray,1.0);
186 ps_fillarcslice(out,0,0,inner,outer,-angle,angle);
187 ps_color(out,0,0,0);
189 ps_arcslice(out,0,0,inner,outer,-angle,angle);
191 ps_ctext(out,inner+fontwidth,-fontsize/2.0,resnm[i],eXLeft);
192 ps_rotate(out,-2*angle);
193 i++;
195 if ((i % (2*angle)) == 0) {
196 inner=outer;
197 outer+=ring;
200 ps_close(out);
203 int gmx_wheel(int argc,char *argv[])
205 const char *desc[] = {
206 "wheel plots a helical wheel representation of your sequence.",
207 "The input sequence is in the .dat file where the first line contains",
208 "the number of residues and each consecutive line contains a residue"
209 "name."
211 output_env_t oenv;
212 static real rot0=0;
213 static bool bNum=TRUE;
214 static char *title=NULL;
215 static int r0=1;
216 t_pargs pa [] = {
217 { "-r0", FALSE, etINT, {&r0},
218 "The first residue number in the sequence" },
219 { "-rot0",FALSE, etREAL,{&rot0},
220 "Rotate around an angle initially (90 degrees makes sense)" },
221 { "-T", FALSE, etSTR, {&title},
222 "Plot a title in the center of the wheel (must be shorter than 10 characters, or it will overwrite the wheel)" },
223 { "-nn", FALSE, etBOOL,{&bNum},
224 "Toggle numbers" }
226 t_filenm fnm[] = {
227 { efDAT, "-f", NULL, ffREAD },
228 { efEPS, "-o", NULL, ffWRITE }
230 #define NFILE asize(fnm)
232 int i,nres;
233 char **resnm;
235 CopyRight(stderr,argv[0]);
236 parse_common_args(&argc,argv,PCA_BE_NICE,NFILE,fnm,asize(pa),pa,
237 asize(desc),desc,0,NULL,&oenv);
239 for(i=1; (i<argc); i++) {
240 if (strcmp(argv[i],"-r0") == 0) {
241 r0=strtol(argv[++i],NULL,10);
242 fprintf(stderr,"First residue is %d\n",r0);
244 else if (strcmp(argv[i],"-rot0") == 0) {
245 rot0=strtod(argv[++i],NULL);
246 fprintf(stderr,"Initial rotation is %g\n",rot0);
248 else if (strcmp(argv[i],"-T") == 0) {
249 title=strdup(argv[++i]);
250 fprintf(stderr,"Title will be '%s'\n",title);
252 else if (strcmp(argv[i],"-nn") == 0) {
253 bNum=FALSE;
254 fprintf(stderr,"No residue numbers\n");
256 else
257 gmx_fatal(FARGS,"Incorrect usage of option %s",argv[i]);
260 nres=get_lines(ftp2fn(efDAT,NFILE,fnm),&resnm);
261 if (bNum)
262 wheel(ftp2fn(efEPS,NFILE,fnm),nres,resnm,r0,rot0,title);
263 else
264 wheel2(ftp2fn(efEPS,NFILE,fnm),nres,resnm,r0,rot0,title);
266 thanx(stderr);
268 return 0;