Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
FitPDB.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file FitPDB.c
5 
6  \version V1.4
7  \date 07.07.14
8  \brief Fit two PDB linked lists. Also a weighted fit and support
9  routines
10 
11  \copyright (c) UCL / Dr. Andrew C. R. Martin 1993-6
12  \author Dr. Andrew C. R. Martin
13  \par
14  Institute of Structural & Molecular Biology,
15  University College London,
16  Gower Street,
17  London.
18  WC1E 6BT.
19  \par
20  andrew@bioinf.org.uk
21  andrew.martin@ucl.ac.uk
22 
23 **************************************************************************
24 
25  This code is NOT IN THE PUBLIC DOMAIN, but it may be copied
26  according to the conditions laid out in the accompanying file
27  COPYING.DOC.
28 
29  The code may be modified as required, but any modifications must be
30  documented so that the person responsible can be identified.
31 
32  The code may not be sold commercially or included as part of a
33  commercial product except as described in the file COPYING.DOC.
34 
35 **************************************************************************
36 
37  Description:
38  ============
39 
40 
41 **************************************************************************
42 
43  Usage:
44  ======
45 
46 **************************************************************************
47 
48  Revision History:
49  =================
50 - V1.0 01.03.94 Original release
51 - V1.1 11.03.94 Fixed bug in calls to matfit(). Had not been changed
52  to reflect modification in MatMult3_33().
53 - V1.2 14.03.94 Fixed FitPDB(); wasn't filling in the output matrix
54 - V1.3 14.03.96 Added FitCaPDB()
55  Changed FitPDB() and FitCaCbPDB() to use
56  ApplyMatrixPDB() rather than RotatePDB() since the PDB
57  linked lists are already at the origin
58 - V1.4 07.07.14 Use bl prefix for functions By: CTP
59 
60 *************************************************************************/
61 /* Doxygen
62  -------
63  #GROUP Handling PDB Data
64  #SUBGROUP Fitting
65  #KEYFUNCTION blFitPDB()
66  Fits two PDB linked lists. Actually fits fit_pdb onto ref_pdb and also
67  returns the rotation matrix. This may be NULL if these data are not
68  required.
69 */
70 /************************************************************************/
71 /* Includes
72 */
73 #include <math.h>
74 #include <stdlib.h>
75 #include <string.h>
76 
77 #include "MathType.h"
78 #include "SysDefs.h"
79 #include "macros.h"
80 #include "fit.h"
81 #include "pdb.h"
82 
83 /************************************************************************/
84 /* Defines and macros
85 */
86 
87 /************************************************************************/
88 /* Globals
89 */
90 
91 /************************************************************************/
92 /* Prototypes
93 */
94 
95 /************************************************************************/
96 /*>BOOL blFitPDB(PDB *ref_pdb, PDB *fit_pdb, REAL rm[3][3])
97  --------------------------------------------------------
98 *//**
99 
100  \param[in] *ref_pdb Reference PDB linked list
101  \param[in,out] *fit_pdb Mobile PDB linked list
102  \param[out] rm Rotation matrix (May be input as NULL).
103  \return Success
104 
105  Fits two PDB linked lists. Actually fits fit_pdb onto ref_pdb and also
106  returns the rotation matrix. This may be NULL if these data are not
107  required.
108 
109 - 17.06.93 Original based on code from ProFit By: ACRM
110 - 11.03.94 Changed call to matfit(). Corrected to normal matrix.
111 - 14.03.94 Actually fills in the rotation matrix (!). Restores original
112  data if fitting failed.
113 - 14.03.96 Changed to use ApplyMatrixPDB() rather than RotatePDB() since
114  we are already at the origin
115 - 07.07.14 Use bl prefix for functions By: CTP
116 */
117 BOOL blFitPDB(PDB *ref_pdb, PDB *fit_pdb, REAL rm[3][3])
118 {
119  REAL RotMat[3][3];
120  COOR *ref_coor = NULL,
121  *fit_coor = NULL;
122  VEC3F ref_CofG,
123  fit_CofG;
124  int NCoor = 0,
125  i, j;
126  BOOL RetVal;
127 
128  /* Get the CofG of the reference structure */
129  blGetCofGPDB(ref_pdb, &ref_CofG);
130  blGetCofGPDB(fit_pdb, &fit_CofG);
131 
132  /* Move them both to the origin */
133  blOriginPDB(ref_pdb);
134  blOriginPDB(fit_pdb);
135 
136  /* Create coordinate arrays */
137  NCoor = blGetPDBCoor(ref_pdb, &ref_coor);
138  if(blGetPDBCoor(fit_pdb, &fit_coor) != NCoor)
139  {
140  /* Free and return if arrays don't match */
141  if(ref_coor) free(ref_coor);
142  if(fit_coor) free(fit_coor);
143  return(FALSE);
144  }
145 
146  /* Can't fit with fewer than 3 coordinates */
147  if(NCoor < 3)
148  {
149  if(ref_coor) free(ref_coor);
150  if(fit_coor) free(fit_coor);
151  return(FALSE);
152  }
153 
154  /* Everything OK, go ahead with the fitting */
155  RetVal = blMatfit(ref_coor,fit_coor,RotMat,NCoor,NULL,FALSE);
156 
157  /* Now we can rotate the rotation list */
158  if(RetVal)
159  {
160  blApplyMatrixPDB(fit_pdb, RotMat);
161  blTranslatePDB(fit_pdb, ref_CofG);
162  blTranslatePDB(ref_pdb, ref_CofG);
163  }
164  else
165  {
166  blTranslatePDB(fit_pdb, fit_CofG);
167  blTranslatePDB(ref_pdb, ref_CofG);
168  }
169 
170  /* Free the coordinate arrays */
171  free(ref_coor);
172  free(fit_coor);
173 
174  /* Fill in the rotation matrix for output, if required */
175  if(rm!=NULL)
176  {
177  for(i=0; i<3; i++)
178  for(j=0; j<3; j++)
179  rm[i][j] = RotMat[i][j];
180  }
181 
182  return(RetVal);
183 }
184 
Include file for PDB routines.
short BOOL
Definition: SysDefs.h:64
#define NULL
Definition: array2.c:99
Definition: pdb.h:298
#define FALSE
Definition: macros.h:223
Useful macros.
Definition: MathType.h:69
int blGetPDBCoor(PDB *pdb, COOR **coor)
Definition: GetPDBCoor.c:104
double REAL
Definition: MathType.h:67
BOOL blFitPDB(PDB *ref_pdb, PDB *fit_pdb, REAL rm[3][3])
Definition: FitPDB.c:117
BOOL blMatfit(COOR *x1, COOR *x2, REAL rm[3][3], int n, REAL *wt1, BOOL column)
Definition: fit.c:128
Include file for least squares fitting.
void blGetCofGPDB(PDB *pdb, VEC3F *cg)
Definition: GetCGPDB.c:98
System-type variable type definitions.
void blOriginPDB(PDB *pdb)
Definition: OriginPDB.c:96
Type definitions for maths.
void blTranslatePDB(PDB *pdb, VEC3F tvect)
Definition: TranslatePDB.c:95
void blApplyMatrixPDB(PDB *pdb, REAL matrix[3][3])
Definition: ApMatPDB.c:92