3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
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
33 * Gyas ROwers Mature At Cryogenic Speed
55 enum { ebQuit, ebStart, ebStop, ebRewind, ebGly, ebutNR };
58 #define SX(x) ((int)(((x)+M_PI)*scx))
59 #define SY(y) ((int)((M_PI-(y))*scy))
61 enum { esStop, esGo, esNR };
70 t_windata but[ebutNR];
73 static void plot_pp(t_x11 *x11,Window w,t_phipsi *pp,t_dih dih[])
76 int th=(XTextHeight(x11->font)+6)/2;
78 x0=SX(dih[pp->iphi].ang);
79 y0=SY(dih[pp->ipsi].ang);
80 XFillRectangle(x11->disp,w,x11->gc,x0-1,y0-1,4,4);
83 TextInRect(x11,w,pp->label,x0+6,y0-th,30,2*th,eXLeft,eYCenter);
86 static gmx_bool label_pp(t_x11 *x11,Window w,int npp,t_phipsi pp[],
87 t_dih dih[],int mx,int my)
94 for(i=0; (i<npp); i++) {
95 x0=SX(dih[pp[i].iphi].ang);
96 y0=SY(dih[pp[i].ipsi].ang);
97 d=(mx-x0)*(mx-x0)+(my-y0)*(my-y0);
104 pp[imin].bShow=!pp[imin].bShow;
110 static gmx_bool xrCallBack(struct t_x11 *x11,XEvent *event, Window w, void *data)
117 (void)XTextHeight(x11->font);
120 scx=app->xrwd.width/(2.0*M_PI);
121 scy=app->xrwd.height/(2.0*M_PI);
122 switch (event->type) {
124 XClearWindow(x11->disp,app->xrwd.self);
125 XDrawLine(x11->disp,app->xrwd.self,x11->gc,
126 SX(0),SY(-M_PI)+1,SX(0),SY(M_PI)-1);
127 XDrawLine(x11->disp,app->xrwd.self,x11->gc,
128 SX(-M_PI)+1,SY(0),SX(M_PI)-1,SY(0));
129 TextInRect(x11,app->xrwd.self,"Phi",SX(M_PI)-50,SY(0)+4,46,20,eXRight,eYTop);
130 TextInRect(x11,app->xrwd.self,"Psi",SX(0)+4,4,46,20,eXLeft,eYTop);
131 for(i=0; (i<xr->npp); i++)
132 if (app->bShowGly || !app->bIsGly[i])
133 plot_pp(x11,app->xrwd.self,&(xr->pp[i]),xr->dih);
136 if (label_pp(x11,app->xrwd.self,xr->npp,xr->pp,xr->dih,
137 event->xbutton.x,event->xbutton.y))
138 ExposeWin(x11->disp,app->xrwd.self);
140 case ConfigureNotify:
141 app->xrwd.width=event->xconfigure.width;
142 app->xrwd.height=event->xconfigure.height;
145 if (app->status == esGo) {
146 if (!new_data(app->xr))
149 ExposeWin(x11->disp,app->xrwd.self);
150 sprintf(buf,"Rama: t=%.2f",app->xr->t);
151 XSetStandardProperties(x11->disp,app->wd.self,buf,
152 "Rama",0,NULL,0,NULL);
159 static gmx_bool appCallBack(struct t_x11 *x11,XEvent *event, Window w, void *data)
165 for(win=0; (win<ebutNR); win++)
166 if (app->but[win].self == w)
171 switch(event->type) {
173 TextInWin(x11,&(app->but[win]),app->but[win].text,eXCenter,eYCenter);
181 ExposeWin(x11->disp,app->xrwd.self);
187 rewind_trj(app->xr->traj);
190 app->bShowGly=!app->bShowGly;
191 ExposeWin(x11->disp,app->xrwd.self);
202 static void size_app(t_x11 *x11,t_app *app)
206 th=XTextHeight(x11->font)+4;
207 dx=app->wd.width/ebutNR;
208 for(i=0; (i<ebutNR); i++) {
209 app->but[i].width=dx-4;
210 app->but[i].height=th+4;
211 XMoveResizeWindow(x11->disp,app->but[i].self,i*dx+2,2,dx-4,th+4);
213 XMoveResizeWindow(x11->disp,app->xrwd.self,2,th+10,
214 app->wd.width-6,app->wd.height-th-10-4);
217 static gmx_bool mainCallBack(struct t_x11 *x11,XEvent *event, Window w, void *data)
223 switch (event->type) {
224 case ConfigureNotify:
225 wt=event->xconfigure.width;
226 ht=event->xconfigure.height;
227 if ((app->wd.width != wt) || (app->wd.height != ht)) {
228 fprintf(stderr,"New wxh = %dx%d\n",wt,ht);
238 static t_xrama *init_xrama(t_x11 *x11,Window Parent,int y0,t_app *app)
244 InitWin(&(app->xrwd),2,y0,MAXDEG+1,MAXDEG+1,1,"Ramachandran Movie");
245 app->xrwd.self=XCreateSimpleWindow(x11->disp,Parent,app->xrwd.x,app->xrwd.y,
246 app->xrwd.width,app->xrwd.height,
247 app->xrwd.bwidth,x11->fg,x11->bg);
248 x11->RegisterCallback(x11,app->xrwd.self,Parent,xrCallBack,app);
249 x11->SetInputMask(x11,app->xrwd.self,ButtonPressMask | ExposureMask |
250 StructureNotifyMask);
255 static t_app *init_app(t_x11 *x11,int argc,char *argv[])
257 static const char *but_nm[ebutNR] = { "Quit", "Start", "Stop", "Rewind", "Toggle Gly" };
266 th=XTextHeight(x11->font)+4;
267 InitWin(&(app->wd),0,0,MAXDEG+6,MAXDEG+6+th+6,0,"Ramachandran Movie");
268 dx=app->wd.width/ebutNR;
269 app->wd.self=XCreateSimpleWindow(x11->disp,x11->root,app->wd.x,app->wd.y,
270 app->wd.width,app->wd.height,
271 app->wd.bwidth,x11->fg,x11->bg);
272 x11->RegisterCallback(x11,app->wd.self,x11->root,mainCallBack,app);
273 x11->SetInputMask(x11,app->wd.self,StructureNotifyMask);
275 pm=XCreatePixmapFromBitmapData(x11->disp,x11->root,(char *)rama_bits,
276 rama_width,rama_height,WHITE,BLACK,1);
277 XSetStandardProperties(x11->disp,app->wd.self,app->wd.text,
278 "Rama",pm,argv,argc,&hints);
279 x11->RegisterCallback(x11,app->wd.self,x11->root,appCallBack,app);
280 x11->SetInputMask(x11,app->wd.self,ButtonPressMask | ExposureMask |
281 StructureNotifyMask);
283 app->xr=init_xrama(x11,app->wd.self,th+6,app);
284 for(i=0; (i<ebutNR); i++) {
286 InitWin(wd,i*dx+2,2,dx-4,th,1,but_nm[i]);
287 wd->self=XCreateSimpleWindow(x11->disp,app->wd.self,
288 wd->x,wd->y,wd->width,wd->height,
289 wd->bwidth,x11->fg,x11->bg);
290 x11->RegisterCallback(x11,wd->self,app->wd.self,appCallBack,app);
291 x11->SetInputMask(x11,wd->self,ButtonPressMask | ExposureMask);
296 static void mk_gly(t_app *app)
300 snew(app->bIsGly,app->xr->npp);
301 for(i=0; (i<app->xr->npp); i++) {
302 if (strstr(app->xr->pp[i].label,"GLY") != NULL)
307 int main(int argc,char *argv[])
309 const char *desc[] = {
310 "[TT]g_xrama[tt] shows a Ramachandran movie, that is, it shows",
311 "the Phi/Psi angles as a function of time in an X-Window.[PAR]"
312 "Static Phi/Psi plots for printing can be made with [TT]g_rama[tt].[PAR]",
313 "Some of the more common X command line options can be used:[BR]",
314 "[TT]-bg[tt], [TT]-fg[tt] change colors, [TT]-font fontname[tt], changes the font."
322 { efTRX, "-f", NULL, ffREAD },
323 { efTPX, NULL, NULL, ffREAD }
325 #define NFILE asize(fnm)
327 CopyRight(stderr,argv[0]);
328 parse_common_args(&argc,argv,PCA_CAN_TIME,NFILE,fnm,0,NULL,
329 asize(desc),desc,0,NULL,&oenv);
332 if ((x11=GetX11(&argc,argv)) == NULL) {
333 fprintf(stderr,"Can't open display, set your DISPLAY environment variable\n");
336 XSetForeground(x11->disp,x11->gc,x11->fg);
337 app=init_app(x11,argc,argv);
339 ramatop = init_rama(oenv,ftp2fn(efTRX,NFILE,fnm),ftp2fn(efTPX,NFILE,fnm),
343 XMapWindow(x11->disp,app->wd.self);
344 XMapSubwindows(x11->disp,app->wd.self);