File: draw_bottom.c

package info (click to toggle)
garlic 1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,516 kB
  • sloc: ansic: 52,465; makefile: 2,254
file content (218 lines) | stat: -rw-r--r-- 6,901 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/* Copyright (C) 2000 Damir Zucic */

/*=============================================================================

				draw_bottom.c

Purpose:
	Draw the exposed polar residues  at the surface of  the bottom
	complex. This complex is colored red. Hydrogen bond donors are
	shown as crosses,  acceptors as circles and residues which may
	be both donors and acceptors are shown as combined crosses and
	circles.

Input:
	(1) Pointer to GUIS structure.
	(2) Pointer to RuntimeS structure.

Output:
	(1) Symbols (crosses and circles) drawn to docking window.
	(2) Return value.

Return value:
	The number of symbols.

========includes:============================================================*/

#include <stdio.h>

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>

#include "defines.h"
#include "typedefs.h"

/*======draw exposed polar residues of the bottom complex:===================*/

int DrawBottom_ (GUIS *guiSP, RuntimeS *runtimeSP)
{
int			symbolsN = 0;
int			exposed_polarN, exposed_polarI;
MolComplexS		*curr_mol_complexSP;
int			*exposed_atomIP;
ExposedResidueS		*exposed_polarSP;
int			geom_returnF;
Window			root_windowID;
int			x0, y0;
unsigned int		width, height, border_width, bpp;
int			square_width, half_square_width;
int			screen_center_x0, screen_center_y0;
int			screen_x0, screen_y0, screen_x1, screen_y1;
int			screen_delta_x, screen_delta_y;
double			docking_area_width;
double			scale_factor;
int			atom_screen_radius;
double			plane_center_x, plane_center_z;
ExposedResidueS		*curr_exposedSP;
AtomS			*curr_atomSP;
double			x, z;
double			relative_x, relative_z;
double			d;
int			screen_x, screen_y;
double			donorI;

/* Copy pointers: */
exposed_polarN = runtimeSP->exposed_polar1N;
curr_mol_complexSP = runtimeSP->mol_complex1SP;
exposed_atomIP = runtimeSP->exposed_atom1IP;
exposed_polarSP = runtimeSP->exposed_polar1SP;

/* Docking window geometry: */
geom_returnF = XGetGeometry(guiSP->displaySP,
			    guiSP->docking_winS.ID,
			    &root_windowID,
                            &x0, &y0, &width, &height,
			    &border_width, &bpp);

/* Refresh docking window: */
XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->black_colorID);
XFillRectangle (guiSP->displaySP, guiSP->docking_winS.ID, guiSP->theGCA[0],
		0, 0, width, height);

/* Prepare some geometric parameters: */
square_width = (int) width - 8 * (int) guiSP->docking_winS.border_width;
if (height < width) square_width = (int) height -
				   8 * (int) guiSP->docking_winS.border_width;
half_square_width = square_width / 2;
screen_center_x0 = width  / 2;
screen_center_y0 = height / 2;
screen_x0 = screen_center_x0 - half_square_width;
screen_y0 = screen_center_y0 - half_square_width;
screen_x1 = screen_center_x0 + half_square_width;
screen_y1 = screen_center_y0 + half_square_width;
screen_delta_x = screen_x1 - screen_x0;
screen_delta_y = screen_y1 - screen_y0;
docking_area_width = runtimeSP->docking_area_width;
if (docking_area_width != 0.0)
	{
	scale_factor = square_width / docking_area_width;
	}
else scale_factor = 0.0;
atom_screen_radius = (int) (scale_factor * 2.0);

/* Draw bounding rectangle (white): */
XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->white_colorID);
XDrawRectangle (guiSP->displaySP, guiSP->docking_winS.ID, guiSP->theGCA[0],
		screen_x0, screen_y0,
		(unsigned int) screen_delta_x, (unsigned int) screen_delta_y);

/* Copy the plane center position (plane belongs to bottom complex): */
plane_center_x = runtimeSP->mol_complex1SP->planeS.center_x[0];
plane_center_z = runtimeSP->mol_complex1SP->planeS.center_z[0];

