File: quick_select.c

package info (click to toggle)
garlic 1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,516 kB
  • sloc: ansic: 52,465; makefile: 2,254
file content (141 lines) | stat: -rw-r--r-- 4,327 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* Copyright (C) 2000-2003 Damir Zucic */

/*=============================================================================

				quick_select.c

Purpose:
	Execute select command  (the quick version):  try to interpret the
	selection string as short selection string. Three selections modes
	are available:  0 = overwrite,  1 = restrict,  2 = expand previous
	selection.

Input:
	(1) Pointer to MolComplexS structure, with macromol. complexes.
	(2) Number of macromolecular complexes.
	(3) The selection string.
	(4) Selection mode index  (0 = overwr., 1 = restrict, 2 = expand).

Output:
	(1) The flag selectedF will be equal to one for selected atoms and
	    equal to zero for all other atoms.
	(2) Return value.

Return value:
	(1) The number of  selected atoms,  if selection  is done  in this
	    function.
	(2) Negative value on failure.

Notes:
	(1) This function  will try  to interpret  the selection string as
	    the set of residue ranges or as the set of residue names.  The
	    decision will be based on the string content: if it appears to
	    consist of printable characters which are  not alphabetic,  it
	    will be interpreted as  the set of residue ranges.  Otherwise,
	    it will be  interpreted as  the set  of residue names.  If the
	    string contains keyword EXCEPT (EXC), it may be interpreted as
	    a set of residue ranges  though it contains  alphabetic chars.

	(2) There is  no way to specify  the chain identifiers  and atomic
	    names using the "quick" selection syntax.  Only residue ranges
	    and residue names may be specified.

	(3) The return value  -1  has no special meaning,  except that the
	    selection job was not done properly.

========includes:============================================================*/

#include <stdio.h>

#include <string.h>
#include <ctype.h>

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>

#include "defines.h"
#include "typedefs.h"

/*======function prototypes:=================================================*/

int		Include_ (SelectS *, char *);
int		Exclude_ (SelectS *, char *);
long		ApplySelection_ (MolComplexS *, int,
				 SelectS *, SelectS *, int);

/*======execute select command (quick selection string):=====================*/

long QuickSelect_ (MolComplexS *mol_complexSP, int mol_complexesN,
		   char *stringP, int selection_modeI)
{
long		selected_atomsN;
char		copyA[STRINGSIZE];
int		rangesF;
char		*P;
int		n;
char		full_stringA[STRINGSIZE];
SelectS		include_selectS, exclude_selectS;

/* The short (quick) selection string should not contain any slashes: */
if (strstr (stringP, "/") != NULL) return (long) -1;

/* Make a copy of the string, to allow some modifications before check: */
strncpy (copyA, stringP, STRINGSIZE - 1);
copyA[STRINGSIZE - 1] = '\0';

/* If keyword  EXC  is present,  replace  all */
/* alphabetic characters after E with blanks: */
if ((P = strstr (copyA, "EXC")) != NULL)
	{
	while ((n = *P++) != '\0')
		{
		if (!isalpha (n)) break;
		else *(P - 1) = ' ';
		}
	}

/* Try to recognize the string type. The rangesF will be */
/* equal to one  if the specifyed string  was recognized */
/* as the set of residue ranges  and to  zero otherwise. */
rangesF = 1;
P = copyA;
while ((n = *P++) != '\0')
	{
	if (isalpha (n))
		{
		rangesF = 0;
		break;
		}
	}

/* Prepare the full selection string: */

/** If string was recognized as the set of residue ranges: **/
if (rangesF) sprintf (full_stringA, "*/%s/*/*", stringP);

/** If string was not recognized as the set of residue ranges, **/
/** assume it can be interpreted as  the set of residue names: **/
else sprintf (full_stringA, "*/*/%s/*", stringP);

/* Identify chains,  residue ranges,  residue */
/* names and atoms which have to be included: */
if (Include_ (&include_selectS, full_stringA) < 0) return (long) -2;

/* Identify chains,  residue ranges,  residue */
/* names and atoms which have to be excluded: */
if (Exclude_ (&exclude_selectS, full_stringA) < 0) return (long) -3;

/* Do the selection: */
selected_atomsN = ApplySelection_ (mol_complexSP, mol_complexesN,
				   &include_selectS, &exclude_selectS,
				   selection_modeI);

/* Return the number of selected atoms: */
return selected_atomsN;
}

/*===========================================================================*/