1
/* Copyright (C) 2000 Damir Zucic */
3
/*=============================================================================
8
Execute hybonds command. Generate and show (or hide) hydrogen bonds.
9
If hydrogen bonds were generated before, check is it necessary to
10
refresh the information about hydrogen bonds.
13
(1) Pointer to MolComplexS structure, with macromol. complexes.
14
(2) The number of macromolecular complexes.
15
(3) Pointer to RuntimeS structure, with some runtime data.
16
(4) Pointer to ConfigS structure, with configuration data.
17
(5) Pointer to GUIS structure, with GUI data.
18
(6) Pointer to NearestAtomS structure.
19
(7) The number of pixels in the main window free area.
20
(8) Pointer to refreshI.
21
(9) Pointer to the remainder of the command string. It is either
22
empty or contains the keyword OFF.
25
(1) Hydrogen bonds should be either visible or hidden.
29
(1) Positive (command) code on success.
30
(2) Negative (error) code on failure.
32
========includes:============================================================*/
39
#include <X11/Xutil.h>
41
#include <X11/Xatom.h>
47
/*======function prototypes:=================================================*/
49
char *ExtractToken_ (char *, int, char *, char *);
50
unsigned long GenerateHyBonds_ (MolComplexS *, int, ConfigS *, int);
51
size_t MainRefresh_ (MolComplexS *, int,
52
RuntimeS *, ConfigS *, GUIS *,
53
NearestAtomS *, size_t, unsigned int);
54
int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *);
56
/*======execute hybonds command:=============================================*/
58
int HydrogenBonds_ (MolComplexS *mol_complexSP, int mol_complexesN,
59
RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP,
60
NearestAtomS *nearest_atomSP, size_t pixelsN,
61
unsigned int *refreshIP, char *stringP)
64
char tokenA[STRINGSIZE];
67
MolComplexS *curr_mol_complexSP;
68
static char messageA[SHORTSTRINGSIZE] =
69
"This may take some time, please be patient!";
70
int message_length, text_width;
71
int frame_width, frame_height, screen_x0, screen_y0;
73
/* Initialize the styleI: */
76
/* Extract the first token: */
77
remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n");
79
/* If available, the first token should contain the bond drawing style: */
82
/** Extract the bond drawing style: **/
83
if (strstr (tokenA, "OFF") == tokenA) styleI = -1;
84
else if (strcmp (tokenA, "0") == 0) styleI = 0;
85
else if (strcmp (tokenA, "1") == 0) styleI = 1;
86
else if (strcmp (tokenA, "2") == 0) styleI = 2;
87
else if (strcmp (tokenA, "3") == 0) styleI = 3;
88
else if (strcmp (tokenA, "4") == 0) styleI = 4;
89
else if (strcmp (tokenA, "5") == 0) styleI = 5;
92
sprintf (runtimeSP->messageA,
93
"Hydrogen bond drawing style \"%s\" not available!",
95
runtimeSP->message_length = strlen (runtimeSP->messageA);
100
/* If the first token was keyword OFF: */
103
/** Hide hydrogen bonds in every caught complex: **/
104
for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++)
106
/*** Pointer to the current macromolecular complex: ***/
107
curr_mol_complexSP = mol_complexSP + mol_complexI;
109
/*** Check is the current macromol. complex caught: ***/
110
if (curr_mol_complexSP->catchF == 0) continue;
112
/*** Hide hydrogen bonds: ***/
113
curr_mol_complexSP->hydrogen_bonds_hiddenF = 1;
116
/** Refresh the main window: **/
118
MainRefresh_ (mol_complexSP, mol_complexesN,
119
runtimeSP, configSP, guiSP,
120
nearest_atomSP, pixelsN, *refreshIP);
122
/** Refresh the control window: **/
123
ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
126
/** Return to caller: **/
127
return COMMAND_HYBONDS;
130
/* If this point is reached, make hydrogen bonds visible: */
131
for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++)
133
/** Pointer to the current macromolecular complex: **/
134
curr_mol_complexSP = mol_complexSP + mol_complexI;
136
/** Check is the current macromol. complex caught: **/
137
if (curr_mol_complexSP->catchF == 0) continue;
139
/** Make hydrogen bonds visible (unhide): **/
140
curr_mol_complexSP->hydrogen_bonds_hiddenF = 0;
143
/* Inform user that this function may take some time to execute: */
144
message_length = strlen (messageA);
145
text_width = XTextWidth (guiSP->main_winS.fontSP, messageA, message_length);
146
frame_width = text_width + 50;
147
frame_height = 4 * guiSP->main_winS.text_line_height;
148
screen_x0 = (guiSP->main_win_free_area_width - frame_width) / 2;
149
screen_y0 = (guiSP->main_win_free_area_height - frame_height) / 2;
150
XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->dark_red_colorID);
151
XFillRectangle (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0],
152
screen_x0, screen_y0, frame_width, frame_height);
153
XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->yellow_colorID);
154
screen_x0 = (guiSP->main_win_free_area_width - text_width) / 2;
155
screen_y0 = (guiSP->main_win_free_area_height +
156
guiSP->main_winS.text_line_height) / 2;
157
XDrawString (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0],
158
screen_x0, screen_y0, messageA, message_length);
159
XFlush (guiSP->displaySP);
161
/* Generate hydrogen bonds, or just update the bond drawing style: */
162
GenerateHyBonds_ (mol_complexSP, mol_complexesN, configSP, styleI);
164
/* Refresh the main window: */
166
MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP,
167
nearest_atomSP, pixelsN, *refreshIP);
169
/* Refresh the control window: */
170
ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP);
172
/* Return positive value on success: */
173
return COMMAND_HYBONDS;
176
/*===========================================================================*/