4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
27 * Great Red Oystrich Makes All Chemists Sane
29 static char *SRCID_ngmx_c = "$Id$";
51 /* Forward declarations: I Don't want all that init shit here */
52 void init_gmx(t_x11 *x11,char *program,int nfile,t_filenm fnm[]);
54 int EventSignaller(t_manager *man);
56 static void dump_xw(char *dispname,Window w,char *fn)
60 sprintf(comm,"xwd -id %d -display %s > %s",(int)w,dispname,fn);
64 static void dump_it(t_manager *man)
68 ps=ps_open("ngmx.ps",0,0,man->molw->wd.width,man->molw->wd.height);
73 static void done_gmx(t_x11 *x11,t_gmx *gmx)
75 done_logo(x11,gmx->logo);
77 done_man(x11,gmx->man);
79 x11->UnRegisterCallback(x11,gmx->wd->self);
82 static void move_gmx(t_x11 *x11,t_gmx *gmx,int width,int height,
87 fprintf(stderr,"Move gmx %dx%d\n",width,height);
89 y0=XTextHeight(x11->font);
92 XResizeWindow(x11->disp,gmx->pd->wd.self,width,y0);
94 XMoveWindow(x11->disp,gmx->man->wd.self,0,y0+1);
95 XResizeWindow(x11->disp,gmx->man->wd.self,width,height-y0-1);
97 wl=gmx->logo->wd.width;
98 hl=gmx->logo->wd.height;
99 XMoveWindow(x11->disp,gmx->logo->wd.self,(width-wl)/2,(height-y0-hl)/2);
102 static bool HandleClient(t_x11 *x11,int ID,t_gmx *gmx)
111 write_gmx(x11,gmx,IDDODUMP);
114 if (gmx->man->bAnimate)
115 hide_but(x11,gmx->man->vbox);
117 if (gmx->man->bAnimate)
118 show_but(x11,gmx->man->vbox);
123 ShowDlg(gmx->dlgs[edExport]);
126 write_sto_conf(gmx->confout,*gmx->man->top.name,
127 &(gmx->man->top.atoms),
128 gmx->man->x,NULL,gmx->man->box);
139 edit_file("topol.gmx");
142 edit_file("confin.gmx");
145 edit_file("mdparin.gmx");
151 ShowDlg(gmx->dlgs[edFilter]);
154 do_filter(x11,gmx->man,gmx->filter);
157 check_pd_item(pd,IDANIMATE,toggle_animate(x11,gmx->man));
160 no_labels(x11,gmx->man);
163 reset_view(gmx->man->view);
164 ExposeWin(x11->disp,gmx->man->molw->wd.self);
167 show_mb(gmx,emNotImplemented);
170 ShowDlg(gmx->dlgs[edBonds]);
173 set_bond_type(x11,gmx->man->molw,eBThin);
176 set_bond_type(x11,gmx->man->molw,eBFat);
179 set_bond_type(x11,gmx->man->molw,eBVeryFat);
182 set_bond_type(x11,gmx->man->molw,eBSpheres);
185 set_box_type(x11,gmx->man->molw,esbNone);
188 set_box_type(x11,gmx->man->molw,esbRect);
191 set_box_type(x11,gmx->man->molw,esbTri);
194 set_box_type(x11,gmx->man->molw,esbTrunc);
205 show_mb(gmx,emNotImplemented);
213 show_logo(x11,gmx->logo);
222 static bool MainCallBack(t_x11 *x11,XEvent *event, Window w, void *data)
225 int nsel,width,height;
230 switch(event->type) {
232 hide_pd(x11,gmx->pd);
234 case ConfigureNotify:
235 width=event->xconfigure.width;
236 height=event->xconfigure.height;
237 if ((width!=gmx->wd->width) || (height!=gmx->wd->height))
238 move_gmx(x11,gmx,width,height,TRUE);
241 hide_pd(x11,gmx->pd);
242 nsel=event->xclient.data.l[0];
243 result = HandleClient(x11,nsel,gmx);
251 int main(int argc, char *argv[])
253 static char *desc[] = {
254 "ngmx is the Gromacs trajectory viewer. This program reads a",
255 "trajectory file, a run input file and an index file and plots a",
256 "3D structure of your molecule on your standard X Window",
257 "screen. No need for a high end graphics workstation, it even",
258 "works on Monochrome screens.[PAR]",
259 "The following features have been implemented:",
260 "3D view, rotation, translation and scaling of your molecule(s),",
261 "labels on atoms, animation of trajectories,",
262 "hardcopy in PostScript format, user defined atom-filters",
263 "runs on MIT-X (real X), open windows and motif,",
264 "user friendly menus, option to remove periodicity, option to",
265 "show computational box.[PAR]",
266 "Some of the more common X command line options can be used:[BR]",
267 "-bg, -fg change colors, -font fontname, changes the font."
269 static char *bugs[] = {
270 "Balls option does not work",
271 "Some times dumps core without a good reason"
276 { efTRX, "-f", NULL, ffREAD },
277 { efTPX, NULL, NULL, ffREAD },
278 { efNDX, NULL, NULL, ffOPTRD }
280 #define NFILE asize(fnm)
282 CopyRight(stdout,argv[0]);
283 parse_common_args(&argc,argv,PCA_CAN_TIME,FALSE,NFILE,fnm,
284 0,NULL,asize(desc),desc,asize(bugs),bugs);
286 if ((x11=GetX11(&argc,argv))==NULL) {
287 fprintf(stderr,"Can't connect to X Server.\n"
288 "Check your DISPLAY environment variable\n");
291 init_gmx(x11,argv[0],NFILE,fnm);
301 static t_mentry FileMenu[] = {
302 { 0, IDEXPORT, FALSE, "Export..." },
303 { 0, IDDUMPWIN, FALSE, "Print" },
304 { 0, IDQUIT, FALSE, "Quit" }
307 static t_mentry DispMenu[] = {
308 { 0, IDFILTER, FALSE, "Filter..." },
309 { 0, IDANIMATE, FALSE, "Animate" },
310 { 0, IDLABELSOFF, FALSE, "Labels Off"},
311 { 0, IDRESETVIEW, FALSE, "Reset View"},
312 { 0, IDBONDOPTS, FALSE, "Options..."}
315 static t_mentry HelpMenu[] = {
316 { 0, IDHELP, FALSE, "Help" },
317 { 0, IDABOUT, FALSE, "About Gromacs..." }
320 static t_mentry *gmx_pd[] = { FileMenu, DispMenu, HelpMenu };
322 #define MSIZE asize(gmx_pd)
324 static int gmx_pd_size[MSIZE] = {
325 asize(FileMenu), asize(DispMenu), asize(HelpMenu)
328 static char *MenuTitle[MSIZE] = {
329 "File", "Display", "Help"
332 void init_gmx(t_x11 *x11,char *program,int nfile,t_filenm fnm[])
338 int step,natom,nre,natom_trx;
348 read_tpx(ftp2fn(efTPX,nfile,fnm),&step,&t,&lambda,NULL,box,
349 &natom,NULL,NULL,NULL,&top);
351 read_first_frame(&status,ftp2fn(efTRX,nfile,fnm),&fr,TRX_DONT_SKIP);
353 natom_trx = fr.natoms;
355 /* Creates a simple window */
356 w0=DisplayWidth(x11->disp,x11->screen)-132;
357 h0=DisplayHeight(x11->disp,x11->screen)-140;
358 InitWin(gmx->wd,0,0,w0,h0,3,bromacs());
359 gmx->wd->self=XCreateSimpleWindow(x11->disp,x11->root,
360 gmx->wd->x, gmx->wd->y,
361 gmx->wd->width,gmx->wd->height,
362 gmx->wd->bwidth,WHITE,BLACK);
363 pm=XCreatePixmapFromBitmapData(x11->disp,x11->root,
364 (char *)gromacs_bits,gromacs_width,
367 hints.flags=PMinSize;
368 hints.min_width=2*EWIDTH+40;
369 hints.min_height=EHEIGHT+LDHEIGHT+LEGHEIGHT+40;
370 XSetStandardProperties(x11->disp,gmx->wd->self,gmx->wd->text,program,
373 x11->RegisterCallback(x11,gmx->wd->self,x11->root,MainCallBack,gmx);
374 x11->SetInputMask(x11,gmx->wd->self,
375 ButtonPressMask | ButtonReleaseMask |
376 OwnerGrabButtonMask | ExposureMask |
377 StructureNotifyMask);
379 /* The order of creating windows is important here! */
381 gmx->man = init_man(x11,gmx->wd->self,0,0,1,1,WHITE,BLACK,box);
382 gmx->logo = init_logo(x11,gmx->wd->self);
384 /* Now put all windows in the proper place */
385 move_gmx(x11,gmx,w0,h0,FALSE);
387 XMapWindow(x11->disp,gmx->wd->self);
388 map_man(x11,gmx->man);
391 gmx->pd=init_pd(x11,gmx->wd->self,gmx->wd->width,
392 XTextHeight(x11->font),x11->fg,x11->bg,
393 MSIZE,gmx_pd_size,gmx_pd,MenuTitle);
395 /* Dialogs & Filters */
397 gmx->filter=init_filter(&(top.atoms),ftp2fn_null(efNDX,nfile,fnm),
402 /* Now do file shit */
403 set_file(x11,gmx->man,ftp2fn(efTRX,nfile,fnm),ftp2fn(efTPX,nfile,fnm));
405 /*show_logo(x11,gmx->logo);*/
407 ShowDlg(gmx->dlgs[edFilter]);