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

« back to all changes in this revision

Viewing changes to select_above.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
                                select_above.c
 
6
 
 
7
Purpose:
 
8
        Select atoms above the plane. The normal vector defines what is up
 
9
        and what is down.
 
10
 
 
11
Input:
 
12
        (1) Pointer to MolComplexS structure, with macromol. complexes.
 
13
        (2) Number of macromolecular complexes.
 
14
        (4) Selection mode index  (0 = overwrite, 1 = restrict, 2 = expand
 
15
            previous selection).
 
16
 
 
17
Output:
 
18
        (1) The  flag  selectedF  set to one  for selected atoms  in every
 
19
            caught macromolecular complex.
 
20
        (2) Return value.
 
21
 
 
22
Return value:
 
23
        (1) The number of selected atoms (zero or positive value).
 
24
 
 
25
========includes:============================================================*/
 
26
 
 
27
#include <stdio.h>
 
28
 
 
29
#include <X11/Xlib.h>
 
30
#include <X11/Xutil.h>
 
31
#include <X11/Xos.h>
 
32
#include <X11/Xatom.h>
 
33
 
 
34
#include "defines.h"
 
35
#include "typedefs.h"
 
36
 
 
37
/*======function prototypes:=================================================*/
 
38
 
 
39
double          ScalarProduct_ (VectorS *, VectorS *);
 
40
 
 
41
/*======select atoms above the plane:========================================*/
 
42
 
 
43
long SelectAbove_ (MolComplexS *mol_complexSP, int mol_complexesN,
 
44
                   int selection_modeI)
 
45
{
 
46
long            selected_atomsN = 0;
 
47
int             mol_complexI;
 
48
MolComplexS     *curr_mol_complexSP;
 
49
size_t          atomsN, atomI;
 
50
VectorS         normal_vectorS;
 
51
double          plane_center_x, plane_center_y, plane_center_z;
 
52
AtomS           *curr_atomSP;
 
53
double          x, y, z;
 
54
VectorS         curr_vectorS;
 
55
unsigned char   aboveF;
 
56
 
 
57
/* Select all atoms above the plane: */
 
58
for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++)
 
59
        {
 
60
        /* Pointer to the current macromolecular complex: */
 
61
        curr_mol_complexSP = mol_complexSP + mol_complexI;
 
62
 
 
63
        /* Check is the current macromolecular complex caught: */
 
64
        if (curr_mol_complexSP->catchF == 0) continue;
 
65
 
 
66
        /* Number of atoms in a macromolecular complex: */
 
67
        atomsN = curr_mol_complexSP->atomsN;
 
68
        if (atomsN == 0) continue;
 
69
 
 
70
        /* The normal vector: */ 
 
71
        normal_vectorS.x = curr_mol_complexSP->planeS.normal_x[0];
 
72
        normal_vectorS.y = curr_mol_complexSP->planeS.normal_y;
 
73
        normal_vectorS.z = curr_mol_complexSP->planeS.normal_z[0];
 
74
 
 
75
        /* Position of the plane center: */
 
76
        plane_center_x = curr_mol_complexSP->planeS.center_x[0];
 
77
        plane_center_y = curr_mol_complexSP->planeS.center_y;
 
78
        plane_center_z = curr_mol_complexSP->planeS.center_z[0];
 
79
 
 
80
        /* Scan all atoms in the current complex: */
 
81
        for (atomI = 0; atomI < atomsN; atomI++)
 
82
                {
 
83
                /* Pointer to the current atom: */
 
84
                curr_atomSP = curr_mol_complexSP->atomSP + atomI;
 
85
 
 
86
                /* Copy the coordinates: */
 
87
                x = curr_atomSP->raw_atomS.x[0];
 
88
                y = curr_atomSP->raw_atomS.y;
 
89
                z = curr_atomSP->raw_atomS.z[0];
 
90
 
 
91
                /* Position of the atom relative to the plane center: */
 
92
                curr_vectorS.x = x - plane_center_x;
 
93
                curr_vectorS.y = y - plane_center_y;
 
94
                curr_vectorS.z = z - plane_center_z;
 
95
 
 
96
                /* Reset the flag: */
 
97
                aboveF = 0;
 
98
 
 
99
                /* Check the sign of the scalar product: */
 
100
                if (ScalarProduct_ (&curr_vectorS, &normal_vectorS) > 0)
 
101
                        {
 
102
                        aboveF = 1;
 
103
                        }
 
104
 
 
105
                /* Set the selection flag for the current atom: */
 
106
                switch (selection_modeI)
 
107
                        {
 
108
                        /* Overwrite the previous selection: */
 
109
                        case 0:
 
110
                                curr_atomSP->selectedF = aboveF;
 
111
                                break;
 
112
 
 
113
                        /* Restrict the previous selection: */
 
114
                        case 1:
 
115
                                curr_atomSP->selectedF &= aboveF;
 
116
                                break;
 
117
 
 
118
                        /* Expand the previous selection: */
 
119
                        case 2:
 
120
                                curr_atomSP->selectedF |= aboveF;
 
121
                                break;
 
122
 
 
123
                        default:
 
124
                                ;
 
125
                        }
 
126
 
 
127
                /* Check the selection flag; increase */
 
128
                /* the count if flag is equal to one: */
 
129
                if (curr_atomSP->selectedF) selected_atomsN++;
 
130
                }
 
131
        }
 
132
 
 
133
/* Return the number of selected atoms: */
 
134
return selected_atomsN;
 
135
}
 
136
 
 
137
/*===========================================================================*/
 
138
 
 
139