Upped the version to 3.2.0
[gromacs.git] / src / ngmx / ngmx.c
blobcd77b08e4a18770724d02c5a6808a80838bdb48e
1 /*
2 * $Id$
3 *
4 * This source code is part of
5 *
6 * G R O M A C S
7 *
8 * GROningen MAchine for Chemical Simulations
9 *
10 * VERSION 3.2.0
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
33 * And Hey:
34 * Gyas ROwers Mature At Cryogenic Speed
36 #include <ctype.h>
37 #include <string.h>
39 #include "sysstuff.h"
40 #include "macros.h"
41 #include "smalloc.h"
42 #include "fatal.h"
43 #include "typedefs.h"
44 #include "string2.h"
45 #include "statutil.h"
46 #include "Xstuff.h"
47 #include "gromacs.bm"
48 #include "copyrite.h"
49 #include "confio.h"
50 #include "dialogs.h"
51 #include "writeps.h"
52 #include "molps.h"
53 #include "nmol.h"
54 #include "tpxio.h"
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)
63 char comm[256];
65 sprintf(comm,"xwd -id %d -display %s > %s",(int)w,dispname,fn);
66 system(comm);
69 static void dump_it(t_manager *man)
71 t_psdata ps;
73 ps=ps_open("ngmx.ps",0,0,man->molw->wd.width,man->molw->wd.height);
74 ps_draw_mol(ps,man);
75 ps_close(ps);
78 static void done_gmx(t_x11 *x11,t_gmx *gmx)
80 done_logo(x11,gmx->logo);
81 done_pd(x11,gmx->pd);
82 done_man(x11,gmx->man);
83 done_dlgs(gmx);
84 x11->UnRegisterCallback(x11,gmx->wd->self);
87 static void move_gmx(t_x11 *x11,t_gmx *gmx,int width,int height,
88 bool bSizePD)
90 int y0,wl,hl;
91 #ifdef DEBUG
92 fprintf(stderr,"Move gmx %dx%d\n",width,height);
93 #endif
94 y0=XTextHeight(x11->font);
95 /* Resize PD-Menu */
96 if (bSizePD)
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)
109 t_pulldown *pd;
111 pd=gmx->pd;
113 switch(ID) {
114 /* File Menu */
115 case IDDUMPWIN:
116 write_gmx(x11,gmx,IDDODUMP);
117 break;
118 case IDDODUMP:
119 if (gmx->man->bAnimate)
120 hide_but(x11,gmx->man->vbox);
121 dump_it(gmx->man);
122 if (gmx->man->bAnimate)
123 show_but(x11,gmx->man->vbox);
124 break;
125 case IDCLOSE:
126 case IDIMPORT:
127 case IDEXPORT:
128 ShowDlg(gmx->dlgs[edExport]);
129 break;
130 case IDDOEXPORT:
131 write_sto_conf(gmx->confout,*gmx->man->top.name,
132 &(gmx->man->top.atoms),
133 gmx->man->x,NULL,gmx->man->box);
134 break;
135 case IDQUIT:
136 show_mb(gmx,emQuit);
137 break;
138 case IDTERM:
139 done_gmx(x11,gmx);
140 return TRUE;
142 /* Edit Menu */
143 case IDEDITTOP:
144 edit_file("topol.gmx");
145 break;
146 case IDEDITCOORDS:
147 edit_file("confin.gmx");
148 break;
149 case IDEDITPARAMS:
150 edit_file("mdparin.gmx");
151 break;
153 /* Display Menu */
154 case IDFILTER:
155 if (gmx->filter)
156 ShowDlg(gmx->dlgs[edFilter]);
157 break;
158 case IDDOFILTER:
159 do_filter(x11,gmx->man,gmx->filter);
160 break;
161 case IDANIMATE:
162 check_pd_item(pd,IDANIMATE,toggle_animate(x11,gmx->man));
163 break;
164 case IDLABELSOFF:
165 no_labels(x11,gmx->man);
166 break;
167 case IDRESETVIEW:
168 reset_view(gmx->man->view);
169 ExposeWin(x11->disp,gmx->man->molw->wd.self);
170 break;
171 case IDPHOTO:
172 show_mb(gmx,emNotImplemented);
173 break;
174 case IDBONDOPTS:
175 ShowDlg(gmx->dlgs[edBonds]);
176 break;
177 case IDTHIN:
178 set_bond_type(x11,gmx->man->molw,eBThin);
179 break;
180 case IDFAT:
181 set_bond_type(x11,gmx->man->molw,eBFat);
182 break;
183 case IDVERYFAT:
184 set_bond_type(x11,gmx->man->molw,eBVeryFat);
185 break;
186 case IDBALLS:
187 set_bond_type(x11,gmx->man->molw,eBSpheres);
188 break;
189 case IDNOBOX:
190 set_box_type(x11,gmx->man->molw,esbNone);
191 break;
192 case IDRECTBOX:
193 set_box_type(x11,gmx->man->molw,esbRect);
194 break;
195 case IDTRIBOX:
196 set_box_type(x11,gmx->man->molw,esbTri);
197 break;
198 case IDTOBOX:
199 set_box_type(x11,gmx->man->molw,esbTrunc);
200 break;
202 /* Analysis Menu */
203 case IDBOND:
204 case IDANGLE:
205 case IDDIH:
206 case IDRMS:
207 case IDRDF:
208 case IDENERGIES:
209 case IDCORR:
210 show_mb(gmx,emNotImplemented);
211 break;
213 /* Help Menu */
214 case IDHELP:
215 show_mb(gmx,emHelp);
216 break;
217 case IDABOUT:
218 show_logo(x11,gmx->logo);
219 break;
221 default:
222 break;
224 return FALSE;
227 static bool MainCallBack(t_x11 *x11,XEvent *event, Window w, void *data)
229 t_gmx *gmx;
230 int nsel,width,height;
231 bool result;
233 result = FALSE;
234 gmx=(t_gmx *)data;
235 switch(event->type) {
236 case ButtonRelease:
237 hide_pd(x11,gmx->pd);
238 break;
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);
244 break;
245 case ClientMessage:
246 hide_pd(x11,gmx->pd);
247 nsel=event->xclient.data.l[0];
248 result = HandleClient(x11,nsel,gmx);
249 break;
250 default:
251 break;
253 return result;
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"
279 t_x11 *x11;
280 t_filenm fnm[] = {
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");
294 exit(1);
296 init_gmx(x11,argv[0],NFILE,fnm);
298 x11->MainLoop(x11);
299 x11->CleanUp(x11);
301 thanx(stderr);
303 return 0;
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[])
339 Pixmap pm;
340 t_gmx *gmx;
341 XSizeHints hints;
342 int w0,h0;
343 int step,natom,nre,natom_trx;
344 real t,lambda;
345 t_topology top;
346 matrix box;
347 t_trxframe fr;
348 int status;
349 char quote[256];
351 snew(gmx,1);
352 snew(gmx->wd,1);
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);
358 close_trx(status);
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,
371 gromacs_height,
372 WHITE,BLACK,1);
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,
377 pm,NULL,0,&hints);
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! */
386 /* Manager */
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);
396 /* Pull Down menu */
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),
404 natom_trx);
406 init_dlgs(x11,gmx);
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]);