File: disulfide_bonds.c

package info (click to toggle)
garlic 1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,516 kB
  • sloc: ansic: 52,465; makefile: 2,254
file content (137 lines) | stat: -rw-r--r-- 3,708 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
/* Copyright (C) 2000-2003 Damir Zucic */

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

				disulfide_bonds.c

Purpose:
	Prepare disulfide bonds.  Only the distance  between two sulfur
	atoms is checked; the angle between two methylene groups is not
	checked.

Input:
	(1) Pointer to MolComplexS structure, with macromolecular data.
	(2) The array index of a given macromolecular complex.
	(3) Pointer to ConfigS structure, with configuration data.

Output:
	(1) Information about dusulfide bonds added.
	(2) Return value.

Return value:
	(1) The total number of bonds on success.
	(2) Zero if there are no atoms.
	(3) Negative, if there are some atoms but there are no bonds.

Notes:
	(1) If some atoms are deleted or inserted, all bonds have to be
	    updated. Note that array indices are shifted after addition
	    or deletion of atoms;  that's the most important reason for
	    thorough revision of bonds.

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

#include <stdio.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:=================================================*/

int		CheckDistance_ (double *, AtomS *, AtomS *, ConfigS *);
int		AddBond_ (AtomS *, int, int, int, size_t, double, int);

/*======prepare disulfide bonds:=============================================*/

size_t DisulfideBonds_ (MolComplexS *mol_complexSP,
			int mol_complexI, ConfigS *configSP)
{
size_t		total_bondsN = 0;
int		styleI;
size_t		atomsN, atom1I, atom2I;
		/* Use signed int to store the following indices: */
AtomS		*atom1SP, *atom2SP;
int		pairID;
int		bond_typeI;
double		distance;
char		alt_location1, alt_location2; 

/* Initialize the styleI: */
styleI = 1;

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

/* Disulfide bonds are treated as type 2: */
bond_typeI = 2;

/* The outer atomic loop: */
for (atom1I = 0; atom1I < atomsN; atom1I++)
	{
	/* Pointer to atom 1: */
	atom1SP = mol_complexSP->atomSP + atom1I;

	/* Check is this sulfur: */
	if (strcmp (atom1SP->raw_atomS.chemical_symbolA, " S") != 0) continue;

	/* The inner atomic loop: */
	for (atom2I = 0; atom2I < atomsN; atom2I++)
		{
		/* Atom is not bound to itself: */
		if (atom2I == atom1I) continue;

		/* Pointer to atom 2: */
		atom2SP = mol_complexSP->atomSP + atom2I;

		/* Both atoms should be sulfur atoms: */
		if (strcmp (atom1SP->raw_atomS.chemical_symbolA, " S") != 0)
			continue;
		if (strcmp (atom2SP->raw_atomS.chemical_symbolA, " S") != 0)
			continue;

		/* Check is there a chemical bond: */
		pairID = CheckDistance_ (&distance,
					 atom1SP, atom2SP, configSP);

		/* If bond is bad, check the next atom 2: */
		if (pairID <= 0) continue;

		/* Compare the alternate location indicators; */
		/* if both indicators  are different from ' ' */
		/* and mutually different,  the bond  is bad! */
		alt_location1 = atom1SP->raw_atomS.alt_location;
		alt_location2 = atom2SP->raw_atomS.alt_location;
		if ((alt_location1 != alt_location2) &&
		    (alt_location1 != ' ') && (alt_location2 != ' '))
			{
			continue;
			}

		/* If this point is reached, the bond does exist! */

		/* Add bond to atom 1: */
		AddBond_ (atom1SP,
			  pairID, bond_typeI,
			  mol_complexI, atom2I,
			  distance, styleI);

		/* Update the number of bonds in a macromolecular complex: */
		total_bondsN++;
		}
	}

/* If this point is reached, return the total number of bonds: */
return total_bondsN;
}

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