Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
FitCaPDB.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file FitCaPDB.c
5 
6  \version V1.6
7  \date 19.08.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-2009
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
52  changed 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() Changed FitPDB() and FitCaCbPDB()
55  to use ApplyMatrixPDB() rather than RotatePDB()
56  since the PDB linked lists are already at the
57  origin
58  - V1.4 28.01.09 Initialize RetVal - this randomly worked in 32bit
59  but broke in 64bit
60  - V1.5 07.07.14 Use bl prefix for functions By: CTP
61  - V1.6 19.08.14 Fixed calls to renamed function:
62  blSelectAtomsPDBAsCopy() By: CTP
63 
64 *************************************************************************/
65 /* Doxygen
66  -------
67  #GROUP Handling PDB Data
68  #SUBGROUP Fitting
69  #FUNCTION blFitCaPDB()
70  Fits two PDB linked lists using only the CA atoms.
71 */
72 /************************************************************************/
73 /* Includes
74 */
75 #include <math.h>
76 #include <stdlib.h>
77 #include <string.h>
78 
79 #include "MathType.h"
80 #include "SysDefs.h"
81 #include "macros.h"
82 #include "fit.h"
83 #include "pdb.h"
84 
85 /************************************************************************/
86 /* Defines and macros
87 */
88 
89 /************************************************************************/
90 /* Globals
91 */
92 
93 /************************************************************************/
94 /* Prototypes
95 */
96 
97 /************************************************************************/
98 /*>BOOL blFitCaPDB(PDB *ref_pdb, PDB *fit_pdb, REAL rm[3][3])
99  --------------------------------------------------------
100 *//**
101 
102  \param[in] *ref_pdb Reference PDB linked list
103  \param[in,out] *fit_pdb Mobile PDB linked list
104  \param[out] rm Rotation matrix (May be input as NULL).
105  \return Success
106 
107  Fits two PDB linked lists using only the CA atoms.
108 
109  Actually fits fit_pdb onto ref_pdb and also returns the rotation
110  matrix. This may be NULL if these data are not required.
111 
112 - 14.03.96 Original based on FitPDB() By: ACRM
113 - 28.01.09 Initialize RetVal to TRUE!
114 - 07.07.14 Use bl prefix for functions By: CTP
115 - 19.08.14 Added AsCopy suffix to calls to blSelectAtomsPDB() By: CTP
116 */
117 BOOL blFitCaPDB(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_ca_CofG,
123  fit_ca_CofG,
124  tvect;
125  int NCoor = 0,
126  i, j,
127  natoms;
128  BOOL RetVal = TRUE;
129  PDB *ref_ca_pdb = NULL,
130  *fit_ca_pdb = NULL;
131  char *sel[2];
132 
133  /* First extract only the CA atoms */
134  SELECT(sel[0], "CA ");
135  if(sel[0]==NULL)
136  return(FALSE);
137  if( (ref_ca_pdb = blSelectAtomsPDBAsCopy(ref_pdb, 1, sel, &natoms))
138  == NULL )
139  RetVal = FALSE;
140  if( (fit_ca_pdb = blSelectAtomsPDBAsCopy(fit_pdb, 1, sel, &natoms))
141  == NULL )
142  RetVal = FALSE;
143  free(sel[0]);
144 
145  /* If we succeeded in building our CA PDB linked lists... */
146  if(RetVal)
147  {
148  /* Get the CofG of the CA structures and the original mobile */
149  blGetCofGPDB(ref_ca_pdb, &ref_ca_CofG);
150  blGetCofGPDB(fit_ca_pdb, &fit_ca_CofG);
151 
152  /* Move them both to the origin */
153  blOriginPDB(ref_ca_pdb);
154  blOriginPDB(fit_ca_pdb);
155 
156  /* Create coordinate arrays, checking numbers match */
157  NCoor = blGetPDBCoor(ref_ca_pdb, &ref_coor);
158  if(blGetPDBCoor(fit_ca_pdb, &fit_coor) != NCoor)
159  {
160  RetVal = FALSE;
161  }
162  else
163  {
164  /* Can't fit with fewer than 3 coordinates */
165  if(NCoor < 3)
166  {
167  RetVal = FALSE;
168  }
169  else
170  {
171  /* Everything OK, go ahead with the fitting */
172  if(!blMatfit(ref_coor,fit_coor,RotMat,NCoor,NULL,FALSE))
173  {
174  RetVal = FALSE;
175  }
176  else
177  {
178  /* Apply the operations to the true coordinates */
179  tvect.x = (-fit_ca_CofG.x);
180  tvect.y = (-fit_ca_CofG.y);
181  tvect.z = (-fit_ca_CofG.z);
182  blTranslatePDB(fit_pdb, tvect);
183  blApplyMatrixPDB(fit_pdb, RotMat);
184  blTranslatePDB(fit_pdb, ref_ca_CofG);
185  }
186  }
187  }
188  }
189 
190  /* Free the coordinate arrays and CA PDB linked lists */
191  if(ref_coor) free(ref_coor);
192  if(fit_coor) free(fit_coor);
193  if(ref_ca_pdb) FREELIST(ref_ca_pdb, PDB);
194  if(fit_ca_pdb) FREELIST(fit_ca_pdb, PDB);
195 
196  /* Fill in the rotation matrix for output, if required */
197  if(RetVal && (rm!=NULL))
198  {
199  for(i=0; i<3; i++)
200  for(j=0; j<3; j++)
201  rm[i][j] = RotMat[i][j];
202  }
203 
204  return(RetVal);
205 }
206 
Include file for PDB routines.
REAL x
Definition: MathType.h:70
short BOOL
Definition: SysDefs.h:64
#define NULL
Definition: array2.c:99
Definition: pdb.h:298
PDB * blSelectAtomsPDBAsCopy(PDB *pdbin, int nsel, char **sel, int *natom)
Definition: SelAtPDB.c:173
#define FALSE
Definition: macros.h:223
BOOL blFitCaPDB(PDB *ref_pdb, PDB *fit_pdb, REAL rm[3][3])
Definition: FitCaPDB.c:117
Useful macros.
Definition: MathType.h:69
int blGetPDBCoor(PDB *pdb, COOR **coor)
Definition: GetPDBCoor.c:104
double REAL
Definition: MathType.h:67
#define TRUE
Definition: macros.h:219
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.
#define SELECT(x, w)
Definition: pdb.h:357
void blGetCofGPDB(PDB *pdb, VEC3F *cg)
Definition: GetCGPDB.c:98
#define FREELIST(y, z)
Definition: macros.h:264
System-type variable type definitions.
void blOriginPDB(PDB *pdb)
Definition: OriginPDB.c:96
Type definitions for maths.
REAL z
Definition: MathType.h:70
void blTranslatePDB(PDB *pdb, VEC3F tvect)
Definition: TranslatePDB.c:95
REAL y
Definition: MathType.h:70
void blApplyMatrixPDB(PDB *pdb, REAL matrix[3][3])
Definition: ApMatPDB.c:92