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
56 ebQuit, ebStart, ebStop, ebRewind, ebGly, ebutNR
60 #define SX(x) ((int)(((x)+M_PI)*scx))
61 #define SY(y) ((int)((M_PI-(y))*scy))
74 t_windata but[ebutNR];
77 static void plot_pp(t_x11 *x11, Window w, t_phipsi *pp, t_dih dih[])
80 int th = (XTextHeight(x11->font)+6)/2;
82 x0 = SX(dih[pp->iphi].ang);
83 y0 = SY(dih[pp->ipsi].ang);
84 XFillRectangle(x11->disp, w, x11->gc, x0-1, y0-1, 4, 4);
88 TextInRect(x11, w, pp->label, x0+6, y0-th, 30, 2*th, eXLeft, eYCenter);
92 static gmx_bool label_pp(t_x11 *x11, Window w, int npp, t_phipsi pp[],
93 t_dih dih[], int mx, int my)
100 for (i = 0; (i < npp); i++)
102 x0 = SX(dih[pp[i].iphi].ang);
103 y0 = SY(dih[pp[i].ipsi].ang);
104 d = (mx-x0)*(mx-x0)+(my-y0)*(my-y0);
113 pp[imin].bShow = !pp[imin].bShow;
119 static gmx_bool xrCallBack(struct t_x11 *x11, XEvent *event, Window w, void *data)
126 (void)XTextHeight(x11->font);
129 scx = app->xrwd.width/(2.0*M_PI);
130 scy = app->xrwd.height/(2.0*M_PI);
134 XClearWindow(x11->disp, app->xrwd.self);
135 XDrawLine(x11->disp, app->xrwd.self, x11->gc,
136 SX(0), SY(-M_PI)+1, SX(0), SY(M_PI)-1);
137 XDrawLine(x11->disp, app->xrwd.self, x11->gc,
138 SX(-M_PI)+1, SY(0), SX(M_PI)-1, SY(0));
139 TextInRect(x11, app->xrwd.self, "Phi", SX(M_PI)-50, SY(0)+4, 46, 20, eXRight, eYTop);
140 TextInRect(x11, app->xrwd.self, "Psi", SX(0)+4, 4, 46, 20, eXLeft, eYTop);
141 for (i = 0; (i < xr->npp); i++)
143 if (app->bShowGly || !app->bIsGly[i])
145 plot_pp(x11, app->xrwd.self, &(xr->pp[i]), xr->dih);
150 if (label_pp(x11, app->xrwd.self, xr->npp, xr->pp, xr->dih,
151 event->xbutton.x, event->xbutton.y))
153 ExposeWin(x11->disp, app->xrwd.self);
156 case ConfigureNotify:
157 app->xrwd.width = event->xconfigure.width;
158 app->xrwd.height = event->xconfigure.height;
161 if (app->status == esGo)
163 if (!new_data(app->xr))
165 app->status = ebStop;
169 ExposeWin(x11->disp, app->xrwd.self);
170 sprintf(buf, "Rama: t=%.2f", app->xr->t);
171 XSetStandardProperties(x11->disp, app->wd.self, buf,
172 "Rama", 0, NULL, 0, NULL);
179 static gmx_bool appCallBack(struct t_x11 *x11, XEvent *event, Window w, void *data)
185 for (win = 0; (win < ebutNR); win++)
187 if (app->but[win].self == w)
200 TextInWin(x11, &(app->but[win]), app->but[win].text, eXCenter, eYCenter);
209 ExposeWin(x11->disp, app->xrwd.self);
212 app->status = esStop;
215 rewind_trj(app->xr->traj);
218 app->bShowGly = !app->bShowGly;
219 ExposeWin(x11->disp, app->xrwd.self);
222 XBell(x11->disp, 50);
230 static void size_app(t_x11 *x11, t_app *app)
234 th = XTextHeight(x11->font)+4;
235 dx = app->wd.width/ebutNR;
236 for (i = 0; (i < ebutNR); i++)
238 app->but[i].width = dx-4;
239 app->but[i].height = th+4;
240 XMoveResizeWindow(x11->disp, app->but[i].self, i*dx+2, 2, dx-4, th+4);
242 XMoveResizeWindow(x11->disp, app->xrwd.self, 2, th+10,
243 app->wd.width-6, app->wd.height-th-10-4);
246 static gmx_bool mainCallBack(struct t_x11 *x11, XEvent *event, Window w, void *data)
254 case ConfigureNotify:
255 wt = event->xconfigure.width;
256 ht = event->xconfigure.height;
257 if ((app->wd.width != wt) || (app->wd.height != ht))
259 fprintf(stderr, "New wxh = %dx%d\n", wt, ht);
269 static t_xrama *init_xrama(t_x11 *x11, Window Parent, int y0, t_app *app)
275 InitWin(&(app->xrwd), 2, y0, MAXDEG+1, MAXDEG+1, 1, "Ramachandran Movie");
276 app->xrwd.self = XCreateSimpleWindow(x11->disp, Parent, app->xrwd.x, app->xrwd.y,
277 app->xrwd.width, app->xrwd.height,
278 app->xrwd.bwidth, x11->fg, x11->bg);
279 x11->RegisterCallback(x11, app->xrwd.self, Parent, xrCallBack, app);
280 x11->SetInputMask(x11, app->xrwd.self, ButtonPressMask | ExposureMask |
281 StructureNotifyMask);
286 static t_app *init_app(t_x11 *x11, int argc, char *argv[])
288 static const char *but_nm[ebutNR] = { "Quit", "Start", "Stop", "Rewind", "Toggle Gly" };
297 th = XTextHeight(x11->font)+4;
298 InitWin(&(app->wd), 0, 0, MAXDEG+6, MAXDEG+6+th+6, 0, "Ramachandran Movie");
299 dx = app->wd.width/ebutNR;
300 app->wd.self = XCreateSimpleWindow(x11->disp, x11->root, app->wd.x, app->wd.y,
301 app->wd.width, app->wd.height,
302 app->wd.bwidth, x11->fg, x11->bg);
303 x11->RegisterCallback(x11, app->wd.self, x11->root, mainCallBack, app);
304 x11->SetInputMask(x11, app->wd.self, StructureNotifyMask);
306 pm = XCreatePixmapFromBitmapData(x11->disp, x11->root, (char *)rama_bits,
307 rama_width, rama_height, WHITE, BLACK, 1);
308 XSetStandardProperties(x11->disp, app->wd.self, app->wd.text,
309 "Rama", pm, argv, argc, &hints);
310 x11->RegisterCallback(x11, app->wd.self, x11->root, appCallBack, app);
311 x11->SetInputMask(x11, app->wd.self, ButtonPressMask | ExposureMask |
312 StructureNotifyMask);
314 app->xr = init_xrama(x11, app->wd.self, th+6, app);
315 for (i = 0; (i < ebutNR); i++)
318 InitWin(wd, i*dx+2, 2, dx-4, th, 1, but_nm[i]);
319 wd->self = XCreateSimpleWindow(x11->disp, app->wd.self,
320 wd->x, wd->y, wd->width, wd->height,
321 wd->bwidth, x11->fg, x11->bg);
322 x11->RegisterCallback(x11, wd->self, app->wd.self, appCallBack, app);
323 x11->SetInputMask(x11, wd->self, ButtonPressMask | ExposureMask);
328 static void mk_gly(t_app *app)
332 snew(app->bIsGly, app->xr->npp);
333 for (i = 0; (i < app->xr->npp); i++)
335 if (strstr(app->xr->pp[i].label, "GLY") != NULL)
337 app->bIsGly[i] = TRUE;
342 int main(int argc, char *argv[])
344 const char *desc[] = {
345 "[TT]g_xrama[tt] shows a Ramachandran movie, that is, it shows",
346 "the Phi/Psi angles as a function of time in an X-Window.[PAR]"
347 "Static Phi/Psi plots for printing can be made with [TT]g_rama[tt].[PAR]",
348 "Some of the more common X command line options can be used:[BR]",
349 "[TT]-bg[tt], [TT]-fg[tt] change colors, [TT]-font fontname[tt], changes the font."
357 { efTRX, "-f", NULL, ffREAD },
358 { efTPX, NULL, NULL, ffREAD }
360 #define NFILE asize(fnm)
362 CopyRight(stderr, argv[0]);
363 parse_common_args(&argc, argv, PCA_CAN_TIME, NFILE, fnm, 0, NULL,
364 asize(desc), desc, 0, NULL, &oenv);
367 if ((x11 = GetX11(&argc, argv)) == NULL)
369 fprintf(stderr, "Can't open display, set your DISPLAY environment variable\n");
372 XSetForeground(x11->disp, x11->gc, x11->fg);
373 app = init_app(x11, argc, argv);
375 ramatop = init_rama(oenv, ftp2fn(efTRX, NFILE, fnm), ftp2fn(efTPX, NFILE, fnm),
379 XMapWindow(x11->disp, app->wd.self);
380 XMapSubwindows(x11->disp, app->wd.self);