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

« back to all changes in this revision

Viewing changes to calculate_psi.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
                                calculate_psi.c
 
6
 
 
7
Purpose:
 
8
        Calculate dihedral angle psi.
 
9
 
 
10
Input:
 
11
        (1) Pointer to VectorS structure, with N atom coordinates for the
 
12
            previous residue.
 
13
        (2) Pointer to VectorS structure, with CA atom coordinates.
 
14
        (3) Pointer to VectorS structure, with C atom coordinates.
 
15
        (4) Pointer to VectorS structure, with O atom coordinates.
 
16
 
 
17
Output:
 
18
        Return value.
 
19
 
 
20
Return value:
 
21
        (1) Dihedral angle psi, on success.
 
22
        (2) BADDIHEDANGLE on failure.
 
23
 
 
24
Notes:
 
25
        (1) This should help you to understand  phi and  psi definitions:
 
26
            ........./................
 
27
            | H * - * N              |
 
28
            |        \    phi1 = 180 |
 
29
            |         * CA           |
 
30
            |        /    psi1 = 180 |
 
31
            | O * - * C              |
 
32
            |........\...............|
 
33
            |       N * - * H        |
 
34
            |        /    phi2 = 180 |
 
35
            |    CA *                |
 
36
            |        \    psi2 = 180 |
 
37
            |       C * - * O        |
 
38
            |......../...............|
 
39
 
 
40
========includes:============================================================*/
 
41
 
 
42
#include <stdio.h>
 
43
 
 
44
#include <math.h>
 
45
 
 
46
#include <X11/Xlib.h>
 
47
#include <X11/Xutil.h>
 
48
#include <X11/Xos.h>
 
49
#include <X11/Xatom.h>
 
50
 
 
51
#include "defines.h"
 
52
#include "typedefs.h"
 
53
 
 
54
/*======function prototypes:=================================================*/
 
55
 
 
56
void            VectorProduct_ (VectorS *, VectorS *, VectorS *);
 
57
double          AbsoluteValue_ (VectorS *);
 
58
double          ScalarProduct_ (VectorS *, VectorS *);
 
59
 
 
60
/*======calculate the psi angle:=============================================*/
 
61
 
 
62
double CalculatePsi_ (VectorS *N_vectorSP, VectorS *CA_vectorSP,
 
63
                      VectorS *C_vectorSP, VectorS *O_vectorSP)
 
64
{
 
65
VectorS         CA_N_vectorS, CA_C_vectorS, C_O_vectorS;
 
66
VectorS         u1S, u2S, v1S, v2S;
 
67
double          denom, ratio;
 
68
double          alpha, psi;
 
69
 
 
70
 
 
71
/* Prepare three auxiliary vectors: */
 
72
CA_N_vectorS.x = N_vectorSP->x - CA_vectorSP->x;
 
73
CA_N_vectorS.y = N_vectorSP->y - CA_vectorSP->y;
 
74
CA_N_vectorS.z = N_vectorSP->z - CA_vectorSP->z;
 
75
CA_C_vectorS.x = C_vectorSP->x - CA_vectorSP->x;
 
76
CA_C_vectorS.y = C_vectorSP->y - CA_vectorSP->y;
 
77
CA_C_vectorS.z = C_vectorSP->z - CA_vectorSP->z;
 
78
C_O_vectorS.x  = O_vectorSP->x - C_vectorSP->x;
 
79
C_O_vectorS.y  = O_vectorSP->y - C_vectorSP->y;
 
80
C_O_vectorS.z  = O_vectorSP->z - C_vectorSP->z;
 
81
 
 
82
/* Two vectors perpendicular to CA_C_vectorS, mutually orthog., */
 
83
/* one in the plane defined by  CA_C_vectorS and  CA_N_vectorS: */
 
84
VectorProduct_ (&u1S, &CA_N_vectorS, &CA_C_vectorS);
 
85
VectorProduct_ (&u2S, &u1S, &CA_C_vectorS);
 
86
 
 
87
/* Two vectors perpendicular to CA_C_vectorS, mutually orthog., */
 
88
/* one in the plane  defined by  CA_C_vectorS and  C_O_vectorS: */
 
89
VectorProduct_ (&v1S, &CA_C_vectorS, &C_O_vectorS);
 
90
VectorProduct_ (&v2S, &v1S, &CA_C_vectorS);
 
91
 
 
92
/* The angle alpha, which will be used to calculate phi: */
 
93
denom = AbsoluteValue_ (&v2S) * AbsoluteValue_ (&u2S);
 
94
if (denom == 0.0)
 
95
        {
 
96
        return BADDIHEDANGLE;
 
97
        }
 
98
ratio = ScalarProduct_ (&v2S, &u2S) / denom;
 
99
if ((ratio > 1.0) || (ratio < -1.0)) return BADDIHEDANGLE;
 
100
alpha = acos (ratio);
 
101
 
 
102
/* There are two possible solutions; the right one is resolved here: */
 
103
if (ScalarProduct_ (&v2S, &u1S) >= 0) psi = alpha;
 
104
else psi = -alpha;
 
105
 
 
106
/* Return the angle (in radians): */
 
107
return psi;
 
108
}
 
109
 
 
110
/*===========================================================================*/
 
111
 
 
112