1
/* Copyright (C) 2000 Damir Zucic */
3
/*=============================================================================
8
Draw hydrophobicity plots. This function is used if the main win.
9
drawing mode is equal to four. The sequence stored to the sequence
10
buffer is used to calculate requested functions.
13
(1) Pointer to RuntimeS structure, with some runtime data.
14
(2) Pointer to GUIS structure, with GUI data.
15
(3) Pointer to NearestAtomS structure, with information about the
16
atom occupying the given pixel.
17
(4) The number of pixels in the main window free area.
18
(5) The refreshI, used to check the NearestAtomS associated with
19
a given pixel. It is currently unused in this function.
22
(1) Hydrophobicity plots should be drawn to the main window.
26
(1) The number of residues used in calculation.
29
(1) The initial drawing destination is the hidden pixmap, and the
30
content of this pixmap is copied later to the main window.
32
(2) The residue index is stored as the atomic index. The function
33
value (averaged hydrophobicity, hydrophobic moment etc.) is
34
stored as z coordinate.
36
========includes:============================================================*/
44
#include <X11/Xutil.h>
46
#include <X11/Xatom.h>
51
/*======function prototypes:=================================================*/
53
int RefreshPixmap_ (Display *, Pixmap, GC,
54
unsigned int, unsigned int, unsigned long);
55
int ParseColor_ (RGBS *, unsigned long *, GUIS *, char *, char *);
57
/*======draw hydrophobicity plots:===========================================*/
59
size_t DrawPlots_ (RuntimeS *runtimeSP, GUIS *guiSP,
60
NearestAtomS *nearest_atomSP, size_t pixelsN,
61
unsigned int refreshI)
63
int residuesN, residueI; /* Do not use size_t instead of int ! */
65
int serialI, range_startI, range_endI, residues_in_plotN = 0;
67
int window_width, half_window_width, windowI, combinedI;
68
double angle_step, angle;
69
double hydrophobicity, averaged_hydrophobicity = 0;
70
double min_average_hyphob, max_average_hyphob;
71
double hydrophobic_moment, abs_squared, moment_x, moment_y;
72
double min_hyphob_moment, max_hyphob_moment;
73
int screen_width, screen_height;
74
int screen_margin_x, screen_margin_top, screen_margin_bottom;
75
int screen_delta_x, screen_delta_y;
76
int residue_screen_width, half_residue_width;
77
int residues_per_sectionN;
78
int sectionsN, sectionI;
79
int section_width, section_height;
80
int frame_x0, frame_x1, frame_y0, frame_y1;
82
unsigned long color1ID, color2ID, color3ID, color4ID;
84
double ordinate_min, ordinate_max, ordinate_range, ordinate_scale;
86
int screen_x0, screen_x1, screen_y0, screen_y1;
89
char stringA[SHORTSTRINGSIZE];
91
int text_height, text_ascent, text_width, half_text_width;
92
int old_screen_y = 0, screen_x, screen_y;
93
int draw_vertical_lineF = 0;
95
NearestAtomS *curr_pixelSP;
98
/*------prepare some parameters:---------------------------------------------*/
100
/* The number of residues in sequence buffer: */
101
residuesN = (int) runtimeSP->residuesN;
104
strcpy (runtimeSP->messageA, "The sequence buffer is empty!");
105
runtimeSP->message_length = strlen (runtimeSP->messageA);
109
/* Paranoid check - at least one flag should be different from zero: */
110
if ((runtimeSP->averaged_hydrophobicityF == 0) &&
111
(runtimeSP->hydrophobic_momentF == 0)) return 0;
113
/* Residue serial range: */
114
range_startI = runtimeSP->range_startI;
115
range_endI = runtimeSP->range_endI;
117
/* Count the number of residues in the specified range: */
118
for (residueI = 0; residueI < residuesN; residueI++)
120
/* Check is the residue serial index inside the range: */
121
serialI = *(runtimeSP->serialIP + residueI);
122
if ((serialI < range_startI) || (serialI > range_endI)) continue;
124
/* Increase the count of residues if current */
125
/* residue belongs to the specified range: */
129
/* Check the number of residues in a plot: */
130
if (residues_in_plotN == 0)
132
strcpy (runtimeSP->messageA, "The specified range is empty!");
133
runtimeSP->message_length = strlen (runtimeSP->messageA);
137
/* The sliding window width: */
138
window_width = runtimeSP->sliding_window_width;
139
half_window_width = window_width / 2;
141
/* The helix step angle: */
142
angle_step = DEG_TO_RAD * runtimeSP->helix_step_angle;
144
/*------refresh the hidden pixmap:-------------------------------------------*/
146
/* Refresh the hidden pixmap, where drawing will be done: */
147
RefreshPixmap_ (guiSP->displaySP,
148
guiSP->main_hidden_pixmapID,
150
guiSP->control_winS.x0, guiSP->input_winS.y0,
151
guiSP->main_winS.bg_colorID);
153
/*------calculate the averaged hydrophobicity:-------------------------------*/
155
/* Initialize the extreme values: */
156
min_average_hyphob = +999999;
157
max_average_hyphob = -999999;
159
/* Scan the sequence: */
160
for (residueI = 0; residueI < residuesN; residueI++)
162
/* Reset the number of residues used for averaging: */
165
/* Reset the averaged hydrophobicity: */
166
averaged_hydrophobicity = 0.0;
168
/* Scan the sliding window: */
169
for (windowI = 0; windowI < window_width; windowI++)
171
/* Prepare and check the combined index: */
172
combinedI = residueI - half_window_width + windowI;
173
if (combinedI < 0) continue;
174
if (combinedI >= residuesN) continue;
176
/* The hydrophobicity of the residue defined by combinedI: */
178
(double) *(runtimeSP->hydrophobicityP + combinedI);
180
/* Add hydrophobicity to the total: */
181
averaged_hydrophobicity += hydrophobicity;
183
/* Increase the number of residues used for averaging: */
187
/* Check how many residues were used: */
188
if (used_residuesN == window_width)
190
averaged_hydrophobicity /= (double) window_width;
192
else averaged_hydrophobicity = 0.0;
194
/* Store the average hydrophobicity: */
195
*(runtimeSP->averaged_hydrophobicityP + residueI) =
196
(float) averaged_hydrophobicity;
198
/* Dummy values should not be used to determine extremes: */
199
if (used_residuesN != window_width) continue;
201
/* Find the extreme values: */
202
if (averaged_hydrophobicity < min_average_hyphob)
204
min_average_hyphob = averaged_hydrophobicity;
206
if (averaged_hydrophobicity > max_average_hyphob)
208
max_average_hyphob = averaged_hydrophobicity;
212
/*------calculate the hydrophobic moment:------------------------------------*/
214
/* Initialize the extreme values: */
215
min_hyphob_moment = +999999;
216
max_hyphob_moment = -999999;
218
/* Scan the sequence: */
219
for (residueI = 0; residueI < residuesN; residueI++)
221
/* Reset the number of residues used for calculation: */
224
/* Reset the projections: */
228
/* Scan the sliding window: */
229
for (windowI = 0; windowI < window_width; windowI++)
231
/* Prepare and check the combined index: */
232
combinedI = residueI - half_window_width + windowI;
233
if (combinedI < 0) continue;
234
if (combinedI >= residuesN) continue;
236
/* The hydrophobicity of the residue defined by combinedI: */
237
hydrophobicity = *(runtimeSP->hydrophobicityP + combinedI);
240
angle = angle_step * (double) windowI;
242
/* Hydrophobic moment projections: */
243
moment_x += (double) hydrophobicity * cos (angle);
244
moment_y += (double) hydrophobicity * sin (angle);
246
/* Increase the number of residues used for calculation: */
250
/* Calculate the hydrophobic moment: */
251
abs_squared = moment_x * moment_x + moment_y * moment_y;
252
if (used_residuesN == window_width)
254
hydrophobic_moment = sqrt (abs_squared) /
255
(double) window_width;
257
else hydrophobic_moment = 0.0;
259
/* Store the hydrophobic moment: */
260
*(runtimeSP->hydrophobic_momentP + residueI) =
261
(float) hydrophobic_moment;
263
/* Dummy values should not be used to determine extreme values: */
264
if (used_residuesN != window_width) continue;
266
/* Find the extreme values: */
267
if (hydrophobic_moment < min_hyphob_moment)
269
min_hyphob_moment = hydrophobic_moment;
271
if (hydrophobic_moment > max_hyphob_moment)
273
max_hyphob_moment = hydrophobic_moment;
277
/*------prepare geometric parameters:----------------------------------------*/
279
/* Width, height and margins (margins will be updated later): */
280
screen_width = guiSP->main_win_free_area_width;
281
screen_height = guiSP->main_win_free_area_height;
282
screen_margin_x = screen_width / 40;
283
if (screen_margin_x < 4) screen_margin_x = 4;
284
screen_margin_bottom = screen_height / 40;
285
if (screen_margin_bottom < 4) screen_margin_bottom = 4;
286
screen_margin_top = 2 * screen_margin_bottom + guiSP->main_winS.font_height;
287
screen_delta_x = screen_width - 2 * screen_margin_x;
288
if (screen_delta_x < 10) screen_delta_x = 10;
289
screen_delta_y = screen_height - screen_margin_top - screen_margin_bottom;
290
if (screen_delta_y < 10) screen_delta_y = 10;
292
/* Break the entire sequence range into more */
293
/* parts, if the number of residues is large: */
294
residue_screen_width = RESIDUE_WIDTH;
295
half_residue_width = residue_screen_width / 2;
296
if (residue_screen_width <= 0) return 0;
297
residues_per_sectionN = screen_delta_x / residue_screen_width;
298
if (residues_per_sectionN == 0) sectionsN = 1;
299
else sectionsN = (residues_in_plotN + residues_per_sectionN - 1) /
300
residues_per_sectionN;
302
/* The screen height should be divided into equal portions: */
303
if (sectionsN == 0) section_height = screen_delta_y;
304
else section_height = screen_delta_y / sectionsN;
306
/* Avoid ugly proportions: */
307
if (section_height / residue_screen_width > 80)
309
section_height = 80 * residue_screen_width;
312
/* Update plot width, height and margins: */
313
if (residues_in_plotN > residues_per_sectionN)
315
screen_delta_x = residues_per_sectionN * residue_screen_width;
319
screen_delta_x = residues_in_plotN * residue_screen_width;
321
screen_margin_x = (screen_width - screen_delta_x) / 2;
322
screen_margin_bottom = (screen_height -
323
section_height * sectionsN -
324
guiSP->main_winS.font_height) / 3;
325
if (screen_margin_bottom < 4) screen_margin_bottom = 4;
326
screen_margin_top = 2 * screen_margin_bottom + guiSP->main_winS.font_height;
328
/* Set the section width: */
329
section_width = screen_delta_x;
331
/*------draw frames:---------------------------------------------------------*/
333
/* Frame left and right edge: */
334
frame_x0 = screen_margin_x;
335
frame_x1 = frame_x0 + section_width;
337
/* Frame top and bottom edge: */
338
frame_y0 = screen_margin_top;
339
frame_y1 = screen_margin_top + sectionsN * section_height;
341
/* Prepare colors: */
342
ParseColor_ (&rgbS, &color1ID, guiSP, "RGB:3333/3333/3333", "black");
343
ParseColor_ (&rgbS, &color2ID, guiSP, "RGB:6666/6666/6666", "black");
344
ParseColor_ (&rgbS, &color3ID, guiSP, "RGB:AAAA/AAAA/AAAA", "white");
345
ParseColor_ (&rgbS, &color4ID, guiSP, "RGB:EEEE/EEEE/EEEE", "white");
346
XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID);
347
XSetForeground (guiSP->displaySP, guiSP->theGCA[2], color2ID);
348
XSetForeground (guiSP->displaySP, guiSP->theGCA[3], color3ID);
349
XSetForeground (guiSP->displaySP, guiSP->theGCA[4], color4ID);
350
XSetForeground (guiSP->displaySP, guiSP->theGCA[5], color3ID);
351
XSetForeground (guiSP->displaySP, guiSP->theGCA[6], color2ID);
352
XSetForeground (guiSP->displaySP, guiSP->theGCA[7], color1ID);
354
/* Draw vertical lines: */
355
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1],
356
frame_x0 - 3, frame_y0 - 3, frame_x0 - 3, frame_y1 + 3);
357
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2],
358
frame_x0 - 2, frame_y0 - 3, frame_x0 - 2, frame_y1 + 3);
359
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3],
360
frame_x0 - 1, frame_y0 - 3, frame_x0 - 1, frame_y1 + 3);
361
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[4],
362
frame_x0 - 0, frame_y0 - 3, frame_x0 - 0, frame_y1 + 3);
363
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[5],
364
frame_x0 + 1, frame_y0 - 3, frame_x0 + 1, frame_y1 + 3);
365
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[6],
366
frame_x0 + 2, frame_y0 - 3, frame_x0 + 2, frame_y1 + 3);
367
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[7],
368
frame_x0 + 3, frame_y0 - 3, frame_x0 + 3, frame_y1 + 3);
369
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1],
370
frame_x1 - 3, frame_y0 - 3, frame_x1 - 3, frame_y1 + 3);
371
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2],
372
frame_x1 - 2, frame_y0 - 3, frame_x1 - 2, frame_y1 + 3);
373
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3],
374
frame_x1 - 1, frame_y0 - 3, frame_x1 - 1, frame_y1 + 3);
375
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[4],
376
frame_x1 - 0, frame_y0 - 3, frame_x1 - 0, frame_y1 + 3);
377
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[5],
378
frame_x1 + 1, frame_y0 - 3, frame_x1 + 1, frame_y1 + 3);
379
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[6],
380
frame_x1 + 2, frame_y0 - 3, frame_x1 + 2, frame_y1 + 3);
381
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[7],
382
frame_x1 + 3, frame_y0 - 3, frame_x1 + 3, frame_y1 + 3);
384
/* Draw horizontal lines: */
385
for (sectionI = 0; sectionI <= sectionsN; sectionI++)
387
section_y0 = screen_margin_top + sectionI * section_height;
388
XDrawLine (guiSP->displaySP,
389
guiSP->main_hidden_pixmapID,
391
frame_x0 + 3, section_y0 - 3,
392
frame_x1 - 3, section_y0 - 3);
393
XDrawLine (guiSP->displaySP,
394
guiSP->main_hidden_pixmapID,
396
frame_x0 + 2, section_y0 - 2,
397
frame_x1 - 2, section_y0 - 2);
398
XDrawLine (guiSP->displaySP,
399
guiSP->main_hidden_pixmapID,
401
frame_x0 + 1, section_y0 - 1,
402
frame_x1 - 1, section_y0 - 1);
403
XDrawLine (guiSP->displaySP,
404
guiSP->main_hidden_pixmapID,
406
frame_x0 + 0, section_y0 - 0,
407
frame_x1 - 0, section_y0 - 0);
408
XDrawLine (guiSP->displaySP,
409
guiSP->main_hidden_pixmapID,
411
frame_x0 + 1, section_y0 + 1,
412
frame_x1 - 1, section_y0 + 1);
413
XDrawLine (guiSP->displaySP,
414
guiSP->main_hidden_pixmapID,
416
frame_x0 + 2, section_y0 + 2,
417
frame_x1 - 2, section_y0 + 2);
418
XDrawLine (guiSP->displaySP,
419
guiSP->main_hidden_pixmapID,
421
frame_x0 + 3, section_y0 + 3,
422
frame_x1 - 3, section_y0 + 3);
425
/* Fix top and bottom of the frame: */
426
section_y0 = screen_margin_top;
427
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1],
428
frame_x0 - 3, section_y0 - 3, frame_x1 + 3, section_y0 - 3);
429
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2],
430
frame_x0 - 2, section_y0 - 2, frame_x1 + 2, section_y0 - 2);
431
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3],
432
frame_x0 - 1, section_y0 - 1, frame_x1 + 1, section_y0 - 1);
433
section_y0 = screen_margin_top + sectionsN * section_height;
434
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1],
435
frame_x0 - 3, section_y0 + 3, frame_x1 + 3, section_y0 + 3);
436
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2],
437
frame_x0 - 2, section_y0 + 2, frame_x1 + 2, section_y0 + 2);
438
XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3],
439
frame_x0 - 1, section_y0 + 1, frame_x1 + 1, section_y0 + 1);
441
/*------prepare ordinate extreme values and scale factor:--------------------*/
443
/* Prepare extreme values for the ordinate axis: */
444
ordinate_min = +999999;
445
ordinate_max = -999999;
446
if (runtimeSP->averaged_hydrophobicityF)
448
if (min_average_hyphob < ordinate_min)
450
ordinate_min = min_average_hyphob;
452
if (max_average_hyphob > ordinate_max)
454
ordinate_max = max_average_hyphob;
457
if (runtimeSP->hydrophobic_momentF)
459
if (min_hyphob_moment < ordinate_min)
461
ordinate_min = min_hyphob_moment;
463
if (max_hyphob_moment > ordinate_max)
465
ordinate_max = max_hyphob_moment;
469
/* Shift both values slightly for esthetic reasons: */
470
ordinate_range = ordinate_max - ordinate_min;
471
ordinate_min -= 0.15 * ordinate_range;
472
ordinate_max += 0.15 * ordinate_range;
474
/* Prepare the ordinate scale factor: */
475
ordinate_range = ordinate_max - ordinate_min;
476
if (ordinate_range != 0.0)
478
ordinate_scale = (double) section_height / ordinate_range;
480
else ordinate_scale = 0.0;
482
/*------draw vertical grid (every 10 residues):------------------------------*/
484
/* Initialize the plot index: */
487
/* Scan the sequence: */
488
for (residueI = 9; residueI < residuesN; residueI += 10)
490
/* Check is the residue serial index inside the range: */
491
serialI = *(runtimeSP->serialIP + residueI);
492
if ((serialI < range_startI) || (serialI > range_endI))
497
/* Prepare the position: */
498
sectionI = plotI / residues_per_sectionN;
499
local_residueI = plotI % residues_per_sectionN;
500
screen_x = screen_margin_x + local_residueI * residue_screen_width;
501
if ((screen_x >= frame_x1 - 3) || (screen_x <= frame_x0 + 3))
506
screen_y0 = screen_margin_top + (sectionI + 1) * section_height - 4;
507
screen_y1 = screen_margin_top + sectionI * section_height + 4;
510
XDrawLine (guiSP->displaySP,
511
guiSP->main_hidden_pixmapID,
513
screen_x, screen_y0, screen_x, screen_y1);
514
XDrawLine (guiSP->displaySP,
515
guiSP->main_hidden_pixmapID,
517
screen_x + 1, screen_y0, screen_x + 1, screen_y1);
519
/* Update the plot index: */
523
/*------draw abscisa:--------------------------------------------------------*/
525
/* Left and right extent of the abscisa axis: */
526
screen_x0 = frame_x0 + 4;
527
screen_x1 = frame_x1 - 4;
529
/* Draw abscisa in each section: */
530
if ((ordinate_min < 0.0) && (ordinate_max > 0.0))
532
for (sectionI = 0; sectionI < sectionsN; sectionI++)
534
d = -ordinate_min * ordinate_scale;
535
screen_y0 = screen_margin_top +
536
(sectionI + 1) * section_height -
538
XDrawLine (guiSP->displaySP,
539
guiSP->main_hidden_pixmapID,
541
screen_x0, screen_y0 + 1, screen_x1, screen_y0 + 1);
542
XDrawLine (guiSP->displaySP,
543
guiSP->main_hidden_pixmapID,
545
screen_x0, screen_y0, screen_x1, screen_y0);
546
XDrawLine (guiSP->displaySP,
547
guiSP->main_hidden_pixmapID,
549
screen_x0, screen_y0 - 1, screen_x1, screen_y0 - 1);
553
/*------draw labels:---------------------------------------------------------*/
555
/* Text height and ascent for the main window font: */
556
text_height = guiSP->main_winS.font_height;
557
text_ascent = guiSP->main_winS.fontSP->ascent;
559
/* Prepare the text color: */
560
XSetForeground (guiSP->displaySP, guiSP->theGCA[0],
561
guiSP->main_winS.fg_colorID);
563
/* Reset the plot index: */
566
/* Scan the sequence: */
567
for (residueI = 9; residueI < residuesN; residueI += 10)
569
/* Use the stored sequence index: */
570
residue_serialI = *(runtimeSP->serialIP + residueI);
572
/* Check is the residue serial index inside the range: */
573
if ((residue_serialI < range_startI) ||
574
(residue_serialI > range_endI))
579
/* Prepare section index and local residue index: */
580
sectionI = plotI / residues_per_sectionN;
581
local_residueI = plotI % residues_per_sectionN;
583
/* Prepare the label: */
584
sprintf (stringA, "%d", residue_serialI);
585
string_length = strlen (stringA);
586
text_width = XTextWidth (guiSP->main_winS.fontSP,
587
stringA, strlen (stringA));
588
half_text_width = text_width / 2;
590
/* Prepare the position where the label should be drawn: */
591
screen_x = screen_margin_x +
592
local_residueI * residue_screen_width -
594
if ((screen_x >= frame_x1 - text_width - 3) ||
595
(screen_x <= frame_x0 + 3))
600
d = -ordinate_min * ordinate_scale;
601
screen_y = screen_margin_top + (sectionI + 1) * section_height - 5;
603
/* Draw the label: */
604
XDrawString (guiSP->displaySP,
605
guiSP->main_hidden_pixmapID,
608
stringA, strlen (stringA));
610
/* Update the plot index: */
614
/*------draw averaged hydrophobicity:----------------------------------------*/
616
if (runtimeSP->averaged_hydrophobicityF)
618
/* Prepare three colors for averaged hydrophobicity: */
619
ParseColor_ (&rgbS, &color1ID, guiSP, "RGB:FFFF/8888/8888", "white");
620
ParseColor_ (&rgbS, &color2ID, guiSP, "RGB:FFFF/0000/0000", "white");
621
ParseColor_ (&rgbS, &color3ID, guiSP, "RGB:8888/0000/0000", "black");
622
XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID);
623
XSetForeground (guiSP->displaySP, guiSP->theGCA[2], color2ID);
624
XSetForeground (guiSP->displaySP, guiSP->theGCA[3], color3ID);
626
/* Reset the plot index: */
629
/* Scan the sequence: */
630
for (residueI = 0; residueI <= residuesN; residueI++)
632
/* Check is the residue serial index inside the range: */
633
serialI = *(runtimeSP->serialIP + residueI);
634
if ((serialI < range_startI) || (serialI > range_endI))
639
/* Copy the averaged hydrophobicity: */
640
averaged_hydrophobicity =
641
(double) *(runtimeSP->averaged_hydrophobicityP +
644
/* Prepare screen coordinates: */
645
sectionI = plotI / residues_per_sectionN;
646
local_residueI = plotI % residues_per_sectionN;
647
screen_x0 = screen_margin_x +
648
local_residueI * residue_screen_width -
649
half_residue_width - 1;
650
screen_x1 = screen_x0 + residue_screen_width + 2;
651
d = (averaged_hydrophobicity - ordinate_min) * ordinate_scale;
652
screen_y0 = screen_margin_top + sectionI * section_height;
653
screen_y1 = screen_y0 + section_height;
654
screen_y = screen_y1 - (int) d;
656
/* If residue is near the N or C term., draw nothing: */
657
local_residueI = plotI % residues_per_sectionN;
658
if ((plotI < half_window_width) ||
659
(plotI > residues_in_plotN - window_width))
661
old_screen_y = screen_y0;
666
/* Draw triple line: */
667
XDrawLine (guiSP->displaySP,
668
guiSP->main_hidden_pixmapID,
670
screen_x0, screen_y - 1,
671
screen_x1, screen_y - 1);
672
XDrawLine (guiSP->displaySP,
673
guiSP->main_hidden_pixmapID,
676
screen_x1, screen_y);
677
XDrawLine (guiSP->displaySP,
678
guiSP->main_hidden_pixmapID,
680
screen_x0, screen_y + 1,
681
screen_x1, screen_y + 1);
683
/* Initialize the flag which says is */
684
/* it necessary to draw vertical line: */
685
draw_vertical_lineF = 1;
687
/* For the first residue in the current */
688
/* section do not draw vertical line: */
689
local_residueI = plotI % residues_per_sectionN;
690
if (local_residueI == 0)
692
old_screen_y = screen_y0;
693
draw_vertical_lineF = 0;
696
/* For the first visible residue, do not draw vertical line: */
697
if (plotI == half_window_width)
699
old_screen_y = screen_y;
700
draw_vertical_lineF = 0;
703
/* Check is it necessary to draw vertical line: */
704
if (old_screen_y == screen_y)
706
old_screen_y = screen_y;
707
draw_vertical_lineF = 0;
710
/* Prepare the shift which is required to draw corners; take */
711
/* the next res. if there is no need to draw vertical lines: */
712
if (old_screen_y < screen_y) shift = -1;
715
/* Draw three vertical lines: */
716
if (draw_vertical_lineF)
718
XDrawLine (guiSP->displaySP,
719
guiSP->main_hidden_pixmapID,
721
screen_x0, old_screen_y - shift,
722
screen_x0, screen_y - shift);
723
XDrawLine (guiSP->displaySP,
724
guiSP->main_hidden_pixmapID,
726
screen_x0 + 1, old_screen_y,
727
screen_x0 + 1, screen_y);
728
XDrawLine (guiSP->displaySP,
729
guiSP->main_hidden_pixmapID,
731
screen_x0 + 2, old_screen_y + shift,
732
screen_x0 + 2, screen_y + shift);
735
/* Copy the y coordinate for later use: */
736
old_screen_y = screen_y;
738
/* Fill NearestAtomS array: */
739
for (screen_x = screen_x0 + 2;
740
screen_x <= screen_x1 - 1;
743
for (screen_y = screen_y0;
744
screen_y <= screen_y1;
747
/* Prepare index to the array */
748
/* of NearestAtomS structures: */
749
pixelI = guiSP->main_win_free_area_width *
752
/* Check the pixel index: */
753
if (pixelI >= pixelsN) continue;
755
/* Pointer to NearestAtomS struct. */
756
/* assigned to current coordinates: */
757
curr_pixelSP = nearest_atomSP + pixelI;
759
/* Refresh NearestAtomS associated with */
760
/* this pixel; residue index is stored */
761
/* to location reserved for atom index. */
762
curr_pixelSP->last_refreshI = refreshI;
763
curr_pixelSP->atomI = residueI;
764
curr_pixelSP->z = averaged_hydrophobicity;
768
/* Update the plot index: */
773
/*------draw hydrophobic moment:---------------------------------------------*/
775
if (runtimeSP->hydrophobic_momentF)
777
/* Prepare three colors for hydrophobic moment: */
778
ParseColor_ (&rgbS, &color1ID, guiSP, "RGB:8888/DDDD/FFFF", "white");
779
ParseColor_ (&rgbS, &color2ID, guiSP, "RGB:0000/8888/FFFF", "white");
780
ParseColor_ (&rgbS, &color3ID, guiSP, "RGB:0000/4444/8888", "black");
781
XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID);
782
XSetForeground (guiSP->displaySP, guiSP->theGCA[2], color2ID);
783
XSetForeground (guiSP->displaySP, guiSP->theGCA[3], color3ID);
785
/* Reset the plot index: */
788
/* Scan the sequence: */
789
for (residueI = 0; residueI <= residuesN; residueI++)
791
/* Check is the residue serial index inside the range: */
792
serialI = *(runtimeSP->serialIP + residueI);
793
if ((serialI < range_startI) || (serialI > range_endI))
798
/* Copy the hydrophobic moment: */
800
(double) *(runtimeSP->hydrophobic_momentP +
803
/* Prepare screen coordinates: */
804
sectionI = plotI / residues_per_sectionN;
805
local_residueI = plotI % residues_per_sectionN;
806
screen_x0 = screen_margin_x +
807
local_residueI * residue_screen_width -
808
half_residue_width - 1;
809
screen_x1 = screen_x0 + residue_screen_width + 2;
810
d = (hydrophobic_moment - ordinate_min) * ordinate_scale;
812
screen_y0 = screen_margin_top + sectionI * section_height;
813
screen_y1 = screen_y0 + section_height;
814
screen_y = screen_y1 - (int) d;
816
/* If residue is near the N or C term., draw nothing: */
817
local_residueI = plotI % residues_per_sectionN;
818
if ((plotI < half_window_width) ||
819
(plotI > residues_in_plotN - window_width))
821
old_screen_y = screen_y;
826
/* Draw triple line: */
827
XDrawLine (guiSP->displaySP,
828
guiSP->main_hidden_pixmapID,
830
screen_x0, screen_y - 1,
831
screen_x1, screen_y - 1);
832
XDrawLine (guiSP->displaySP,
833
guiSP->main_hidden_pixmapID,
836
screen_x1, screen_y);
837
XDrawLine (guiSP->displaySP,
838
guiSP->main_hidden_pixmapID,
840
screen_x0, screen_y + 1,
841
screen_x1, screen_y + 1);
843
/* Initialize the flag which says is */
844
/* it necessary to draw vertical line: */
845
draw_vertical_lineF = 1;
847
/* For the first residue in the current */
848
/* section do not draw vertical line: */
849
local_residueI = plotI % residues_per_sectionN;
850
if (local_residueI == 0)
852
old_screen_y = screen_y0;
853
draw_vertical_lineF = 0;
856
/* For the first visible residue, do not draw vertical line: */
857
if (plotI == half_window_width)
859
old_screen_y = screen_y;
860
draw_vertical_lineF = 0;
863
/* Check is it necessary to draw vertical line: */
864
if (old_screen_y == screen_y)
866
old_screen_y = screen_y;
867
draw_vertical_lineF = 0;
870
/* Prepare the shift which is required to draw corners; take */
871
/* the next res. if there is no need to draw vertical lines: */
872
if (old_screen_y < screen_y0) shift = -1;
875
/* Draw three vertical lines: */
876
if (draw_vertical_lineF)
878
XDrawLine (guiSP->displaySP,
879
guiSP->main_hidden_pixmapID,
881
screen_x0, old_screen_y - shift,
882
screen_x0, screen_y - shift);
883
XDrawLine (guiSP->displaySP,
884
guiSP->main_hidden_pixmapID,
886
screen_x0 + 1, old_screen_y,
887
screen_x0 + 1, screen_y);
888
XDrawLine (guiSP->displaySP,
889
guiSP->main_hidden_pixmapID,
891
screen_x0 + 2, old_screen_y + shift,
892
screen_x0 + 2, screen_y + shift);
895
/* Copy the y coordinate for later use: */
896
old_screen_y = screen_y;
898
/* Fill NearestAtomS array: */
899
for (screen_x = screen_x0 + 2;
900
screen_x <= screen_x1 - 1;
903
for (screen_y = screen_y0;
904
screen_y <= screen_y1;
907
/* Prepare index to the array */
908
/* of NearestAtomS structures: */
909
pixelI = guiSP->main_win_free_area_width *
912
/* Check the pixel index: */
913
if (pixelI >= pixelsN) continue;
915
/* Pointer to NearestAtomS struct. */
916
/* assigned to current coordinates: */
917
curr_pixelSP = nearest_atomSP + pixelI;
919
/* Refresh NearestAtomS associated with */
920
/* this pixel; residue index is stored */
921
/* to location reserved for atom index. */
922
curr_pixelSP->last_refreshI = refreshI;
923
curr_pixelSP->atomI = residueI;
924
curr_pixelSP->z = hydrophobic_moment;
928
/* Update the plot index: */
933
/*------copy the prepared image to the main window:--------------------------*/
935
/* Copy hidden pixmap to the main window: */
936
XCopyArea (guiSP->displaySP,
937
guiSP->main_hidden_pixmapID, guiSP->main_winS.ID,
940
guiSP->main_win_free_area_width, guiSP->main_win_free_area_height,
943
return (size_t) residuesN;
946
/*===========================================================================*/