4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2004, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * For more info, check our website at http://www.gromacs.org
34 * Gyas ROwers Mature At Cryogenic Speed
56 /* Forward declarations: I Don't want all that init shit here */
57 void init_gmx(t_x11
*x11
,char *program
,int nfile
,t_filenm fnm
[]);
59 int EventSignaller(t_manager
*man
);
61 static void dump_xw(char *dispname
,Window w
,char *fn
)
65 sprintf(comm
,"xwd -id %d -display %s > %s",(int)w
,dispname
,fn
);
69 static void dump_it(t_manager
*man
)
73 ps
=ps_open("ngmx.ps",0,0,man
->molw
->wd
.width
,man
->molw
->wd
.height
);
78 static void done_gmx(t_x11
*x11
,t_gmx
*gmx
)
80 done_logo(x11
,gmx
->logo
);
82 done_man(x11
,gmx
->man
);
84 x11
->UnRegisterCallback(x11
,gmx
->wd
->self
);
87 static void move_gmx(t_x11
*x11
,t_gmx
*gmx
,int width
,int height
,
92 fprintf(stderr
,"Move gmx %dx%d\n",width
,height
);
94 y0
=XTextHeight(x11
->font
);
97 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 write_gmx(x11
,gmx
,IDDODUMP
);
119 if (gmx
->man
->bAnimate
)
120 hide_but(x11
,gmx
->man
->vbox
);
122 if (gmx
->man
->bAnimate
)
123 show_but(x11
,gmx
->man
->vbox
);
128 ShowDlg(gmx
->dlgs
[edExport
]);
131 write_sto_conf(gmx
->confout
,*gmx
->man
->top
.name
,
132 &(gmx
->man
->top
.atoms
),
133 gmx
->man
->x
,NULL
,gmx
->man
->box
);
144 edit_file("topol.gmx");
147 edit_file("confin.gmx");
150 edit_file("mdparin.gmx");
156 ShowDlg(gmx
->dlgs
[edFilter
]);
159 do_filter(x11
,gmx
->man
,gmx
->filter
);
162 check_pd_item(pd
,IDANIMATE
,toggle_animate(x11
,gmx
->man
));
165 no_labels(x11
,gmx
->man
);
168 reset_view(gmx
->man
->view
);
169 ExposeWin(x11
->disp
,gmx
->man
->molw
->wd
.self
);
172 show_mb(gmx
,emNotImplemented
);
175 ShowDlg(gmx
->dlgs
[edBonds
]);
178 set_bond_type(x11
,gmx
->man
->molw
,eBThin
);
181 set_bond_type(x11
,gmx
->man
->molw
,eBFat
);
184 set_bond_type(x11
,gmx
->man
->molw
,eBVeryFat
);
187 set_bond_type(x11
,gmx
->man
->molw
,eBSpheres
);
190 set_box_type(x11
,gmx
->man
->molw
,esbNone
);
193 set_box_type(x11
,gmx
->man
->molw
,esbRect
);
196 set_box_type(x11
,gmx
->man
->molw
,esbTri
);
199 set_box_type(x11
,gmx
->man
->molw
,esbTrunc
);
210 show_mb(gmx
,emNotImplemented
);
218 show_logo(x11
,gmx
->logo
);
227 static bool MainCallBack(t_x11
*x11
,XEvent
*event
, Window w
, void *data
)
230 int nsel
,width
,height
;
235 switch(event
->type
) {
237 hide_pd(x11
,gmx
->pd
);
239 case ConfigureNotify
:
240 width
=event
->xconfigure
.width
;
241 height
=event
->xconfigure
.height
;
242 if ((width
!=gmx
->wd
->width
) || (height
!=gmx
->wd
->height
))
243 move_gmx(x11
,gmx
,width
,height
,TRUE
);
246 hide_pd(x11
,gmx
->pd
);
247 nsel
=event
->xclient
.data
.l
[0];
248 result
= HandleClient(x11
,nsel
,gmx
);
256 int main(int argc
, char *argv
[])
258 static char *desc
[] = {
259 "ngmx is the Gromacs trajectory viewer. This program reads a",
260 "trajectory file, a run input file and an index file and plots a",
261 "3D structure of your molecule on your standard X Window",
262 "screen. No need for a high end graphics workstation, it even",
263 "works on Monochrome screens.[PAR]",
264 "The following features have been implemented:",
265 "3D view, rotation, translation and scaling of your molecule(s),",
266 "labels on atoms, animation of trajectories,",
267 "hardcopy in PostScript format, user defined atom-filters",
268 "runs on MIT-X (real X), open windows and motif,",
269 "user friendly menus, option to remove periodicity, option to",
270 "show computational box.[PAR]",
271 "Some of the more common X command line options can be used:[BR]",
272 "-bg, -fg change colors, -font fontname, changes the font."
274 static char *bugs
[] = {
275 "Balls option does not work",
276 "Some times dumps core without a good reason"
281 { efTRX
, "-f", NULL
, ffREAD
},
282 { efTPX
, NULL
, NULL
, ffREAD
},
283 { efNDX
, NULL
, NULL
, ffOPTRD
}
285 #define NFILE asize(fnm)
287 CopyRight(stdout
,argv
[0]);
288 parse_common_args(&argc
,argv
,PCA_CAN_TIME
,NFILE
,fnm
,
289 0,NULL
,asize(desc
),desc
,asize(bugs
),bugs
);
291 if ((x11
=GetX11(&argc
,argv
))==NULL
) {
292 fprintf(stderr
,"Can't connect to X Server.\n"
293 "Check your DISPLAY environment variable\n");
296 init_gmx(x11
,argv
[0],NFILE
,fnm
);
306 static t_mentry FileMenu
[] = {
307 { 0, IDEXPORT
, FALSE
, "Export..." },
308 { 0, IDDUMPWIN
, FALSE
, "Print" },
309 { 0, IDQUIT
, FALSE
, "Quit" }
312 static t_mentry DispMenu
[] = {
313 { 0, IDFILTER
, FALSE
, "Filter..." },
314 { 0, IDANIMATE
, FALSE
, "Animate" },
315 { 0, IDLABELSOFF
, FALSE
, "Labels Off"},
316 { 0, IDRESETVIEW
, FALSE
, "Reset View"},
317 { 0, IDBONDOPTS
, FALSE
, "Options..."}
320 static t_mentry HelpMenu
[] = {
321 { 0, IDHELP
, FALSE
, "Help" },
322 { 0, IDABOUT
, FALSE
, "About Gromacs..." }
325 static t_mentry
*gmx_pd
[] = { FileMenu
, DispMenu
, HelpMenu
};
327 #define MSIZE asize(gmx_pd)
329 static int gmx_pd_size
[MSIZE
] = {
330 asize(FileMenu
), asize(DispMenu
), asize(HelpMenu
)
333 static char *MenuTitle
[MSIZE
] = {
334 "File", "Display", "Help"
337 void init_gmx(t_x11
*x11
,char *program
,int nfile
,t_filenm fnm
[])
343 int step
,natom
,nre
,natom_trx
;
354 read_tpx(ftp2fn(efTPX
,nfile
,fnm
),&step
,&t
,&lambda
,NULL
,box
,
355 &natom
,NULL
,NULL
,NULL
,&top
);
357 read_first_frame(&status
,ftp2fn(efTRX
,nfile
,fnm
),&fr
,TRX_DONT_SKIP
);
359 natom_trx
= fr
.natoms
;
361 /* Creates a simple window */
362 w0
=DisplayWidth(x11
->disp
,x11
->screen
)-132;
363 h0
=DisplayHeight(x11
->disp
,x11
->screen
)-140;
364 InitWin(gmx
->wd
,0,0,w0
,h0
,3,bromacs(quote
,255));
365 gmx
->wd
->self
=XCreateSimpleWindow(x11
->disp
,x11
->root
,
366 gmx
->wd
->x
, gmx
->wd
->y
,
367 gmx
->wd
->width
,gmx
->wd
->height
,
368 gmx
->wd
->bwidth
,WHITE
,BLACK
);
369 pm
=XCreatePixmapFromBitmapData(x11
->disp
,x11
->root
,
370 (char *)gromacs_bits
,gromacs_width
,
373 hints
.flags
=PMinSize
;
374 hints
.min_width
=2*EWIDTH
+40;
375 hints
.min_height
=EHEIGHT
+LDHEIGHT
+LEGHEIGHT
+40;
376 XSetStandardProperties(x11
->disp
,gmx
->wd
->self
,gmx
->wd
->text
,program
,
379 x11
->RegisterCallback(x11
,gmx
->wd
->self
,x11
->root
,MainCallBack
,gmx
);
380 x11
->SetInputMask(x11
,gmx
->wd
->self
,
381 ButtonPressMask
| ButtonReleaseMask
|
382 OwnerGrabButtonMask
| ExposureMask
|
383 StructureNotifyMask
);
385 /* The order of creating windows is important here! */
387 gmx
->man
= init_man(x11
,gmx
->wd
->self
,0,0,1,1,WHITE
,BLACK
,box
);
388 gmx
->logo
= init_logo(x11
,gmx
->wd
->self
);
390 /* Now put all windows in the proper place */
391 move_gmx(x11
,gmx
,w0
,h0
,FALSE
);
393 XMapWindow(x11
->disp
,gmx
->wd
->self
);
394 map_man(x11
,gmx
->man
);
397 gmx
->pd
=init_pd(x11
,gmx
->wd
->self
,gmx
->wd
->width
,
398 XTextHeight(x11
->font
),x11
->fg
,x11
->bg
,
399 MSIZE
,gmx_pd_size
,gmx_pd
,MenuTitle
);
401 /* Dialogs & Filters */
403 gmx
->filter
=init_filter(&(top
.atoms
),ftp2fn_null(efNDX
,nfile
,fnm
),
408 /* Now do file shit */
409 set_file(x11
,gmx
->man
,ftp2fn(efTRX
,nfile
,fnm
),ftp2fn(efTPX
,nfile
,fnm
));
411 /*show_logo(x11,gmx->logo);*/
413 ShowDlg(gmx
->dlgs
[edFilter
]);