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,2014,2015,2017,2019,2020, 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 "gromacs/commandline/pargs.h"
48 #include "gromacs/fileio/confio.h"
49 #include "gromacs/fileio/oenv.h"
50 #include "gromacs/fileio/tpxio.h"
51 #include "gromacs/trajectory/trajectoryframe.h"
52 #include "gromacs/utility/arraysize.h"
53 #include "gromacs/utility/coolstuff.h"
54 #include "gromacs/utility/fatalerror.h"
55 #include "gromacs/utility/smalloc.h"
59 # include "gromacs/fileio/writeps.h"
63 # include "gromacs.bm"
68 static void dump_it(t_manager* man)
72 ps = ps_open("view.ps", 0, 0, man->molw->wd.width, man->molw->wd.height);
73 ps_draw_mol(&ps, man);
77 static void done_gmx(t_x11* x11, t_gmx* gmx)
79 done_logo(x11, gmx->logo);
80 done_pd(x11, gmx->pd);
81 done_man(x11, gmx->man);
83 x11->UnRegisterCallback(x11, gmx->wd->self);
86 static void move_gmx(t_x11* x11, t_gmx* gmx, int width, int height, bool bSizePD)
90 std::fprintf(stderr, "Move gmx %dx%d\n", width, height);
92 y0 = XTextHeight(x11->font);
96 XResizeWindow(x11->disp, gmx->pd->wd.self, width, y0);
99 XMoveWindow(x11->disp, gmx->man->wd.self, 0, y0 + 1);
100 XResizeWindow(x11->disp, gmx->man->wd.self, width, height - y0 - 1);
102 wl = gmx->logo->wd.width;
103 hl = gmx->logo->wd.height;
104 XMoveWindow(x11->disp, gmx->logo->wd.self, (width - wl) / 2, (height - y0 - hl) / 2);
107 static bool HandleClient(t_x11* x11, int ID, t_gmx* gmx)
116 case IDDUMPWIN: write_gmx(x11, gmx, IDDODUMP); break;
118 if (gmx->man->bAnimate)
120 hide_but(x11, gmx->man->vbox);
123 if (gmx->man->bAnimate)
125 show_but(x11, gmx->man->vbox);
130 case IDEXPORT: ShowDlg(gmx->dlgs[edExport]); break;
132 write_sto_conf(gmx->confout,
134 &(gmx->man->top.atoms),
137 gmx->man->molw->pbcType,
140 case IDQUIT: show_mb(gmx, emQuit); break;
141 case IDTERM: done_gmx(x11, gmx); return true;
144 case IDEDITTOP: edit_file("topol.gmx"); break;
145 case IDEDITCOORDS: edit_file("confin.gmx"); break;
146 case IDEDITPARAMS: edit_file("mdparin.gmx"); break;
152 ShowDlg(gmx->dlgs[edFilter]);
155 case IDDOFILTER: do_filter(x11, gmx->man, gmx->filter); break;
156 case IDANIMATE: check_pd_item(pd, IDANIMATE, toggle_animate(x11, gmx->man)); break;
157 case IDLABELSOFF: no_labels(x11, gmx->man); break;
159 reset_view(gmx->man->view);
160 ExposeWin(x11->disp, gmx->man->molw->wd.self);
162 case IDPHOTO: show_mb(gmx, emNotImplemented); break;
163 case IDBONDOPTS: ShowDlg(gmx->dlgs[edBonds]); break;
164 case IDTHIN: set_bond_type(x11, gmx->man->molw, eBThin); break;
165 case IDFAT: set_bond_type(x11, gmx->man->molw, eBFat); break;
166 case IDVERYFAT: set_bond_type(x11, gmx->man->molw, eBVeryFat); break;
167 case IDBALLS: set_bond_type(x11, gmx->man->molw, eBSpheres); break;
168 case IDNOBOX: set_box_type(x11, gmx->man->molw, esbNone); break;
169 case IDRECTBOX: set_box_type(x11, gmx->man->molw, esbRect); break;
170 case IDTRIBOX: set_box_type(x11, gmx->man->molw, esbTri); break;
171 case IDTOBOX: set_box_type(x11, gmx->man->molw, esbTrunc); break;
180 case IDCORR: show_mb(gmx, emNotImplemented); break;
183 case IDHELP: show_mb(gmx, emHelp); break;
184 case IDABOUT: show_logo(x11, gmx->logo); break;
191 static bool MainCallBack(t_x11* x11, XEvent* event, Window /*w*/, void* data)
194 int nsel, width, height;
201 case ButtonRelease: hide_pd(x11, gmx->pd); break;
202 case ConfigureNotify:
203 width = event->xconfigure.width;
204 height = event->xconfigure.height;
205 if ((width != gmx->wd->width) || (height != gmx->wd->height))
207 move_gmx(x11, gmx, width, height, true);
211 hide_pd(x11, gmx->pd);
212 nsel = event->xclient.data.l[0];
213 result = HandleClient(x11, nsel, gmx);
220 static t_mentry FileMenu[] = { { 0, IDEXPORT, false, "Export..." },
221 { 0, IDDUMPWIN, false, "Print" },
222 { 0, IDQUIT, false, "Quit" } };
224 static t_mentry DispMenu[] = { { 0, IDFILTER, false, "Filter..." },
225 { 0, IDANIMATE, false, "Animate" },
226 { 0, IDLABELSOFF, false, "Labels Off" },
227 { 0, IDRESETVIEW, false, "Reset View" },
228 { 0, IDBONDOPTS, false, "Options..." } };
230 static t_mentry HelpMenu[] = { { 0, IDHELP, false, "Help" },
231 { 0, IDABOUT, false, "About GROMACS..." } };
233 static t_mentry* gmx_pd[] = { FileMenu, DispMenu, HelpMenu };
235 # define MSIZE asize(gmx_pd)
237 static int gmx_pd_size[MSIZE] = { asize(FileMenu), asize(DispMenu), asize(HelpMenu) };
239 static const char* MenuTitle[MSIZE] = { "File", "Display", "Help" };
241 static void init_gmx(t_x11* x11, char* program, int nfile, t_filenm fnm[], gmx_output_env_t* oenv)
247 int natom, natom_trx;
257 pbcType = read_tpx_top(ftp2fn(efTPR, nfile, fnm), nullptr, box, &natom, nullptr, nullptr, &top);
259 read_first_frame(oenv, &status, ftp2fn(efTRX, nfile, fnm), &fr, TRX_DONT_SKIP);
261 natom_trx = fr.natoms;
263 /* Creates a simple window */
264 w0 = DisplayWidth(x11->disp, x11->screen) - 132;
265 h0 = DisplayHeight(x11->disp, x11->screen) - 140;
266 InitWin(gmx->wd, 0, 0, w0, h0, 3, gmx::bromacs().c_str());
267 gmx->wd->self = XCreateSimpleWindow(
268 x11->disp, x11->root, gmx->wd->x, gmx->wd->y, gmx->wd->width, gmx->wd->height, gmx->wd->bwidth, WHITE, BLACK);
269 pm = XCreatePixmapFromBitmapData(
270 x11->disp, x11->root, (char*)gromacs_bits, gromacs_width, gromacs_height, WHITE, BLACK, 1);
271 hints.flags = PMinSize;
272 hints.min_width = 2 * EWIDTH + 40;
273 hints.min_height = EHEIGHT + LDHEIGHT + LEGHEIGHT + 40;
274 XSetStandardProperties(x11->disp, gmx->wd->self, gmx->wd->text, program, pm, nullptr, 0, &hints);
276 x11->RegisterCallback(x11, gmx->wd->self, x11->root, MainCallBack, gmx);
277 x11->SetInputMask(x11,
279 ButtonPressMask | ButtonReleaseMask | OwnerGrabButtonMask | ExposureMask
280 | StructureNotifyMask);
282 /* The order of creating windows is important here! */
284 gmx->man = init_man(x11, gmx->wd->self, 0, 0, 1, 1, WHITE, BLACK, pbcType, box, oenv);
285 gmx->logo = init_logo(x11, gmx->wd->self, false);
287 /* Now put all windows in the proper place */
288 move_gmx(x11, gmx, w0, h0, false);
290 XMapWindow(x11->disp, gmx->wd->self);
291 map_man(x11, gmx->man);
295 x11, gmx->wd->self, gmx->wd->width, x11->fg, x11->bg, MSIZE, gmx_pd_size, gmx_pd, MenuTitle);
297 /* Dialogs & Filters */
299 gmx->filter = init_filter(&(top.atoms), ftp2fn_null(efNDX, nfile, fnm), natom_trx);
303 /* Now do file operations */
304 set_file(x11, gmx->man, ftp2fn(efTRX, nfile, fnm), ftp2fn(efTPR, nfile, fnm));
306 ShowDlg(gmx->dlgs[edFilter]);
310 int gmx_view(int argc, char* argv[])
312 const char* desc[] = {
313 "[THISMODULE] is the GROMACS trajectory viewer. This program reads a",
314 "trajectory file, a run input file and an index file and plots a",
315 "3D structure of your molecule on your standard X Window",
316 "screen. No need for a high end graphics workstation, it even",
317 "works on Monochrome screens.[PAR]",
318 "The following features have been implemented:",
319 "3D view, rotation, translation and scaling of your molecule(s),",
320 "labels on atoms, animation of trajectories,",
321 "hardcopy in PostScript format, user defined atom-filters",
322 "runs on MIT-X (real X), open windows and motif,",
323 "user friendly menus, option to remove periodicity, option to",
324 "show computational box.[PAR]",
325 "Some of the more common X command line options can be used: ",
326 "[TT]-bg[tt], [TT]-fg[tt] change colors, [TT]-font fontname[tt] changes the font."
328 const char* bugs[] = { "Balls option does not work",
329 "Some times dumps core without a good reason" };
331 gmx_output_env_t* oenv;
332 t_filenm fnm[] = { { efTRX, "-f", nullptr, ffREAD },
333 { efTPR, nullptr, nullptr, ffREAD },
334 { efNDX, nullptr, nullptr, ffOPTRD } };
335 #define NFILE asize(fnm)
337 if (parse_common_args(
338 &argc, argv, PCA_CAN_TIME, NFILE, fnm, 0, nullptr, asize(desc), desc, asize(bugs), bugs, &oenv))
341 std::fprintf(stderr, "Compiled without X-Windows - can not run viewer.\n");
345 if ((x11 = GetX11(&argc, argv)) == nullptr)
348 "Can't connect to X Server.\n"
349 "Check your DISPLAY environment variable\n");
353 init_gmx(x11, argv[0], NFILE, fnm, oenv);