The outage for Sunday 24th November has been cancelled.
Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
phi.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file phi.c
5 
6  \version V1.8
7  \date 17.07.14
8  \brief Calculate a torsion angle
9 
10  \copyright (c) UCL / Dr. Andrew C. R. Martin 1993-2014
11  \author Dr. Andrew C. R. Martin
12  \par
13  Institute of Structural & Molecular Biology,
14  University College London,
15  Gower Street,
16  London.
17  WC1E 6BT.
18  \par
19  andrew@bioinf.org.uk
20  andrew.martin@ucl.ac.uk
21 
22 **************************************************************************
23 
24  This code is NOT IN THE PUBLIC DOMAIN, but it may be copied
25  according to the conditions laid out in the accompanying file
26  COPYING.DOC.
27 
28  The code may be modified as required, but any modifications must be
29  documented so that the person responsible can be identified.
30 
31  The code may not be sold commercially or included as part of a
32  commercial product except as described in the file COPYING.DOC.
33 
34 **************************************************************************
35 
36  Description:
37  ============
38 
39 
40 **************************************************************************
41 
42  Usage:
43  ======
44 
45 **************************************************************************
46 
47  Revision History:
48  =================
49 
50 - V1.7 07.07.14 Use bl prefix for functions By: CTP
51 - V1.8 17.07.14 Removed unused varables By: ACRM
52 
53 *************************************************************************/
54 /* Doxygen
55  -------
56  #GROUP Maths
57  #SUBGROUP Geometry
58  #FUNCTION blPhi()
59  Calculates the torsion angle described by 4 sets of coordinates.
60 */
61 /************************************************************************/
62 /* Includes
63 */
64 #include <math.h>
65 #include "MathType.h"
66 
67 /************************************************************************/
68 /* Defines and macros
69 */
70 
71 /************************************************************************/
72 /* Globals
73 */
74 
75 /************************************************************************/
76 /* Prototypes
77 */
78 
79 
80 /************************************************************************/
81 /*>REAL blPhi(REAL xi,REAL yi,REAL zi,REAL xj,REAL yj,REAL zj,
82  REAL xk,REAL yk,REAL zk,REAL xl,REAL yl,REAL zl)
83  ---------------------------------------------------------
84 *//**
85 
86  \param[in] xi Input coordinate
87  \param[in] yi Input coordinate
88  \param[in] zi Input coordinate
89  \param[in] xj Input coordinate
90  \param[in] yj Input coordinate
91  \param[in] zj Input coordinate
92  \param[in] xk Input coordinate
93  \param[in] yk Input coordinate
94  \param[in] zk Input coordinate
95  \param[in] xl Input coordinate
96  \param[in] yl Input coordinate
97  \param[in] zl Input coordinate
98  \return The torsion angle between the 4 atoms
99 
100  Calculates the torsion angle described by 4 sets of coordinates.
101 
102 - 04.03.91 Original By: ACRM
103 - 16.06.93 Changed float to REAL
104 - 07.07.14 Use bl prefix for functions By: CTP
105 - 17.07.14 Removed unused variables By: ACRM
106 */
108  REAL yi,
109  REAL zi,
110  REAL xj,
111  REAL yj,
112  REAL zj,
113  REAL xk,
114  REAL yk,
115  REAL zk,
116  REAL xl,
117  REAL yl,
118  REAL zl)
119 {
120  REAL xij,yij,zij,
121  xkj,ykj,zkj,
122  xkl,ykl,zkl,
123  dxi,dyi,dzi,
124  gxi,gyi,gzi,
125  bi,bk,ct,
126  z1,z2,ap,s;
127 
128  /* Calculate the vectors C,B,C */
129  xij = xi - xj;
130  yij = yi - yj;
131  zij = zi - zj;
132  xkj = xk - xj;
133  ykj = yk - yj;
134  zkj = zk - zj;
135  xkl = xk - xl;
136  ykl = yk - yl;
137  zkl = zk - zl;
138 
139  /* Calculate the normals to the two planes n1 and n2
140  this is given as the cross products:
141  AB x BC
142  --------- = n1
143  |AB x BC|
144 
145  BC x CD
146  --------- = n2
147  |BC x CD|
148  */
149  dxi = yij * zkj - zij * ykj; /* Normal to plane 1 */
150  dyi = zij * xkj - xij * zkj;
151  dzi = xij * ykj - yij * xkj;
152  gxi = zkj * ykl - ykj * zkl; /* Normal to plane 2 */
153  gyi = xkj * zkl - zkj * xkl;
154  gzi = ykj * xkl - xkj * ykl;
155 
156  /* Calculate the length of the two normals */
157  bi = dxi * dxi + dyi * dyi + dzi * dzi;
158  bk = gxi * gxi + gyi * gyi + gzi * gzi;
159  ct = dxi * gxi + dyi * gyi + dzi * gzi;
160 
161  bi = (REAL)sqrt((double)bi);
162  bk = (REAL)sqrt((double)bk);
163 
164  z1 = 1./bi;
165  z2 = 1./bk;
166 
167  ct = ct * z1 * z2;
168  if (ct > 1.0) ct = 1.0;
169  if (ct < (-1.0)) ct = -1.0;
170  ap = acos(ct);
171 
172  s = xkj * (dzi * gyi - dyi * gzi)
173  + ykj * (dxi * gzi - dzi * gxi)
174  + zkj * (dyi * gxi - dxi * gyi);
175 
176  if (s < 0.0) ap = -ap;
177 
178  ap = (ap > 0.0) ? PI-ap : -(PI+ap);
179 
180  return(ap);
181 }
182 
#define PI
Definition: macros.h:215
double REAL
Definition: MathType.h:67
REAL blPhi(REAL xi, REAL yi, REAL zi, REAL xj, REAL yj, REAL zj, REAL xk, REAL yk, REAL zk, REAL xl, REAL yl, REAL zl)
Definition: phi.c:107
Type definitions for maths.