4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Copyright (c) 1991-2001, University of Groningen, The Netherlands
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * If you want to redistribute modifications, please consider that
18 * scientific software is very special. Version control is crucial -
19 * bugs must be traceable. We will be happy to consider code for
20 * inclusion in the official distribution, but derived work must not
21 * be called official GROMACS. Details are found in the README & COPYING
22 * files - if they are missing, get the official version at www.gromacs.org.
24 * To help us fund GROMACS development, we humbly ask that you cite
25 * the papers on the package - you can find them in the top README file.
27 * For more info, check our website at http://www.gromacs.org
30 * Glycine aRginine prOline Methionine Alanine Cystine Serine
53 /* Forward declarations: I Don't want all that init shit here */
54 void init_gmx(t_x11
*x11
,char *program
,int nfile
,t_filenm fnm
[]);
56 int EventSignaller(t_manager
*man
);
58 static void dump_xw(char *dispname
,Window w
,char *fn
)
62 sprintf(comm
,"xwd -id %d -display %s > %s",(int)w
,dispname
,fn
);
66 static void dump_it(t_manager
*man
)
70 ps
=ps_open("ngmx.ps",0,0,man
->molw
->wd
.width
,man
->molw
->wd
.height
);
75 static void done_gmx(t_x11
*x11
,t_gmx
*gmx
)
77 done_logo(x11
,gmx
->logo
);
79 done_man(x11
,gmx
->man
);
81 x11
->UnRegisterCallback(x11
,gmx
->wd
->self
);
84 static void move_gmx(t_x11
*x11
,t_gmx
*gmx
,int width
,int height
,
89 fprintf(stderr
,"Move gmx %dx%d\n",width
,height
);
91 y0
=XTextHeight(x11
->font
);
94 XResizeWindow(x11
->disp
,gmx
->pd
->wd
.self
,width
,y0
);
96 XMoveWindow(x11
->disp
,gmx
->man
->wd
.self
,0,y0
+1);
97 XResizeWindow(x11
->disp
,gmx
->man
->wd
.self
,width
,height
-y0
-1);
99 wl
=gmx
->logo
->wd
.width
;
100 hl
=gmx
->logo
->wd
.height
;
101 XMoveWindow(x11
->disp
,gmx
->logo
->wd
.self
,(width
-wl
)/2,(height
-y0
-hl
)/2);
104 static bool HandleClient(t_x11
*x11
,int ID
,t_gmx
*gmx
)
113 write_gmx(x11
,gmx
,IDDODUMP
);
116 if (gmx
->man
->bAnimate
)
117 hide_but(x11
,gmx
->man
->vbox
);
119 if (gmx
->man
->bAnimate
)
120 show_but(x11
,gmx
->man
->vbox
);
125 ShowDlg(gmx
->dlgs
[edExport
]);
128 write_sto_conf(gmx
->confout
,*gmx
->man
->top
.name
,
129 &(gmx
->man
->top
.atoms
),
130 gmx
->man
->x
,NULL
,gmx
->man
->box
);
141 edit_file("topol.gmx");
144 edit_file("confin.gmx");
147 edit_file("mdparin.gmx");
153 ShowDlg(gmx
->dlgs
[edFilter
]);
156 do_filter(x11
,gmx
->man
,gmx
->filter
);
159 check_pd_item(pd
,IDANIMATE
,toggle_animate(x11
,gmx
->man
));
162 no_labels(x11
,gmx
->man
);
165 reset_view(gmx
->man
->view
);
166 ExposeWin(x11
->disp
,gmx
->man
->molw
->wd
.self
);
169 show_mb(gmx
,emNotImplemented
);
172 ShowDlg(gmx
->dlgs
[edBonds
]);
175 set_bond_type(x11
,gmx
->man
->molw
,eBThin
);
178 set_bond_type(x11
,gmx
->man
->molw
,eBFat
);
181 set_bond_type(x11
,gmx
->man
->molw
,eBVeryFat
);
184 set_bond_type(x11
,gmx
->man
->molw
,eBSpheres
);
187 set_box_type(x11
,gmx
->man
->molw
,esbNone
);
190 set_box_type(x11
,gmx
->man
->molw
,esbRect
);
193 set_box_type(x11
,gmx
->man
->molw
,esbTri
);
196 set_box_type(x11
,gmx
->man
->molw
,esbTrunc
);
207 show_mb(gmx
,emNotImplemented
);
215 show_logo(x11
,gmx
->logo
);
224 static bool MainCallBack(t_x11
*x11
,XEvent
*event
, Window w
, void *data
)
227 int nsel
,width
,height
;
232 switch(event
->type
) {
234 hide_pd(x11
,gmx
->pd
);
236 case ConfigureNotify
:
237 width
=event
->xconfigure
.width
;
238 height
=event
->xconfigure
.height
;
239 if ((width
!=gmx
->wd
->width
) || (height
!=gmx
->wd
->height
))
240 move_gmx(x11
,gmx
,width
,height
,TRUE
);
243 hide_pd(x11
,gmx
->pd
);
244 nsel
=event
->xclient
.data
.l
[0];
245 result
= HandleClient(x11
,nsel
,gmx
);
253 int main(int argc
, char *argv
[])
255 static char *desc
[] = {
256 "ngmx is the Gromacs trajectory viewer. This program reads a",
257 "trajectory file, a run input file and an index file and plots a",
258 "3D structure of your molecule on your standard X Window",
259 "screen. No need for a high end graphics workstation, it even",
260 "works on Monochrome screens.[PAR]",
261 "The following features have been implemented:",
262 "3D view, rotation, translation and scaling of your molecule(s),",
263 "labels on atoms, animation of trajectories,",
264 "hardcopy in PostScript format, user defined atom-filters",
265 "runs on MIT-X (real X), open windows and motif,",
266 "user friendly menus, option to remove periodicity, option to",
267 "show computational box.[PAR]",
268 "Some of the more common X command line options can be used:[BR]",
269 "-bg, -fg change colors, -font fontname, changes the font."
271 static char *bugs
[] = {
272 "Balls option does not work",
273 "Some times dumps core without a good reason"
278 { efTRX
, "-f", NULL
, ffREAD
},
279 { efTPX
, NULL
, NULL
, ffREAD
},
280 { efNDX
, NULL
, NULL
, ffOPTRD
}
282 #define NFILE asize(fnm)
284 CopyRight(stdout
,argv
[0]);
285 parse_common_args(&argc
,argv
,PCA_CAN_TIME
,NFILE
,fnm
,
286 0,NULL
,asize(desc
),desc
,asize(bugs
),bugs
);
288 if ((x11
=GetX11(&argc
,argv
))==NULL
) {
289 fprintf(stderr
,"Can't connect to X Server.\n"
290 "Check your DISPLAY environment variable\n");
293 init_gmx(x11
,argv
[0],NFILE
,fnm
);
303 static t_mentry FileMenu
[] = {
304 { 0, IDEXPORT
, FALSE
, "Export..." },
305 { 0, IDDUMPWIN
, FALSE
, "Print" },
306 { 0, IDQUIT
, FALSE
, "Quit" }
309 static t_mentry DispMenu
[] = {
310 { 0, IDFILTER
, FALSE
, "Filter..." },
311 { 0, IDANIMATE
, FALSE
, "Animate" },
312 { 0, IDLABELSOFF
, FALSE
, "Labels Off"},
313 { 0, IDRESETVIEW
, FALSE
, "Reset View"},
314 { 0, IDBONDOPTS
, FALSE
, "Options..."}
317 static t_mentry HelpMenu
[] = {
318 { 0, IDHELP
, FALSE
, "Help" },
319 { 0, IDABOUT
, FALSE
, "About Gromacs..." }
322 static t_mentry
*gmx_pd
[] = { FileMenu
, DispMenu
, HelpMenu
};
324 #define MSIZE asize(gmx_pd)
326 static int gmx_pd_size
[MSIZE
] = {
327 asize(FileMenu
), asize(DispMenu
), asize(HelpMenu
)
330 static char *MenuTitle
[MSIZE
] = {
331 "File", "Display", "Help"
334 void init_gmx(t_x11
*x11
,char *program
,int nfile
,t_filenm fnm
[])
340 int step
,natom
,nre
,natom_trx
;
351 read_tpx(ftp2fn(efTPX
,nfile
,fnm
),&step
,&t
,&lambda
,NULL
,box
,
352 &natom
,NULL
,NULL
,NULL
,&top
);
354 read_first_frame(&status
,ftp2fn(efTRX
,nfile
,fnm
),&fr
,TRX_DONT_SKIP
);
356 natom_trx
= fr
.natoms
;
358 /* Creates a simple window */
359 w0
=DisplayWidth(x11
->disp
,x11
->screen
)-132;
360 h0
=DisplayHeight(x11
->disp
,x11
->screen
)-140;
361 InitWin(gmx
->wd
,0,0,w0
,h0
,3,bromacs(quote
,255));
362 gmx
->wd
->self
=XCreateSimpleWindow(x11
->disp
,x11
->root
,
363 gmx
->wd
->x
, gmx
->wd
->y
,
364 gmx
->wd
->width
,gmx
->wd
->height
,
365 gmx
->wd
->bwidth
,WHITE
,BLACK
);
366 pm
=XCreatePixmapFromBitmapData(x11
->disp
,x11
->root
,
367 (char *)gromacs_bits
,gromacs_width
,
370 hints
.flags
=PMinSize
;
371 hints
.min_width
=2*EWIDTH
+40;
372 hints
.min_height
=EHEIGHT
+LDHEIGHT
+LEGHEIGHT
+40;
373 XSetStandardProperties(x11
->disp
,gmx
->wd
->self
,gmx
->wd
->text
,program
,
376 x11
->RegisterCallback(x11
,gmx
->wd
->self
,x11
->root
,MainCallBack
,gmx
);
377 x11
->SetInputMask(x11
,gmx
->wd
->self
,
378 ButtonPressMask
| ButtonReleaseMask
|
379 OwnerGrabButtonMask
| ExposureMask
|
380 StructureNotifyMask
);
382 /* The order of creating windows is important here! */
384 gmx
->man
= init_man(x11
,gmx
->wd
->self
,0,0,1,1,WHITE
,BLACK
,box
);
385 gmx
->logo
= init_logo(x11
,gmx
->wd
->self
);
387 /* Now put all windows in the proper place */
388 move_gmx(x11
,gmx
,w0
,h0
,FALSE
);
390 XMapWindow(x11
->disp
,gmx
->wd
->self
);
391 map_man(x11
,gmx
->man
);
394 gmx
->pd
=init_pd(x11
,gmx
->wd
->self
,gmx
->wd
->width
,
395 XTextHeight(x11
->font
),x11
->fg
,x11
->bg
,
396 MSIZE
,gmx_pd_size
,gmx_pd
,MenuTitle
);
398 /* Dialogs & Filters */
400 gmx
->filter
=init_filter(&(top
.atoms
),ftp2fn_null(efNDX
,nfile
,fnm
),
405 /* Now do file shit */
406 set_file(x11
,gmx
->man
,ftp2fn(efTRX
,nfile
,fnm
),ftp2fn(efTPX
,nfile
,fnm
));
408 /*show_logo(x11,gmx->logo);*/
410 ShowDlg(gmx
->dlgs
[edFilter
]);