File: sec_structure_from.c

package info (click to toggle)
garlic 1.5-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,324 kB
  • ctags: 1,378
  • sloc: ansic: 50,306; makefile: 1,088
file content (159 lines) | stat: -rw-r--r-- 4,574 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
156
157
158
159
/* Copyright (C) 2000 Damir Zucic */

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

			    sec_structure_from.c

Purpose:
	Copy the secondary structure  from the specified macromolecular
	complex to  the secondary structure buffer.  Only the structure
	for selected range(s) is copied.  A given residue is treated as
	selected if  the first atom of  this residue  is selected.  For
	proteins, this is typically N.

Input:
	(1) Pointer to MolComplexS structure, with macromol. complexes.
	(2) The number of macromolecular complexes.
	(3) Pointer to RuntimeS structure.
	(4) Pointer to the string which contains  the macromol. complex
	    identifier.

Output:
	(1) Secondary structure from the specified complex is copied to
	    the secondary structure buffer.
	(2) Return value.

Return value:
	(1) Positive (command) code on success.
	(2) Negative (error) code on failure.

========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 "commands.h"
#include "typedefs.h"

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

char		*ExtractToken_ (char *, int, char *, char *);

/*======copy secondary structure from complex to sec. str. buffer:===========*/

int SecondaryStructureFrom_ (MolComplexS *mol_complexSP, int mol_complexesN,
			     RuntimeS *runtimeSP, char *stringP)
{
char			*remainderP;
char			tokenA[SHORTSTRINGSIZE];
int			complexID;
int			mol_complexI;
static MolComplexS	*curr_mol_complexSP;
int			job_doneF = 0;
size_t			residueI, residuesN;
size_t			selected_residueI = 0;
ResidueS		*curr_residueSP;
AtomS			*first_atomSP;

/* At least one macromolecular complex should be available: */
if (mol_complexesN == 0)
	{
	strcpy (runtimeSP->messageA, "No structure loaded!");
	runtimeSP->message_length = strlen (runtimeSP->messageA);
	return -1;
	}

/* Take the first token; it should be present: */
remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE, stringP, " \t\n");
if (!remainderP)
	{
	strcpy (runtimeSP->messageA, "Complex identifier missing!");
	runtimeSP->message_length = strlen (runtimeSP->messageA);
	return -2;
	}

/* Extract the macromolecular complex identifier: */
if (sscanf (tokenA, "%d", &complexID) != 1)
	{
	strcpy (runtimeSP->messageA, "Bad macromolecular complex identifier!");
	runtimeSP->message_length = strlen (runtimeSP->messageA);
	return -3;
	}

/* Check is the requested complex available at all: */
for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++)
	{
	/** Prepare the pointer to the current macromolecular complex: **/
	curr_mol_complexSP = mol_complexSP + mol_complexI;

	/* Check the number of atoms;  for bad */
	/* and discarded complexes it is zero: */
	if (curr_mol_complexSP->atomsN == 0) continue;

	/* If macromol. complex is recognized, set the catch flag to one: */
	if (curr_mol_complexSP->mol_complexID == complexID)
		{
		job_doneF = 1;
		break;
		}
	}

/* If the requested complex is not available, return negative value: */
if (job_doneF == 0)
	{
	strcpy (runtimeSP->messageA,
		"The requested complex is not available!");
	runtimeSP->message_length = strlen (runtimeSP->messageA);
	return -4;
	}

/* Prepare the number of residues: */
residuesN = curr_mol_complexSP->residuesN;

/* Copy the secondary structure (for selected residues only): */
residuesN = curr_mol_complexSP->residuesN;
for (residueI = 0; residueI < residuesN; residueI++)
	{
	/* Pointer to the current residue: */
	curr_residueSP = curr_mol_complexSP->residueSP + residueI;

	/* Pointer to the first atom: */
	first_atomSP = curr_mol_complexSP->atomSP +
		       curr_residueSP->residue_startI;

	/* If the first atom is not selected, do not copy the residue name: */
	if (first_atomSP->selectedF == 0) continue;

	/* Copy the secondary structure code: */
	*(runtimeSP->sec_structureP + selected_residueI) =
			*(curr_mol_complexSP->secondary_structureP + residueI);

	/* Update the selected residue index: */
	selected_residueI++;

	/* Check the number of selected residues: */
	if (selected_residueI >= MAXRESIDUES)
		{
		strcpy (runtimeSP->messageA,
			"Secondary structure too long!");
		runtimeSP->message_length = strlen (runtimeSP->messageA);
		return -5;
		}
	}

/*@@*/ /* This function should be tested with a real structure! */

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

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