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

« back to all changes in this revision

Viewing changes to special_select.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
                                special_select.c
 
6
 
 
7
Purpose:
 
8
        Execute select command (the special version): try to interpret the
 
9
        selection string  as the special keyword.  Three selections  modes
 
10
        are available:  0 = overwrite,  1 = restrict,  2 = expand previous
 
11
        selection.  Special keywords  are:  ALL,  *,  POLAR,  HYDROPHOBIC,
 
12
        AROMATIC,  ALIPHATIC,  SMALL,  TINY,  POSITIVE,  NEGATIVE,  BASIC,
 
13
        ACIDIC, CHARGED, MAIN_CHAIN, SIDE_CHAINS, HETERO, CIS, TRANS, BAD,
 
14
        COMPLEMENT, SEQUENCE, SPHERE, ALTERNATE, MODEL, ABOVE  and  BELOW.
 
15
        Most of these keywords may be abbreviated to three characters. The
 
16
        only exception is keyword  HYDROPHOBIC:  it may be replaced by PHO
 
17
        or by HYDROPHO.
 
18
 
 
19
Input:
 
20
        (1) Pointer to MolComplexS structure, with macromol. complexes.
 
21
        (2) Number of macromolecular complexes.
 
22
        (3) Pointer to RuntimeS structure (the sequence buffer is there).
 
23
        (4) The selection string.
 
24
        (5) Selection mode index  (0 = overwr., 1 = restrict, 2 = expand).
 
25
 
 
26
Output:
 
27
        (1) The flag selectedF will be equal to one for selected atoms and
 
28
            equal to zero for all other atoms.
 
29
        (2) Return value.
 
30
 
 
31
Return value:
 
32
        (1) The number of  selected atoms,  if selection  is done  in this
 
33
            function.
 
34
        (2) -1 if selection string is not suitable for this function.
 
35
        (3) Some other negative value on failure.
 
36
 
 
37
========includes:============================================================*/
 
38
 
 
39
#include <stdio.h>
 
40
 
 
41
#include <string.h>
 
42
 
 
43
#include <X11/Xlib.h>
 
44
#include <X11/Xutil.h>
 
45
#include <X11/Xos.h>
 
46
#include <X11/Xatom.h>
 
47
 
 
48
#include "defines.h"
 
49
#include "typedefs.h"
 
50
 
 
51
/*======function prototypes:=================================================*/
 
52
 
 
53
char            *ExtractToken_ (char *, int, char *, char *);
 
54
int             ExtractIndex_ (char *);
 
55
long            SelectHetero_ (MolComplexS *, int, int);
 
56
long            SelectCisTrans_ (MolComplexS *, int, int, int);
 
57
long            SelectComplement_ (MolComplexS *, int, int);
 
58
long            SelectSequence_ (MolComplexS *, int, RuntimeS *, int);
 
59
long            SelectSphere_ (MolComplexS *, int, RuntimeS *, int);
 
60
long            SelectAlternate_ (MolComplexS *, int, int);
 
61
long            SelectModel_ (MolComplexS *, int, int, short int);
 
62
long            SelectAbove_ (MolComplexS *, int, int);
 
63
long            SelectBelow_ (MolComplexS *, int, int);
 
64
int             Include_ (SelectS *, char *);
 
65
int             Exclude_ (SelectS *, char *);
 
66
long            ApplySelection_ (MolComplexS *, int,
 
67
                                 SelectS *, SelectS *, int);
 
68
 
 
69
/*======execute select command (special selection string):===================*/
 
70
 
 
71
long SpecialSelect_ (MolComplexS *mol_complexSP, int mol_complexesN,
 
72
                     RuntimeS *runtimeSP, char *stringP, int selection_modeI)
 
