1
/* Copyright (C) 2000 Damir Zucic */
3
/*=============================================================================
8
Draw bonds, using style 1 (a single line per bond). Half of each
9
bond is drawn and another half is assigned to the partner. Middle
10
color is used. The z value is calculated for each pixel. A bond
11
is visible only if both atoms forming this bond are visible.
14
(1) Pointer to MolComplexS structure.
15
(2) Number of macromolecular complexes.
16
(3) Pointer to ConfigS structure, with configuration data.
17
(4) Pointer to GUIS structure.
18
(5) Pointer to NearestAtomS structure, with information about the
19
atom occupying the given pixel.
20
(6) The number of pixels in the main window free area.
21
(7) The refreshI, used to check the NearestAtomS associated with
25
(1) Atoms drawn to the hidden pixmap.
29
(1) The number of bonds drawn.
32
(1) Indentation is exceptionally 4 spaces.
34
(2) Deep indentation is allowed in this function. This is not my
35
favorite coding style but it may help to improve performance.
37
(3) The vector from the current atom to the bond partner belongs
38
to one of five regions. If atomic positions are exactly the
39
same, the vector belongs to the region "zero". Otherwise, it
40
belongs to one of four quadrants. Quadrants are arranged as
51
(4) Nothing is drawn for bonds perpendicular to the screen.
53
=============================================================================*/
58
#include <X11/Xutil.h>
60
#include <X11/Xatom.h>
65
/*======function prototypes:=================================================*/
67
int BondStyle1Quadrant1_ (Aux1S *);
68
int BondStyle1Quadrant2_ (Aux1S *);
69
int BondStyle1Quadrant3_ (Aux1S *);
70
int BondStyle1Quadrant4_ (Aux1S *);
72
/*======draw bonds using style 1 (a single line):============================*/
74
size_t DrawBondsStyle1_ (MolComplexS *mol_complexSP, int mol_complexesN,
75
ConfigS *configSP, GUIS *guiSP,
76
NearestAtomS *nearest_atomSP, size_t pixelsN,
77
unsigned int refreshI)
79
size_t bonds_drawnN = 0;
83
MolComplexS *curr_mol_complexSP, *partner_mol_complexSP;
85
AtomS *curr_atomSP, *partner_atomSP;
86
short int bondsN, bondI;
87
TrueBondS *curr_bondSP;
88
int screen_abs_delta_x, screen_abs_delta_y;
90
double z_shift, delta_z_sign;
93
/* Number of images: */
94
if (configSP->stereoF) imagesN = 2;
97
/* Prepare the auxiliary Aux1S structure, used to */
98
/* reduce the number of arguments in function calls: */
99
aux1S.configSP = configSP;
101
aux1S.nearest_atomSP = nearest_atomSP;
102
aux1S.pixelsN = pixelsN;
103
aux1S.refreshI = refreshI;
105
/* Draw each macromolecular complex: */
106
for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++)
108
/* Pointer to current macromolecular complex: */
109
curr_mol_complexSP = mol_complexSP + mol_complexI;
111
/* Prepare and check the number of atoms: */
112
atomsN = curr_mol_complexSP->atomsN;
113
if (atomsN == 0) continue;
115
/* Copy the macromol. complex index into aux1S: */
116
aux1S.mol_complexI = mol_complexI;
118
/* Copy the flag which says are hydrogen bonds hidden or not: */
119
hybonds_hiddenF = curr_mol_complexSP->hydrogen_bonds_hiddenF;
121
/* Draw bonds which have the given style: */
122
for (atomI = 0; atomI < atomsN; atomI++)
124
/* Pointer to the current atom: */
125
curr_atomSP = curr_mol_complexSP->atomSP + atomI;
127
/* Check is atom hidden: */
128
if (curr_atomSP->hiddenF) continue;
130
/* Check is atom inside slab: */
131
if (!curr_atomSP->inside_slabF) continue;
133
/* Check is atom inside window: */
134
if (!curr_atomSP->inside_windowF) continue;
136
/* Prepare the color: */
137
XSetForeground (guiSP->displaySP, guiSP->theGCA[0],
138
curr_atomSP->left_colorID);
140
/* Copy the color value into Aux1S: */
141
aux1S.colorIDA[0] = curr_atomSP->left_colorID;
143
/* Copy the atomic index into aux1S: */
146
/* Number of bonds: */
147
bondsN = curr_atomSP->bondsN;
150
for (bondI = 0; bondI < bondsN; bondI++)
152
/* Pointer to the structure with data about current bond: */
153
curr_bondSP = curr_atomSP->true_bondSA + bondI;
155
/* Check bond drawing style: */
156
if (curr_bondSP->bond_styleI != 1) continue;
158
/* If the current bond is hydrogen bond, it may be hidden: */
159
if (curr_bondSP->bond_typeI == 0)
161
if (hybonds_hiddenF) continue;
164
/* The complex which contains the atom forming the bond: */
165
partner_mol_complexSP = mol_complexSP +
166
curr_bondSP->neighbor_mol_complexI;
168
/* Pointer to the bond partner: */
169
partner_atomSP = partner_mol_complexSP->atomSP +
170
curr_bondSP->neighbor_arrayI;
172
/* If partner is not visible, do not draw this bond: */
173
if (partner_atomSP->hiddenF) continue;
175
/* Draw one (mono) or two bonds (stereo): */
176
for (imageI = 0; imageI < imagesN; imageI++)
178
/* Copy imageI to aux1S: */
179
aux1S.imageI = imageI;
181
/* Prepare screen coordinates of */
182
/* both atoms involved in bond: */
183
aux1S.screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI];
184
aux1S.screen_y0 = curr_atomSP->raw_atomS.screen_y;
185
aux1S.screen_x1 = partner_atomSP->raw_atomS.screen_x[imageI];
186
aux1S.screen_y1 = partner_atomSP->raw_atomS.screen_y;
187
aux1S.atomic_z0 = curr_atomSP->raw_atomS.z[imageI];
188
aux1S.atomic_z1 = partner_atomSP->raw_atomS.z[imageI];
190
/* Prepare differences: */
191
aux1S.screen_delta_x = aux1S.screen_x1 - aux1S.screen_x0;
192
aux1S.screen_delta_y = aux1S.screen_y1 - aux1S.screen_y0;
193
aux1S.atomic_delta_z = aux1S.atomic_z1 - aux1S.atomic_z0;
195
/* Tilt the bond to ensure the proper stacking of bonds: */
197
if (aux1S.atomic_delta_z < 0) delta_z_sign = -1.0;
198
z_shift = delta_z_sign * Z_SHIFT;
199
aux1S.atomic_z0 += z_shift;
200
aux1S.atomic_z1 -= z_shift;
201
aux1S.atomic_delta_z -= 3 * z_shift;
203
/* Some absolute differences: */
204
screen_abs_delta_x = abs (aux1S.screen_delta_x);
205
screen_abs_delta_y = abs (aux1S.screen_delta_y);
207
/* Find the region: */
208
if (screen_abs_delta_x >= screen_abs_delta_y)
210
if (aux1S.screen_delta_x >= 0) regionI = 1;
215
if (aux1S.screen_delta_y >= 0) regionI = 2;
218
if ((aux1S.screen_delta_x == 0) && (aux1S.screen_delta_y == 0))
223
/* Each region has its own drawing procedure: */
226
/* Both atoms are projected to the same point, */
227
/* i.e. this bond is perpendicular to the screen: */
232
/* Right quadrant: */
234
BondStyle1Quadrant1_ (&aux1S);
237
/* Bottom quadrant (check Note 3!): */
239
BondStyle1Quadrant2_ (&aux1S);
244
BondStyle1Quadrant3_ (&aux1S);
247
/* Top quadrant (check Note 3!): */
249
BondStyle1Quadrant4_ (&aux1S);
252
/* This should be the impossible case: */
257
/* Update the counter: */
262
} /* mol_complexI loop */
264
/* Return the number of bonds which were drawn: */
268
/*===========================================================================*/