2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
47 #include "gmx_fatal.h"
52 #include "gromacs/fileio/confio.h"
53 #include "gromacs/fileio/tpxio.h"
65 static void dump_it(t_manager *man)
69 ps = ps_open("view.ps", 0, 0, man->molw->wd.width, man->molw->wd.height);
74 static void done_gmx(t_x11 *x11, t_gmx *gmx)
76 done_logo(x11, gmx->logo);
77 done_pd(x11, gmx->pd);
78 done_man(x11, gmx->man);
80 x11->UnRegisterCallback(x11, gmx->wd->self);
83 static void move_gmx(t_x11 *x11, t_gmx *gmx, int width, int height,
88 fprintf(stderr, "Move gmx %dx%d\n", width, height);
90 y0 = XTextHeight(x11->font);
94 XResizeWindow(x11->disp, gmx->pd->wd.self, width, y0);
97 XMoveWindow(x11->disp, gmx->man->wd.self, 0, y0+1);
98 XResizeWindow(x11->disp, gmx->man->wd.self, width, height-y0-1);
100 wl = gmx->logo->wd.width;
101 hl = gmx->logo->wd.height;
102 XMoveWindow(x11->disp, gmx->logo->wd.self, (width-wl)/2, (height-y0-hl)/2);
105 static bool HandleClient(t_x11 *x11, int ID, t_gmx *gmx)
115 write_gmx(x11, gmx, IDDODUMP);
118 if (gmx->man->bAnimate)
120 hide_but(x11, gmx->man->vbox);
123 if (gmx->man->bAnimate)
125 show_but(x11, gmx->man->vbox);
131 ShowDlg(gmx->dlgs[edExport]);
134 write_sto_conf(gmx->confout, *gmx->man->top.name,
135 &(gmx->man->top.atoms),
136 gmx->man->x, NULL, gmx->man->molw->ePBC, gmx->man->box);
139 show_mb(gmx, emQuit);
147 edit_file("topol.gmx");
150 edit_file("confin.gmx");
153 edit_file("mdparin.gmx");
160 ShowDlg(gmx->dlgs[edFilter]);
164 do_filter(x11, gmx->man, gmx->filter);
167 check_pd_item(pd, IDANIMATE, toggle_animate(x11, gmx->man));
170 no_labels(x11, gmx->man);
173 reset_view(gmx->man->view);
174 ExposeWin(x11->disp, gmx->man->molw->wd.self);
177 show_mb(gmx, emNotImplemented);
180 ShowDlg(gmx->dlgs[edBonds]);
183 set_bond_type(x11, gmx->man->molw, eBThin);
186 set_bond_type(x11, gmx->man->molw, eBFat);
189 set_bond_type(x11, gmx->man->molw, eBVeryFat);
192 set_bond_type(x11, gmx->man->molw, eBSpheres);
195 set_box_type(x11, gmx->man->molw, esbNone);
198 set_box_type(x11, gmx->man->molw, esbRect);
201 set_box_type(x11, gmx->man->molw, esbTri);
204 set_box_type(x11, gmx->man->molw, esbTrunc);
215 show_mb(gmx, emNotImplemented);
220 show_mb(gmx, emHelp);
223 show_logo(x11, gmx->logo);
232 static bool MainCallBack(t_x11 *x11, XEvent *event, Window /*w*/, void *data)
235 int nsel, width, height;
243 hide_pd(x11, gmx->pd);
245 case ConfigureNotify:
246 width = event->xconfigure.width;
247 height = event->xconfigure.height;
248 if ((width != gmx->wd->width) || (height != gmx->wd->height))
250 move_gmx(x11, gmx, width, height, true);
254 hide_pd(x11, gmx->pd);
255 nsel = event->xclient.data.l[0];
256 result = HandleClient(x11, nsel, gmx);
264 static t_mentry FileMenu[] = {
265 { 0, IDEXPORT, false, "Export..." },
266 { 0, IDDUMPWIN, false, "Print" },
267 { 0, IDQUIT, false, "Quit" }
270 static t_mentry DispMenu[] = {
271 { 0, IDFILTER, false, "Filter..." },
272 { 0, IDANIMATE, false, "Animate" },
273 { 0, IDLABELSOFF, false, "Labels Off"},
274 { 0, IDRESETVIEW, false, "Reset View"},
275 { 0, IDBONDOPTS, false, "Options..."}
278 static t_mentry HelpMenu[] = {
279 { 0, IDHELP, false, "Help" },
280 { 0, IDABOUT, false, "About Gromacs..." }
283 static t_mentry *gmx_pd[] = { FileMenu, DispMenu, HelpMenu };
285 #define MSIZE asize(gmx_pd)
287 static int gmx_pd_size[MSIZE] = {
288 asize(FileMenu), asize(DispMenu), asize(HelpMenu)
291 static const char *MenuTitle[MSIZE] = {
292 "File", "Display", "Help"
295 static void init_gmx(t_x11 *x11, char *program, int nfile, t_filenm fnm[],
296 const output_env_t oenv)
302 int natom, natom_trx;
313 ePBC = read_tpx_top(ftp2fn(efTPX, nfile, fnm),
314 NULL, box, &natom, NULL, NULL, NULL, &top);
316 read_first_frame(oenv, &status, ftp2fn(efTRX, nfile, fnm), &fr, TRX_DONT_SKIP);
318 natom_trx = fr.natoms;
320 /* Creates a simple window */
321 w0 = DisplayWidth(x11->disp, x11->screen)-132;
322 h0 = DisplayHeight(x11->disp, x11->screen)-140;
324 InitWin(gmx->wd, 0, 0, w0, h0, 3, quote);
325 gmx->wd->self = XCreateSimpleWindow(x11->disp, x11->root,
326 gmx->wd->x, gmx->wd->y,
327 gmx->wd->width, gmx->wd->height,
328 gmx->wd->bwidth, WHITE, BLACK);
329 pm = XCreatePixmapFromBitmapData(x11->disp, x11->root,
330 (char *)gromacs_bits, gromacs_width,
333 hints.flags = PMinSize;
334 hints.min_width = 2*EWIDTH+40;
335 hints.min_height = EHEIGHT+LDHEIGHT+LEGHEIGHT+40;
336 XSetStandardProperties(x11->disp, gmx->wd->self, gmx->wd->text, program,
337 pm, NULL, 0, &hints);
339 x11->RegisterCallback(x11, gmx->wd->self, x11->root, MainCallBack, gmx);
340 x11->SetInputMask(x11, gmx->wd->self,
341 ButtonPressMask | ButtonReleaseMask |
342 OwnerGrabButtonMask | ExposureMask |
343 StructureNotifyMask);
345 /* The order of creating windows is important here! */
347 gmx->man = init_man(x11, gmx->wd->self, 0, 0, 1, 1, WHITE, BLACK, ePBC, box, oenv);
348 gmx->logo = init_logo(x11, gmx->wd->self, false);
350 /* Now put all windows in the proper place */
351 move_gmx(x11, gmx, w0, h0, false);
353 XMapWindow(x11->disp, gmx->wd->self);
354 map_man(x11, gmx->man);
357 gmx->pd = init_pd(x11, gmx->wd->self, gmx->wd->width,
359 MSIZE, gmx_pd_size, gmx_pd, MenuTitle);
361 /* Dialogs & Filters */
363 gmx->filter = init_filter(&(top.atoms), ftp2fn_null(efNDX, nfile, fnm),
368 /* Now do file shit */
369 set_file(x11, gmx->man, ftp2fn(efTRX, nfile, fnm), ftp2fn(efTPX, nfile, fnm));
371 ShowDlg(gmx->dlgs[edFilter]);
375 int gmx_view(int argc, char *argv[])
377 const char *desc[] = {
378 "[THISMODULE] is the GROMACS trajectory viewer. This program reads a",
379 "trajectory file, a run input file and an index file and plots a",
380 "3D structure of your molecule on your standard X Window",
381 "screen. No need for a high end graphics workstation, it even",
382 "works on Monochrome screens.[PAR]",
383 "The following features have been implemented:",
384 "3D view, rotation, translation and scaling of your molecule(s),",
385 "labels on atoms, animation of trajectories,",
386 "hardcopy in PostScript format, user defined atom-filters",
387 "runs on MIT-X (real X), open windows and motif,",
388 "user friendly menus, option to remove periodicity, option to",
389 "show computational box.[PAR]",
390 "Some of the more common X command line options can be used: ",
391 "[TT]-bg[tt], [TT]-fg[tt] change colors, [TT]-font fontname[tt] changes the font."
393 const char *bugs[] = {
394 "Balls option does not work",
395 "Some times dumps core without a good reason"
400 { efTRX, "-f", NULL, ffREAD },
401 { efTPX, NULL, NULL, ffREAD },
402 { efNDX, NULL, NULL, ffOPTRD }
404 #define NFILE asize(fnm)
406 if (parse_common_args(&argc, argv, PCA_CAN_TIME, NFILE, fnm,
407 0, NULL, asize(desc), desc, asize(bugs), bugs, &oenv))
410 fprintf(stderr, "Compiled without X-Windows - can not run viewer.\n");
414 if ((x11 = GetX11(&argc, argv)) == NULL)
416 fprintf(stderr, "Can't connect to X Server.\n"
417 "Check your DISPLAY environment variable\n");
421 init_gmx(x11, argv[0], NFILE, fnm, oenv);