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 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
48 #include "gmx_fatal.h"
62 /* Forward declarations: I Don't want all that init shit here */
63 void init_gmx(t_x11
*x11
,char *program
,int nfile
,t_filenm fnm
[],
64 const output_env_t oenv
);
66 static void dump_xw(char *dispname
,Window w
,char *fn
)
71 sprintf(comm
,"xwd -id %d -display %s > %s",(int)w
,dispname
,fn
);
74 printf("Warning-- No calls to system(3) supported on this platform.");
75 printf("Warning-- Skipping execution of 'system(\"%s\")'.", buf
);
81 static void dump_it(t_manager
*man
)
85 ps
=ps_open("ngmx.ps",0,0,man
->molw
->wd
.width
,man
->molw
->wd
.height
);
90 static void done_gmx(t_x11
*x11
,t_gmx
*gmx
)
92 done_logo(x11
,gmx
->logo
);
94 done_man(x11
,gmx
->man
);
96 x11
->UnRegisterCallback(x11
,gmx
->wd
->self
);
99 static void move_gmx(t_x11
*x11
,t_gmx
*gmx
,int width
,int height
,
104 fprintf(stderr
,"Move gmx %dx%d\n",width
,height
);
106 y0
=XTextHeight(x11
->font
);
109 XResizeWindow(x11
->disp
,gmx
->pd
->wd
.self
,width
,y0
);
111 XMoveWindow(x11
->disp
,gmx
->man
->wd
.self
,0,y0
+1);
112 XResizeWindow(x11
->disp
,gmx
->man
->wd
.self
,width
,height
-y0
-1);
114 wl
=gmx
->logo
->wd
.width
;
115 hl
=gmx
->logo
->wd
.height
;
116 XMoveWindow(x11
->disp
,gmx
->logo
->wd
.self
,(width
-wl
)/2,(height
-y0
-hl
)/2);
119 static gmx_bool
HandleClient(t_x11
*x11
,int ID
,t_gmx
*gmx
)
128 write_gmx(x11
,gmx
,IDDODUMP
);
131 if (gmx
->man
->bAnimate
)
132 hide_but(x11
,gmx
->man
->vbox
);
134 if (gmx
->man
->bAnimate
)
135 show_but(x11
,gmx
->man
->vbox
);
140 ShowDlg(gmx
->dlgs
[edExport
]);
143 write_sto_conf(gmx
->confout
,*gmx
->man
->top
.name
,
144 &(gmx
->man
->top
.atoms
),
145 gmx
->man
->x
,NULL
,gmx
->man
->molw
->ePBC
,gmx
->man
->box
);
156 edit_file("topol.gmx");
159 edit_file("confin.gmx");
162 edit_file("mdparin.gmx");
168 ShowDlg(gmx
->dlgs
[edFilter
]);
171 do_filter(x11
,gmx
->man
,gmx
->filter
);
174 check_pd_item(pd
,IDANIMATE
,toggle_animate(x11
,gmx
->man
));
177 no_labels(x11
,gmx
->man
);
180 reset_view(gmx
->man
->view
);
181 ExposeWin(x11
->disp
,gmx
->man
->molw
->wd
.self
);
184 show_mb(gmx
,emNotImplemented
);
187 ShowDlg(gmx
->dlgs
[edBonds
]);
190 set_bond_type(x11
,gmx
->man
->molw
,eBThin
);
193 set_bond_type(x11
,gmx
->man
->molw
,eBFat
);
196 set_bond_type(x11
,gmx
->man
->molw
,eBVeryFat
);
199 set_bond_type(x11
,gmx
->man
->molw
,eBSpheres
);
202 set_box_type(x11
,gmx
->man
->molw
,esbNone
);
205 set_box_type(x11
,gmx
->man
->molw
,esbRect
);
208 set_box_type(x11
,gmx
->man
->molw
,esbTri
);
211 set_box_type(x11
,gmx
->man
->molw
,esbTrunc
);
222 show_mb(gmx
,emNotImplemented
);
230 show_logo(x11
,gmx
->logo
);
239 static gmx_bool
MainCallBack(t_x11
*x11
,XEvent
*event
, Window w
, void *data
)
242 int nsel
,width
,height
;
247 switch(event
->type
) {
249 hide_pd(x11
,gmx
->pd
);
251 case ConfigureNotify
:
252 width
=event
->xconfigure
.width
;
253 height
=event
->xconfigure
.height
;
254 if ((width
!=gmx
->wd
->width
) || (height
!=gmx
->wd
->height
))
255 move_gmx(x11
,gmx
,width
,height
,TRUE
);
258 hide_pd(x11
,gmx
->pd
);
259 nsel
=event
->xclient
.data
.l
[0];
260 result
= HandleClient(x11
,nsel
,gmx
);
268 int main(int argc
, char *argv
[])
270 const char *desc
[] = {
271 "[TT]ngmx[tt] is the GROMACS trajectory viewer. This program reads a",
272 "trajectory file, a run input file and an index file and plots a",
273 "3D structure of your molecule on your standard X Window",
274 "screen. No need for a high end graphics workstation, it even",
275 "works on Monochrome screens.[PAR]",
276 "The following features have been implemented:",
277 "3D view, rotation, translation and scaling of your molecule(s),",
278 "labels on atoms, animation of trajectories,",
279 "hardcopy in PostScript format, user defined atom-filters",
280 "runs on MIT-X (real X), open windows and motif,",
281 "user friendly menus, option to remove periodicity, option to",
282 "show computational box.[PAR]",
283 "Some of the more common X command line options can be used: ",
284 "[TT]-bg[tt], [TT]-fg[tt] change colors, [TT]-font fontname[tt] changes the font."
286 const char *bugs
[] = {
287 "Balls option does not work",
288 "Some times dumps core without a good reason"
294 { efTRX
, "-f", NULL
, ffREAD
},
295 { efTPX
, NULL
, NULL
, ffREAD
},
296 { efNDX
, NULL
, NULL
, ffOPTRD
}
298 #define NFILE asize(fnm)
300 CopyRight(stderr
,argv
[0]);
301 parse_common_args(&argc
,argv
,PCA_CAN_TIME
,NFILE
,fnm
,
302 0,NULL
,asize(desc
),desc
,asize(bugs
),bugs
,&oenv
);
304 if ((x11
=GetX11(&argc
,argv
))==NULL
) {
305 fprintf(stderr
,"Can't connect to X Server.\n"
306 "Check your DISPLAY environment variable\n");
309 init_gmx(x11
,argv
[0],NFILE
,fnm
,oenv
);
319 static t_mentry FileMenu
[] = {
320 { 0, IDEXPORT
, FALSE
, "Export..." },
321 { 0, IDDUMPWIN
, FALSE
, "Print" },
322 { 0, IDQUIT
, FALSE
, "Quit" }
325 static t_mentry DispMenu
[] = {
326 { 0, IDFILTER
, FALSE
, "Filter..." },
327 { 0, IDANIMATE
, FALSE
, "Animate" },
328 { 0, IDLABELSOFF
, FALSE
, "Labels Off"},
329 { 0, IDRESETVIEW
, FALSE
, "Reset View"},
330 { 0, IDBONDOPTS
, FALSE
, "Options..."}
333 static t_mentry HelpMenu
[] = {
334 { 0, IDHELP
, FALSE
, "Help" },
335 { 0, IDABOUT
, FALSE
, "About Gromacs..." }
338 static t_mentry
*gmx_pd
[] = { FileMenu
, DispMenu
, HelpMenu
};
340 #define MSIZE asize(gmx_pd)
342 static int gmx_pd_size
[MSIZE
] = {
343 asize(FileMenu
), asize(DispMenu
), asize(HelpMenu
)
346 static const char *MenuTitle
[MSIZE
] = {
347 "File", "Display", "Help"
350 void init_gmx(t_x11
*x11
,char *program
,int nfile
,t_filenm fnm
[],
351 const output_env_t oenv
)
357 int natom
,nre
,natom_trx
;
368 ePBC
= read_tpx_top(ftp2fn(efTPX
,nfile
,fnm
),
369 NULL
,box
,&natom
,NULL
,NULL
,NULL
,&top
);
371 read_first_frame(oenv
,&status
,ftp2fn(efTRX
,nfile
,fnm
),&fr
,TRX_DONT_SKIP
);
373 natom_trx
= fr
.natoms
;
375 /* Creates a simple window */
376 w0
=DisplayWidth(x11
->disp
,x11
->screen
)-132;
377 h0
=DisplayHeight(x11
->disp
,x11
->screen
)-140;
379 InitWin(gmx
->wd
,0,0,w0
,h0
,3,quote
);
380 gmx
->wd
->self
=XCreateSimpleWindow(x11
->disp
,x11
->root
,
381 gmx
->wd
->x
, gmx
->wd
->y
,
382 gmx
->wd
->width
,gmx
->wd
->height
,
383 gmx
->wd
->bwidth
,WHITE
,BLACK
);
384 pm
=XCreatePixmapFromBitmapData(x11
->disp
,x11
->root
,
385 (char *)gromacs_bits
,gromacs_width
,
388 hints
.flags
=PMinSize
;
389 hints
.min_width
=2*EWIDTH
+40;
390 hints
.min_height
=EHEIGHT
+LDHEIGHT
+LEGHEIGHT
+40;
391 XSetStandardProperties(x11
->disp
,gmx
->wd
->self
,gmx
->wd
->text
,program
,
394 x11
->RegisterCallback(x11
,gmx
->wd
->self
,x11
->root
,MainCallBack
,gmx
);
395 x11
->SetInputMask(x11
,gmx
->wd
->self
,
396 ButtonPressMask
| ButtonReleaseMask
|
397 OwnerGrabButtonMask
| ExposureMask
|
398 StructureNotifyMask
);
400 /* The order of creating windows is important here! */
402 gmx
->man
= init_man(x11
,gmx
->wd
->self
,0,0,1,1,WHITE
,BLACK
,ePBC
,box
,oenv
);
403 gmx
->logo
= init_logo(x11
,gmx
->wd
->self
,FALSE
);
405 /* Now put all windows in the proper place */
406 move_gmx(x11
,gmx
,w0
,h0
,FALSE
);
408 XMapWindow(x11
->disp
,gmx
->wd
->self
);
409 map_man(x11
,gmx
->man
);
412 gmx
->pd
=init_pd(x11
,gmx
->wd
->self
,gmx
->wd
->width
,
413 XTextHeight(x11
->font
),x11
->fg
,x11
->bg
,
414 MSIZE
,gmx_pd_size
,gmx_pd
,MenuTitle
);
416 /* Dialogs & Filters */
418 gmx
->filter
=init_filter(&(top
.atoms
),ftp2fn_null(efNDX
,nfile
,fnm
),
423 /* Now do file shit */
424 set_file(x11
,gmx
->man
,ftp2fn(efTRX
,nfile
,fnm
),ftp2fn(efTPX
,nfile
,fnm
));
426 /*show_logo(x11,gmx->logo);*/
428 ShowDlg(gmx
->dlgs
[edFilter
]);