File: refresh_backbone.c

package info (click to toggle)
garlic 1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 4,516 kB
  • sloc: ansic: 52,465; makefile: 2,254
file content (155 lines) | stat: -rw-r--r-- 4,182 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* Copyright (C) 2001-2003 Damir Zucic */

/*=============================================================================

				refresh_backbone.c

Purpose:
	Refresh the backbone information.

Input:
	(1) Pointer to  MolComplexS structure.
	(2) Pointer to ConfigS structure.

Output:
	(1) The array of BackboneS structures refreshed.
	(2) Return value.

Return value:
	(1) Positive on success.
	(2) Zero if there are no atoms.

========includes:============================================================*/

#include <stdio.h>

#include <stdlib.h>
#include <string.h>

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>

#include "defines.h"
#include "typedefs.h"

/*======function prototypes:=================================================*/

void		ErrorMessage_ (char *, char *, char *,
			       char *, char *, char *, char *);

/*======refresh backbone data:===============================================*/

int RefreshBackbone_ (MolComplexS *mol_complexSP, ConfigS *configSP)
{
size_t		atomI, atomsN;
AtomS		*curr_atomSP;
int		c_alphaI = 0;
BackboneS	*curr_backboneSP;
size_t		atom1I, atom2I;
AtomS		*atom0SP, *atom1SP, *atom2SP;
double		x0, y0, z0, x1, y1, z1, x2, y2, z2, delta_x, delta_y, delta_z;
double		d1_squared, d2_squared;
double		max_dist_squared;

/* Return zero if there are no atoms in this macromolecular complex: */
atomsN = mol_complexSP->atomsN;
if (atomsN == 0) return 0;

/* The maximal distance squared: */
max_dist_squared = configSP->CA_CA_dist_max_squared;

/* Initialize the BackboneS pointer: */
curr_backboneSP = mol_complexSP->backboneSP;

/* Scan the macromolecular complex and copy */
/* the updated array indices of  CA  atoms: */
for (atomI = 0; atomI < atomsN; atomI++)
	{
	/** Pointer to the current atom: **/
	curr_atomSP = mol_complexSP->atomSP + atomI;

	/** Check the purified atom name: **/
	if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "CA") != 0)
			continue;

	/** Pointer to the current BackboneS structure: **/
	curr_backboneSP = mol_complexSP->backboneSP + c_alphaI;

	/** Copy the index of the current atom: **/
	curr_backboneSP->c_alphaI = atomI;

	/** Update and check the counter of CA atoms: **/
	c_alphaI++;
	if (c_alphaI >= (int) mol_complexSP->c_alphaN) break;
	}

/* Check distances between neighbouring CA atoms: */
for (c_alphaI = 0; c_alphaI < (int) mol_complexSP->c_alphaN; c_alphaI++)
	{
	/** Pointer to the current BackboneS: **/
	curr_backboneSP = mol_complexSP->backboneSP + c_alphaI;

	/** Pointer to the current CA atom: **/
	atom0SP = mol_complexSP->atomSP + curr_backboneSP->c_alphaI;

	/** Position of the current CA atom: **/
	x0 = atom0SP->raw_atomS.x[0];
	y0 = atom0SP->raw_atomS.y;
	z0 = atom0SP->raw_atomS.z[0];

	/** Check distances between current CA, previous CA and next CA: **/

	/*** For the first CA, the previous CA does not exist: ***/
	if (c_alphaI > 0)
		{
		atom1I = (curr_backboneSP - 1)->c_alphaI;
		atom1SP = mol_complexSP->atomSP + atom1I;
		x1 = atom1SP->raw_atomS.x[0];
		y1 = atom1SP->raw_atomS.y;
		z1 = atom1SP->raw_atomS.z[0];
		delta_x = x1 - x0;
		delta_y = y1 - y0;
		delta_z = z1 - z0;
		d1_squared = delta_x * delta_x +
			     delta_y * delta_y +
			     delta_z * delta_z;
		if (d1_squared <= max_dist_squared)
			{
			curr_backboneSP->previous_c_alphaF = 1;
			curr_backboneSP->previous_c_alphaI = atom1I;
			}
		else curr_backboneSP->previous_c_alphaF = 0;
		}

	/*** For the last CA, the next CA does not exist: ***/
	if (c_alphaI < (int) mol_complexSP->c_alphaN - 1)
		{
		atom2I = (curr_backboneSP + 1)->c_alphaI;
		atom2SP = mol_complexSP->atomSP + atom2I;
		x2 = atom2SP->raw_atomS.x[0];
		y2 = atom2SP->raw_atomS.y;
		z2 = atom2SP->raw_atomS.z[0];
		delta_x = x2 - x0;
		delta_y = y2 - y0;
		delta_z = z2 - z0;
		d2_squared = delta_x * delta_x +
			     delta_y * delta_y +
			     delta_z * delta_z;
		if (d2_squared <= max_dist_squared)
			{
			curr_backboneSP->next_c_alphaF = 1;
			curr_backboneSP->next_c_alphaI = atom2I;
			}
		else curr_backboneSP->next_c_alphaF = 0;
		}
	}

/* Return positive value on success: */
return 1;
}

/*===========================================================================*/