Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
angle.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file angle.c
5 
6  \version V1.6
7  \date 07.07.14
8  \brief Calculate angles, torsions, etc.
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  These routines return angles and torsion angles. The definition of a
40  torsion angle is the chemical definition:
41  i.e. Assuming the atoms are co-planar:
42 
43 
44  A---B A---B
45  | = 0.0 | = 180.0
46  | |
47  D---C C---D
48 
49 **************************************************************************
50 
51  Usage:
52  ======
53 
54 
55  REAL angle(xi,yi,zi,xj,yj,zj,xk,yk,zk)
56  Input: REAL xi,yi,zi Input coordinates
57  Input: xj,yj,zj
58  Input: xk,yk,zk
59  Returns: REAL The angle between the 3 atoms
60 
61 
62  REAL phi(xi,yi,zi,xj,yj,zj,xk,yk,zk,xl,yl,zl)
63  Input: REAL xi,yi,zi Input coordinates
64  Input: xj,yj,zj
65  Input: xk,yk,zk
66  Input: xl,yl,zl
67  Returns: REAL The torsion angle between the 4 atoms
68 
69 
70  REAL simpleang(ang)
71  Input: REAL ang An angle
72  Returns: REAL Simplified angle
73 
74  Simplifies a signed angle to an unsigned angle <=2*PI
75 
76 
77  REAL TrueAngle(REAL opp, REAL adj)
78  Input: REAL opp Length of opposite side
79  Input: REAL adj Length of adjacent side
80  Returns: REAL The angle from 0 to 2PI
81 
82  Returns the true positive angle between 0 and 2PI given the opp and
83  adj lengths
84 
85 **************************************************************************
86 
87  Revision History:
88  =================
89 - V1.0 07.02.91 Original
90 - V1.1 17.02.91 Corrected comments to new standard and added phi()
91 - V1.2 04.03.91 angle() and phi() now return _correct_ values!
92 - V1.3 01.06.92 ANSIed
93 - V1.4 08.12.92 Changed abs() to ABS() from macros.h
94 - V1.5 27.03.95 Added TrueAngle()
95 - V1.6 07.07.14 Use bl prefix for functions By: CTP
96 
97 
98 *************************************************************************/
99 /* Doxygen
100  -------
101  #GROUP Maths
102  #SUBGROUP Geometry
103  #FUNCTION blAngle()
104  Calculates the angle between three sets of coordinates
105 */
106 /************************************************************************/
107 /* Includes
108 */
109 #include <math.h>
110 
111 #include "MathType.h"
112 #include "macros.h"
113 
114 /************************************************************************/
115 /* Defines and macros
116 */
117 
118 /************************************************************************/
119 /* Globals
120 */
121 
122 /************************************************************************/
123 /* Prototypes
124 */
125 
126 /************************************************************************/
127 /*>REAL blAngle(REAL xi,REAL yi,REAL zi,REAL xj,REAL yj,
128  REAL zj,REAL xk,REAL yk,REAL zk)
129  -----------------------------------------------------
130 *//**
131 
132  \param[in] xi Input coordinate
133  \param[in] yi Input coordinate
134  \param[in] zi Input coordinate
135  \param[in] xj Input coordinate
136  \param[in] yj Input coordinate
137  \param[in] zj Input coordinate
138  \param[in] xk Input coordinate
139  \param[in] yk Input coordinate
140  \param[in] zk Input coordinate
141  \return The angle between the 3 atoms
142 
143  Calculates the angle between three sets of coordinates
144 
145 - 07.02.89 Original By: ACRM
146 - 04.03.91 Fixed return value
147 - 16.06.93 Changed float to REAL
148 - 07.07.14 Use bl prefix for functions By: CTP
149 */
151  REAL yi,
152  REAL zi,
153  REAL xj,
154  REAL yj,
155  REAL zj,
156  REAL xk,
157  REAL yk,
158  REAL zk)
159 {
160  REAL qx,qy,qz,sq,px,py,pz,sp,cosa2,a2;
161 
162  px = xi - xj;
163  py = yi - yj;
164  pz = zi - zj;
165  sp = sqrt(px * px + py * py + pz * pz);
166 
167  qx = xk - xj;
168  qy = yk - yj;
169  qz = zk - zj;
170  sq = sqrt(qx * qx + qy * qy + qz * qz);
171 
172  cosa2 = (qx * px + qy * py + qz * pz) / (sp * sq);
173  a2 = acos(cosa2);
174 
175  return(a2);
176 }
177 
REAL blAngle(REAL xi, REAL yi, REAL zi, REAL xj, REAL yj, REAL zj, REAL xk, REAL yk, REAL zk)
Definition: angle.c:150
Useful macros.
double REAL
Definition: MathType.h:67
Type definitions for maths.