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

« back to all changes in this revision

Viewing changes to geomcenter.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
                                geomcenter.c
 
6
 
 
7
Purpose:
 
8
        Find geometric center position. Add it to MolComplexS structure.
 
9
 
 
10
Input:
 
11
        (1) Pointer to MolComplexS structure (macromolecular complex).
 
12
 
 
13
Output:
 
14
        (1) Geometric center vector stored to MolComplexS structure.
 
15
        (2) Return value.
 
16
 
 
17
Return value:
 
18
        (1) Positive if there are some atoms.
 
19
        (2) Zero if there are no atoms at all.
 
20
 
 
21
========includes:============================================================*/
 
22
 
 
23
#include <stdio.h>
 
24
#include <X11/Xlib.h>
 
25
#include <X11/Xutil.h>
 
26
#include <X11/Xos.h>
 
27
#include <X11/Xatom.h>
 
28
 
 
29
#include "defines.h"
 
30
#include "typedefs.h"
 
31
 
 
32
/*======find geometric center position:======================================*/
 
33
 
 
34
int GeometricCenter_ (MolComplexS *mol_complexSP)
 
35
{
 
36
size_t          atomsN, i;
 
37
AtomS           *curr_atomSP;
 
38
double          x = 0.0, y = 0.0, z = 0.0, denom;
 
39
 
 
40
atomsN = mol_complexSP->atomsN;
 
41
if (atomsN <= 0) return 0;
 
42
 
 
43
curr_atomSP = mol_complexSP->atomSP;
 
44
for (i = 0; i < atomsN; i++)
 
45
        {
 
46
        x += curr_atomSP->raw_atomS.x[0];
 
47
        y += curr_atomSP->raw_atomS.y;
 
48
        z += curr_atomSP->raw_atomS.z[0];
 
49
        curr_atomSP++;
 
50
        }
 
51
denom = 1.0 / (double) atomsN;  /* This is safe: atomsN is checked above! */
 
52
mol_complexSP->geometric_center_vectorS.x = x * denom;
 
53
mol_complexSP->geometric_center_vectorS.y = y * denom;
 
54
mol_complexSP->geometric_center_vectorS.z = z * denom;
 
55
 
 
56
return 1;
 
57
}
 
58
 
 
59
/*===========================================================================*/
 
60
 
 
61