3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
33 * Gyas ROwers Mature At Cryogenic Speed
45 #include "gromacs/fileio/tpxio.h"
51 #include "gromacs/fileio/futil.h"
60 static void add_object(t_manager *man, eObject eO, atom_id ai, atom_id aj)
62 srenew(man->obj, ++man->nobj);
63 man->obj[man->nobj-1].eO = eO;
64 man->obj[man->nobj-1].eV = eVNormal;
65 man->obj[man->nobj-1].color = WHITE;
66 man->obj[man->nobj-1].ai = ai;
67 man->obj[man->nobj-1].aj = aj;
68 man->obj[man->nobj-1].z = 0.0;
71 static void add_bonds(t_manager *man, t_functype func[],
72 t_ilist *b, bool bB[])
74 bool *bH = man->bHydro;
76 t_iatom type, ai, aj, ak;
80 fprintf(stderr, "Going to make bonds from an ilist with %d entries\n", b->nr);
83 for (i = 0; (i < b->nr); )
88 delta = interaction_function[ftype].nratoms;
90 if (ftype == F_SETTLE)
94 bB[ai] = bB[aj] = bB[ak] = true;
95 add_object(man, eOHBond, ai, aj);
96 add_object(man, eOHBond, ai, ak);
98 else if (IS_CHEMBOND(ftype))
102 fprintf(stderr, "Adding bond from %d to %d\n", ai, aj);
104 bB[ai] = bB[aj] = true;
105 if (!(bH[ai] == bH[aj]))
107 add_object(man, eOHBond, ai, aj);
109 else if (!bH[ai] && !bH[aj])
111 add_object(man, eOBond, ai, aj);
115 fprintf(stderr, "Type: %5d, delta: %5d\n", type, delta);
122 static void add_bpl(t_manager *man, t_idef *idef, bool bB[])
126 for (ftype = 0; ftype < F_NRE; ftype++)
128 if (IS_CHEMBOND(ftype) || ftype == F_SETTLE)
130 add_bonds(man, idef->functype, &idef->il[ftype], bB);
135 static atom_id which_atom(t_manager *man, int x, int y)
141 for (i = 0; (i < man->natom); i++)
143 if ((abs(ix[i][XX]-x) < DELTA) && (abs(ix[i][YY]-y) < DELTA))
154 static void do_label(t_x11 *x11, t_manager *man, int x, int y, bool bSet)
159 if ((ai = which_atom(man, x, y)) != NO_ATID)
163 if (bSet && !man->bLabel[ai])
166 man->bLabel[ai] = true;
168 else if (!bSet && man->bLabel[ai])
171 man->bLabel[ai] = false;
177 XSetForeground(x11->disp, x11->gc, col);
178 XDrawString(x11->disp, man->molw->wd.self, x11->gc, x+2, y-2, man->szLab[ai],
179 strlen(man->szLab[ai]));
180 XSetForeground(x11->disp, x11->gc, x11->fg);
184 static void show_label(t_x11 *x11, t_manager *man, int x, int y)
186 do_label(x11, man, x, y, true);
189 static void hide_label(t_x11 *x11, t_manager *man, int x, int y)
191 do_label(x11, man, x, y, false);
194 void set_file(t_x11 *x11, t_manager *man, const char *trajectory,
198 char buf[256], quote[256];
204 read_tpxheader(status, &sh, true, NULL, NULL);
205 snew(man->ix, sh.natoms);
206 snew(man->zz, sh.natoms);
207 snew(man->col, sh.natoms);
208 snew(man->size, sh.natoms);
209 snew(man->vdw, sh.natoms);
210 snew(man->bLabel, sh.natoms);
211 snew(man->bVis, sh.natoms);
212 for (i = 0; (i < sh.natoms); i++)
214 man->bVis[i] = false;
219 snew(man->szLab, sh.natoms);
220 snew(man->bHydro, sh.natoms);
222 read_tpx_top(status, NULL, man->box, &man->natom, NULL, NULL, NULL, &man->top);
223 man->gpbc = gmx_rmpbc_init(&man->top.idef, -1, man->natom);
226 read_first_x(man->oenv, &man->status, trajectory, &(man->time), &(man->x),
228 man->trajfile = strdup(trajectory);
229 if (man->natom > man->top.atoms.nr)
231 gmx_fatal(FARGS, "Topology %s (%d atoms) and trajectory %s (%d atoms) "
232 "do not match", status, man->top.atoms.nr,
233 trajectory, man->natom);
236 cool_quote(quote, 255, NULL);
237 sprintf(buf, "%s: %s", *man->top.name, quote);
238 man->title.text = strdup(buf);
239 man->view = init_view(man->box);
240 at = &(man->top.atoms);
241 aps = gmx_atomprop_init();
242 for (i = 0; (i < man->natom); i++)
244 char *aname = *(at->atomname[i]);
245 t_resinfo *ri = &at->resinfo[at->atom[i].resind];
247 man->col[i] = Type2Color(aname);
248 snew(man->szLab[i], 20);
251 sprintf(man->szLab[i], "%s%d%c, %s", *ri->name, ri->nr, ri->ic, aname);
255 sprintf(man->szLab[i], "%s%d, %s", *ri->name, ri->nr, aname);
257 man->bHydro[i] = (toupper(aname[0]) == 'H');
262 else if (!gmx_atomprop_query(aps, epropVDW, *ri->name, aname, &(man->vdw[i])))
267 gmx_atomprop_destroy(aps);
268 add_bpl(man, &(man->top.idef), bB);
269 for (i = 0; (i < man->natom); i++)
273 add_object(man, eOSingle, (atom_id) i, 0);
278 ExposeWin(x11->disp, man->molw->wd.self);
281 void step_message(t_x11 *x11, t_manager *man)
285 letter.type = ClientMessage;
286 letter.xclient.display = x11->disp;
287 letter.xclient.window = man->wd.self;
288 letter.xclient.message_type = 0;
289 letter.xclient.format = 32;
290 letter.xclient.data.l[0] = IDSTEP;
291 letter.xclient.data.l[1] = Button1;
292 XSendEvent(x11->disp, letter.xclient.window, True, 0, &letter);
295 static void reset_mols(t_block *mols, matrix box, rvec x[])
301 for (i = 0; (i < mols->nr); i++)
304 m1 = mols->index[i+1];
309 for (j = m0; (j < m1); j++)
313 for (m = 0; (m < DIM); m++)
317 for (m = 0; (m < DIM); m++)
323 else if (xcm[m] >= box[m][m])
328 ix = icm[XX], iy = icm[YY], iz = icm[ZZ];
330 if ((ix != 0) || (iy != 0) || (iz != 0))
332 for (j = m0; (j < m1); j++)
342 static bool step_man(t_manager *man, int *nat)
344 static int ncount = 0;
345 static bool bWarn = false;
351 fprintf(stderr, "Not initiated yet!");
354 bEof = read_next_x(man->oenv, man->status, &man->time, man->x, man->box);
356 if (ncount == man->nSkip)
358 switch (man->molw->boxtype)
361 put_atoms_in_triclinic_unitcell(ecenterDEF, man->box, man->natom, man->x);
364 warn = put_atoms_in_compact_unitcell(man->molw->ePBC, ecenterDEF, man->box,
368 fprintf(stderr, "\n%s\n", warn);
379 gmx_rmpbc(man->gpbc, man->natom, man->box, man->x);
380 reset_mols(&(man->top.mols), man->box, man->x);
389 return step_man(man, nat);
396 static void HandleClient(t_x11 *x11, t_manager *man, long data[])
398 int ID, button, x, y;
406 bPos = (button == Button1);
412 rotate_3d(man->view, ID-IDROTX, bPos);
418 fac = 0.8; /* Reduce distance between eye and origin */
425 /* zoom changed to scale by Berk Hess 3-7-96
426 if (zoom_3d(man->view,fac))
427 draw_mol(x11,man); */
428 man->view->sc_x /= fac;
429 man->view->sc_y /= fac;
435 translate_view(man->view, ID-IDTRANSX, bPos);
441 rewind_trj(man->status);
442 read_next_x(man->oenv, man->status, &(man->time), man->x,
453 if (!step_man(man, &nat))
463 usleep(man->nWait*1000);
482 show_label(x11, man, x, y);
485 hide_label(x11, man, x, y);
492 if (man->bAnimate && !man->bEof && !man->bStop)
494 step_message(x11, man);
498 static bool TitleCallBack(t_x11 *x11, XEvent *event, Window w, void *data)
502 wd = (t_windata *)data;
506 if (wd->text && (wd->width > 10))
508 XSetForeground(x11->disp, x11->gc, WHITE);
509 TextInWin(x11, wd, wd->text, eXCenter, eYCenter);
510 XDrawLine(x11->disp, wd->self, x11->gc, 0, wd->height,
511 wd->width, wd->height);
514 case ConfigureNotify:
515 wd->width = event->xconfigure.width;
516 wd->height = event->xconfigure.height;
522 static bool ManCallBack(t_x11 *x11, XEvent *event, Window w, void *data)
527 man = (t_manager *)data;
530 case ConfigureNotify:
531 width = event->xconfigure.width;
532 height = event->xconfigure.height;
533 if ((width != man->wd.width) || (height != man->wd.height))
535 move_man(x11, man, width, height);
539 HandleClient(x11, man, event->xclient.data.l);
547 void no_labels(t_x11 *x11, t_manager *man)
551 for (i = 0; (i < man->natom); i++)
553 man->bLabel[i] = false;
558 void move_man(t_x11 *x11, t_manager *man, int width, int height)
560 int x0, y0, mw, mh, hb;
564 fprintf(stderr, "Move manager %dx%d\n", width, height);
566 man->wd.width = width;
567 man->wd.height = height;
569 /* Move all subwindows, resize only Mol window */
570 x0 = width-EWIDTH-AIR-4*BORDER; /* Starting of ewin etc. */
574 mw = x0-2*AIR-4*BORDER;
575 mh = height-y0-AIR-2*BORDER;
576 XMoveResizeWindow(x11->disp, man->molw->wd.self, AIR, y0, mw, mh);
579 th = XTextHeight(x11->font);
580 XMoveResizeWindow(x11->disp, man->title.self, 0, 0, mw, th+AIR);
583 XMoveResizeWindow(x11->disp, man->legw->wd.self, x0, y0, EWIDTH, LEGHEIGHT);
584 y0 += LEGHEIGHT+AIR+2*BORDER;
588 printf("Error: Windows falling out of main window!\n");
592 hb = height-y0-AIR-2*BORDER;
593 XMoveResizeWindow(x11->disp, man->bbox->wd.self, x0, y0, EWIDTH, hb);
596 x0 = (mw-man->vbox->wd.width)/2;
597 y0 = (mh-2-AIR-man->vbox->wd.height);
598 XMoveWindow(x11->disp, man->vbox->wd.self, x0, y0);
601 void map_man(t_x11 *x11, t_manager *man)
603 XMapWindow(x11->disp, man->wd.self);
604 map_mw(x11, man->molw);
605 XMapWindow(x11->disp, man->title.self);
606 map_legw(x11, man->legw);
607 show_but(x11, man->bbox);
610 bool toggle_animate (t_x11 *x11, t_manager *man)
614 man->bAnimate = !man->bAnimate;
619 show_but(x11, man->vbox);
623 hide_but(x11, man->vbox);
626 return man->bAnimate;
629 bool toggle_pbc (t_manager *man)
631 man->bPbc = !man->bPbc;
637 t_manager *init_man(t_x11 *x11, Window Parent,
638 int x, int y, int width, int height,
639 unsigned long fg, unsigned long bg,
640 int ePBC, matrix box,
641 const output_env_t oenv)
650 InitWin(&(man->wd), x, y, width, height, 0, "Manager");
651 man->wd.self = XCreateSimpleWindow(x11->disp, Parent, man->wd.x, man->wd.y,
652 man->wd.width, man->wd.height,
653 man->wd.bwidth, fg, bg);
654 x11->RegisterCallback(x11, man->wd.self, Parent, ManCallBack, man);
655 x11->SetInputMask(x11, man->wd.self, StructureNotifyMask |
656 ExposureMask | ButtonPressMask);
658 /* The order of creating windows is important for the stacking order */
660 man->molw = init_mw(x11, man->wd.self, 0, 0, 1, 1, WHITE, BLUE, ePBC, box);
663 InitWin(&(man->title), 0, 0, 1, 1, 0, NULL);
664 man->title.self = XCreateSimpleWindow(x11->disp, man->molw->wd.self,
665 man->title.x, man->title.y,
666 man->title.width, man->title.height,
667 man->title.bwidth, WHITE, BLUE);
668 x11->RegisterCallback(x11, man->title.self, man->molw->wd.self,
669 TitleCallBack, &(man->title));
670 x11->SetInputMask(x11, man->title.self, ExposureMask | StructureNotifyMask);
673 man->bbox = init_bbox(x11, man->wd.self, man->wd.self, 1, WHITE, BLUE);
676 man->legw = init_legw(x11, man->wd.self, 0, 0, EWIDTH, LEGHEIGHT, WHITE, BLUE);
679 man->vbox = init_vbox(x11, man->molw->wd.self, man->wd.self, WHITE, BLUE);
684 void done_man(t_x11 *x11, t_manager *man)
686 done_bbox(x11, man->vbox);
687 done_bbox(x11, man->bbox);
688 done_mw(x11, man->molw);
689 done_legw(x11, man->legw);
690 x11->UnRegisterCallback(x11, man->title.self);
691 x11->UnRegisterCallback(x11, man->wd.self);
701 void do_filter(t_x11 *x11, t_manager *man, t_filter *filter)
706 for (i = 0; (i < man->natom); i++)
708 man->bVis[i] = false;
710 for (i = 0; (i < filter->grps->nr); i++)
712 if (filter->bShow[i])
714 for (j = filter->grps->index[i]; (j < filter->grps->index[i+1]); j++)
716 man->bVis[filter->grps->a[j]] = true;
721 ExposeWin(x11->disp, man->wd.self);