/* Prepare cyan color: */
XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->cyan_colorID);

/* Scan the list of exposed polar residues: */
for (exposed_polarI = 0; exposed_polarI < exposed_polarN; exposed_polarI++)
	{
	/* Pointer to the current exposed polar residue: */
	curr_exposedSP = exposed_polarSP + exposed_polarI;

	/* If this residue is excluded check the next one: */
	if (curr_exposedSP->excludedF) continue;

	/* Pointer to the representative atom: */
	curr_atomSP = curr_mol_complexSP->atomSP +
	curr_exposedSP->representative_atomI;

	/* Copy the atomic coordinates: */
	x = curr_atomSP->raw_atomS.x[0];
	z = curr_atomSP->raw_atomS.z[0];

	/* Position of the atom relative to the plane center: */
	relative_x = x - plane_center_x;
	relative_z = z - plane_center_z;

	/* Atomic coordinates in screen units: */
	d = scale_factor * relative_z + screen_center_x0;
	screen_x = (int) d;
	d = scale_factor * relative_x + screen_center_y0;
	screen_y = (int) d;

	/* Check the screen coordinates: */
	if ((screen_x < screen_x0) || (screen_x > screen_x1)) continue;
	if ((screen_y < screen_y0) || (screen_y > screen_y1)) continue;

	/* Prepare the color index: */
	donorI = (int) curr_exposedSP->donorI;

	/* If the current residue is hydrogen bond donor, draw cross: */
	if ((donorI == 1) || (donorI == 2))
		{
		XDrawLine (guiSP->displaySP,
			   guiSP->docking_winS.ID,
			   guiSP->theGCA[0],
			   screen_x, screen_y + atom_screen_radius,
			   screen_x, screen_y - atom_screen_radius);
		XDrawLine (guiSP->displaySP,
			   guiSP->docking_winS.ID,
			   guiSP->theGCA[0],
			   screen_x - 1, screen_y + atom_screen_radius,
			   screen_x - 1, screen_y - atom_screen_radius);
		XDrawLine (guiSP->displaySP,
			   guiSP->docking_winS.ID,
			   guiSP->theGCA[0],
			   screen_x + 1, screen_y + atom_screen_radius,
			   screen_x + 1, screen_y - atom_screen_radius);
		XDrawLine (guiSP->displaySP,
			   guiSP->docking_winS.ID,
			   guiSP->theGCA[0],
			   screen_x - atom_screen_radius, screen_y,
			   screen_x + atom_screen_radius, screen_y);
		XDrawLine (guiSP->displaySP,
			   guiSP->docking_winS.ID,
			   guiSP->theGCA[0],
			   screen_x - atom_screen_radius, screen_y - 1,
			   screen_x + atom_screen_radius, screen_y - 1);
		XDrawLine (guiSP->displaySP,
			   guiSP->docking_winS.ID,
			   guiSP->theGCA[0],
			   screen_x - atom_screen_radius, screen_y + 1,
			   screen_x + atom_screen_radius, screen_y + 1);
		}
	
	/* If the current residue is hydrogen bond acceptor, draw circle: */
	if ((donorI == 0) || (donorI == 2))
		{
		XDrawArc (guiSP->displaySP,
			  guiSP->docking_winS.ID,
			  guiSP->theGCA[0],
			  screen_x - atom_screen_radius,
			  screen_y - atom_screen_radius,
			  (unsigned int) (2 * atom_screen_radius),
			  (unsigned int) (2 * atom_screen_radius),
			  0, 23040);
		XDrawArc (guiSP->displaySP,
			  guiSP->docking_winS.ID,
			  guiSP->theGCA[0],
			  screen_x - atom_screen_radius - 1,
			  screen_y - atom_screen_radius - 1,
			  (unsigned int) (2 * atom_screen_radius + 2),
			  (unsigned int) (2 * atom_screen_radius + 2),
			  0, 23040);
		}

	/* Increment the counter: */
	symbolsN++;
	}

/* Return the number of symbols drawn: */
return symbolsN;
}

/*===========================================================================*/