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
45 #include "gmx_fatal.h"
50 #include "gromacs/fileio/confio.h"
51 #include "gromacs/fileio/tpxio.h"
63 static void dump_it(t_manager *man)
67 ps = ps_open("view.ps", 0, 0, man->molw->wd.width, man->molw->wd.height);
72 static void done_gmx(t_x11 *x11, t_gmx *gmx)
74 done_logo(x11, gmx->logo);
75 done_pd(x11, gmx->pd);
76 done_man(x11, gmx->man);
78 x11->UnRegisterCallback(x11, gmx->wd->self);
81 static void move_gmx(t_x11 *x11, t_gmx *gmx, int width, int height,
86 fprintf(stderr, "Move gmx %dx%d\n", width, height);
88 y0 = XTextHeight(x11->font);
92 XResizeWindow(x11->disp, gmx->pd->wd.self, width, y0);
95 XMoveWindow(x11->disp, gmx->man->wd.self, 0, y0+1);
96 XResizeWindow(x11->disp, gmx->man->wd.self, width, height-y0-1);
98 wl = gmx->logo->wd.width;
99 hl = gmx->logo->wd.height;
100 XMoveWindow(x11->disp, gmx->logo->wd.self, (width-wl)/2, (height-y0-hl)/2);
103 static bool HandleClient(t_x11 *x11, int ID, t_gmx *gmx)
113 write_gmx(x11, gmx, IDDODUMP);
116 if (gmx->man->bAnimate)
118 hide_but(x11, gmx->man->vbox);
121 if (gmx->man->bAnimate)
123 show_but(x11, gmx->man->vbox);
129 ShowDlg(gmx->dlgs[edExport]);
132 write_sto_conf(gmx->confout, *gmx->man->top.name,
133 &(gmx->man->top.atoms),
134 gmx->man->x, NULL, gmx->man->molw->ePBC, gmx->man->box);
137 show_mb(gmx, emQuit);
145 edit_file("topol.gmx");
148 edit_file("confin.gmx");
151 edit_file("mdparin.gmx");
158 ShowDlg(gmx->dlgs[edFilter]);
162 do_filter(x11, gmx->man, gmx->filter);
165 check_pd_item(pd, IDANIMATE, toggle_animate(x11, gmx->man));
168 no_labels(x11, gmx->man);
171 reset_view(gmx->man->view);
172 ExposeWin(x11->disp, gmx->man->molw->wd.self);
175 show_mb(gmx, emNotImplemented);
178 ShowDlg(gmx->dlgs[edBonds]);
181 set_bond_type(x11, gmx->man->molw, eBThin);
184 set_bond_type(x11, gmx->man->molw, eBFat);
187 set_bond_type(x11, gmx->man->molw, eBVeryFat);
190 set_bond_type(x11, gmx->man->molw, eBSpheres);
193 set_box_type(x11, gmx->man->molw, esbNone);
196 set_box_type(x11, gmx->man->molw, esbRect);
199 set_box_type(x11, gmx->man->molw, esbTri);
202 set_box_type(x11, gmx->man->molw, esbTrunc);
213 show_mb(gmx, emNotImplemented);
218 show_mb(gmx, emHelp);
221 show_logo(x11, gmx->logo);
230 static bool MainCallBack(t_x11 *x11, XEvent *event, Window w, void *data)
233 int nsel, width, height;
241 hide_pd(x11, gmx->pd);
243 case ConfigureNotify:
244 width = event->xconfigure.width;
245 height = event->xconfigure.height;
246 if ((width != gmx->wd->width) || (height != gmx->wd->height))
248 move_gmx(x11, gmx, width, height, true);
252 hide_pd(x11, gmx->pd);
253 nsel = event->xclient.data.l[0];
254 result = HandleClient(x11, nsel, gmx);
262 static t_mentry FileMenu[] = {
263 { 0, IDEXPORT, false, "Export..." },
264 { 0, IDDUMPWIN, false, "Print" },
265 { 0, IDQUIT, false, "Quit" }
268 static t_mentry DispMenu[] = {
269 { 0, IDFILTER, false, "Filter..." },
270 { 0, IDANIMATE, false, "Animate" },
271 { 0, IDLABELSOFF, false, "Labels Off"},
272 { 0, IDRESETVIEW, false, "Reset View"},
273 { 0, IDBONDOPTS, false, "Options..."}
276 static t_mentry HelpMenu[] = {
277 { 0, IDHELP, false, "Help" },
278 { 0, IDABOUT, false, "About Gromacs..." }
281 static t_mentry *gmx_pd[] = { FileMenu, DispMenu, HelpMenu };
283 #define MSIZE asize(gmx_pd)
285 static int gmx_pd_size[MSIZE] = {
286 asize(FileMenu), asize(DispMenu), asize(HelpMenu)
289 static const char *MenuTitle[MSIZE] = {
290 "File", "Display", "Help"
293 static void init_gmx(t_x11 *x11, char *program, int nfile, t_filenm fnm[],
294 const output_env_t oenv)
300 int natom, natom_trx;
311 ePBC = read_tpx_top(ftp2fn(efTPX, nfile, fnm),
312 NULL, box, &natom, NULL, NULL, NULL, &top);
314 read_first_frame(oenv, &status, ftp2fn(efTRX, nfile, fnm), &fr, TRX_DONT_SKIP);
316 natom_trx = fr.natoms;
318 /* Creates a simple window */
319 w0 = DisplayWidth(x11->disp, x11->screen)-132;
320 h0 = DisplayHeight(x11->disp, x11->screen)-140;
322 InitWin(gmx->wd, 0, 0, w0, h0, 3, quote);
323 gmx->wd->self = XCreateSimpleWindow(x11->disp, x11->root,
324 gmx->wd->x, gmx->wd->y,
325 gmx->wd->width, gmx->wd->height,
326 gmx->wd->bwidth, WHITE, BLACK);
327 pm = XCreatePixmapFromBitmapData(x11->disp, x11->root,
328 (char *)gromacs_bits, gromacs_width,
331 hints.flags = PMinSize;
332 hints.min_width = 2*EWIDTH+40;
333 hints.min_height = EHEIGHT+LDHEIGHT+LEGHEIGHT+40;
334 XSetStandardProperties(x11->disp, gmx->wd->self, gmx->wd->text, program,
335 pm, NULL, 0, &hints);
337 x11->RegisterCallback(x11, gmx->wd->self, x11->root, MainCallBack, gmx);
338 x11->SetInputMask(x11, gmx->wd->self,
339 ButtonPressMask | ButtonReleaseMask |
340 OwnerGrabButtonMask | ExposureMask |
341 StructureNotifyMask);
343 /* The order of creating windows is important here! */
345 gmx->man = init_man(x11, gmx->wd->self, 0, 0, 1, 1, WHITE, BLACK, ePBC, box, oenv);
346 gmx->logo = init_logo(x11, gmx->wd->self, false);
348 /* Now put all windows in the proper place */
349 move_gmx(x11, gmx, w0, h0, false);
351 XMapWindow(x11->disp, gmx->wd->self);
352 map_man(x11, gmx->man);
355 gmx->pd = init_pd(x11, gmx->wd->self, gmx->wd->width,
357 MSIZE, gmx_pd_size, gmx_pd, MenuTitle);
359 /* Dialogs & Filters */
361 gmx->filter = init_filter(&(top.atoms), ftp2fn_null(efNDX, nfile, fnm),
366 /* Now do file shit */
367 set_file(x11, gmx->man, ftp2fn(efTRX, nfile, fnm), ftp2fn(efTPX, nfile, fnm));
369 ShowDlg(gmx->dlgs[edFilter]);
373 int gmx_view(int argc, char *argv[])
375 const char *desc[] = {
376 "[TT]view[tt] is the GROMACS trajectory viewer. This program reads a",
377 "trajectory file, a run input file and an index file and plots a",
378 "3D structure of your molecule on your standard X Window",
379 "screen. No need for a high end graphics workstation, it even",
380 "works on Monochrome screens.[PAR]",
381 "The following features have been implemented:",
382 "3D view, rotation, translation and scaling of your molecule(s),",
383 "labels on atoms, animation of trajectories,",
384 "hardcopy in PostScript format, user defined atom-filters",
385 "runs on MIT-X (real X), open windows and motif,",
386 "user friendly menus, option to remove periodicity, option to",
387 "show computational box.[PAR]",
388 "Some of the more common X command line options can be used: ",
389 "[TT]-bg[tt], [TT]-fg[tt] change colors, [TT]-font fontname[tt] changes the font."
391 const char *bugs[] = {
392 "Balls option does not work",
393 "Some times dumps core without a good reason"
398 { efTRX, "-f", NULL, ffREAD },
399 { efTPX, NULL, NULL, ffREAD },
400 { efNDX, NULL, NULL, ffOPTRD }
402 #define NFILE asize(fnm)
404 if (parse_common_args(&argc, argv, PCA_CAN_TIME, NFILE, fnm,
405 0, NULL, asize(desc), desc, asize(bugs), bugs, &oenv))
408 fprintf(stderr, "Compiled without X-Windows - can not run viewer.\n");
412 if ((x11 = GetX11(&argc, argv)) == NULL)
414 fprintf(stderr, "Can't connect to X Server.\n"
415 "Check your DISPLAY environment variable\n");
419 init_gmx(x11, argv[0], NFILE, fnm, oenv);