1
/* Copyright (C) 2000 Damir Zucic */
3
/*=============================================================================
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
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).
27
(1) The flag selectedF will be equal to one for selected atoms and
28
equal to zero for all other atoms.
32
(1) The number of selected atoms, if selection is done in this
34
(2) -1 if selection string is not suitable for this function.
35
(3) Some other negative value on failure.
37
========includes:============================================================*/
44
#include <X11/Xutil.h>
46
#include <X11/Xatom.h>
51
/*======function prototypes:=================================================*/
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);
69
/*======execute select command (special selection string):===================*/
71
long SpecialSelect_ (MolComplexS *mol_complexSP, int mol_complexesN,
72
RuntimeS *runtimeSP, char *stringP, int selection_modeI)
75
char tokenA[STRINGSIZE];
76
char full_stringA[STRINGSIZE];
80
SelectS include_selectS, exclude_selectS;
81
short int model_serialI;
83
/* Purify the selection string (remove the leading and trailing separators): */
84
if (!ExtractToken_ (tokenA, STRINGSIZE, stringP, " ,;\t\n")) return -1;
86
/* Check the selection string: */
89
if ((strstr (tokenA, "ALL") == tokenA) || (strstr (tokenA, "*") == tokenA))
90
strcpy (full_stringA, "*/*/*/*");
93
else if (strstr (tokenA, "POL") == tokenA)
95
"*/*/ARG,LYS,HIS,ASP,GLU,ASN,GLN,SER,THR,TRP,TYR/*");
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/*");
104
else if (strstr (tokenA, "ARO") == tokenA)
105
strcpy (full_stringA, "*/*/PHE,TYR,TRP,HIS/*");
108
else if (strstr (tokenA, "ALI") == tokenA)
109
strcpy (full_stringA, "*/*/ILE,LEU,VAL/*");
112
else if (strstr (tokenA, "SMA") == tokenA)
113
strcpy (full_stringA, "*/*/GLY,ALA,SER,THR,CYS,VAL,PRO,ASP,ASN/*");
116
else if (strstr (tokenA, "TIN") == tokenA)
117
strcpy (full_stringA, "*/*/GLY,ALA,SER/*");
120
else if (strstr (tokenA, "POS") == tokenA)
121
strcpy (full_stringA, "*/*/ARG,LYS,HIS/*");
124
else if (strstr (tokenA, "NEG") == tokenA)
125
strcpy (full_stringA, "*/*/GLU,ASP/*");
128
else if (strstr (tokenA, "BAS") == tokenA)
129
strcpy (full_stringA, "*/*/ARG,LYS,HIS/*");
132
else if (strstr (tokenA, "ACI") == tokenA)
133
strcpy (full_stringA, "*/*/GLU,ASP/*");
136
else if (strstr (tokenA, "CHA") == tokenA)
137
strcpy (full_stringA, "*/*/ARG,LYS,HIS,GLU,ASP/*");
140
else if (strstr (tokenA, "MAI") == tokenA)
141
strcpy (full_stringA, "*/*/*/CA,C,N,O");
144
else if (strstr (tokenA, "SID") == tokenA)
145
strcpy (full_stringA, "*/*/*/* EXCEPT CA,C,N,O");
148
else if (strstr (tokenA, "HET") == tokenA)
150
selected_atomsN = SelectHetero_ (mol_complexSP, mol_complexesN,
152
return selected_atomsN;
156
else if (strstr (tokenA, "CIS") == tokenA)
158
selected_atomsN = SelectCisTrans_ (mol_complexSP, mol_complexesN,
160
return selected_atomsN;
164
else if (strstr (tokenA, "TRA") == tokenA)
166
selected_atomsN = SelectCisTrans_ (mol_complexSP, mol_complexesN,
168
return selected_atomsN;
172
else if (strstr (tokenA, "BAD") == tokenA)
174
selected_atomsN = SelectCisTrans_ (mol_complexSP, mol_complexesN,
176
return selected_atomsN;
180
else if (strstr (tokenA, "COM") == tokenA)
182
selected_atomsN = SelectComplement_ (mol_complexSP, mol_complexesN,
184
return selected_atomsN;
188
else if (strstr (tokenA, "SEQ") == tokenA)
190
selected_atomsN = SelectSequence_ (mol_complexSP, mol_complexesN,
191
runtimeSP, selection_modeI);
192
return selected_atomsN;
196
else if (strstr (tokenA, "SPH") == tokenA)
198
selected_atomsN = SelectSphere_ (mol_complexSP, mol_complexesN,
199
runtimeSP, selection_modeI);
200
return selected_atomsN;
204
else if (strstr (tokenA, "ALT") == tokenA)
206
selected_atomsN = SelectAlternate_ (mol_complexSP, mol_complexesN,
208
return selected_atomsN;
212
else if (strstr (tokenA, "MOD") == tokenA)
214
model_serialI = (short int) ExtractIndex_ (stringP);
215
selected_atomsN = SelectModel_ (mol_complexSP, mol_complexesN,
216
selection_modeI, model_serialI);
217
return selected_atomsN;
221
else if (strstr (tokenA, "ABO") == tokenA)
223
selected_atomsN = SelectAbove_ (mol_complexSP, mol_complexesN,
225
return selected_atomsN;
229
else if (strstr (tokenA, "BEL") == tokenA)
231
selected_atomsN = SelectBelow_ (mol_complexSP, mol_complexesN,
233
return selected_atomsN;
236
/** String not recognized: **/
237
else return -1; /* Must be -1! */
241
while ((n = *P++) != '\0') if (n == '/') slashesN++;
242
if (slashesN != 3) return -1;
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;
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;
252
/* Do the selection: */
253
selected_atomsN = ApplySelection_ (mol_complexSP, mol_complexesN,
254
&include_selectS, &exclude_selectS,
257
/* Return the number of selected atoms: */
258
return selected_atomsN;
261
/*===========================================================================*/