1
/* Copyright (C) 2000 Damir Zucic */
3
/*=============================================================================
8
Calculate dihedral angle psi.
11
(1) Pointer to VectorS structure, with N atom coordinates for the
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.
21
(1) Dihedral angle psi, on success.
22
(2) BADDIHEDANGLE on failure.
25
(1) This should help you to understand phi and psi definitions:
26
........./................
32
|........\...............|
38
|......../...............|
40
========includes:============================================================*/
47
#include <X11/Xutil.h>
49
#include <X11/Xatom.h>
54
/*======function prototypes:=================================================*/
56
void VectorProduct_ (VectorS *, VectorS *, VectorS *);
57
double AbsoluteValue_ (VectorS *);
58
double ScalarProduct_ (VectorS *, VectorS *);
60
/*======calculate the psi angle:=============================================*/
62
double CalculatePsi_ (VectorS *N_vectorSP, VectorS *CA_vectorSP,
63
VectorS *C_vectorSP, VectorS *O_vectorSP)
65
VectorS CA_N_vectorS, CA_C_vectorS, C_O_vectorS;
66
VectorS u1S, u2S, v1S, v2S;
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;
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);
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);
92
/* The angle alpha, which will be used to calculate phi: */
93
denom = AbsoluteValue_ (&v2S) * AbsoluteValue_ (&u2S);
98
ratio = ScalarProduct_ (&v2S, &u2S) / denom;
99
if ((ratio > 1.0) || (ratio < -1.0)) return BADDIHEDANGLE;
100
alpha = acos (ratio);
102
/* There are two possible solutions; the right one is resolved here: */
103
if (ScalarProduct_ (&v2S, &u1S) >= 0) psi = alpha;
106
/* Return the angle (in radians): */
110
/*===========================================================================*/