changed reading hint
[gromacs/adressmacs.git] / src / tools / wheel.c
blobc7ecf0f46d453974dce1f2cc3bfa4eef065fc6ee
1 /*
2 * $Id$
3 *
4 * This source code is part of
5 *
6 * G R O M A C S
7 *
8 * GROningen MAchine for Chemical Simulations
9 *
10 * VERSION 2.0
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
16 * Please refer to:
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
23 * or e-mail to:
24 * gromacs@chem.rug.nl
26 * And Hey:
27 * Great Red Oystrich Makes All Chemists Sane
29 static char *SRCID_wheel_c = "$Id$";
31 #include <math.h>
32 #include "sysstuff.h"
33 #include "physics.h"
34 #include "string2.h"
35 #include "typedefs.h"
36 #include "smalloc.h"
37 #include "macros.h"
38 #include "vec.h"
39 #include "xvgr.h"
40 #include "pbc.h"
41 #include "copyrite.h"
42 #include "futil.h"
43 #include "strdb.h"
44 #include "statutil.h"
45 #include "pbc.h"
46 #include "rdgroup.h"
47 #include "gstat.h"
48 #include "fatal.h"
49 #include "writeps.h"
50 #include "strdb.h"
52 bool *bPhobics(int nres,char *resnm[])
54 int i,nb;
55 char **cb;
56 bool *bb;
58 nb=get_strings("phbres.dat",&cb);
59 snew(bb,nres);
61 for(i=0; (i<nres); i++) {
62 if (search_str(nb,cb,resnm[i]) != -1)
63 bb[i]=TRUE;
65 return bb;
68 void wheel(char *fn,int nres,char *resnm[],int r0,real rot0,char *title)
70 const real fontsize = 16;
71 const real gray = 0.9;
72 const real fontasp = 0.6;
73 const real fontwidth = fontsize*fontasp;
75 FILE *out;
76 int i,sl,slen;
77 real ring,inner,outer;
78 real xc,yc,box;
79 bool *bPh;
80 char **rnms;
81 char sign;
83 inner=75.0;
84 slen=0;
85 snew(rnms,nres);
86 for(i=0; (i<nres); i++) {
87 snew(rnms[i],256);
88 sl=strlen(resnm[i]);
89 sign=resnm[i][sl-1];
90 if ((sign == '+') || (sign == '-'))
91 resnm[i][sl-1] = '\0';
92 sprintf(rnms[i],"%s-%d",resnm[i],i+r0);
93 if ((sign == '+') || (sign == '-')) {
94 sl=strlen(rnms[i]);
95 rnms[i][sl]=sign;
96 rnms[i][sl+1]='\0';
99 slen=max(slen,(int)strlen(rnms[i]));
101 ring=(2+slen)*fontwidth;
102 outer=inner+ring;
103 box=inner*1.5+(1+(nres / 18))*ring;
105 bPh=bPhobics(nres,resnm);
107 out=ps_open(fn,0,0,2.0*box,2.0*box);
108 xc=box;
109 yc=box;
111 ps_font(out,efontHELV,1.5*fontsize);
112 ps_translate(out,xc,yc);
113 if (title)
114 ps_ctext(out,0,-fontsize*1.5/2.0,title,eXCenter);
115 ps_font(out,efontHELV,fontsize);
117 fprintf(out,"%g rotate\n",rot0);
118 for(i=0; (i<nres); ) {
119 if (bPh[i]) {
120 ps_color(out,gray,gray,gray);
121 ps_fillarcslice(out,0,0,inner,outer,-10,10);
122 ps_color(out,0,0,0);
124 ps_arcslice(out,0,0,inner,outer,-10,10);
126 ps_ctext(out,inner+fontwidth,-fontsize/2.0,rnms[i],eXLeft);
127 fprintf(out,"-100 rotate\n");
128 i++;
130 if ((i % 18) == 0) {
131 inner=outer;
132 outer+=ring;
135 ps_close(out);
138 void wheel2(char *fn,int nres,char *resnm[],int r0,real rot0,char *title)
140 const real fontsize = 14;
141 const real gray = 0.9;
142 const real fontasp = 0.45;
143 const int angle = 9;
144 const real fontwidth = fontsize*fontasp;
146 FILE *out;
147 int i,slen;
148 real ring,inner,outer;
149 real xc,yc,box;
151 inner=60.0;
152 slen=0;
153 for(i=0; (i<nres); i++) {
154 slen=max(slen,(int)strlen(resnm[i]));
156 fprintf(stderr,"slen = %d\n",slen);
157 ring=(slen)*fontwidth;
158 outer=inner+ring;
159 box=(1+(nres / (2*angle)))*outer;
161 out=ps_open(fn,0,0,2.0*box,2.0*box);
162 xc=box;
163 yc=box;
165 ps_font(out,efontHELV,1.5*fontsize);
166 ps_translate(out,xc,yc);
167 ps_color(out,0,0,0);
168 if (title)
169 ps_ctext(out,0,-fontsize*1.5/2.0,title,eXCenter);
170 ps_font(out,efontHELV,fontsize);
172 fprintf(out,"%g rotate\n",rot0);
173 for(i=0; (i<nres); ) {
174 if ((i % 5) == 4) {
175 ps_color(out,gray,gray,1.0);
176 ps_fillarcslice(out,0,0,inner,outer,-angle,angle);
177 ps_color(out,0,0,0);
179 ps_arcslice(out,0,0,inner,outer,-angle,angle);
181 ps_ctext(out,inner+fontwidth,-fontsize/2.0,resnm[i],eXLeft);
182 fprintf(out,"%d rotate\n",-2*angle);
183 i++;
185 if ((i % (2*angle)) == 0) {
186 inner=outer;
187 outer+=ring;
190 ps_close(out);
193 int main(int argc,char *argv[])
195 static char *desc[] = {
196 "wheel plots a helical wheel representation of your sequence."
197 "The input sequence is in the .dat file where the first line contains",
198 "the number of residues and each consecutive line contains a residue"
199 "name."
201 static real rot0=0;
202 static bool bNum=TRUE;
203 static char *title=NULL;
204 static int r0=1;
205 t_pargs pa [] = {
206 { "-r0", FALSE, etINT, {&r0},
207 "The first residue number in the sequence" },
208 { "-rot0",FALSE, etREAL,{&rot0},
209 "Rotate around an angle initially (90 degrees makes sense)" },
210 { "-T", FALSE, etSTR, {&title},
211 "Plot a title in the center of the wheel (must be shorter than 10 characters, or it will overwrite the wheel)" },
212 { "-nn", FALSE, etBOOL,{&bNum},
213 "Toggle numbers" }
215 t_filenm fnm[] = {
216 { efDAT, "-f", NULL, ffREAD },
217 { efEPS, "-o", NULL, ffWRITE }
219 #define NFILE asize(fnm)
221 int i,nres;
222 char **resnm;
224 CopyRight(stderr,argv[0]);
225 parse_common_args(&argc,argv,0,TRUE,NFILE,fnm,asize(pa),pa,
226 asize(desc),desc,0,NULL);
228 for(i=1; (i<argc); i++) {
229 if (strcmp(argv[i],"-r0") == 0) {
230 r0=atoi(argv[++i]);
231 fprintf(stderr,"First residue is %d\n",r0);
233 else if (strcmp(argv[i],"-rot0") == 0) {
234 rot0=atof(argv[++i]);
235 fprintf(stderr,"Initial rotation is %g\n",rot0);
237 else if (strcmp(argv[i],"-T") == 0) {
238 title=strdup(argv[++i]);
239 fprintf(stderr,"Title will be '%s'\n",title);
241 else if (strcmp(argv[i],"-nn") == 0) {
242 bNum=FALSE;
243 fprintf(stderr,"No residue numbers\n");
245 else
246 fatal_error(0,"Incorrect usage of option %s",argv[i]);
249 nres=get_lines(ftp2fn(efDAT,NFILE,fnm),&resnm);
250 if (bNum)
251 wheel(ftp2fn(efEPS,NFILE,fnm),nres,resnm,r0,rot0,title);
252 else
253 wheel2(ftp2fn(efEPS,NFILE,fnm),nres,resnm,r0,rot0,title);
255 thanx(stdout);
257 return 0;