4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
27 * Great Red Oystrich Makes All Chemists Sane
29 static char *SRCID_manager_c = "$Id$";
52 static void add_object(t_manager *man,eObject eO,atom_id ai,atom_id aj)
54 srenew(man->obj,++man->nobj);
55 man->obj[man->nobj-1].eO = eO;
56 man->obj[man->nobj-1].eV = eVNormal;
57 man->obj[man->nobj-1].color = WHITE;
58 man->obj[man->nobj-1].ai = ai;
59 man->obj[man->nobj-1].aj = aj;
60 man->obj[man->nobj-1].z = 0.0;
63 static void add_bonds(t_manager *man,t_functype func[],
68 t_iatom type,ai,aj,ak;
72 fprintf(stderr,"Going to make bonds from an ilist with %d entries\n",b->nr);
75 for(i=0; (i<b->nr); ) {
79 delta = interaction_function[ftype].nratoms;
81 if (ftype == F_SETTLE) {
84 bB[ai]=bB[aj]=bB[ak]=TRUE;
85 add_object(man,eOHBond,ai,aj);
86 add_object(man,eOHBond,ai,ak);
88 else if ( interaction_function[ftype].flags & IF_CONNECT ) {
91 fprintf(stderr,"Adding bond from %d to %d\n",ai,aj);
94 if (!(bH[ai] == bH[aj]))
95 add_object(man,eOHBond,ai,aj);
96 else if (!bH[ai] && !bH[aj])
97 add_object(man,eOBond,ai,aj);
100 fprintf(stderr,"Type: %5d, delta: %5d\n",type,delta);
107 static void add_bpl(t_manager *man,t_idef *idef,bool bB[])
109 add_bonds(man,idef->functype,&idef->il[F_BONDS],bB);
110 add_bonds(man,idef->functype,&idef->il[F_G96BONDS],bB);
111 add_bonds(man,idef->functype,&idef->il[F_MORSE],bB);
112 add_bonds(man,idef->functype,&idef->il[F_CUBICBONDS],bB);
113 add_bonds(man,idef->functype,&idef->il[F_CONNBONDS],bB);
114 add_bonds(man,idef->functype,&idef->il[F_SHAKE],bB);
115 add_bonds(man,idef->functype,&idef->il[F_SETTLE],bB);
118 static atom_id which_atom(t_manager *man,int x, int y)
124 for(i=0; (i<man->natom); i++) {
125 if ((abs(ix[i][XX]-x) < DELTA) && (abs(ix[i][YY]-y) < DELTA)) {
133 static void do_label(t_x11 *x11,t_manager *man,int x,int y,bool bSet)
138 if ((ai=which_atom(man,x,y)) != NO_ATID) {
141 if (bSet && !man->bLabel[ai]) {
143 man->bLabel[ai]=TRUE;
145 else if (!bSet && man->bLabel[ai]) {
147 man->bLabel[ai]=FALSE;
151 XSetForeground(x11->disp,x11->gc,col);
152 XDrawString(x11->disp,man->molw->wd.self,x11->gc,x+2,y-2,man->szLab[ai],
153 strlen(man->szLab[ai]));
154 XSetForeground(x11->disp,x11->gc,x11->fg);
158 static void show_label(t_x11 *x11,t_manager *man,int x,int y)
160 do_label(x11,man,x,y,TRUE);
163 static void hide_label(t_x11 *x11,t_manager *man,int x,int y)
165 do_label(x11,man,x,y,FALSE);
168 void set_file(t_x11 *x11,t_manager *man,char *trajectory,char *status)
177 read_tpxheader(status,&sh);
178 snew(man->ix,sh.natoms);
179 snew(man->zz,sh.natoms);
180 snew(man->col,sh.natoms);
181 snew(man->size,sh.natoms);
182 snew(man->vdw,sh.natoms);
183 snew(man->bLabel,sh.natoms);
184 snew(man->bVis,sh.natoms);
185 for(i=0; (i<sh.natoms); i++)
190 snew(man->szLab,sh.natoms);
191 snew(man->bHydro,sh.natoms);
193 read_tpx(status,&(man->step),&(man->time),&rdum,NULL,man->box,
194 &man->natom,NULL,NULL,NULL,&man->top);
197 read_first_x(&man->status,trajectory,&(man->time),&(man->x),man->box);
198 man->trajfile=strdup(trajectory);
199 if (man->natom > man->top.atoms.nr)
200 fatal_error(0,"Topology %s (%d atoms) and trajectory %s (%d atoms) "
201 "do not match",status,man->top.atoms.nr,
202 trajectory,man->natom);
204 sprintf(buf,"%s: %s",*man->top.name,cool_quote());
205 man->title.text = strdup(buf);
206 man->view = init_view(man->box);
207 at=&(man->top.atoms);
208 for(i=0; (i<man->natom); i++) {
209 char *aname=*(at->atomname[i]);
210 int resnr=at->atom[i].resnr;
212 man->col[i]=Type2Color(aname);
213 snew(man->szLab[i],20);
214 sprintf(man->szLab[i],"%s%d, %s",*(at->resname[resnr]),resnr+1,aname);
215 man->bHydro[i]=(toupper(aname[0])=='H');
216 if ( man->bHydro[i] )
219 man->vdw[i]=get_vdw(*(at->resname[resnr]),aname,0);
221 add_bpl(man,&(man->top.idef),bB);
222 for(i=0; (i<man->natom); i++)
224 add_object(man,eOSingle,(atom_id) i,0);
227 ExposeWin(x11->disp,man->molw->wd.self);
230 void step_message(t_x11 *x11,t_manager *man)
234 letter.type=ClientMessage;
235 letter.xclient.display=x11->disp;
236 letter.xclient.window=man->wd.self;
237 letter.xclient.message_type=0;
238 letter.xclient.format=32;
239 letter.xclient.data.l[0]=IDSTEP;
240 letter.xclient.data.l[1]=Button1;
241 XSendEvent(x11->disp,letter.xclient.window,True,0,&letter);
244 bool ReadMonfile(char *fn,int *nbars, int *bars)
247 if ((fp = fopen(fn,"r"))==NULL)
250 for((*nbars)=0; fscanf(fp,"%d",&bars[*nbars])>0; (*nbars)++)
257 static void reset_mols(t_block *mols,matrix box,rvec x[])
263 for(i=0; (i<mols->nr); i++) {
270 for(j=m0; (j<m1); j++) {
274 for(m=0; (m<DIM); m++)
276 for(m=0; (m<DIM); m++) {
279 else if (xcm[m] >= box[m][m])
282 ix=icm[XX],iy=icm[YY],iz=icm[ZZ];
284 if ((ix != 0) || (iy != 0) || (iz != 0)) {
285 for(j=m0; (j<m1); j++) {
295 static bool step_man(t_manager *man,int *nat)
303 fprintf(stderr,"Not initiated yet!");
306 bEof=read_next_x(man->status,&man->time,man->natom,man->x,man->box);
308 if (ncount == man->nSkip) {
309 switch (man->molw->boxtype) {
311 put_atoms_in_triclinic_unitcell(man->box,man->natom,man->x);
314 put_atoms_in_compact_unitcell(man->box,man->natom,man->x);
322 rm_pbc(&(man->top.idef),man->natom,man->box,man->x,man->x);
323 reset_mols(&(man->top.blocks[ebMOLS]),man->box,man->x);
328 if (man->nSkip > 0) {
330 return step_man(man,nat);
337 static void HandleClient(t_x11 *x11,t_manager *man,long data[])
347 bPos=(button==Button1);
352 rotate_3d(man->view,ID-IDROTX,bPos);
357 fac=0.8; /* Reduce distance between eye and origin */
361 /* zoom changed to scale by Berk Hess 3-7-96
362 if (zoom_3d(man->view,fac))
363 draw_mol(x11,man); */
364 man->view->sc_x/=fac;
365 man->view->sc_y/=fac;
371 translate_view(man->view,ID-IDTRANSX,bPos);
375 if (man->status != -1) {
376 rewind_trj(man->status);
377 read_next_x(man->status,&(man->time),man->natom,man->x,man->box);
386 if (!step_man(man,&nat)) {
393 usleep(man->nWait*1000);
411 show_label(x11,man,x,y);
414 hide_label(x11,man,x,y);
421 if (man->bAnimate && !man->bEof && !man->bStop)
422 step_message(x11,man);
425 static bool TitleCallBack(t_x11 *x11,XEvent *event, Window w, void *data)
429 wd=(t_windata *)data;
430 switch (event->type) {
432 if (wd->text && (wd->width > 10)) {
433 XSetForeground(x11->disp,x11->gc,WHITE);
434 TextInWin(x11,wd,wd->text,eXCenter,eYCenter);
435 XDrawLine(x11->disp,wd->self,x11->gc,0,wd->height,
436 wd->width,wd->height);
439 case ConfigureNotify:
440 wd->width=event->xconfigure.width;
441 wd->height=event->xconfigure.height;
447 static bool ManCallBack(t_x11 *x11,XEvent *event, Window w, void *data)
452 man=(t_manager *)data;
453 switch(event->type) {
454 case ConfigureNotify:
455 width=event->xconfigure.width;
456 height=event->xconfigure.height;
457 if ((width!=man->wd.width) || (height!=man->wd.height))
458 move_man(x11,man,width,height);
461 HandleClient(x11,man,event->xclient.data.l);
469 void no_labels(t_x11 *x11,t_manager *man)
473 for(i=0; (i<man->natom); i++)
474 man->bLabel[i]=FALSE;
478 void move_man(t_x11 *x11,t_manager *man,int width,int height)
484 fprintf(stderr,"Move manager %dx%d\n",width,height);
487 man->wd.height=height;
489 /* Move all subwindows, resize only Mol window */
490 x0=width-EWIDTH-AIR-4*BORDER; /* Starting of ewin etc. */
494 mw=x0-2*AIR-4*BORDER;
495 mh=height-y0-AIR-2*BORDER;
496 XMoveResizeWindow(x11->disp,man->molw->wd.self,AIR,y0,mw,mh);
499 th=XTextHeight(x11->font);
500 XMoveResizeWindow(x11->disp,man->title.self,0,0,mw,th+AIR);
503 XMoveResizeWindow(x11->disp,man->legw->wd.self,x0,y0,EWIDTH,LEGHEIGHT);
504 y0+=LEGHEIGHT+AIR+2*BORDER;
507 printf("Error: Windows falling out of main window!\n");
510 hb=height-y0-AIR-2*BORDER;
511 XMoveResizeWindow(x11->disp,man->bbox->wd.self,x0,y0,EWIDTH,hb);
514 x0=(mw-man->vbox->wd.width)/2;
515 y0=(mh-2-AIR-man->vbox->wd.height);
516 XMoveWindow(x11->disp,man->vbox->wd.self,x0,y0);
519 void map_man(t_x11 *x11,t_manager *man)
521 XMapWindow(x11->disp,man->wd.self);
522 map_mw(x11,man->molw);
523 XMapWindow(x11->disp,man->title.self);
524 map_legw(x11,man->legw);
525 show_but(x11,man->bbox);
528 bool toggle_animate (t_x11 *x11,t_manager *man)
530 if (man->status != -1) {
531 man->bAnimate=!man->bAnimate;
535 show_but(x11,man->vbox);
537 hide_but(x11,man->vbox);
539 return man->bAnimate;
542 bool toggle_pbc (t_manager *man)
544 man->bPbc=!man->bPbc;
550 t_manager *init_man(t_x11 *x11,Window Parent,
551 int x,int y,int width,int height,
552 unsigned long fg,unsigned long bg,
561 InitWin(&(man->wd),x,y,width,height,0,"Manager");
562 man->wd.self=XCreateSimpleWindow(x11->disp,Parent,man->wd.x, man->wd.y,
563 man->wd.width,man->wd.height,
564 man->wd.bwidth,fg,bg);
565 x11->RegisterCallback(x11,man->wd.self,Parent,ManCallBack,man);
566 x11->SetInputMask(x11,man->wd.self,StructureNotifyMask |
567 ExposureMask | ButtonPressMask);
569 /* The order of creating windows is important for the stacking order */
571 man->molw=init_mw(x11,man->wd.self,0,0,1,1,WHITE,BLUE,box);
574 InitWin(&(man->title),0,0,1,1,0,NULL);
575 man->title.self=XCreateSimpleWindow(x11->disp,man->molw->wd.self,
576 man->title.x,man->title.y,
577 man->title.width,man->title.height,
578 man->title.bwidth,WHITE,BLUE);
579 x11->RegisterCallback(x11,man->title.self,man->molw->wd.self,
580 TitleCallBack,&(man->title));
581 x11->SetInputMask(x11,man->title.self,ExposureMask | StructureNotifyMask);
584 man->bbox=init_bbox(x11,man->wd.self,man->wd.self,1,WHITE,BLUE);
587 man->legw=init_legw(x11,man->wd.self,0,0,EWIDTH,LEGHEIGHT,WHITE,BLUE);
590 man->vbox=init_vbox(x11,man->molw->wd.self,man->wd.self,WHITE,BLUE);
595 void done_man(t_x11 *x11,t_manager *man)
597 done_bbox(x11,man->vbox);
598 done_bbox(x11,man->bbox);
599 done_mw(x11,man->molw);
600 done_legw(x11,man->legw);
601 x11->UnRegisterCallback(x11,man->title.self);
602 x11->UnRegisterCallback(x11,man->wd.self);
612 void do_filter(t_x11 *x11,t_manager *man,t_filter *filter)
617 for(i=0; (i<man->natom); i++)
619 for(i=0; (i<filter->grps->nr); i++) {
620 if (filter->bShow[i])
621 for(j=filter->grps->index[i]; (j<filter->grps->index[i+1]); j++)
622 man->bVis[filter->grps->a[j]]=TRUE;
625 ExposeWin(x11->disp,man->wd.self);