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_xrama_c
= "$Id$";
48 enum { ebQuit
, ebStart
, ebStop
, ebRewind
, ebGly
, ebutNR
};
51 #define SX(x) ((int)(((x)+M_PI)*scx))
52 #define SY(y) ((int)((M_PI-(y))*scy))
54 enum { esStop
, esGo
, esNR
};
63 t_windata but
[ebutNR
];
66 static void plot_pp(t_x11
*x11
,Window w
,t_phipsi
*pp
,t_dih dih
[])
69 int th
=(XTextHeight(x11
->font
)+6)/2;
71 x0
=SX(dih
[pp
->iphi
].ang
);
72 y0
=SY(dih
[pp
->ipsi
].ang
);
73 XFillRectangle(x11
->disp
,w
,x11
->gc
,x0
-1,y0
-1,4,4);
76 TextInRect(x11
,w
,pp
->label
,x0
+6,y0
-th
,30,2*th
,eXLeft
,eYCenter
);
79 static bool label_pp(t_x11
*x11
,Window w
,int npp
,t_phipsi pp
[],
80 t_dih dih
[],int mx
,int my
)
87 for(i
=0; (i
<npp
); i
++) {
88 x0
=SX(dih
[pp
[i
].iphi
].ang
);
89 y0
=SY(dih
[pp
[i
].ipsi
].ang
);
90 d
=(mx
-x0
)*(mx
-x0
)+(my
-y0
)*(my
-y0
);
97 pp
[imin
].bShow
=!pp
[imin
].bShow
;
103 static bool xrCallBack(struct t_x11
*x11
,XEvent
*event
, Window w
, void *data
)
110 (void)XTextHeight(x11
->font
);
113 scx
=app
->xrwd
.width
/(2.0*M_PI
);
114 scy
=app
->xrwd
.height
/(2.0*M_PI
);
115 switch (event
->type
) {
117 XClearWindow(x11
->disp
,app
->xrwd
.self
);
118 XDrawLine(x11
->disp
,app
->xrwd
.self
,x11
->gc
,
119 SX(0),SY(-M_PI
)+1,SX(0),SY(M_PI
)-1);
120 XDrawLine(x11
->disp
,app
->xrwd
.self
,x11
->gc
,
121 SX(-M_PI
)+1,SY(0),SX(M_PI
)-1,SY(0));
122 TextInRect(x11
,app
->xrwd
.self
,"Phi",SX(M_PI
)-50,SY(0)+4,46,20,eXRight
,eYTop
);
123 TextInRect(x11
,app
->xrwd
.self
,"Psi",SX(0)+4,4,46,20,eXLeft
,eYTop
);
124 for(i
=0; (i
<xr
->npp
); i
++)
125 if (app
->bShowGly
|| !app
->bIsGly
[i
])
126 plot_pp(x11
,app
->xrwd
.self
,&(xr
->pp
[i
]),xr
->dih
);
129 if (label_pp(x11
,app
->xrwd
.self
,xr
->npp
,xr
->pp
,xr
->dih
,
130 event
->xbutton
.x
,event
->xbutton
.y
))
131 ExposeWin(x11
->disp
,app
->xrwd
.self
);
133 case ConfigureNotify
:
134 app
->xrwd
.width
=event
->xconfigure
.width
;
135 app
->xrwd
.height
=event
->xconfigure
.height
;
138 if (app
->status
== esGo
) {
139 if (!new_data(app
->xr
))
142 ExposeWin(x11
->disp
,app
->xrwd
.self
);
143 sprintf(buf
,"Rama: t=%.2f",app
->xr
->t
);
144 XSetStandardProperties(x11
->disp
,app
->wd
.self
,buf
,
145 "Rama",0,NULL
,0,NULL
);
152 static bool appCallBack(struct t_x11
*x11
,XEvent
*event
, Window w
, void *data
)
158 for(win
=0; (win
<ebutNR
); win
++)
159 if (app
->but
[win
].self
== w
)
164 switch(event
->type
) {
166 TextInWin(x11
,&(app
->but
[win
]),app
->but
[win
].text
,eXCenter
,eYCenter
);
174 ExposeWin(x11
->disp
,app
->xrwd
.self
);
180 rewind_trj(app
->xr
->traj
);
183 app
->bShowGly
=!app
->bShowGly
;
184 ExposeWin(x11
->disp
,app
->xrwd
.self
);
195 static void size_app(t_x11
*x11
,t_app
*app
)
199 th
=XTextHeight(x11
->font
)+4;
200 dx
=app
->wd
.width
/ebutNR
;
201 for(i
=0; (i
<ebutNR
); i
++) {
202 app
->but
[i
].width
=dx
-4;
203 app
->but
[i
].height
=th
+4;
204 XMoveResizeWindow(x11
->disp
,app
->but
[i
].self
,i
*dx
+2,2,dx
-4,th
+4);
206 XMoveResizeWindow(x11
->disp
,app
->xrwd
.self
,2,th
+10,
207 app
->wd
.width
-6,app
->wd
.height
-th
-10-4);
210 static bool mainCallBack(struct t_x11
*x11
,XEvent
*event
, Window w
, void *data
)
216 switch (event
->type
) {
217 case ConfigureNotify
:
218 wt
=event
->xconfigure
.width
;
219 ht
=event
->xconfigure
.height
;
220 if ((app
->wd
.width
!= wt
) || (app
->wd
.height
!= ht
)) {
221 fprintf(stderr
,"New wxh = %dx%d\n",wt
,ht
);
231 static t_xrama
*init_xrama(t_x11
*x11
,Window Parent
,int y0
,t_app
*app
)
237 InitWin(&(app
->xrwd
),2,y0
,MAXDEG
+1,MAXDEG
+1,1,"Ramachandran Movie");
238 app
->xrwd
.self
=XCreateSimpleWindow(x11
->disp
,Parent
,app
->xrwd
.x
,app
->xrwd
.y
,
239 app
->xrwd
.width
,app
->xrwd
.height
,
240 app
->xrwd
.bwidth
,x11
->fg
,x11
->bg
);
241 x11
->RegisterCallback(x11
,app
->xrwd
.self
,Parent
,xrCallBack
,app
);
242 x11
->SetInputMask(x11
,app
->xrwd
.self
,ButtonPressMask
| ExposureMask
|
243 StructureNotifyMask
);
248 static t_app
*init_app(t_x11
*x11
,int argc
,char *argv
[])
250 static char *but_nm
[ebutNR
] = { "Quit", "Start", "Stop", "Rewind", "Toggle Gly" };
259 th
=XTextHeight(x11
->font
)+4;
260 InitWin(&(app
->wd
),0,0,MAXDEG
+6,MAXDEG
+6+th
+6,0,"Ramachandran Movie");
261 dx
=app
->wd
.width
/ebutNR
;
262 app
->wd
.self
=XCreateSimpleWindow(x11
->disp
,x11
->root
,app
->wd
.x
,app
->wd
.y
,
263 app
->wd
.width
,app
->wd
.height
,
264 app
->wd
.bwidth
,x11
->fg
,x11
->bg
);
265 x11
->RegisterCallback(x11
,app
->wd
.self
,x11
->root
,mainCallBack
,app
);
266 x11
->SetInputMask(x11
,app
->wd
.self
,StructureNotifyMask
);
268 pm
=XCreatePixmapFromBitmapData(x11
->disp
,x11
->root
,(char *)rama_bits
,
269 rama_width
,rama_height
,WHITE
,BLACK
,1);
270 XSetStandardProperties(x11
->disp
,app
->wd
.self
,app
->wd
.text
,
271 "Rama",pm
,argv
,argc
,&hints
);
272 x11
->RegisterCallback(x11
,app
->wd
.self
,x11
->root
,appCallBack
,app
);
273 x11
->SetInputMask(x11
,app
->wd
.self
,ButtonPressMask
| ExposureMask
|
274 StructureNotifyMask
);
276 app
->xr
=init_xrama(x11
,app
->wd
.self
,th
+6,app
);
277 for(i
=0; (i
<ebutNR
); i
++) {
279 InitWin(wd
,i
*dx
+2,2,dx
-4,th
,1,but_nm
[i
]);
280 wd
->self
=XCreateSimpleWindow(x11
->disp
,app
->wd
.self
,
281 wd
->x
,wd
->y
,wd
->width
,wd
->height
,
282 wd
->bwidth
,x11
->fg
,x11
->bg
);
283 x11
->RegisterCallback(x11
,wd
->self
,app
->wd
.self
,appCallBack
,app
);
284 x11
->SetInputMask(x11
,wd
->self
,ButtonPressMask
| ExposureMask
);
289 static void mk_gly(t_app
*app
)
293 snew(app
->bIsGly
,app
->xr
->npp
);
294 for(i
=0; (i
<app
->xr
->npp
); i
++) {
295 if (strstr(app
->xr
->pp
[i
].label
,"GLY") != NULL
)
300 int main(int argc
,char *argv
[])
302 static char *desc
[] = {
303 "xrama shows a Ramachandran movie, that is, it shows",
304 "the Phi/Psi angles as a function of time in an X-Window.[PAR]"
305 "Static Phi/Psi plots for printing can be made with g_rama.[PAR]",
306 "Some of the more common X command line options can be used:[BR]",
307 "-bg, -fg change colors, -font fontname, changes the font."
313 { efTRX
, "-f", NULL
, ffREAD
},
314 { efTPX
, NULL
, NULL
, ffREAD
}
316 #define NFILE asize(fnm)
318 CopyRight(stderr
,argv
[0]);
319 parse_common_args(&argc
,argv
,PCA_CAN_TIME
,FALSE
,NFILE
,fnm
,0,NULL
,
320 asize(desc
),desc
,0,NULL
);
322 init_lookup_table(stdout
);
324 if ((x11
=GetX11(&argc
,argv
)) == NULL
) {
325 fprintf(stderr
,"Can't open display, set your DISPLAY environment variable\n");
328 XSetForeground(x11
->disp
,x11
->gc
,x11
->fg
);
329 app
=init_app(x11
,argc
,argv
);
331 init_rama(ftp2fn(efTRX
,NFILE
,fnm
),ftp2fn(efTPX
,NFILE
,fnm
),app
->xr
);
334 XMapWindow(x11
->disp
,app
->wd
.self
);
335 XMapSubwindows(x11
->disp
,app
->wd
.self
);