Fixed a bug in the pdb-writing code.
[gromacs.git] / src / tools / wheel.c
blob85b21c5b98ffc0734e99a9289a6901fda0b0cdc1
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 3.1
11 * Copyright (c) 1991-2001, University of Groningen, The Netherlands
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * If you want to redistribute modifications, please consider that
18 * scientific software is very special. Version control is crucial -
19 * bugs must be traceable. We will be happy to consider code for
20 * inclusion in the official distribution, but derived work must not
21 * be called official GROMACS. Details are found in the README & COPYING
22 * files - if they are missing, get the official version at www.gromacs.org.
24 * To help us fund GROMACS development, we humbly ask that you cite
25 * the papers on the package - you can find them in the top README file.
27 * For more info, check our website at http://www.gromacs.org
29 * And Hey:
30 * Green Red Orange Magenta Azure Cyan Skyblue
32 static char *SRCID_wheel_c = "$Id$";
33 #include <math.h>
34 #include "sysstuff.h"
35 #include "physics.h"
36 #include "string2.h"
37 #include "typedefs.h"
38 #include "smalloc.h"
39 #include "macros.h"
40 #include "vec.h"
41 #include "xvgr.h"
42 #include "pbc.h"
43 #include "copyrite.h"
44 #include "futil.h"
45 #include "strdb.h"
46 #include "statutil.h"
47 #include "pbc.h"
48 #include "rdgroup.h"
49 #include "gstat.h"
50 #include "fatal.h"
51 #include "writeps.h"
52 #include "strdb.h"
54 bool *bPhobics(int nres,char *resnm[])
56 int i,nb;
57 char **cb;
58 bool *bb;
60 nb=get_strings("phbres.dat",&cb);
61 snew(bb,nres);
63 for(i=0; (i<nres); i++) {
64 if (search_str(nb,cb,resnm[i]) != -1)
65 bb[i]=TRUE;
67 return bb;
70 void wheel(char *fn,int nres,char *resnm[],int r0,real rot0,char *title)
72 const real fontsize = 16;
73 const real gray = 0.9;
74 const real fontasp = 0.6;
75 const real fontwidth = fontsize*fontasp;
77 FILE *out;
78 int i,sl,slen;
79 real ring,inner,outer;
80 real xc,yc,box;
81 bool *bPh;
82 char **rnms;
83 char sign;
85 inner=75.0;
86 slen=0;
87 snew(rnms,nres);
88 for(i=0; (i<nres); i++) {
89 snew(rnms[i],256);
90 sl=strlen(resnm[i]);
91 sign=resnm[i][sl-1];
92 if ((sign == '+') || (sign == '-'))
93 resnm[i][sl-1] = '\0';
94 sprintf(rnms[i],"%s-%d",resnm[i],i+r0);
95 if ((sign == '+') || (sign == '-')) {
96 sl=strlen(rnms[i]);
97 rnms[i][sl]=sign;
98 rnms[i][sl+1]='\0';
101 slen=max(slen,(int)strlen(rnms[i]));
103 ring=(2+slen)*fontwidth;
104 outer=inner+ring;
105 box=inner*1.5+(1+(nres / 18))*ring;
107 bPh=bPhobics(nres,resnm);
109 out=ps_open(fn,0,0,2.0*box,2.0*box);
110 xc=box;
111 yc=box;
113 ps_font(out,efontHELV,1.5*fontsize);
114 ps_translate(out,xc,yc);
115 if (title)
116 ps_ctext(out,0,-fontsize*1.5/2.0,title,eXCenter);
117 ps_font(out,efontHELV,fontsize);
119 fprintf(out,"%g rotate\n",rot0);
120 for(i=0; (i<nres); ) {
121 if (bPh[i]) {
122 ps_color(out,gray,gray,gray);
123 ps_fillarcslice(out,0,0,inner,outer,-10,10);
124 ps_color(out,0,0,0);
126 ps_arcslice(out,0,0,inner,outer,-10,10);
128 ps_ctext(out,inner+fontwidth,-fontsize/2.0,rnms[i],eXLeft);
129 fprintf(out,"-100 rotate\n");
130 i++;
132 if ((i % 18) == 0) {
133 inner=outer;
134 outer+=ring;
137 ps_close(out);
140 void wheel2(char *fn,int nres,char *resnm[],int r0,real rot0,char *title)
142 const real fontsize = 14;
143 const real gray = 0.9;
144 const real fontasp = 0.45;
145 const int angle = 9;
146 const real fontwidth = fontsize*fontasp;
148 FILE *out;
149 int i,slen;
150 real ring,inner,outer;
151 real xc,yc,box;
153 inner=60.0;
154 slen=0;
155 for(i=0; (i<nres); i++) {
156 slen=max(slen,(int)strlen(resnm[i]));
158 fprintf(stderr,"slen = %d\n",slen);
159 ring=(slen)*fontwidth;
160 outer=inner+ring;
161 box=(1+(nres / (2*angle)))*outer;
163 out=ps_open(fn,0,0,2.0*box,2.0*box);
164 xc=box;
165 yc=box;
167 ps_font(out,efontHELV,1.5*fontsize);
168 ps_translate(out,xc,yc);
169 ps_color(out,0,0,0);
170 if (title)
171 ps_ctext(out,0,-fontsize*1.5/2.0,title,eXCenter);
172 ps_font(out,efontHELV,fontsize);
174 fprintf(out,"%g rotate\n",rot0);
175 for(i=0; (i<nres); ) {
176 if ((i % 5) == 4) {
177 ps_color(out,gray,gray,1.0);
178 ps_fillarcslice(out,0,0,inner,outer,-angle,angle);
179 ps_color(out,0,0,0);
181 ps_arcslice(out,0,0,inner,outer,-angle,angle);
183 ps_ctext(out,inner+fontwidth,-fontsize/2.0,resnm[i],eXLeft);
184 fprintf(out,"%d rotate\n",-2*angle);
185 i++;
187 if ((i % (2*angle)) == 0) {
188 inner=outer;
189 outer+=ring;
192 ps_close(out);
195 int main(int argc,char *argv[])
197 static char *desc[] = {
198 "wheel plots a helical wheel representation of your sequence."
199 "The input sequence is in the .dat file where the first line contains",
200 "the number of residues and each consecutive line contains a residue"
201 "name."
203 static real rot0=0;
204 static bool bNum=TRUE;
205 static char *title=NULL;
206 static int r0=1;
207 t_pargs pa [] = {
208 { "-r0", FALSE, etINT, {&r0},
209 "The first residue number in the sequence" },
210 { "-rot0",FALSE, etREAL,{&rot0},
211 "Rotate around an angle initially (90 degrees makes sense)" },
212 { "-T", FALSE, etSTR, {&title},
213 "Plot a title in the center of the wheel (must be shorter than 10 characters, or it will overwrite the wheel)" },
214 { "-nn", FALSE, etBOOL,{&bNum},
215 "Toggle numbers" }
217 t_filenm fnm[] = {
218 { efDAT, "-f", NULL, ffREAD },
219 { efEPS, "-o", NULL, ffWRITE }
221 #define NFILE asize(fnm)
223 int i,nres;
224 char **resnm;
226 CopyRight(stderr,argv[0]);
227 parse_common_args(&argc,argv,PCA_BE_NICE,NFILE,fnm,asize(pa),pa,
228 asize(desc),desc,0,NULL);
230 for(i=1; (i<argc); i++) {
231 if (strcmp(argv[i],"-r0") == 0) {
232 r0=atoi(argv[++i]);
233 fprintf(stderr,"First residue is %d\n",r0);
235 else if (strcmp(argv[i],"-rot0") == 0) {
236 rot0=atof(argv[++i]);
237 fprintf(stderr,"Initial rotation is %g\n",rot0);
239 else if (strcmp(argv[i],"-T") == 0) {
240 title=strdup(argv[++i]);
241 fprintf(stderr,"Title will be '%s'\n",title);
243 else if (strcmp(argv[i],"-nn") == 0) {
244 bNum=FALSE;
245 fprintf(stderr,"No residue numbers\n");
247 else
248 fatal_error(0,"Incorrect usage of option %s",argv[i]);
251 nres=get_lines(ftp2fn(efDAT,NFILE,fnm),&resnm);
252 if (bNum)
253 wheel(ftp2fn(efEPS,NFILE,fnm),nres,resnm,r0,rot0,title);
254 else
255 wheel2(ftp2fn(efEPS,NFILE,fnm),nres,resnm,r0,rot0,title);
257 thanx(stderr);
259 return 0;