~ubuntu-branches/ubuntu/breezy/garlic/breezy

« back to all changes in this revision

Viewing changes to bonds_style1.c

  • Committer: Bazaar Package Importer
  • Author(s): zhaoway
  • Date: 2001-04-24 07:09:13 UTC
  • Revision ID: james.westby@ubuntu.com-20010424070913-uzpupnwdfhmliebz
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 Damir Zucic */
 
2
 
 
3
/*=============================================================================
 
4
 
 
5
                                bonds_style1.c
 
6
 
 
7
Purpose:
 
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.
 
12
 
 
13
Input:
 
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
 
22
            a given pixel.
 
23
 
 
24
Output:
 
25
        (1) Atoms drawn to the hidden pixmap.
 
26
        (2) Return value.
 
27
 
 
28
Return value:
 
29
        (1) The number of bonds drawn.
 
30
 
 
31
Notes:
 
32
        (1) Indentation is exceptionally 4 spaces.
 
33
 
 
34
        (2) Deep indentation is allowed in this function.  This is not my
 
35
            favorite coding style but it may help to improve performance.
 
36
 
 
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
 
41
            shown here:
 
42
 
 
43
             ***    4    ***       o----->
 
44
               ***     ***         |       X
 
45
                 *** ***           |
 
46
             3     ***    1        V
 
47
                 *** ***              Y
 
48
               ***     ***
 
49
             ***    2    ***
 
50
 
 
51
        (4) Nothing is drawn for bonds perpendicular to the screen.
 
52
 
 
53
=============================================================================*/
 
54
 
 
55
#include <stdio.h>
 
56
 
 
57
#include <X11/Xlib.h>
 
58
#include <X11/Xutil.h>
 
59
#include <X11/Xos.h>
 
60
#include <X11/Xatom.h>
 
61
 
 
62
#include "defines.h"
 
63
#include "typedefs.h"
 
64
 
 
65
/*======function prototypes:=================================================*/
 
66
 
 
67
int             BondStyle1Quadrant1_ (Aux1S *);
 
68
int             BondStyle1Quadrant2_ (Aux1S *);
 
69
int             BondStyle1Quadrant3_ (Aux1S *);
 
70
int             BondStyle1Quadrant4_ (Aux1S *);
 
71
 
 
72
/*======draw bonds using style 1 (a single line):============================*/
 
73
 
 
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)
 
78
{
 
79
size_t                  bonds_drawnN = 0;
 
80
int                     imageI, imagesN;
 
81
Aux1S                   aux1S;
 
82
int                     mol_complexI;
 
83
MolComplexS             *curr_mol_complexSP, *partner_mol_complexSP;
 
84
size_t                  atomsN, atomI;
 
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;
 
89
int                     regionI;
 
90
double                  z_shift, delta_z_sign;
 
91
int                     hybonds_hiddenF;
 
92
 
 
93
/* Number of images: */
 
94
if (configSP->stereoF) imagesN = 2;
 
95
else imagesN = 1;
 
96
 
 
97
/* Prepare the auxiliary  Aux1S  structure,  used to */
 
98
/* reduce the number of arguments in function calls: */
 
99
aux1S.configSP = configSP;
 
100
aux1S.guiSP = guiSP;
 
101
aux1S.nearest_atomSP = nearest_atomSP;
 
102
aux1S.pixelsN = pixelsN;
 
103
aux1S.refreshI = refreshI;
 
104
 
 
105
/* Draw each macromolecular complex: */
 
106
for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++)
 