73
{
 
74
long            selected_atomsN;
 
75
char            tokenA[STRINGSIZE];
 
76
char            full_stringA[STRINGSIZE];
 
77
char            *P;
 
78
int             n;
 
79
int             slashesN = 0;
 
80
SelectS         include_selectS, exclude_selectS;
 
81
short int       model_serialI;
 
82
 
 
83
/* Purify the selection string (remove the leading and trailing separators): */
 
84
if (!ExtractToken_ (tokenA, STRINGSIZE, stringP, " ,;\t\n")) return -1;
 
85
 
 
86
/* Check the selection string: */
 
87
 
 
88
/** ALL: **/
 
89
if ((strstr (tokenA, "ALL") == tokenA) || (strstr (tokenA, "*") == tokenA))
 
90
        strcpy (full_stringA, "*/*/*/*");
 
91
 
 
92
/** POLAR: **/
 
93
else if (strstr (tokenA, "POL") == tokenA)
 
94
        strcpy (full_stringA,
 
95
                "*/*/ARG,LYS,HIS,ASP,GLU,ASN,GLN,SER,THR,TRP,TYR/*");
 
96
 
 
97
/** HYDROPHOBIC: **/
 
98
else if ((strstr (tokenA, "HYDROPHO") == tokenA) ||
 
99
         (strstr (tokenA, "PHO") == tokenA))
 
100
        strcpy (full_stringA,
 
101
                "*/*/ALA,ILE,LEU,MET,PHE,TRP,VAL,TYR,CYS,GLY,HIS/*");
 
102
 
 
103
/** AROMATIC: **/
 
104
else if (strstr (tokenA, "ARO") == tokenA)
 
105
        strcpy (full_stringA, "*/*/PHE,TYR,TRP,HIS/*");
 
106
 
 
107
/** ALIPHATIC: **/
 
108
else if (strstr (tokenA, "ALI") == tokenA)
 
109
        strcpy (full_stringA, "*/*/ILE,LEU,VAL/*");
 
110
 
 
111
/** SMALL: **/
 
112
else if (strstr (tokenA, "SMA") == tokenA)
 
113
        strcpy (full_stringA, "*/*/GLY,ALA,SER,THR,CYS,VAL,PRO,ASP,ASN/*");
 
114
 
 
115
/** TINY: **/
 
116
else if (strstr (tokenA, "TIN") == tokenA)
 
117
        strcpy (full_stringA, "*/*/GLY,ALA,SER/*");
 
118
 
 
119
/** POSITIVE: **/
 
120
else if (strstr (tokenA, "POS") == tokenA)
 
121
        strcpy (full_stringA, "*/*/ARG,LYS,HIS/*");
 
122
 
 
123
/** NEGATIVE: **/
 
124
else if (strstr (tokenA, "NEG") == tokenA)
 
125
        strcpy (full_stringA, "*/*/GLU,ASP/*");
 
126
 
 
127
/** BASIC: **/
 
128
else if (strstr (tokenA, "BAS") == tokenA)
 
129
        strcpy (full_stringA, "*/*/ARG,LYS,HIS/*");
 
130
 
 
131
/** ACIDIC: **/
 
132
else if (strstr (tokenA, "ACI") == tokenA)
 
133
        strcpy (full_stringA, "*/*/GLU,ASP/*");
 
134
 
 
135
/** CHARGED: **/
 
136
else if (strstr (tokenA, "CHA") == tokenA)
 
137
        strcpy (full_stringA, "*/*/ARG,LYS,HIS,GLU,ASP/*");
 
138
 
 
139
/** MAIN_CHAIN: **/
 
140
else if (strstr (tokenA, "MAI") == tokenA)
 
141
        strcpy (full_stringA, "*/*/*/CA,C,N,O");
 
142
 
 
143
/** SIDE_CHAINS: **/
 
144
else if (strstr (tokenA, "SID") == tokenA)
 
145
        strcpy (full_stringA, "*/*/*/* EXCEPT CA,C,N,O");
 
146
 
 
147
/** HETERO: **/
 
148
else if (strstr (tokenA, "HET") == tokenA)
 
149
        {
 
150
        selected_atomsN = SelectHetero_ (mol_complexSP, mol_complexesN,
 
151
                                         selection_modeI);
 
152
        return selected_atomsN;
 
153
        }
 
154
 
 
155
/** CIS: **/
 
156
else if (strstr (tokenA, "CIS") == tokenA)
 
157
        {
 
158
        selected_atomsN = SelectCisTrans_ (mol_complexSP, mol_complexesN,
 
159
                                           selection_modeI, 2);
 
160
        return selected_atomsN;
 
161
        }
 
162
 
 
163
/** TRANS: **/
 
164
else if (strstr (tokenA, "TRA") == tokenA)
 
165
        {
 
166
        selected_atomsN = SelectCisTrans_ (mol_complexSP, mol_complexesN,
 
167
                                           selection_modeI, 1);
 
168
        return selected_atomsN;
 
169
        }
 
170
 
 
171
/** BAD: **/
 
172
else if (strstr (tokenA, "BAD") == tokenA)
 
173
        {
 
174
        selected_atomsN = SelectCisTrans_ (mol_complexSP, mol_complexesN,
 
175
                                           selection_modeI, 0);
 
176
        return selected_atomsN;
 
177
        }
 
178
 
 
179
/** COMPLEMENT: **/
 
180
else if (strstr (tokenA, "COM") == tokenA)
 
181
        {
 
182
        selected_atomsN = SelectComplement_ (mol_complexSP, mol_complexesN,
 
183
                                             selection_modeI);
 
184
        return selected_atomsN;
 
185
        }
 
186
 
 
187
/** SEQUENCE: **/
 
188
else if (strstr (tokenA, "SEQ") == tokenA)
 
189
        {
 
190
        selected_atomsN = SelectSequence_ (mol_complexSP, mol_complexesN,
 
191
                                           runtimeSP, selection_modeI);
 
192
        return selected_atomsN;
 
193
        }
 
194
 
 
195
/** SPHERE: **/
 
196
else if (strstr (tokenA, "SPH") == tokenA)
 
197
        {
 
198
        selected_atomsN = SelectSphere_ (mol_complexSP, mol_complexesN,
 
199
                                         runtimeSP, selection_modeI);
 
200
        return selected_atomsN;
 
201
        }
 
202
 
 
203
/** ALTERNATE: **/
 
204
else if (strstr (tokenA, "ALT") == tokenA)
 
205
        {
 
206
        selected_atomsN = SelectAlternate_ (mol_complexSP, mol_complexesN,
 
207
                                            selection_modeI);
 
208
        return selected_atomsN;
 
209
        }
 
210
 
 
211
/** MODEL: **/
 
212
else if (strstr (tokenA, "MOD") == tokenA)
 
213
        {
 
214
        model_serialI = (short int) ExtractIndex_ (stringP);
 
215
        selected_atomsN = SelectModel_ (mol_complexSP, mol_complexesN,
 
216
                                        selection_modeI, model_serialI);
 
217
        return selected_atomsN;
 
218
        }
 
219
 
 
220
/** ABOVE: **/
 
221
else if (strstr (tokenA, "ABO") == tokenA)
 
222
        {
 
223
        selected_atomsN = SelectAbove_ (mol_complexSP, mol_complexesN,
 
224
                                        selection_modeI);
 
225
        return selected_atomsN;
 
226
        }
 
227
 
 
228
/** BELOW: **/
 
229
else if (strstr (tokenA, "BEL") == tokenA)
 
230
        {
 
231
        selected_atomsN = SelectBelow_ (mol_complexSP, mol_complexesN,
 
232
                                        selection_modeI);
 
233
        return selected_atomsN;
 
234
        }
 
235
 
 
236
/** String not recognized: **/
 
237
else return -1;         /* Must be -1! */
 
238
 
 
239
/* Count slashes: */
 
240
P = full_stringA;
 
241
while ((n = *P++) != '\0') if (n == '/') slashesN++;
 
242
if (slashesN != 3) return -1;
 
243
 
 
244
/* Identify chains,  residue ranges,  residue */
 
245
/* names and atoms which have to be included: */
 
246
if (Include_ (&include_selectS, full_stringA) < 0) return -2;
 
247
 
 
248
/* Identify chains,  residue ranges,  residue */
 
249
/* names and atoms which have to be excluded: */
 
250
if (Exclude_ (&exclude_selectS, full_stringA) < 0) return -3;
 
251
 
 
252
/* Do the selection: */
 
253
selected_atomsN = ApplySelection_ (mol_complexSP, mol_complexesN,
 
254
                                   &include_selectS, &exclude_selectS,
 
255
                                   selection_modeI);
 
256
 
 
257
/* Return the number of selected atoms: */
 
258
return selected_atomsN;
 
259
}
 
260
 
 
261
/*===========================================================================*/
 
262
 
 
263