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

« back to all changes in this revision

Viewing changes to hybonds.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
                                hybonds.c
 
6
 
 
7
Purpose:
 
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.
 
11
 
 
12
Input:
 
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.
 
23
 
 
24
Output:
 
25
        (1) Hydrogen bonds should be either visible or hidden.
 
26
        (2) Return value.
 
27
 
 
28
Return value:
 
29
        (1) Positive (command) code on success.
 
30
        (2) Negative (error) code on failure.
 
31
 
 
32
========includes:============================================================*/
 
33
 
 
34
#include <stdio.h>
 
35
 
 
36
#include <string.h>
 
37
 
 
38
#include <X11/Xlib.h>
 
39
#include <X11/Xutil.h>
 
40
#include <X11/Xos.h>
 
41
#include <X11/Xatom.h>
 
42
 
 
43
#include "defines.h"
 
44
#include "commands.h"
 
45
#include "typedefs.h"
 
46
 
 
47
/*======function prototypes:=================================================*/
 
48
 
 
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 *);
 
55
 
 
56
/*======execute hybonds command:=============================================*/
 
57
 
 
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)
 
62
{
 
63
char            *remainderP;
 
64
char            tokenA[STRINGSIZE];
 
65
short int       styleI;
 
66
int             mol_complexI;
 
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;
 
72
 
 
73
/* Initialize the styleI: */
 
74
styleI = 1;
 
75
 
 
76
/* Extract the first token: */
 
77
remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n");
 
78
 
 
79
/* If available, the first token should contain the bond drawing style: */
 
80
if (remainderP)
 
81
        {
 
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;
 
90
        else
 
91
                {
 
92
                sprintf (runtimeSP->messageA,
 
93
                         "Hydrogen bond drawing style \"%s\" not available!",
 
94
                         tokenA);
 
95
                runtimeSP->message_length = strlen (runtimeSP->messageA);
 
96
                return ERROR_HYBONDS;
 
97
                }
 
98
        }
 
99
 
 
100
/* If the first token was keyword OFF: */
 
101
if (styleI == -1)
 
102
        {
 
103
        /** Hide hydrogen bonds in every caught complex: **/
 
104
        for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++)
 
105
                {
 
106
                /*** Pointer to the current macromolecular complex: ***/
 
107
                curr_mol_complexSP = mol_complexSP + mol_complexI;
 
108
 
 
109
                /*** Check is the current macromol. complex caught: ***/
 
110
                if (curr_mol_complexSP->catchF == 0) continue;
 
111
 
 
112
                /*** Hide hydrogen bonds: ***/
 
113
                curr_mol_complexSP->hydrogen_bonds_hiddenF = 1;
 
114
                }
 
115
 
 
116
        /** Refresh the main window: **/
 
117
        (*refreshIP)++;
 
118
        MainRefresh_ (mol_complexSP, mol_complexesN,
 
119
                      runtimeSP, configSP, guiSP,
 
120
                      nearest_atomSP, pixelsN, *refreshIP);
 
121
 
 
122
        /** Refresh the control window: **/
 
123
        ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
 
124
                         configSP, guiSP);
 
125
 
 
126
        /** Return to caller: **/
 
127
        return COMMAND_HYBONDS;
 
128
        }
 
129
 
 
130
/* If this point is reached, make hydrogen bonds visible: */
 
131
for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++)
 
132
        {
 
133
        /** Pointer to the current macromolecular complex: **/
 
134
        curr_mol_complexSP = mol_complexSP + mol_complexI;
 
135
 
 
136
        /** Check is the current macromol. complex caught: **/
 
137
        if (curr_mol_complexSP->catchF == 0) continue;
 
138
 
 
139
        /** Make hydrogen bonds visible (unhide): **/
 
140
        curr_mol_complexSP->hydrogen_bonds_hiddenF = 0;
 
141
        }
 
142
 
 
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);
 
160
 
 
161
/* Generate hydrogen bonds, or just update the bond drawing style: */
 
162
GenerateHyBonds_ (mol_complexSP, mol_complexesN, configSP, styleI);
 
163
 
 
164
/* Refresh the main window: */
 
165
(*refreshIP)++;
 
166
MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP,
 
167
              nearest_atomSP, pixelsN, *refreshIP);
 
168
 
 
169
/* Refresh the control window: */
 
170
ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP);
 
171
 
 
172
/* Return positive value on success: */
 
173
return COMMAND_HYBONDS;
 
174
}
 
175
 
 
176
/*===========================================================================*/
 
177
 
 
178