107
    {
 
108
    /* Pointer to current macromolecular complex: */
 
109
    curr_mol_complexSP = mol_complexSP + mol_complexI;
 
110
 
 
111
    /* Prepare and check the number of atoms: */
 
112
    atomsN = curr_mol_complexSP->atomsN;
 
113
    if (atomsN == 0) continue;
 
114
 
 
115
    /* Copy the macromol. complex index into aux1S: */
 
116
    aux1S.mol_complexI = mol_complexI;
 
117
 
 
118
    /* Copy the flag which says are hydrogen bonds hidden or not: */
 
119
    hybonds_hiddenF = curr_mol_complexSP->hydrogen_bonds_hiddenF;
 
120
 
 
121
    /* Draw bonds which have the given style: */
 
122
    for (atomI = 0; atomI < atomsN; atomI++)
 
123
        {
 
124
        /* Pointer to the current atom: */
 
125
        curr_atomSP = curr_mol_complexSP->atomSP + atomI;
 
126
 
 
127
        /* Check is atom hidden: */
 
128
        if (curr_atomSP->hiddenF) continue;
 
129
 
 
130
        /* Check is atom inside slab: */
 
131
        if (!curr_atomSP->inside_slabF) continue;
 
132
 
 
133
        /* Check is atom inside window: */
 
134
        if (!curr_atomSP->inside_windowF) continue;
 
135
 
 
136
        /* Prepare the color: */
 
137
        XSetForeground (guiSP->displaySP, guiSP->theGCA[0],
 
138
                        curr_atomSP->left_colorID);
 
139
 
 
140
        /* Copy the color value into Aux1S: */
 
141
        aux1S.colorIDA[0] = curr_atomSP->left_colorID;
 
142
 
 
143
        /* Copy the atomic index into aux1S: */
 
144
        aux1S.atomI = atomI;
 
145
 
 
146
        /* Number of bonds: */
 
147
        bondsN = curr_atomSP->bondsN;
 
148
 
 
149
        /* Bond loop: */
 
150
        for (bondI = 0; bondI < bondsN; bondI++)
 
151
            {
 
152
            /* Pointer to the structure with data about current bond: */
 
153
            curr_bondSP = curr_atomSP->true_bondSA + bondI;
 
154
 
 
155
            /* Check bond drawing style: */
 
156
            if (curr_bondSP->bond_styleI != 1) continue;
 
157
 
 
158
            /* If the current bond is hydrogen bond, it may be hidden: */
 
159
            if (curr_bondSP->bond_typeI == 0)
 
160
                {
 
161
                if (hybonds_hiddenF) continue;
 
162
                }
 
163
 
 
164
            /* The complex which contains the atom forming the bond: */
 
165
            partner_mol_complexSP = mol_complexSP +
 
166
                                    curr_bondSP->neighbor_mol_complexI;
 
167
 
 
168
            /* Pointer to the bond partner: */
 
169
            partner_atomSP = partner_mol_complexSP->atomSP +
 
170
                             curr_bondSP->neighbor_arrayI;
 
171
 
 
172
            /* If partner is not visible, do not draw this bond: */
 
173
            if (partner_atomSP->hiddenF) continue;
 
174
 
 
175
            /* Draw one (mono) or two bonds (stereo): */
 
176
            for (imageI = 0; imageI < imagesN; imageI++)
 
177
                {
 
178
                /* Copy imageI to aux1S: */
 
179
                aux1S.imageI = imageI;
 
180
 
 
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];
 
189
 
 
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;
 
194
 
 
195
                /* Tilt the bond to ensure the proper stacking of bonds: */
 
196
                delta_z_sign = 1.0;
 
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;
 
202
 
 
203
                /* Some absolute differences: */
 
204
                screen_abs_delta_x = abs (aux1S.screen_delta_x);
 
205
                screen_abs_delta_y = abs (aux1S.screen_delta_y);
 
206
 
 
207
                /* Find the region: */
 
208
                if (screen_abs_delta_x >= screen_abs_delta_y)
 
209
                    {
 
210
                    if (aux1S.screen_delta_x >= 0) regionI = 1;
 
211
                    else regionI = 3;
 
212
                    }
 
213
                else
 
214
                    {
 
215
                    if (aux1S.screen_delta_y >= 0) regionI = 2;
 
216
                    else regionI = 4;
 
217
                    }
 
218
                if ((aux1S.screen_delta_x == 0) && (aux1S.screen_delta_y == 0))
 
219
                    {
 
220
                    regionI = 0;
 
221
                    }
 
222
 
 
223
                /* Each region has its own drawing procedure: */
 
224
                switch (regionI)
 
225
                    {
 
226
                    /* Both atoms are  projected to  the same  point, */
 
227
                    /* i.e. this bond is perpendicular to the screen: */
 
228
                    case 0:
 
229
                        /* Do nothing! */
 
230
                        break;
 
231
 
 
232
                    /* Right quadrant: */
 
233
                    case 1:
 
234
                        BondStyle1Quadrant1_ (&aux1S);
 
235
                        break;
 
236
 
 
237
                    /* Bottom quadrant (check Note 3!): */
 
238
                    case 2:
 
239
                        BondStyle1Quadrant2_ (&aux1S);
 
240
                        break;
 
241
 
 
242
                    /* Left quadrant: */
 
243
                    case 3:
 
244
                        BondStyle1Quadrant3_ (&aux1S);
 
245
                        break;
 
246
 
 
247
                    /* Top quadrant (check Note 3!): */
 
248
                    case 4:
 
249
                        BondStyle1Quadrant4_ (&aux1S);
 
250
                        break;
 
251
 
 
252
                    /* This should be the impossible case: */
 
253
                    default:
 
254
                        ;
 
255
                    }
 
256
 
 
257
                /* Update the counter: */
 
258
                bonds_drawnN++;
 
259
                }       /* imageI loop */
 
260
            }           /* bondI  loop */
 
261
        }               /* atomI  loop */
 
262
    }                   /* mol_complexI loop */
 
263
 
 
264
/* Return the number of bonds which were drawn: */
 
265
return bonds_drawnN;
 
266
}
 
267
 
 
268
/*===========================================================================*/
 
269
 
 
270