4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-2001
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
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 * Do check out http://www.gromacs.org , or mail us at gromacs@gromacs.org .
34 * Giving Russians Opium May Alter Current Situation
36 static char *SRCID_manager_c = "$Id$";
58 static void add_object(t_manager *man,eObject eO,atom_id ai,atom_id aj)
60 srenew(man->obj,++man->nobj);
61 man->obj[man->nobj-1].eO = eO;
62 man->obj[man->nobj-1].eV = eVNormal;
63 man->obj[man->nobj-1].color = WHITE;
64 man->obj[man->nobj-1].ai = ai;
65 man->obj[man->nobj-1].aj = aj;
66 man->obj[man->nobj-1].z = 0.0;
69 static void add_bonds(t_manager *man,t_functype func[],
74 t_iatom type,ai,aj,ak;
78 fprintf(stderr,"Going to make bonds from an ilist with %d entries\n",b->nr);
81 for(i=0; (i<b->nr); ) {
85 delta = interaction_function[ftype].nratoms;
87 if (ftype == F_SETTLE) {
90 bB[ai]=bB[aj]=bB[ak]=TRUE;
91 add_object(man,eOHBond,ai,aj);
92 add_object(man,eOHBond,ai,ak);
94 else if ( interaction_function[ftype].flags & IF_CONNECT ) {
97 fprintf(stderr,"Adding bond from %d to %d\n",ai,aj);
100 if (!(bH[ai] == bH[aj]))
101 add_object(man,eOHBond,ai,aj);
102 else if (!bH[ai] && !bH[aj])
103 add_object(man,eOBond,ai,aj);
106 fprintf(stderr,"Type: %5d, delta: %5d\n",type,delta);
113 static void add_bpl(t_manager *man,t_idef *idef,bool bB[])
115 add_bonds(man,idef->functype,&idef->il[F_BONDS],bB);
116 add_bonds(man,idef->functype,&idef->il[F_G96BONDS],bB);
117 add_bonds(man,idef->functype,&idef->il[F_MORSE],bB);
118 add_bonds(man,idef->functype,&idef->il[F_CUBICBONDS],bB);
119 add_bonds(man,idef->functype,&idef->il[F_CONNBONDS],bB);
120 add_bonds(man,idef->functype,&idef->il[F_SHAKE],bB);
121 add_bonds(man,idef->functype,&idef->il[F_SETTLE],bB);
124 static atom_id which_atom(t_manager *man,int x, int y)
130 for(i=0; (i<man->natom); i++) {
131 if ((abs(ix[i][XX]-x) < DELTA) && (abs(ix[i][YY]-y) < DELTA)) {
139 static void do_label(t_x11 *x11,t_manager *man,int x,int y,bool bSet)
144 if ((ai=which_atom(man,x,y)) != NO_ATID) {
147 if (bSet && !man->bLabel[ai]) {
149 man->bLabel[ai]=TRUE;
151 else if (!bSet && man->bLabel[ai]) {
153 man->bLabel[ai]=FALSE;
157 XSetForeground(x11->disp,x11->gc,col);
158 XDrawString(x11->disp,man->molw->wd.self,x11->gc,x+2,y-2,man->szLab[ai],
159 strlen(man->szLab[ai]));
160 XSetForeground(x11->disp,x11->gc,x11->fg);
164 static void show_label(t_x11 *x11,t_manager *man,int x,int y)
166 do_label(x11,man,x,y,TRUE);
169 static void hide_label(t_x11 *x11,t_manager *man,int x,int y)
171 do_label(x11,man,x,y,FALSE);
174 void set_file(t_x11 *x11,t_manager *man,char *trajectory,char *status)
183 read_tpxheader(status,&sh);
184 snew(man->ix,sh.natoms);
185 snew(man->zz,sh.natoms);
186 snew(man->col,sh.natoms);
187 snew(man->size,sh.natoms);
188 snew(man->vdw,sh.natoms);
189 snew(man->bLabel,sh.natoms);
190 snew(man->bVis,sh.natoms);
191 for(i=0; (i<sh.natoms); i++)
196 snew(man->szLab,sh.natoms);
197 snew(man->bHydro,sh.natoms);
199 read_tpx(status,&(man->step),&(man->time),&rdum,NULL,man->box,
200 &man->natom,NULL,NULL,NULL,&man->top);
203 read_first_x(&man->status,trajectory,&(man->time),&(man->x),man->box);
204 man->trajfile=strdup(trajectory);
205 if (man->natom > man->top.atoms.nr)
206 fatal_error(0,"Topology %s (%d atoms) and trajectory %s (%d atoms) "
207 "do not match",status,man->top.atoms.nr,
208 trajectory,man->natom);
210 sprintf(buf,"%s: %s",*man->top.name,cool_quote());
211 man->title.text = strdup(buf);
212 man->view = init_view(man->box);
213 at=&(man->top.atoms);
214 for(i=0; (i<man->natom); i++) {
215 char *aname=*(at->atomname[i]);
216 int resnr=at->atom[i].resnr;
218 man->col[i]=Type2Color(aname);
219 snew(man->szLab[i],20);
220 sprintf(man->szLab[i],"%s%d, %s",*(at->resname[resnr]),resnr+1,aname);
221 man->bHydro[i]=(toupper(aname[0])=='H');
222 if ( man->bHydro[i] )
225 man->vdw[i]=get_vdw(*(at->resname[resnr]),aname,0);
227 add_bpl(man,&(man->top.idef),bB);
228 for(i=0; (i<man->natom); i++)
230 add_object(man,eOSingle,(atom_id) i,0);
233 ExposeWin(x11->disp,man->molw->wd.self);
236 void step_message(t_x11 *x11,t_manager *man)
240 letter.type=ClientMessage;
241 letter.xclient.display=x11->disp;
242 letter.xclient.window=man->wd.self;
243 letter.xclient.message_type=0;
244 letter.xclient.format=32;
245 letter.xclient.data.l[0]=IDSTEP;
246 letter.xclient.data.l[1]=Button1;
247 XSendEvent(x11->disp,letter.xclient.window,True,0,&letter);
250 bool ReadMonfile(char *fn,int *nbars, int *bars)
253 if ((fp = fopen(fn,"r"))==NULL)
256 for((*nbars)=0; fscanf(fp,"%d",&bars[*nbars])>0; (*nbars)++)
263 static void reset_mols(t_block *mols,matrix box,rvec x[])
269 for(i=0; (i<mols->nr); i++) {
276 for(j=m0; (j<m1); j++) {
280 for(m=0; (m<DIM); m++)
282 for(m=0; (m<DIM); m++) {
285 else if (xcm[m] >= box[m][m])
288 ix=icm[XX],iy=icm[YY],iz=icm[ZZ];
290 if ((ix != 0) || (iy != 0) || (iz != 0)) {
291 for(j=m0; (j<m1); j++) {
301 static bool step_man(t_manager *man,int *nat)
309 fprintf(stderr,"Not initiated yet!");
312 bEof=read_next_x(man->status,&man->time,man->natom,man->x,man->box);
314 if (ncount == man->nSkip) {
315 switch (man->molw->boxtype) {
317 put_atoms_in_triclinic_unitcell(man->box,man->natom,man->x);
320 put_atoms_in_compact_unitcell(man->box,man->natom,man->x);
328 rm_pbc(&(man->top.idef),man->natom,man->box,man->x,man->x);
329 reset_mols(&(man->top.blocks[ebMOLS]),man->box,man->x);
334 if (man->nSkip > 0) {
336 return step_man(man,nat);
343 static void HandleClient(t_x11 *x11,t_manager *man,long data[])
353 bPos=(button==Button1);
358 rotate_3d(man->view,ID-IDROTX,bPos);
363 fac=0.8; /* Reduce distance between eye and origin */
367 /* zoom changed to scale by Berk Hess 3-7-96
368 if (zoom_3d(man->view,fac))
369 draw_mol(x11,man); */
370 man->view->sc_x/=fac;
371 man->view->sc_y/=fac;
377 translate_view(man->view,ID-IDTRANSX,bPos);
381 if (man->status != -1) {
382 rewind_trj(man->status);
383 read_next_x(man->status,&(man->time),man->natom,man->x,man->box);
392 if (!step_man(man,&nat)) {
399 usleep(man->nWait*1000);
417 show_label(x11,man,x,y);
420 hide_label(x11,man,x,y);
427 if (man->bAnimate && !man->bEof && !man->bStop)
428 step_message(x11,man);
431 static bool TitleCallBack(t_x11 *x11,XEvent *event, Window w, void *data)
435 wd=(t_windata *)data;
436 switch (event->type) {
438 if (wd->text && (wd->width > 10)) {
439 XSetForeground(x11->disp,x11->gc,WHITE);
440 TextInWin(x11,wd,wd->text,eXCenter,eYCenter);
441 XDrawLine(x11->disp,wd->self,x11->gc,0,wd->height,
442 wd->width,wd->height);
445 case ConfigureNotify:
446 wd->width=event->xconfigure.width;
447 wd->height=event->xconfigure.height;
453 static bool ManCallBack(t_x11 *x11,XEvent *event, Window w, void *data)
458 man=(t_manager *)data;
459 switch(event->type) {
460 case ConfigureNotify:
461 width=event->xconfigure.width;
462 height=event->xconfigure.height;
463 if ((width!=man->wd.width) || (height!=man->wd.height))
464 move_man(x11,man,width,height);
467 HandleClient(x11,man,event->xclient.data.l);
475 void no_labels(t_x11 *x11,t_manager *man)
479 for(i=0; (i<man->natom); i++)
480 man->bLabel[i]=FALSE;
484 void move_man(t_x11 *x11,t_manager *man,int width,int height)
490 fprintf(stderr,"Move manager %dx%d\n",width,height);
493 man->wd.height=height;
495 /* Move all subwindows, resize only Mol window */
496 x0=width-EWIDTH-AIR-4*BORDER; /* Starting of ewin etc. */
500 mw=x0-2*AIR-4*BORDER;
501 mh=height-y0-AIR-2*BORDER;
502 XMoveResizeWindow(x11->disp,man->molw->wd.self,AIR,y0,mw,mh);
505 th=XTextHeight(x11->font);
506 XMoveResizeWindow(x11->disp,man->title.self,0,0,mw,th+AIR);
509 XMoveResizeWindow(x11->disp,man->legw->wd.self,x0,y0,EWIDTH,LEGHEIGHT);
510 y0+=LEGHEIGHT+AIR+2*BORDER;
513 printf("Error: Windows falling out of main window!\n");
516 hb=height-y0-AIR-2*BORDER;
517 XMoveResizeWindow(x11->disp,man->bbox->wd.self,x0,y0,EWIDTH,hb);
520 x0=(mw-man->vbox->wd.width)/2;
521 y0=(mh-2-AIR-man->vbox->wd.height);
522 XMoveWindow(x11->disp,man->vbox->wd.self,x0,y0);
525 void map_man(t_x11 *x11,t_manager *man)
527 XMapWindow(x11->disp,man->wd.self);
528 map_mw(x11,man->molw);
529 XMapWindow(x11->disp,man->title.self);
530 map_legw(x11,man->legw);
531 show_but(x11,man->bbox);
534 bool toggle_animate (t_x11 *x11,t_manager *man)
536 if (man->status != -1) {
537 man->bAnimate=!man->bAnimate;
541 show_but(x11,man->vbox);
543 hide_but(x11,man->vbox);
545 return man->bAnimate;
548 bool toggle_pbc (t_manager *man)
550 man->bPbc=!man->bPbc;
556 t_manager *init_man(t_x11 *x11,Window Parent,
557 int x,int y,int width,int height,
558 unsigned long fg,unsigned long bg,
567 InitWin(&(man->wd),x,y,width,height,0,"Manager");
568 man->wd.self=XCreateSimpleWindow(x11->disp,Parent,man->wd.x, man->wd.y,
569 man->wd.width,man->wd.height,
570 man->wd.bwidth,fg,bg);
571 x11->RegisterCallback(x11,man->wd.self,Parent,ManCallBack,man);
572 x11->SetInputMask(x11,man->wd.self,StructureNotifyMask |
573 ExposureMask | ButtonPressMask);
575 /* The order of creating windows is important for the stacking order */
577 man->molw=init_mw(x11,man->wd.self,0,0,1,1,WHITE,BLUE,box);
580 InitWin(&(man->title),0,0,1,1,0,NULL);
581 man->title.self=XCreateSimpleWindow(x11->disp,man->molw->wd.self,
582 man->title.x,man->title.y,
583 man->title.width,man->title.height,
584 man->title.bwidth,WHITE,BLUE);
585 x11->RegisterCallback(x11,man->title.self,man->molw->wd.self,
586 TitleCallBack,&(man->title));
587 x11->SetInputMask(x11,man->title.self,ExposureMask | StructureNotifyMask);
590 man->bbox=init_bbox(x11,man->wd.self,man->wd.self,1,WHITE,BLUE);
593 man->legw=init_legw(x11,man->wd.self,0,0,EWIDTH,LEGHEIGHT,WHITE,BLUE);
596 man->vbox=init_vbox(x11,man->molw->wd.self,man->wd.self,WHITE,BLUE);
601 void done_man(t_x11 *x11,t_manager *man)
603 done_bbox(x11,man->vbox);
604 done_bbox(x11,man->bbox);
605 done_mw(x11,man->molw);
606 done_legw(x11,man->legw);
607 x11->UnRegisterCallback(x11,man->title.self);
608 x11->UnRegisterCallback(x11,man->wd.self);
618 void do_filter(t_x11 *x11,t_manager *man,t_filter *filter)
623 for(i=0; (i<man->natom); i++)
625 for(i=0; (i<filter->grps->nr); i++) {
626 if (filter->bShow[i])
627 for(j=filter->grps->index[i]; (j<filter->grps->index[i+1]); j++)
628 man->bVis[filter->grps->a[j]]=TRUE;
631 ExposeWin(x11->disp,man->wd.self);